mirror of
https://github.com/Relintai/mesh_data_resource.git
synced 2024-11-14 10:17:26 +01:00
Added automatically approximated simple shape collider generation to the importers. (They don't have offset support yet. Soon.)
This commit is contained in:
parent
f06da26b6b
commit
fbf96617e3
@ -24,7 +24,7 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include "core/version.h"
|
#include "core/version.h"
|
||||||
|
|
||||||
const String MeshDataResource::BINDING_STRING_COLLIDER_TYPE = "None,Trimesh Collision Shape,Single Convex Collision Shape,Multiple Convex Collision Shapes";
|
const String MeshDataResource::BINDING_STRING_COLLIDER_TYPE = "None,Trimesh Collision Shape,Single Convex Collision Shape,Multiple Convex Collision Shapes,Approximated Box,Approximated Capsule,Approximated Cylinder,Approximated Sphere";
|
||||||
|
|
||||||
Array MeshDataResource::get_array() {
|
Array MeshDataResource::get_array() {
|
||||||
return _arrays;
|
return _arrays;
|
||||||
|
@ -41,6 +41,10 @@ public:
|
|||||||
COLLIDER_TYPE_TRIMESH_COLLISION_SHAPE,
|
COLLIDER_TYPE_TRIMESH_COLLISION_SHAPE,
|
||||||
COLLIDER_TYPE_SINGLE_CONVEX_COLLISION_SHAPE,
|
COLLIDER_TYPE_SINGLE_CONVEX_COLLISION_SHAPE,
|
||||||
COLLIDER_TYPE_MULTIPLE_CONVEX_COLLISION_SHAPES,
|
COLLIDER_TYPE_MULTIPLE_CONVEX_COLLISION_SHAPES,
|
||||||
|
COLLIDER_TYPE_APPROXIMATED_BOX,
|
||||||
|
COLLIDER_TYPE_APPROXIMATED_CAPSULE,
|
||||||
|
COLLIDER_TYPE_APPROXIMATED_CYLINDER,
|
||||||
|
COLLIDER_TYPE_APPROXIMATED_SPHERE,
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -138,6 +138,64 @@ Error EditorImportColladaMdr::import(const String &p_source_file, const String &
|
|||||||
}
|
}
|
||||||
|
|
||||||
mdr->set_collision_shapes(shapes);
|
mdr->set_collision_shapes(shapes);
|
||||||
|
} else if (collider_type == MeshDataResource::COLLIDER_TYPE_APPROXIMATED_BOX) {
|
||||||
|
Ref<ArrayMesh> m;
|
||||||
|
m.instance();
|
||||||
|
m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, mdr->get_array());
|
||||||
|
|
||||||
|
Ref<BoxShape> shape;
|
||||||
|
shape.instance();
|
||||||
|
|
||||||
|
AABB aabb = m->get_aabb();
|
||||||
|
Vector3 size = aabb.get_size();
|
||||||
|
|
||||||
|
shape->set_extents(size * 0.5);
|
||||||
|
|
||||||
|
mdr->add_collision_shape(shape);
|
||||||
|
} else if (collider_type == MeshDataResource::COLLIDER_TYPE_APPROXIMATED_CAPSULE) {
|
||||||
|
Ref<ArrayMesh> m;
|
||||||
|
m.instance();
|
||||||
|
m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, mdr->get_array());
|
||||||
|
|
||||||
|
Ref<CapsuleShape> shape;
|
||||||
|
shape.instance();
|
||||||
|
|
||||||
|
AABB aabb = m->get_aabb();
|
||||||
|
Vector3 size = aabb.get_size();
|
||||||
|
|
||||||
|
shape->set_height(size.y * 0.5);
|
||||||
|
shape->set_radius(MIN(size.x, size.z) * 0.5);
|
||||||
|
|
||||||
|
mdr->add_collision_shape(shape);
|
||||||
|
} else if (collider_type == MeshDataResource::COLLIDER_TYPE_APPROXIMATED_CYLINDER) {
|
||||||
|
Ref<ArrayMesh> m;
|
||||||
|
m.instance();
|
||||||
|
m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, mdr->get_array());
|
||||||
|
|
||||||
|
Ref<CylinderShape> shape;
|
||||||
|
shape.instance();
|
||||||
|
|
||||||
|
AABB aabb = m->get_aabb();
|
||||||
|
Vector3 size = aabb.get_size();
|
||||||
|
|
||||||
|
shape->set_height(size.y * 0.5);
|
||||||
|
shape->set_radius(MIN(size.x, size.z) * 0.5);
|
||||||
|
|
||||||
|
mdr->add_collision_shape(shape);
|
||||||
|
} else if (collider_type == MeshDataResource::COLLIDER_TYPE_APPROXIMATED_SPHERE) {
|
||||||
|
Ref<ArrayMesh> m;
|
||||||
|
m.instance();
|
||||||
|
m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, mdr->get_array());
|
||||||
|
|
||||||
|
Ref<SphereShape> shape;
|
||||||
|
shape.instance();
|
||||||
|
|
||||||
|
AABB aabb = m->get_aabb();
|
||||||
|
Vector3 size = aabb.get_size();
|
||||||
|
|
||||||
|
shape->set_radius(MIN(size.x, MIN(size.y, size.z)) * 0.5);
|
||||||
|
|
||||||
|
mdr->add_collision_shape(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
n->queue_delete();
|
n->queue_delete();
|
||||||
|
@ -139,6 +139,64 @@ Error EditorImportGLTFMdr::import(const String &p_source_file, const String &p_s
|
|||||||
}
|
}
|
||||||
|
|
||||||
mdr->set_collision_shapes(shapes);
|
mdr->set_collision_shapes(shapes);
|
||||||
|
} else if (collider_type == MeshDataResource::COLLIDER_TYPE_APPROXIMATED_BOX) {
|
||||||
|
Ref<ArrayMesh> m;
|
||||||
|
m.instance();
|
||||||
|
m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, mdr->get_array());
|
||||||
|
|
||||||
|
Ref<BoxShape> shape;
|
||||||
|
shape.instance();
|
||||||
|
|
||||||
|
AABB aabb = m->get_aabb();
|
||||||
|
Vector3 size = aabb.get_size();
|
||||||
|
|
||||||
|
shape->set_extents(size * 0.5);
|
||||||
|
|
||||||
|
mdr->add_collision_shape(shape);
|
||||||
|
} else if (collider_type == MeshDataResource::COLLIDER_TYPE_APPROXIMATED_CAPSULE) {
|
||||||
|
Ref<ArrayMesh> m;
|
||||||
|
m.instance();
|
||||||
|
m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, mdr->get_array());
|
||||||
|
|
||||||
|
Ref<CapsuleShape> shape;
|
||||||
|
shape.instance();
|
||||||
|
|
||||||
|
AABB aabb = m->get_aabb();
|
||||||
|
Vector3 size = aabb.get_size();
|
||||||
|
|
||||||
|
shape->set_height(size.y * 0.5);
|
||||||
|
shape->set_radius(MIN(size.x, size.z) * 0.5);
|
||||||
|
|
||||||
|
mdr->add_collision_shape(shape);
|
||||||
|
} else if (collider_type == MeshDataResource::COLLIDER_TYPE_APPROXIMATED_CYLINDER) {
|
||||||
|
Ref<ArrayMesh> m;
|
||||||
|
m.instance();
|
||||||
|
m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, mdr->get_array());
|
||||||
|
|
||||||
|
Ref<CylinderShape> shape;
|
||||||
|
shape.instance();
|
||||||
|
|
||||||
|
AABB aabb = m->get_aabb();
|
||||||
|
Vector3 size = aabb.get_size();
|
||||||
|
|
||||||
|
shape->set_height(size.y * 0.5);
|
||||||
|
shape->set_radius(MIN(size.x, size.z) * 0.5);
|
||||||
|
|
||||||
|
mdr->add_collision_shape(shape);
|
||||||
|
} else if (collider_type == MeshDataResource::COLLIDER_TYPE_APPROXIMATED_SPHERE) {
|
||||||
|
Ref<ArrayMesh> m;
|
||||||
|
m.instance();
|
||||||
|
m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, mdr->get_array());
|
||||||
|
|
||||||
|
Ref<SphereShape> shape;
|
||||||
|
shape.instance();
|
||||||
|
|
||||||
|
AABB aabb = m->get_aabb();
|
||||||
|
Vector3 size = aabb.get_size();
|
||||||
|
|
||||||
|
shape->set_radius(MIN(size.x, MIN(size.y, size.z)) * 0.5);
|
||||||
|
|
||||||
|
mdr->add_collision_shape(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
n->queue_delete();
|
n->queue_delete();
|
||||||
|
Loading…
Reference in New Issue
Block a user