diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2016-05-23 13:28:28 +0200 |
---|---|---|
committer | Rémi Verschelde <remi@verschelde.fr> | 2016-05-23 13:28:28 +0200 |
commit | 29d9eb02b9b96df9542523665947bc7b18ec80b2 (patch) | |
tree | d6304cd3b3f27cd5e8bcf2b0c05a4fe0d63dee01 | |
parent | e75701e0b5ab909b8ec434c060340d6706537647 (diff) | |
parent | 0d20ceeb61be915fea81c22c174efb9253d96974 (diff) |
Merge pull request #4765 from Ovnuniarchos/ColorPoly
Polygon2D now exposes vertex colors.
-rw-r--r-- | scene/2d/polygon_2d.cpp | 27 | ||||
-rw-r--r-- | scene/2d/polygon_2d.h | 4 |
2 files changed, 30 insertions, 1 deletions
diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp index fc6986327f..03ced12c55 100644 --- a/scene/2d/polygon_2d.cpp +++ b/scene/2d/polygon_2d.cpp @@ -145,7 +145,18 @@ void Polygon2D::_notification(int p_what) { Vector<Color> colors; - colors.push_back(color); + int color_len=vertex_colors.size(); + colors.resize(len); + { + DVector<Color>::Read color_r=vertex_colors.read(); + for(int i=0;i<color_len && i<len;i++){ + colors[i]=color_r[i]; + } + for(int i=color_len;i<len;i++){ + colors[i]=color; + } + } + Vector<int> indices = Geometry::triangulate_polygon(points); VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(),indices,points,colors,uvs,texture.is_valid()?texture->get_rid():RID()); @@ -188,6 +199,16 @@ Color Polygon2D::get_color() const{ return color; } +void Polygon2D::set_vertex_colors(const DVector<Color>& p_colors){ + + vertex_colors=p_colors; + update(); +} +DVector<Color> Polygon2D::get_vertex_colors() const{ + + return vertex_colors; +} + void Polygon2D::set_texture(const Ref<Texture>& p_texture){ texture=p_texture; @@ -293,6 +314,9 @@ void Polygon2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_color","color"),&Polygon2D::set_color); ObjectTypeDB::bind_method(_MD("get_color"),&Polygon2D::get_color); + ObjectTypeDB::bind_method(_MD("set_vertex_colors","vertex_colors"),&Polygon2D::set_vertex_colors); + ObjectTypeDB::bind_method(_MD("get_vertex_colors"),&Polygon2D::get_vertex_colors); + ObjectTypeDB::bind_method(_MD("set_texture","texture"),&Polygon2D::set_texture); ObjectTypeDB::bind_method(_MD("get_texture"),&Polygon2D::get_texture); @@ -323,6 +347,7 @@ void Polygon2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::VECTOR2_ARRAY,"polygon"),_SCS("set_polygon"),_SCS("get_polygon")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2_ARRAY,"uv"),_SCS("set_uv"),_SCS("get_uv")); ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),_SCS("set_color"),_SCS("get_color")); + ADD_PROPERTY( PropertyInfo(Variant::COLOR_ARRAY,"vertex_colors"),_SCS("set_vertex_colors"),_SCS("get_vertex_colors")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_offset"),_SCS("get_offset")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture/texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"texture/offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset")); diff --git a/scene/2d/polygon_2d.h b/scene/2d/polygon_2d.h index 517b623ccd..eaa642787c 100644 --- a/scene/2d/polygon_2d.h +++ b/scene/2d/polygon_2d.h @@ -9,6 +9,7 @@ class Polygon2D : public Node2D { DVector<Vector2> polygon; DVector<Vector2> uv; + DVector<Color> vertex_colors; Color color; Ref<Texture> texture; Vector2 tex_scale; @@ -40,6 +41,9 @@ public: void set_color(const Color& p_color); Color get_color() const; + void set_vertex_colors(const DVector<Color>& p_colors); + DVector<Color> get_vertex_colors() const; + void set_texture(const Ref<Texture>& p_texture); Ref<Texture> get_texture() const; |