39
39
namespace TestArrayMesh {
40
40
41
41
TEST_CASE (" [SceneTree][ArrayMesh] Adding and modifying blendshapes." ) {
42
- Ref<ArrayMesh> mesh = memnew (ArrayMesh);
42
+ Ref<ArrayMesh> mesh;
43
+ mesh.instantiate ();
43
44
StringName name_a{ " ShapeA" };
44
45
StringName name_b{ " ShapeB" };
45
46
@@ -76,8 +77,9 @@ TEST_CASE("[SceneTree][ArrayMesh] Adding and modifying blendshapes.") {
76
77
}
77
78
78
79
SUBCASE (" Adding blend shape after surface is added causes error" ) {
79
- Ref<CylinderMesh> cylinder = memnew (CylinderMesh);
80
- Array cylinder_array{};
80
+ Ref<CylinderMesh> cylinder;
81
+ cylinder.instantiate ();
82
+ Array cylinder_array;
81
83
cylinder_array.resize (Mesh::ARRAY_MAX);
82
84
cylinder->create_mesh_array (cylinder_array, 3 .f , 3 .f , 5 .f );
83
85
mesh->add_surface_from_arrays (Mesh::PRIMITIVE_TRIANGLES, cylinder_array);
@@ -89,8 +91,9 @@ TEST_CASE("[SceneTree][ArrayMesh] Adding and modifying blendshapes.") {
89
91
}
90
92
91
93
SUBCASE (" Adding blend shapes once all surfaces have been removed is allowed" ) {
92
- Ref<CylinderMesh> cylinder = memnew (CylinderMesh);
93
- Array cylinder_array{};
94
+ Ref<CylinderMesh> cylinder;
95
+ cylinder.instantiate ();
96
+ Array cylinder_array;
94
97
cylinder_array.resize (Mesh::ARRAY_MAX);
95
98
cylinder->create_mesh_array (cylinder_array, 3 .f , 3 .f , 5 .f );
96
99
mesh->add_surface_from_arrays (Mesh::PRIMITIVE_TRIANGLES, cylinder_array);
@@ -136,16 +139,17 @@ TEST_CASE("[SceneTree][ArrayMesh] Adding and modifying blendshapes.") {
136
139
SUBCASE (" Clearing all blend shapes once all surfaces have been removed is allowed" ) {
137
140
mesh->add_blend_shape (name_a);
138
141
mesh->add_blend_shape (name_b);
139
- Ref<CylinderMesh> cylinder = memnew (CylinderMesh);
140
- Array cylinder_array{};
142
+ Ref<CylinderMesh> cylinder;
143
+ cylinder.instantiate ();
144
+ Array cylinder_array;
141
145
cylinder_array.resize (Mesh::ARRAY_MAX);
142
146
cylinder->create_mesh_array (cylinder_array, 3 .f , 3 .f , 5 .f );
143
- Array blend_shape{} ;
147
+ Array blend_shape;
144
148
blend_shape.resize (Mesh::ARRAY_MAX);
145
149
blend_shape[Mesh::ARRAY_VERTEX] = cylinder_array[Mesh::ARRAY_VERTEX];
146
150
blend_shape[Mesh::ARRAY_NORMAL] = cylinder_array[Mesh::ARRAY_NORMAL];
147
151
blend_shape[Mesh::ARRAY_TANGENT] = cylinder_array[Mesh::ARRAY_TANGENT];
148
- Array blend_shapes{} ;
152
+ Array blend_shapes;
149
153
blend_shapes.push_back (blend_shape);
150
154
blend_shapes.push_back (blend_shape);
151
155
mesh->add_surface_from_arrays (Mesh::PRIMITIVE_TRIANGLES, cylinder_array, blend_shapes);
@@ -165,8 +169,7 @@ TEST_CASE("[SceneTree][ArrayMesh] Adding and modifying blendshapes.") {
165
169
SUBCASE (" Can't add surface with incorrect number of blend shapes." ) {
166
170
mesh->add_blend_shape (name_a);
167
171
mesh->add_blend_shape (name_b);
168
- Ref<CylinderMesh> cylinder = memnew (CylinderMesh);
169
- Array cylinder_array{};
172
+ Array cylinder_array;
170
173
ERR_PRINT_OFF
171
174
mesh->add_surface_from_arrays (Mesh::PRIMITIVE_TRIANGLES, cylinder_array);
172
175
ERR_PRINT_ON
@@ -176,16 +179,17 @@ TEST_CASE("[SceneTree][ArrayMesh] Adding and modifying blendshapes.") {
176
179
SUBCASE (" Can't clear blend shapes after surface had been added." ) {
177
180
mesh->add_blend_shape (name_a);
178
181
mesh->add_blend_shape (name_b);
179
- Ref<CylinderMesh> cylinder = memnew (CylinderMesh);
180
- Array cylinder_array{};
182
+ Ref<CylinderMesh> cylinder;
183
+ cylinder.instantiate ();
184
+ Array cylinder_array;
181
185
cylinder_array.resize (Mesh::ARRAY_MAX);
182
186
cylinder->create_mesh_array (cylinder_array, 3 .f , 3 .f , 5 .f );
183
- Array blend_shape{} ;
187
+ Array blend_shape;
184
188
blend_shape.resize (Mesh::ARRAY_MAX);
185
189
blend_shape[Mesh::ARRAY_VERTEX] = cylinder_array[Mesh::ARRAY_VERTEX];
186
190
blend_shape[Mesh::ARRAY_NORMAL] = cylinder_array[Mesh::ARRAY_NORMAL];
187
191
blend_shape[Mesh::ARRAY_TANGENT] = cylinder_array[Mesh::ARRAY_TANGENT];
188
- Array blend_shapes{} ;
192
+ Array blend_shapes;
189
193
blend_shapes.push_back (blend_shape);
190
194
blend_shapes.push_back (blend_shape);
191
195
mesh->add_surface_from_arrays (Mesh::PRIMITIVE_TRIANGLES, cylinder_array, blend_shapes);
@@ -203,15 +207,18 @@ TEST_CASE("[SceneTree][ArrayMesh] Adding and modifying blendshapes.") {
203
207
}
204
208
205
209
TEST_CASE (" [SceneTree][ArrayMesh] Surface metadata tests." ) {
206
- Ref<ArrayMesh> mesh = memnew (ArrayMesh);
207
- Ref<CylinderMesh> cylinder = memnew (CylinderMesh);
208
- Array cylinder_array{};
210
+ Ref<ArrayMesh> mesh;
211
+ mesh.instantiate ();
212
+ Ref<CylinderMesh> cylinder;
213
+ cylinder.instantiate ();
214
+ Array cylinder_array;
209
215
cylinder_array.resize (Mesh::ARRAY_MAX);
210
216
cylinder->create_mesh_array (cylinder_array, 3 .f , 3 .f , 5 .f );
211
217
mesh->add_surface_from_arrays (Mesh::PRIMITIVE_TRIANGLES, cylinder_array);
212
218
213
- Ref<BoxMesh> box = memnew (BoxMesh);
214
- Array box_array{};
219
+ Ref<BoxMesh> box;
220
+ box.instantiate ();
221
+ Array box_array;
215
222
box_array.resize (Mesh::ARRAY_MAX);
216
223
box->create_mesh_array (box_array, Vector3 (2 .f , 1 .2f , 1 .6f ));
217
224
mesh->add_surface_from_arrays (Mesh::PRIMITIVE_TRIANGLES, box_array);
@@ -255,68 +262,77 @@ TEST_CASE("[SceneTree][ArrayMesh] Surface metadata tests.") {
255
262
}
256
263
257
264
SUBCASE (" Set material to two different surfaces." ) {
258
- Ref<Material> mat = memnew (Material);
265
+ Ref<Material> mat;
266
+ mat.instantiate ();
259
267
mesh->surface_set_material (0 , mat);
260
268
CHECK (mesh->surface_get_material (0 ) == mat);
261
269
mesh->surface_set_material (1 , mat);
262
270
CHECK (mesh->surface_get_material (1 ) == mat);
263
271
}
264
272
265
273
SUBCASE (" Set same material multiple times doesn't change material of surface." ) {
266
- Ref<Material> mat = memnew (Material);
274
+ Ref<Material> mat;
275
+ mat.instantiate ();
267
276
mesh->surface_set_material (0 , mat);
268
277
mesh->surface_set_material (0 , mat);
269
278
mesh->surface_set_material (0 , mat);
270
279
CHECK (mesh->surface_get_material (0 ) == mat);
271
280
}
272
281
273
282
SUBCASE (" Set material of surface then change to different material." ) {
274
- Ref<Material> mat1 = memnew (Material);
275
- Ref<Material> mat2 = memnew (Material);
283
+ Ref<Material> mat1;
284
+ mat1.instantiate ();
285
+ Ref<Material> mat2;
286
+ mat2.instantiate ();
276
287
mesh->surface_set_material (1 , mat1);
277
288
CHECK (mesh->surface_get_material (1 ) == mat1);
278
289
mesh->surface_set_material (1 , mat2);
279
290
CHECK (mesh->surface_get_material (1 ) == mat2);
280
291
}
281
292
282
293
SUBCASE (" Get the LOD of the mesh." ) {
283
- Dictionary lod{} ;
284
- mesh->add_surface_from_arrays (Mesh::PRIMITIVE_TRIANGLES, cylinder_array, TypedArray<Array>{} , lod);
294
+ Dictionary lod;
295
+ mesh->add_surface_from_arrays (Mesh::PRIMITIVE_TRIANGLES, cylinder_array, TypedArray<Array>() , lod);
285
296
CHECK (mesh->surface_get_lods (2 ) == lod);
286
297
}
287
298
288
299
SUBCASE (" Get the blend shape arrays from the mesh." ) {
289
- TypedArray<Array> blend{} ;
300
+ TypedArray<Array> blend;
290
301
mesh->add_surface_from_arrays (Mesh::PRIMITIVE_TRIANGLES, cylinder_array, blend);
291
302
CHECK (mesh->surface_get_blend_shape_arrays (2 ) == blend);
292
303
}
293
304
}
294
305
295
306
TEST_CASE (" [SceneTree][ArrayMesh] Get/Set mesh metadata and actions" ) {
296
- Ref<ArrayMesh> mesh = memnew (ArrayMesh);
297
- Ref<CylinderMesh> cylinder = memnew (CylinderMesh);
298
- Array cylinder_array{};
307
+ Ref<ArrayMesh> mesh;
308
+ mesh.instantiate ();
309
+ Ref<CylinderMesh> cylinder;
310
+ cylinder.instantiate ();
311
+ Array cylinder_array;
299
312
cylinder_array.resize (Mesh::ARRAY_MAX);
300
313
constexpr float cylinder_radius = 3 .f ;
301
314
constexpr float cylinder_height = 5 .f ;
302
315
cylinder->create_mesh_array (cylinder_array, cylinder_radius, cylinder_radius, cylinder_height);
303
316
mesh->add_surface_from_arrays (Mesh::PRIMITIVE_TRIANGLES, cylinder_array);
304
317
305
- Ref<BoxMesh> box = memnew (BoxMesh);
306
- Array box_array{};
318
+ Ref<BoxMesh> box;
319
+ box.instantiate ();
320
+ Array box_array;
307
321
box_array.resize (Mesh::ARRAY_MAX);
308
322
const Vector3 box_size = Vector3 (2 .f , 1 .2f , 1 .6f );
309
323
box->create_mesh_array (box_array, box_size);
310
324
mesh->add_surface_from_arrays (Mesh::PRIMITIVE_TRIANGLES, box_array);
311
325
312
326
SUBCASE (" Set the shadow mesh." ) {
313
- Ref<ArrayMesh> shadow = memnew (ArrayMesh);
327
+ Ref<ArrayMesh> shadow ;
328
+ shadow .instantiate ();
314
329
mesh->set_shadow_mesh (shadow );
315
330
CHECK (mesh->get_shadow_mesh () == shadow );
316
331
}
317
332
318
333
SUBCASE (" Set the shadow mesh multiple times." ) {
319
- Ref<ArrayMesh> shadow = memnew (ArrayMesh);
334
+ Ref<ArrayMesh> shadow ;
335
+ shadow .instantiate ();
320
336
mesh->set_shadow_mesh (shadow );
321
337
mesh->set_shadow_mesh (shadow );
322
338
mesh->set_shadow_mesh (shadow );
@@ -325,8 +341,10 @@ TEST_CASE("[SceneTree][ArrayMesh] Get/Set mesh metadata and actions") {
325
341
}
326
342
327
343
SUBCASE (" Set the same shadow mesh on multiple meshes." ) {
328
- Ref<ArrayMesh> shadow = memnew (ArrayMesh);
329
- Ref<ArrayMesh> mesh2 = memnew (ArrayMesh);
344
+ Ref<ArrayMesh> shadow ;
345
+ shadow .instantiate ();
346
+ Ref<ArrayMesh> mesh2;
347
+ mesh2.instantiate ();
330
348
mesh->set_shadow_mesh (shadow );
331
349
mesh2->set_shadow_mesh (shadow );
332
350
@@ -335,22 +353,24 @@ TEST_CASE("[SceneTree][ArrayMesh] Get/Set mesh metadata and actions") {
335
353
}
336
354
337
355
SUBCASE (" Set the shadow mesh and then change it." ) {
338
- Ref<ArrayMesh> shadow = memnew (ArrayMesh);
356
+ Ref<ArrayMesh> shadow ;
357
+ shadow .instantiate ();
339
358
mesh->set_shadow_mesh (shadow );
340
359
CHECK (mesh->get_shadow_mesh () == shadow );
341
- Ref<ArrayMesh> shadow2 = memnew (ArrayMesh);
360
+ Ref<ArrayMesh> shadow2;
361
+ shadow2.instantiate ();
342
362
mesh->set_shadow_mesh (shadow2);
343
363
CHECK (mesh->get_shadow_mesh () == shadow2);
344
364
}
345
365
346
366
SUBCASE (" Set custom AABB." ) {
347
- AABB bound{} ;
367
+ AABB bound;
348
368
mesh->set_custom_aabb (bound);
349
369
CHECK (mesh->get_custom_aabb () == bound);
350
370
}
351
371
352
372
SUBCASE (" Set custom AABB multiple times." ) {
353
- AABB bound{} ;
373
+ AABB bound;
354
374
mesh->set_custom_aabb (bound);
355
375
mesh->set_custom_aabb (bound);
356
376
mesh->set_custom_aabb (bound);
@@ -359,8 +379,8 @@ TEST_CASE("[SceneTree][ArrayMesh] Get/Set mesh metadata and actions") {
359
379
}
360
380
361
381
SUBCASE (" Set custom AABB then change to another AABB." ) {
362
- AABB bound{} ;
363
- AABB bound2{} ;
382
+ AABB bound;
383
+ AABB bound2;
364
384
mesh->set_custom_aabb (bound);
365
385
CHECK (mesh->get_custom_aabb () == bound);
366
386
mesh->set_custom_aabb (bound2);
@@ -380,7 +400,8 @@ TEST_CASE("[SceneTree][ArrayMesh] Get/Set mesh metadata and actions") {
380
400
SUBCASE (" Create surface from raw SurfaceData data." ) {
381
401
RID mesh_rid = mesh->get_rid ();
382
402
RS::SurfaceData surface_data = RS::get_singleton ()->mesh_get_surface (mesh_rid, 0 );
383
- Ref<ArrayMesh> mesh2 = memnew (ArrayMesh);
403
+ Ref<ArrayMesh> mesh2;
404
+ mesh2.instantiate ();
384
405
mesh2->add_surface (surface_data.format , Mesh::PRIMITIVE_TRIANGLES, surface_data.vertex_data , surface_data.attribute_data ,
385
406
surface_data.skin_data , surface_data.vertex_count , surface_data.index_data , surface_data.index_count , surface_data.aabb );
386
407
CHECK (mesh2->get_surface_count () == 1 );
0 commit comments