Add fast path to Polygon2D
This saves a huge amount of time when animating vertices of a Polygon2D manually
This commit is contained in:
1 parent
c3058391d7
commit
083d46af71
2 files changed
+34
-3
No files matched your search
+29
-3
@@ -354,7 +354,19 @@ void Polygon2D::_notification(int p_what) {
|
||||
}
|
||||
}
|
||||
|
||||
RS::get_singleton()->mesh_clear(mesh);
|
||||
bool has_uv = uvs.size() == points.size();
|
||||
bool has_color = colors.size() == points.size();
|
||||
bool has_bones = skeleton_node != nullptr;
|
||||
|
||||
bool needs_clear = len != last_len;
|
||||
needs_clear |= index_array.size() != last_index_count;
|
||||
needs_clear |= has_uv != last_has_uv;
|
||||
needs_clear |= has_color != last_has_color;
|
||||
needs_clear |= has_bones || has_bones != last_has_bones;
|
||||
|
||||
if (needs_clear) {
|
||||
RS::get_singleton()->mesh_clear(mesh);
|
||||
}
|
||||
|
||||
if (index_array.size()) {
|
||||
Array arr;
|
||||
@@ -397,10 +409,24 @@ void Polygon2D::_notification(int p_what) {
|
||||
return;
|
||||
}
|
||||
|
||||
RS::get_singleton()->mesh_add_surface(mesh, sd);
|
||||
RS::get_singleton()->canvas_item_add_mesh(get_canvas_item(), mesh, Transform2D(), Color(1, 1, 1), texture.is_valid() ? texture->get_scaled_rid() : RID());
|
||||
if (needs_clear) {
|
||||
RS::get_singleton()->mesh_add_surface(mesh, sd);
|
||||
} else {
|
||||
RS::get_singleton()->mesh_surface_update_vertex_region(mesh, 0, 0, sd.vertex_data);
|
||||
if (has_uv || has_color) {
|
||||
RS::get_singleton()->mesh_surface_update_attribute_region(mesh, 0, 0, sd.attribute_data);
|
||||
}
|
||||
RS::get_singleton()->mesh_surface_update_index_region(mesh, 0, 0, sd.index_data);
|
||||
}
|
||||
}
|
||||
|
||||
last_len = len;
|
||||
last_index_count = index_array.size();
|
||||
last_has_uv = has_uv;
|
||||
last_has_color = has_color;
|
||||
last_has_bones = has_bones;
|
||||
|
||||
RS::get_singleton()->canvas_item_add_mesh(get_canvas_item(), mesh, Transform2D(), Color(1, 1, 1), texture.is_valid() ? texture->get_scaled_rid() : RID());
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,11 @@ class Polygon2D : public Node2D {
|
||||
void _skeleton_bone_setup_changed();
|
||||
|
||||
RID mesh;
|
||||
int last_len = 0;
|
||||
int last_index_count = 0;
|
||||
bool last_has_uv = false;
|
||||
bool last_has_color = false;
|
||||
bool last_has_bones = false;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
Reference in new issue
Block a user