summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/animation.cpp16
-rw-r--r--scene/resources/animation.h4
-rw-r--r--scene/resources/baked_light.cpp184
-rw-r--r--scene/resources/baked_light.h30
-rw-r--r--scene/resources/video_stream.h22
5 files changed, 204 insertions, 52 deletions
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index 7fa606f5da..67f45ced2b 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -1716,7 +1716,7 @@ void Animation::clear() {
}
-void Animation::_transform_track_optimize(int p_idx,float p_allowed_err) {
+void Animation::_transform_track_optimize(int p_idx,float p_alowed_linear_err,float p_alowed_angular_err) {
ERR_FAIL_INDEX(p_idx,tracks.size());
ERR_FAIL_COND(tracks[p_idx]->type!=TYPE_TRANSFORM);
@@ -1756,7 +1756,7 @@ void Animation::_transform_track_optimize(int p_idx,float p_allowed_err) {
Vector3 s[2]={ v0, v2 };
real_t d =Geometry::get_closest_point_to_segment(v1,s).distance_to(v1);
- if (d>pd.length()*p_allowed_err) {
+ if (d>pd.length()*p_alowed_linear_err) {
continue; //beyond allowed error for colinearity
}
@@ -1795,7 +1795,7 @@ void Animation::_transform_track_optimize(int p_idx,float p_allowed_err) {
}
real_t err_01 = Math::acos(v01.normalized().dot(v02.normalized()))/Math_PI;
- if (err_01>p_allowed_err) {
+ if (err_01>p_alowed_angular_err) {
//not rotating in the same axis
continue;
}
@@ -1841,7 +1841,7 @@ void Animation::_transform_track_optimize(int p_idx,float p_allowed_err) {
Vector3 s[2]={ v0, v2 };
real_t d =Geometry::get_closest_point_to_segment(v1,s).distance_to(v1);
- if (d>pd.length()*p_allowed_err) {
+ if (d>pd.length()*p_alowed_linear_err) {
continue; //beyond allowed error for colinearity
}
@@ -1866,7 +1866,7 @@ void Animation::_transform_track_optimize(int p_idx,float p_allowed_err) {
if (t[k]==-1)
continue;
- if (Math::abs(lt-t[k])>p_allowed_err) {
+ if (Math::abs(lt-t[k])>p_alowed_linear_err) {
erase=false;
break;
}
@@ -1879,7 +1879,7 @@ void Animation::_transform_track_optimize(int p_idx,float p_allowed_err) {
if (erase) {
- if (Math::abs(lt-c)>p_allowed_err) {
+ if (Math::abs(lt-c)>p_alowed_linear_err) {
//todo, evaluate changing the transition if this fails?
//this could be done as a second pass and would be
//able to optimize more
@@ -1905,7 +1905,7 @@ void Animation::_transform_track_optimize(int p_idx,float p_allowed_err) {
}
-void Animation::optimize(float p_allowed_err) {
+void Animation::optimize(float p_allowed_linear_err,float p_allowed_angular_err) {
int total_tt=0;
@@ -1913,7 +1913,7 @@ void Animation::optimize(float p_allowed_err) {
for(int i=0;i<tracks.size();i++) {
if (tracks[i]->type==TYPE_TRANSFORM)
- _transform_track_optimize(i,p_allowed_err);
+ _transform_track_optimize(i,p_allowed_linear_err,p_allowed_angular_err);
}
diff --git a/scene/resources/animation.h b/scene/resources/animation.h
index 4366bdaca8..4c4e2f0275 100644
--- a/scene/resources/animation.h
+++ b/scene/resources/animation.h
@@ -204,7 +204,7 @@ private:
return idxr;
}
- void _transform_track_optimize(int p_idx,float p_allowed_err=0.05);
+ void _transform_track_optimize(int p_idx, float p_allowed_err=0.05, float p_alowed_angular_err=0.01);
protected:
@@ -271,7 +271,7 @@ public:
void clear();
- void optimize(float p_allowed_err=0.05);
+ void optimize(float p_allowed_linear_err=0.05,float p_allowed_angular_err=0.01);
Animation();
~Animation();
diff --git a/scene/resources/baked_light.cpp b/scene/resources/baked_light.cpp
index 725ac1c946..647c8df5d4 100644
--- a/scene/resources/baked_light.cpp
+++ b/scene/resources/baked_light.cpp
@@ -5,6 +5,7 @@ void BakedLight::set_mode(Mode p_mode) {
mode=p_mode;
VS::get_singleton()->baked_light_set_mode(baked_light,(VS::BakedLightMode(p_mode)));
+
}
BakedLight::Mode BakedLight::get_mode() const{
@@ -23,56 +24,79 @@ DVector<uint8_t> BakedLight::get_octree() const {
}
-void BakedLight::_update_lightmaps() {
-
- VS::get_singleton()->baked_light_clear_lightmaps(baked_light);
- for(Map<int,Ref<Texture> >::Element *E=lightmaps.front();E;E=E->next()) {
- VS::get_singleton()->baked_light_add_lightmap(baked_light,E->get()->get_rid(),E->key());
- }
-}
-void BakedLight::add_lightmap(const Ref<Texture> p_texture,int p_id) {
+void BakedLight::add_lightmap(const Ref<Texture> &p_texture,Size2 p_gen_size) {
- ERR_FAIL_COND(!p_texture.is_valid());
- ERR_FAIL_COND(p_id<0);
- lightmaps[p_id]=p_texture;
- VS::get_singleton()->baked_light_add_lightmap(baked_light,p_texture->get_rid(),p_id);
+ LightMap lm;
+ lm.texture=p_texture;
+ lm.gen_size=p_gen_size;
+ lightmaps.push_back(lm);
+ _update_lightmaps();
+ _change_notify();
}
-void BakedLight::erase_lightmap(int p_id) {
+void BakedLight::set_lightmap_gen_size(int p_idx,const Size2& p_size){
- ERR_FAIL_COND(!lightmaps.has(p_id));
- lightmaps.erase(p_id);
+ ERR_FAIL_INDEX(p_idx,lightmaps.size());
+ lightmaps[p_idx].gen_size=p_size;
_update_lightmaps();
}
+Size2 BakedLight::get_lightmap_gen_size(int p_idx) const{
-void BakedLight::get_lightmaps(List<int> *r_lightmaps) {
+ ERR_FAIL_INDEX_V(p_idx,lightmaps.size(),Size2());
+ return lightmaps[p_idx].gen_size;
- for(Map<int,Ref<Texture> >::Element *E=lightmaps.front();E;E=E->next()) {
+}
+void BakedLight::set_lightmap_texture(int p_idx,const Ref<Texture> &p_texture){
- r_lightmaps->push_back(E->key());
- }
+ ERR_FAIL_INDEX(p_idx,lightmaps.size());
+ lightmaps[p_idx].texture=p_texture;
+ _update_lightmaps();
}
+Ref<Texture> BakedLight::get_lightmap_texture(int p_idx) const{
-Ref<Texture> BakedLight::get_lightmap_texture(int p_id) {
+ ERR_FAIL_INDEX_V(p_idx,lightmaps.size(),Ref<Texture>());
+ return lightmaps[p_idx].texture;
- if (!lightmaps.has(p_id))
- return Ref<Texture>();
-
- return lightmaps[p_id];
+}
+void BakedLight::erase_lightmap(int p_idx){
+ ERR_FAIL_INDEX(p_idx,lightmaps.size());
+ lightmaps.remove(p_idx);
+ _update_lightmaps();
+ _change_notify();
}
+int BakedLight::get_lightmaps_count() const{
-void BakedLight::clear_lightmaps() {
+ return lightmaps.size();
+}
+void BakedLight::clear_lightmaps(){
lightmaps.clear();
_update_lightmaps();
+ _change_notify();
+}
+
+
+
+void BakedLight::_update_lightmaps() {
+
+ VS::get_singleton()->baked_light_clear_lightmaps(baked_light);
+ for(int i=0;i<lightmaps.size();i++) {
+
+ RID tid;
+ if (lightmaps[i].texture.is_valid())
+ tid=lightmaps[i].texture->get_rid();
+ VS::get_singleton()->baked_light_add_lightmap(baked_light,tid,i);
+ }
}
+
+
RID BakedLight::get_rid() const {
return baked_light;
@@ -84,12 +108,11 @@ Array BakedLight::_get_lightmap_data() const {
ret.resize(lightmaps.size()*2);
int idx=0;
- for(Map<int,Ref<Texture> >::Element *E=lightmaps.front();E;E=E->next()) {
+ for(int i=0;i<lightmaps.size();i++) {
- ret[idx++]=E->key();
- ret[idx++]=E->get();
+ ret[idx++]=Size2(lightmaps[i].gen_size);
+ ret[idx++]=lightmaps[i].texture;
}
-
return ret;
}
@@ -99,11 +122,13 @@ void BakedLight::_set_lightmap_data(Array p_array){
lightmaps.clear();
for(int i=0;i<p_array.size();i+=2) {
- int id = p_array[i];
+ Size2 size = p_array[i];
Ref<Texture> tex = p_array[i+1];
- ERR_CONTINUE(id<0);
- ERR_CONTINUE(tex.is_null());
- lightmaps[id]=tex;
+// ERR_CONTINUE(tex.is_null());
+ LightMap lm;
+ lm.gen_size=size;
+ lm.texture=tex;
+ lightmaps.push_back(lm);
}
_update_lightmaps();
}
@@ -204,7 +229,7 @@ bool BakedLight::get_bake_flag(BakeFlags p_flags) const{
void BakedLight::set_format(Format p_format) {
format=p_format;
-
+ VS::get_singleton()->baked_light_set_lightmap_multiplier(baked_light,format==FORMAT_HDR8?8.0:1.0);
}
BakedLight::Format BakedLight::get_format() const{
@@ -212,6 +237,88 @@ BakedLight::Format BakedLight::get_format() const{
return format;
}
+void BakedLight::set_transfer_lightmaps_only_to_uv2(bool p_enable) {
+
+ transfer_only_uv2=p_enable;
+}
+
+bool BakedLight::get_transfer_lightmaps_only_to_uv2() const{
+
+ return transfer_only_uv2;
+}
+
+
+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();
+ ERR_FAIL_COND_V(idx<0,false);
+ ERR_FAIL_COND_V(idx>lightmaps.size(),false);
+
+ String what = n.get_slice("/",2);
+ Ref<Texture> tex;
+ Size2 gens;
+
+ if (what=="texture")
+ tex=p_value;
+ else if (what=="gen_size")
+ gens=p_value;
+
+ if (idx==lightmaps.size()) {
+ if (tex.is_valid() || gens!=Size2())
+ add_lightmap(tex,gens);
+ } else {
+ if (tex.is_valid())
+ set_lightmap_texture(idx,tex);
+ else if (gens!=Size2())
+ set_lightmap_gen_size(idx,gens);
+ }
+
+
+ return true;
+}
+
+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();
+ ERR_FAIL_COND_V(idx<0,false);
+ ERR_FAIL_COND_V(idx>lightmaps.size(),false);
+
+ String what = n.get_slice("/",2);
+
+ if (what=="texture") {
+ if (idx==lightmaps.size())
+ r_ret=Ref<Texture>();
+ else
+ r_ret=lightmaps[idx].texture;
+
+ } else if (what=="gen_size") {
+
+ if (idx==lightmaps.size())
+ r_ret=Size2();
+ else
+ r_ret=Size2(lightmaps[idx].gen_size);
+ } else
+ return false;
+
+ return true;
+
+
+}
+void BakedLight::_get_property_list( List<PropertyInfo> *p_list) const{
+
+ for(int i=0;i<=lightmaps.size();i++) {
+
+ p_list->push_back(PropertyInfo(Variant::VECTOR2,"lightmaps/"+itos(i)+"/gen_size",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR));
+ p_list->push_back(PropertyInfo(Variant::OBJECT,"lightmaps/"+itos(i)+"/texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture",PROPERTY_USAGE_EDITOR));
+ }
+}
+
void BakedLight::_bind_methods(){
@@ -222,7 +329,7 @@ void BakedLight::_bind_methods(){
ObjectTypeDB::bind_method(_MD("set_octree","octree"),&BakedLight::set_octree);
ObjectTypeDB::bind_method(_MD("get_octree"),&BakedLight::get_octree);
- ObjectTypeDB::bind_method(_MD("add_lightmap","texture:Texture","id"),&BakedLight::add_lightmap);
+ ObjectTypeDB::bind_method(_MD("add_lightmap","texture:Texture","gen_size"),&BakedLight::add_lightmap);
ObjectTypeDB::bind_method(_MD("erase_lightmap","id"),&BakedLight::erase_lightmap);
ObjectTypeDB::bind_method(_MD("clear_lightmaps"),&BakedLight::clear_lightmaps);
@@ -253,6 +360,11 @@ void BakedLight::_bind_methods(){
ObjectTypeDB::bind_method(_MD("set_format","format"),&BakedLight::set_format);
ObjectTypeDB::bind_method(_MD("get_format"),&BakedLight::get_format);
+ ObjectTypeDB::bind_method(_MD("set_transfer_lightmaps_only_to_uv2","enable"),&BakedLight::set_transfer_lightmaps_only_to_uv2);
+ ObjectTypeDB::bind_method(_MD("get_transfer_lightmaps_only_to_uv2"),&BakedLight::get_transfer_lightmaps_only_to_uv2);
+
+
+
ObjectTypeDB::bind_method(_MD("set_energy_multiplier","energy_multiplier"),&BakedLight::set_energy_multiplier);
ObjectTypeDB::bind_method(_MD("get_energy_multiplier"),&BakedLight::get_energy_multiplier);
@@ -276,6 +388,7 @@ void BakedLight::_bind_methods(){
ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"baking_flags/specular"),_SCS("set_bake_flag"),_SCS("get_bake_flag"),BAKE_SPECULAR);
ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"baking_flags/translucent"),_SCS("set_bake_flag"),_SCS("get_bake_flag"),BAKE_TRANSLUCENT);
ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"baking_flags/conserve_energy"),_SCS("set_bake_flag"),_SCS("get_bake_flag"),BAKE_CONSERVE_ENERGY);
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL,"lightmap/use_only_uv2"),_SCS("set_transfer_lightmaps_only_to_uv2"),_SCS("get_transfer_lightmaps_only_to_uv2"));
ADD_PROPERTY( PropertyInfo(Variant::RAW_ARRAY,"octree",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_octree"),_SCS("get_octree"));
ADD_PROPERTY( PropertyInfo(Variant::ARRAY,"lightmaps",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_lightmap_data"),_SCS("_get_lightmap_data"));
@@ -308,6 +421,7 @@ BakedLight::BakedLight() {
edge_damp=0.0;
normal_damp=0.0;
format=FORMAT_RGB;
+ transfer_only_uv2=false;
flags[BAKE_DIFFUSE]=true;
flags[BAKE_SPECULAR]=false;
diff --git a/scene/resources/baked_light.h b/scene/resources/baked_light.h
index df86f98c08..57ed7d7aee 100644
--- a/scene/resources/baked_light.h
+++ b/scene/resources/baked_light.h
@@ -33,7 +33,13 @@ private:
RID baked_light;
Mode mode;
- Map<int,Ref<Texture> > lightmaps;
+ struct LightMap {
+ Size2i gen_size;
+ Ref<Texture> texture;
+ };
+
+
+ Vector< LightMap> lightmaps;
//bake vars
int cell_subdiv;
@@ -45,6 +51,7 @@ private:
float edge_damp;
float normal_damp;
int bounces;
+ bool transfer_only_uv2;
Format format;
bool flags[BAKE_MAX];
@@ -54,6 +61,13 @@ private:
Array _get_lightmap_data() const;
void _set_lightmap_data(Array p_array);
+
+protected:
+
+ bool _set(const StringName& p_name, const Variant& p_value);
+ bool _get(const StringName& p_name,Variant &r_ret) const;
+ void _get_property_list( List<PropertyInfo> *p_list) const;
+
static void _bind_methods();
public:
@@ -91,16 +105,22 @@ public:
void set_format(Format p_margin);
Format get_format() const;
+ void set_transfer_lightmaps_only_to_uv2(bool p_enable);
+ bool get_transfer_lightmaps_only_to_uv2() const;
+
void set_mode(Mode p_mode);
Mode get_mode() const;
void set_octree(const DVector<uint8_t>& p_octree);
DVector<uint8_t> get_octree() const;
- void add_lightmap(const Ref<Texture> p_texture,int p_id);
- void erase_lightmap(int p_id);
- void get_lightmaps(List<int> *r_lightmaps);
- Ref<Texture> get_lightmap_texture(int p_id);
+ void add_lightmap(const Ref<Texture> &p_texture,Size2 p_gen_size=Size2(256,256));
+ void set_lightmap_gen_size(int p_idx,const Size2& p_size);
+ Size2 get_lightmap_gen_size(int p_idx) const;
+ void set_lightmap_texture(int p_idx,const Ref<Texture> &p_texture);
+ Ref<Texture> get_lightmap_texture(int p_idx) const;
+ void erase_lightmap(int p_idx);
+ int get_lightmaps_count() const;
void clear_lightmaps();
virtual RID get_rid() const;
diff --git a/scene/resources/video_stream.h b/scene/resources/video_stream.h
index 32bc8670f0..eafacce159 100644
--- a/scene/resources/video_stream.h
+++ b/scene/resources/video_stream.h
@@ -33,19 +33,37 @@
-class VideoStream : public AudioStreamResampled {
+class VideoStream : public Resource {
- OBJ_TYPE(VideoStream,AudioStreamResampled);
+ OBJ_TYPE(VideoStream,Resource);
protected:
static void _bind_methods();
public:
+ virtual void stop()=0;
+ virtual void play()=0;
+
+ virtual bool is_playing() const=0;
+
+ virtual void set_paused(bool p_paused)=0;
+ virtual bool is_paused(bool p_paused) const=0;
+
+ virtual void set_loop(bool p_enable)=0;
+ virtual bool has_loop() const=0;
+
+ virtual float get_length() const=0;
+
+ virtual float get_pos() const=0;
+ virtual void seek_pos(float p_time)=0;
+
virtual int get_pending_frame_count() const=0;
virtual Image pop_frame()=0;
virtual Image peek_frame() const=0;
+ virtual void update(float p_time)=0;
+
VideoStream();
};