Skip to content

Commit cb05b49

Browse files
committed
Simplify the GPUParticles3D editor gizmo to improve readability
- Remove handles as users should use the Generate Visibility AABB option whenever possible, so manual resizing isn't needed often. (For particles that move quickly and have Local Coords disabled, Extra Cull Margin can be increased in the GeometryInstance3D properties in the inspector.) - Remove translucent filled part of the gizmo to be more consistent with GeometryInstance3D's recently introduced Custom AABB gizmo. - Remove center marker as it can visually obstruct particles. This paves the way for future emission shape gizmos which will feature handles.
1 parent 6118592 commit cb05b49

File tree

2 files changed

+0
-121
lines changed

2 files changed

+0
-121
lines changed

editor/plugins/gizmos/gpu_particles_3d_gizmo_plugin.cpp

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ GPUParticles3DGizmoPlugin::GPUParticles3DGizmoPlugin() {
4141
Color gizmo_color = EDITOR_DEF_RST("editors/3d_gizmos/gizmo_colors/particles", Color(0.8, 0.7, 0.4));
4242
create_material("particles_material", gizmo_color);
4343
gizmo_color.a = MAX((gizmo_color.a - 0.2) * 0.02, 0.0);
44-
create_material("particles_solid_material", gizmo_color);
4544
create_icon_material("particles_icon", EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("GizmoGPUParticles3D"), EditorStringName(EditorIcons)));
46-
create_handle_material("handles");
4745
}
4846

4947
bool GPUParticles3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
@@ -62,96 +60,6 @@ bool GPUParticles3DGizmoPlugin::is_selectable_when_hidden() const {
6260
return true;
6361
}
6462

65-
String GPUParticles3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const {
66-
switch (p_id) {
67-
case 0:
68-
return "Size X";
69-
case 1:
70-
return "Size Y";
71-
case 2:
72-
return "Size Z";
73-
case 3:
74-
return "Pos X";
75-
case 4:
76-
return "Pos Y";
77-
case 5:
78-
return "Pos Z";
79-
}
80-
81-
return "";
82-
}
83-
84-
Variant GPUParticles3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const {
85-
GPUParticles3D *particles = Object::cast_to<GPUParticles3D>(p_gizmo->get_node_3d());
86-
return particles->get_visibility_aabb();
87-
}
88-
89-
void GPUParticles3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) {
90-
GPUParticles3D *particles = Object::cast_to<GPUParticles3D>(p_gizmo->get_node_3d());
91-
92-
Transform3D gt = particles->get_global_transform();
93-
Transform3D gi = gt.affine_inverse();
94-
95-
bool move = p_id >= 3;
96-
p_id = p_id % 3;
97-
98-
AABB aabb = particles->get_visibility_aabb();
99-
Vector3 ray_from = p_camera->project_ray_origin(p_point);
100-
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
101-
102-
Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) };
103-
104-
Vector3 ofs = aabb.get_center();
105-
106-
Vector3 axis;
107-
axis[p_id] = 1.0;
108-
109-
if (move) {
110-
Vector3 ra, rb;
111-
Geometry3D::get_closest_points_between_segments(ofs - axis * 4096, ofs + axis * 4096, sg[0], sg[1], ra, rb);
112-
113-
float d = ra[p_id];
114-
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
115-
d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap());
116-
}
117-
118-
aabb.position[p_id] = d - 1.0 - aabb.size[p_id] * 0.5;
119-
particles->set_visibility_aabb(aabb);
120-
121-
} else {
122-
Vector3 ra, rb;
123-
Geometry3D::get_closest_points_between_segments(ofs, ofs + axis * 4096, sg[0], sg[1], ra, rb);
124-
125-
float d = ra[p_id] - ofs[p_id];
126-
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
127-
d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap());
128-
}
129-
130-
if (d < 0.001) {
131-
d = 0.001;
132-
}
133-
//resize
134-
aabb.position[p_id] = (aabb.position[p_id] + aabb.size[p_id] * 0.5) - d;
135-
aabb.size[p_id] = d * 2;
136-
particles->set_visibility_aabb(aabb);
137-
}
138-
}
139-
140-
void GPUParticles3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel) {
141-
GPUParticles3D *particles = Object::cast_to<GPUParticles3D>(p_gizmo->get_node_3d());
142-
143-
if (p_cancel) {
144-
particles->set_visibility_aabb(p_restore);
145-
return;
146-
}
147-
148-
EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
149-
ur->create_action(TTR("Change Particles AABB"));
150-
ur->add_do_method(particles, "set_visibility_aabb", particles->get_visibility_aabb());
151-
ur->add_undo_method(particles, "set_visibility_aabb", p_restore);
152-
ur->commit_action();
153-
}
154-
15563
void GPUParticles3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
15664
p_gizmo->clear();
15765

@@ -168,33 +76,9 @@ void GPUParticles3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
16876
lines.push_back(b);
16977
}
17078

171-
Vector<Vector3> handles;
172-
173-
for (int i = 0; i < 3; i++) {
174-
Vector3 ax;
175-
ax[i] = aabb.position[i] + aabb.size[i];
176-
ax[(i + 1) % 3] = aabb.position[(i + 1) % 3] + aabb.size[(i + 1) % 3] * 0.5;
177-
ax[(i + 2) % 3] = aabb.position[(i + 2) % 3] + aabb.size[(i + 2) % 3] * 0.5;
178-
handles.push_back(ax);
179-
}
180-
181-
Vector3 center = aabb.get_center();
182-
for (int i = 0; i < 3; i++) {
183-
Vector3 ax;
184-
ax[i] = 1.0;
185-
handles.push_back(center + ax);
186-
lines.push_back(center);
187-
lines.push_back(center + ax);
188-
}
189-
19079
Ref<Material> material = get_material("particles_material", p_gizmo);
19180

19281
p_gizmo->add_lines(lines, material);
193-
194-
Ref<Material> solid_material = get_material("particles_solid_material", p_gizmo);
195-
p_gizmo->add_solid_box(solid_material, aabb.get_size(), aabb.get_center());
196-
197-
p_gizmo->add_handles(handles, get_material("handles"));
19882
}
19983

20084
Ref<Material> icon = get_material("particles_icon", p_gizmo);

editor/plugins/gizmos/gpu_particles_3d_gizmo_plugin.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ class GPUParticles3DGizmoPlugin : public EditorNode3DGizmoPlugin {
4343
bool is_selectable_when_hidden() const override;
4444
void redraw(EditorNode3DGizmo *p_gizmo) override;
4545

46-
String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
47-
Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override;
48-
void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
49-
void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
50-
5146
GPUParticles3DGizmoPlugin();
5247
};
5348

0 commit comments

Comments
 (0)