Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-BRep Mesh Support #969

Merged
merged 4 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading