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
This commit is contained in:
Dion Moult
2025-02-13 13:07:29 +11:00
parent 79046e2970
commit 1e946fd98e
3 changed files with 3 additions and 2 deletions
@@ -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}'."
+1
View File
@@ -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
+1 -1
View File
@@ -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]