Wavefront OBJ exporter

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
vejmarie
Posts: 713
Joined: Mon Jan 04, 2016 4:52 pm
Location: Somewhere between France, USA and Taiwan
Contact:

Re: Wavefront OBJ exporter

Post by vejmarie »

Looks like that getGlobalPlacement is going to make it ;)
Nocturnial

Re: Wavefront OBJ exporter

Post by Nocturnial »

vocx wrote: Sun Oct 06, 2019 4:19 am By the way, did you do anything else with the Wavefront OBJ exporter? Or did you decide to focus on the Render workbench instead?
I'm still working on the wavefront exporter, but at the moment development is blocked pending a decision. This is not a criticism because it's better to delay and evaluate than to accept whatever.

After that, I took parts of the exporter code I wrote (which weren't in dispute) and reused them in the renderer workbench (multimaterial specifically). When there's a resolution, I'll either integrate the fixes and enhancements for (multi-)materials I wrote for the render wb back into the wavefront exporter. Or maybe argue for a function which returns a list of (material, shape/mesh) instead of duplicating this code across exporters, render workbench, archtexture,... I don't know if the latter is even a good option.

What I'm trying to say is I'm working on both because there's duplicate code, but I'm not quite sure where to put it so it could be shared and what would be a good api.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Wavefront OBJ exporter

Post by vocx »

Nocturnial wrote: Mon Oct 07, 2019 2:58 pm ...
What I'm trying to say is I'm working on both because there's duplicate code, but I'm not quite sure where to put it so it could be shared and what would be a good api.
It sounds to me that it could be in importOBJ.py in the Arch Workbench. Since this is a basic workbench, you guarantee that is available. Meanwhile, Render and ArchTexture can use it, once they are installed from the Addon Manager.
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
vejmarie
Posts: 713
Joined: Mon Jan 04, 2016 4:52 pm
Location: Somewhere between France, USA and Taiwan
Contact:

Re: Wavefront OBJ exporter

Post by vejmarie »

vocx wrote: Mon Oct 07, 2019 3:41 pm
Nocturnial wrote: Mon Oct 07, 2019 2:58 pm ...
What I'm trying to say is I'm working on both because there's duplicate code, but I'm not quite sure where to put it so it could be shared and what would be a good api.
It sounds to me that it could be in importOBJ.py in the Arch Workbench. Since this is a basic workbench, you guarantee that is available. Meanwhile, Render and ArchTexture can use it, once they are installed from the Addon Manager.
I am working on this part of the code, and I agree this is where we shall update, it is coming straight with FreeCAD :)
Nocturnial

Re: Wavefront OBJ exporter

Post by Nocturnial »

vejmarie wrote: Mon Oct 07, 2019 4:52 pm
vocx wrote: Mon Oct 07, 2019 3:41 pm It sounds to me that it could be in importOBJ.py in the Arch Workbench. Since this is a basic workbench, you guarantee that is available. Meanwhile, Render and ArchTexture can use it, once they are installed from the Addon Manager.
I am working on this part of the code, and I agree this is where we shall update, it is coming straight with FreeCAD :)
Sorry to ruin things..
The reason I know where to get the normals is because I read the c++ code to export wavefront objects. That's one of the things I'm talking about when I say there's code duplication. The c++ code exports one mesh at a time. While we want to export an entire scene.

The c++ code can also export ply files which I need for the render wb. But it exports them by naming a field "face_index" instead of "face_indices" or something similar. So I've (re)written a short ply exporter in python.

The question is whether we completely drop the c++ implementation for a python implementation or add customization options to the c++ exporter?
User avatar
vejmarie
Posts: 713
Joined: Mon Jan 04, 2016 4:52 pm
Location: Somewhere between France, USA and Taiwan
Contact:

Re: Wavefront OBJ exporter

Post by vejmarie »

Do not worry you do not ruin anything, I am a big C++ fan. I was looking for a quick OBJ exporter for an internal need ;). I got my stuff working now and will push the code on top of Yorik one (everything is in Python and I can export a global scene, mesh by mesh using the Absolute coordinate (getGlobalPlacement) and it works like a charm. This is still an enhancement against Yorik implementation which do not display anything currently as it doesn't contain the normals. I have implemented that too based on the discussion we just had into that thread.
As soon as your implementation will be ready I will be switching. I still need to have all part generating a dedicated mesh, as my goal is to allow my users to comment assemblies on per part bases.
User avatar
vejmarie
Posts: 713
Joined: Mon Jan 04, 2016 4:52 pm
Location: Somewhere between France, USA and Taiwan
Contact:

Re: Wavefront OBJ exporter

Post by vejmarie »

Just posted my code through PR #2593. It is improving current implementation into Arch
Last edited by Kunda1 on Tue Oct 08, 2019 6:46 pm, edited 1 time in total.
Reason: created hyperlink for convenience
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Wavefront OBJ exporter

Post by yorik »

Awesome! Merged!
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Wavefront OBJ exporter

Post by Kunda1 »

vejmarie wrote: Mon Oct 07, 2019 6:42 pm Just posted my code through PR #2593. It is improving current implementation into Arch
Nice!
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Wavefront OBJ exporter

Post by sgrogan »

vejmarie wrote: Mon Oct 07, 2019 6:42 pm Just posted my code through PR #2593. It is improving current implementation into Arch
Very minor issue, I get a python syntax error with self tests for ImportOBJ.py lines 76,77,82,83
It looks OK on git hub https://github.com/FreeCAD/FreeCAD/blob ... OBJ.py#L76
The referenced lines are tabs not spaces locally, is this something with my git settings, I haven't seen this before?
I can see and fix the problem locally with Notepad++
syntax.PNG
syntax.PNG (36.06 KiB) Viewed 1313 times
Pasteing the same in code tags fixes it?

Code: Select all

    if isinstance(shape,Part.Shape):
        for e in shape.Edges:
            try:
                if not isinstance(e.Curve,Part.LineSegment):
                    if not curves:
			myshape = obj.Shape.copy(False)
			myshape.Placement=obj.getGlobalPlacement()
                        mesh=MeshPart.meshFromShape(Shape=myshape, LinearDeflection=0.1, AngularDeflection=0.7, Relative=True)
                        FreeCAD.Console.PrintWarning(translate("Arch","Found a shape containing curves, triangulating")+"\n")
                        break
            except: # unimplemented curve type
		myshape = obj.Shape.copy(False)
		myshape.Placement=obj.getGlobalPlacement()
                mesh=MeshPart.meshFromShape(Shape=myshape, LinearDeflection=0.1, AngularDeflection=0.7, Relative=True)
                FreeCAD.Console.PrintWarning(translate("Arch","Found a shape containing curves, triangulating")+"\n")
                break
"fight the good fight"
Post Reply