If possible: how to get 3D printable CAD data from GDscript? If no standard way: any ideas or recommendations?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By toblin

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,

:bust_in_silhouette: Reply From: Magso

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.

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.

toblin | 2020-02-23 08:19

:bust_in_silhouette: Reply From: wombatstampede

Currently, Godot has no exporter for 3D models/meshes.
There’s a project for that but that might be more complex than your requirements:

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)

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: