Skip to content

Commit

Permalink
Add a get_node_index method to GLTFState
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke committed May 27, 2023
1 parent 9a3221f commit 5e139c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
11 changes: 10 additions & 1 deletion modules/gltf/doc_classes/GLTFState.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
</description>
</method>
<method name="get_node_index">
<return type="int" />
<param index="0" name="scene_node" type="Node" />
<description>
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.
</description>
</method>
<method name="get_nodes">
<return type="GLTFNode[]" />
<description>
Expand All @@ -100,7 +108,8 @@
<return type="Node" />
<param index="0" name="idx" type="int" />
<description>
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.
</description>
</method>
<method name="get_skeletons">
Expand Down
10 changes: 10 additions & 0 deletions modules/gltf/gltf_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<GLTFNodeIndex, Node *> 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();
}
Expand Down
2 changes: 1 addition & 1 deletion modules/gltf/gltf_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class GLTFState : public Resource {
void set_animations(TypedArray<GLTFAnimation> 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);

Expand Down

0 comments on commit 5e139c2

Please sign in to comment.