summaryrefslogtreecommitdiff
path: root/modules/gltf/gltf_document.cpp
diff options
context:
space:
mode:
authorK. S. Ernest (iFire) Lee <ernest.lee@chibifire.com>2021-10-13 02:18:43 -0700
committerK. S. Ernest (iFire) Lee <ernest.lee@chibifire.com>2021-10-13 15:18:27 -0700
commite3d118991672d7c02a1a5b538c9912c76916c9d7 (patch)
tree8fbd5dae740c99c98b357c5c2ce4c2095442021f /modules/gltf/gltf_document.cpp
parentd956904091b620bea5ee6eec9bd1413a97bba69a (diff)
Restore gltf animation export after split.
Diffstat (limited to 'modules/gltf/gltf_document.cpp')
-rw-r--r--modules/gltf/gltf_document.cpp89
1 files changed, 37 insertions, 52 deletions
diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp
index 6fd542ca68..11f30be5a4 100644
--- a/modules/gltf/gltf_document.cpp
+++ b/modules/gltf/gltf_document.cpp
@@ -6192,11 +6192,7 @@ void GLTFDocument::_process_mesh_instances(Ref<GLTFState> state, Node *scene_roo
}
}
-GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state, GLTFAnimation::Track p_track, Ref<Animation> p_animation, Transform3D p_bone_rest, int32_t p_track_i, GLTFNodeIndex p_node_i) {
-#ifndef _MSC_VER
-#warning this needs to be redone
-#endif
-#if 0
+GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state, GLTFAnimation::Track p_track, Ref<Animation> p_animation, int32_t p_track_i, GLTFNodeIndex p_node_i) {
Animation::InterpolationType interpolation = p_animation->track_get_interpolation_type(p_track_i);
GLTFAnimation::Interpolation gltf_interpolation = GLTFAnimation::INTERP_LINEAR;
@@ -6215,35 +6211,35 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state
for (int32_t key_i = 0; key_i < key_count; key_i++) {
times.write[key_i] = p_animation->track_get_key_time(p_track_i, key_i);
}
-
-
- if (track_type == Animation::TYPE_TRANSFORM3D) {
- p_track.position_track.times = times;
- p_track.position_track.interpolation = gltf_interpolation;
- p_track.rotation_track.times = times;
- p_track.rotation_track.interpolation = gltf_interpolation;
+ if (track_type == Animation::TYPE_SCALE_3D) {
p_track.scale_track.times = times;
p_track.scale_track.interpolation = gltf_interpolation;
-
p_track.scale_track.values.resize(key_count);
- p_track.scale_track.interpolation = gltf_interpolation;
+ for (int32_t key_i = 0; key_i < key_count; key_i++) {
+ Vector3 scale;
+ Error err = p_animation->scale_track_get_key(p_track_i, key_i, &scale);
+ ERR_CONTINUE(err != OK);
+ p_track.scale_track.values.write[key_i] = scale;
+ }
+ } else if (track_type == Animation::TYPE_POSITION_3D) {
+ p_track.position_track.times = times;
p_track.position_track.values.resize(key_count);
p_track.position_track.interpolation = gltf_interpolation;
- p_track.rotation_track.values.resize(key_count);
- p_track.rotation_track.interpolation = gltf_interpolation;
for (int32_t key_i = 0; key_i < key_count; key_i++) {
Vector3 position;
+ Error err = p_animation->position_track_get_key(p_track_i, key_i, &position);
+ ERR_CONTINUE(err != OK);
+ p_track.position_track.values.write[key_i] = position;
+ }
+ } else if (track_type == Animation::TYPE_ROTATION_3D) {
+ p_track.rotation_track.times = times;
+ p_track.rotation_track.interpolation = gltf_interpolation;
+ p_track.rotation_track.values.resize(key_count);
+ for (int32_t key_i = 0; key_i < key_count; key_i++) {
Quaternion rotation;
- Vector3 scale;
- Error err = p_animation->transform_track_get_key(p_track_i, key_i, &position, &rotation, &scale);
+ Error err = p_animation->rotation_track_get_key(p_track_i, key_i, &rotation);
ERR_CONTINUE(err != OK);
- Transform3D xform;
- xform.basis.set_quaternion_scale(rotation, scale);
- xform.origin = position;
- xform = p_bone_rest * xform;
- p_track.position_track.values.write[key_i] = xform.get_origin();
- p_track.rotation_track.values.write[key_i] = xform.basis.get_rotation_quaternion();
- p_track.scale_track.values.write[key_i] = xform.basis.get_scale();
+ p_track.rotation_track.values.write[key_i] = rotation;
}
} else if (path.find(":transform") != -1) {
p_track.position_track.times = times;
@@ -6335,13 +6331,10 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state
Vector3 bezier_track = p_track.scale_track.values[key_i];
if (path.find("/scale:x") != -1) {
bezier_track.x = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
- bezier_track.x = p_bone_rest.affine_inverse().basis.get_scale().x * bezier_track.x;
} else if (path.find("/scale:y") != -1) {
bezier_track.y = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
- bezier_track.y = p_bone_rest.affine_inverse().basis.get_scale().y * bezier_track.y;
} else if (path.find("/scale:z") != -1) {
bezier_track.z = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
- bezier_track.z = p_bone_rest.affine_inverse().basis.get_scale().z * bezier_track.z;
}
p_track.scale_track.values.write[key_i] = bezier_track;
}
@@ -6364,19 +6357,15 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state
Vector3 bezier_track = p_track.position_track.values[key_i];
if (path.find("/position:x") != -1) {
bezier_track.x = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
- bezier_track.x = p_bone_rest.affine_inverse().origin.x * bezier_track.x;
} else if (path.find("/position:y") != -1) {
bezier_track.y = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
- bezier_track.y = p_bone_rest.affine_inverse().origin.y * bezier_track.y;
} else if (path.find("/position:z") != -1) {
bezier_track.z = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
- bezier_track.z = p_bone_rest.affine_inverse().origin.z * bezier_track.z;
}
p_track.position_track.values.write[key_i] = bezier_track;
}
}
}
-#endif
return p_track;
}
@@ -6403,7 +6392,7 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap,
if (position_track_i) {
track = position_track_i->get();
}
- track = _convert_animation_track(state, track, animation, Transform3D(), track_i, node_index);
+ track = _convert_animation_track(state, track, animation, track_i, node_index);
gltf_animation->get_tracks().insert(node_index, track);
}
}
@@ -6419,7 +6408,7 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap,
if (rotation_degree_track_i) {
track = rotation_degree_track_i->get();
}
- track = _convert_animation_track(state, track, animation, Transform3D(), track_i, node_index);
+ track = _convert_animation_track(state, track, animation, track_i, node_index);
gltf_animation->get_tracks().insert(node_index, track);
}
}
@@ -6435,7 +6424,7 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap,
if (scale_track_i) {
track = scale_track_i->get();
}
- track = _convert_animation_track(state, track, animation, Transform3D(), track_i, node_index);
+ track = _convert_animation_track(state, track, animation, track_i, node_index);
gltf_animation->get_tracks().insert(node_index, track);
}
}
@@ -6446,7 +6435,7 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap,
for (const KeyValue<GLTFNodeIndex, Node *> &transform_track_i : state->scene_nodes) {
if (transform_track_i.value == node) {
GLTFAnimation::Track track;
- track = _convert_animation_track(state, track, animation, Transform3D(), track_i, transform_track_i.key);
+ track = _convert_animation_track(state, track, animation, track_i, transform_track_i.key);
gltf_animation->get_tracks().insert(transform_track_i.key, track);
}
}
@@ -6523,7 +6512,6 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap,
Ref<GLTFSkeleton> skeleton_gltf = state->skeletons[skeleton_gltf_i];
int32_t bone = skeleton->find_bone(suffix);
ERR_CONTINUE(bone == -1);
- Transform3D xform = skeleton->get_bone_rest(bone);
if (!skeleton_gltf->godot_bone_node.has(bone)) {
continue;
}
@@ -6533,27 +6521,24 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap,
if (property_track_i) {
track = property_track_i->get();
}
- track = _convert_animation_track(state, track, animation, xform, track_i, node_i);
+ track = _convert_animation_track(state, track, animation, track_i, node_i);
gltf_animation->get_tracks()[node_i] = track;
}
}
} else if (String(orig_track_path).find(":") == -1) {
ERR_CONTINUE(!ap->get_parent());
- for (int32_t node_i = 0; node_i < ap->get_parent()->get_child_count(); node_i++) {
- const Node *child = ap->get_parent()->get_child(node_i);
- const Node *node = child->get_node_or_null(orig_track_path);
- for (const KeyValue<GLTFNodeIndex, Node *> &scene_node_i : state->scene_nodes) {
- if (scene_node_i.value == node) {
- GLTFNodeIndex node_index = scene_node_i.key;
- Map<int, GLTFAnimation::Track>::Element *node_track_i = gltf_animation->get_tracks().find(node_index);
- GLTFAnimation::Track track;
- if (node_track_i) {
- track = node_track_i->get();
- }
- track = _convert_animation_track(state, track, animation, Transform3D(), track_i, node_index);
- gltf_animation->get_tracks().insert(node_index, track);
- break;
+ Node *godot_node = ap->get_parent()->get_node_or_null(orig_track_path);
+ for (const KeyValue<GLTFNodeIndex, Node *> &scene_node_i : state->scene_nodes) {
+ if (scene_node_i.value == godot_node) {
+ GLTFNodeIndex node_i = scene_node_i.key;
+ Map<int, GLTFAnimation::Track>::Element *node_track_i = gltf_animation->get_tracks().find(node_i);
+ GLTFAnimation::Track track;
+ if (node_track_i) {
+ track = node_track_i->get();
}
+ track = _convert_animation_track(state, track, animation, track_i, node_i);
+ gltf_animation->get_tracks()[node_i] = track;
+ break;
}
}
}