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

Center alligning in case of 3mf write #17241

Merged
merged 2 commits into from
Nov 14, 2023
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
3 changes: 1 addition & 2 deletions plugins/3MFReader/ThreeMFReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ def _read(self, file_name: str) -> Union[SceneNode, List[SceneNode]]:
if mesh_data is not None:
extents = mesh_data.getExtents()
if extents is not None:
# We use a different coordinate space, so flip Z and Y
center_vector = Vector(extents.center.x, extents.center.z, extents.center.y)
center_vector = Vector(extents.center.x, extents.center.y, extents.center.z)
casperlamboo marked this conversation as resolved.
Show resolved Hide resolved
transform_matrix.setByTranslation(center_vector)
transform_matrix.multiply(um_node.getLocalTransformation())
um_node.setTransformation(transform_matrix)
Expand Down
12 changes: 10 additions & 2 deletions plugins/3MFWriter/ThreeMFWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,20 @@ def _convertUMNodeToSavitarNode(um_node, transformation=Matrix()):
savitar_node = Savitar.SceneNode()
savitar_node.setName(um_node.getName())

node_matrix = um_node.getLocalTransformation()
node_matrix = Matrix()
mesh_data = um_node.getMeshData()
# compensate for original center position, if object(s) is/are not around its zero position
if mesh_data is not None:
extents = mesh_data.getExtents()
if extents is not None:
# We use a different coordinate space while writing, so flip Z and Y
center_vector = Vector(extents.center.x, extents.center.z, extents.center.y)
node_matrix.setByTranslation(center_vector)
node_matrix.multiply(um_node.getLocalTransformation())

matrix_string = ThreeMFWriter._convertMatrixToString(node_matrix.preMultiply(transformation))

savitar_node.setTransformation(matrix_string)
mesh_data = um_node.getMeshData()
if mesh_data is not None:
savitar_node.getMeshData().setVerticesFromBytes(mesh_data.getVerticesAsByteArray())
indices_array = mesh_data.getIndicesAsByteArray()
Expand Down
Loading