From a98741e372e9a5b288d8b0d4ab0f4cb71c943349 Mon Sep 17 00:00:00 2001 From: Gonzalo Casas Date: Fri, 28 Aug 2026 15:18:22 +0200 Subject: [PATCH] Speed up Rhino transformation conversions ~11x --- CHANGELOG.md | 1 + src/compas_rhino/conversions/transformations.py | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90aadc97f34f..ec62de4c1632 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `compas_rhino.uninstall` will try to remove compas packages from all possible install locations. * Changed `angle_vectors_projected` to raise `ValueError` when an input vector is parallel to projection normal. * Changed `angle_vectors` to raise `ValueError` when one of the input vectors is a zero-length vector instead of returning 0. +* Changed `transformation_to_rhino` and `transformation_matrix_to_rhino` to assign the matrix components directly to the fields of `Rhino.Geometry.Transform` instead of looping over its indexer. About 11x faster per conversion, noticable when used inside an animation loop. ### Removed diff --git a/src/compas_rhino/conversions/transformations.py b/src/compas_rhino/conversions/transformations.py index 089fe85c7b90..0235af0ce851 100644 --- a/src/compas_rhino/conversions/transformations.py +++ b/src/compas_rhino/conversions/transformations.py @@ -18,11 +18,7 @@ def transformation_to_rhino(transformation): :rhino:`Rhino.Geometry.Transform` """ - transform = Rhino.Geometry.Transform(1.0) - for i in range(0, 4): - for j in range(0, 4): - transform[i, j] = transformation[i, j] - return transform + return transformation_matrix_to_rhino(transformation.matrix) def transformation_matrix_to_rhino(matrix): @@ -38,8 +34,10 @@ def transformation_matrix_to_rhino(matrix): :rhino:`Rhino.Geometry.Transform` """ - transform = Rhino.Geometry.Transform(1.0) - for i in range(0, 4): - for j in range(0, 4): - transform[i, j] = matrix[i][j] + row_0, row_1, row_2, row_3 = matrix + transform = Rhino.Geometry.Transform.Identity + transform.M00, transform.M01, transform.M02, transform.M03 = row_0 + transform.M10, transform.M11, transform.M12, transform.M13 = row_1 + transform.M20, transform.M21, transform.M22, transform.M23 = row_2 + transform.M30, transform.M31, transform.M32, transform.M33 = row_3 return transform