diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/baked_light.cpp | 16 | ||||
-rw-r--r-- | scene/resources/baked_light.h | 11 | ||||
-rw-r--r-- | scene/resources/polygon_path_finder.cpp | 80 | ||||
-rw-r--r-- | scene/resources/polygon_path_finder.h | 11 |
4 files changed, 111 insertions, 7 deletions
diff --git a/scene/resources/baked_light.cpp b/scene/resources/baked_light.cpp index b3de7143ee..725ac1c946 100644 --- a/scene/resources/baked_light.cpp +++ b/scene/resources/baked_light.cpp @@ -201,6 +201,16 @@ bool BakedLight::get_bake_flag(BakeFlags p_flags) const{ return flags[p_flags]; } +void BakedLight::set_format(Format p_format) { + + format=p_format; + +} + +BakedLight::Format BakedLight::get_format() const{ + + return format; +} void BakedLight::_bind_methods(){ @@ -240,6 +250,10 @@ void BakedLight::_bind_methods(){ ObjectTypeDB::bind_method(_MD("set_normal_damp","normal_damp"),&BakedLight::set_normal_damp); ObjectTypeDB::bind_method(_MD("get_normal_damp"),&BakedLight::get_normal_damp); + ObjectTypeDB::bind_method(_MD("set_format","format"),&BakedLight::set_format); + ObjectTypeDB::bind_method(_MD("get_format"),&BakedLight::get_format); + + ObjectTypeDB::bind_method(_MD("set_energy_multiplier","energy_multiplier"),&BakedLight::set_energy_multiplier); ObjectTypeDB::bind_method(_MD("get_energy_multiplier"),&BakedLight::get_energy_multiplier); @@ -251,6 +265,7 @@ void BakedLight::_bind_methods(){ ADD_PROPERTY( PropertyInfo(Variant::INT,"mode/mode",PROPERTY_HINT_ENUM,"Octree,Lightmaps"),_SCS("set_mode"),_SCS("get_mode")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/format",PROPERTY_HINT_ENUM,"RGB,HDR8,HDR16"),_SCS("set_format"),_SCS("get_format")); ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/cell_subdiv",PROPERTY_HINT_RANGE,"4,14,1"),_SCS("set_cell_subdivision"),_SCS("get_cell_subdivision")); ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/lattice_subdiv",PROPERTY_HINT_RANGE,"1,5,1"),_SCS("set_initial_lattice_subdiv"),_SCS("get_initial_lattice_subdiv")); ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/light_bounces",PROPERTY_HINT_RANGE,"0,3,1"),_SCS("set_bounces"),_SCS("get_bounces")); @@ -292,6 +307,7 @@ BakedLight::BakedLight() { cell_extra_margin=0.05; edge_damp=0.0; normal_damp=0.0; + format=FORMAT_RGB; flags[BAKE_DIFFUSE]=true; flags[BAKE_SPECULAR]=false; diff --git a/scene/resources/baked_light.h b/scene/resources/baked_light.h index 8b50f6e0d3..df86f98c08 100644 --- a/scene/resources/baked_light.h +++ b/scene/resources/baked_light.h @@ -14,6 +14,13 @@ public: MODE_LIGHTMAPS }; + enum Format { + + FORMAT_RGB, + FORMAT_HDR8, + FORMAT_HDR16 + }; + enum BakeFlags { BAKE_DIFFUSE, BAKE_SPECULAR, @@ -38,6 +45,7 @@ private: float edge_damp; float normal_damp; int bounces; + Format format; bool flags[BAKE_MAX]; @@ -80,6 +88,8 @@ public: void set_bake_flag(BakeFlags p_flags,bool p_enable); bool get_bake_flag(BakeFlags p_flags) const; + void set_format(Format p_margin); + Format get_format() const; void set_mode(Mode p_mode); Mode get_mode() const; @@ -100,6 +110,7 @@ public: }; +VARIANT_ENUM_CAST(BakedLight::Format); VARIANT_ENUM_CAST(BakedLight::Mode); VARIANT_ENUM_CAST(BakedLight::BakeFlags); diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp index 9f7b6d5b9e..ca8b6bc110 100644 --- a/scene/resources/polygon_path_finder.cpp +++ b/scene/resources/polygon_path_finder.cpp @@ -2,7 +2,7 @@ #include "geometry.h" -bool PolygonPathFinder::_is_point_inside(const Vector2& p_point) { +bool PolygonPathFinder::_is_point_inside(const Vector2& p_point) const { int crosses=0; @@ -36,6 +36,7 @@ void PolygonPathFinder::setup(const Vector<Vector2>& p_points, const Vector<int> int point_count=p_points.size(); points.resize(point_count+2); + bounds=Rect2(); for(int i=0;i<p_points.size();i++) { @@ -43,6 +44,12 @@ void PolygonPathFinder::setup(const Vector<Vector2>& p_points, const Vector<int> outside_point.x = i==0?p_points[0].x:(MAX( p_points[i].x, outside_point.x )); outside_point.y = i==0?p_points[0].y:(MAX( p_points[i].y, outside_point.y )); + + if (i==0) { + bounds.pos=points[i].pos; + } else { + bounds.expand_to(points[i].pos); + } } outside_point.x+=20.451+Math::randf()*10.2039; @@ -108,10 +115,14 @@ void PolygonPathFinder::setup(const Vector<Vector2>& p_points, const Vector<int> Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector2& p_to) { Vector<Vector2> path; - if (!_is_point_inside(p_from)) + if (!_is_point_inside(p_from)) { + printf("p_from outside\n"); return path; - if (!_is_point_inside(p_to)) + }; + if (!_is_point_inside(p_to)) { + printf("p_to outside\n"); return path; + }; //test direct connection { @@ -148,8 +159,8 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector points[bidx].pos=p_to; points[aidx].distance=0; points[bidx].distance=0; - points[aidx].distance=0; - points[bidx].distance=0; + points[aidx].prev=-1; + points[bidx].prev=-1; for(int i=0;i<points.size()-2;i++) { @@ -185,7 +196,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector } if (!valid_a && !valid_b) - continue; + break; } @@ -220,6 +231,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector while(true) { if (open_list.size()==0) { + printf("open list empty\n"); break; } //check open list @@ -315,6 +327,7 @@ void PolygonPathFinder::_set_data(const Dictionary& p_data) { ERR_FAIL_COND(!p_data.has("points")); ERR_FAIL_COND(!p_data.has("connections")); ERR_FAIL_COND(!p_data.has("segments")); + ERR_FAIL_COND(!p_data.has("bounds")); DVector<Vector2> p=p_data["points"]; Array c=p_data["connections"]; @@ -348,6 +361,7 @@ void PolygonPathFinder::_set_data(const Dictionary& p_data) { Edge e(sr[i],sr[i+1]); edges.insert(e); } + bounds=p_data["bounds"]; } @@ -387,6 +401,7 @@ Dictionary PolygonPathFinder::_get_data() const{ } + d["bounds"]=bounds; d["points"]=p; d["connections"]=connections; d["segments"]=ind; @@ -395,10 +410,63 @@ Dictionary PolygonPathFinder::_get_data() const{ } +bool PolygonPathFinder::is_point_inside(const Vector2& p_point) const { + + return _is_point_inside(p_point); +} + +Vector2 PolygonPathFinder::get_closest_point(const Vector2& p_point) const { + + int closest_idx=-1; + float closest_dist=1e20; + for(int i=0;i<points.size()-2;i++) { + + float d = p_point.distance_squared_to(points[i].pos); + if (d<closest_dist) { + d=closest_dist; + closest_idx=i; + } + + } + + ERR_FAIL_COND_V(closest_idx==-1,Vector2()); + + return points[closest_idx].pos; +} + + +Vector<Vector2> PolygonPathFinder::get_intersections(const Vector2& p_from, const Vector2& p_to) const { + + Vector<Vector2> inters; + + for (Set<Edge>::Element *E=edges.front();E;E=E->next()) { + Vector2 a = points[E->get().points[0]].pos; + Vector2 b = points[E->get().points[1]].pos; + + Vector2 res; + if (Geometry::segment_intersects_segment_2d(a,b,p_from,p_to,&res)) { + inters.push_back(res); + } + } + + return inters; + +} + +Rect2 PolygonPathFinder::get_bounds() const { + + return bounds; +} + + void PolygonPathFinder::_bind_methods() { ObjectTypeDB::bind_method(_MD("setup","points","connections"),&PolygonPathFinder::setup); ObjectTypeDB::bind_method(_MD("find_path","from","to"),&PolygonPathFinder::find_path); + ObjectTypeDB::bind_method(_MD("get_intersections","from","to"),&PolygonPathFinder::get_intersections); + ObjectTypeDB::bind_method(_MD("get_closest_point","point"),&PolygonPathFinder::get_closest_point); + ObjectTypeDB::bind_method(_MD("is_point_inside","point"),&PolygonPathFinder::is_point_inside); + ObjectTypeDB::bind_method(_MD("get_bounds"),&PolygonPathFinder::get_bounds); ObjectTypeDB::bind_method(_MD("_set_data"),&PolygonPathFinder::_set_data); ObjectTypeDB::bind_method(_MD("_get_data"),&PolygonPathFinder::_get_data); diff --git a/scene/resources/polygon_path_finder.h b/scene/resources/polygon_path_finder.h index 31253e3177..002ce709ec 100644 --- a/scene/resources/polygon_path_finder.h +++ b/scene/resources/polygon_path_finder.h @@ -31,15 +31,18 @@ class PolygonPathFinder : public Resource { if (a>b) { SWAP(a,b); } + points[0] = a; + points[1] = b; } }; Vector2 outside_point; + Rect2 bounds; Vector<Point> points; Set<Edge> edges; - bool _is_point_inside(const Vector2& p_point); + bool _is_point_inside(const Vector2& p_point) const; void _set_data(const Dictionary& p_data); Dictionary _get_data() const; @@ -52,6 +55,12 @@ public: void setup(const Vector<Vector2>& p_points, const Vector<int>& p_connections); Vector<Vector2> find_path(const Vector2& p_from, const Vector2& p_to); + bool is_point_inside(const Vector2& p_point) const; + Vector2 get_closest_point(const Vector2& p_point) const; + Vector<Vector2> get_intersections(const Vector2& p_from, const Vector2& p_to) const; + Rect2 get_bounds() const; + + PolygonPathFinder(); }; |