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.
This commit is contained in:
Andrej730
2025-05-07 12:10:11 +05:00
parent d539cad1c2
commit 172775d4ed
+9 -3
View File
@@ -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: