From d1a5bbf2a0ba2266ed814d3e8a168619e0ede8ab Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 13 Aug 2021 22:56:05 +0200 Subject: [PATCH] Added a method to MeshDataInstance that can return a substitute MeshInstance. --- nodes/mesh_data_instance.cpp | 20 ++++++++++++++++++++ nodes/mesh_data_instance.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/nodes/mesh_data_instance.cpp b/nodes/mesh_data_instance.cpp index dee9381..9db6e22 100644 --- a/nodes/mesh_data_instance.cpp +++ b/nodes/mesh_data_instance.cpp @@ -19,6 +19,8 @@ #include "../../texture_packer/texture_resource/packer_image_resource.h" #endif +#include "scene/3d/mesh_instance.h" + bool MeshDataInstance::get_snap_to_mesh() const { return _snap_to_mesh; } @@ -168,6 +170,22 @@ void MeshDataInstance::free_meshes() { } } +Node *MeshDataInstance::get_substitute_for_room() { + if (!_mesh.is_valid()) { + return nullptr; + } + + Ref m; + m.instance(); + + m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, _mesh->get_array()); + + MeshInstance *mi = memnew(MeshInstance); + mi->set_mesh(m); + + return mi; +} + MeshDataInstance::MeshDataInstance() { _dirty = false; _snap_to_mesh = false; @@ -226,4 +244,6 @@ void MeshDataInstance::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_material", "get_material"); ClassDB::bind_method(D_METHOD("refresh"), &MeshDataInstance::refresh); + + ClassDB::bind_method(D_METHOD("get_substitute_for_room"), &MeshDataInstance::get_substitute_for_room); } diff --git a/nodes/mesh_data_instance.h b/nodes/mesh_data_instance.h index 1de4db9..3f6c510 100644 --- a/nodes/mesh_data_instance.h +++ b/nodes/mesh_data_instance.h @@ -65,6 +65,8 @@ public: void setup_material_texture(); void free_meshes(); + Node *get_substitute_for_room(); + MeshDataInstance(); ~MeshDataInstance();