Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix merging inertials with mass 0 #357

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion phobos/blender/model/inertia.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,13 @@ def combine_com_3x3(objects):
for obj in objects:
combined_com = combined_com + obj.matrix_local.translation * obj['mass']
combined_mass += obj['mass']
combined_com = combined_com / combined_mass
if combined_mass != 0:
combined_com = combined_com / combined_mass
else:
combined_com = mathutils.Vector((0.0,) * 3)
for obj in objects:
combined_com = combined_com + obj.matrix_local.translation
log(message=f"Inertial {objects[0].name} exported with mass 0")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way you put the else part the combined_com will be somewhere outside the objects. If there is now mass we should take the center of volumes. Therefore the obj.matrix_local.translation should be weighted with the volume off the obj (convex hull if not watertight).

log(" Combined center of mass: " + str(combined_com), 'DEBUG')
return combined_mass, combined_com

Expand Down