From 8866a34f22b6f282dced2d40e65442bf4f98186a Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 20 Sep 2024 17:02:51 +1000 Subject: [PATCH] Fix #5408. Use an angular tolerance of 0.1 degrees to determine if something has moved and need resyncing. --- src/bonsai/bonsai/tool/ifc.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/bonsai/bonsai/tool/ifc.py b/src/bonsai/bonsai/tool/ifc.py index 57c81b84cf..de3b6dd735 100644 --- a/src/bonsai/bonsai/tool/ifc.py +++ b/src/bonsai/bonsai/tool/ifc.py @@ -77,12 +77,16 @@ class Ifc(bonsai.core.tool.Ifc): if not obj.BIMObjectProperties.location_checksum: return True # Let's be conservative loc_check = np.frombuffer(eval(obj.BIMObjectProperties.location_checksum)) - rot_check = np.frombuffer(eval(obj.BIMObjectProperties.rotation_checksum)) loc_real = np.array(obj.matrix_world.translation).flatten() - rot_real = np.array(obj.matrix_world.to_3x3()).flatten() - if np.allclose(loc_check, loc_real, atol=1e-4) and np.allclose(rot_check, rot_real, atol=1e-2): - return False - return True + if not np.allclose(loc_check, loc_real, atol=1e-4): # 0.1 mm + return True + rot_check = np.frombuffer(eval(obj.BIMObjectProperties.rotation_checksum)).reshape(3, 3) + rot_real = np.array(obj.matrix_world.to_3x3()) + rot_dot = np.dot(rot_check, rot_real.T) + angle_rad = np.arccos(np.clip((np.trace(rot_dot) - 1) / 2, -1, 1)) + if angle_rad > 0.0017453292519943296: # 0.1 degrees + return True + return False @classmethod def schema(cls) -> ifcopenshell_wrapper.schema_definition: