Fix compile for 4.0.

This commit is contained in:
Relintai 2020-07-29 00:02:05 +02:00
parent 9a83350bba
commit a9bab9896d
7 changed files with 61 additions and 27 deletions

View File

@ -64,7 +64,7 @@ Vector<Variant> 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
}

View File

@ -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);

View File

@ -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<ImageTexture> 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);

View File

@ -31,6 +31,7 @@ SOFTWARE.
#else
#include "scene/3d/mesh_instance_3d.h"
#define SpatialMaterial StandardMaterial3D
#define MeshInstance MeshInstance3D
#define Texture Texture2D
#endif

View File

@ -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 N>
class Vector;
template <class N>
using PoolVector = Vector<N>;
#endif
const String MDRImportPluginBase::BINDING_MDR_IMPORT_TYPE = "Single,Multiple";
void MDRImportPluginBase::get_import_options(List<ImportOption> *r_options, int p_preset) const {
@ -242,7 +281,7 @@ Ref<MeshDataResource> MDRImportPluginBase::get_mesh(MeshInstance *mi, const Map<
m.instance();
m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, mdr->get_array());
Vector<Ref<Shape> > shapes = mesh->convex_decompose();
Vector<Ref<Shape>> shapes = mesh->convex_decompose();
for (int j = 0; j < shapes.size(); ++j) {
scale_shape(shapes[j], scale);
@ -381,7 +420,7 @@ Ref<MeshDataResource> MDRImportPluginBase::get_mesh_arrays(Array &arrs, const Ma
m.instance();
m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, mdr->get_array());
Vector<Ref<Shape> > shapes = mesh->convex_decompose();
Vector<Ref<Shape>> 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<StringName,
}
Ref<Shape> MDRImportPluginBase::scale_shape(Ref<Shape> shape, const Vector3 &scale) {
if (shape.is_null())
return shape;
if (Object::cast_to<SphereShape>(*shape)) {
Ref<SphereShape> ss = shape;
ss->set_radius(ss->get_radius() * MAX(scale.x, MAX(scale.y, scale.z)));
}
if (Object::cast_to<BoxShape>(*shape)) {
Ref<BoxShape> bs = shape;
bs->set_extents(bs->get_extents() * scale);
}
if (Object::cast_to<CapsuleShape>(*shape)) {
Ref<CapsuleShape> cs = shape;
float sc = MAX(scale.x, MAX(scale.y, scale.z));
@ -724,7 +759,6 @@ Ref<Shape> MDRImportPluginBase::scale_shape(Ref<Shape> shape, const Vector3 &sca
}
if (Object::cast_to<CylinderShape>(*shape)) {
Ref<CylinderShape> cs = shape;
float sc = MAX(scale.x, MAX(scale.y, scale.z));
@ -734,7 +768,6 @@ Ref<Shape> MDRImportPluginBase::scale_shape(Ref<Shape> shape, const Vector3 &sca
}
if (Object::cast_to<ConcavePolygonShape>(*shape)) {
Ref<ConcavePolygonShape> cps = shape;
PoolVector3Array arr = cps->get_faces();
@ -749,7 +782,6 @@ Ref<Shape> MDRImportPluginBase::scale_shape(Ref<Shape> shape, const Vector3 &sca
}
if (Object::cast_to<ConvexPolygonShape>(*shape)) {
Ref<ConvexPolygonShape> cps = shape;
PoolVector3Array arr = cps->get_points();

View File

@ -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";
}

View File

@ -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";
}