From 6df53e0401fd7c2f8e81cd7d8189584706d3d7d8 Mon Sep 17 00:00:00 2001 From: Daniel Rakos Date: Thu, 31 Jan 2019 18:04:36 +0100 Subject: MeshLibrary export improvements - From now materials assigned to the MeshInstance (not the Mesh) get exported into the MeshLibrary when such materials exist. This enables workflows where the MeshLibrary is exported from an imported scene (e.g. GLTF) where the materials assigned to the Mesh (not the MeshInstance) get overwritten on re-import, thus can't use editor set materials in the exported MeshLibrary unless they are assigned to the MeshInstance whose materials get saved with the inherited scene thus persist across re-imports. - When appending to an existing MeshLibrary only generate previews for newly added or modified meshes. - During preview generation transform camera and lights instead of the mesh and use the source MeshInstance's transform for the mesh to avoid weird previews being generated for meshes with a position dependent material (e.g. when using triplanar mapping). - Adjust the camera angle and light directions used in mesh preview generation for better results. --- editor/plugins/mesh_library_editor_plugin.cpp | 30 ++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'editor/plugins/mesh_library_editor_plugin.cpp') 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 p_library, if (!p_merge) p_library->clear(); + Map 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 p_library, if (mesh.is_null()) continue; + mesh = mesh->duplicate(); + for (int j = 0; j < mesh->get_surface_count(); ++j) { + Ref 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 p_library, } p_library->set_item_mesh(id, mesh); + mesh_instances[id] = mi; Vector collisions; @@ -155,14 +167,26 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref p_library, if (1) { Vector > meshes; + Vector transforms; Vector 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 > textures = EditorInterface::get_singleton()->make_mesh_previews(meshes, EditorSettings::get_singleton()->get("editors/grid_map/preview_size")); + Vector > 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++; + } } } } -- cgit v1.2.3