diff --git a/nodes/mesh_data_instance.cpp b/nodes/mesh_data_instance.cpp index 3589f5e..8fe6202 100644 --- a/nodes/mesh_data_instance.cpp +++ b/nodes/mesh_data_instance.cpp @@ -30,8 +30,12 @@ void MeshDataInstance::set_mesh_data(const Ref &mesh) { _mesh = mesh; - if (_mesh.is_valid() && is_inside_tree()) { - setup_mesh(); + if (_mesh.is_valid()) { + if (is_inside_tree()) { + setup_mesh(); + } else { + _dirty = true; + } } } @@ -118,6 +122,7 @@ void MeshDataInstance::setup_material_texture() { } MeshDataInstance::MeshDataInstance() { + _dirty = false; _snap_to_mesh = false; _snap_axis = Vector3(0, -1, 0); } @@ -125,16 +130,21 @@ MeshDataInstance::~MeshDataInstance() { _mesh.unref(); _texture.unref(); } -/* -void MeshDataInstance::notification(int p_what) { + +void MeshDataInstance::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - if (get_parent() == NULL) - return; + if (_dirty) { + _dirty = false; + + if (_mesh.is_valid()) { + setup_mesh(); + } + } } } } -*/ + void MeshDataInstance::_bind_methods() { ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &MeshDataInstance::get_snap_to_mesh); ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &MeshDataInstance::set_snap_to_mesh); diff --git a/nodes/mesh_data_instance.h b/nodes/mesh_data_instance.h index 36fc08a..1c1ad49 100644 --- a/nodes/mesh_data_instance.h +++ b/nodes/mesh_data_instance.h @@ -67,10 +67,11 @@ public: ~MeshDataInstance(); protected: - //void notification(int p_what); + void _notification(int p_what); static void _bind_methods(); private: + bool _dirty; bool _snap_to_mesh; Vector3 _snap_axis; Ref _mesh; diff --git a/props/prop_data_mesh_data.cpp b/props/prop_data_mesh_data.cpp index e8a5f77..77ca15f 100644 --- a/props/prop_data_mesh_data.cpp +++ b/props/prop_data_mesh_data.cpp @@ -25,6 +25,7 @@ SOFTWARE. #if PROPS_PRESENT #include "../nodes/mesh_data_instance.h" +#include "scene/resources/material.h" Ref PropDataMeshData::get_mesh() const { return _mesh; @@ -84,9 +85,13 @@ void PropDataMeshData::_processor_process(Ref prop_data, Node *node, c Node *PropDataMeshData::_processor_get_node_for(const Transform &transform) { MeshDataInstance *i = memnew(MeshDataInstance); - i->set_mesh_data(get_mesh()); + Ref m; + m.instance(); + + i->set_material(m); i->set_texture(get_texture()); - i->set_transform(transform * get_transform()); + i->set_mesh_data(get_mesh()); + i->set_transform(get_transform()); return i; }