danini-the-panini / mittsu

3D Graphics Library for Ruby.
https://github.com/danini-the-panini/mittsu
MIT License
508 stars 33 forks source link

3MF exporter #120

Open Floppy opened 6 months ago

Floppy commented 6 months ago

My current need for Mittsu is to be able to convert files into more efficient forms, as a feature for https://manyfold.app. So, I'm working on a 3MF exporter. This is NOT an existing THREE.js feature, so you may want it to be in a separate addon gem - up to you.

It adds two dependencies; builder which was already a transitive dependency from minitest, and rubyzip which is completely new. It also uses rexml in dev for testing the output.

THREE.js annoyingly uses parse for exporting which makes no sense; I've rename it export and made parse an alias for consistency with the original.

Floppy commented 6 months ago

Getting there with this; it now generates valid 3MF files. Just working on getting the child object traversal and relationships right, because at the moment running the example produces a version of male02.obj without various parts, which is... suboptimal :)

Floppy commented 6 months ago

OK, the root cause of my problem is in the OBJ loader, rather than the 3MF output, and I've filed it for a rainy day as https://github.com/danini-the-panini/mittsu/issues/123.

I'll update the converter example to use a simpler model, and then this should be done, at least for an initial basic form.

Floppy commented 6 months ago

OK, working 3MF export is ready! There are probably plenty of edge cases to find, but as an MVP, I'm happy with it.

Screenshot 2024-02-26 at 14 56 05

Floppy commented 6 months ago

This is also green now, I was missing a gem dependency for rexml.

Floppy commented 5 months ago

@danini-the-panini it's just occurred to me that while I'm writing mesh analysis code in https://github.com/manyfold3d/manyfold/pull/1981/files#diff-b33a35020b14550d6b315e9628edd985f88159a26555ab2f4027358e592ebfab, this is actually required to check that meshes are valid for 3MF files before exporting. Would you like me to PR that stuff into the mittsu core? It checks that meshes are manifold, and that they aren't inside out.

danini-the-panini commented 5 months ago

As in, generic manifold checks for all meshes? I'm not sure that's necessary, since inside out meshes are useful in some cases, and are still valid in mittsu

Floppy commented 5 months ago

Yeah, that's what I was thinking, it's probably too specific as those things are totally valid unless you're trying to bring things into the real world. I wonder if that has similar implications for this PR, because it currently could produce invalid 3MF files.

Floppy commented 5 months ago

What with 3mf being non-threejs functionality, that might be another argument that this should be in a separate extension gem, not core.

danini-the-panini commented 5 months ago

No i think it's fine in Core, at least for now