summaryrefslogtreecommitdiff
path: root/scene/resources/animation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/animation.cpp')
-rw-r--r--scene/resources/animation.cpp175
1 files changed, 95 insertions, 80 deletions
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index 1d15b6f2bc..5b9baa6a67 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -72,6 +72,8 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) {
track_set_path(track,p_value);
else if (what=="interp")
track_set_interpolation_type(track,InterpolationType(p_value.operator int()));
+ else if (what=="loop_wrap")
+ track_set_interpolation_loop_wrap(track,p_value);
else if (what=="imported")
track_set_imported(track,p_value);
else if (what == "keys" || what=="key_values") {
@@ -79,14 +81,14 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) {
if (track_get_type(track)==TYPE_TRANSFORM) {
TransformTrack *tt = static_cast<TransformTrack*>(tracks[track]);
- DVector<float> values=p_value;
+ PoolVector<float> values=p_value;
int vcount=values.size();
#if 0 // old compatibility hack
if ((vcount%11) == 0) {
- DVector<float>::Read r = values.read();
+ PoolVector<float>::Read r = values.read();
tt->transforms.resize(vcount/11);
@@ -121,7 +123,7 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) {
#endif
ERR_FAIL_COND_V(vcount%12,false); // shuld be multiple of 11
- DVector<float>::Read r = values.read();
+ PoolVector<float>::Read r = values.read();
tt->transforms.resize(vcount/12);
@@ -172,7 +174,7 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) {
- DVector<float> times=d["times"];
+ PoolVector<float> times=d["times"];
Array values=d["values"];
ERR_FAIL_COND_V(times.size()!=values.size(),false);
@@ -181,7 +183,7 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) {
int valcount=times.size();
- DVector<float>::Read rt = times.read();
+ PoolVector<float>::Read rt = times.read();
vt->values.resize(valcount);
@@ -193,10 +195,10 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) {
if (d.has("transitions")) {
- DVector<float> transitions = d["transitions"];
+ PoolVector<float> transitions = d["transitions"];
ERR_FAIL_COND_V(transitions.size()!=valcount,false);
- DVector<float>::Read rtr = transitions.read();
+ PoolVector<float>::Read rtr = transitions.read();
for(int i=0;i<valcount;i++) {
@@ -218,7 +220,7 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) {
ERR_FAIL_COND_V(!d.has("times"),false);
ERR_FAIL_COND_V(!d.has("values"),false);
- DVector<float> times=d["times"];
+ PoolVector<float> times=d["times"];
Array values=d["values"];
ERR_FAIL_COND_V(times.size()!=values.size(),false);
@@ -227,7 +229,7 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) {
int valcount=times.size();
- DVector<float>::Read rt = times.read();
+ PoolVector<float>::Read rt = times.read();
for(int i=0;i<valcount;i++) {
@@ -236,10 +238,10 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) {
if (d.has("transitions")) {
- DVector<float> transitions = d["transitions"];
+ PoolVector<float> transitions = d["transitions"];
ERR_FAIL_COND_V(transitions.size()!=valcount,false);
- DVector<float>::Read rtr = transitions.read();
+ PoolVector<float>::Read rtr = transitions.read();
for(int i=0;i<valcount;i++) {
@@ -291,17 +293,19 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const {
r_ret=track_get_path(track);
else if (what=="interp")
r_ret = track_get_interpolation_type(track);
+ else if (what=="loop_wrap")
+ r_ret = track_get_interpolation_loop_wrap(track);
else if (what=="imported")
r_ret = track_is_imported(track);
else if (what=="keys") {
if (track_get_type(track)==TYPE_TRANSFORM) {
- DVector<real_t> keys;
+ PoolVector<real_t> keys;
int kk=track_get_key_count(track);
keys.resize(kk*12);
- DVector<real_t>::Write w = keys.write();
+ PoolVector<real_t>::Write w = keys.write();
int idx=0;
for(int i=0;i<track_get_key_count(track);i++) {
@@ -327,7 +331,7 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const {
w[idx++]=scale.z;
}
- w = DVector<real_t>::Write();
+ w = PoolVector<real_t>::Write();
r_ret=keys;
return true;
@@ -338,8 +342,8 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const {
Dictionary d;
- DVector<float> key_times;
- DVector<float> key_transitions;
+ PoolVector<float> key_times;
+ PoolVector<float> key_transitions;
Array key_values;
int kk=vt->values.size();
@@ -348,8 +352,8 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const {
key_transitions.resize(kk);
key_values.resize(kk);
- DVector<float>::Write wti=key_times.write();
- DVector<float>::Write wtr=key_transitions.write();
+ PoolVector<float>::Write wti=key_times.write();
+ PoolVector<float>::Write wtr=key_transitions.write();
int idx=0;
@@ -363,8 +367,8 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const {
idx++;
}
- wti=DVector<float>::Write();
- wtr=DVector<float>::Write();
+ wti=PoolVector<float>::Write();
+ wtr=PoolVector<float>::Write();
d["times"]=key_times;
d["transitions"]=key_transitions;
@@ -382,8 +386,8 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const {
Dictionary d;
- DVector<float> key_times;
- DVector<float> key_transitions;
+ PoolVector<float> key_times;
+ PoolVector<float> key_transitions;
Array key_values;
int kk=track_get_key_count(track);
@@ -392,8 +396,8 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const {
key_transitions.resize(kk);
key_values.resize(kk);
- DVector<float>::Write wti=key_times.write();
- DVector<float>::Write wtr=key_transitions.write();
+ PoolVector<float>::Write wti=key_times.write();
+ PoolVector<float>::Write wtr=key_transitions.write();
int idx=0;
for(int i=0;i<track_get_key_count(track);i++) {
@@ -404,8 +408,8 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const {
idx++;
}
- wti=DVector<float>::Write();
- wtr=DVector<float>::Write();
+ wti=PoolVector<float>::Write();
+ wtr=PoolVector<float>::Write();
d["times"]=key_times;
d["transitions"]=key_transitions;
@@ -440,6 +444,7 @@ void Animation::_get_property_list( List<PropertyInfo> *p_list) const {
p_list->push_back( PropertyInfo( Variant::STRING, "tracks/"+itos(i)+"/type", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) );
p_list->push_back( PropertyInfo( Variant::NODE_PATH, "tracks/"+itos(i)+"/path", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) );
p_list->push_back( PropertyInfo( Variant::INT, "tracks/"+itos(i)+"/interp", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) );
+ p_list->push_back( PropertyInfo( Variant::BOOL, "tracks/"+itos(i)+"/loop_wrap", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) );
p_list->push_back( PropertyInfo( Variant::BOOL, "tracks/"+itos(i)+"/imported", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) );
p_list->push_back( PropertyInfo( Variant::ARRAY, "tracks/"+itos(i)+"/keys", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) );
}
@@ -559,6 +564,19 @@ Animation::InterpolationType Animation::track_get_interpolation_type(int p_track
return tracks[p_track]->interpolation;
}
+void Animation::track_set_interpolation_loop_wrap(int p_track,bool p_enable) {
+ ERR_FAIL_INDEX(p_track, tracks.size());
+ tracks[p_track]->loop_wrap=p_enable;
+ emit_changed();
+
+}
+
+bool Animation::track_get_interpolation_loop_wrap(int p_track) const{
+
+ ERR_FAIL_INDEX_V(p_track, tracks.size(),INTERPOLATION_NEAREST);
+ return tracks[p_track]->loop_wrap;
+
+}
// transform
/*
@@ -1185,14 +1203,14 @@ Variant Animation::_cubic_interpolate( const Variant& p_pre_a,const Variant& p_a
return a.cubic_slerp(b,pa,pb,p_c);
} break;
- case Variant::_AABB: {
+ case Variant::RECT3: {
- AABB a=p_a;
- AABB b=p_b;
- AABB pa=p_pre_a;
- AABB pb=p_post_b;
+ Rect3 a=p_a;
+ Rect3 b=p_b;
+ Rect3 pa=p_pre_a;
+ Rect3 pb=p_post_b;
- return AABB(
+ return Rect3(
a.pos.cubic_interpolate(b.pos,pa.pos,pb.pos,p_c),
a.size.cubic_interpolate(b.size,pa.size,pb.size,p_c)
);
@@ -1211,7 +1229,7 @@ float Animation::_cubic_interpolate( const float& p_pre_a,const float& p_a, cons
}
template<class T>
-T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, InterpolationType p_interp, bool *p_ok) const {
+T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, InterpolationType p_interp, bool p_loop_wrap,bool *p_ok) const {
int len=_find( p_keys, length )+1; // try to find last key (there may be more past the end)
@@ -1239,7 +1257,7 @@ T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, Inter
float c=0;
// prepare for all cases of interpolation
- if (loop) {
+ if (loop && p_loop_wrap) {
// loop
if (idx>=0) {
@@ -1363,7 +1381,7 @@ Error Animation::transform_track_interpolate(int p_track, float p_time, Vector3
bool ok;
- TransformKey tk = _interpolate( tt->transforms, p_time, tt->interpolation, &ok );
+ TransformKey tk = _interpolate( tt->transforms, p_time, tt->interpolation, tt->loop_wrap, &ok );
if (!ok) // ??
return ERR_UNAVAILABLE;
@@ -1391,7 +1409,7 @@ Variant Animation::value_track_interpolate(int p_track, float p_time) const {
bool ok;
- Variant res = _interpolate( vt->values, p_time, vt->update_mode==UPDATE_CONTINUOUS?vt->interpolation:INTERPOLATION_NEAREST, &ok );
+ Variant res = _interpolate( vt->values, p_time, vt->update_mode==UPDATE_CONTINUOUS?vt->interpolation:INTERPOLATION_NEAREST,vt->loop_wrap, &ok );
if (ok) {
@@ -1680,59 +1698,61 @@ float Animation::get_step() const{
void Animation::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("add_track","type","at_pos"),&Animation::add_track,DEFVAL(-1));
- ObjectTypeDB::bind_method(_MD("remove_track","idx"),&Animation::remove_track);
- ObjectTypeDB::bind_method(_MD("get_track_count"),&Animation::get_track_count);
- ObjectTypeDB::bind_method(_MD("track_get_type","idx"),&Animation::track_get_type);
- ObjectTypeDB::bind_method(_MD("track_get_path","idx"),&Animation::track_get_path);
- ObjectTypeDB::bind_method(_MD("track_set_path","idx","path"),&Animation::track_set_path);
- ObjectTypeDB::bind_method(_MD("find_track","path"),&Animation::find_track);
+ ClassDB::bind_method(_MD("add_track","type","at_pos"),&Animation::add_track,DEFVAL(-1));
+ ClassDB::bind_method(_MD("remove_track","idx"),&Animation::remove_track);
+ ClassDB::bind_method(_MD("get_track_count"),&Animation::get_track_count);
+ ClassDB::bind_method(_MD("track_get_type","idx"),&Animation::track_get_type);
+ ClassDB::bind_method(_MD("track_get_path","idx"),&Animation::track_get_path);
+ ClassDB::bind_method(_MD("track_set_path","idx","path"),&Animation::track_set_path);
+ ClassDB::bind_method(_MD("find_track","path"),&Animation::find_track);
- ObjectTypeDB::bind_method(_MD("track_move_up","idx"),&Animation::track_move_up);
- ObjectTypeDB::bind_method(_MD("track_move_down","idx"),&Animation::track_move_down);
+ ClassDB::bind_method(_MD("track_move_up","idx"),&Animation::track_move_up);
+ ClassDB::bind_method(_MD("track_move_down","idx"),&Animation::track_move_down);
- ObjectTypeDB::bind_method(_MD("track_set_imported","idx","imported"),&Animation::track_set_imported);
- ObjectTypeDB::bind_method(_MD("track_is_imported","idx"),&Animation::track_is_imported);
+ ClassDB::bind_method(_MD("track_set_imported","idx","imported"),&Animation::track_set_imported);
+ ClassDB::bind_method(_MD("track_is_imported","idx"),&Animation::track_is_imported);
- ObjectTypeDB::bind_method(_MD("transform_track_insert_key","idx","time","loc","rot","scale"),&Animation::transform_track_insert_key);
- ObjectTypeDB::bind_method(_MD("track_insert_key","idx","time","key","transition"),&Animation::track_insert_key,DEFVAL(1));
- ObjectTypeDB::bind_method(_MD("track_remove_key","idx","key_idx"),&Animation::track_remove_key);
- ObjectTypeDB::bind_method(_MD("track_remove_key_at_pos","idx","pos"),&Animation::track_remove_key_at_pos);
- ObjectTypeDB::bind_method(_MD("track_set_key_value","idx","key","value"),&Animation::track_set_key_value);
- ObjectTypeDB::bind_method(_MD("track_set_key_transition","idx","key_idx","transition"),&Animation::track_set_key_transition);
- ObjectTypeDB::bind_method(_MD("track_get_key_transition","idx","key_idx"),&Animation::track_get_key_transition);
+ ClassDB::bind_method(_MD("transform_track_insert_key","idx","time","loc","rot","scale"),&Animation::transform_track_insert_key);
+ ClassDB::bind_method(_MD("track_insert_key","idx","time","key","transition"),&Animation::track_insert_key,DEFVAL(1));
+ ClassDB::bind_method(_MD("track_remove_key","idx","key_idx"),&Animation::track_remove_key);
+ ClassDB::bind_method(_MD("track_remove_key_at_pos","idx","pos"),&Animation::track_remove_key_at_pos);
+ ClassDB::bind_method(_MD("track_set_key_value","idx","key","value"),&Animation::track_set_key_value);
+ ClassDB::bind_method(_MD("track_set_key_transition","idx","key_idx","transition"),&Animation::track_set_key_transition);
+ ClassDB::bind_method(_MD("track_get_key_transition","idx","key_idx"),&Animation::track_get_key_transition);
- ObjectTypeDB::bind_method(_MD("track_get_key_count","idx"),&Animation::track_get_key_count);
- ObjectTypeDB::bind_method(_MD("track_get_key_value","idx","key_idx"),&Animation::track_get_key_value);
- ObjectTypeDB::bind_method(_MD("track_get_key_time","idx","key_idx"),&Animation::track_get_key_time);
- ObjectTypeDB::bind_method(_MD("track_find_key","idx","time","exact"),&Animation::track_find_key,DEFVAL(false));
+ ClassDB::bind_method(_MD("track_get_key_count","idx"),&Animation::track_get_key_count);
+ ClassDB::bind_method(_MD("track_get_key_value","idx","key_idx"),&Animation::track_get_key_value);
+ ClassDB::bind_method(_MD("track_get_key_time","idx","key_idx"),&Animation::track_get_key_time);
+ ClassDB::bind_method(_MD("track_find_key","idx","time","exact"),&Animation::track_find_key,DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("track_set_interpolation_type","idx","interpolation"),&Animation::track_set_interpolation_type);
- ObjectTypeDB::bind_method(_MD("track_get_interpolation_type","idx"),&Animation::track_get_interpolation_type);
+ ClassDB::bind_method(_MD("track_set_interpolation_type","idx","interpolation"),&Animation::track_set_interpolation_type);
+ ClassDB::bind_method(_MD("track_get_interpolation_type","idx"),&Animation::track_get_interpolation_type);
+ ClassDB::bind_method(_MD("track_set_interpolation_loop_wrap","idx","interpolation"),&Animation::track_set_interpolation_loop_wrap);
+ ClassDB::bind_method(_MD("track_get_interpolation_loop_wrap","idx"),&Animation::track_get_interpolation_loop_wrap);
- ObjectTypeDB::bind_method(_MD("transform_track_interpolate","idx","time_sec"),&Animation::_transform_track_interpolate);
- ObjectTypeDB::bind_method(_MD("value_track_set_update_mode","idx","mode"),&Animation::value_track_set_update_mode);
- ObjectTypeDB::bind_method(_MD("value_track_get_update_mode","idx"),&Animation::value_track_get_update_mode);
+ ClassDB::bind_method(_MD("transform_track_interpolate","idx","time_sec"),&Animation::_transform_track_interpolate);
+ ClassDB::bind_method(_MD("value_track_set_update_mode","idx","mode"),&Animation::value_track_set_update_mode);
+ ClassDB::bind_method(_MD("value_track_get_update_mode","idx"),&Animation::value_track_get_update_mode);
- ObjectTypeDB::bind_method(_MD("value_track_get_key_indices","idx","time_sec","delta"),&Animation::_value_track_get_key_indices);
+ ClassDB::bind_method(_MD("value_track_get_key_indices","idx","time_sec","delta"),&Animation::_value_track_get_key_indices);
- ObjectTypeDB::bind_method(_MD("method_track_get_key_indices","idx","time_sec","delta"),&Animation::_method_track_get_key_indices);
- ObjectTypeDB::bind_method(_MD("method_track_get_name","idx","key_idx"),&Animation::method_track_get_name);
- ObjectTypeDB::bind_method(_MD("method_track_get_params","idx","key_idx"),&Animation::method_track_get_params);
+ ClassDB::bind_method(_MD("method_track_get_key_indices","idx","time_sec","delta"),&Animation::_method_track_get_key_indices);
+ ClassDB::bind_method(_MD("method_track_get_name","idx","key_idx"),&Animation::method_track_get_name);
+ ClassDB::bind_method(_MD("method_track_get_params","idx","key_idx"),&Animation::method_track_get_params);
- ObjectTypeDB::bind_method(_MD("set_length","time_sec"),&Animation::set_length);
- ObjectTypeDB::bind_method(_MD("get_length"),&Animation::get_length);
+ ClassDB::bind_method(_MD("set_length","time_sec"),&Animation::set_length);
+ ClassDB::bind_method(_MD("get_length"),&Animation::get_length);
- ObjectTypeDB::bind_method(_MD("set_loop","enabled"),&Animation::set_loop);
- ObjectTypeDB::bind_method(_MD("has_loop"),&Animation::has_loop);
+ ClassDB::bind_method(_MD("set_loop","enabled"),&Animation::set_loop);
+ ClassDB::bind_method(_MD("has_loop"),&Animation::has_loop);
- ObjectTypeDB::bind_method(_MD("set_step","size_sec"),&Animation::set_step);
- ObjectTypeDB::bind_method(_MD("get_step"),&Animation::get_step);
+ ClassDB::bind_method(_MD("set_step","size_sec"),&Animation::set_step);
+ ClassDB::bind_method(_MD("get_step"),&Animation::get_step);
- ObjectTypeDB::bind_method(_MD("clear"),&Animation::clear);
+ ClassDB::bind_method(_MD("clear"),&Animation::clear);
BIND_CONSTANT( TYPE_VALUE );
BIND_CONSTANT( TYPE_TRANSFORM );
@@ -1985,11 +2005,6 @@ void Animation::_transform_track_optimize(int p_idx,float p_alowed_linear_err,fl
prev_erased=false;
norm=Vector3();
}
-
-
-
- // print_line(itos(i)+" could be eliminated: "+rtos(tr));
- //}
}