Skip to content

Commit

Permalink
godot MeshLibrary export: recurse 4 nodes deep
Browse files Browse the repository at this point in the history
before we only recursed 2 nodes deep, now we just do 4 nodes deep - this should be sufficient until there is a new system for exporting nodes with more control.

Fixes importing certain Kenney assets, like described in godotengine#85085 or shown in https://dev.to/robpc/why-godot-drops-objects-when-creating-a-meshlibrary-14bg

We still only pick at most 1 MeshInstance3D from every node of only the immediate scene children
  • Loading branch information
WebFreak001 committed Jan 27, 2024
1 parent 17e7f85 commit 716710f
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions editor/plugins/mesh_library_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,31 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
p_library->clear();
}

// maximum depth how far into a node we look to find a MeshInstance3D
// note that we only pick the first found MeshInstance3D child of any given root node.
const int max_parenting_nodes = 4;

HashMap<int, MeshInstance3D *> mesh_instances;

for (int i = 0; i < p_scene->get_child_count(); i++) {
Node *child = p_scene->get_child(i);

if (!Object::cast_to<MeshInstance3D>(child)) {
if (child->get_child_count() > 0) {
child = child->get_child(0);
if (!Object::cast_to<MeshInstance3D>(child)) {
continue;
bool found = false;
for (int try_no = 0; try_no < max_parenting_nodes; try_no++) {
if (child->get_child_count() > 0) {
child = child->get_child(0);
if (Object::cast_to<MeshInstance3D>(child)) {
found = true;
break;
}
} else {
break;
}
}

} else {
if (!found)
continue;
}
}

MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(child);
Expand Down

0 comments on commit 716710f

Please sign in to comment.