From 782fb4b438bd1f7c7be21b6ed17641bfc36669ed Mon Sep 17 00:00:00 2001 From: Alex Zastrow Date: Tue, 12 Mar 2024 14:30:33 +0100 Subject: [PATCH] Fix inertia calculation #351 Fixes inertia calculation for meshes with quads that are not selected --- phobos/utils/inertia.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/phobos/utils/inertia.py b/phobos/utils/inertia.py index cdffe8be9..4968f2d31 100644 --- a/phobos/utils/inertia.py +++ b/phobos/utils/inertia.py @@ -126,7 +126,16 @@ def calculateMeshInertia(mass, data, scale=None): vertices = numpy.asarray([numpy.asarray(scale * v.co) for v in data.vertices]) prev_mode = bpy.context.mode bpy.ops.object.mode_set(mode='EDIT') + # store selected vertices + selected_vertices = [v.index for v in data.vertices if v.select] + # select all vertices for conversion + bpy.ops.mesh.select_all(action='SELECT') bpy.ops.mesh.quads_convert_to_tris(quad_method='FIXED') + # reset selected vertices + bpy.ops.mesh.select_all(action='DESELECT') + bpy.ops.object.mode_set(mode='OBJECT') + for i in selected_vertices: + data.vertices[i].select = True bpy.ops.object.mode_set(mode=prev_mode) faces = [[v for v in p.vertices] for p in data.polygons] triangle_normals = numpy.asarray([t.normal for t in data.polygons])