Arch OBJ: Difference between revisions

From FreeCAD Documentation
(Module to Workbench renaming.)
(Docnav)
Line 7: Line 7:
|[[Arch_JSON|JSON]]
|[[Arch_JSON|JSON]]
|[[Arch_Workbench|Arch Workbench]]
|[[Arch_Workbench|Arch Workbench]]
|IconL=
|IconR=
|IconC=Workbench_Arch.svg
}}
}}


Line 51: Line 54:
* [https://forum.freecadweb.org/viewtopic.php?f=8&t=37452 Convert STEP to Wavefront OBJ with colors of faces]
* [https://forum.freecadweb.org/viewtopic.php?f=8&t=37452 Convert STEP to Wavefront OBJ with colors of faces]


==Tutorials== <!--T:3-->
==Tutorials==

<!--T:3-->
* [[Import_from_STL_or_OBJ|Import from STL or OBJ]]
* [[Import_from_STL_or_OBJ|Import from STL or OBJ]]
* [[Export_to_STL_or_OBJ|Export to STL or OBJ]]
* [[Export_to_STL_or_OBJ|Export to STL or OBJ]]



<!--T:4-->
<!--T:4-->
Line 60: Line 66:
|[[Arch_JSON|JSON]]
|[[Arch_JSON|JSON]]
|[[Arch_Workbench|Arch Workbench]]
|[[Arch_Workbench|Arch Workbench]]
|IconL=
|IconR=
|IconC=Workbench_Arch.svg
}}
}}



Revision as of 15:50, 9 March 2022

Description

Additionally to the standard FreeCAD OBJ exporter, the Arch Workbench features an alternative exporter that exports coplanar faces as whole OBJ faces, instead of triangulating Shape-based objects, like the standard exporter does.

Exporting without GUI

Exporting without the graphical interface is possible from the command line, using the Mesh Workbench exporter only.

In this example, a STEP file is imported, the colors of the Shape are saved, then a mesh is created from it, the colors of the original object are re-applied to the faces of the new mesh, which is then exported to OBJ format. Since this is done with the Mesh Workbench, the result is a triangulated mesh.

import Mesh
import MeshPart
import Import

data = Import.open("example.stp")
shape = data[0][0].Shape
shape_colors = data[0][1]

mesh = MeshPart.meshFromShape(Shape=shape, LinearDeflection=0.1, Segments=True)

face_colors = [(0, 0, 0)] * mesh.CountFacets

for i in range(mesh.countSegments()):
    color = shape_colors[i]
    segm = mesh.getSegment(i)
    for j in segm:
        face_colors[j] = color

mesh.write(Filename="new_example.obj", Material=face_colors, Format="obj")

More information

Tutorials