mirror of
https://github.com/godotengine/godot.git
synced 2024-11-27 09:16:35 +08:00
Merge pull request #21907 from JFonS/concave_collision_gizmo
Fix SoftBody gizmo slowness, add ConcaveShape wireframe
This commit is contained in:
commit
efeb88b102
@ -55,6 +55,7 @@
|
||||
#include "scene/3d/visibility_notifier.h"
|
||||
#include "scene/resources/box_shape.h"
|
||||
#include "scene/resources/capsule_shape.h"
|
||||
#include "scene/resources/concave_polygon_shape.h"
|
||||
#include "scene/resources/convex_polygon_shape.h"
|
||||
#include "scene/resources/cylinder_shape.h"
|
||||
#include "scene/resources/plane_shape.h"
|
||||
@ -908,7 +909,6 @@ void LightSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
}
|
||||
|
||||
p_gizmo->add_lines(lines, material);
|
||||
p_gizmo->add_collision_segments(lines);
|
||||
p_gizmo->add_unscaled_billboard(icon, 0.05);
|
||||
}
|
||||
|
||||
@ -939,8 +939,6 @@ void LightSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
}
|
||||
|
||||
p_gizmo->add_lines(points, material, true);
|
||||
p_gizmo->add_collision_segments(points);
|
||||
|
||||
p_gizmo->add_unscaled_billboard(icon, 0.05);
|
||||
|
||||
Vector<Vector3> handles;
|
||||
@ -982,38 +980,14 @@ void LightSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
|
||||
p_gizmo->add_lines(points, material);
|
||||
|
||||
float ra = 16 * Math_PI * 2.0 / 64.0;
|
||||
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * w;
|
||||
|
||||
Vector<Vector3> handles;
|
||||
handles.push_back(Vector3(0, 0, -r));
|
||||
|
||||
Vector<Vector3> collision_segments;
|
||||
|
||||
for (int i = 0; i < 64; i++) {
|
||||
|
||||
float ra = i * Math_PI * 2.0 / 64.0;
|
||||
float rb = (i + 1) * Math_PI * 2.0 / 64.0;
|
||||
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * w;
|
||||
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * w;
|
||||
|
||||
collision_segments.push_back(Vector3(a.x, a.y, -d));
|
||||
collision_segments.push_back(Vector3(b.x, b.y, -d));
|
||||
|
||||
if (i % 16 == 0) {
|
||||
|
||||
collision_segments.push_back(Vector3(a.x, a.y, -d));
|
||||
collision_segments.push_back(Vector3());
|
||||
}
|
||||
|
||||
if (i == 16) {
|
||||
|
||||
handles.push_back(Vector3(a.x, a.y, -d));
|
||||
}
|
||||
}
|
||||
|
||||
collision_segments.push_back(Vector3(0, 0, -r));
|
||||
collision_segments.push_back(Vector3());
|
||||
handles.push_back(Vector3(a.x, a.y, -d));
|
||||
|
||||
p_gizmo->add_handles(handles, get_material("handles"));
|
||||
p_gizmo->add_collision_segments(collision_segments);
|
||||
p_gizmo->add_unscaled_billboard(icon, 0.05);
|
||||
}
|
||||
}
|
||||
@ -1149,7 +1123,6 @@ void AudioStreamPlayer3DSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo)
|
||||
}
|
||||
|
||||
p_gizmo->add_lines(points, material);
|
||||
p_gizmo->add_collision_segments(points);
|
||||
|
||||
Vector<Vector3> handles;
|
||||
float ha = Math::deg2rad(player->get_emission_angle());
|
||||
@ -1344,7 +1317,6 @@ void CameraSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
}
|
||||
|
||||
p_gizmo->add_lines(lines, material);
|
||||
p_gizmo->add_collision_segments(lines);
|
||||
p_gizmo->add_unscaled_billboard(icon, 0.05);
|
||||
p_gizmo->add_handles(handles, get_material("handles"));
|
||||
|
||||
@ -1387,7 +1359,6 @@ void CameraSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
}
|
||||
|
||||
p_gizmo->add_lines(lines, material);
|
||||
p_gizmo->add_collision_segments(lines);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2123,12 +2094,10 @@ void SoftBodySpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
|
||||
Vector<Vector3> points;
|
||||
soft_body->get_mesh()->generate_debug_mesh_indices(points);
|
||||
soft_body->get_mesh()->clear_cache();
|
||||
|
||||
Ref<Material> material = get_material("shape_material", p_gizmo);
|
||||
|
||||
p_gizmo->add_lines(lines, material);
|
||||
p_gizmo->add_collision_segments(lines);
|
||||
p_gizmo->add_handles(points, get_material("handles"));
|
||||
p_gizmo->add_collision_triangles(tm);
|
||||
}
|
||||
@ -2445,7 +2414,6 @@ void ParticlesGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
Ref<Material> icon = get_material("particles_icon", p_gizmo);
|
||||
|
||||
p_gizmo->add_lines(lines, material);
|
||||
p_gizmo->add_collision_segments(lines);
|
||||
|
||||
if (p_gizmo->is_selected()) {
|
||||
Ref<Material> solid_material = get_material("particles_solid_material", p_gizmo);
|
||||
@ -2630,7 +2598,6 @@ void ReflectionProbeGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
}
|
||||
|
||||
p_gizmo->add_unscaled_billboard(icon, 0.05);
|
||||
p_gizmo->add_collision_segments(lines);
|
||||
p_gizmo->add_handles(handles, get_material("handles"));
|
||||
}
|
||||
|
||||
@ -2745,7 +2712,6 @@ void GIProbeGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
}
|
||||
|
||||
p_gizmo->add_lines(lines, material);
|
||||
p_gizmo->add_collision_segments(lines);
|
||||
|
||||
lines.clear();
|
||||
|
||||
@ -2915,7 +2881,6 @@ void BakedIndirectLightGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
}
|
||||
|
||||
p_gizmo->add_lines(lines, material);
|
||||
p_gizmo->add_collision_segments(lines);
|
||||
|
||||
Vector<Vector3> handles;
|
||||
|
||||
@ -3506,6 +3471,14 @@ void CollisionShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Object::cast_to<ConcavePolygonShape>(*s)) {
|
||||
|
||||
Ref<ConcavePolygonShape> cs = s;
|
||||
Ref<ArrayMesh> mesh = cs->get_debug_mesh()->duplicate();
|
||||
mesh->surface_set_material(0, material);
|
||||
p_gizmo->add_mesh(mesh);
|
||||
}
|
||||
|
||||
if (Object::cast_to<RayShape>(*s)) {
|
||||
|
||||
Ref<RayShape> rs = s;
|
||||
|
@ -37,11 +37,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void Mesh::_clear_triangle_mesh() const {
|
||||
|
||||
triangle_mesh.unref();
|
||||
}
|
||||
|
||||
Ref<TriangleMesh> Mesh::generate_triangle_mesh() const {
|
||||
|
||||
if (triangle_mesh.is_valid())
|
||||
@ -111,6 +106,11 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const {
|
||||
|
||||
void Mesh::generate_debug_mesh_lines(Vector<Vector3> &r_lines) {
|
||||
|
||||
if (debug_lines.size() > 0) {
|
||||
r_lines = debug_lines;
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<TriangleMesh> tm = generate_triangle_mesh();
|
||||
if (tm.is_null())
|
||||
return;
|
||||
@ -120,23 +120,25 @@ void Mesh::generate_debug_mesh_lines(Vector<Vector3> &r_lines) {
|
||||
const int triangles_num = tm->get_triangles().size();
|
||||
PoolVector<Vector3> vertices = tm->get_vertices();
|
||||
|
||||
r_lines.resize(tm->get_triangles().size() * 6); // 3 lines x 2 points each line
|
||||
debug_lines.resize(tm->get_triangles().size() * 6); // 3 lines x 2 points each line
|
||||
|
||||
PoolVector<int>::Read ind_r = triangle_indices.read();
|
||||
PoolVector<Vector3>::Read ver_r = vertices.read();
|
||||
for (int j = 0, x = 0, i = 0; i < triangles_num; j += 6, x += 3, ++i) {
|
||||
// Triangle line 1
|
||||
r_lines.write[j + 0] = ver_r[ind_r[x + 0]];
|
||||
r_lines.write[j + 1] = ver_r[ind_r[x + 1]];
|
||||
debug_lines.write[j + 0] = ver_r[ind_r[x + 0]];
|
||||
debug_lines.write[j + 1] = ver_r[ind_r[x + 1]];
|
||||
|
||||
// Triangle line 2
|
||||
r_lines.write[j + 2] = ver_r[ind_r[x + 1]];
|
||||
r_lines.write[j + 3] = ver_r[ind_r[x + 2]];
|
||||
debug_lines.write[j + 2] = ver_r[ind_r[x + 1]];
|
||||
debug_lines.write[j + 3] = ver_r[ind_r[x + 2]];
|
||||
|
||||
// Triangle line 3
|
||||
r_lines.write[j + 4] = ver_r[ind_r[x + 2]];
|
||||
r_lines.write[j + 5] = ver_r[ind_r[x + 0]];
|
||||
debug_lines.write[j + 4] = ver_r[ind_r[x + 2]];
|
||||
debug_lines.write[j + 5] = ver_r[ind_r[x + 0]];
|
||||
}
|
||||
|
||||
r_lines = debug_lines;
|
||||
}
|
||||
void Mesh::generate_debug_mesh_indices(Vector<Vector3> &r_points) {
|
||||
Ref<TriangleMesh> tm = generate_triangle_mesh();
|
||||
@ -536,8 +538,9 @@ void Mesh::_bind_methods() {
|
||||
BIND_ENUM_CONSTANT(ARRAY_MAX);
|
||||
}
|
||||
|
||||
void Mesh::clear_cache() {
|
||||
_clear_triangle_mesh();
|
||||
void Mesh::clear_cache() const {
|
||||
triangle_mesh.unref();
|
||||
debug_lines.clear();
|
||||
}
|
||||
|
||||
Mesh::Mesh() {
|
||||
@ -850,7 +853,7 @@ void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array &
|
||||
_recompute_aabb();
|
||||
}
|
||||
|
||||
_clear_triangle_mesh();
|
||||
clear_cache();
|
||||
_change_notify();
|
||||
emit_changed();
|
||||
}
|
||||
@ -929,7 +932,7 @@ void ArrayMesh::surface_remove(int p_idx) {
|
||||
VisualServer::get_singleton()->mesh_remove_surface(mesh, p_idx);
|
||||
surfaces.remove(p_idx);
|
||||
|
||||
_clear_triangle_mesh();
|
||||
clear_cache();
|
||||
_recompute_aabb();
|
||||
_change_notify();
|
||||
emit_changed();
|
||||
@ -1035,7 +1038,7 @@ void ArrayMesh::add_surface_from_mesh_data(const Geometry::MeshData &p_mesh_data
|
||||
else
|
||||
aabb.merge_with(s.aabb);
|
||||
|
||||
_clear_triangle_mesh();
|
||||
clear_cache();
|
||||
|
||||
surfaces.push_back(s);
|
||||
_change_notify();
|
||||
|
@ -44,11 +44,10 @@ class Mesh : public Resource {
|
||||
GDCLASS(Mesh, Resource);
|
||||
|
||||
mutable Ref<TriangleMesh> triangle_mesh; //cached
|
||||
mutable Vector<Vector3> debug_lines;
|
||||
Size2 lightmap_size_hint;
|
||||
|
||||
protected:
|
||||
void _clear_triangle_mesh() const;
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
@ -146,7 +145,7 @@ public:
|
||||
|
||||
void set_lightmap_size_hint(const Vector2 &p_size);
|
||||
Size2 get_lightmap_size_hint() const;
|
||||
void clear_cache();
|
||||
void clear_cache() const;
|
||||
|
||||
Mesh();
|
||||
};
|
||||
|
@ -89,7 +89,7 @@ void PrimitiveMesh::_update() const {
|
||||
|
||||
pending_request = false;
|
||||
|
||||
_clear_triangle_mesh();
|
||||
clear_cache();
|
||||
|
||||
const_cast<PrimitiveMesh *>(this)->emit_changed();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user