Need help getting started with simple 3d programming task

What I want to do: I want to display various colored blocks with various lines connecting them in a 3d space. A couple hundred or so blocks, 2 to 8 or so lines out of each. Groups of blocks will form things line triangles, squares, 3d prism shapes, cylinders, etc.

I’m an experienced programmer. I want to write a Mac program in Swift to display them such that the user can rotate the whole space, zoom in and out, and drag individual blocks around in order to from groups into shapes (as mentioned above).

I’m assuming I should use OpenGL. But I’m having trouble finding tutorials or samples or documentation to get me started. This isn’t a game, I don’t need animation, I don’t need to display a sphere with lighting and shadows, just a relatively simple 3d “drawing” that can be manipulated in simple ways. But everything I’ve found so far googling seems to be way beyond what I need and I end up feeling overwhelmed.

Does anyone have any suggestions or pointers?

And before anyone asks, this is not a class project or anything like that, just something of my own I’d like to do.

I just saw a presentation on A-Frame, and you may find it quite useful. It is a web-enabled wrapper around OpenGL, if I understand it correctly. Feel free to check it out at https://aframe.io/.

Even though game engines are overkill, they may still be a good choice. I understand you want to use Swift, so ignore this post if that is truly a requirement vs just your starting thought process.

For example, I’m using jmonkeyengine for java for non-game graphics stuff. Using the default project setup and just the first few pages of the hello world tutorial, you could have something like you describe up and working with about 30 lines of code cut and pasted from tutorial.

Basically:
Loop to create multiple shapes:
a few lines of code with default things supplied by engine to create a 3D shape and add to scene
Add a light source so there is a little shading so you can view the 3D nature (otherwise difficult to see if all sides same color)

The ability to shift the view is built in to the default project.
I’ve never used the Unity engine, but I’ve read that it’s pretty user friendly.

Do you have a goal of learning how to do 3D programming from the ground up, and are willing to spend (at least) a few dozen hours on the effort, or are you mostly looking to accomplish your goal as quickly as possible?

If the latter, I agree with RaftPeople–grab a free game engine. Unity is a good one. Unreal Engine is a bit more advanced but harder to use in my experience.

If the former, I’m happy to answer questions, and can come up with some online resources.

Thanks for the replies. I was hoping to use Swift, mainly because I’m fairly proficient at it and really like it. But my program actually already exists in Java, written many, many years ago using the old Java Graphics library and achieving “rotation” of the drawing by brute force changing all the coordinates of every point and redrawing the entire screen manually. So jmonkeyengine might be the best way for me to go, I’ll try your suggestion, RaftPeople.

In reply to Dr. Strangelove’s question, my immediate goal is get my little drawing up in 3d with as little effort as possible. But eventually I would like to learn real 3d programming, and at various times in the last few years I’ve done some googling, I think I even took a stab at learning Unity once bit didn’t get very far. I appreciate the offer of help, but right now I don’t know enough to even ask an intelligent question. Before posting here, I started reading this intro to graphics and 3d concepts, https://www.scratchapixel.com/lessons/3d-basic-rendering/get-started, but when it got into ray tracing I felt like it was way beyond what I needed for my little project. So I came here to find out if there’s an easy way or if I have no choice but to spend those dozens of hours.

So if you have some good pointers to beginner tutorials, I would appreciate it.

When I started out with OpenGL, I used GLUT (OpenGL Utility Toolkit) to create the background window. If you search for “introduction opengl glut”, you should find plenty of example code to get started.

After you get a simple example working, I’d experiment with different shapes and capabilities. You can also learn about the GLM and GLSL shaders.

Be sure to proceed gradually. Debugging an OpenGL application is a nightmare, so it’s critical to understand how the code works.

I’ve just started the process of converting from my own custom set of 2D routines to using an engine, so I’m still getting up to speed with jmonkeyengine. I spent last weekend going through the tutorials and getting some basic stuff working like some rotating 3D cubes with basic lighting. I can answer some basic questions, but that’s about it, feel free to post in this thread and I’ll provide any info I can.
You may be wondering why I was using custom routines, here’s the answer:
I had some 2D graphics needs for a couple different simulations I wrote a long time ago that needed to be in Java, but Java had a couple issues:
1 - Java graphics were just too slow for my needs (tracking and drawing tens of thousands of very small objects)
2 - Java wouldn’t use the floating point hardware at the time

So I wrote a set of routines that used direct pixel writes to draw along with integer based routines where you could choose how many bits were for fractional amounts. It was fast and worked great, but my current project needs 3D and I don’t want to reinvent the wheel.

I downloaded JMonkeyEngine, but on my MacBook Pro running OSX 10.12.6, it doesn’t launch, I double-click the app and nothing happens, nothing in the console either. I’ve asked on the JME forums.

It requires Java, I’m on version 8 on windows. It’s a fork of Netbeans IDE, not sure if that will help with debugging.

Could be classpath?

Thanks, I have Java and Netbeans. Netbeans runs just fine. It’s my karma, this almost always happens to me, I hit the weird error that no one else has ever hit. Still hoping someone on the JME forum will have an answer.

OpenGL makes everything difficult unless you’re doing fully lit scenes with textures and bumpmaps. It’s probably possible, but the documentation ignores the question of how to do simple things and the graphics cards can be testy when it comes to drawing with “easier” settings. Overall, I’d say skip it.

Game Engines tend to be either really expensive, because they work, or are free because they’re some guy’s hobby and he gave up somewhere near the beginning of the project.

This framework for WebGL (browser-based 3D) looks like it might be optimized for basic shapes:

https://en.wikipedia.org/wiki/A-Frame_(virtual_reality_framework)

You’d just be moving them around with JavaScript.

Thanks, Sage Rat, that’s the conclusion I seem to come to every time I try to learn OpenGL. I found site called SwiftGL that has a tutorial for using OpenGL from Swift. It seemed promising, but as I read it I found that he doesn’t even use the native Mac windowing, but rather something called GLFW? So I’m back to thinking it’s way more than I need, and a pretty steep/long learning curve that, for now, I don’t think I have the patience for.

The good news is that I got JMonkeyEngine working, apparently it’s not smart enough to find the JDK that NetBeans uses, I had to manually edit the script. So I’ll try that, and if it, too, ends up being too daunting I’ll try A-Frame next.

Glad to hear you got it working. I would strongly suggest the tutorials, they step you through creating default projects that take care of some stuff for you and then they give nice complete simple working examples, pretty easy.

That’s no longer true. Unity and Unreal Engine are both non-toy engines and have a tiered licensing model that starts at free. Only once revenue reaches a certain point do they take a cut; for early development and just playing around, they don’t cost anything.