From 0d20ceeb61be915fea81c22c174efb9253d96974 Mon Sep 17 00:00:00 2001 From: Ovnuniarchos Date: Mon, 23 May 2016 03:40:45 +0200 Subject: [PATCH] Polygon2D now exposes vertex colors. --- scene/2d/polygon_2d.cpp | 27 ++++++++++++++++++++++++++- scene/2d/polygon_2d.h | 4 ++++ 2 files changed, 30 insertions(+), 1 deletion(-) 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 colors; - colors.push_back(color); + int color_len=vertex_colors.size(); + colors.resize(len); + { + DVector::Read color_r=vertex_colors.read(); + for(int i=0;i 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& p_colors){ + + vertex_colors=p_colors; + update(); +} +DVector Polygon2D::get_vertex_colors() const{ + + return vertex_colors; +} + void Polygon2D::set_texture(const Ref& 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 polygon; DVector uv; + DVector vertex_colors; Color color; Ref 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& p_colors); + DVector get_vertex_colors() const; + void set_texture(const Ref& p_texture); Ref get_texture() const;