From 1e946fd98e1f7739d43c3c310a23aa4c0b1713f6 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 13 Feb 2025 13:07:29 +1100 Subject: [PATCH] Fix three small but significant typos in previous fixes. BTW @andrej730 that optimisation is awesome. Here's a timeit: import bpy import numpy as np import timeit obj = bpy.context.active_object verts = obj.data.vertices def foreach_get_method(): coords = np.empty(len(verts) * 3, dtype=np.float32) obj.data.vertices.foreach_get("co", coords) coords = coords.reshape(-1, 3) coords = coords.astype("d") coords /= 10 return coords def list_comprehension_method(): coords = [v.co / 10 for v in verts] return coords # Number of times each function will be executed num_runs = 10000 t_listcomp = timeit.timeit(list_comprehension_method, number=num_runs) t_foreach = timeit.timeit(foreach_get_method, number=num_runs) print("foreach method: {:.6f} seconds over {} runs".format(t_foreach, num_runs)) print("List comprehension method: {:.6f} seconds over {} runs".format(t_listcomp, num_runs)) # foreach method: 0.088656 seconds over 10000 runs # List comprehension method: 0.644446 seconds over 10000 runs --- src/bonsai/bonsai/bim/module/geometry/operator.py | 2 +- src/bonsai/bonsai/tool/blender.py | 1 + src/bonsai/bonsai/tool/model.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/geometry/operator.py b/src/bonsai/bonsai/bim/module/geometry/operator.py index e231f878dc..f592c0f98d 100644 --- a/src/bonsai/bonsai/bim/module/geometry/operator.py +++ b/src/bonsai/bonsai/bim/module/geometry/operator.py @@ -113,7 +113,7 @@ class OverrideMeshSeparate(bpy.types.Operator, tool.Ifc.Operator): representation_type = representation.RepresentationType if representation_type in ("Brep", "AdvancedBrep"): item = builder.faceted_brep(verts, faces) - elif representation_type in ("Tessellation"): + elif representation_type == "Tessellation": item = builder.mesh(verts, faces) else: assert False, f"Unexpected representation type: '{representation_type}'." diff --git a/src/bonsai/bonsai/tool/blender.py b/src/bonsai/bonsai/tool/blender.py index f7e997158a..5a73420e25 100644 --- a/src/bonsai/bonsai/tool/blender.py +++ b/src/bonsai/bonsai/tool/blender.py @@ -1150,6 +1150,7 @@ class Blender(bonsai.core.tool.Blender): # It's faster to get them as f and then convert to d # with .astype("d"), if precision is needed. coords = np.empty(len(verts) * 3, dtype="f") + verts.foreach_get("co", coords) coords = coords.reshape(-1, 3) return coords diff --git a/src/bonsai/bonsai/tool/model.py b/src/bonsai/bonsai/tool/model.py index 317e04ee1f..2eb32b68f0 100644 --- a/src/bonsai/bonsai/tool/model.py +++ b/src/bonsai/bonsai/tool/model.py @@ -1750,7 +1750,7 @@ class Model(bonsai.core.tool.Model): else: profile_defs.append(tmp.createIfcArbitraryClosedProfileDef("AREA", None, curve)) - if total_profile_defs := len(profile_defs) == 0: + if (total_profile_defs := len(profile_defs)) == 0: return elif total_profile_defs == 1: profile_def = profile_defs[0]