summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/animation.cpp24
-rw-r--r--scene/resources/animation.h2
-rw-r--r--scene/resources/baked_light.cpp8
-rw-r--r--scene/resources/mesh.cpp10
-rw-r--r--scene/resources/mesh_library.cpp8
-rw-r--r--scene/resources/packed_scene.cpp9
-rw-r--r--scene/resources/sample_library.cpp4
-rw-r--r--scene/resources/theme.cpp12
8 files changed, 45 insertions, 32 deletions
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index 095406dad9..afd4dc5304 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -42,8 +42,8 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) {
set_step(p_value);
else if (name.begins_with("tracks/")) {
- int track=name.get_slice("/",1).to_int();
- String what=name.get_slice("/",2);
+ int track=name.get_slicec('/',1).to_int();
+ String what=name.get_slicec('/',2);
if (tracks.size()==track && what=="type") {
@@ -257,8 +257,8 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const {
r_ret= step;
else if (name.begins_with("tracks/")) {
- int track=name.get_slice("/",1).to_int();
- String what=name.get_slice("/",2);
+ int track=name.get_slicec('/',1).to_int();
+ String what=name.get_slicec('/',2);
ERR_FAIL_INDEX_V( track, tracks.size(), false );
if (what=="type") {
@@ -1718,7 +1718,7 @@ void Animation::clear() {
-bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0,const TKey<TransformKey> &t1, const TKey<TransformKey> &t2, float p_alowed_linear_err,float p_alowed_angular_err,float p_max_optimizable_angle) {
+bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0,const TKey<TransformKey> &t1, const TKey<TransformKey> &t2, float p_alowed_linear_err,float p_alowed_angular_err,float p_max_optimizable_angle,const Vector3& p_norm) {
real_t c = (t1.time-t0.time)/(t2.time-t0.time);
@@ -1754,6 +1754,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0,const
return false; //beyond allowed error for colinearity
}
+ if (p_norm!=Vector3() && Math::acos(pd.normalized().dot(p_norm))>p_alowed_angular_err)
+ return false;
+
t[0] = (d1-d0)/(d2-d0);
}
}
@@ -1905,16 +1908,21 @@ void Animation::_transform_track_optimize(int p_idx,float p_alowed_linear_err,fl
bool prev_erased=false;
TKey<TransformKey> first_erased;
+ Vector3 norm;
+
for(int i=1;i<tt->transforms.size()-1;i++) {
TKey<TransformKey> &t0 = tt->transforms[i-1];
TKey<TransformKey> &t1 = tt->transforms[i];
TKey<TransformKey> &t2 = tt->transforms[i+1];
- bool erase = _transform_track_optimize_key(t0,t1,t2,p_alowed_linear_err,p_alowed_angular_err,p_max_optimizable_angle);
+ bool erase = _transform_track_optimize_key(t0,t1,t2,p_alowed_linear_err,p_alowed_angular_err,p_max_optimizable_angle,norm);
+ if (erase && !prev_erased) {
+ norm=(t2.value.loc-t1.value.loc).normalized();
+ }
- if (prev_erased && !_transform_track_optimize_key(t0,first_erased,t2,p_alowed_linear_err,p_alowed_angular_err,p_max_optimizable_angle)) {
+ if (prev_erased && !_transform_track_optimize_key(t0,first_erased,t2,p_alowed_linear_err,p_alowed_angular_err,p_max_optimizable_angle,norm)) {
//avoid error to go beyond first erased key
erase=false;
}
@@ -1932,9 +1940,11 @@ void Animation::_transform_track_optimize(int p_idx,float p_alowed_linear_err,fl
} else {
prev_erased=false;
+ norm=Vector3();
}
+
// print_line(itos(i)+" could be eliminated: "+rtos(tr));
//}
}
diff --git a/scene/resources/animation.h b/scene/resources/animation.h
index d4042646fb..256826a4bb 100644
--- a/scene/resources/animation.h
+++ b/scene/resources/animation.h
@@ -204,7 +204,7 @@ private:
return idxr;
}
- bool _transform_track_optimize_key(const TKey<TransformKey> &t0,const TKey<TransformKey> &t1, const TKey<TransformKey> &t2, float p_alowed_linear_err,float p_alowed_angular_err,float p_max_optimizable_angle);
+ bool _transform_track_optimize_key(const TKey<TransformKey> &t0,const TKey<TransformKey> &t1, const TKey<TransformKey> &t2, float p_alowed_linear_err,float p_alowed_angular_err,float p_max_optimizable_angle,const Vector3& p_norm);
void _transform_track_optimize(int p_idx, float p_allowed_err=0.05, float p_alowed_angular_err=0.01,float p_max_optimizable_angle=Math_PI*0.125);
protected:
diff --git a/scene/resources/baked_light.cpp b/scene/resources/baked_light.cpp
index 226edec9ae..31282a0274 100644
--- a/scene/resources/baked_light.cpp
+++ b/scene/resources/baked_light.cpp
@@ -311,11 +311,11 @@ bool BakedLight::_set(const StringName& p_name, const Variant& p_value) {
String n = p_name;
if (!n.begins_with("lightmap"))
return false;
- int idx = n.get_slice("/",1).to_int();
+ int idx = n.get_slicec('/',1).to_int();
ERR_FAIL_COND_V(idx<0,false);
ERR_FAIL_COND_V(idx>lightmaps.size(),false);
- String what = n.get_slice("/",2);
+ String what = n.get_slicec('/',2);
Ref<Texture> tex;
Size2 gens;
@@ -343,11 +343,11 @@ bool BakedLight::_get(const StringName& p_name,Variant &r_ret) const{
String n = p_name;
if (!n.begins_with("lightmap"))
return false;
- int idx = n.get_slice("/",1).to_int();
+ int idx = n.get_slicec('/',1).to_int();
ERR_FAIL_COND_V(idx<0,false);
ERR_FAIL_COND_V(idx>lightmaps.size(),false);
- String what = n.get_slice("/",2);
+ String what = n.get_slicec('/',2);
if (what=="texture") {
if (idx==lightmaps.size())
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index 039a4788d5..8cb0904415 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -99,7 +99,7 @@ bool Mesh::_set(const StringName& p_name, const Variant& p_value) {
if (sl==-1)
return false;
int idx=sname.substr(8,sl-8).to_int()-1;
- String what = sname.get_slice("/",1);
+ String what = sname.get_slicec('/',1);
if (what=="material")
surface_set_material(idx,p_value);
else if (what=="name")
@@ -117,8 +117,8 @@ bool Mesh::_set(const StringName& p_name, const Variant& p_value) {
return false;
- int idx=sname.get_slice("/",1).to_int();
- String what=sname.get_slice("/",2);
+ int idx=sname.get_slicec('/',1).to_int();
+ String what=sname.get_slicec('/',2);
if (idx==surfaces.size()) {
@@ -180,7 +180,7 @@ bool Mesh::_get(const StringName& p_name,Variant &r_ret) const {
if (sl==-1)
return false;
int idx=sname.substr(8,sl-8).to_int()-1;
- String what = sname.get_slice("/",1);
+ String what = sname.get_slicec('/',1);
if (what=="material")
r_ret=surface_get_material(idx);
else if (what=="name")
@@ -195,7 +195,7 @@ bool Mesh::_get(const StringName& p_name,Variant &r_ret) const {
return false;
- int idx=sname.get_slice("/",1).to_int();
+ int idx=sname.get_slicec('/',1).to_int();
ERR_FAIL_INDEX_V(idx,surfaces.size(),false);
Dictionary d;
diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp
index ffa29572ff..5ebab9be76 100644
--- a/scene/resources/mesh_library.cpp
+++ b/scene/resources/mesh_library.cpp
@@ -35,8 +35,8 @@ bool MeshLibrary::_set(const StringName& p_name, const Variant& p_value) {
String name=p_name;
if (name.begins_with("item/")) {
- int idx = name.get_slice("/",1).to_int();
- String what = name.get_slice("/",2);
+ int idx = name.get_slicec('/',1).to_int();
+ String what = name.get_slicec('/',2);
if (!item_map.has(idx))
create_item(idx);
@@ -60,9 +60,9 @@ bool MeshLibrary::_set(const StringName& p_name, const Variant& p_value) {
bool MeshLibrary::_get(const StringName& p_name,Variant &r_ret) const {
String name=p_name;
- int idx = name.get_slice("/",1).to_int();
+ int idx = name.get_slicec('/',1).to_int();
ERR_FAIL_COND_V(!item_map.has(idx),false);
- String what = name.get_slice("/",2);
+ String what = name.get_slicec('/',2);
if(what=="name")
r_ret= get_item_name(idx);
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index a1cb1205e5..b6082c3a76 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -53,7 +53,7 @@ Node *PackedScene::instance(bool p_gen_edit_state) const {
if (prop_count)
props=&variants[0];
- Vector<Variant> properties;
+ //Vector<Variant> properties;
const NodeData *nd = &nodes[0];
@@ -257,10 +257,13 @@ Error PackedScene::_parse_node(Node *p_owner,Node *p_node,int p_parent_idx, Map<
String name = E->get().name;
Variant value = p_node->get( E->get().name );
- if (E->get().usage & PROPERTY_USAGE_STORE_IF_NONZERO && value.is_zero()) {
+ if (nd.instance<0 && ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONZERO) && value.is_zero()) || ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONONE) && value.is_one())) {
continue;
}
+ print_line("PASSED!");
+ print_line("at: "+String(p_node->get_name())+"::"+name+": - nz: "+itos(E->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO)+" no: "+itos(E->get().usage&PROPERTY_USAGE_STORE_IF_NONONE));
+ print_line("value: "+String(value)+" is zero: "+itos(value.is_zero())+" is one" +itos(value.is_one()));
if (nd.instance>=0) {
//only save changed properties in instance
@@ -278,7 +281,7 @@ Error PackedScene::_parse_node(Node *p_owner,Node *p_node,int p_parent_idx, Map<
continue;
}
- if (instance_state[name]==value) {
+ if (instance_state.has(name) && instance_state[name]==value) {
continue;
}
diff --git a/scene/resources/sample_library.cpp b/scene/resources/sample_library.cpp
index 6bb9bc0d06..ffcaa1e675 100644
--- a/scene/resources/sample_library.cpp
+++ b/scene/resources/sample_library.cpp
@@ -34,7 +34,7 @@ bool SampleLibrary::_set(const StringName& p_name, const Variant& p_value) {
if (String(p_name).begins_with("samples/")) {
- String name=String(p_name).get_slice("/",1);
+ String name=String(p_name).get_slicec('/',1);
if (p_value.get_type()==Variant::NIL)
sample_map.erase(name);
else {
@@ -66,7 +66,7 @@ bool SampleLibrary::_get(const StringName& p_name,Variant &r_ret) const {
if (String(p_name).begins_with("samples/")) {
- String name=String(p_name).get_slice("/",1);
+ String name=String(p_name).get_slicec('/',1);
if(sample_map.has(name)) {
Dictionary d;
d["sample"]=sample_map[name].sample;
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp
index 21bdb6c0ab..3060fe41b4 100644
--- a/scene/resources/theme.cpp
+++ b/scene/resources/theme.cpp
@@ -40,9 +40,9 @@ bool Theme::_set(const StringName& p_name, const Variant& p_value) {
if (sname.find("/")!=-1) {
- String type=sname.get_slice("/",1);
- String node_type=sname.get_slice("/",0);
- String name=sname.get_slice("/",2);
+ String type=sname.get_slicec('/',1);
+ String node_type=sname.get_slicec('/',0);
+ String name=sname.get_slicec('/',2);
if (type=="icons") {
@@ -75,9 +75,9 @@ bool Theme::_get(const StringName& p_name,Variant &r_ret) const {
if (sname.find("/")!=-1) {
- String type=sname.get_slice("/",1);
- String node_type=sname.get_slice("/",0);
- String name=sname.get_slice("/",2);
+ String type=sname.get_slicec('/',1);
+ String node_type=sname.get_slicec('/',0);
+ String name=sname.get_slicec('/',2);
if (type=="icons") {