@@ -98,8 +98,10 @@ void CollisionPolygon3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
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 int 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,24 +121,25 @@ 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 int 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 ) {
@@ -165,18 +168,19 @@ void CollisionPolygon3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
165
168
Vector<Color> cap_colours_bottom;
166
169
Vector<int > cap_indices_bottom;
167
170
168
- const int index_offset = verts. size () ;
171
+ const int index_offset = verts_size ;
169
172
170
173
const Vector<Vector2> &convex = decomp[i];
174
+ const int convex_size = convex.size ();
171
175
172
- for (int j = 0 ; j < convex. size () ; j++) {
176
+ for (int j = 0 ; j < convex_size ; j++) {
173
177
cap_verts_bottom.push_back (Vector3 (convex[j].x , convex[j].y , -depth));
174
178
cap_colours_bottom.push_back (collision_color);
175
179
}
176
180
177
- if (convex. size () >= 3 ) {
178
- for (int j = 1 ; j < convex. size () ; j++) {
179
- const int k = (j + 1 ) % convex. size () ;
181
+ if (convex_size >= 3 ) {
182
+ for (int j = 1 ; j < convex_size ; j++) {
183
+ const int k = (j + 1 ) % convex_size ;
180
184
181
185
cap_indices_bottom.push_back (index_offset + 0 );
182
186
cap_indices_bottom.push_back (index_offset + j);
@@ -194,18 +198,19 @@ void CollisionPolygon3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
194
198
Vector<Color> cap_colours_top;
195
199
Vector<int > cap_indices_top;
196
200
197
- const int index_offset = verts. size () ;
201
+ const int index_offset = verts_size ;
198
202
199
203
const Vector<Vector2> &convex = decomp[i];
204
+ const int convex_size = convex.size ();
200
205
201
- for (int j = 0 ; j < convex. size () ; j++) {
206
+ for (int j = 0 ; j < convex_size ; j++) {
202
207
cap_verts_top.push_back (Vector3 (convex[j].x , convex[j].y , depth));
203
208
cap_colours_top.push_back (collision_color);
204
209
}
205
210
206
- if (convex. size () >= 3 ) {
207
- for (int j = 1 ; j < convex. size () ; j++) {
208
- const int k = (j + 1 ) % convex. size () ;
211
+ if (convex_size >= 3 ) {
212
+ for (int j = 1 ; j < convex_size ; j++) {
213
+ const int k = (j + 1 ) % convex_size ;
209
214
210
215
cap_indices_top.push_back (index_offset + k);
211
216
cap_indices_top.push_back (index_offset + j);
0 commit comments