Calculate proper animation length.
This commit is contained in:
parent
583b6a594a
commit
ffe54af0db
@ -29,9 +29,9 @@
|
|||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
#include "animation.h"
|
#include "animation.h"
|
||||||
#include "scene/scene_string_names.h"
|
|
||||||
|
|
||||||
#include "core/math/geometry_3d.h"
|
#include "core/math/geometry_3d.h"
|
||||||
|
#include "scene/scene_string_names.h"
|
||||||
|
|
||||||
bool Animation::_set(const StringName &p_name, const Variant &p_value) {
|
bool Animation::_set(const StringName &p_name, const Variant &p_value) {
|
||||||
String name = p_name;
|
String name = p_name;
|
||||||
@ -79,17 +79,16 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) {
|
|||||||
TransformTrack *tt = static_cast<TransformTrack *>(tracks[track]);
|
TransformTrack *tt = static_cast<TransformTrack *>(tracks[track]);
|
||||||
Vector<real_t> values = p_value;
|
Vector<real_t> values = p_value;
|
||||||
int vcount = values.size();
|
int vcount = values.size();
|
||||||
ERR_FAIL_COND_V(vcount % 12, false); // should be multiple of 12
|
ERR_FAIL_COND_V(vcount % TRANSFORM_TRACK_SIZE, false);
|
||||||
|
|
||||||
const real_t *r = values.ptr();
|
const real_t *r = values.ptr();
|
||||||
|
|
||||||
int transform3d_size = (int)sizeof(Transform3D);
|
int64_t count = vcount / TRANSFORM_TRACK_SIZE;
|
||||||
|
tt->transforms.resize(count);
|
||||||
|
|
||||||
tt->transforms.resize(vcount / transform3d_size);
|
for (int i = 0; i < count; i++) {
|
||||||
|
|
||||||
for (int i = 0; i < (vcount / transform3d_size); i++) {
|
|
||||||
TKey<TransformKey> &tk = tt->transforms.write[i];
|
TKey<TransformKey> &tk = tt->transforms.write[i];
|
||||||
const real_t *ofs = &r[i * 12];
|
const real_t *ofs = &r[i * TRANSFORM_TRACK_SIZE];
|
||||||
tk.time = ofs[0];
|
tk.time = ofs[0];
|
||||||
tk.transition = ofs[1];
|
tk.transition = ofs[1];
|
||||||
|
|
||||||
@ -356,7 +355,7 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const {
|
|||||||
if (track_get_type(track) == TYPE_TRANSFORM3D) {
|
if (track_get_type(track) == TYPE_TRANSFORM3D) {
|
||||||
Vector<real_t> keys;
|
Vector<real_t> keys;
|
||||||
int kk = track_get_key_count(track);
|
int kk = track_get_key_count(track);
|
||||||
keys.resize(kk * sizeof(Transform3D));
|
keys.resize(kk * TRANSFORM_TRACK_SIZE);
|
||||||
|
|
||||||
real_t *w = keys.ptrw();
|
real_t *w = keys.ptrw();
|
||||||
|
|
||||||
|
@ -92,6 +92,9 @@ private:
|
|||||||
Vector3 scale;
|
Vector3 scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Not necessarily the same size as Transform3D. The amount of numbers in Animation::Key and TransformKey.
|
||||||
|
const int32_t TRANSFORM_TRACK_SIZE = 12;
|
||||||
|
|
||||||
/* TRANSFORM TRACK */
|
/* TRANSFORM TRACK */
|
||||||
|
|
||||||
struct TransformTrack : public Track {
|
struct TransformTrack : public Track {
|
||||||
|
Loading…
Reference in New Issue
Block a user