Skip to content

Commit

Permalink
Non-BRep Mesh Support (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBarclay authored Mar 21, 2024
2 parents 610f890 + 2b95e4d commit a4f9195
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a4f9195

Please sign in to comment.