-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
/
mesh.cpp
2341 lines (1949 loc) · 81.4 KB
/
mesh.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**************************************************************************/
/* mesh.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "mesh.h"
#include "core/math/convex_hull.h"
#include "core/templates/pair.h"
#include "scene/resources/surface_tool.h"
#include "scene/resources/concave_polygon_shape_3d.h"
#include "scene/resources/convex_polygon_shape_3d.h"
void MeshConvexDecompositionSettings::set_max_concavity(real_t p_max_concavity) {
max_concavity = CLAMP(p_max_concavity, 0.001, 1.0);
}
real_t MeshConvexDecompositionSettings::get_max_concavity() const {
return max_concavity;
};
void MeshConvexDecompositionSettings::set_symmetry_planes_clipping_bias(real_t p_symmetry_planes_clipping_bias) {
symmetry_planes_clipping_bias = CLAMP(p_symmetry_planes_clipping_bias, 0.0, 1.0);
};
real_t MeshConvexDecompositionSettings::get_symmetry_planes_clipping_bias() const {
return symmetry_planes_clipping_bias;
};
void MeshConvexDecompositionSettings::set_revolution_axes_clipping_bias(real_t p_revolution_axes_clipping_bias) {
revolution_axes_clipping_bias = CLAMP(p_revolution_axes_clipping_bias, 0.0, 1.0);
};
real_t MeshConvexDecompositionSettings::get_revolution_axes_clipping_bias() const {
return revolution_axes_clipping_bias;
};
void MeshConvexDecompositionSettings::set_min_volume_per_convex_hull(real_t p_min_volume_per_convex_hull) {
min_volume_per_convex_hull = CLAMP(p_min_volume_per_convex_hull, 0.0001, 0.01);
}
real_t MeshConvexDecompositionSettings::get_min_volume_per_convex_hull() const {
return min_volume_per_convex_hull;
}
void MeshConvexDecompositionSettings::set_resolution(uint32_t p_resolution) {
resolution = p_resolution < 10'000 ? 10'000 : (p_resolution > 100'000 ? 100'000 : p_resolution);
}
uint32_t MeshConvexDecompositionSettings::get_resolution() const {
return resolution;
}
void MeshConvexDecompositionSettings::set_max_num_vertices_per_convex_hull(uint32_t p_max_num_vertices_per_convex_hull) {
max_num_vertices_per_convex_hull = p_max_num_vertices_per_convex_hull < 4 ? 4 : (p_max_num_vertices_per_convex_hull > 1024 ? 1024 : p_max_num_vertices_per_convex_hull);
}
uint32_t MeshConvexDecompositionSettings::get_max_num_vertices_per_convex_hull() const {
return max_num_vertices_per_convex_hull;
}
void MeshConvexDecompositionSettings::set_plane_downsampling(uint32_t p_plane_downsampling) {
plane_downsampling = p_plane_downsampling < 1 ? 1 : (p_plane_downsampling > 16 ? 16 : p_plane_downsampling);
}
uint32_t MeshConvexDecompositionSettings::get_plane_downsampling() const {
return plane_downsampling;
}
void MeshConvexDecompositionSettings::set_convex_hull_downsampling(uint32_t p_convex_hull_downsampling) {
convex_hull_downsampling = p_convex_hull_downsampling < 1 ? 1 : (p_convex_hull_downsampling > 16 ? 16 : p_convex_hull_downsampling);
}
uint32_t MeshConvexDecompositionSettings::get_convex_hull_downsampling() const {
return convex_hull_downsampling;
}
void MeshConvexDecompositionSettings::set_normalize_mesh(bool p_normalize_mesh) {
normalize_mesh = p_normalize_mesh;
}
bool MeshConvexDecompositionSettings::get_normalize_mesh() const {
return normalize_mesh;
}
void MeshConvexDecompositionSettings::set_mode(Mode p_mode) {
mode = p_mode;
}
MeshConvexDecompositionSettings::Mode MeshConvexDecompositionSettings::get_mode() const {
return mode;
}
void MeshConvexDecompositionSettings::set_convex_hull_approximation(bool p_convex_hull_approximation) {
convex_hull_approximation = p_convex_hull_approximation;
}
bool MeshConvexDecompositionSettings::get_convex_hull_approximation() const {
return convex_hull_approximation;
}
void MeshConvexDecompositionSettings::set_max_convex_hulls(uint32_t p_max_convex_hulls) {
max_convex_hulls = p_max_convex_hulls < 1 ? 1 : (p_max_convex_hulls > 32 ? 32 : p_max_convex_hulls);
}
uint32_t MeshConvexDecompositionSettings::get_max_convex_hulls() const {
return max_convex_hulls;
}
void MeshConvexDecompositionSettings::set_project_hull_vertices(bool p_project_hull_vertices) {
project_hull_vertices = p_project_hull_vertices;
}
bool MeshConvexDecompositionSettings::get_project_hull_vertices() const {
return project_hull_vertices;
}
void MeshConvexDecompositionSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_max_concavity", "max_concavity"), &MeshConvexDecompositionSettings::set_max_concavity);
ClassDB::bind_method(D_METHOD("get_max_concavity"), &MeshConvexDecompositionSettings::get_max_concavity);
ClassDB::bind_method(D_METHOD("set_symmetry_planes_clipping_bias", "symmetry_planes_clipping_bias"), &MeshConvexDecompositionSettings::set_symmetry_planes_clipping_bias);
ClassDB::bind_method(D_METHOD("get_symmetry_planes_clipping_bias"), &MeshConvexDecompositionSettings::get_symmetry_planes_clipping_bias);
ClassDB::bind_method(D_METHOD("set_revolution_axes_clipping_bias", "revolution_axes_clipping_bias"), &MeshConvexDecompositionSettings::set_revolution_axes_clipping_bias);
ClassDB::bind_method(D_METHOD("get_revolution_axes_clipping_bias"), &MeshConvexDecompositionSettings::get_revolution_axes_clipping_bias);
ClassDB::bind_method(D_METHOD("set_min_volume_per_convex_hull", "min_volume_per_convex_hull"), &MeshConvexDecompositionSettings::set_min_volume_per_convex_hull);
ClassDB::bind_method(D_METHOD("get_min_volume_per_convex_hull"), &MeshConvexDecompositionSettings::get_min_volume_per_convex_hull);
ClassDB::bind_method(D_METHOD("set_resolution", "min_volume_per_convex_hull"), &MeshConvexDecompositionSettings::set_resolution);
ClassDB::bind_method(D_METHOD("get_resolution"), &MeshConvexDecompositionSettings::get_resolution);
ClassDB::bind_method(D_METHOD("set_max_num_vertices_per_convex_hull", "max_num_vertices_per_convex_hull"), &MeshConvexDecompositionSettings::set_max_num_vertices_per_convex_hull);
ClassDB::bind_method(D_METHOD("get_max_num_vertices_per_convex_hull"), &MeshConvexDecompositionSettings::get_max_num_vertices_per_convex_hull);
ClassDB::bind_method(D_METHOD("set_plane_downsampling", "plane_downsampling"), &MeshConvexDecompositionSettings::set_plane_downsampling);
ClassDB::bind_method(D_METHOD("get_plane_downsampling"), &MeshConvexDecompositionSettings::get_plane_downsampling);
ClassDB::bind_method(D_METHOD("set_convex_hull_downsampling", "convex_hull_downsampling"), &MeshConvexDecompositionSettings::set_convex_hull_downsampling);
ClassDB::bind_method(D_METHOD("get_convex_hull_downsampling"), &MeshConvexDecompositionSettings::get_convex_hull_downsampling);
ClassDB::bind_method(D_METHOD("set_normalize_mesh", "normalize_mesh"), &MeshConvexDecompositionSettings::set_normalize_mesh);
ClassDB::bind_method(D_METHOD("get_normalize_mesh"), &MeshConvexDecompositionSettings::get_normalize_mesh);
ClassDB::bind_method(D_METHOD("set_mode", "mode"), &MeshConvexDecompositionSettings::set_mode);
ClassDB::bind_method(D_METHOD("get_mode"), &MeshConvexDecompositionSettings::get_mode);
ClassDB::bind_method(D_METHOD("set_convex_hull_approximation", "convex_hull_approximation"), &MeshConvexDecompositionSettings::set_convex_hull_approximation);
ClassDB::bind_method(D_METHOD("get_convex_hull_approximation"), &MeshConvexDecompositionSettings::get_convex_hull_approximation);
ClassDB::bind_method(D_METHOD("set_max_convex_hulls", "max_convex_hulls"), &MeshConvexDecompositionSettings::set_max_convex_hulls);
ClassDB::bind_method(D_METHOD("get_max_convex_hulls"), &MeshConvexDecompositionSettings::get_max_convex_hulls);
ClassDB::bind_method(D_METHOD("set_project_hull_vertices", "project_hull_vertices"), &MeshConvexDecompositionSettings::set_project_hull_vertices);
ClassDB::bind_method(D_METHOD("get_project_hull_vertices"), &MeshConvexDecompositionSettings::get_project_hull_vertices);
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_concavity", PROPERTY_HINT_RANGE, "0.001,1.0,0.001"), "set_max_concavity", "get_max_concavity");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "symmetry_planes_clipping_bias", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_symmetry_planes_clipping_bias", "get_symmetry_planes_clipping_bias");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "revolution_axes_clipping_bias", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_revolution_axes_clipping_bias", "get_revolution_axes_clipping_bias");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "min_volume_per_convex_hull", PROPERTY_HINT_RANGE, "0.0001,0.01,0.0001"), "set_min_volume_per_convex_hull", "get_min_volume_per_convex_hull");
ADD_PROPERTY(PropertyInfo(Variant::INT, "resolution"), "set_resolution", "get_resolution");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_num_vertices_per_convex_hull"), "set_max_num_vertices_per_convex_hull", "get_max_num_vertices_per_convex_hull");
ADD_PROPERTY(PropertyInfo(Variant::INT, "plane_downsampling", PROPERTY_HINT_RANGE, "1,16,1"), "set_plane_downsampling", "get_plane_downsampling");
ADD_PROPERTY(PropertyInfo(Variant::INT, "convex_hull_downsampling", PROPERTY_HINT_RANGE, "1,16,1"), "set_convex_hull_downsampling", "get_convex_hull_downsampling");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "normalize_mesh"), "set_normalize_mesh", "get_normalize_mesh");
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Voxel,Tetrahedron"), "set_mode", "get_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "convex_hull_approximation"), "set_convex_hull_approximation", "get_convex_hull_approximation");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_convex_hulls"), "set_max_convex_hulls", "get_max_convex_hulls");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "project_hull_vertices"), "set_project_hull_vertices", "get_project_hull_vertices");
BIND_ENUM_CONSTANT(CONVEX_DECOMPOSITION_MODE_VOXEL);
BIND_ENUM_CONSTANT(CONVEX_DECOMPOSITION_MODE_TETRAHEDRON);
}
Mesh::ConvexDecompositionFunc Mesh::convex_decomposition_function = nullptr;
int Mesh::get_surface_count() const {
int ret = 0;
GDVIRTUAL_REQUIRED_CALL(_get_surface_count, ret);
return ret;
}
int Mesh::surface_get_array_len(int p_idx) const {
int ret = 0;
GDVIRTUAL_REQUIRED_CALL(_surface_get_array_len, p_idx, ret);
return ret;
}
int Mesh::surface_get_array_index_len(int p_idx) const {
int ret = 0;
GDVIRTUAL_REQUIRED_CALL(_surface_get_array_index_len, p_idx, ret);
return ret;
}
Array Mesh::surface_get_arrays(int p_surface) const {
Array ret;
GDVIRTUAL_REQUIRED_CALL(_surface_get_arrays, p_surface, ret);
return ret;
}
TypedArray<Array> Mesh::surface_get_blend_shape_arrays(int p_surface) const {
TypedArray<Array> ret;
GDVIRTUAL_REQUIRED_CALL(_surface_get_blend_shape_arrays, p_surface, ret);
return ret;
}
Dictionary Mesh::surface_get_lods(int p_surface) const {
Dictionary ret;
GDVIRTUAL_REQUIRED_CALL(_surface_get_lods, p_surface, ret);
return ret;
}
BitField<Mesh::ArrayFormat> Mesh::surface_get_format(int p_idx) const {
uint32_t ret = 0;
GDVIRTUAL_REQUIRED_CALL(_surface_get_format, p_idx, ret);
return ret;
}
Mesh::PrimitiveType Mesh::surface_get_primitive_type(int p_idx) const {
uint32_t ret = PRIMITIVE_MAX;
GDVIRTUAL_REQUIRED_CALL(_surface_get_primitive_type, p_idx, ret);
return (Mesh::PrimitiveType)ret;
}
void Mesh::surface_set_material(int p_idx, const Ref<Material> &p_material) {
GDVIRTUAL_REQUIRED_CALL(_surface_set_material, p_idx, p_material);
}
Ref<Material> Mesh::surface_get_material(int p_idx) const {
Ref<Material> ret;
GDVIRTUAL_REQUIRED_CALL(_surface_get_material, p_idx, ret);
return ret;
}
int Mesh::get_blend_shape_count() const {
int ret = 0;
GDVIRTUAL_REQUIRED_CALL(_get_blend_shape_count, ret);
return ret;
}
StringName Mesh::get_blend_shape_name(int p_index) const {
StringName ret;
GDVIRTUAL_REQUIRED_CALL(_get_blend_shape_name, p_index, ret);
return ret;
}
void Mesh::set_blend_shape_name(int p_index, const StringName &p_name) {
GDVIRTUAL_REQUIRED_CALL(_set_blend_shape_name, p_index, p_name);
}
AABB Mesh::get_aabb() const {
AABB ret;
GDVIRTUAL_REQUIRED_CALL(_get_aabb, ret);
return ret;
}
Ref<TriangleMesh> Mesh::generate_triangle_mesh() const {
if (triangle_mesh.is_valid()) {
return triangle_mesh;
}
int faces_size = 0;
for (int i = 0; i < get_surface_count(); i++) {
switch (surface_get_primitive_type(i)) {
case PRIMITIVE_TRIANGLES: {
int len = (surface_get_format(i) & ARRAY_FORMAT_INDEX) ? surface_get_array_index_len(i) : surface_get_array_len(i);
// Don't error if zero, it's valid (we'll just skip it later).
ERR_CONTINUE_MSG((len % 3) != 0, vformat("Ignoring surface %d, incorrect %s count: %d (for PRIMITIVE_TRIANGLES).", i, (surface_get_format(i) & ARRAY_FORMAT_INDEX) ? "index" : "vertex", len));
faces_size += len;
} break;
case PRIMITIVE_TRIANGLE_STRIP: {
int len = (surface_get_format(i) & ARRAY_FORMAT_INDEX) ? surface_get_array_index_len(i) : surface_get_array_len(i);
// Don't error if zero, it's valid (we'll just skip it later).
ERR_CONTINUE_MSG(len != 0 && len < 3, vformat("Ignoring surface %d, incorrect %s count: %d (for PRIMITIVE_TRIANGLE_STRIP).", i, (surface_get_format(i) & ARRAY_FORMAT_INDEX) ? "index" : "vertex", len));
faces_size += (len == 0) ? 0 : (len - 2) * 3;
} break;
default: {
} break;
}
}
if (faces_size == 0) {
return triangle_mesh;
}
Vector<Vector3> faces;
faces.resize(faces_size);
Vector<int32_t> surface_indices;
surface_indices.resize(faces_size / 3);
Vector3 *facesw = faces.ptrw();
int32_t *surface_indicesw = surface_indices.ptrw();
int widx = 0;
for (int i = 0; i < get_surface_count(); i++) {
Mesh::PrimitiveType primitive = surface_get_primitive_type(i);
if (primitive != PRIMITIVE_TRIANGLES && primitive != PRIMITIVE_TRIANGLE_STRIP) {
continue;
}
int len = (surface_get_format(i) & ARRAY_FORMAT_INDEX) ? surface_get_array_index_len(i) : surface_get_array_len(i);
if ((primitive == PRIMITIVE_TRIANGLES && (len == 0 || (len % 3) != 0)) ||
(primitive == PRIMITIVE_TRIANGLE_STRIP && len < 3) ||
(surface_get_format(i) & ARRAY_FLAG_USES_EMPTY_VERTEX_ARRAY)) {
// Error was already shown, just skip (including zero).
continue;
}
Array a = surface_get_arrays(i);
ERR_FAIL_COND_V(a.is_empty(), Ref<TriangleMesh>());
int vc = surface_get_array_len(i);
Vector<Vector3> vertices = a[ARRAY_VERTEX];
ERR_FAIL_COND_V(vertices.is_empty(), Ref<TriangleMesh>());
const Vector3 *vr = vertices.ptr();
int32_t from_index = widx / 3;
if (surface_get_format(i) & ARRAY_FORMAT_INDEX) {
int ic = surface_get_array_index_len(i);
Vector<int> indices = a[ARRAY_INDEX];
const int *ir = indices.ptr();
if (primitive == PRIMITIVE_TRIANGLES) {
for (int j = 0; j < ic; j++) {
int index = ir[j];
ERR_FAIL_COND_V(index >= vc, Ref<TriangleMesh>());
facesw[widx++] = vr[index];
}
} else { // PRIMITIVE_TRIANGLE_STRIP
for (int j = 2; j < ic; j++) {
facesw[widx++] = vr[ir[j - 2]];
facesw[widx++] = vr[ir[j - 1]];
facesw[widx++] = vr[ir[j]];
}
}
} else {
if (primitive == PRIMITIVE_TRIANGLES) {
for (int j = 0; j < vc; j++) {
facesw[widx++] = vr[j];
}
} else { // PRIMITIVE_TRIANGLE_STRIP
for (int j = 2; j < vc; j++) {
facesw[widx++] = vr[j - 2];
facesw[widx++] = vr[j - 1];
facesw[widx++] = vr[j];
}
}
}
int32_t to_index = widx / 3;
for (int j = from_index; j < to_index; j++) {
surface_indicesw[j] = i;
}
}
triangle_mesh = Ref<TriangleMesh>(memnew(TriangleMesh));
triangle_mesh->create(faces);
return triangle_mesh;
}
Ref<TriangleMesh> Mesh::generate_surface_triangle_mesh(int p_surface) const {
ERR_FAIL_INDEX_V(p_surface, get_surface_count(), Ref<TriangleMesh>());
if (surface_triangle_meshes.size() != get_surface_count()) {
surface_triangle_meshes.resize(get_surface_count());
}
if (surface_triangle_meshes[p_surface].is_valid()) {
return surface_triangle_meshes[p_surface];
}
int facecount = 0;
if (surface_get_primitive_type(p_surface) != PRIMITIVE_TRIANGLES) {
return Ref<TriangleMesh>();
}
if (surface_get_format(p_surface) & ARRAY_FORMAT_INDEX) {
facecount += surface_get_array_index_len(p_surface);
} else {
facecount += surface_get_array_len(p_surface);
}
Vector<Vector3> faces;
faces.resize(facecount);
Vector3 *facesw = faces.ptrw();
Array a = surface_get_arrays(p_surface);
ERR_FAIL_COND_V(a.is_empty(), Ref<TriangleMesh>());
int vc = surface_get_array_len(p_surface);
Vector<Vector3> vertices = a[ARRAY_VERTEX];
const Vector3 *vr = vertices.ptr();
int widx = 0;
if (surface_get_format(p_surface) & ARRAY_FORMAT_INDEX) {
int ic = surface_get_array_index_len(p_surface);
Vector<int> indices = a[ARRAY_INDEX];
const int *ir = indices.ptr();
for (int j = 0; j < ic; j++) {
int index = ir[j];
facesw[widx++] = vr[index];
}
} else {
for (int j = 0; j < vc; j++) {
facesw[widx++] = vr[j];
}
}
Ref<TriangleMesh> tr_mesh = Ref<TriangleMesh>(memnew(TriangleMesh));
tr_mesh->create(faces);
surface_triangle_meshes.set(p_surface, tr_mesh);
return tr_mesh;
}
void Mesh::generate_debug_mesh_lines(Vector<Vector3> &r_lines) {
if (debug_lines.size() > 0) {
r_lines = debug_lines;
return;
}
Ref<TriangleMesh> tm = generate_triangle_mesh();
if (tm.is_null()) {
return;
}
Vector<int> triangle_indices;
tm->get_indices(&triangle_indices);
const int triangles_num = tm->get_triangles().size();
Vector<Vector3> vertices = tm->get_vertices();
debug_lines.resize(tm->get_triangles().size() * 6); // 3 lines x 2 points each line
const int *ind_r = triangle_indices.ptr();
const Vector3 *ver_r = vertices.ptr();
for (int j = 0, x = 0, i = 0; i < triangles_num; j += 6, x += 3, ++i) {
// Triangle line 1
debug_lines.write[j + 0] = ver_r[ind_r[x + 0]];
debug_lines.write[j + 1] = ver_r[ind_r[x + 1]];
// Triangle line 2
debug_lines.write[j + 2] = ver_r[ind_r[x + 1]];
debug_lines.write[j + 3] = ver_r[ind_r[x + 2]];
// Triangle line 3
debug_lines.write[j + 4] = ver_r[ind_r[x + 2]];
debug_lines.write[j + 5] = ver_r[ind_r[x + 0]];
}
r_lines = debug_lines;
}
void Mesh::generate_debug_mesh_indices(Vector<Vector3> &r_points) {
Ref<TriangleMesh> tm = generate_triangle_mesh();
if (tm.is_null()) {
return;
}
Vector<Vector3> vertices = tm->get_vertices();
int vertices_size = vertices.size();
r_points.resize(vertices_size);
for (int i = 0; i < vertices_size; ++i) {
r_points.write[i] = vertices[i];
}
}
Vector<Vector3> Mesh::_get_faces() const {
return Variant(get_faces());
}
Vector<Face3> Mesh::get_faces() const {
Ref<TriangleMesh> tm = generate_triangle_mesh();
if (tm.is_valid()) {
return tm->get_faces();
}
return Vector<Face3>();
}
Vector<Face3> Mesh::get_surface_faces(int p_surface) const {
Ref<TriangleMesh> tm = generate_surface_triangle_mesh(p_surface);
if (tm.is_valid()) {
return tm->get_faces();
}
return Vector<Face3>();
}
Ref<ConvexPolygonShape3D> Mesh::create_convex_shape(bool p_clean, bool p_simplify) const {
if (p_simplify) {
Ref<MeshConvexDecompositionSettings> settings = Ref<MeshConvexDecompositionSettings>();
settings.instantiate();
settings->set_max_convex_hulls(1);
settings->set_max_concavity(1.0);
Vector<Ref<Shape3D>> decomposed = convex_decompose(settings);
if (decomposed.size() == 1) {
return decomposed[0];
} else {
ERR_PRINT("Convex shape simplification failed, falling back to simpler process.");
}
}
Vector<Vector3> vertices;
for (int i = 0; i < get_surface_count(); i++) {
Array a = surface_get_arrays(i);
ERR_FAIL_COND_V(a.is_empty(), Ref<ConvexPolygonShape3D>());
Vector<Vector3> v = a[ARRAY_VERTEX];
vertices.append_array(v);
}
Ref<ConvexPolygonShape3D> shape = memnew(ConvexPolygonShape3D);
if (p_clean) {
Geometry3D::MeshData md;
Error err = ConvexHullComputer::convex_hull(vertices, md);
if (err == OK) {
shape->set_points(md.vertices);
return shape;
} else {
ERR_PRINT("Convex shape cleaning failed, falling back to simpler process.");
}
}
shape->set_points(vertices);
return shape;
}
Ref<ConcavePolygonShape3D> Mesh::create_trimesh_shape() const {
Vector<Face3> faces = get_faces();
if (faces.size() == 0) {
return Ref<ConcavePolygonShape3D>();
}
Vector<Vector3> face_points;
face_points.resize(faces.size() * 3);
for (int i = 0; i < face_points.size(); i += 3) {
Face3 f = faces.get(i / 3);
face_points.set(i, f.vertex[0]);
face_points.set(i + 1, f.vertex[1]);
face_points.set(i + 2, f.vertex[2]);
}
Ref<ConcavePolygonShape3D> shape = memnew(ConcavePolygonShape3D);
shape->set_faces(face_points);
return shape;
}
Ref<Mesh> Mesh::create_outline(float p_margin) const {
Array arrays;
int index_accum = 0;
for (int i = 0; i < get_surface_count(); i++) {
if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) {
continue;
}
Array a = surface_get_arrays(i);
ERR_FAIL_COND_V(a.is_empty(), Ref<ArrayMesh>());
if (i == 0) {
arrays = a;
Vector<Vector3> v = a[ARRAY_VERTEX];
index_accum += v.size();
} else {
int vcount = 0;
for (int j = 0; j < arrays.size(); j++) {
if (arrays[j].get_type() == Variant::NIL || a[j].get_type() == Variant::NIL) {
//mismatch, do not use
arrays[j] = Variant();
continue;
}
switch (j) {
case ARRAY_VERTEX:
case ARRAY_NORMAL: {
Vector<Vector3> dst = arrays[j];
Vector<Vector3> src = a[j];
if (j == ARRAY_VERTEX) {
vcount = src.size();
}
if (dst.size() == 0 || src.size() == 0) {
arrays[j] = Variant();
continue;
}
dst.append_array(src);
arrays[j] = dst;
} break;
case ARRAY_TANGENT:
case ARRAY_BONES:
case ARRAY_WEIGHTS: {
Vector<real_t> dst = arrays[j];
Vector<real_t> src = a[j];
if (dst.size() == 0 || src.size() == 0) {
arrays[j] = Variant();
continue;
}
dst.append_array(src);
arrays[j] = dst;
} break;
case ARRAY_COLOR: {
Vector<Color> dst = arrays[j];
Vector<Color> src = a[j];
if (dst.size() == 0 || src.size() == 0) {
arrays[j] = Variant();
continue;
}
dst.append_array(src);
arrays[j] = dst;
} break;
case ARRAY_TEX_UV:
case ARRAY_TEX_UV2: {
Vector<Vector2> dst = arrays[j];
Vector<Vector2> src = a[j];
if (dst.size() == 0 || src.size() == 0) {
arrays[j] = Variant();
continue;
}
dst.append_array(src);
arrays[j] = dst;
} break;
case ARRAY_INDEX: {
Vector<int> dst = arrays[j];
Vector<int> src = a[j];
if (dst.size() == 0 || src.size() == 0) {
arrays[j] = Variant();
continue;
}
{
int ss = src.size();
int *w = src.ptrw();
for (int k = 0; k < ss; k++) {
w[k] += index_accum;
}
}
dst.append_array(src);
arrays[j] = dst;
index_accum += vcount;
} break;
}
}
}
}
ERR_FAIL_COND_V(arrays.size() != ARRAY_MAX, Ref<ArrayMesh>());
{
int *ir = nullptr;
Vector<int> indices = arrays[ARRAY_INDEX];
bool has_indices = false;
Vector<Vector3> vertices = arrays[ARRAY_VERTEX];
int vc = vertices.size();
ERR_FAIL_COND_V(!vc, Ref<ArrayMesh>());
Vector3 *r = vertices.ptrw();
if (indices.size()) {
ERR_FAIL_COND_V(indices.size() % 3 != 0, Ref<ArrayMesh>());
vc = indices.size();
ir = indices.ptrw();
has_indices = true;
} else {
// Ensure there are enough vertices to construct at least one triangle.
ERR_FAIL_COND_V(vertices.size() % 3 != 0, Ref<ArrayMesh>());
}
HashMap<Vector3, Vector3> normal_accum;
//fill normals with triangle normals
for (int i = 0; i < vc; i += 3) {
Vector3 t[3];
if (has_indices) {
t[0] = r[ir[i + 0]];
t[1] = r[ir[i + 1]];
t[2] = r[ir[i + 2]];
} else {
t[0] = r[i + 0];
t[1] = r[i + 1];
t[2] = r[i + 2];
}
Vector3 n = Plane(t[0], t[1], t[2]).normal;
for (int j = 0; j < 3; j++) {
HashMap<Vector3, Vector3>::Iterator E = normal_accum.find(t[j]);
if (!E) {
normal_accum[t[j]] = n;
} else {
float d = n.dot(E->value);
if (d < 1.0) {
E->value += n * (1.0 - d);
}
//E->get()+=n;
}
}
}
//normalize
for (KeyValue<Vector3, Vector3> &E : normal_accum) {
E.value.normalize();
}
//displace normals
int vc2 = vertices.size();
for (int i = 0; i < vc2; i++) {
Vector3 t = r[i];
HashMap<Vector3, Vector3>::Iterator E = normal_accum.find(t);
ERR_CONTINUE(!E);
t += E->value * p_margin;
r[i] = t;
}
arrays[ARRAY_VERTEX] = vertices;
if (!has_indices) {
Vector<int> new_indices;
new_indices.resize(vertices.size());
int *iw = new_indices.ptrw();
for (int j = 0; j < vc2; j += 3) {
iw[j] = j;
iw[j + 1] = j + 2;
iw[j + 2] = j + 1;
}
arrays[ARRAY_INDEX] = new_indices;
} else {
for (int j = 0; j < vc; j += 3) {
SWAP(ir[j + 1], ir[j + 2]);
}
arrays[ARRAY_INDEX] = indices;
}
}
Ref<ArrayMesh> newmesh = memnew(ArrayMesh);
newmesh->add_surface_from_arrays(PRIMITIVE_TRIANGLES, arrays);
return newmesh;
}
void Mesh::set_lightmap_size_hint(const Size2i &p_size) {
lightmap_size_hint = p_size;
}
Size2i Mesh::get_lightmap_size_hint() const {
return lightmap_size_hint;
}
Ref<Resource> Mesh::create_placeholder() const {
Ref<PlaceholderMesh> placeholder;
placeholder.instantiate();
placeholder->set_aabb(get_aabb());
return placeholder;
}
void Mesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_lightmap_size_hint", "size"), &Mesh::set_lightmap_size_hint);
ClassDB::bind_method(D_METHOD("get_lightmap_size_hint"), &Mesh::get_lightmap_size_hint);
ClassDB::bind_method(D_METHOD("get_aabb"), &Mesh::get_aabb);
ClassDB::bind_method(D_METHOD("get_faces"), &Mesh::_get_faces);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "lightmap_size_hint"), "set_lightmap_size_hint", "get_lightmap_size_hint");
ClassDB::bind_method(D_METHOD("get_surface_count"), &Mesh::get_surface_count);
ClassDB::bind_method(D_METHOD("surface_get_arrays", "surf_idx"), &Mesh::surface_get_arrays);
ClassDB::bind_method(D_METHOD("surface_get_blend_shape_arrays", "surf_idx"), &Mesh::surface_get_blend_shape_arrays);
ClassDB::bind_method(D_METHOD("surface_set_material", "surf_idx", "material"), &Mesh::surface_set_material);
ClassDB::bind_method(D_METHOD("surface_get_material", "surf_idx"), &Mesh::surface_get_material);
ClassDB::bind_method(D_METHOD("create_placeholder"), &Mesh::create_placeholder);
BIND_ENUM_CONSTANT(PRIMITIVE_POINTS);
BIND_ENUM_CONSTANT(PRIMITIVE_LINES);
BIND_ENUM_CONSTANT(PRIMITIVE_LINE_STRIP);
BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLES);
BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_STRIP);
BIND_ENUM_CONSTANT(ARRAY_VERTEX);
BIND_ENUM_CONSTANT(ARRAY_NORMAL);
BIND_ENUM_CONSTANT(ARRAY_TANGENT);
BIND_ENUM_CONSTANT(ARRAY_COLOR);
BIND_ENUM_CONSTANT(ARRAY_TEX_UV);
BIND_ENUM_CONSTANT(ARRAY_TEX_UV2);
BIND_ENUM_CONSTANT(ARRAY_CUSTOM0);
BIND_ENUM_CONSTANT(ARRAY_CUSTOM1);
BIND_ENUM_CONSTANT(ARRAY_CUSTOM2);
BIND_ENUM_CONSTANT(ARRAY_CUSTOM3);
BIND_ENUM_CONSTANT(ARRAY_BONES);
BIND_ENUM_CONSTANT(ARRAY_WEIGHTS);
BIND_ENUM_CONSTANT(ARRAY_INDEX);
BIND_ENUM_CONSTANT(ARRAY_MAX);
BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGBA8_UNORM);
BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGBA8_SNORM);
BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RG_HALF);
BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGBA_HALF);
BIND_ENUM_CONSTANT(ARRAY_CUSTOM_R_FLOAT);
BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RG_FLOAT);
BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGB_FLOAT);
BIND_ENUM_CONSTANT(ARRAY_CUSTOM_RGBA_FLOAT);
BIND_ENUM_CONSTANT(ARRAY_CUSTOM_MAX);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_VERTEX);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_NORMAL);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_TANGENT);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_COLOR);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_TEX_UV);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_TEX_UV2);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM0);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM1);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM2);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM3);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_BONES);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_WEIGHTS);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_INDEX);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_BLEND_SHAPE_MASK);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM_BASE);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM_BITS);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM0_SHIFT);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM1_SHIFT);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM2_SHIFT);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM3_SHIFT);
BIND_BITFIELD_FLAG(ARRAY_FORMAT_CUSTOM_MASK);
BIND_BITFIELD_FLAG(ARRAY_COMPRESS_FLAGS_BASE);
BIND_BITFIELD_FLAG(ARRAY_FLAG_USE_2D_VERTICES);
BIND_BITFIELD_FLAG(ARRAY_FLAG_USE_DYNAMIC_UPDATE);
BIND_BITFIELD_FLAG(ARRAY_FLAG_USE_8_BONE_WEIGHTS);
BIND_BITFIELD_FLAG(ARRAY_FLAG_USES_EMPTY_VERTEX_ARRAY);
BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED);
BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE);
GDVIRTUAL_BIND(_get_surface_count)
GDVIRTUAL_BIND(_surface_get_array_len, "index")
GDVIRTUAL_BIND(_surface_get_array_index_len, "index")
GDVIRTUAL_BIND(_surface_get_arrays, "index")
GDVIRTUAL_BIND(_surface_get_blend_shape_arrays, "index")
GDVIRTUAL_BIND(_surface_get_lods, "index")
GDVIRTUAL_BIND(_surface_get_format, "index")
GDVIRTUAL_BIND(_surface_get_primitive_type, "index")
GDVIRTUAL_BIND(_surface_set_material, "index", "material")
GDVIRTUAL_BIND(_surface_get_material, "index")
GDVIRTUAL_BIND(_get_blend_shape_count)
GDVIRTUAL_BIND(_get_blend_shape_name, "index")
GDVIRTUAL_BIND(_set_blend_shape_name, "index", "name")
GDVIRTUAL_BIND(_get_aabb)
}
void Mesh::clear_cache() const {
triangle_mesh.unref();
debug_lines.clear();
}
Vector<Ref<Shape3D>> Mesh::convex_decompose(const Ref<MeshConvexDecompositionSettings> &p_settings) const {
ERR_FAIL_NULL_V(convex_decomposition_function, Vector<Ref<Shape3D>>());
Ref<TriangleMesh> tm = generate_triangle_mesh();
ERR_FAIL_COND_V(!tm.is_valid(), Vector<Ref<Shape3D>>());
const Vector<TriangleMesh::Triangle> &triangles = tm->get_triangles();
int triangle_count = triangles.size();
Vector<uint32_t> indices;
{
indices.resize(triangle_count * 3);
uint32_t *w = indices.ptrw();
for (int i = 0; i < triangle_count; i++) {
for (int j = 0; j < 3; j++) {
w[i * 3 + j] = triangles[i].indices[j];
}
}
}
const Vector<Vector3> &vertices = tm->get_vertices();
int vertex_count = vertices.size();
Vector<Vector<Vector3>> decomposed = convex_decomposition_function((real_t *)vertices.ptr(), vertex_count, indices.ptr(), triangle_count, p_settings, nullptr);
Vector<Ref<Shape3D>> ret;
for (int i = 0; i < decomposed.size(); i++) {
Ref<ConvexPolygonShape3D> shape;
shape.instantiate();
shape->set_points(decomposed[i]);
ret.push_back(shape);
}
return ret;
}
int Mesh::get_builtin_bind_pose_count() const {
return 0;
}
Transform3D Mesh::get_builtin_bind_pose(int p_index) const {
return Transform3D();
}
Mesh::Mesh() {
}
enum OldArrayType {
OLD_ARRAY_VERTEX,
OLD_ARRAY_NORMAL,
OLD_ARRAY_TANGENT,
OLD_ARRAY_COLOR,
OLD_ARRAY_TEX_UV,
OLD_ARRAY_TEX_UV2,
OLD_ARRAY_BONES,
OLD_ARRAY_WEIGHTS,
OLD_ARRAY_INDEX,
OLD_ARRAY_MAX,
};
enum OldArrayFormat {
/* OLD_ARRAY FORMAT FLAGS */
OLD_ARRAY_FORMAT_VERTEX = 1 << OLD_ARRAY_VERTEX, // mandatory
OLD_ARRAY_FORMAT_NORMAL = 1 << OLD_ARRAY_NORMAL,
OLD_ARRAY_FORMAT_TANGENT = 1 << OLD_ARRAY_TANGENT,
OLD_ARRAY_FORMAT_COLOR = 1 << OLD_ARRAY_COLOR,
OLD_ARRAY_FORMAT_TEX_UV = 1 << OLD_ARRAY_TEX_UV,
OLD_ARRAY_FORMAT_TEX_UV2 = 1 << OLD_ARRAY_TEX_UV2,
OLD_ARRAY_FORMAT_BONES = 1 << OLD_ARRAY_BONES,
OLD_ARRAY_FORMAT_WEIGHTS = 1 << OLD_ARRAY_WEIGHTS,
OLD_ARRAY_FORMAT_INDEX = 1 << OLD_ARRAY_INDEX,
OLD_ARRAY_COMPRESS_BASE = (OLD_ARRAY_INDEX + 1),
OLD_ARRAY_COMPRESS_VERTEX = 1 << (OLD_ARRAY_VERTEX + OLD_ARRAY_COMPRESS_BASE), // mandatory
OLD_ARRAY_COMPRESS_NORMAL = 1 << (OLD_ARRAY_NORMAL + OLD_ARRAY_COMPRESS_BASE),
OLD_ARRAY_COMPRESS_TANGENT = 1 << (OLD_ARRAY_TANGENT + OLD_ARRAY_COMPRESS_BASE),
OLD_ARRAY_COMPRESS_COLOR = 1 << (OLD_ARRAY_COLOR + OLD_ARRAY_COMPRESS_BASE),
OLD_ARRAY_COMPRESS_TEX_UV = 1 << (OLD_ARRAY_TEX_UV + OLD_ARRAY_COMPRESS_BASE),
OLD_ARRAY_COMPRESS_TEX_UV2 = 1 << (OLD_ARRAY_TEX_UV2 + OLD_ARRAY_COMPRESS_BASE),
OLD_ARRAY_COMPRESS_BONES = 1 << (OLD_ARRAY_BONES + OLD_ARRAY_COMPRESS_BASE),
OLD_ARRAY_COMPRESS_WEIGHTS = 1 << (OLD_ARRAY_WEIGHTS + OLD_ARRAY_COMPRESS_BASE),
OLD_ARRAY_COMPRESS_INDEX = 1 << (OLD_ARRAY_INDEX + OLD_ARRAY_COMPRESS_BASE),
OLD_ARRAY_FLAG_USE_2D_VERTICES = OLD_ARRAY_COMPRESS_INDEX << 1,
OLD_ARRAY_FLAG_USE_16_BIT_BONES = OLD_ARRAY_COMPRESS_INDEX << 2,
OLD_ARRAY_FLAG_USE_DYNAMIC_UPDATE = OLD_ARRAY_COMPRESS_INDEX << 3,
OLD_ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION = OLD_ARRAY_COMPRESS_INDEX << 4,
};
#ifndef DISABLE_DEPRECATED
static Array _convert_old_array(const Array &p_old) {
Array new_array;
new_array.resize(Mesh::ARRAY_MAX);
new_array[Mesh::ARRAY_VERTEX] = p_old[OLD_ARRAY_VERTEX];
new_array[Mesh::ARRAY_NORMAL] = p_old[OLD_ARRAY_NORMAL];
new_array[Mesh::ARRAY_TANGENT] = p_old[OLD_ARRAY_TANGENT];
new_array[Mesh::ARRAY_COLOR] = p_old[OLD_ARRAY_COLOR];
new_array[Mesh::ARRAY_TEX_UV] = p_old[OLD_ARRAY_TEX_UV];
new_array[Mesh::ARRAY_TEX_UV2] = p_old[OLD_ARRAY_TEX_UV2];
new_array[Mesh::ARRAY_BONES] = p_old[OLD_ARRAY_BONES];
new_array[Mesh::ARRAY_WEIGHTS] = p_old[OLD_ARRAY_WEIGHTS];
new_array[Mesh::ARRAY_INDEX] = p_old[OLD_ARRAY_INDEX];
return new_array;