From 5e139c2ab927f0546a5f6b6a974a931b53013978 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Fri, 26 May 2023 17:22:29 -0500 Subject: [PATCH] Add a get_node_index method to GLTFState --- modules/gltf/doc_classes/GLTFState.xml | 11 ++++++++++- modules/gltf/gltf_state.cpp | 10 ++++++++++ modules/gltf/gltf_state.h | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/modules/gltf/doc_classes/GLTFState.xml b/modules/gltf/doc_classes/GLTFState.xml index 34dd1069f5e..7614839b8bc 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 b493e498f12..372348d90de 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 f2036fca1e8..a2371b80408 100644 --- a/modules/gltf/gltf_state.h +++ b/modules/gltf/gltf_state.h @@ -204,7 +204,7 @@ public: 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);