DSchroer / dslcad

DSLCad is a programming language & interpreter for building 3D models.
https://dslcad.com
GNU Lesser General Public License v2.1
467 stars 14 forks source link

.obj exporter? #2

Open MrLeap opened 1 year ago

MrLeap commented 1 year ago

Would be handy to be able to export the meshes as something commonly supported by gamedev engines.

.obj seems suitable to the task, it's a very easy, human readable format. The only format perhaps more ubiquitous is .fbx, which is far less friendly.

.gltf is another good candiate.

Really any of these would open a gateway of silliness.

virtualritz commented 1 year ago

It would be even more handy if the OBJ could also/alternatively contain the (trimmed) NURB surfaces from the b-rep.

Few people today know this but Waveront OBJ is perfectly capable of storing these (scroll down to Free-form curve and surface types).

Among the apps that ingest such OBJs with higher order geometry are Maya and Rhinoceros 3D. The latter together with the procedural Grashopper modeling tool makes for a very interesting combo with DSLCAD.

I wanted to look into adding at least NURBS + trim curves support to tobj anyway.

Generating the .obj data through Maya &| Rhino was the plan but if this comes to DSLCAD I'd prefer that to get some generative regression testing going for NURBS support in tobj. I.e. DSDLCAD→.objtobj.

DSchroer commented 7 months ago

I have moved the export format from stl which is basic to 3mf to try to be forward looking. I think its better to support one format well rather than have a bunch of different formats. Its should be trivial to convert 3mf to obj with a tool like meshlabs.

Closing this for now since multi type export is not something I think the project needs. There are plenty of good converter tools.

virtualritz commented 7 months ago

The point I made in this ticket, was having a way to export NURBS that is easier to implement than STEP.

If you have a B-rep modeling tool, you want to have a way to export data as lossless as possible.

For example, if I want to create CAM tool paths in something like Fusion360, your input data should not be a triangle mesh.

Furthermore, if you mesh a surface, you can create a quad mesh and only use triangles sparsely, e.g. at trimmed edges. This has advantages if you want to further process the mesh to make it an asset in a game or VFX context, e.g. to be rendered as a Catmull-Clark subdivision surface.

AFAIK 3MF only supports triangles.

The whole point of using a B-rep modeler in the first place is moot then if all you can export are triangle meshes. Use a SDF modeler instead. ;)

DSchroer commented 7 months ago

The 3MF format is forward looking and moving to allow volumetric specification. At the moment its likely not very supported but I am not sure if OBJ B-rep is very supported either at this point.

https://github.com/3MFConsortium/spec_volumetric/blob/master/3MF%20Volumetric%20Extension.md

DSchroer commented 7 months ago

What matters most if the development flow. User experience if you prefer that term. B-rep vs SDF should be hidden from the user in a tool like this. It shouldnt matter.

virtualritz commented 7 months ago

I think the misunderstanding comes from the fact that you assume people export from dslcad and then just 3D print.

If I want to use a CNC to mill from a block of metal, plastic or wood, polygon meshes are the worst input geometry.

If you come from a polygon modeler, you'd likely convert to subdivision surfaces or T-spline nets and then convert those to bicubic patches to get higher order geometry to feed into the CAM for the CNC.

But when you come from a B-Rep modeler, like dslcad, that makes no sense. You already have high quality, higher order geometry to start with. Why would you tessellate that into polygon soup, in between? Worse, you can never recover the original shapes from their meshed approximations that way.

So the way to go is to offer OBJ export to trimmed NURBS (low hanging fruit) and then STEP (potentially a lot more work). Check out the truck project for the latter.

To test OBJ files containing NURBS geometry you can use Maya or Rhino3D (both have test versions).

DSchroer commented 6 months ago

@virtualritz from your experience. Would the BREP object file from Opencascade work or is it pretty non standard?

https://dev.opencascade.org/doc/occt-6.7.0/overview/html/occt_brep_format.html

virtualritz commented 6 months ago

STEP is kind of the industry standard for exchange of B-Rep data. It's to B-Rep data what OBJ (still) is to mesh data. The other one is IGES. OpenCascade is product-specific. Just like CATIA or Solidworks formats are. I.e. I wouldn't make supporting them a priority.

As for STEP: hence my suggestion to look at the truck crate, specifically their truck-stepio which in turn is based on ruststep.

That said, I would still support OBJ, both for meshed geometry (especially if the mesher can produce n-gons instead of dicing everything into triangles) and for trimmed NURBS export.

Simply because it is a vety low hanging fruit and the NURBS part is easy to verify via Maya or Rhino3D demo versions. They both read OBJ files containing higher order geometry.

As a user, OBJ export should give me those advantages:

DSchroer commented 6 months ago

Looks like I am in the position where work could start on this. From what I can tell there are no out of the box obj file libraries with free form curve support so it would need to be hand written.

@virtualritz would you be able/willing to help with that development?

DSchroer commented 6 months ago

I suspect we could implement it here: crates/persistence/src/lib.rs

virtualritz commented 6 months ago

I suspect we could implement it here: crates/persistence/src/lib.r

Cool! But maybe change the name of this crate so you can eventuall publish it on crates.io (name clash, AFAICS).

Format specs are in the section Free-form curve/surface attributes here.

I can offer help like so:

Sample Files

These can be inspected to see how a (reasonably) well-formed OBJ containing these geometry types should look like.

I can contact different people for samples if you want to add STEP support, eventually.

Testing

Code Review

I can also look at code but I can't make any promises when or how much.

I just started a new job and as such my spare time has become a scarce resource.

DSchroer commented 6 months ago

Name may change later. Right now its not really intended for publishing. All the crates are pretty connected to dslcad themself.

virtualritz commented 4 months ago

Here are the promised examples from Rhino. Sorry this took so long.

A sphere and some CSG union operation between a sphere and a cube.

Sadly, from the looks of it, Rhino does not export join information to the OBJ.

Maybe we have more luck with Maya data that contains attached (Maya lingo), trimmed surfaces.