diff --git a/modules/props/prop_instance.cpp b/modules/props/prop_instance.cpp index 6061814e1..f256b3412 100644 --- a/modules/props/prop_instance.cpp +++ b/modules/props/prop_instance.cpp @@ -104,6 +104,13 @@ void PropInstance::collision_layer_changed() { void PropInstance::collision_mask_changed() { } +AABB PropInstance::get_aabb() const { + return _aabb; +} +PoolVector PropInstance::get_faces(uint32_t p_usage_flags) const { + return PoolVector(); +} + void PropInstance::init_materials() { call("_init_materials"); } @@ -139,11 +146,17 @@ void PropInstance::_build() { } } + _aabb = AABB(); + _aabb.position = get_global_translation(); + if (!_prop_data.is_valid()) { return; } prop_preprocess(Transform(), _prop_data); + + update_gizmos(); + _change_notify(); } void PropInstance::_build_finished() { @@ -201,6 +214,9 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref &pr add_child(twn); + //_aabb.merge_with(twn->get_aabb()); + _aabb.expand_to(t.get_origin()); + continue; } @@ -220,6 +236,8 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref &pr if (sp) { sp->set_transform(t); + + _aabb.expand_to(t.get_origin()); } continue; @@ -240,6 +258,8 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref &pr light->set_param(Light::PARAM_SPECULAR, light_data->get_light_specular()); light->set_transform(t); + _aabb.expand_to(t.get_origin()); + continue; } @@ -249,6 +269,8 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref &pr Node *static_body = static_body_data->processor_get_node_for(t); add_child(static_body); + _aabb.expand_to(t.get_origin()); + continue; } @@ -262,6 +284,8 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref &pr continue; } + _aabb.merge_with(mdr->get_aabb()); + MeshDataInstance *mdi = memnew(MeshDataInstance); add_child(mdi); mdi->set_transform(t); @@ -292,6 +316,9 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref &pr mdi->set_mesh_data(mdr); + //_aabb.merge_with(mdi->get_aabb()); + _aabb.expand_to(t.get_origin()); + continue; } #endif diff --git a/modules/props/prop_instance.h b/modules/props/prop_instance.h index 459896c90..38c8de4ed 100644 --- a/modules/props/prop_instance.h +++ b/modules/props/prop_instance.h @@ -32,7 +32,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "scene/main/spatial.h" +#include "scene/3d/visual_instance.h" #include "scene/resources/material/material.h" @@ -40,8 +40,8 @@ #include "props/prop_data.h" -class PropInstance : public Spatial { - GDCLASS(PropInstance, Spatial); +class PropInstance : public VisualInstance { + GDCLASS(PropInstance, VisualInstance); public: Ref get_prop_data(); @@ -59,6 +59,9 @@ public: virtual void collision_layer_changed(); virtual void collision_mask_changed(); + virtual AABB get_aabb() const; + virtual PoolVector get_faces(uint32_t p_usage_flags) const; + void init_materials(); virtual void _init_materials(); @@ -88,6 +91,8 @@ protected: bool _build_queued; bool _building; + + AABB _aabb; }; #endif diff --git a/modules/props/prop_instance_merger.cpp b/modules/props/prop_instance_merger.cpp index 1a8baffac..0cc4c30bf 100644 --- a/modules/props/prop_instance_merger.cpp +++ b/modules/props/prop_instance_merger.cpp @@ -602,6 +602,10 @@ void PropInstanceMerger::_build_finished() { if (_build_queued) { call_deferred("build"); + } else { + update_gizmos(); + + _change_notify(); } } @@ -642,6 +646,8 @@ void PropInstanceMerger::_prop_preprocess(Transform transform, const Refget_collision_shape_transform(j); _job->add_collision_shape(collision_shape, et, true); + + _aabb.expand_to(t.get_origin()); } } @@ -656,6 +662,8 @@ void PropInstanceMerger::_prop_preprocess(Transform transform, const Refadd_tiled_wall(tiled_wall_data, t); + _aabb.expand_to(t.get_origin()); + if (tiled_wall_data->get_collision()) { Ref tws; tws.instance(); @@ -694,6 +702,7 @@ void PropInstanceMerger::_prop_preprocess(Transform transform, const Refset_transform(t); + _aabb.expand_to(t.get_origin()); } continue; @@ -720,6 +729,8 @@ void PropInstanceMerger::_prop_preprocess(Transform transform, const Refadd_light(light); + _aabb.expand_to(t.get_origin()); + continue; } @@ -733,10 +744,14 @@ void PropInstanceMerger::_prop_preprocess(Transform transform, const Refget_aabb()); + _job->add_mesh(mesh_data, t); for (int j = 0; j < mdr->get_collision_shape_count(); ++j) { - _job->add_collision_shape(mdr->get_collision_shape(j), t * mdr->get_collision_shape_offset(j)); + Transform ct = t * mdr->get_collision_shape_offset(j); + _job->add_collision_shape(mdr->get_collision_shape(j), ct); + _aabb.expand_to(ct.get_origin()); } } #endif