From a98be434b783d550af336483400894090c95c352 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Fri, 26 May 2023 16:15:39 -0500 Subject: [PATCH] Fix center of mass when importing GLTF physics bodies --- modules/gltf/extensions/physics/gltf_physics_body.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/gltf/extensions/physics/gltf_physics_body.cpp b/modules/gltf/extensions/physics/gltf_physics_body.cpp index b7fb23d37ff..a187fc53a16 100644 --- a/modules/gltf/extensions/physics/gltf_physics_body.cpp +++ b/modules/gltf/extensions/physics/gltf_physics_body.cpp @@ -112,6 +112,9 @@ Ref GLTFPhysicsBody::from_node(const CollisionObject3D *p_body_ physics_body->linear_velocity = body->get_linear_velocity(); physics_body->angular_velocity = body->get_angular_velocity(); physics_body->inertia = body->get_inertia(); + if (body->get_center_of_mass() != Vector3()) { + WARN_PRINT("GLTFPhysicsBody: This rigid body has a center of mass offset from the origin, which will be ignored when exporting to GLTF."); + } if (cast_to(p_body_node)) { physics_body->body_type = "vehicle"; } else { @@ -140,6 +143,7 @@ CollisionObject3D *GLTFPhysicsBody::to_node() const { body->set_linear_velocity(linear_velocity); body->set_angular_velocity(angular_velocity); body->set_inertia(inertia); + body->set_center_of_mass_mode(RigidBody3D::CENTER_OF_MASS_MODE_CUSTOM); return body; } if (body_type == "rigid") { @@ -148,6 +152,7 @@ CollisionObject3D *GLTFPhysicsBody::to_node() const { body->set_linear_velocity(linear_velocity); body->set_angular_velocity(angular_velocity); body->set_inertia(inertia); + body->set_center_of_mass_mode(RigidBody3D::CENTER_OF_MASS_MODE_CUSTOM); return body; } if (body_type == "static") {