Skip to content

Commit 409a399

Browse files
committed
Merge pull request #77602 from aaronfranke/gltf-import-center-of-mass
Fix center of mass when importing GLTF physics bodies
2 parents 8d79a74 + a98be43 commit 409a399

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

modules/gltf/extensions/physics/gltf_physics_body.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ Ref<GLTFPhysicsBody> GLTFPhysicsBody::from_node(const CollisionObject3D *p_body_
112112
physics_body->linear_velocity = body->get_linear_velocity();
113113
physics_body->angular_velocity = body->get_angular_velocity();
114114
physics_body->inertia = body->get_inertia();
115+
if (body->get_center_of_mass() != Vector3()) {
116+
WARN_PRINT("GLTFPhysicsBody: This rigid body has a center of mass offset from the origin, which will be ignored when exporting to GLTF.");
117+
}
115118
if (cast_to<VehicleBody3D>(p_body_node)) {
116119
physics_body->body_type = "vehicle";
117120
} else {
@@ -140,6 +143,7 @@ CollisionObject3D *GLTFPhysicsBody::to_node() const {
140143
body->set_linear_velocity(linear_velocity);
141144
body->set_angular_velocity(angular_velocity);
142145
body->set_inertia(inertia);
146+
body->set_center_of_mass_mode(RigidBody3D::CENTER_OF_MASS_MODE_CUSTOM);
143147
return body;
144148
}
145149
if (body_type == "rigid") {
@@ -148,6 +152,7 @@ CollisionObject3D *GLTFPhysicsBody::to_node() const {
148152
body->set_linear_velocity(linear_velocity);
149153
body->set_angular_velocity(angular_velocity);
150154
body->set_inertia(inertia);
155+
body->set_center_of_mass_mode(RigidBody3D::CENTER_OF_MASS_MODE_CUSTOM);
151156
return body;
152157
}
153158
if (body_type == "static") {

0 commit comments

Comments
 (0)