diff --git a/prop_instance.cpp b/prop_instance.cpp index ea84215..fcce675 100644 --- a/prop_instance.cpp +++ b/prop_instance.cpp @@ -51,6 +51,32 @@ void PropInstance::set_material(const Ref &material) { _material = material; } +void PropInstance::set_collision_layer(uint32_t p_layer) { + _collision_layer = p_layer; + + collision_layer_changed(); +} + +uint32_t PropInstance::get_collision_layer() const { + return _collision_layer; +} + +void PropInstance::set_collision_mask(uint32_t p_mask) { + _collision_mask = p_mask; + + collision_mask_changed(); +} + +uint32_t PropInstance::get_collision_mask() const { + return _collision_mask; +} + +void PropInstance::collision_layer_changed() { +} + +void PropInstance::collision_mask_changed() { +} + void PropInstance::init_materials() { call("_init_materials"); } @@ -228,6 +254,9 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref &pr PropInstance::PropInstance() { _build_queued = false; _building = false; + + _collision_layer = 1; + _collision_mask = 1; } PropInstance::~PropInstance() { @@ -255,6 +284,16 @@ void PropInstance::_bind_methods() { ClassDB::bind_method(D_METHOD("set_material", "material"), &PropInstance::set_material); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_material", "get_material"); + ClassDB::bind_method(D_METHOD("get_collision_layer"), &PropInstance::get_collision_layer); + ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &PropInstance::set_collision_layer); + + ClassDB::bind_method(D_METHOD("get_collision_mask"), &PropInstance::get_collision_mask); + ClassDB::bind_method(D_METHOD("set_collision_mask", "layer"), &PropInstance::set_collision_mask); + + ADD_GROUP("Collision", "collision_"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); + BIND_VMETHOD(MethodInfo("_prop_preprocess", PropertyInfo(Variant::TRANSFORM, "tarnsform"), PropertyInfo(Variant::OBJECT, "prop_data", PROPERTY_HINT_RESOURCE_TYPE, "PropData"))); diff --git a/prop_instance.h b/prop_instance.h index f75b238..7bf5b88 100644 --- a/prop_instance.h +++ b/prop_instance.h @@ -49,6 +49,15 @@ public: Ref get_material(); void set_material(const Ref &material); + void set_collision_layer(uint32_t p_layer); + uint32_t get_collision_layer() const; + + void set_collision_mask(uint32_t p_mask); + uint32_t get_collision_mask() const; + + virtual void collision_layer_changed(); + virtual void collision_mask_changed(); + void init_materials(); virtual void _init_materials(); @@ -73,6 +82,9 @@ protected: Ref _prop_data; Ref _material; + uint32_t _collision_layer; + uint32_t _collision_mask; + bool _build_queued; bool _building; }; diff --git a/prop_instance_merger.cpp b/prop_instance_merger.cpp index 56587cf..451d895 100644 --- a/prop_instance_merger.cpp +++ b/prop_instance_merger.cpp @@ -694,6 +694,25 @@ void PropInstanceMerger::_prop_preprocess(Transform transform, const Refbody_set_collision_layer(c.body, _collision_layer); + } + } +} +void PropInstanceMerger::collision_mask_changed() { + for (int i = 0; i < _colliders.size(); ++i) { + const ColliderBody &c = _colliders[i]; + + if (c.body != RID()) { + PhysicsServer::get_singleton()->body_set_collision_mask(c.body, _collision_mask); + } + } +} + PropInstanceMerger::PropInstanceMerger() { _build_queued = false; _auto_lod = true; diff --git a/prop_instance_merger.h b/prop_instance_merger.h index 8ddb7c1..0465a93 100644 --- a/prop_instance_merger.h +++ b/prop_instance_merger.h @@ -122,6 +122,9 @@ public: void _prop_preprocess(Transform tarnsform, const Ref &prop); + void collision_layer_changed(); + void collision_mask_changed(); + PropInstanceMerger(); ~PropInstanceMerger(); diff --git a/prop_instance_prop_job.cpp b/prop_instance_prop_job.cpp index d0a596b..13a2d23 100644 --- a/prop_instance_prop_job.cpp +++ b/prop_instance_prop_job.cpp @@ -234,8 +234,8 @@ void PropInstancePropJob::phase_physics_process() { PhysicsServer::get_singleton()->body_add_shape(body, e.shape->get_rid()); //TODO store the layer mask somewhere - PhysicsServer::get_singleton()->body_set_collision_layer(body, 1); - PhysicsServer::get_singleton()->body_set_collision_mask(body, 1); + PhysicsServer::get_singleton()->body_set_collision_layer(body, _prop_instace->get_collision_layer()); + PhysicsServer::get_singleton()->body_set_collision_mask(body, _prop_instace->get_collision_mask()); if (_prop_instace->is_inside_tree() && _prop_instace->is_inside_world()) { Ref world = _prop_instace->GET_WORLD();