Ghostkeeper / Blender3mfFormat

Blender add-on to import/export 3MF files
GNU General Public License v2.0
172 stars 20 forks source link

Mesh not importing #69

Open YoakeNoTenshi opened 4 weeks ago

YoakeNoTenshi commented 4 weeks ago

Importing some 3mf files results in objects without any mesh. The file was generated with Bambu Studio.

Blender 4.0 / 4.1 File I was trying to import: https://makerworld.com/en/models/20200#profileId-20736 image image image

YoakeNoTenshi commented 3 weeks ago

Fix proposed in this PR: https://github.com/Ghostkeeper/Blender3mfFormat/pull/70

Ghostkeeper commented 2 weeks ago

Thank you for investigating that so thoroughly!

The 3MF specification requires that object IDs are defined before they are used: https://github.com/3MFConsortium/spec_core/blob/1.2.3/3MF%20Core%20Specification.md#34-model . In that case, the current code would work. The spec doesn't say anything about that the object IDs are also defined in the same file as where they are used, though if it needs to be defined before used this could be implied. I could find nothing about whether IDs need to be unique to the document or to the whole 3MF file.

This extension has the philosophy that it should repair files if they are malformed instead of refuse to load them, so it'd be good to make the extension resilient to objects being defined out-of-order and your fix is good.

Before merging though, I'd like to investigate a bit more how it would work if there are duplicate object IDs in different .model files. If this is allowed by the spec, this fix could break well-formed 3MF files that use duplicate object IDs across documents (it would select an arbitrary object with that ID instead of the object from the same file). Maybe we'd have to make it "prefer" IDs from the same file, but still load IDs from different files if the ID is not in the current file. If the spec doesn't allow duplicate IDs, the proposed fix is safe and should be merged. Then it would be nice if the extension logs a warning about duplicate IDs if they are used.

I have to get out now, but I'll get back to you on this. Looks good so far at least.

Ghostkeeper commented 2 weeks ago

I found that indeed the spec requires that IDs are unique in the "3D model": https://github.com/3MFConsortium/spec_core/blob/1.2.3/3MF%20Core%20Specification.md#34-model , and that a 3D model is contained in a single XML document in the archive.

So I think we have to extend this solution so that it prefers IDs referenced from the same document. This will allow correctly-formed 3MF files to be loaded correctly, if they use the same resource IDs across different documents, yet still allow incorrectly-formed 3MF files to be loaded as they likely intended. I'll help guide you towards a reliable implementation in the PR.

YoakeNoTenshi commented 2 weeks ago

Hey there,

I just wanted to say thank you for a very well written plugin. It saved a lot of time for a project I'm working on :)

If you have a clear idea how to implement your solution then feel free to close my PR, no hard feelings!

Ghostkeeper commented 2 weeks ago

I'll use your PR, but extend it a bit so that it prefers resources from the current file :) It's a good start.

(But more likely tomorrow or next week if I can find some time.)

vijaiaeroastro commented 1 week ago

@Ghostkeeper My name is Vijai, and I am one of the developers of lib3mf. We recently released official Python bindings for lib3mf that adhere to the 3MF Consortium's specification. We also have a collection of useful Python examples available here. You have done a great job in making the 3MF format work within the Blender ecosystem. We would be very interested in collaborating with you to enhance Blender's 3MF support. If you prefer to communicate via email, you can contact me at github@kaditham.meshing.engineer.