@@ -41,7 +41,7 @@ CollisionPolygon3DGizmoPlugin::CollisionPolygon3DGizmoPlugin() {
41
41
create_collision_material (" shape_material_arraymesh_disabled" , 0.015625 );
42
42
}
43
43
44
- void CollisionPolygon3DGizmoPlugin::create_collision_material (const String & p_name, float p_alpha) {
44
+ void CollisionPolygon3DGizmoPlugin::create_collision_material (const String& p_name, float p_alpha) {
45
45
Vector<Ref<StandardMaterial3D>> mats;
46
46
47
47
const Color collision_color (1.0 , 1.0 , 1.0 , p_alpha);
@@ -70,7 +70,7 @@ void CollisionPolygon3DGizmoPlugin::create_collision_material(const String &p_na
70
70
materials[p_name] = mats;
71
71
}
72
72
73
- bool CollisionPolygon3DGizmoPlugin::has_gizmo (Node3D * p_spatial) {
73
+ bool CollisionPolygon3DGizmoPlugin::has_gizmo (Node3D* p_spatial) {
74
74
return Object::cast_to<CollisionPolygon3D>(p_spatial) != nullptr ;
75
75
}
76
76
@@ -82,24 +82,26 @@ int CollisionPolygon3DGizmoPlugin::get_priority() const {
82
82
return -1 ;
83
83
}
84
84
85
- void CollisionPolygon3DGizmoPlugin::redraw (EditorNode3DGizmo * p_gizmo) {
86
- CollisionPolygon3D * polygon = Object::cast_to<CollisionPolygon3D>(p_gizmo->get_node_3d ());
85
+ void CollisionPolygon3DGizmoPlugin::redraw (EditorNode3DGizmo* p_gizmo) {
86
+ CollisionPolygon3D* polygon = Object::cast_to<CollisionPolygon3D>(p_gizmo->get_node_3d ());
87
87
88
88
p_gizmo->clear ();
89
89
90
90
const Ref<StandardMaterial3D> material =
91
- get_material (!polygon->is_disabled () ? " shape_material" : " shape_material_disabled" , p_gizmo);
91
+ get_material (!polygon->is_disabled () ? " shape_material" : " shape_material_disabled" , p_gizmo);
92
92
const Ref<StandardMaterial3D> material_arraymesh =
93
- get_material (!polygon->is_disabled () ? " shape_material_arraymesh" : " shape_material_arraymesh_disabled" , p_gizmo);
93
+ get_material (!polygon->is_disabled () ? " shape_material_arraymesh" : " shape_material_arraymesh_disabled" , p_gizmo);
94
94
95
95
const Color collision_color = polygon->is_disabled () ? Color (1.0 , 1.0 , 1.0 , 0.75 ) : polygon->get_debug_color ();
96
96
97
97
Vector<Vector2> points = polygon->get_polygon ();
98
98
float depth = polygon->get_depth () * 0.5 ;
99
99
100
100
Vector<Vector3> lines;
101
- for (int i = 0 ; i < points.size (); i++) {
102
- int n = (i + 1 ) % points.size ();
101
+ const uint64_t points_size = points.size ();
102
+
103
+ for (int i = 0 ; i < points_size; i++) {
104
+ int n = (i + 1 ) % points_size;
103
105
lines.push_back (Vector3 (points[i].x , points[i].y , depth));
104
106
lines.push_back (Vector3 (points[n].x , points[n].y , depth));
105
107
lines.push_back (Vector3 (points[i].x , points[i].y , -depth));
@@ -119,30 +121,32 @@ void CollisionPolygon3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
119
121
// Determine orientation of the 2D polygon's vertices to determine
120
122
// which direction to draw outer polygons.
121
123
float signed_area = 0 .0f ;
122
- for (int i = 0 ; i < points. size () ; i++) {
123
- const int j = (i + 1 ) % points. size () ;
124
+ for (int i = 0 ; i < points_size ; i++) {
125
+ const int j = (i + 1 ) % points_size ;
124
126
signed_area += points[i].x * points[j].y - points[j].x * points[i].y ;
125
127
}
126
128
127
129
// Generate triangles for the sides of the extruded polygon.
128
- for (int i = 0 ; i < points. size () ; i++) {
130
+ for (int i = 0 ; i < points_size ; i++) {
129
131
verts.push_back (Vector3 (points[i].x , points[i].y , depth));
130
132
verts.push_back (Vector3 (points[i].x , points[i].y , -depth));
131
133
132
134
colors.push_back (collision_color);
133
135
colors.push_back (collision_color);
134
136
}
135
137
136
- for (int i = 0 ; i < verts.size (); i += 2 ) {
137
- const int j = (i + 1 ) % verts.size ();
138
- const int k = (i + 2 ) % verts.size ();
139
- const int l = (i + 3 ) % verts.size ();
138
+ const uint64_t verts_size = verts.size ();
139
+ for (int i = 0 ; i < verts_size; i += 2 ) {
140
+ const int j = (i + 1 ) % verts_size;
141
+ const int k = (i + 2 ) % verts_size;
142
+ const int l = (i + 3 ) % verts_size;
140
143
141
144
indices.push_back (i);
142
145
if (signed_area < 0 ) {
143
146
indices.push_back (j);
144
147
indices.push_back (k);
145
- } else {
148
+ }
149
+ else {
146
150
indices.push_back (k);
147
151
indices.push_back (j);
148
152
}
@@ -151,32 +155,35 @@ void CollisionPolygon3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
151
155
if (signed_area < 0 ) {
152
156
indices.push_back (l);
153
157
indices.push_back (k);
154
- } else {
158
+ }
159
+ else {
155
160
indices.push_back (k);
156
161
indices.push_back (l);
157
162
}
158
163
}
159
164
160
165
Vector<Vector<Vector2>> decomp = Geometry2D::decompose_polygon_in_convex (polygon->get_polygon ());
161
166
167
+
162
168
// Generate triangles for the bottom cap of the extruded polygon.
163
169
for (int i = 0 ; i < decomp.size (); i++) {
164
170
Vector<Vector3> cap_verts_bottom;
165
171
Vector<Color> cap_colours_bottom;
166
172
Vector<int > cap_indices_bottom;
167
173
168
- const int index_offset = verts. size () ;
174
+ const int index_offset = verts_size ;
169
175
170
- const Vector<Vector2> &convex = decomp[i];
176
+ const Vector<Vector2>& convex = decomp[i];
177
+ const uint64_t convex_size = convex.size ();
171
178
172
- for (int j = 0 ; j < convex. size () ; j++) {
179
+ for (int j = 0 ; j < convex_size ; j++) {
173
180
cap_verts_bottom.push_back (Vector3 (convex[j].x , convex[j].y , -depth));
174
181
cap_colours_bottom.push_back (collision_color);
175
182
}
176
183
177
- if (convex. size () >= 3 ) {
178
- for (int j = 1 ; j < convex. size () ; j++) {
179
- const int k = (j + 1 ) % convex. size () ;
184
+ if (convex_size >= 3 ) {
185
+ for (int j = 1 ; j < convex_size ; j++) {
186
+ const int k = (j + 1 ) % convex_size ;
180
187
181
188
cap_indices_bottom.push_back (index_offset + 0 );
182
189
cap_indices_bottom.push_back (index_offset + j);
@@ -194,18 +201,19 @@ void CollisionPolygon3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
194
201
Vector<Color> cap_colours_top;
195
202
Vector<int > cap_indices_top;
196
203
197
- const int index_offset = verts. size () ;
204
+ const int index_offset = verts_size ;
198
205
199
- const Vector<Vector2> &convex = decomp[i];
206
+ const Vector<Vector2>& convex = decomp[i];
207
+ const uint64_t convex_size = convex.size ();
200
208
201
- for (int j = 0 ; j < convex. size () ; j++) {
209
+ for (int j = 0 ; j < convex_size ; j++) {
202
210
cap_verts_top.push_back (Vector3 (convex[j].x , convex[j].y , depth));
203
211
cap_colours_top.push_back (collision_color);
204
212
}
205
213
206
- if (convex. size () >= 3 ) {
207
- for (int j = 1 ; j < convex. size () ; j++) {
208
- const int k = (j + 1 ) % convex. size () ;
214
+ if (convex_size >= 3 ) {
215
+ for (int j = 1 ; j < convex_size ; j++) {
216
+ const int k = (j + 1 ) % convex_size ;
209
217
210
218
cap_indices_top.push_back (index_offset + k);
211
219
cap_indices_top.push_back (index_offset + j);
0 commit comments