diff --git a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Components.py b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Components.py index 6f0d554756..9f50ffaea6 100644 --- a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Components.py +++ b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Components.py @@ -43,14 +43,18 @@ def _MapAllComponents( else: partDefinition.dynamic = True - for body in component.bRepBodies: + def processBody(body: adsk.fusion.BRepBody | adsk.fusion.MeshBody): if progressDialog.wasCancelled(): raise RuntimeError("User canceled export") if body.isLightBulbOn: part_body = partDefinition.bodies.add() fill_info(part_body, body) part_body.part = comp_ref - _ParseBRep(body, options, part_body.triangle_mesh) + + if isinstance(body, adsk.fusion.BRepBody): + _ParseBRep(body, options, part_body.triangle_mesh) + else: + _ParseMesh(body, options, part_body.triangle_mesh) appearance_key = "{}_{}".format(body.appearance.name, body.appearance.id) # this should be appearance @@ -59,6 +63,12 @@ def _MapAllComponents( else: part_body.appearance_override = "default" + for body in component.bRepBodies: + processBody(body) + + for body in component.meshBodies: + processBody(body) + @TimeThis def _ParseComponentRoot( @@ -199,6 +209,29 @@ def _ParseBRep( ) +def _ParseMesh( + meshBody: adsk.fusion.MeshBody, + options: ParseOptions, + trimesh: assembly_pb2.TriangleMesh, +) -> any: + try: + mesh = meshBody.displayMesh + + fill_info(trimesh, meshBody) + trimesh.has_volume = True + + plainmesh_out = trimesh.mesh + + plainmesh_out.verts.extend(mesh.nodeCoordinatesAsFloat) + plainmesh_out.normals.extend(mesh.normalVectorsAsFloat) + plainmesh_out.indices.extend(mesh.nodeIndices) + plainmesh_out.uv.extend(mesh.textureCoordinatesAsFloat) + except: + logging.getLogger("{INTERNAL_ID}.Parser.BrepBody").error( + "Failed:\n{}".format(traceback.format_exc()) + ) + + def _MapRigidGroups( rootComponent: adsk.fusion.Component, joints: joint_pb2.Joints ) -> None: diff --git a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Parser.py b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Parser.py index 0676932f5c..bf3cae59a7 100644 --- a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Parser.py +++ b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Parser.py @@ -166,6 +166,12 @@ def export(self) -> bool: path = pathlib.Path(self.parseOptions.fileLocation).parent path.mkdir(parents=True, exist_ok=True) + ### Print out assembly as JSON + # miraJson = MessageToJson(assembly_out) + # miraJsonFile = open(f'', 'wb') + # miraJsonFile.write(str.encode(miraJson)) + # miraJsonFile.close() + if self.parseOptions.compress: self.logger.debug("Compressing file") with gzip.open(self.parseOptions.fileLocation, "wb", 9) as f: