export wavefront obj file: support multi-materials in a window object (arch)

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Nocturnial

export wavefront obj file: support multi-materials in a window object (arch)

Post by Nocturnial »

I know it might be too premature but in the sticky post in the forum it said to post what I'm planning to do before I submit code. I'll probably use the wrong terminology because I'm new to this, feel free to correct me.

At the moment you can export your project as a wavefront obj file and import it to, for example, blender. The python script at the moment doesn't recognize multi-materials when applied to windows and everything gets exported as a single object.

I did some experiments in the python console to figure out how the window object was stored and think I can find the shapes of the individual components (frames, panels, etc..). I was thinking of implementing something along the line of: "If there's a multi-material and the object is a window => export the child shapes separately and find the material in the multi-material".

If that works maybe I can extend it to when there are hinges defined, freecad could then also optionally export it as a separate object/group in the obj format. In that case there are still several manual steps involved. When importing it in your 3d program, you need to parent that (sub)object to an empty axis node and then rotate it if you needed that in an animation. I'm not sure about the usefulness of this feature, but at that point we already have the code to split the window object apart if needed.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: export wavefront obj file: support multi-materials in a window object (arch)

Post by vocx »

Nocturnial wrote: Thu Aug 15, 2019 2:32 pm At the moment you can export your project as a wavefront obj file and import it to, for example, blender. The python script at the moment doesn't recognize multi-materials when applied to windows and everything gets exported as a single object.
As someone who once did exactly that, FreeCAD to Blender through OBJ, I think any improvements that you can do are very welcome.

See Tutorial Render with Blender. At the end of that Tutorial there is mention of the Blender plugin to import FreeCAD files directly, that is, without using OBJ as an intermediate format.

If your objective is to improve Blender-FreeCAD integration, probably your efforts should be made on improving that plugin. If you just want to improve the OBJ importer-exporter of FreeCAD, then by all means go ahead and improve Arch's importOBJ.py.
I did some experiments in the python console to figure out how the window object was stored...
I suggest you ask in the Draft, Arch, BIM subforum as that is where people usually discuss Arch topics.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: export wavefront obj file: support multi-materials in a window object (arch)

Post by yorik »

Nocturnial wrote: Thu Aug 15, 2019 2:32 pm I was thinking of implementing something along the line of: "If there's a multi-material and the object is a window => export the child shapes separately and find the material in the multi-material".

If that works maybe I can extend it to when there are hinges defined
Looks like a good plan! Indeed any bettering there is welcome. I'm curious if obj doesn't support having more than one material per object? If not, then indeed your proposed way seems the best way to go.

About hinges, it might not be too hard either, you could just grab the solids that are under a same hinge, then place their blender pivot point at the midpoint of the hinge... That would make them pretty easy to open in Blender...

But indeed if your only purpose is Blender, the FreeCAD-to-Blender importer might be more interesting to you..
Post Reply