From 172775d4ed4986e7a6592df3060d13e6fe0cefa3 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 7 May 2025 12:10:11 +0500 Subject: [PATCH] Fix constant camera representation update because of the float garbage values Similar issue to 82f25f5 Basically matrix is a little bit different every time you activate drawing even if user made no changes to camera position. My guess is basically all float values stored by Blender somewhere deep as float32 but when you access matrix world, Blender converts them to Python floats (which are float64) and some garbage values introduced along the way creating this noise. --- src/bonsai/bonsai/bim/module/drawing/prop.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/drawing/prop.py b/src/bonsai/bonsai/bim/module/drawing/prop.py index d23f2727b4..3980271c93 100644 --- a/src/bonsai/bonsai/bim/module/drawing/prop.py +++ b/src/bonsai/bonsai/bim/module/drawing/prop.py @@ -610,13 +610,19 @@ class BIMCameraProperties(PropertyGroup): # allowing all camera initialization to stay encapsulated in `create_camera`. camera = self.id_data assert isinstance(camera, bpy.types.Camera) + + # Rounding is necessary to avoid float garbage differences + # forcing unnecessary representation update. + def round_(f: float) -> float: + return round(f, 6) + representation = json.dumps( { - "matrix": [list(x) for x in matrix_world], + "matrix": [[round_(v) for v in row] for row in matrix_world], "raster_x": self.raster_x, "raster_y": self.raster_y, - "ortho_scale": camera.ortho_scale, - "clip_end": camera.clip_end, + "ortho_scale": round_(camera.ortho_scale), + "clip_end": round_(camera.clip_end), } ) if self.representation != representation: