Skip to content

Commit 24f562b

Browse files
authored
Merge pull request #52024 from V-Sekai/anim-length
Calculate proper animation length.
2 parents c89a5fb + ffe54af commit 24f562b

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

scene/resources/animation.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
/*************************************************************************/
3030

3131
#include "animation.h"
32-
#include "scene/scene_string_names.h"
3332

3433
#include "core/math/geometry_3d.h"
34+
#include "scene/scene_string_names.h"
3535

3636
bool Animation::_set(const StringName &p_name, const Variant &p_value) {
3737
String name = p_name;
@@ -79,17 +79,16 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) {
7979
TransformTrack *tt = static_cast<TransformTrack *>(tracks[track]);
8080
Vector<real_t> values = p_value;
8181
int vcount = values.size();
82-
ERR_FAIL_COND_V(vcount % 12, false); // should be multiple of 12
82+
ERR_FAIL_COND_V(vcount % TRANSFORM_TRACK_SIZE, false);
8383

8484
const real_t *r = values.ptr();
8585

86-
int transform3d_size = (int)sizeof(Transform3D);
87-
88-
tt->transforms.resize(vcount / transform3d_size);
86+
int64_t count = vcount / TRANSFORM_TRACK_SIZE;
87+
tt->transforms.resize(count);
8988

90-
for (int i = 0; i < (vcount / transform3d_size); i++) {
89+
for (int i = 0; i < count; i++) {
9190
TKey<TransformKey> &tk = tt->transforms.write[i];
92-
const real_t *ofs = &r[i * 12];
91+
const real_t *ofs = &r[i * TRANSFORM_TRACK_SIZE];
9392
tk.time = ofs[0];
9493
tk.transition = ofs[1];
9594

@@ -356,7 +355,7 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const {
356355
if (track_get_type(track) == TYPE_TRANSFORM3D) {
357356
Vector<real_t> keys;
358357
int kk = track_get_key_count(track);
359-
keys.resize(kk * sizeof(Transform3D));
358+
keys.resize(kk * TRANSFORM_TRACK_SIZE);
360359

361360
real_t *w = keys.ptrw();
362361

scene/resources/animation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class Animation : public Resource {
9292
Vector3 scale;
9393
};
9494

95+
// Not necessarily the same size as Transform3D. The amount of numbers in Animation::Key and TransformKey.
96+
const int32_t TRANSFORM_TRACK_SIZE = 12;
97+
9598
/* TRANSFORM TRACK */
9699

97100
struct TransformTrack : public Track {

0 commit comments

Comments
 (0)