Skip to content

Commit

Permalink
Prevent AnimationPlayer from being added on GLTF import if the option…
Browse files Browse the repository at this point in the history
… is unchecked. Fixes #63954
  • Loading branch information
hakro committed Aug 10, 2022
1 parent 94a8065 commit 805ffdf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions modules/gltf/doc_classes/GLTFState.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@
</member>
<member name="buffers" type="Array" setter="set_buffers" getter="get_buffers" default="[]">
</member>
<member name="create_animations" type="bool" setter="set_create_animations" getter="get_create_animations" default="true">
</member>
<member name="glb_data" type="PackedByteArray" setter="set_glb_data" getter="get_glb_data" default="PackedByteArray()">
</member>
<member name="json" type="Dictionary" setter="set_json" getter="get_json" default="{}">
Expand Down
3 changes: 3 additions & 0 deletions modules/gltf/editor/editor_scene_importer_gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ Node *EditorSceneFormatImporterGLTF::import_scene(const String &p_path, uint32_t
}
return nullptr;
}
if (p_options.has("animation/import")) {
state->set_create_animations(bool(p_options["animation/import"]));
}
return doc->generate_scene(state, p_bake_fps);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/gltf/gltf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6899,7 +6899,7 @@ Node *GLTFDocument::generate_scene(Ref<GLTFState> state, int32_t p_bake_fps) {
Node *root = gltf_root_node->get_parent();
ERR_FAIL_NULL_V(root, nullptr);
_process_mesh_instances(state, root);
if (state->animations.size()) {
if (state->get_create_animations() && state->animations.size()) {
AnimationPlayer *ap = memnew(AnimationPlayer);
root->add_child(ap, true);
ap->set_owner(root);
Expand Down
11 changes: 11 additions & 0 deletions modules/gltf/gltf_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ void GLTFState::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_skeletons", "skeletons"), &GLTFState::set_skeletons);
ClassDB::bind_method(D_METHOD("get_skeleton_to_node"), &GLTFState::get_skeleton_to_node);
ClassDB::bind_method(D_METHOD("set_skeleton_to_node", "skeleton_to_node"), &GLTFState::set_skeleton_to_node);
ClassDB::bind_method(D_METHOD("get_create_animations"), &GLTFState::get_create_animations);
ClassDB::bind_method(D_METHOD("set_create_animations", "create_animations"), &GLTFState::set_create_animations);
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);
Expand Down Expand Up @@ -106,6 +108,7 @@ void GLTFState::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "unique_animation_names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_unique_animation_names", "get_unique_animation_names"); // Set<String>
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "skeletons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skeletons", "get_skeletons"); // Vector<Ref<GLTFSkeleton>>
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "skeleton_to_node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_skeleton_to_node", "get_skeleton_to_node"); // RBMap<GLTFSkeletonIndex,
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "create_animations"), "set_create_animations", "get_create_animations"); // bool
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "animations", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_animations", "get_animations"); // Vector<Ref<GLTFAnimation>>
}

Expand Down Expand Up @@ -285,6 +288,14 @@ void GLTFState::set_skeleton_to_node(Dictionary p_skeleton_to_node) {
GLTFTemplateConvert::set_from_dict(skeleton_to_node, p_skeleton_to_node);
}

bool GLTFState::get_create_animations() {
return create_animations;
}

void GLTFState::set_create_animations(bool p_create_animations) {
create_animations = p_create_animations;
}

Array GLTFState::get_animations() {
return GLTFTemplateConvert::to_array(animations);
}
Expand Down
4 changes: 4 additions & 0 deletions modules/gltf/gltf_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class GLTFState : public Resource {
bool use_named_skin_binds = false;
bool use_khr_texture_transform = false;
bool discard_meshes_and_materials = false;
bool create_animations = true;

Vector<Ref<GLTFNode>> nodes;
Vector<Vector<uint8_t>> buffers;
Expand Down Expand Up @@ -168,6 +169,9 @@ class GLTFState : public Resource {
Dictionary get_skeleton_to_node();
void set_skeleton_to_node(Dictionary p_skeleton_to_node);

bool get_create_animations();
void set_create_animations(bool p_create_animations);

Array get_animations();
void set_animations(Array p_animations);

Expand Down

0 comments on commit 805ffdf

Please sign in to comment.