Skip to content

Commit 25bc3b3

Browse files
committed
scene reformatting
1 parent f0d52f8 commit 25bc3b3

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

trimesh/scene/scene.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,10 @@ def scaled(self, scale):
697697
A copy of the current scene but scaled
698698
"""
699699
scale = float(scale)
700-
scale_matrix = np.eye(4) * scale
700+
# matrix for 2D scaling
701+
scale_2D = np.eye(3) * scale
702+
# matrix for 3D scaling
703+
scale_3D = np.eye(4) * scale
701704

702705
# preallocate transforms and geometries
703706
nodes = self.graph.nodes_geometry
@@ -710,27 +713,30 @@ def scaled(self, scale):
710713

711714
# result is a copy
712715
result = self.copy()
716+
# remove all existing transforms
713717
result.graph.clear()
714718

715719
for group in grouping.group(geometries):
720+
# hashable reference to self.geometry
716721
geometry = geometries[group[0]]
722+
# original transform from world to geometry
717723
original = transforms[group[0]]
718-
new_geom = np.dot(scale_matrix, original)
724+
# transform for geometry
725+
new_geom = np.dot(scale_3D, original)
719726

720727
if result.geometry[geometry].vertices.shape[1] == 2:
721728
# if our scene is 2D only scale in 2D
722-
result.geometry[geometry].apply_transform(np.eye(3) * scale)
729+
result.geometry[geometry].apply_transform(scale_2D)
723730
else:
724731
# otherwise apply the full transform
725732
result.geometry[geometry].apply_transform(new_geom)
726733

727-
for node, t in zip(self.graph.nodes_geometry[group],
734+
for node, T in zip(self.graph.nodes_geometry[group],
728735
transforms[group]):
729736
# generate the new transforms
730737
transform = util.multi_dot(
731-
[scale_matrix,
732-
t,
733-
np.linalg.inv(new_geom)])
738+
[scale_3D, T, np.linalg.inv(new_geom)])
739+
# apply scale to translation
734740
transform[:3, 3] *= scale
735741
# update scene with new transforms
736742
result.graph.update(frame_to=node,

trimesh/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.35.20'
1+
__version__ = '2.35.21'

0 commit comments

Comments
 (0)