diff --git a/modules/props/doc_classes/PropDataProp.xml b/modules/props/doc_classes/PropDataProp.xml
index 1252f41eb..c25742bfe 100644
--- a/modules/props/doc_classes/PropDataProp.xml
+++ b/modules/props/doc_classes/PropDataProp.xml
@@ -7,8 +7,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/modules/props/prop_instance_merger.cpp b/modules/props/prop_instance_merger.cpp
index d4c481f00..7052819a6 100644
--- a/modules/props/prop_instance_merger.cpp
+++ b/modules/props/prop_instance_merger.cpp
@@ -1033,3 +1033,7 @@ void PropInstanceMerger::_bind_methods() {
ClassDB::bind_method(D_METHOD("free_meshes"), &PropInstanceMerger::free_meshes);
ClassDB::bind_method(D_METHOD("free_colliders"), &PropInstanceMerger::free_colliders);
}
+
+PropInstanceMerger::ColliderBody::ColliderBody() {
+ owns_shape = false;
+}
diff --git a/modules/props/prop_instance_merger.h b/modules/props/prop_instance_merger.h
index 8ad929032..455a29df1 100644
--- a/modules/props/prop_instance_merger.h
+++ b/modules/props/prop_instance_merger.h
@@ -43,6 +43,7 @@
#include "props/prop_data.h"
class MeshDataInstance;
+class Shape;
class PropInstanceMerger : public PropInstance {
GDCLASS(PropInstanceMerger, PropInstance);
@@ -143,9 +144,7 @@ protected:
RID shape_rid;
bool owns_shape;
- ColliderBody() {
- owns_shape = false;
- }
+ ColliderBody();
};
struct MeshEntry {
diff --git a/modules/props/prop_instance_prop_job.cpp b/modules/props/prop_instance_prop_job.cpp
index d31b4906e..d0012a0dc 100644
--- a/modules/props/prop_instance_prop_job.cpp
+++ b/modules/props/prop_instance_prop_job.cpp
@@ -763,3 +763,7 @@ void PropInstancePropJob::_bind_methods() {
ClassDB::bind_method(D_METHOD("_physics_process", "delta"), &PropInstancePropJob::_physics_process);
}
+
+PropInstancePropJob::CollisionShapeEntry::CollisionShapeEntry() {
+ owns_shape = false;
+}
\ No newline at end of file
diff --git a/modules/props/prop_instance_prop_job.h b/modules/props/prop_instance_prop_job.h
index bf5046a71..db341474b 100644
--- a/modules/props/prop_instance_prop_job.h
+++ b/modules/props/prop_instance_prop_job.h
@@ -128,9 +128,7 @@ protected:
Transform transform;
bool owns_shape;
- CollisionShapeEntry() {
- owns_shape = false;
- }
+ CollisionShapeEntry();
};
Ref _material_cache;
diff --git a/modules/props/props/prop_data_prop.cpp b/modules/props/props/prop_data_prop.cpp
index 179471fc2..30a655dc0 100644
--- a/modules/props/props/prop_data_prop.cpp
+++ b/modules/props/props/prop_data_prop.cpp
@@ -32,8 +32,11 @@
#include "prop_data_prop.h"
#include "../prop_instance.h"
+#include "../prop_instance_merger.h"
#include "prop_data.h"
+#include "scene/resources/material/material.h"
+
#include "modules/modules_enabled.gen.h"
Ref PropDataProp::get_prop() const {
@@ -43,6 +46,52 @@ void PropDataProp::set_prop(const Ref value) {
_prop = value;
}
+//Materials
+Ref PropDataProp::material_get(const int index) {
+ ERR_FAIL_INDEX_V(index, _materials.size(), Ref(NULL));
+
+ return _materials[index];
+}
+
+void PropDataProp::material_add(const Ref &value) {
+ ERR_FAIL_COND(!value.is_valid());
+
+ _materials.push_back(value);
+}
+
+int PropDataProp::material_get_num() const {
+ return _materials.size();
+}
+
+void PropDataProp::materials_clear() {
+ _materials.clear();
+}
+
+Vector PropDataProp::materials_get() {
+ Vector r;
+ for (int i = 0; i < _materials.size(); i++) {
+ r.push_back(_materials[i].get_ref_ptr());
+ }
+ return r;
+}
+
+void PropDataProp::materials_set(const Vector &materials) {
+ _materials.clear();
+
+ for (int i = 0; i < materials.size(); i++) {
+ Ref material = Ref(materials[i]);
+
+ _materials.push_back(material);
+ }
+}
+
+bool PropDataProp::get_is_merger() {
+ return _is_merger;
+}
+void PropDataProp::set_is_merger(bool value) {
+ _is_merger = value;
+}
+
bool PropDataProp::get_snap_to_mesh() {
return _snap_to_mesh;
}
@@ -79,6 +128,20 @@ void PropDataProp::_processor_process(Ref prop_data, Node *node, const
l.instance();
l->set_prop(i->get_prop_data());
l->set_transform(transform * i->get_transform());
+
+ PropInstanceMerger *im = Object::cast_to(node);
+
+ if (im) {
+ l->materials_set(im->materials_get());
+ l->set_is_merger(true);
+ } else {
+ Ref mat = i->get_material();
+
+ if (mat.is_valid()) {
+ l->material_add(mat);
+ }
+ }
+
prop_data->add_prop(l);
return;
@@ -86,15 +149,30 @@ void PropDataProp::_processor_process(Ref prop_data, Node *node, const
}
Node *PropDataProp::_processor_get_node_for(const Transform &transform) {
- PropInstance *i = memnew(PropInstance);
+ if (_is_merger) {
+ PropInstanceMerger *i = memnew(PropInstanceMerger);
- i->set_prop_data(get_prop());
- i->set_transform(get_transform());
+ i->set_prop_data(get_prop());
+ i->set_transform(get_transform());
+ i->materials_set(materials_get());
- return i;
+ return i;
+ } else {
+ PropInstance *i = memnew(PropInstance);
+
+ i->set_prop_data(get_prop());
+ i->set_transform(get_transform());
+
+ if (_materials.size() > 0) {
+ i->set_material(_materials[0]);
+ }
+
+ return i;
+ }
}
PropDataProp::PropDataProp() {
+ _is_merger = false;
_snap_to_mesh = false;
_snap_axis = Vector3(0, 1, 0);
}
@@ -109,6 +187,20 @@ void PropDataProp::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_prop", "value"), &PropDataProp::set_prop);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop", PROPERTY_HINT_RESOURCE_TYPE, "PropData"), "set_prop", "get_prop");
+ ///Materials
+ ClassDB::bind_method(D_METHOD("material_get", "index"), &PropDataProp::material_get);
+ ClassDB::bind_method(D_METHOD("material_add", "value"), &PropDataProp::material_add);
+ ClassDB::bind_method(D_METHOD("material_get_num"), &PropDataProp::material_get_num);
+ ClassDB::bind_method(D_METHOD("materials_clear"), &PropDataProp::materials_clear);
+
+ ClassDB::bind_method(D_METHOD("materials_get"), &PropDataProp::materials_get);
+ ClassDB::bind_method(D_METHOD("materials_set"), &PropDataProp::materials_set);
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "materials", PROPERTY_HINT_NONE, "23/20:Material", PROPERTY_USAGE_DEFAULT, "Material"), "materials_set", "materials_get");
+
+ ClassDB::bind_method(D_METHOD("get_is_merger"), &PropDataProp::get_is_merger);
+ ClassDB::bind_method(D_METHOD("set_is_merger", "value"), &PropDataProp::set_is_merger);
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "is_merger"), "set_is_merger", "get_is_merger");
+
ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &PropDataProp::get_snap_to_mesh);
ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &PropDataProp::set_snap_to_mesh);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_to_mesh"), "set_snap_to_mesh", "get_snap_to_mesh");
diff --git a/modules/props/props/prop_data_prop.h b/modules/props/props/prop_data_prop.h
index 5eeedc54a..1f1df9531 100644
--- a/modules/props/props/prop_data_prop.h
+++ b/modules/props/props/prop_data_prop.h
@@ -43,6 +43,8 @@
#include "../../texture_packer/texture_packer.h"
#endif
+class Material;
+
class PropDataProp : public PropDataEntry {
GDCLASS(PropDataProp, PropDataEntry);
@@ -50,6 +52,18 @@ public:
Ref get_prop() const;
void set_prop(const Ref value);
+ ///Materials
+ Ref material_get(const int index);
+ void material_add(const Ref &value);
+ int material_get_num() const;
+ void materials_clear();
+
+ Vector materials_get();
+ void materials_set(const Vector &materials);
+
+ bool get_is_merger();
+ void set_is_merger(bool value);
+
bool get_snap_to_mesh();
void set_snap_to_mesh(bool value);
@@ -71,9 +85,11 @@ protected:
static void _bind_methods();
private:
+ bool _is_merger;
bool _snap_to_mesh;
Vector3 _snap_axis;
Ref _prop;
+ Vector[> _materials;
};
#endif
]