diff --git a/modules/gltf/doc_classes/GLTFState.xml b/modules/gltf/doc_classes/GLTFState.xml
index 34dd1069f5ee..7614839b8bc3 100644
--- a/modules/gltf/doc_classes/GLTFState.xml
+++ b/modules/gltf/doc_classes/GLTFState.xml
@@ -90,6 +90,14 @@
Returns an array of all [GLTFMesh]es in the GLTF file. These are the meshes that the [member GLTFNode.mesh] index refers to.
+
+
+
+
+ Returns the index of the [GLTFNode] corresponding to this Godot scene node. This is the inverse of [method get_scene_node]. Useful during the export process.
+ [b]Note:[/b] Not every Godot scene node will have a corresponding [GLTFNode], and not every [GLTFNode] will have a scene node generated. If there is no [GLTFNode] index for this scene node, [code]-1[/code] is returned.
+
+
@@ -100,7 +108,8 @@
- Returns the Godot scene node that corresponds to the same index as the [GLTFNode] it was generated from. Not every [GLTFNode] will have a scene node generated, and not every generated scene node will have a corresponding [GLTFNode].
+ Returns the Godot scene node that corresponds to the same index as the [GLTFNode] it was generated from. This is the inverse of [method get_node_index]. Useful during the import process.
+ [b]Note:[/b] Not every [GLTFNode] will have a scene node generated, and not every generated scene node will have a corresponding [GLTFNode]. If there is no scene node for this [GLTFNode] index, [code]null[/code] is returned.
diff --git a/modules/gltf/gltf_state.cpp b/modules/gltf/gltf_state.cpp
index b493e498f127..372348d90de7 100644
--- a/modules/gltf/gltf_state.cpp
+++ b/modules/gltf/gltf_state.cpp
@@ -87,6 +87,7 @@ void GLTFState::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_animations"), &GLTFState::get_animations);
ClassDB::bind_method(D_METHOD("set_animations", "animations"), &GLTFState::set_animations);
ClassDB::bind_method(D_METHOD("get_scene_node", "idx"), &GLTFState::get_scene_node);
+ ClassDB::bind_method(D_METHOD("get_node_index", "scene_node"), &GLTFState::get_node_index);
ClassDB::bind_method(D_METHOD("get_additional_data", "extension_name"), &GLTFState::get_additional_data);
ClassDB::bind_method(D_METHOD("set_additional_data", "extension_name", "additional_data"), &GLTFState::set_additional_data);
ClassDB::bind_method(D_METHOD("get_handle_binary_image"), &GLTFState::get_handle_binary_image);
@@ -335,6 +336,15 @@ Node *GLTFState::get_scene_node(GLTFNodeIndex idx) {
return scene_nodes[idx];
}
+GLTFNodeIndex GLTFState::get_node_index(Node *p_node) {
+ for (KeyValue x : scene_nodes) {
+ if (x.value == p_node) {
+ return x.key;
+ }
+ }
+ return -1;
+}
+
int GLTFState::get_animation_players_count(int idx) {
return animation_players.size();
}
diff --git a/modules/gltf/gltf_state.h b/modules/gltf/gltf_state.h
index f2036fca1e82..a2371b804082 100644
--- a/modules/gltf/gltf_state.h
+++ b/modules/gltf/gltf_state.h
@@ -204,7 +204,7 @@ class GLTFState : public Resource {
void set_animations(TypedArray p_animations);
Node *get_scene_node(GLTFNodeIndex idx);
- ImporterMeshInstance3D *get_scene_mesh_instance(GLTFNodeIndex idx);
+ GLTFNodeIndex get_node_index(Node *p_node);
int get_animation_players_count(int idx);