summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBastiaan Olij <mux213@gmail.com>2024-06-23 21:28:33 +1000
committerBastiaan Olij <mux213@gmail.com>2024-06-24 10:16:58 +1000
commitab0c974f28f5980fcf5cee15e7c6666c5276775b (patch)
treed656b64c4632d1532422879b318ed378622c95a1
parent04bf7d4cade645a5923cc80d87ac1c6109e2cdfe (diff)
downloadredot-engine-ab0c974f28f5980fcf5cee15e7c6666c5276775b.tar.gz
Fix default collision shape on imported rigidbody
-rw-r--r--editor/import/3d/resource_importer_scene.cpp2
-rw-r--r--editor/import/3d/resource_importer_scene.h24
2 files changed, 23 insertions, 3 deletions
diff --git a/editor/import/3d/resource_importer_scene.cpp b/editor/import/3d/resource_importer_scene.cpp
index 55a7208169..2db3fb1f07 100644
--- a/editor/import/3d/resource_importer_scene.cpp
+++ b/editor/import/3d/resource_importer_scene.cpp
@@ -1959,7 +1959,7 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "generate/physics", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "generate/navmesh", PROPERTY_HINT_ENUM, "Disabled,Mesh + NavMesh,NavMesh Only"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "physics/body_type", PROPERTY_HINT_ENUM, "Static,Dynamic,Area"), 0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "physics/shape_type", PROPERTY_HINT_ENUM, "Decompose Convex,Simple Convex,Trimesh,Box,Sphere,Cylinder,Capsule", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 2));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "physics/shape_type", PROPERTY_HINT_ENUM, "Decompose Convex,Simple Convex,Trimesh,Box,Sphere,Cylinder,Capsule,Automatic", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 7));
r_options->push_back(ImportOption(PropertyInfo(Variant::OBJECT, "physics/physics_material_override", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsMaterial"), Variant()));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "physics/layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), 1));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "physics/mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), 1));
diff --git a/editor/import/3d/resource_importer_scene.h b/editor/import/3d/resource_importer_scene.h
index cd6a725231..f9124ad289 100644
--- a/editor/import/3d/resource_importer_scene.h
+++ b/editor/import/3d/resource_importer_scene.h
@@ -212,6 +212,7 @@ class ResourceImporterScene : public ResourceImporter {
SHAPE_TYPE_SPHERE,
SHAPE_TYPE_CYLINDER,
SHAPE_TYPE_CAPSULE,
+ SHAPE_TYPE_AUTOMATIC,
};
static Error _check_resource_save_paths(const Dictionary &p_data);
@@ -324,11 +325,21 @@ public:
template <typename M>
Vector<Ref<Shape3D>> ResourceImporterScene::get_collision_shapes(const Ref<ImporterMesh> &p_mesh, const M &p_options, float p_applied_root_scale) {
ERR_FAIL_COND_V(p_mesh.is_null(), Vector<Ref<Shape3D>>());
- ShapeType generate_shape_type = SHAPE_TYPE_TRIMESH;
+
+ ShapeType generate_shape_type = SHAPE_TYPE_AUTOMATIC;
if (p_options.has(SNAME("physics/shape_type"))) {
generate_shape_type = (ShapeType)p_options[SNAME("physics/shape_type")].operator int();
}
+ if (generate_shape_type == SHAPE_TYPE_AUTOMATIC) {
+ BodyType body_type = BODY_TYPE_STATIC;
+ if (p_options.has(SNAME("physics/body_type"))) {
+ body_type = (BodyType)p_options[SNAME("physics/body_type")].operator int();
+ }
+
+ generate_shape_type = body_type == BODY_TYPE_DYNAMIC ? SHAPE_TYPE_DECOMPOSE_CONVEX : SHAPE_TYPE_TRIMESH;
+ }
+
if (generate_shape_type == SHAPE_TYPE_DECOMPOSE_CONVEX) {
Ref<MeshConvexDecompositionSettings> decomposition_settings = Ref<MeshConvexDecompositionSettings>();
decomposition_settings.instantiate();
@@ -482,11 +493,20 @@ template <typename M>
Transform3D ResourceImporterScene::get_collision_shapes_transform(const M &p_options) {
Transform3D transform;
- ShapeType generate_shape_type = SHAPE_TYPE_TRIMESH;
+ ShapeType generate_shape_type = SHAPE_TYPE_AUTOMATIC;
if (p_options.has(SNAME("physics/shape_type"))) {
generate_shape_type = (ShapeType)p_options[SNAME("physics/shape_type")].operator int();
}
+ if (generate_shape_type == SHAPE_TYPE_AUTOMATIC) {
+ BodyType body_type = BODY_TYPE_STATIC;
+ if (p_options.has(SNAME("physics/body_type"))) {
+ body_type = (BodyType)p_options[SNAME("physics/body_type")].operator int();
+ }
+
+ generate_shape_type = body_type == BODY_TYPE_DYNAMIC ? SHAPE_TYPE_DECOMPOSE_CONVEX : SHAPE_TYPE_TRIMESH;
+ }
+
if (generate_shape_type == SHAPE_TYPE_BOX ||
generate_shape_type == SHAPE_TYPE_SPHERE ||
generate_shape_type == SHAPE_TYPE_CYLINDER ||