summaryrefslogtreecommitdiff
path: root/scene/2d/polygon_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/polygon_2d.cpp')
-rw-r--r--scene/2d/polygon_2d.cpp128
1 files changed, 89 insertions, 39 deletions
diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp
index a6da027e0a..95656b9610 100644
--- a/scene/2d/polygon_2d.cpp
+++ b/scene/2d/polygon_2d.cpp
@@ -61,7 +61,7 @@ bool Polygon2D::_edit_use_pivot() const {
Rect2 Polygon2D::_edit_get_rect() const {
if (rect_cache_dirty) {
int l = polygon.size();
- PoolVector<Vector2>::Read r = polygon.read();
+ const Vector2 *r = polygon.ptr();
item_rect = Rect2();
for (int i = 0; i < l; i++) {
Vector2 pos = r[i] + offset;
@@ -108,7 +108,7 @@ void Polygon2D::_notification(int p_what) {
skeleton_node = Object::cast_to<Skeleton2D>(get_node(skeleton));
}
- ObjectID new_skeleton_id = 0;
+ ObjectID new_skeleton_id;
if (skeleton_node) {
VS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), skeleton_node->get_skeleton());
@@ -120,11 +120,11 @@ void Polygon2D::_notification(int p_what) {
if (new_skeleton_id != current_skeleton_id) {
Object *old_skeleton = ObjectDB::get_instance(current_skeleton_id);
if (old_skeleton) {
- old_skeleton->disconnect("bone_setup_changed", this, "_skeleton_bone_setup_changed");
+ old_skeleton->disconnect("bone_setup_changed", callable_mp(this, &Polygon2D::_skeleton_bone_setup_changed));
}
if (skeleton_node) {
- skeleton_node->connect("bone_setup_changed", this, "_skeleton_bone_setup_changed");
+ skeleton_node->connect("bone_setup_changed", callable_mp(this, &Polygon2D::_skeleton_bone_setup_changed));
}
current_skeleton_id = new_skeleton_id;
@@ -148,7 +148,7 @@ void Polygon2D::_notification(int p_what) {
{
- PoolVector<Vector2>::Read polyr = polygon.read();
+ const Vector2 *polyr = polygon.ptr();
for (int i = 0; i < len; i++) {
points.write[i] = polyr[i] + offset;
}
@@ -217,7 +217,7 @@ void Polygon2D::_notification(int p_what) {
if (points.size() == uv.size()) {
- PoolVector<Vector2>::Read uvr = uv.read();
+ const Vector2 *uvr = uv.ptr();
for (int i = 0; i < len; i++) {
uvs.write[i] = texmat.xform(uvr[i]) / tex_size;
@@ -257,7 +257,7 @@ void Polygon2D::_notification(int p_what) {
}
int bone_index = bone->get_index_in_skeleton();
- PoolVector<float>::Read r = bone_weights[i].weights.read();
+ const float *r = bone_weights[i].weights.ptr();
for (int j = 0; j < vc; j++) {
if (r[j] == 0.0)
continue; //weight is unpainted, skip
@@ -296,7 +296,7 @@ void Polygon2D::_notification(int p_what) {
Vector<Color> colors;
if (vertex_colors.size() == points.size()) {
colors.resize(len);
- PoolVector<Color>::Read color_r = vertex_colors.read();
+ const Color *color_r = vertex_colors.ptr();
for (int i = 0; i < len; i++) {
colors.write[i] = color_r[i];
}
@@ -304,23 +304,20 @@ void Polygon2D::_notification(int p_what) {
colors.push_back(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());
-
if (invert || polygons.size() == 0) {
Vector<int> indices = Geometry::triangulate_polygon(points);
if (indices.size()) {
- VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID(), -1, RID(), antialiased);
+ VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID(), -1, normal_map.is_valid() ? normal_map->get_rid() : RID(), specular_map.is_valid() ? specular_map->get_rid() : RID(), Color(specular_color.r, specular_color.g, specular_color.b, shininess));
}
} else {
//draw individual polygons
Vector<int> total_indices;
for (int i = 0; i < polygons.size(); i++) {
- PoolVector<int> src_indices = polygons[i];
+ Vector<int> src_indices = polygons[i];
int ic = src_indices.size();
if (ic < 3)
continue;
- PoolVector<int>::Read r = src_indices.read();
+ const int *r = src_indices.ptr();
Vector<Vector2> tmp_points;
tmp_points.resize(ic);
@@ -344,7 +341,7 @@ void Polygon2D::_notification(int p_what) {
}
if (total_indices.size()) {
- VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), total_indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID(), -1, RID(), antialiased);
+ VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), total_indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID());
}
}
@@ -352,13 +349,13 @@ void Polygon2D::_notification(int p_what) {
}
}
-void Polygon2D::set_polygon(const PoolVector<Vector2> &p_polygon) {
+void Polygon2D::set_polygon(const Vector<Vector2> &p_polygon) {
polygon = p_polygon;
rect_cache_dirty = true;
update();
}
-PoolVector<Vector2> Polygon2D::get_polygon() const {
+Vector<Vector2> Polygon2D::get_polygon() const {
return polygon;
}
@@ -372,13 +369,13 @@ int Polygon2D::get_internal_vertex_count() const {
return internal_vertices;
}
-void Polygon2D::set_uv(const PoolVector<Vector2> &p_uv) {
+void Polygon2D::set_uv(const Vector<Vector2> &p_uv) {
uv = p_uv;
update();
}
-PoolVector<Vector2> Polygon2D::get_uv() const {
+Vector<Vector2> Polygon2D::get_uv() const {
return uv;
}
@@ -404,17 +401,17 @@ Color Polygon2D::get_color() const {
return color;
}
-void Polygon2D::set_vertex_colors(const PoolVector<Color> &p_colors) {
+void Polygon2D::set_vertex_colors(const Vector<Color> &p_colors) {
vertex_colors = p_colors;
update();
}
-PoolVector<Color> Polygon2D::get_vertex_colors() const {
+Vector<Color> Polygon2D::get_vertex_colors() const {
return vertex_colors;
}
-void Polygon2D::set_texture(const Ref<Texture> &p_texture) {
+void Polygon2D::set_texture(const Ref<Texture2D> &p_texture) {
texture = p_texture;
@@ -428,11 +425,47 @@ void Polygon2D::set_texture(const Ref<Texture> &p_texture) {
}*/
update();
}
-Ref<Texture> Polygon2D::get_texture() const {
+Ref<Texture2D> Polygon2D::get_texture() const {
return texture;
}
+void Polygon2D::set_normal_map(const Ref<Texture2D> &p_normal_map) {
+ normal_map = p_normal_map;
+ update();
+}
+
+Ref<Texture2D> Polygon2D::get_normal_map() const {
+ return normal_map;
+}
+
+void Polygon2D::set_specular_map(const Ref<Texture2D> &p_specular_map) {
+ specular_map = p_specular_map;
+ update();
+}
+
+Ref<Texture2D> Polygon2D::get_specular_map() const {
+ return specular_map;
+}
+
+void Polygon2D::set_specular_color(const Color &p_specular_color) {
+ specular_color = p_specular_color;
+ update();
+}
+
+Color Polygon2D::get_specular_color() const {
+ return specular_color;
+}
+
+void Polygon2D::set_shininess(float p_shininess) {
+ shininess = CLAMP(p_shininess, 0.0, 1.0);
+ update();
+}
+
+float Polygon2D::get_shininess() const {
+ return shininess;
+}
+
void Polygon2D::set_texture_offset(const Vector2 &p_offset) {
tex_ofs = p_offset;
@@ -515,7 +548,7 @@ Vector2 Polygon2D::get_offset() const {
return offset;
}
-void Polygon2D::add_bone(const NodePath &p_path, const PoolVector<float> &p_weights) {
+void Polygon2D::add_bone(const NodePath &p_path, const Vector<float> &p_weights) {
Bone bone;
bone.path = p_path;
@@ -529,9 +562,9 @@ NodePath Polygon2D::get_bone_path(int p_index) const {
ERR_FAIL_INDEX_V(p_index, bone_weights.size(), NodePath());
return bone_weights[p_index].path;
}
-PoolVector<float> Polygon2D::get_bone_weights(int p_index) const {
+Vector<float> Polygon2D::get_bone_weights(int p_index) const {
- ERR_FAIL_INDEX_V(p_index, bone_weights.size(), PoolVector<float>());
+ ERR_FAIL_INDEX_V(p_index, bone_weights.size(), Vector<float>());
return bone_weights[p_index].weights;
}
void Polygon2D::erase_bone(int p_idx) {
@@ -544,7 +577,7 @@ void Polygon2D::clear_bones() {
bone_weights.clear();
}
-void Polygon2D::set_bone_weights(int p_index, const PoolVector<float> &p_weights) {
+void Polygon2D::set_bone_weights(int p_index, const Vector<float> &p_weights) {
ERR_FAIL_INDEX(p_index, bone_weights.size());
bone_weights.write[p_index].weights = p_weights;
update();
@@ -603,6 +636,18 @@ void Polygon2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &Polygon2D::set_texture);
ClassDB::bind_method(D_METHOD("get_texture"), &Polygon2D::get_texture);
+ ClassDB::bind_method(D_METHOD("set_normal_map", "normal_map"), &Polygon2D::set_normal_map);
+ ClassDB::bind_method(D_METHOD("get_normal_map"), &Polygon2D::get_normal_map);
+
+ ClassDB::bind_method(D_METHOD("set_specular_map", "specular_map"), &Polygon2D::set_specular_map);
+ ClassDB::bind_method(D_METHOD("get_specular_map"), &Polygon2D::get_specular_map);
+
+ ClassDB::bind_method(D_METHOD("set_specular_color", "specular_color"), &Polygon2D::set_specular_color);
+ ClassDB::bind_method(D_METHOD("get_specular_color"), &Polygon2D::get_specular_color);
+
+ ClassDB::bind_method(D_METHOD("set_shininess", "shininess"), &Polygon2D::set_shininess);
+ ClassDB::bind_method(D_METHOD("get_shininess"), &Polygon2D::get_shininess);
+
ClassDB::bind_method(D_METHOD("set_texture_offset", "texture_offset"), &Polygon2D::set_texture_offset);
ClassDB::bind_method(D_METHOD("get_texture_offset"), &Polygon2D::get_texture_offset);
@@ -645,29 +690,32 @@ void Polygon2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_bones", "bones"), &Polygon2D::_set_bones);
ClassDB::bind_method(D_METHOD("_get_bones"), &Polygon2D::_get_bones);
- ClassDB::bind_method(D_METHOD("_skeleton_bone_setup_changed"), &Polygon2D::_skeleton_bone_setup_changed);
-
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "antialiased"), "set_antialiased", "get_antialiased");
- ADD_GROUP("Texture", "");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
- ADD_GROUP("Texture", "texture_");
+ ADD_GROUP("Texture2D", "");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture");
+ ADD_GROUP("Texture2D", "texture_");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_offset"), "set_texture_offset", "get_texture_offset");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_scale"), "set_texture_scale", "get_texture_scale");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "texture_rotation_degrees", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater"), "set_texture_rotation_degrees", "get_texture_rotation_degrees");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "texture_rotation", PROPERTY_HINT_NONE, "", 0), "set_texture_rotation", "get_texture_rotation");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "texture_rotation_degrees", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater"), "set_texture_rotation_degrees", "get_texture_rotation_degrees");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "texture_rotation", PROPERTY_HINT_NONE, "", 0), "set_texture_rotation", "get_texture_rotation");
+ ADD_GROUP("Lighting", "");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "normal_map", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_normal_map", "get_normal_map");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "specular_map", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_specular_map", "get_specular_map");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "specular_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_specular_color", "get_specular_color");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "shininess", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_shininess", "get_shininess");
ADD_GROUP("Skeleton", "");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton2D"), "set_skeleton", "get_skeleton");
ADD_GROUP("Invert", "invert_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "invert_enable"), "set_invert", "get_invert");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "invert_border", PROPERTY_HINT_RANGE, "0.1,16384,0.1"), "set_invert_border", "get_invert_border");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "invert_border", PROPERTY_HINT_RANGE, "0.1,16384,0.1"), "set_invert_border", "get_invert_border");
ADD_GROUP("Data", "");
- ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon");
- ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "uv"), "set_uv", "get_uv");
- ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "vertex_colors"), "set_vertex_colors", "get_vertex_colors");
+ ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon");
+ ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "uv"), "set_uv", "get_uv");
+ ADD_PROPERTY(PropertyInfo(Variant::PACKED_COLOR_ARRAY, "vertex_colors"), "set_vertex_colors", "get_vertex_colors");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons"), "set_polygons", "get_polygons");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bones", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_bones", "_get_bones");
ADD_PROPERTY(PropertyInfo(Variant::INT, "internal_vertex_count", PROPERTY_HINT_RANGE, "0,1000"), "set_internal_vertex_count", "get_internal_vertex_count");
@@ -684,5 +732,7 @@ Polygon2D::Polygon2D() {
color = Color(1, 1, 1);
rect_cache_dirty = true;
internal_vertices = 0;
- current_skeleton_id = 0;
+
+ specular_color = Color(1, 1, 1, 1);
+ shininess = 1.0;
}