@@ -41,9 +41,7 @@ GPUParticles3DGizmoPlugin::GPUParticles3DGizmoPlugin() {
41
41
Color gizmo_color = EDITOR_DEF_RST (" editors/3d_gizmos/gizmo_colors/particles" , Color (0.8 , 0.7 , 0.4 ));
42
42
create_material (" particles_material" , gizmo_color);
43
43
gizmo_color.a = MAX ((gizmo_color.a - 0.2 ) * 0.02 , 0.0 );
44
- create_material (" particles_solid_material" , gizmo_color);
45
44
create_icon_material (" particles_icon" , EditorNode::get_singleton ()->get_editor_theme ()->get_icon (SNAME (" GizmoGPUParticles3D" ), EditorStringName (EditorIcons)));
46
- create_handle_material (" handles" );
47
45
}
48
46
49
47
bool GPUParticles3DGizmoPlugin::has_gizmo (Node3D *p_spatial) {
@@ -62,96 +60,6 @@ bool GPUParticles3DGizmoPlugin::is_selectable_when_hidden() const {
62
60
return true ;
63
61
}
64
62
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
-
155
63
void GPUParticles3DGizmoPlugin::redraw (EditorNode3DGizmo *p_gizmo) {
156
64
p_gizmo->clear ();
157
65
@@ -168,33 +76,9 @@ void GPUParticles3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
168
76
lines.push_back (b);
169
77
}
170
78
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
-
190
79
Ref<Material> material = get_material (" particles_material" , p_gizmo);
191
80
192
81
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" ));
198
82
}
199
83
200
84
Ref<Material> icon = get_material (" particles_icon" , p_gizmo);
0 commit comments