feat: updated engine version to 4.4-rc1

This commit is contained in:
Sara 2025-02-23 14:38:14 +01:00
parent ee00efde1f
commit 21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *
Import("env")

View file

@ -32,7 +32,6 @@
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/audio_listener_3d.h"
AudioListener3DGizmoPlugin::AudioListener3DGizmoPlugin() {

View file

@ -34,11 +34,10 @@
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/audio_stream_player_3d.h"
AudioStreamPlayer3DGizmoPlugin::AudioStreamPlayer3DGizmoPlugin() {
Color gizmo_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/stream_player_3d", Color(0.4, 0.8, 1));
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/stream_player_3d");
create_icon_material("stream_player_3d_icon", EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Gizmo3DSamplePlayer"), EditorStringName(EditorIcons)));
create_material("stream_player_3d_material_primary", gizmo_color);

View file

@ -30,7 +30,6 @@
#include "camera_3d_gizmo_plugin.h"
#include "core/config/project_settings.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
@ -39,31 +38,13 @@
#include "scene/3d/camera_3d.h"
Camera3DGizmoPlugin::Camera3DGizmoPlugin() {
Color gizmo_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/camera", Color(0.8, 0.4, 0.8));
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/camera");
create_material("camera_material", gizmo_color);
create_icon_material("camera_icon", EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("GizmoCamera3D"), EditorStringName(EditorIcons)));
create_handle_material("handles");
}
Size2i Camera3DGizmoPlugin::_get_viewport_size(Camera3D *p_camera) {
Viewport *viewport = p_camera->get_viewport();
Window *window = Object::cast_to<Window>(viewport);
if (window) {
return window->get_size();
}
SubViewport *sub_viewport = Object::cast_to<SubViewport>(viewport);
ERR_FAIL_NULL_V(sub_viewport, Size2i());
if (sub_viewport == EditorNode::get_singleton()->get_scene_root()) {
return Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
}
return sub_viewport->get_size();
}
bool Camera3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
return Object::cast_to<Camera3D>(p_spatial) != nullptr;
}
@ -112,9 +93,12 @@ void Camera3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id,
float a = _find_closest_angle_to_half_pi_arc(s[0], s[1], 1.0, gt2);
camera->set("fov", CLAMP(a * 2.0, 1, 179));
} else {
Camera3D::KeepAspect aspect = camera->get_keep_aspect_mode();
Vector3 camera_far = aspect == Camera3D::KeepAspect::KEEP_WIDTH ? Vector3(4096, 0, -1) : Vector3(0, 4096, -1);
Vector3 ra, rb;
Geometry3D::get_closest_points_between_segments(Vector3(0, 0, -1), Vector3(4096, 0, -1), s[0], s[1], ra, rb);
float d = ra.x * 2;
Geometry3D::get_closest_points_between_segments(Vector3(0, 0, -1), camera_far, s[0], s[1], ra, rb);
float d = aspect == Camera3D::KeepAspect::KEEP_WIDTH ? ra.x * 2 : ra.y * 2;
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap());
}
@ -163,7 +147,7 @@ void Camera3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Ref<Material> material = get_material("camera_material", p_gizmo);
Ref<Material> icon = get_material("camera_icon", p_gizmo);
const Size2i viewport_size = _get_viewport_size(camera);
const Size2i viewport_size = Node3DEditor::get_camera_viewport_size(camera);
const real_t viewport_aspect = viewport_size.x > 0 && viewport_size.y > 0 ? viewport_size.aspect() : 1.0;
const Size2 size_factor = viewport_aspect > 1.0 ? Size2(1.0, 1.0 / viewport_aspect) : Size2(viewport_aspect, 1.0);
@ -213,25 +197,33 @@ void Camera3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
} break;
case Camera3D::PROJECTION_ORTHOGONAL: {
float size = camera->get_size();
Camera3D::KeepAspect aspect = camera->get_keep_aspect_mode();
float hsize = size * 0.5;
Vector3 right(hsize * size_factor.x, 0, 0);
Vector3 up(0, hsize * size_factor.y, 0);
float size = camera->get_size();
float keep_size = size * 0.5;
Vector3 right, up;
Vector3 back(0, 0, -1.0);
Vector3 front(0, 0, 0);
if (aspect == Camera3D::KeepAspect::KEEP_WIDTH) {
right = Vector3(keep_size, 0, 0);
up = Vector3(0, keep_size / viewport_aspect, 0);
handles.push_back(right + back);
} else {
right = Vector3(keep_size * viewport_aspect, 0, 0);
up = Vector3(0, keep_size, 0);
handles.push_back(up + back);
}
ADD_QUAD(-up - right, -up + right, up + right, up - right);
ADD_QUAD(-up - right + back, -up + right + back, up + right + back, up - right + back);
ADD_QUAD(up + right, up + right + back, up - right + back, up - right);
ADD_QUAD(-up + right, -up + right + back, -up - right + back, -up - right);
handles.push_back(right + back);
right.x = MIN(right.x, hsize * 0.25);
Vector3 tup(0, up.y + hsize / 2, back.z);
right.x = MIN(right.x, keep_size * 0.25);
Vector3 tup(0, up.y + keep_size / 2, back.z);
ADD_TRIANGLE(tup, right + up + back, -right + up + back);
} break;
case Camera3D::PROJECTION_FRUSTUM: {

View file

@ -37,7 +37,6 @@ class Camera3DGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(Camera3DGizmoPlugin, EditorNode3DGizmoPlugin);
private:
static Size2i _get_viewport_size(Camera3D *p_camera);
static float _find_closest_angle_to_half_pi_arc(const Vector3 &p_from, const Vector3 &p_to, float p_arc_radius, const Transform3D &p_arc_xform);
public:

View file

@ -30,8 +30,6 @@
#include "collision_object_3d_gizmo_plugin.h"
#include "editor/editor_settings.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/physics/collision_object_3d.h"
#include "scene/3d/physics/collision_polygon_3d.h"
#include "scene/3d/physics/collision_shape_3d.h"

View file

@ -30,16 +30,44 @@
#include "collision_polygon_3d_gizmo_plugin.h"
#include "editor/editor_settings.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "core/math/geometry_2d.h"
#include "scene/3d/physics/collision_polygon_3d.h"
CollisionPolygon3DGizmoPlugin::CollisionPolygon3DGizmoPlugin() {
const Color gizmo_color = SceneTree::get_singleton()->get_debug_collisions_color();
create_material("shape_material", gizmo_color);
const float gizmo_value = gizmo_color.get_v();
const Color gizmo_color_disabled = Color(gizmo_value, gizmo_value, gizmo_value, 0.65);
create_material("shape_material_disabled", gizmo_color_disabled);
create_collision_material("shape_material", 2.0);
create_collision_material("shape_material_arraymesh", 0.0625);
create_collision_material("shape_material_disabled", 0.0625);
create_collision_material("shape_material_arraymesh_disabled", 0.015625);
}
void CollisionPolygon3DGizmoPlugin::create_collision_material(const String &p_name, float p_alpha) {
Vector<Ref<StandardMaterial3D>> mats;
const Color collision_color(1.0, 1.0, 1.0, p_alpha);
for (int i = 0; i < 4; i++) {
bool instantiated = i < 2;
Ref<StandardMaterial3D> material;
material.instantiate();
Color color = collision_color;
color.a *= instantiated ? 0.25 : 1.0;
material->set_albedo(color);
material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 1);
material->set_cull_mode(StandardMaterial3D::CULL_BACK);
material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
mats.push_back(material);
}
materials[p_name] = mats;
}
bool CollisionPolygon3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
@ -59,6 +87,13 @@ void CollisionPolygon3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
p_gizmo->clear();
const Ref<StandardMaterial3D> material =
get_material(!polygon->is_disabled() ? "shape_material" : "shape_material_disabled", p_gizmo);
const Ref<StandardMaterial3D> material_arraymesh =
get_material(!polygon->is_disabled() ? "shape_material_arraymesh" : "shape_material_arraymesh_disabled", p_gizmo);
const Color collision_color = polygon->is_disabled() ? Color(1.0, 1.0, 1.0, 0.75) : polygon->get_debug_color();
Vector<Vector2> points = polygon->get_polygon();
float depth = polygon->get_depth() * 0.5;
@ -73,9 +108,125 @@ void CollisionPolygon3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
lines.push_back(Vector3(points[i].x, points[i].y, -depth));
}
const Ref<Material> material =
get_material(!polygon->is_disabled() ? "shape_material" : "shape_material_disabled", p_gizmo);
if (polygon->get_debug_fill_enabled()) {
Ref<ArrayMesh> array_mesh;
array_mesh.instantiate();
p_gizmo->add_lines(lines, material);
Vector<Vector3> verts;
Vector<Color> colors;
Vector<int> indices;
// Determine orientation of the 2D polygon's vertices to determine
// which direction to draw outer polygons.
float signed_area = 0.0f;
for (int i = 0; i < points.size(); i++) {
const int j = (i + 1) % points.size();
signed_area += points[i].x * points[j].y - points[j].x * points[i].y;
}
// Generate triangles for the sides of the extruded polygon.
for (int i = 0; i < points.size(); i++) {
verts.push_back(Vector3(points[i].x, points[i].y, depth));
verts.push_back(Vector3(points[i].x, points[i].y, -depth));
colors.push_back(collision_color);
colors.push_back(collision_color);
}
for (int i = 0; i < verts.size(); i += 2) {
const int j = (i + 1) % verts.size();
const int k = (i + 2) % verts.size();
const int l = (i + 3) % verts.size();
indices.push_back(i);
if (signed_area < 0) {
indices.push_back(j);
indices.push_back(k);
} else {
indices.push_back(k);
indices.push_back(j);
}
indices.push_back(j);
if (signed_area < 0) {
indices.push_back(l);
indices.push_back(k);
} else {
indices.push_back(k);
indices.push_back(l);
}
}
Vector<Vector<Vector2>> decomp = Geometry2D::decompose_polygon_in_convex(polygon->get_polygon());
// Generate triangles for the bottom cap of the extruded polygon.
for (int i = 0; i < decomp.size(); i++) {
Vector<Vector3> cap_verts_bottom;
Vector<Color> cap_colours_bottom;
Vector<int> cap_indices_bottom;
const int index_offset = verts.size();
const Vector<Vector2> &convex = decomp[i];
for (int j = 0; j < convex.size(); j++) {
cap_verts_bottom.push_back(Vector3(convex[j].x, convex[j].y, -depth));
cap_colours_bottom.push_back(collision_color);
}
if (convex.size() >= 3) {
for (int j = 1; j < convex.size(); j++) {
const int k = (j + 1) % convex.size();
cap_indices_bottom.push_back(index_offset + 0);
cap_indices_bottom.push_back(index_offset + j);
cap_indices_bottom.push_back(index_offset + k);
}
}
verts.append_array(cap_verts_bottom);
colors.append_array(cap_colours_bottom);
indices.append_array(cap_indices_bottom);
}
// Generate triangles for the top cap of the extruded polygon.
for (int i = 0; i < decomp.size(); i++) {
Vector<Vector3> cap_verts_top;
Vector<Color> cap_colours_top;
Vector<int> cap_indices_top;
const int index_offset = verts.size();
const Vector<Vector2> &convex = decomp[i];
for (int j = 0; j < convex.size(); j++) {
cap_verts_top.push_back(Vector3(convex[j].x, convex[j].y, depth));
cap_colours_top.push_back(collision_color);
}
if (convex.size() >= 3) {
for (int j = 1; j < convex.size(); j++) {
const int k = (j + 1) % convex.size();
cap_indices_top.push_back(index_offset + k);
cap_indices_top.push_back(index_offset + j);
cap_indices_top.push_back(index_offset + 0);
}
}
verts.append_array(cap_verts_top);
colors.append_array(cap_colours_top);
indices.append_array(cap_indices_top);
}
Array a;
a.resize(Mesh::ARRAY_MAX);
a[RS::ARRAY_VERTEX] = verts;
a[RS::ARRAY_COLOR] = colors;
a[RS::ARRAY_INDEX] = indices;
array_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, a);
p_gizmo->add_mesh(array_mesh, material_arraymesh);
}
p_gizmo->add_lines(lines, material, false, collision_color);
p_gizmo->add_collision_segments(lines);
}

View file

@ -36,6 +36,8 @@
class CollisionPolygon3DGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(CollisionPolygon3DGizmoPlugin, EditorNode3DGizmoPlugin);
void create_collision_material(const String &p_name, float p_alpha);
public:
bool has_gizmo(Node3D *p_spatial) override;
String get_gizmo_name() const override;

View file

@ -32,7 +32,6 @@
#include "core/math/convex_hull.h"
#include "core/math/geometry_3d.h"
#include "editor/editor_settings.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/plugins/gizmos/gizmo_3d_helper.h"
#include "editor/plugins/node_3d_editor_plugin.h"
@ -49,17 +48,47 @@
CollisionShape3DGizmoPlugin::CollisionShape3DGizmoPlugin() {
helper.instantiate();
const Color gizmo_color = SceneTree::get_singleton()->get_debug_collisions_color();
create_material("shape_material", gizmo_color);
const float gizmo_value = gizmo_color.get_v();
const Color gizmo_color_disabled = Color(gizmo_value, gizmo_value, gizmo_value, 0.65);
create_material("shape_material_disabled", gizmo_color_disabled);
create_collision_material("shape_material", 2.0);
create_collision_material("shape_material_arraymesh", 0.0625);
create_collision_material("shape_material_disabled", 0.0625);
create_collision_material("shape_material_arraymesh_disabled", 0.015625);
create_handle_material("handles");
}
CollisionShape3DGizmoPlugin::~CollisionShape3DGizmoPlugin() {
}
void CollisionShape3DGizmoPlugin::create_collision_material(const String &p_name, float p_alpha) {
Vector<Ref<StandardMaterial3D>> mats;
const Color collision_color(1.0, 1.0, 1.0, p_alpha);
for (int i = 0; i < 4; i++) {
bool instantiated = i < 2;
Ref<StandardMaterial3D> material = memnew(StandardMaterial3D);
Color color = collision_color;
color.a *= instantiated ? 0.25 : 1.0;
material->set_albedo(color);
material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 1);
material->set_cull_mode(StandardMaterial3D::CULL_BACK);
material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
mats.push_back(material);
}
materials[p_name] = mats;
}
bool CollisionShape3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
return Object::cast_to<CollisionShape3D>(p_spatial) != nullptr;
}
@ -93,7 +122,7 @@ String CollisionShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_g
}
if (Object::cast_to<CylinderShape3D>(*s)) {
return p_id == 0 ? "Radius" : "Height";
return helper->cylinder_get_handle_name(p_id);
}
if (Object::cast_to<SeparationRayShape3D>(*s)) {
@ -219,25 +248,15 @@ void CollisionShape3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, i
}
if (Object::cast_to<CylinderShape3D>(*s)) {
Vector3 axis;
axis[p_id == 0 ? 0 : 1] = 1.0;
Ref<CylinderShape3D> cs2 = s;
Vector3 ra, rb;
Geometry3D::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
float d = axis.dot(ra);
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap());
}
if (d < 0.001) {
d = 0.001;
}
if (p_id == 0) {
cs2->set_radius(d);
} else if (p_id == 1) {
cs2->set_height(d * 2.0);
}
real_t height = cs2->get_height();
real_t radius = cs2->get_radius();
Vector3 position;
helper->cylinder_set_handle(sg, p_id, height, radius, position);
cs2->set_height(height);
cs2->set_radius(radius);
cs->set_global_position(position);
}
}
@ -293,31 +312,7 @@ void CollisionShape3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo
if (Object::cast_to<CylinderShape3D>(*s)) {
Ref<CylinderShape3D> ss = s;
if (p_cancel) {
if (p_id == 0) {
ss->set_radius(p_restore);
} else {
ss->set_height(p_restore);
}
return;
}
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
if (p_id == 0) {
ur->create_action(TTR("Change Cylinder Shape Radius"));
ur->add_do_method(ss.ptr(), "set_radius", ss->get_radius());
ur->add_undo_method(ss.ptr(), "set_radius", p_restore);
} else {
ur->create_action(
///
////////
TTR("Change Cylinder Shape Height"));
ur->add_do_method(ss.ptr(), "set_height", ss->get_height());
ur->add_undo_method(ss.ptr(), "set_height", p_restore);
}
ur->commit_action();
helper->cylinder_commit_handle(p_id, TTR("Change Cylinder Shape Radius"), TTR("Change Cylinder Shape Height"), p_cancel, cs, *ss, *ss);
}
if (Object::cast_to<SeparationRayShape3D>(*s)) {
@ -345,9 +340,20 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
return;
}
const Ref<Material> material =
const Ref<StandardMaterial3D> material =
get_material(!cs->is_disabled() ? "shape_material" : "shape_material_disabled", p_gizmo);
Ref<Material> handles_material = get_material("handles");
const Ref<StandardMaterial3D> material_arraymesh =
get_material(!cs->is_disabled() ? "shape_material_arraymesh" : "shape_material_arraymesh_disabled", p_gizmo);
const Ref<Material> handles_material = get_material("handles");
const Color collision_color = cs->is_disabled() ? Color(1.0, 1.0, 1.0, 0.75) : cs->get_debug_color();
if (cs->get_debug_fill_enabled()) {
Ref<ArrayMesh> array_mesh = s->get_debug_arraymesh_faces(collision_color);
if (array_mesh.is_valid() && array_mesh->get_surface_count() > 0) {
p_gizmo->add_mesh(array_mesh, material_arraymesh);
}
}
if (Object::cast_to<SphereShape3D>(*s)) {
Ref<SphereShape3D> sp = s;
@ -385,7 +391,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
collision_segments.push_back(Vector3(b.x, b.y, 0));
}
p_gizmo->add_lines(points, material);
p_gizmo->add_lines(points, material, false, collision_color);
p_gizmo->add_collision_segments(collision_segments);
Vector<Vector3> handles;
handles.push_back(Vector3(r, 0, 0));
@ -408,7 +414,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
const Vector<Vector3> handles = helper->box_get_handles(bs->get_size());
p_gizmo->add_lines(lines, material);
p_gizmo->add_lines(lines, material, false, collision_color);
p_gizmo->add_collision_segments(lines);
p_gizmo->add_handles(handles, handles_material);
}
@ -446,7 +452,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
points.push_back(Vector3(b.y, b.x, 0) + dud);
}
p_gizmo->add_lines(points, material);
p_gizmo->add_lines(points, material, false, collision_color);
Vector<Vector3> collision_segments;
@ -510,7 +516,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
}
}
p_gizmo->add_lines(points, material);
p_gizmo->add_lines(points, material, false, collision_color);
Vector<Vector3> collision_segments;
@ -534,10 +540,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
p_gizmo->add_collision_segments(collision_segments);
Vector<Vector3> handles = {
Vector3(cs2->get_radius(), 0, 0),
Vector3(0, cs2->get_height() * 0.5, 0)
};
Vector<Vector3> handles = helper->cylinder_get_handles(cs2->get_height(), cs2->get_radius());
p_gizmo->add_handles(handles, handles_material);
}
@ -568,27 +571,26 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
p.normal * p.d + p.normal * 3
};
p_gizmo->add_lines(points, material);
p_gizmo->add_lines(points, material, false, collision_color);
p_gizmo->add_collision_segments(points);
}
if (Object::cast_to<ConvexPolygonShape3D>(*s)) {
Vector<Vector3> points = Object::cast_to<ConvexPolygonShape3D>(*s)->get_points();
if (points.size() > 3) {
if (points.size() > 1) { // Need at least 2 points for a line.
Vector<Vector3> varr = Variant(points);
Geometry3D::MeshData md;
Error err = ConvexHullComputer::convex_hull(varr, md);
if (err == OK) {
Vector<Vector3> points2;
points2.resize(md.edges.size() * 2);
Vector<Vector3> lines;
lines.resize(md.edges.size() * 2);
for (uint32_t i = 0; i < md.edges.size(); i++) {
points2.write[i * 2 + 0] = md.vertices[md.edges[i].vertex_a];
points2.write[i * 2 + 1] = md.vertices[md.edges[i].vertex_b];
lines.write[i * 2 + 0] = md.vertices[md.edges[i].vertex_a];
lines.write[i * 2 + 1] = md.vertices[md.edges[i].vertex_b];
}
p_gizmo->add_lines(points2, material);
p_gizmo->add_collision_segments(points2);
p_gizmo->add_lines(lines, material, false, collision_color);
p_gizmo->add_collision_segments(lines);
}
}
}
@ -596,7 +598,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
if (Object::cast_to<ConcavePolygonShape3D>(*s)) {
Ref<ConcavePolygonShape3D> cs2 = s;
Ref<ArrayMesh> mesh = cs2->get_debug_mesh();
p_gizmo->add_mesh(mesh, material);
p_gizmo->add_lines(cs2->get_debug_mesh_lines(), material, false, collision_color);
p_gizmo->add_collision_segments(cs2->get_debug_mesh_lines());
}
@ -607,7 +609,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Vector3(),
Vector3(0, 0, rs->get_length())
};
p_gizmo->add_lines(points, material);
p_gizmo->add_lines(points, material, false, collision_color);
p_gizmo->add_collision_segments(points);
Vector<Vector3> handles;
handles.push_back(Vector3(0, 0, rs->get_length()));
@ -617,7 +619,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
if (Object::cast_to<HeightMapShape3D>(*s)) {
Ref<HeightMapShape3D> hms = s;
Ref<ArrayMesh> mesh = hms->get_debug_mesh();
p_gizmo->add_mesh(mesh, material);
Vector<Vector3> lines = hms->get_debug_mesh_lines();
p_gizmo->add_lines(lines, material, false, collision_color);
}
}

View file

@ -38,6 +38,8 @@ class Gizmo3DHelper;
class CollisionShape3DGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(CollisionShape3DGizmoPlugin, EditorNode3DGizmoPlugin);
void create_collision_material(const String &p_name, float p_alpha);
Ref<Gizmo3DHelper> helper;
public:

View file

@ -33,11 +33,10 @@
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/cpu_particles_3d.h"
CPUParticles3DGizmoPlugin::CPUParticles3DGizmoPlugin() {
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/particles", Color(0.8, 0.7, 0.4));
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/particles");
create_material("particles_material", gizmo_color);
gizmo_color.a = MAX((gizmo_color.a - 0.2) * 0.02, 0.0);
create_material("particles_solid_material", gizmo_color);

View file

@ -33,14 +33,12 @@
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/plugins/gizmos/gizmo_3d_helper.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/decal.h"
DecalGizmoPlugin::DecalGizmoPlugin() {
helper.instantiate();
Color gizmo_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/decal", Color(0.6, 0.5, 1.0));
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/decal");
create_icon_material("decal_icon", EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("GizmoDecal"), EditorStringName(EditorIcons)));

View file

@ -33,14 +33,12 @@
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/plugins/gizmos/gizmo_3d_helper.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/fog_volume.h"
FogVolumeGizmoPlugin::FogVolumeGizmoPlugin() {
helper.instantiate();
Color gizmo_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/fog_volume", Color(0.5, 0.7, 1));
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/fog_volume");
create_material("shape_material", gizmo_color);
gizmo_color.a = 0.15;
create_material("shape_material_internal", gizmo_color);

View file

@ -30,9 +30,7 @@
#include "geometry_instance_3d_gizmo_plugin.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/visual_instance_3d.h"
GeometryInstance3DGizmoPlugin::GeometryInstance3DGizmoPlugin() {

View file

@ -139,3 +139,98 @@ void Gizmo3DHelper::box_commit_handle(const String &p_action_name, bool p_cancel
ur->add_undo_property(p_position_object, p_position_property, initial_transform.get_origin());
ur->commit_action();
}
Vector<Vector3> Gizmo3DHelper::cylinder_get_handles(real_t p_height, real_t p_radius) {
Vector<Vector3> handles;
handles.push_back(Vector3(p_radius, 0, 0));
handles.push_back(Vector3(0, p_height * 0.5, 0));
handles.push_back(Vector3(0, p_height * -0.5, 0));
return handles;
}
String Gizmo3DHelper::cylinder_get_handle_name(int p_id) const {
if (p_id == 0) {
return "Radius";
} else {
return "Height";
}
}
void Gizmo3DHelper::cylinder_set_handle(const Vector3 p_segment[2], int p_id, real_t &r_height, real_t &r_radius, Vector3 &r_cylinder_position) {
int sign = p_id == 2 ? -1 : 1;
int axis = p_id == 0 ? 0 : 1;
Vector3 axis_vector;
axis_vector[axis] = sign;
Vector3 ra, rb;
Geometry3D::get_closest_points_between_segments(axis_vector * -4096, axis_vector * 4096, p_segment[0], p_segment[1], ra, rb);
float d = axis_vector.dot(ra);
// Snap to grid.
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap());
}
if (p_id == 0) {
// Adjust radius.
if (d < 0.001) {
d = 0.001;
}
r_radius = d;
r_cylinder_position = initial_transform.get_origin();
} else if (p_id == 1 || p_id == 2) {
real_t initial_height = initial_value;
// Adjust height.
if (Input::get_singleton()->is_key_pressed(Key::ALT)) {
r_height = d * 2.0;
} else {
r_height = (initial_height * 0.5) + d;
}
if (r_height < 0.001) {
r_height = 0.001;
}
// Adjust position.
if (Input::get_singleton()->is_key_pressed(Key::ALT)) {
r_cylinder_position = initial_transform.get_origin();
} else {
Vector3 offset;
offset[axis] = (r_height - initial_height) * 0.5 * sign;
r_cylinder_position = initial_transform.xform(offset);
}
}
}
void Gizmo3DHelper::cylinder_commit_handle(int p_id, const String &p_radius_action_name, const String &p_height_action_name, bool p_cancel, Object *p_position_object, Object *p_height_object, Object *p_radius_object, const StringName &p_position_property, const StringName &p_height_property, const StringName &p_radius_property) {
if (!p_height_object) {
p_height_object = p_position_object;
}
if (!p_radius_object) {
p_radius_object = p_position_object;
}
if (p_cancel) {
if (p_id == 0) {
p_radius_object->set(p_radius_property, initial_value);
} else {
p_height_object->set(p_height_property, initial_value);
}
p_position_object->set(p_position_property, initial_transform.get_origin());
return;
}
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
ur->create_action(p_id == 0 ? p_radius_action_name : p_height_action_name);
if (p_id == 0) {
ur->add_do_property(p_radius_object, p_radius_property, p_radius_object->get(p_radius_property));
ur->add_undo_property(p_radius_object, p_radius_property, initial_value);
} else {
ur->add_do_property(p_height_object, p_height_property, p_height_object->get(p_height_property));
ur->add_do_property(p_position_object, p_position_property, p_position_object->get(p_position_property));
ur->add_undo_property(p_height_object, p_height_property, initial_value);
ur->add_undo_property(p_position_object, p_position_property, initial_transform.get_origin());
}
ur->commit_action();
}

View file

@ -50,6 +50,11 @@ public:
String box_get_handle_name(int p_id) const;
void box_set_handle(const Vector3 p_segment[2], int p_id, Vector3 &r_box_size, Vector3 &r_box_position);
void box_commit_handle(const String &p_action_name, bool p_cancel, Object *p_position_object, Object *p_size_object = nullptr, const StringName &p_position_property = "global_position", const StringName &p_size_property = "size");
Vector<Vector3> cylinder_get_handles(real_t p_height, real_t p_radius);
String cylinder_get_handle_name(int p_id) const;
void cylinder_set_handle(const Vector3 p_segment[2], int p_id, real_t &r_height, real_t &r_radius, Vector3 &r_cylinder_position);
void cylinder_commit_handle(int p_id, const String &p_radius_action_name, const String &p_height_action_name, bool p_cancel, Object *p_position_object, Object *p_height_object = nullptr, Object *p_radius_object = nullptr, const StringName &p_position_property = "global_position", const StringName &p_height_property = "height", const StringName &p_radius_property = "radius");
};
#endif // GIZMO_3D_HELPER_H

View file

@ -33,12 +33,10 @@
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/gpu_particles_3d.h"
GPUParticles3DGizmoPlugin::GPUParticles3DGizmoPlugin() {
Color gizmo_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/particles", Color(0.8, 0.7, 0.4));
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/particles");
create_material("particles_material", gizmo_color);
gizmo_color.a = MAX((gizmo_color.a - 0.2) * 0.02, 0.0);
create_icon_material("particles_icon", EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("GizmoGPUParticles3D"), EditorStringName(EditorIcons)));

View file

@ -39,12 +39,12 @@
GPUParticlesCollision3DGizmoPlugin::GPUParticlesCollision3DGizmoPlugin() {
helper.instantiate();
Color gizmo_color_attractor = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/particle_attractor", Color(1, 0.7, 0.5));
Color gizmo_color_attractor = EDITOR_GET("editors/3d_gizmos/gizmo_colors/particle_attractor");
create_material("shape_material_attractor", gizmo_color_attractor);
gizmo_color_attractor.a = 0.15;
create_material("shape_material_attractor_internal", gizmo_color_attractor);
Color gizmo_color_collision = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/particle_collision", Color(0.5, 0.7, 1));
Color gizmo_color_collision = EDITOR_GET("editors/3d_gizmos/gizmo_colors/particle_collision");
create_material("shape_material_collision", gizmo_color_collision);
gizmo_color_collision.a = 0.15;
create_material("shape_material_collision_internal", gizmo_color_collision);

View file

@ -32,7 +32,6 @@
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/physics/joints/cone_twist_joint_3d.h"
#include "scene/3d/physics/joints/generic_6dof_joint_3d.h"
#include "scene/3d/physics/joints/hinge_joint_3d.h"
@ -280,8 +279,8 @@ void JointGizmosDrawer::draw_cone(const Transform3D &p_offset, const Basis &p_ba
Joint3DGizmoPlugin::Joint3DGizmoPlugin() {
create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint"));
create_material("joint_body_a_material", EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/joint_body_a", Color(0.6, 0.8, 1)));
create_material("joint_body_b_material", EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/joint_body_b", Color(0.6, 0.9, 1)));
create_material("joint_body_a_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint_body_a"));
create_material("joint_body_b_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint_body_b"));
update_timer = memnew(Timer);
update_timer->set_name("JointGizmoUpdateTimer");
@ -293,9 +292,15 @@ Joint3DGizmoPlugin::Joint3DGizmoPlugin() {
void Joint3DGizmoPlugin::incremental_update_gizmos() {
if (!current_gizmos.is_empty()) {
update_idx++;
update_idx = update_idx % current_gizmos.size();
redraw(current_gizmos.get(update_idx));
HashSet<EditorNode3DGizmo *>::Iterator E = current_gizmos.find(last_drawn);
if (E) {
++E;
}
if (!E) {
E = current_gizmos.begin();
}
redraw(*E);
last_drawn = *E;
}
}

View file

@ -37,7 +37,7 @@ class Joint3DGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(Joint3DGizmoPlugin, EditorNode3DGizmoPlugin);
Timer *update_timer = nullptr;
uint64_t update_idx = 0;
EditorNode3DGizmo *last_drawn = nullptr;
void incremental_update_gizmos();

View file

@ -30,7 +30,6 @@
#include "label_3d_gizmo_plugin.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/label_3d.h"
Label3DGizmoPlugin::Label3DGizmoPlugin() {

View file

@ -30,9 +30,7 @@
#include "light_3d_gizmo_plugin.h"
#include "core/config/project_settings.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/plugins/node_3d_editor_plugin.h"

View file

@ -33,18 +33,20 @@
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/lightmap_gi.h"
LightmapGIGizmoPlugin::LightmapGIGizmoPlugin() {
Color gizmo_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/lightmap_lines", Color(0.5, 0.6, 1));
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/lightmap_lines");
gizmo_color.a = 0.1;
create_material("lightmap_lines", gizmo_color);
Ref<StandardMaterial3D> mat = memnew(StandardMaterial3D);
mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
mat->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
// Fade out probes when camera gets too close to them.
mat->set_distance_fade(StandardMaterial3D::DISTANCE_FADE_PIXEL_DITHER);
mat->set_distance_fade_min_distance(0.5);
mat->set_distance_fade_max_distance(1.5);
mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, false);
mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);

View file

@ -33,13 +33,12 @@
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/lightmap_probe.h"
LightmapProbeGizmoPlugin::LightmapProbeGizmoPlugin() {
create_icon_material("lightmap_probe_icon", EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("GizmoLightmapProbe"), EditorStringName(EditorIcons)));
Color gizmo_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/lightprobe_lines", Color(0.5, 0.6, 1));
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/lightprobe_lines");
gizmo_color.a = 0.3;
create_material("lightprobe_lines", gizmo_color);

View file

@ -32,11 +32,10 @@
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/marker_3d.h"
Marker3DGizmoPlugin::Marker3DGizmoPlugin() {
pos3d_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
pos3d_mesh.instantiate();
Vector<Vector3> cursor_points;
Vector<Color> cursor_colors;

View file

@ -33,6 +33,7 @@
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/soft_body_3d.h"
#include "scene/resources/3d/primitive_meshes.h"
MeshInstance3DGizmoPlugin::MeshInstance3DGizmoPlugin() {
}
@ -60,11 +61,26 @@ void MeshInstance3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Ref<Mesh> m = mesh->get_mesh();
if (!m.is_valid()) {
if (m.is_null()) {
return; //none
}
Ref<TriangleMesh> tm = m->generate_triangle_mesh();
Ref<TriangleMesh> tm;
Ref<PlaneMesh> plane_mesh = mesh->get_mesh();
if (plane_mesh.is_valid() && (plane_mesh->get_subdivide_depth() > 0 || plane_mesh->get_subdivide_width() > 0)) {
// PlaneMesh subdiv makes gizmo redraw very slow due to TriangleMesh BVH calculation for every face.
// For gizmo collision this is very much unnecessary since a PlaneMesh is always flat, 2 faces is enough.
Ref<PlaneMesh> simple_plane_mesh;
simple_plane_mesh.instantiate();
simple_plane_mesh->set_orientation(plane_mesh->get_orientation());
simple_plane_mesh->set_size(plane_mesh->get_size());
simple_plane_mesh->set_center_offset(plane_mesh->get_center_offset());
tm = simple_plane_mesh->generate_triangle_mesh();
} else {
tm = m->generate_triangle_mesh();
}
if (tm.is_valid()) {
p_gizmo->add_collision_triangles(tm);
}

View file

@ -70,68 +70,137 @@ void NavigationLink3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
p_gizmo->clear();
// Draw line between the points.
// Number of points in an octant. So there ill be 8 * points_in_octant points in total.
// Correspond to the smoothness of the circle.
const uint32_t points_in_octant = 4;
real_t inc = (Math_PI / (4 * points_in_octant));
Vector<Vector3> lines;
lines.append(start_position);
lines.append(end_position);
// points_in_octant * 8 * 2 per circle * 2 circles. 2 for the start-end. 4 for the arrow, and another 4 if bidirectionnal.
lines.resize(points_in_octant * 8 * 2 * 2 + 2 + 4 + (link->is_bidirectional() ? 4 : 0));
uint32_t index = 0;
Vector3 *lines_ptrw = lines.ptrw();
// Draw line between the points.
lines_ptrw[index++] = start_position;
lines_ptrw[index++] = end_position;
real_t search_radius_squared = search_radius * search_radius;
// Draw start position search radius
for (int i = 0; i < 30; i++) {
// Create a circle
const float ra = Math::deg_to_rad((float)(i * 12));
const float rb = Math::deg_to_rad((float)((i + 1) * 12));
const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * search_radius;
const Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * search_radius;
// Draw circles at start and end positions in one go.
real_t r = 0;
Vector2 a = Vector2(search_radius, 0);
for (uint32_t i = 0; i < points_in_octant; i++) {
r += inc;
real_t x = Math::cos(r) * search_radius;
real_t y = Math::sqrt(search_radius_squared - (x * x));
// Draw axis-aligned circle
// Draw axis-aligned circle.
switch (up_axis) {
case Vector3::AXIS_X:
lines.append(start_position + Vector3(0, a.x, a.y));
lines.append(start_position + Vector3(0, b.x, b.y));
#define PUSH_OCTANT(_position, a, b) \
lines_ptrw[index++] = _position + Vector3(0, a.x, a.y); \
lines_ptrw[index++] = _position + Vector3(0, x, y); \
lines_ptrw[index++] = _position + Vector3(0, -a.x, a.y); \
lines_ptrw[index++] = _position + Vector3(0, x, y); \
lines_ptrw[index++] = _position + Vector3(0, a.x, -a.y); \
lines_ptrw[index++] = _position + Vector3(0, x, -y); \
lines_ptrw[index++] = _position + Vector3(0, -a.x, -a.y); \
lines_ptrw[index++] = _position + Vector3(0, x, y); \
lines_ptrw[index++] = _position + Vector3(0, a.y, a.x); \
lines_ptrw[index++] = _position + Vector3(0, y, x); \
lines_ptrw[index++] = _position + Vector3(0, -a.y, a.x); \
lines_ptrw[index++] = _position + Vector3(0, -y, x); \
lines_ptrw[index++] = _position + Vector3(0, a.y, -a.x); \
lines_ptrw[index++] = _position + Vector3(0, y, -x); \
lines_ptrw[index++] = _position + Vector3(0, -a.y, -a.x); \
lines_ptrw[index++] = _position + Vector3(0, -y, -x);
PUSH_OCTANT(start_position, a, b)
PUSH_OCTANT(end_position, a, b)
#undef PUSH_OCTANT
break;
case Vector3::AXIS_Y:
lines.append(start_position + Vector3(a.x, 0, a.y));
lines.append(start_position + Vector3(b.x, 0, b.y));
#define PUSH_OCTANT(_position, a, b) \
lines_ptrw[index++] = _position + Vector3(a.x, 0, a.y); \
lines_ptrw[index++] = _position + Vector3(x, 0, y); \
lines_ptrw[index++] = _position + Vector3(-a.x, 0, a.y); \
lines_ptrw[index++] = _position + Vector3(-x, 0, y); \
lines_ptrw[index++] = _position + Vector3(a.x, 0, -a.y); \
lines_ptrw[index++] = _position + Vector3(x, 0, -y); \
lines_ptrw[index++] = _position + Vector3(-a.x, 0, -a.y); \
lines_ptrw[index++] = _position + Vector3(-x, 0, -y); \
lines_ptrw[index++] = _position + Vector3(a.y, 0, a.x); \
lines_ptrw[index++] = _position + Vector3(y, 0, x); \
lines_ptrw[index++] = _position + Vector3(-a.y, 0, a.x); \
lines_ptrw[index++] = _position + Vector3(-y, 0, x); \
lines_ptrw[index++] = _position + Vector3(a.y, 0, -a.x); \
lines_ptrw[index++] = _position + Vector3(y, 0, -x); \
lines_ptrw[index++] = _position + Vector3(-a.y, 0, -a.x); \
lines_ptrw[index++] = _position + Vector3(-y, 0, -x);
PUSH_OCTANT(start_position, a, b)
PUSH_OCTANT(end_position, a, b)
#undef PUSH_OCTANT
break;
case Vector3::AXIS_Z:
lines.append(start_position + Vector3(a.x, a.y, 0));
lines.append(start_position + Vector3(b.x, b.y, 0));
#define PUSH_OCTANT(_position, a, b) \
lines_ptrw[index++] = _position + Vector3(a.x, a.y, 0); \
lines_ptrw[index++] = _position + Vector3(x, y, 0); \
lines_ptrw[index++] = _position + Vector3(-a.x, a.y, 0); \
lines_ptrw[index++] = _position + Vector3(-x, y, 0); \
lines_ptrw[index++] = _position + Vector3(a.x, -a.y, 0); \
lines_ptrw[index++] = _position + Vector3(x, -y, 0); \
lines_ptrw[index++] = _position + Vector3(-a.x, -a.y, 0); \
lines_ptrw[index++] = _position + Vector3(-x, -y, 0); \
lines_ptrw[index++] = _position + Vector3(a.y, a.x, 0); \
lines_ptrw[index++] = _position + Vector3(y, x, 0); \
lines_ptrw[index++] = _position + Vector3(-a.y, a.x, 0); \
lines_ptrw[index++] = _position + Vector3(-y, x, 0); \
lines_ptrw[index++] = _position + Vector3(a.y, -a.x, 0); \
lines_ptrw[index++] = _position + Vector3(y, -x, 0); \
lines_ptrw[index++] = _position + Vector3(-a.y, -a.x, 0); \
lines_ptrw[index++] = _position + Vector3(-y, -x, 0);
PUSH_OCTANT(start_position, a, b)
PUSH_OCTANT(end_position, a, b)
#undef PUSH_OCTANT
break;
}
a.x = x;
a.y = y;
}
// Draw end position search radius
for (int i = 0; i < 30; i++) {
// Create a circle
const float ra = Math::deg_to_rad((float)(i * 12));
const float rb = Math::deg_to_rad((float)((i + 1) * 12));
const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * search_radius;
const Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * search_radius;
const Vector3 link_segment = end_position - start_position;
const Vector3 up = Vector3(0.0, 1.0, 0.0);
const float arror_len = 0.5;
// Draw axis-aligned circle
switch (up_axis) {
case Vector3::AXIS_X:
lines.append(end_position + Vector3(0, a.x, a.y));
lines.append(end_position + Vector3(0, b.x, b.y));
break;
case Vector3::AXIS_Y:
lines.append(end_position + Vector3(a.x, 0, a.y));
lines.append(end_position + Vector3(b.x, 0, b.y));
break;
case Vector3::AXIS_Z:
lines.append(end_position + Vector3(a.x, a.y, 0));
lines.append(end_position + Vector3(b.x, b.y, 0));
break;
}
{
Vector3 anchor = start_position + (link_segment * 0.75);
Vector3 direction = start_position.direction_to(end_position);
Vector3 arrow_dir = direction.cross(up);
lines_ptrw[index++] = anchor;
lines_ptrw[index++] = anchor + (arrow_dir - direction) * arror_len;
arrow_dir = -direction.cross(up);
lines_ptrw[index++] = anchor;
lines_ptrw[index++] = anchor + (arrow_dir - direction) * arror_len;
}
if (link->is_bidirectional()) {
Vector3 anchor = start_position + (link_segment * 0.25);
Vector3 direction = end_position.direction_to(start_position);
Vector3 arrow_dir = direction.cross(up);
lines_ptrw[index++] = anchor;
lines_ptrw[index++] = anchor + (arrow_dir - direction) * arror_len;
arrow_dir = -direction.cross(up);
lines_ptrw[index++] = anchor;
lines_ptrw[index++] = anchor + (arrow_dir - direction) * arror_len;
}
p_gizmo->add_lines(lines, link->is_enabled() ? link_material : link_material_disabled);
p_gizmo->add_collision_segments(lines);
Vector<Vector3> handles;
handles.append(start_position);
handles.append(end_position);
p_gizmo->add_handles(handles, handles_material);
p_gizmo->add_handles(Vector({ start_position, end_position }), handles_material);
}
String NavigationLink3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const {

View file

@ -30,7 +30,6 @@
#include "navigation_region_3d_gizmo_plugin.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/navigation_region_3d.h"
#include "servers/navigation_server_3d.h"

View file

@ -36,7 +36,7 @@
#include "scene/3d/occluder_instance_3d.h"
OccluderInstance3DGizmoPlugin::OccluderInstance3DGizmoPlugin() {
create_material("line_material", EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/occluder", Color(0.8, 0.5, 1)));
create_material("line_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/occluder"));
create_handle_material("handles");
}
@ -242,7 +242,7 @@ void OccluderInstance3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Ref<Occluder3D> o = occluder_instance->get_occluder();
if (!o.is_valid()) {
if (o.is_null()) {
return;
}

View file

@ -0,0 +1,339 @@
/**************************************************************************/
/* particles_3d_emission_shape_gizmo_plugin.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "particles_3d_emission_shape_gizmo_plugin.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/cpu_particles_3d.h"
#include "scene/3d/gpu_particles_3d.h"
#include "scene/resources/3d/primitive_meshes.h"
#include "scene/resources/particle_process_material.h"
Particles3DEmissionShapeGizmoPlugin::Particles3DEmissionShapeGizmoPlugin() {
helper.instantiate();
Color gizmo_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/particles_emission_shape", Color(0.5, 0.7, 1));
create_material("particles_emission_shape_material", gizmo_color);
create_handle_material("handles");
}
bool Particles3DEmissionShapeGizmoPlugin::has_gizmo(Node3D *p_spatial) {
return Object::cast_to<GPUParticles3D>(p_spatial) || Object::cast_to<CPUParticles3D>(p_spatial) != nullptr;
}
String Particles3DEmissionShapeGizmoPlugin::get_gizmo_name() const {
return "Particles3DEmissionShape";
}
int Particles3DEmissionShapeGizmoPlugin::get_priority() const {
return -1;
}
bool Particles3DEmissionShapeGizmoPlugin::is_selectable_when_hidden() const {
return true;
}
String Particles3DEmissionShapeGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const {
return "";
}
Variant Particles3DEmissionShapeGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const {
return Variant();
}
void Particles3DEmissionShapeGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) {
}
void Particles3DEmissionShapeGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel) {
}
void Particles3DEmissionShapeGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
p_gizmo->clear();
if (Object::cast_to<GPUParticles3D>(p_gizmo->get_node_3d())) {
const GPUParticles3D *particles = Object::cast_to<GPUParticles3D>(p_gizmo->get_node_3d());
const Ref<ParticleProcessMaterial> mat = particles->get_process_material();
if (mat.is_valid()) {
const ParticleProcessMaterial::EmissionShape shape = mat->get_emission_shape();
const Ref<Material> material = get_material("particles_emission_shape_material", p_gizmo);
const Ref<Material> handles_material = get_material("handles");
if (shape == ParticleProcessMaterial::EMISSION_SHAPE_SPHERE || shape == ParticleProcessMaterial::EMISSION_SHAPE_SPHERE_SURFACE) {
const Vector3 offset = mat->get_emission_shape_offset();
const Vector3 scale = mat->get_emission_shape_scale();
const float r = mat->get_emission_sphere_radius();
Vector<Vector3> points;
for (int i = 0; i <= 120; i++) {
const float ra = Math::deg_to_rad((float)(i * 3));
const float rb = Math::deg_to_rad((float)((i + 1) * 3));
const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r;
const Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * r;
points.push_back(Vector3(a.x * scale.x + offset.x, offset.y, a.y * scale.z + offset.z));
points.push_back(Vector3(b.x * scale.x + offset.x, offset.y, b.y * scale.z + offset.z));
points.push_back(Vector3(offset.x, a.x * scale.y + offset.y, a.y * scale.z + offset.z));
points.push_back(Vector3(offset.x, b.x * scale.y + offset.y, b.y * scale.z + offset.z));
points.push_back(Vector3(a.x * scale.x + offset.x, a.y * scale.y + offset.y, offset.z));
points.push_back(Vector3(b.x * scale.x + offset.x, b.y * scale.y + offset.y, offset.z));
}
if (p_gizmo->is_selected()) {
p_gizmo->add_lines(points, material);
}
} else if (shape == ParticleProcessMaterial::EMISSION_SHAPE_BOX) {
const Vector3 offset = mat->get_emission_shape_offset();
const Vector3 scale = mat->get_emission_shape_scale();
const Vector3 box_extents = mat->get_emission_box_extents();
Ref<BoxMesh> box;
box.instantiate();
const AABB box_aabb = box->get_aabb();
Vector<Vector3> lines;
for (int i = 0; i < 12; i++) {
Vector3 a;
Vector3 b;
box_aabb.get_edge(i, a, b);
// Multiplication by 2 due to the extents being only half of the box size.
lines.push_back(a * 2.0 * scale * box_extents + offset);
lines.push_back(b * 2.0 * scale * box_extents + offset);
}
if (p_gizmo->is_selected()) {
p_gizmo->add_lines(lines, material);
}
} else if (shape == ParticleProcessMaterial::EMISSION_SHAPE_RING) {
const Vector3 offset = mat->get_emission_shape_offset();
const Vector3 scale = mat->get_emission_shape_scale();
const float ring_height = mat->get_emission_ring_height();
const float half_ring_height = ring_height / 2;
const float ring_radius = mat->get_emission_ring_radius();
const float ring_inner_radius = mat->get_emission_ring_inner_radius();
const Vector3 ring_axis = mat->get_emission_ring_axis();
const float ring_cone_angle = mat->get_emission_ring_cone_angle();
const float ring_radius_top = MAX(ring_radius - Math::tan(Math::deg_to_rad(90.0 - ring_cone_angle)) * ring_height, 0.0);
const float ring_inner_radius_top = (ring_inner_radius / ring_radius) * ring_radius_top;
Vector<Vector3> points;
Basis basis;
basis.rows[1] = ring_axis.normalized();
basis.rows[0] = Vector3(basis[1][1], -basis[1][2], -basis[1][0]).normalized();
basis.rows[0] = (basis[0] - basis[0].dot(basis[1]) * basis[1]).normalized();
basis[2] = basis[0].cross(basis[1]).normalized();
basis.invert();
for (int i = 0; i <= 120; i++) {
const float ra = Math::deg_to_rad((float)(i * 3));
const float ra_sin = Math::sin(ra);
const float ra_cos = Math::cos(ra);
const float rb = Math::deg_to_rad((float)((i + 1) * 3));
const float rb_sin = Math::sin(rb);
const float rb_cos = Math::cos(rb);
const Point2 a = Vector2(ra_sin, ra_cos) * ring_radius;
const Point2 b = Vector2(rb_sin, rb_cos) * ring_radius;
const Point2 a2 = Vector2(ra_sin, ra_cos) * ring_radius_top;
const Point2 b2 = Vector2(rb_sin, rb_cos) * ring_radius_top;
const Point2 inner_a = Vector2(ra_sin, ra_cos) * ring_inner_radius;
const Point2 inner_b = Vector2(rb_sin, rb_cos) * ring_inner_radius;
const Point2 inner_a2 = Vector2(ra_sin, ra_cos) * ring_inner_radius_top;
const Point2 inner_b2 = Vector2(rb_sin, rb_cos) * ring_inner_radius_top;
// Outer top ring cap.
points.push_back(basis.xform(Vector3(a2.x, half_ring_height, a2.y)) * scale + offset);
points.push_back(basis.xform(Vector3(b2.x, half_ring_height, b2.y)) * scale + offset);
// Outer bottom ring cap.
points.push_back(basis.xform(Vector3(a.x, -half_ring_height, a.y)) * scale + offset);
points.push_back(basis.xform(Vector3(b.x, -half_ring_height, b.y)) * scale + offset);
// Inner top ring cap.
points.push_back(basis.xform(Vector3(inner_a2.x, half_ring_height, inner_a2.y)) * scale + offset);
points.push_back(basis.xform(Vector3(inner_b2.x, half_ring_height, inner_b2.y)) * scale + offset);
// Inner bottom ring cap.
points.push_back(basis.xform(Vector3(inner_a.x, -half_ring_height, inner_a.y)) * scale + offset);
points.push_back(basis.xform(Vector3(inner_b.x, -half_ring_height, inner_b.y)) * scale + offset);
}
for (int i = 0; i <= 120; i = i + 30) {
const float ra = Math::deg_to_rad((float)(i * 3));
const float ra_sin = Math::sin(ra);
const float ra_cos = Math::cos(ra);
const Point2 a = Vector2(ra_sin, ra_cos) * ring_radius;
const Point2 a2 = Vector2(ra_sin, ra_cos) * ring_radius_top;
const Point2 inner_a = Vector2(ra_sin, ra_cos) * ring_inner_radius;
const Point2 inner_a2 = Vector2(ra_sin, ra_cos) * ring_inner_radius_top;
// Outer 90 degrees vertical lines.
points.push_back(basis.xform(Vector3(a2.x, half_ring_height, a2.y)) * scale + offset);
points.push_back(basis.xform(Vector3(a.x, -half_ring_height, a.y)) * scale + offset);
// Inner 90 degrees vertical lines.
points.push_back(basis.xform(Vector3(inner_a2.x, half_ring_height, inner_a2.y)) * scale + offset);
points.push_back(basis.xform(Vector3(inner_a.x, -half_ring_height, inner_a.y)) * scale + offset);
}
if (p_gizmo->is_selected()) {
p_gizmo->add_lines(points, material);
}
}
}
} else if (Object::cast_to<CPUParticles3D>(p_gizmo->get_node_3d())) {
const CPUParticles3D *particles = Object::cast_to<CPUParticles3D>(p_gizmo->get_node_3d());
const CPUParticles3D::EmissionShape shape = particles->get_emission_shape();
const Ref<Material> material = get_material("particles_emission_shape_material", p_gizmo);
const Ref<Material> handles_material = get_material("handles");
if (shape == CPUParticles3D::EMISSION_SHAPE_SPHERE || shape == CPUParticles3D::EMISSION_SHAPE_SPHERE_SURFACE) {
const float r = particles->get_emission_sphere_radius();
Vector<Vector3> points;
for (int i = 0; i <= 120; i++) {
const float ra = Math::deg_to_rad((float)(i * 3));
const float rb = Math::deg_to_rad((float)((i + 1) * 3));
const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r;
const Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * r;
points.push_back(Vector3(a.x, 0.0, a.y));
points.push_back(Vector3(b.x, 0.0, b.y));
points.push_back(Vector3(0.0, a.x, a.y));
points.push_back(Vector3(0.0, b.x, b.y));
points.push_back(Vector3(a.x, a.y, 0.0));
points.push_back(Vector3(b.x, b.y, 0.0));
}
if (p_gizmo->is_selected()) {
p_gizmo->add_lines(points, material);
}
} else if (shape == CPUParticles3D::EMISSION_SHAPE_BOX) {
const Vector3 box_extents = particles->get_emission_box_extents();
Ref<BoxMesh> box;
box.instantiate();
const AABB box_aabb = box->get_aabb();
Vector<Vector3> lines;
for (int i = 0; i < 12; i++) {
Vector3 a;
Vector3 b;
box_aabb.get_edge(i, a, b);
// Multiplication by 2 due to the extents being only half of the box size.
lines.push_back(a * 2.0 * box_extents);
lines.push_back(b * 2.0 * box_extents);
}
if (p_gizmo->is_selected()) {
p_gizmo->add_lines(lines, material);
}
} else if (shape == CPUParticles3D::EMISSION_SHAPE_RING) {
const float ring_height = particles->get_emission_ring_height();
const float half_ring_height = ring_height / 2;
const float ring_radius = particles->get_emission_ring_radius();
const float ring_inner_radius = particles->get_emission_ring_inner_radius();
const Vector3 ring_axis = particles->get_emission_ring_axis();
const float ring_cone_angle = particles->get_emission_ring_cone_angle();
const float ring_radius_top = MAX(ring_radius - Math::tan(Math::deg_to_rad(90.0 - ring_cone_angle)) * ring_height, 0.0);
const float ring_inner_radius_top = (ring_inner_radius / ring_radius) * ring_radius_top;
Vector<Vector3> points;
Basis basis;
basis.rows[1] = ring_axis.normalized();
basis.rows[0] = Vector3(basis[1][1], -basis[1][2], -basis[1][0]).normalized();
basis.rows[0] = (basis[0] - basis[0].dot(basis[1]) * basis[1]).normalized();
basis[2] = basis[0].cross(basis[1]).normalized();
basis.invert();
for (int i = 0; i <= 120; i++) {
const float ra = Math::deg_to_rad((float)(i * 3));
const float ra_sin = Math::sin(ra);
const float ra_cos = Math::cos(ra);
const float rb = Math::deg_to_rad((float)((i + 1) * 3));
const float rb_sin = Math::sin(rb);
const float rb_cos = Math::cos(rb);
const Point2 a = Vector2(ra_sin, ra_cos) * ring_radius;
const Point2 b = Vector2(rb_sin, rb_cos) * ring_radius;
const Point2 a2 = Vector2(ra_sin, ra_cos) * ring_radius_top;
const Point2 b2 = Vector2(rb_sin, rb_cos) * ring_radius_top;
const Point2 inner_a = Vector2(ra_sin, ra_cos) * ring_inner_radius;
const Point2 inner_b = Vector2(rb_sin, rb_cos) * ring_inner_radius;
const Point2 inner_a2 = Vector2(ra_sin, ra_cos) * ring_inner_radius_top;
const Point2 inner_b2 = Vector2(rb_sin, rb_cos) * ring_inner_radius_top;
// Outer top ring cap.
points.push_back(basis.xform(Vector3(a2.x, half_ring_height, a2.y)));
points.push_back(basis.xform(Vector3(b2.x, half_ring_height, b2.y)));
// Outer bottom ring cap.
points.push_back(basis.xform(Vector3(a.x, -half_ring_height, a.y)));
points.push_back(basis.xform(Vector3(b.x, -half_ring_height, b.y)));
// Inner top ring cap.
points.push_back(basis.xform(Vector3(inner_a2.x, half_ring_height, inner_a2.y)));
points.push_back(basis.xform(Vector3(inner_b2.x, half_ring_height, inner_b2.y)));
// Inner bottom ring cap.
points.push_back(basis.xform(Vector3(inner_a.x, -half_ring_height, inner_a.y)));
points.push_back(basis.xform(Vector3(inner_b.x, -half_ring_height, inner_b.y)));
}
for (int i = 0; i <= 120; i = i + 30) {
const float ra = Math::deg_to_rad((float)(i * 3));
const float ra_sin = Math::sin(ra);
const float ra_cos = Math::cos(ra);
const Point2 a = Vector2(ra_sin, ra_cos) * ring_radius;
const Point2 a2 = Vector2(ra_sin, ra_cos) * ring_radius_top;
const Point2 inner_a = Vector2(ra_sin, ra_cos) * ring_inner_radius;
const Point2 inner_a2 = Vector2(ra_sin, ra_cos) * ring_inner_radius_top;
// Outer 90 degrees vertical lines.
points.push_back(basis.xform(Vector3(a2.x, half_ring_height, a2.y)));
points.push_back(basis.xform(Vector3(a.x, -half_ring_height, a.y)));
// Inner 90 degrees vertical lines.
points.push_back(basis.xform(Vector3(inner_a2.x, half_ring_height, inner_a2.y)));
points.push_back(basis.xform(Vector3(inner_a.x, -half_ring_height, inner_a.y)));
}
if (p_gizmo->is_selected()) {
p_gizmo->add_lines(points, material);
}
}
}
}

View file

@ -0,0 +1,57 @@
/**************************************************************************/
/* particles_3d_emission_shape_gizmo_plugin.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef PARTICLES_3D_EMISSION_SHAPE_GIZMO_PLUGIN_H
#define PARTICLES_3D_EMISSION_SHAPE_GIZMO_PLUGIN_H
#include "editor/plugins/gizmos/gizmo_3d_helper.h"
#include "editor/plugins/node_3d_editor_gizmos.h"
class Particles3DEmissionShapeGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(Particles3DEmissionShapeGizmoPlugin, EditorNode3DGizmoPlugin);
Ref<Gizmo3DHelper> helper;
public:
bool has_gizmo(Node3D *p_spatial) override;
String get_gizmo_name() const override;
int get_priority() const override;
bool is_selectable_when_hidden() const override;
void redraw(EditorNode3DGizmo *p_gizmo) override;
String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
Particles3DEmissionShapeGizmoPlugin();
};
#endif // PARTICLES_3D_EMISSION_SHAPE_GIZMO_PLUGIN_H

View file

@ -32,9 +32,8 @@
#include "editor/editor_settings.h"
#include "editor/plugins/gizmos/joint_3d_gizmo_plugin.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/physical_bone_simulator_3d.h"
#include "scene/3d/physics/physical_bone_3d.h"
#include "scene/3d/physics/physics_body_3d.h"
PhysicalBone3DGizmoPlugin::PhysicalBone3DGizmoPlugin() {
create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint"));

View file

@ -30,8 +30,6 @@
#include "ray_cast_3d_gizmo_plugin.h"
#include "editor/editor_settings.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/physics/ray_cast_3d.h"
RayCast3DGizmoPlugin::RayCast3DGizmoPlugin() {

View file

@ -40,16 +40,13 @@
ReflectionProbeGizmoPlugin::ReflectionProbeGizmoPlugin() {
helper.instantiate();
Color gizmo_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/reflection_probe", Color(0.6, 1, 0.5));
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/reflection_probe");
create_material("reflection_probe_material", gizmo_color);
gizmo_color.a = 0.5;
create_material("reflection_internal_material", gizmo_color);
gizmo_color.a = 0.1;
create_material("reflection_probe_solid_material", gizmo_color);
create_icon_material("reflection_probe_icon", EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("GizmoReflectionProbe"), EditorStringName(EditorIcons)));
create_handle_material("handles");
}
@ -165,29 +162,43 @@ void ReflectionProbeGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
aabb.position = -size / 2;
aabb.size = size;
for (int i = 0; i < 12; i++) {
Vector3 a, b;
aabb.get_edge(i, a, b);
lines.push_back(a);
lines.push_back(b);
AABB blend_aabb;
for (int i = 0; i < 3; i++) {
blend_aabb.position[i] = aabb.position[i] + probe->get_blend_distance();
blend_aabb.size[i] = aabb.size[i] - probe->get_blend_distance() * 2.0;
if (blend_aabb.size[i] < blend_aabb.position[i]) {
blend_aabb.position[i] = aabb.position[i] + aabb.size[i] / 2.0;
blend_aabb.size[i] = 0.0;
}
}
for (int i = 0; i < 8; i++) {
Vector3 ep = aabb.get_endpoint(i);
internal_lines.push_back(probe->get_origin_offset());
internal_lines.push_back(ep);
if (probe->get_blend_distance() != 0.0) {
for (int i = 0; i < 12; i++) {
Vector3 a;
Vector3 b;
blend_aabb.get_edge(i, a, b);
lines.push_back(a);
lines.push_back(b);
}
for (int i = 0; i < 8; i++) {
Vector3 ep = aabb.get_endpoint(i);
internal_lines.push_back(blend_aabb.get_endpoint(i));
internal_lines.push_back(ep);
}
}
Vector<Vector3> handles = helper->box_get_handles(probe->get_size());
for (int i = 0; i < 3; i++) {
Vector3 orig_handle = probe->get_origin_offset();
orig_handle[i] -= 0.25;
lines.push_back(orig_handle);
handles.push_back(orig_handle);
if (probe->get_origin_offset() != Vector3(0.0, 0.0, 0.0)) {
for (int i = 0; i < 3; i++) {
Vector3 orig_handle = probe->get_origin_offset();
orig_handle[i] -= 0.25;
lines.push_back(orig_handle);
orig_handle[i] += 0.5;
lines.push_back(orig_handle);
orig_handle[i] += 0.5;
lines.push_back(orig_handle);
}
}
Ref<Material> material = get_material("reflection_probe_material", p_gizmo);
@ -196,11 +207,6 @@ void ReflectionProbeGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
p_gizmo->add_lines(lines, material);
p_gizmo->add_lines(internal_lines, material_internal);
if (p_gizmo->is_selected()) {
Ref<Material> solid_material = get_material("reflection_probe_solid_material", p_gizmo);
p_gizmo->add_solid_box(solid_material, probe->get_size());
}
p_gizmo->add_handles(handles, get_material("handles"));
}

View file

@ -30,8 +30,6 @@
#include "shape_cast_3d_gizmo_plugin.h"
#include "editor/editor_settings.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/physics/shape_cast_3d.h"
ShapeCast3DGizmoPlugin::ShapeCast3DGizmoPlugin() {

View file

@ -30,8 +30,6 @@
#include "soft_body_3d_gizmo_plugin.h"
#include "editor/editor_settings.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/soft_body_3d.h"
SoftBody3DGizmoPlugin::SoftBody3DGizmoPlugin() {

View file

@ -30,10 +30,7 @@
#include "spring_arm_3d_gizmo_plugin.h"
#include "editor/editor_settings.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/physics/spring_arm_3d.h"
#include "scene/resources/3d/shape_3d.h"
void SpringArm3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
SpringArm3D *spring_arm = Object::cast_to<SpringArm3D>(p_gizmo->get_node_3d());

View file

@ -0,0 +1,424 @@
/**************************************************************************/
/* spring_bone_3d_gizmo_plugin.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "spring_bone_3d_gizmo_plugin.h"
#include "editor/editor_settings.h"
#include "scene/3d/spring_bone_collision_capsule_3d.h"
#include "scene/3d/spring_bone_collision_plane_3d.h"
#include "scene/3d/spring_bone_collision_sphere_3d.h"
// SpringBoneSimulator3D
SpringBoneSimulator3DGizmoPlugin::SelectionMaterials SpringBoneSimulator3DGizmoPlugin::selection_materials;
SpringBoneSimulator3DGizmoPlugin::SpringBoneSimulator3DGizmoPlugin() {
selection_materials.unselected_mat.instantiate();
selection_materials.unselected_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
selection_materials.unselected_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
selection_materials.unselected_mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
selection_materials.unselected_mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
selection_materials.unselected_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
selection_materials.selected_mat.instantiate();
Ref<Shader> sh;
sh.instantiate();
sh->set_code(R"(
// Skeleton 3D gizmo bones shader.
shader_type spatial;
render_mode unshaded, shadows_disabled;
void vertex() {
if (!OUTPUT_IS_SRGB) {
COLOR.rgb = mix( pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb* (1.0 / 12.92), lessThan(COLOR.rgb,vec3(0.04045)) );
}
VERTEX = VERTEX;
POSITION = PROJECTION_MATRIX * VIEW_MATRIX * MODEL_MATRIX * vec4(VERTEX.xyz, 1.0);
POSITION.z = mix(POSITION.z, POSITION.w, 0.998);
}
void fragment() {
ALBEDO = COLOR.rgb;
ALPHA = COLOR.a;
}
)");
selection_materials.selected_mat->set_shader(sh);
}
SpringBoneSimulator3DGizmoPlugin::~SpringBoneSimulator3DGizmoPlugin() {
selection_materials.unselected_mat.unref();
selection_materials.selected_mat.unref();
}
bool SpringBoneSimulator3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
return Object::cast_to<SpringBoneSimulator3D>(p_spatial) != nullptr;
}
String SpringBoneSimulator3DGizmoPlugin::get_gizmo_name() const {
return "SpringBoneSimulator3D";
}
int SpringBoneSimulator3DGizmoPlugin::get_priority() const {
return -1;
}
void SpringBoneSimulator3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
SpringBoneSimulator3D *simulator = Object::cast_to<SpringBoneSimulator3D>(p_gizmo->get_node_3d());
p_gizmo->clear();
if (!simulator->get_setting_count()) {
return;
}
Skeleton3D *skeleton = simulator->get_skeleton();
if (!skeleton) {
return;
}
Ref<ArrayMesh> mesh = get_joints_mesh(skeleton, simulator, p_gizmo->is_selected());
Transform3D skel_tr = simulator->get_global_transform().inverse() * skeleton->get_global_transform();
p_gizmo->add_mesh(mesh, Ref<Material>(), skel_tr, skeleton->register_skin(skeleton->create_skin_from_rest_transforms()));
}
Ref<ArrayMesh> SpringBoneSimulator3DGizmoPlugin::get_joints_mesh(Skeleton3D *p_skeleton, SpringBoneSimulator3D *p_simulator, bool p_is_selected) {
Color bone_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/spring_bone_joint");
Ref<SurfaceTool> surface_tool;
surface_tool.instantiate();
surface_tool->begin(Mesh::PRIMITIVE_LINES);
if (p_is_selected) {
surface_tool->set_material(selection_materials.selected_mat);
} else {
selection_materials.unselected_mat->set_albedo(bone_color);
surface_tool->set_material(selection_materials.unselected_mat);
}
LocalVector<int> bones;
LocalVector<float> weights;
bones.resize(4);
weights.resize(4);
for (int i = 0; i < 4; i++) {
bones[i] = 0;
weights[i] = 0;
}
weights[0] = 1;
for (int i = 0; i < p_simulator->get_setting_count(); i++) {
int current_bone = -1;
int prev_bone = -1;
int joint_end = p_simulator->get_joint_count(i) - 1;
for (int j = 0; j <= joint_end; j++) {
current_bone = p_simulator->get_joint_bone(i, j);
if (j > 0) {
Transform3D parent_global_pose = p_skeleton->get_bone_global_rest(prev_bone);
Transform3D global_pose = p_skeleton->get_bone_global_rest(current_bone);
draw_line(surface_tool, parent_global_pose.origin, global_pose.origin, bone_color);
draw_sphere(surface_tool, global_pose.basis, global_pose.origin, p_simulator->get_joint_radius(i, j - 1), bone_color);
}
if (j == joint_end && p_simulator->is_end_bone_extended(i) && p_simulator->get_end_bone_length(i) > 0) {
Vector3 axis = p_simulator->get_end_bone_axis(current_bone, p_simulator->get_end_bone_direction(i));
if (axis.is_zero_approx()) {
continue;
}
bones[0] = current_bone;
surface_tool->set_bones(bones);
surface_tool->set_weights(weights);
Transform3D global_pose = p_skeleton->get_bone_global_rest(current_bone);
axis = global_pose.xform(axis * p_simulator->get_end_bone_length(i));
draw_line(surface_tool, global_pose.origin, axis, bone_color);
draw_sphere(surface_tool, global_pose.basis, axis, p_simulator->get_joint_radius(i, j), bone_color);
} else {
bones[0] = current_bone;
surface_tool->set_bones(bones);
surface_tool->set_weights(weights);
}
prev_bone = current_bone;
}
}
return surface_tool->commit();
}
void SpringBoneSimulator3DGizmoPlugin::draw_sphere(Ref<SurfaceTool> &p_surface_tool, const Basis &p_basis, const Vector3 &p_center, float p_radius, const Color &p_color) {
static const Vector3 VECTOR3_RIGHT = Vector3(1, 0, 0);
static const Vector3 VECTOR3_UP = Vector3(0, 1, 0);
static const Vector3 VECTOR3_FORWARD = Vector3(0, 0, 1);
static const int STEP = 16;
static const float SPPI = Math_TAU / (float)STEP;
for (int i = 1; i <= STEP; i++) {
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex(p_center + ((p_basis.xform(VECTOR3_UP * p_radius)).rotated(p_basis.xform(VECTOR3_RIGHT), SPPI * ((i - 1) % STEP))));
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex(p_center + ((p_basis.xform(VECTOR3_UP * p_radius)).rotated(p_basis.xform(VECTOR3_RIGHT), SPPI * (i % STEP))));
}
for (int i = 1; i <= STEP; i++) {
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex(p_center + ((p_basis.xform(VECTOR3_RIGHT * p_radius)).rotated(p_basis.xform(VECTOR3_FORWARD), SPPI * ((i - 1) % STEP))));
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex(p_center + ((p_basis.xform(VECTOR3_RIGHT * p_radius)).rotated(p_basis.xform(VECTOR3_FORWARD), SPPI * (i % STEP))));
}
for (int i = 1; i <= STEP; i++) {
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex(p_center + ((p_basis.xform(VECTOR3_FORWARD * p_radius)).rotated(p_basis.xform(VECTOR3_UP), SPPI * ((i - 1) % STEP))));
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex(p_center + ((p_basis.xform(VECTOR3_FORWARD * p_radius)).rotated(p_basis.xform(VECTOR3_UP), SPPI * (i % STEP))));
}
}
void SpringBoneSimulator3DGizmoPlugin::draw_line(Ref<SurfaceTool> &p_surface_tool, const Vector3 &p_begin_pos, const Vector3 &p_end_pos, const Color &p_color) {
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex(p_begin_pos);
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex(p_end_pos);
}
// SpringBoneCollision3D
SpringBoneCollision3DGizmoPlugin::SelectionMaterials SpringBoneCollision3DGizmoPlugin::selection_materials;
SpringBoneCollision3DGizmoPlugin::SpringBoneCollision3DGizmoPlugin() {
selection_materials.unselected_mat.instantiate();
selection_materials.unselected_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
selection_materials.unselected_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
selection_materials.unselected_mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
selection_materials.unselected_mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
selection_materials.unselected_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
selection_materials.selected_mat.instantiate();
Ref<Shader> sh;
sh.instantiate();
sh->set_code(R"(
// Skeleton 3D gizmo bones shader.
shader_type spatial;
render_mode unshaded, shadows_disabled;
void vertex() {
if (!OUTPUT_IS_SRGB) {
COLOR.rgb = mix( pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb* (1.0 / 12.92), lessThan(COLOR.rgb,vec3(0.04045)) );
}
VERTEX = VERTEX;
POSITION = PROJECTION_MATRIX * VIEW_MATRIX * MODEL_MATRIX * vec4(VERTEX.xyz, 1.0);
POSITION.z = mix(POSITION.z, POSITION.w, 0.998);
}
void fragment() {
ALBEDO = COLOR.rgb;
ALPHA = COLOR.a;
}
)");
selection_materials.selected_mat->set_shader(sh);
}
SpringBoneCollision3DGizmoPlugin::~SpringBoneCollision3DGizmoPlugin() {
selection_materials.unselected_mat.unref();
selection_materials.selected_mat.unref();
}
bool SpringBoneCollision3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
return Object::cast_to<SpringBoneCollision3D>(p_spatial) != nullptr;
}
String SpringBoneCollision3DGizmoPlugin::get_gizmo_name() const {
return "SpringBoneCollision3D";
}
int SpringBoneCollision3DGizmoPlugin::get_priority() const {
return -1;
}
void SpringBoneCollision3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
SpringBoneCollision3D *collision = Object::cast_to<SpringBoneCollision3D>(p_gizmo->get_node_3d());
p_gizmo->clear();
Ref<ArrayMesh> mesh = get_collision_mesh(collision, p_gizmo->is_selected());
p_gizmo->add_mesh(mesh);
}
Ref<ArrayMesh> SpringBoneCollision3DGizmoPlugin::get_collision_mesh(SpringBoneCollision3D *p_collision, bool p_is_selected) {
Color collision_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/spring_bone_collision");
Color inside_collision_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/spring_bone_inside_collision");
Ref<SurfaceTool> surface_tool;
surface_tool.instantiate();
surface_tool->begin(Mesh::PRIMITIVE_LINES);
if (p_is_selected) {
surface_tool->set_material(selection_materials.selected_mat);
} else {
selection_materials.unselected_mat->set_albedo(collision_color);
surface_tool->set_material(selection_materials.unselected_mat);
}
SpringBoneCollisionSphere3D *sphere = Object::cast_to<SpringBoneCollisionSphere3D>(p_collision);
if (sphere) {
draw_sphere(surface_tool, sphere->get_radius(), sphere->is_inside() ? inside_collision_color : collision_color);
return surface_tool->commit();
}
SpringBoneCollisionCapsule3D *capsule = Object::cast_to<SpringBoneCollisionCapsule3D>(p_collision);
if (capsule) {
draw_capsule(surface_tool, capsule->get_radius(), capsule->get_height(), capsule->is_inside() ? inside_collision_color : collision_color);
return surface_tool->commit();
}
SpringBoneCollisionPlane3D *plane = Object::cast_to<SpringBoneCollisionPlane3D>(p_collision);
if (plane) {
draw_plane(surface_tool, collision_color);
return surface_tool->commit();
}
return surface_tool->commit();
}
void SpringBoneCollision3DGizmoPlugin::draw_sphere(Ref<SurfaceTool> &p_surface_tool, float p_radius, const Color &p_color) {
static const Vector3 VECTOR3_RIGHT = Vector3(1, 0, 0);
static const Vector3 VECTOR3_UP = Vector3(0, 1, 0);
static const Vector3 VECTOR3_FORWARD = Vector3(0, 0, 1);
static const int STEP = 16;
static const float SPPI = Math_TAU / (float)STEP;
for (int i = 1; i <= STEP; i++) {
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex((VECTOR3_UP * p_radius).rotated(VECTOR3_RIGHT, SPPI * ((i - 1) % STEP)));
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex((VECTOR3_UP * p_radius).rotated(VECTOR3_RIGHT, SPPI * (i % STEP)));
}
for (int i = 1; i <= STEP; i++) {
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex((VECTOR3_RIGHT * p_radius).rotated(VECTOR3_FORWARD, SPPI * ((i - 1) % STEP)));
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex((VECTOR3_RIGHT * p_radius).rotated(VECTOR3_FORWARD, SPPI * (i % STEP)));
}
for (int i = 1; i <= STEP; i++) {
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex((VECTOR3_FORWARD * p_radius).rotated(VECTOR3_UP, SPPI * ((i - 1) % STEP)));
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex((VECTOR3_FORWARD * p_radius).rotated(VECTOR3_UP, SPPI * (i % STEP)));
}
}
void SpringBoneCollision3DGizmoPlugin::draw_capsule(Ref<SurfaceTool> &p_surface_tool, float p_radius, float p_height, const Color &p_color) {
static const Vector3 VECTOR3_RIGHT = Vector3(1, 0, 0);
static const Vector3 VECTOR3_UP = Vector3(0, 1, 0);
static const Vector3 VECTOR3_FORWARD = Vector3(0, 0, 1);
static const int STEP = 16;
static const int HALF_STEP = 8;
static const float SPPI = Math_TAU / (float)STEP;
static const float HALF_PI = Math_PI * 0.5;
Vector3 top = VECTOR3_UP * (p_height * 0.5 - p_radius);
Vector3 bottom = -top;
for (int i = 1; i <= STEP; i++) {
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex((i - 1 < HALF_STEP ? top : bottom) + (VECTOR3_UP * p_radius).rotated(VECTOR3_RIGHT, -HALF_PI + SPPI * ((i - 1) % STEP)));
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex((i - 1 < HALF_STEP ? top : bottom) + (VECTOR3_UP * p_radius).rotated(VECTOR3_RIGHT, -HALF_PI + SPPI * (i % STEP)));
}
for (int i = 1; i <= STEP; i++) {
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex((i - 1 < HALF_STEP ? top : bottom) + (VECTOR3_RIGHT * p_radius).rotated(VECTOR3_FORWARD, SPPI * ((i - 1) % STEP)));
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex((i - 1 < HALF_STEP ? top : bottom) + (VECTOR3_RIGHT * p_radius).rotated(VECTOR3_FORWARD, SPPI * (i % STEP)));
}
for (int i = 1; i <= STEP; i++) {
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex(top + (VECTOR3_FORWARD * p_radius).rotated(VECTOR3_UP, SPPI * ((i - 1) % STEP)));
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex(top + (VECTOR3_FORWARD * p_radius).rotated(VECTOR3_UP, SPPI * (i % STEP)));
}
for (int i = 1; i <= STEP; i++) {
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex(bottom + (VECTOR3_FORWARD * p_radius).rotated(VECTOR3_UP, SPPI * ((i - 1) % STEP)));
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex(bottom + (VECTOR3_FORWARD * p_radius).rotated(VECTOR3_UP, SPPI * (i % STEP)));
}
LocalVector<Vector3> directions;
directions.resize(4);
directions[0] = VECTOR3_RIGHT;
directions[1] = -VECTOR3_RIGHT;
directions[2] = VECTOR3_FORWARD;
directions[3] = -VECTOR3_FORWARD;
for (int i = 0; i < 4; i++) {
Vector3 dir = directions[i] * p_radius;
p_surface_tool->set_color(p_color);
p_surface_tool->add_vertex(top + dir);
p_surface_tool->add_vertex(bottom + dir);
}
}
void SpringBoneCollision3DGizmoPlugin::draw_plane(Ref<SurfaceTool> &p_surface_tool, const Color &p_color) {
static const Vector3 VECTOR3_UP = Vector3(0, 1, 0);
static const float HALF_PI = Math_PI * 0.5;
static const float ARROW_LENGTH = 0.3;
static const float ARROW_HALF_WIDTH = 0.05;
static const float ARROW_TOP_HALF_WIDTH = 0.1;
static const float ARROW_TOP = 0.5;
static const float RECT_SIZE = 1.0;
static const int RECT_STEP_COUNT = 9;
static const float RECT_HALF_SIZE = RECT_SIZE * 0.5;
static const float RECT_STEP = RECT_SIZE / (float)RECT_STEP_COUNT;
p_surface_tool->set_color(p_color);
// Draw arrow of the normal.
LocalVector<Vector3> arrow;
arrow.resize(7);
arrow[0] = Vector3(0, ARROW_TOP, 0);
arrow[1] = Vector3(-ARROW_TOP_HALF_WIDTH, ARROW_LENGTH, 0);
arrow[2] = Vector3(-ARROW_HALF_WIDTH, ARROW_LENGTH, 0);
arrow[3] = Vector3(-ARROW_HALF_WIDTH, 0, 0);
arrow[4] = Vector3(ARROW_HALF_WIDTH, 0, 0);
arrow[5] = Vector3(ARROW_HALF_WIDTH, ARROW_LENGTH, 0);
arrow[6] = Vector3(ARROW_TOP_HALF_WIDTH, ARROW_LENGTH, 0);
for (int i = 0; i < 2; i++) {
Basis ma(VECTOR3_UP, HALF_PI * i);
for (uint32_t j = 0; j < arrow.size(); j++) {
Vector3 v1 = arrow[j];
Vector3 v2 = arrow[(j + 1) % arrow.size()];
p_surface_tool->add_vertex(ma.xform(v1));
p_surface_tool->add_vertex(ma.xform(v2));
}
}
// Draw dashed line of the rect.
for (int i = 0; i < 4; i++) {
Basis ma(VECTOR3_UP, HALF_PI * i);
for (int j = 0; j < RECT_STEP_COUNT; j++) {
if (j % 2 == 1) {
continue;
}
Vector3 v1 = Vector3(RECT_HALF_SIZE, 0, RECT_HALF_SIZE - RECT_STEP * j);
Vector3 v2 = Vector3(RECT_HALF_SIZE, 0, RECT_HALF_SIZE - RECT_STEP * (j + 1));
p_surface_tool->add_vertex(ma.xform(v1));
p_surface_tool->add_vertex(ma.xform(v2));
}
}
}

View file

@ -0,0 +1,89 @@
/**************************************************************************/
/* spring_bone_3d_gizmo_plugin.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SPRING_BONE_3D_GIZMO_PLUGIN_H
#define SPRING_BONE_3D_GIZMO_PLUGIN_H
#include "editor/plugins/editor_plugin.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/spring_bone_collision_3d.h"
#include "scene/3d/spring_bone_simulator_3d.h"
#include "scene/resources/surface_tool.h"
class SpringBoneSimulator3DGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(SpringBoneSimulator3DGizmoPlugin, EditorNode3DGizmoPlugin);
struct SelectionMaterials {
Ref<StandardMaterial3D> unselected_mat;
Ref<ShaderMaterial> selected_mat;
};
static SelectionMaterials selection_materials;
public:
static Ref<ArrayMesh> get_joints_mesh(Skeleton3D *p_skeleton, SpringBoneSimulator3D *p_simulator, bool p_is_selected);
static void draw_sphere(Ref<SurfaceTool> &p_surface_tool, const Basis &p_basis, const Vector3 &p_center, float p_radius, const Color &p_color);
static void draw_line(Ref<SurfaceTool> &p_surface_tool, const Vector3 &p_begin_pos, const Vector3 &p_end_pos, const Color &p_color);
bool has_gizmo(Node3D *p_spatial) override;
String get_gizmo_name() const override;
int get_priority() const override;
void redraw(EditorNode3DGizmo *p_gizmo) override;
SpringBoneSimulator3DGizmoPlugin();
~SpringBoneSimulator3DGizmoPlugin();
};
class SpringBoneCollision3DGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(SpringBoneCollision3DGizmoPlugin, EditorNode3DGizmoPlugin);
struct SelectionMaterials {
Ref<StandardMaterial3D> unselected_mat;
Ref<ShaderMaterial> selected_mat;
};
static SelectionMaterials selection_materials;
public:
static Ref<ArrayMesh> get_collision_mesh(SpringBoneCollision3D *p_collision, bool p_is_selected);
static void draw_sphere(Ref<SurfaceTool> &p_surface_tool, float p_radius, const Color &p_color);
static void draw_capsule(Ref<SurfaceTool> &p_surface_tool, float p_radius, float p_height, const Color &p_color);
static void draw_plane(Ref<SurfaceTool> &p_surface_tool, const Color &p_color);
bool has_gizmo(Node3D *p_spatial) override;
String get_gizmo_name() const override;
int get_priority() const override;
void redraw(EditorNode3DGizmo *p_gizmo) override;
SpringBoneCollision3DGizmoPlugin();
~SpringBoneCollision3DGizmoPlugin();
};
#endif // SPRING_BONE_3D_GIZMO_PLUGIN_H

View file

@ -30,7 +30,6 @@
#include "sprite_base_3d_gizmo_plugin.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/sprite_3d.h"
SpriteBase3DGizmoPlugin::SpriteBase3DGizmoPlugin() {

View file

@ -30,8 +30,6 @@
#include "vehicle_body_3d_gizmo_plugin.h"
#include "editor/editor_settings.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/physics/vehicle_body_3d.h"
VehicleWheel3DGizmoPlugin::VehicleWheel3DGizmoPlugin() {

View file

@ -36,7 +36,7 @@
#include "scene/3d/visible_on_screen_notifier_3d.h"
VisibleOnScreenNotifier3DGizmoPlugin::VisibleOnScreenNotifier3DGizmoPlugin() {
Color gizmo_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/visibility_notifier", Color(0.8, 0.5, 0.7));
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/visibility_notifier");
create_material("visibility_notifier_material", gizmo_color);
gizmo_color.a = 0.1;
create_material("visibility_notifier_solid_material", gizmo_color);

View file

@ -33,25 +33,20 @@
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/plugins/gizmos/gizmo_3d_helper.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "scene/3d/voxel_gi.h"
VoxelGIGizmoPlugin::VoxelGIGizmoPlugin() {
helper.instantiate();
Color gizmo_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/voxel_gi", Color(0.5, 1, 0.6));
Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/voxel_gi");
create_material("voxel_gi_material", gizmo_color);
// This gizmo draws a lot of lines. Use a low opacity to make it not too intrusive.
gizmo_color.a = 0.1;
gizmo_color.a = 0.02;
create_material("voxel_gi_internal_material", gizmo_color);
gizmo_color.a = 0.05;
create_material("voxel_gi_solid_material", gizmo_color);
create_icon_material("voxel_gi_icon", EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("GizmoVoxelGI"), EditorStringName(EditorIcons)));
create_handle_material("handles");
}
@ -164,11 +159,6 @@ void VoxelGIGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Vector<Vector3> handles = helper->box_get_handles(probe->get_size());
if (p_gizmo->is_selected()) {
Ref<Material> solid_material = get_material("voxel_gi_solid_material", p_gizmo);
p_gizmo->add_solid_box(solid_material, aabb.get_size());
}
p_gizmo->add_handles(handles, get_material("handles"));
}