diff --git a/mesh_data_resource.cpp b/mesh_data_resource.cpp index 9ee27ef..17bbfb0 100644 --- a/mesh_data_resource.cpp +++ b/mesh_data_resource.cpp @@ -64,7 +64,7 @@ Vector MeshDataResource::get_collision_shapes() { r.push_back(_collision_shapes[i].transform); r.push_back(_collision_shapes[i].shape.get_ref_ptr()); #else - r.push_back(_collision_shapes[i].offset); + r.push_back(_collision_shapes[i].transform); r.push_back(_collision_shapes[i].shape); #endif } diff --git a/mesh_data_resource.h b/mesh_data_resource.h index 3cf8ae2..0bcfd52 100644 --- a/mesh_data_resource.h +++ b/mesh_data_resource.h @@ -25,8 +25,16 @@ SOFTWARE. #include "core/array.h" #include "core/resource.h" +#include "core/version.h" #include "scene/resources/mesh.h" + +#if VERSION_MAJOR < 4 #include "scene/resources/shape.h" +#else +#include "scene/resources/shape_3d.h" + +#define Shape Shape3D +#endif class MeshDataResource : public Resource { GDCLASS(MeshDataResource, Resource); diff --git a/nodes/mesh_data_instance.cpp b/nodes/mesh_data_instance.cpp index 8fe6202..4432832 100644 --- a/nodes/mesh_data_instance.cpp +++ b/nodes/mesh_data_instance.cpp @@ -1,5 +1,7 @@ #include "mesh_data_instance.h" +#include "core/version.h" + #if TEXTURE_PACKER_PRESENT #include "../../texture_packer/texture_resource/packer_image_resource.h" #endif @@ -69,10 +71,13 @@ void MeshDataInstance::setup_mesh() { if (!mesh.is_valid()) { mesh.instance(); } - +#if VERSION_MAJOR < 4 for (int i = 0; i < mesh->get_surface_count(); ++i) { mesh->surface_remove(i); } +#else + mesh->clear_surfaces(); +#endif mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arr); @@ -107,7 +112,11 @@ void MeshDataInstance::setup_material_texture() { Ref tex; tex.instance(); +#if VERSION_MAJOR < 4 tex->create_from_image(i, 0); +#else + tex->create_from_image(i); +#endif if (sm.is_valid()) { sm->set_texture(SpatialMaterial::TEXTURE_ALBEDO, tex); diff --git a/nodes/mesh_data_instance.h b/nodes/mesh_data_instance.h index 1c1ad49..c7c1cd9 100644 --- a/nodes/mesh_data_instance.h +++ b/nodes/mesh_data_instance.h @@ -31,6 +31,7 @@ SOFTWARE. #else #include "scene/3d/mesh_instance_3d.h" +#define SpatialMaterial StandardMaterial3D #define MeshInstance MeshInstance3D #define Texture Texture2D #endif diff --git a/plugin/mdr_import_plugin_base.cpp b/plugin/mdr_import_plugin_base.cpp index ec8e575..0a835d8 100644 --- a/plugin/mdr_import_plugin_base.cpp +++ b/plugin/mdr_import_plugin_base.cpp @@ -22,6 +22,10 @@ SOFTWARE. #include "mdr_import_plugin_base.h" +#include "core/version.h" + +#if VERSION_MAJOR < 4 + #include "scene/resources/box_shape.h" #include "scene/resources/capsule_shape.h" #include "scene/resources/concave_polygon_shape.h" @@ -30,6 +34,41 @@ SOFTWARE. #include "scene/resources/shape.h" #include "scene/resources/sphere_shape.h" +#else + +#include "scene/resources/box_shape_3d.h" +#include "scene/resources/capsule_shape_3d.h" +#include "scene/resources/concave_polygon_shape_3d.h" +#include "scene/resources/convex_polygon_shape_3d.h" +#include "scene/resources/cylinder_shape_3d.h" +#include "scene/resources/shape_3d.h" +#include "scene/resources/sphere_shape_3d.h" + +#define BoxShape BoxShape3D +#define CapsuleShape CapsuleShape3D +#define ConcavePolygonShape ConcavePolygonShape3D +#define ConvexPolygonShape ConvexPolygonShape3D +#define CylinderShape CylinderShape3D +#define Shape Shape3D +#define SphereShape SphereShape3D + +#define PoolVector3Array PackedVector3Array +#define PoolVector2Array PackedVector2Array +#define PoolColorArray PackedColorArray +#define PoolIntArray PackedInt64Array +#define PoolRealArray PackedFloat32Array +#define PoolByteArray PackedByteArray + +typedef class RenderingServer VisualServer; +typedef class RenderingServer VS; + +template +class Vector; +template +using PoolVector = Vector; + +#endif + const String MDRImportPluginBase::BINDING_MDR_IMPORT_TYPE = "Single,Multiple"; void MDRImportPluginBase::get_import_options(List *r_options, int p_preset) const { @@ -242,7 +281,7 @@ Ref MDRImportPluginBase::get_mesh(MeshInstance *mi, const Map< m.instance(); m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, mdr->get_array()); - Vector > shapes = mesh->convex_decompose(); + Vector> shapes = mesh->convex_decompose(); for (int j = 0; j < shapes.size(); ++j) { scale_shape(shapes[j], scale); @@ -381,7 +420,7 @@ Ref MDRImportPluginBase::get_mesh_arrays(Array &arrs, const Ma m.instance(); m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, mdr->get_array()); - Vector > shapes = mesh->convex_decompose(); + Vector> shapes = mesh->convex_decompose(); for (int j = 0; j < shapes.size(); ++j) { scale_shape(shapes[j], scale); @@ -695,26 +734,22 @@ Array MDRImportPluginBase::apply_transforms(Array &array, const Map MDRImportPluginBase::scale_shape(Ref shape, const Vector3 &scale) { - if (shape.is_null()) return shape; if (Object::cast_to(*shape)) { - Ref ss = shape; ss->set_radius(ss->get_radius() * MAX(scale.x, MAX(scale.y, scale.z))); } if (Object::cast_to(*shape)) { - Ref bs = shape; bs->set_extents(bs->get_extents() * scale); } if (Object::cast_to(*shape)) { - Ref cs = shape; float sc = MAX(scale.x, MAX(scale.y, scale.z)); @@ -724,7 +759,6 @@ Ref MDRImportPluginBase::scale_shape(Ref shape, const Vector3 &sca } if (Object::cast_to(*shape)) { - Ref cs = shape; float sc = MAX(scale.x, MAX(scale.y, scale.z)); @@ -734,7 +768,6 @@ Ref MDRImportPluginBase::scale_shape(Ref shape, const Vector3 &sca } if (Object::cast_to(*shape)) { - Ref cps = shape; PoolVector3Array arr = cps->get_faces(); @@ -749,7 +782,6 @@ Ref MDRImportPluginBase::scale_shape(Ref shape, const Vector3 &sca } if (Object::cast_to(*shape)) { - Ref cps = shape; PoolVector3Array arr = cps->get_points(); diff --git a/plugin_collada/editor_import_collada_mdr.cpp b/plugin_collada/editor_import_collada_mdr.cpp index b39cda1..01d426c 100644 --- a/plugin_collada/editor_import_collada_mdr.cpp +++ b/plugin_collada/editor_import_collada_mdr.cpp @@ -22,14 +22,6 @@ SOFTWARE. #include "editor_import_collada_mdr.h" -#include "scene/resources/box_shape.h" -#include "scene/resources/capsule_shape.h" -#include "scene/resources/concave_polygon_shape.h" -#include "scene/resources/convex_polygon_shape.h" -#include "scene/resources/cylinder_shape.h" -#include "scene/resources/shape.h" -#include "scene/resources/sphere_shape.h" - String EditorImportColladaMdr::get_importer_name() const { return "collada_mdr"; } diff --git a/plugin_gltf/editor_import_gltf_mdr.cpp b/plugin_gltf/editor_import_gltf_mdr.cpp index 8f4bf97..9622510 100644 --- a/plugin_gltf/editor_import_gltf_mdr.cpp +++ b/plugin_gltf/editor_import_gltf_mdr.cpp @@ -22,14 +22,6 @@ SOFTWARE. #include "editor_import_gltf_mdr.h" -#include "scene/resources/box_shape.h" -#include "scene/resources/capsule_shape.h" -#include "scene/resources/concave_polygon_shape.h" -#include "scene/resources/convex_polygon_shape.h" -#include "scene/resources/cylinder_shape.h" -#include "scene/resources/shape.h" -#include "scene/resources/sphere_shape.h" - String EditorImportGLTFMdr::get_importer_name() const { return "gltf_mdr"; }