diff options
author | reduz <reduzio@gmail.com> | 2021-05-10 13:12:44 -0300 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2021-05-11 11:21:36 -0300 |
commit | 479391ef5405226fa110ac3f5823ecbc7d987b0c (patch) | |
tree | 427b8179758b35cfc859d1e6fb853a4d60e086d5 /scene | |
parent | a1cc6b45dca33982003e5646903df1453e2ab3ae (diff) |
Fixes missng 2D engine bits
-Mesh2D now works
-MultiMesh2D now works
-Polygon2D now works
-Added hooks for processing 2D particles
-Skeleton2D now works
2D particles still not working, but stuff needed for it is now implemented.
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/gpu_particles_2d.cpp | 1 | ||||
-rw-r--r-- | scene/2d/polygon_2d.cpp | 48 | ||||
-rw-r--r-- | scene/2d/polygon_2d.h | 3 | ||||
-rw-r--r-- | scene/3d/gpu_particles_3d.cpp | 1 |
4 files changed, 42 insertions, 11 deletions
diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp index 8a0631a614..774a194e39 100644 --- a/scene/2d/gpu_particles_2d.cpp +++ b/scene/2d/gpu_particles_2d.cpp @@ -369,6 +369,7 @@ void GPUParticles2D::_bind_methods() { GPUParticles2D::GPUParticles2D() { particles = RS::get_singleton()->particles_create(); + RS::get_singleton()->particles_set_mode(particles, RS::PARTICLES_MODE_2D); one_shot = false; // Needed so that set_emitting doesn't access uninitialized values set_emitting(true); diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp index 1a7038bb80..21083e6a4b 100644 --- a/scene/2d/polygon_2d.cpp +++ b/scene/2d/polygon_2d.cpp @@ -302,17 +302,18 @@ void Polygon2D::_notification(int p_what) { colors.write[i] = color_r[i]; } } else { - colors.push_back(color); + colors.resize(len); + for (int i = 0; i < len; i++) { + colors.write[i] = color; + } } + Vector<int> index_array; + if (invert || polygons.size() == 0) { - Vector<int> indices = Geometry2D::triangulate_polygon(points); - if (indices.size()) { - RS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID(), -1); - } + index_array = Geometry2D::triangulate_polygon(points); } else { //draw individual polygons - Vector<int> total_indices; for (int i = 0; i < polygons.size(); i++) { Vector<int> src_indices = polygons[i]; int ic = src_indices.size(); @@ -333,18 +334,38 @@ void Polygon2D::_notification(int p_what) { int ic2 = indices.size(); const int *r2 = indices.ptr(); - int bic = total_indices.size(); - total_indices.resize(bic + ic2); - int *w2 = total_indices.ptrw(); + int bic = index_array.size(); + index_array.resize(bic + ic2); + int *w2 = index_array.ptrw(); for (int j = 0; j < ic2; j++) { w2[j + bic] = r[r2[j]]; } } + } + + RS::get_singleton()->mesh_clear(mesh); + + if (index_array.size()) { + Array arr; + arr.resize(RS::ARRAY_MAX); + arr[RS::ARRAY_VERTEX] = points; + if (uvs.size() == points.size()) { + arr[RS::ARRAY_TEX_UV] = uvs; + } + if (colors.size() == points.size()) { + arr[RS::ARRAY_COLOR] = colors; + } - if (total_indices.size()) { - RS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), total_indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID()); + if (bones.size() == points.size() * 4) { + arr[RS::ARRAY_BONES] = bones; + arr[RS::ARRAY_WEIGHTS] = weights; } + + arr[RS::ARRAY_INDEX] = index_array; + + RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RS::ARRAY_FLAG_USE_2D_VERTICES); + RS::get_singleton()->canvas_item_add_mesh(get_canvas_item(), mesh, Transform2D(), Color(), texture.is_valid() ? texture->get_rid() : RID()); } } break; @@ -655,4 +676,9 @@ void Polygon2D::_bind_methods() { } Polygon2D::Polygon2D() { + mesh = RS::get_singleton()->mesh_create(); +} + +Polygon2D::~Polygon2D() { + RS::get_singleton()->free(mesh); } diff --git a/scene/2d/polygon_2d.h b/scene/2d/polygon_2d.h index c207024a53..f9f36ff9a2 100644 --- a/scene/2d/polygon_2d.h +++ b/scene/2d/polygon_2d.h @@ -72,6 +72,8 @@ class Polygon2D : public Node2D { void _skeleton_bone_setup_changed(); + RID mesh; + protected: void _notification(int p_what); static void _bind_methods(); @@ -149,6 +151,7 @@ public: NodePath get_skeleton() const; Polygon2D(); + ~Polygon2D(); }; #endif // POLYGON_2D_H diff --git a/scene/3d/gpu_particles_3d.cpp b/scene/3d/gpu_particles_3d.cpp index 5339b8a8da..50044ddc67 100644 --- a/scene/3d/gpu_particles_3d.cpp +++ b/scene/3d/gpu_particles_3d.cpp @@ -613,6 +613,7 @@ void GPUParticles3D::_bind_methods() { GPUParticles3D::GPUParticles3D() { particles = RS::get_singleton()->particles_create(); + RS::get_singleton()->particles_set_mode(particles, RS::PARTICLES_MODE_3D); set_base(particles); one_shot = false; // Needed so that set_emitting doesn't access uninitialized values set_emitting(true); |