summaryrefslogtreecommitdiff
path: root/editor/plugins/mesh_library_editor_plugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins/mesh_library_editor_plugin.cpp')
-rw-r--r--editor/plugins/mesh_library_editor_plugin.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/editor/plugins/mesh_library_editor_plugin.cpp b/editor/plugins/mesh_library_editor_plugin.cpp
index aedac7b45d..2622d14ade 100644
--- a/editor/plugins/mesh_library_editor_plugin.cpp
+++ b/editor/plugins/mesh_library_editor_plugin.cpp
@@ -70,6 +70,8 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
if (!p_merge)
p_library->clear();
+ Map<int, MeshInstance *> mesh_instances;
+
for (int i = 0; i < p_scene->get_child_count(); i++) {
Node *child = p_scene->get_child(i);
@@ -90,6 +92,15 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
if (mesh.is_null())
continue;
+ mesh = mesh->duplicate();
+ for (int j = 0; j < mesh->get_surface_count(); ++j) {
+ Ref<Material> mat = mi->get_surface_material(j);
+
+ if (mat.is_valid()) {
+ mesh->surface_set_material(j, mat);
+ }
+ }
+
int id = p_library->find_item_by_name(mi->get_name());
if (id < 0) {
@@ -99,6 +110,7 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
}
p_library->set_item_mesh(id, mesh);
+ mesh_instances[id] = mi;
Vector<MeshLibrary::ShapeData> collisions;
@@ -155,14 +167,26 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
if (1) {
Vector<Ref<Mesh> > meshes;
+ Vector<Transform> transforms;
Vector<int> ids = p_library->get_item_list();
for (int i = 0; i < ids.size(); i++) {
- meshes.push_back(p_library->get_item_mesh(ids[i]));
+
+ if (mesh_instances.find(ids[i])) {
+
+ meshes.push_back(p_library->get_item_mesh(ids[i]));
+ transforms.push_back(mesh_instances[ids[i]]->get_transform());
+ }
}
- Vector<Ref<Texture> > textures = EditorInterface::get_singleton()->make_mesh_previews(meshes, EditorSettings::get_singleton()->get("editors/grid_map/preview_size"));
+ Vector<Ref<Texture> > textures = EditorInterface::get_singleton()->make_mesh_previews(meshes, &transforms, EditorSettings::get_singleton()->get("editors/grid_map/preview_size"));
+ int j = 0;
for (int i = 0; i < ids.size(); i++) {
- p_library->set_item_preview(ids[i], textures[i]);
+
+ if (mesh_instances.find(ids[i])) {
+
+ p_library->set_item_preview(ids[i], textures[j]);
+ j++;
+ }
}
}
}