Skip to content

Commit

Permalink
Merge pull request #356 from AlpenAalAlex/Issue351-Create-Inertials-f…
Browse files Browse the repository at this point in the history
…ails-if-not-all-vertices-are-selected

Fix inertia calculation
  • Loading branch information
hwiedPro authored May 16, 2024
2 parents 0ff405b + 782fb4b commit d27a70b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions phobos/utils/inertia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit d27a70b

Please sign in to comment.