0 votes

Hi forum! This is my first post.

I'm going to develop an evolutionary algorithm to design 3D shapes for 3D printing. With the algorithm I want a simpler user interface that allows the user to act as a selection mechanism. Doing so will require a lot of behind-the-scenes processing that will be easiest to develop using 3D visualizations.

After doing a lot of digging online, I have come to think that Godot and GDscript will suit my needs, and I also consider it a skill worth having for the future. I'm familiar with Python since before, which also means that my learning curve seems infinitesimal. I will get a lot of things for free through the physics and other pre-defined parts of Godot, which will save me a ton of work.

The question I face is the following: for my current endeavor (visualizing an evolutionary algorithm, and having a simple GUI) is there any way that I can export or get mesh data into some kind of CAD format from Gdscript?

I know that e.g. FreeCAD uses python extensively, so it should be possible for me to develop something in Python that will create a usable CAD file. One possible solution could perhaps be to somehow get the GDscript data into Python for further processing. I know that there exists a python bidning for GDscript, but my feeling tells me that it isn't well maintained.

Any ideas, recommendations, or feedback is more than welcome. Feel free to go meta and recommend substantially different courses of action as well (e.g. I should really go for PyOpenGL and Pygames instead, etc).

Best regards,
Tobias

in Engine by (140 points)

2 Answers

+1 vote

GDScript can return a Vector3 array for the mesh vertices using MeshInstance.Mesh.get_faces(). If this array can be copied over using the python binding it should be usable in the algorithm.

by (3,209 points)

That's nice to know where to access the vertices. If indeed that information can be transferred using the binding then that solves the problem.

I've also been thinking that I might be able to print e.g. the vertices into a text file and print the information in a way that python can interpret. This can be considered a plan B.

Thanks for the reply Magso =). I will see if there are any other ideas before closing the topic.

+2 votes

Currently, Godot has no exporter for 3D models/meshes.
There's a project for that but that might be more complex than your requirements:
https://github.com/godotengine/godot/pull/34193

Wavefront OBJ is a documented and simple format to export 3D meshes (OBJ uses text files). That could be implemented in GDScript. My guess is that there are converters that can convert OBJ to some specific 3D printer/tool format.

You can use MeshDataTool to query mesh information in Godot. (As you probably use Surface tool to create meshes)
https://docs.godotengine.org/en/3.2/tutorials/content/procedural_geometry/meshdatatool.html
https://docs.godotengine.org/en/3.2/classes/class_meshdatatool.html

Still, I am a bit unsure if the 3D vertex/faces approach is correct for a 3D printing project. It might be because you don't have to worry about the actual printing resolution/data which will later be derived/interpolated from the 3d data.

Anyway, just in case, there's also a "pixel" approach. You might look here for that:
https://github.com/Zylann/godot_voxel

by (3,252 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.