83
82
#include "GPU_extensions.h"
84
83
#include "GPU_material.h"
85
/* very slow! enable for testing only! */
86
// #define USE_MODIFIER_VALIDATE
88
#ifdef USE_MODIFIER_VALIDATE
89
# define ASSERT_IS_VALID_DM(dm) (BLI_assert((dm == NULL) || (DM_is_valid(dm) == true)))
91
# define ASSERT_IS_VALID_DM(dm)
86
94
static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *ob);
87
95
static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid);
89
///////////////////////////////////
90
///////////////////////////////////
98
/* -------------------------------------------------------------------- */
92
100
static MVert *dm_getVertArray(DerivedMesh *dm)
431
439
int *polyindex = CustomData_get_layer(fdata, CD_ORIGINDEX);
434
totface = dm->getNumTessFaces(dm),
441
const int totface = dm->getNumTessFaces(dm);
437
445
/* Should never occure, but better abort than segfault! */
533
541
/* copy texture space */
534
BKE_mesh_texspace_copy_from_object(&tmp, ob);
543
BKE_mesh_texspace_copy_from_object(&tmp, ob);
536
546
/* not all DerivedMeshes store their verts/edges/faces in CustomData, so
537
547
* we set them here in case they are missing */
878
888
add_shapekey_layers(tdm, me, ob);
880
890
dm = modwrap_applyModifier(md, ob, tdm, 0);
891
ASSERT_IS_VALID_DM(dm);
882
893
if (tdm != dm) tdm->release(tdm);
1439
1450
/* XXX Same as above... For now, only weights preview in WPaint mode. */
1440
1451
const int do_mod_wmcol = do_init_wmcol;
1453
VirtualModifierData virtualModifierData;
1442
1455
ModifierApplyFlag app_flags = useRenderParams ? MOD_APPLY_RENDER : 0;
1443
1456
ModifierApplyFlag deform_app_flags = app_flags;
1450
1463
has_multires = 0;
1452
1465
if (!skipVirtualArmature) {
1453
firstmd = modifiers_getVirtualModifierList(ob);
1466
firstmd = modifiers_getVirtualModifierList(ob, &virtualModifierData);
1456
1469
/* game engine exception */
1671
1685
DM_add_edge_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
1672
1686
DM_add_poly_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
1674
#pragma omp parallel sections if (dm->numVertData + dm->numEdgeData + dm->numPolyData >= DM_OMP_LIMIT)
1688
#pragma omp parallel sections if (dm->numVertData + dm->numEdgeData + dm->numPolyData >= BKE_MESH_OMP_LIMIT)
1676
1690
#pragma omp section
1677
1691
{ range_vn_i(DM_get_vert_data_layer(dm, CD_ORIGINDEX), dm->numVertData, 0); }
1730
1745
mti->requiredDataMask(ob, md) : 0));
1732
1747
ndm = modwrap_applyModifier(md, ob, orcodm, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO);
1748
ASSERT_IS_VALID_DM(ndm);
1735
1751
/* if the modifier returned a new dm, release the old one */
1747
1763
DM_set_only_copy(clothorcodm, nextmask | CD_MASK_ORIGINDEX);
1749
1765
ndm = modwrap_applyModifier(md, ob, clothorcodm, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO);
1766
ASSERT_IS_VALID_DM(ndm);
1752
1769
/* if the modifier returned a new dm, release the old one */
1960
1977
int do_init_wmcol = ((((Mesh *)ob->data)->drawflag & ME_DRAWEIGHT) && !do_final_wmcol);
1961
1978
int do_init_statvis = ((((Mesh *)ob->data)->drawflag & ME_DRAW_STATVIS) && !do_init_wmcol);
1962
1979
const int do_mod_wmcol = do_init_wmcol;
1980
VirtualModifierData virtualModifierData;
1964
1982
modifiers_clearErrors(ob);
2067
2086
mask &= ~CD_MASK_ORCO;
2068
2087
DM_set_only_copy(orcodm, mask | CD_MASK_ORIGINDEX);
2070
if (mti->applyModifierEM)
2089
if (mti->applyModifierEM) {
2071
2090
ndm = modwrap_applyModifierEM(md, ob, em, orcodm, MOD_APPLY_ORCO);
2073
2093
ndm = modwrap_applyModifier(md, ob, orcodm, MOD_APPLY_ORCO);
2095
ASSERT_IS_VALID_DM(ndm);
2076
2098
/* if the modifier returned a new dm, release the old one */
2096
2118
ndm = modwrap_applyModifierEM(md, ob, em, dm, MOD_APPLY_USECACHE);
2098
2120
ndm = modwrap_applyModifier(md, ob, dm, MOD_APPLY_USECACHE);
2121
ASSERT_IS_VALID_DM(ndm);
2101
2124
if (dm && dm != ndm)
2635
2658
/* new computation method */
2637
SGLSLMeshToTangent mesh2tangent = {0};
2638
SMikkTSpaceContext sContext = {0};
2639
SMikkTSpaceInterface sInterface = {0};
2660
SGLSLMeshToTangent mesh2tangent = {NULL};
2661
SMikkTSpaceContext sContext = {NULL};
2662
SMikkTSpaceInterface sInterface = {NULL};
2641
2664
mesh2tangent.precomputedFaceNormals = nors;
2642
2665
mesh2tangent.mtface = mtface;
2737
2760
int offs = 0; /* initial triangulation is 0,1,2 and 0, 2, 3 */
2738
2761
if (nr_verts == 4) {
2739
2762
float pos_len_diag0, pos_len_diag1;
2741
sub_v3_v3v3(vtmp, verts[2], verts[0]);
2742
pos_len_diag0 = dot_v3v3(vtmp, vtmp);
2743
sub_v3_v3v3(vtmp, verts[3], verts[1]);
2744
pos_len_diag1 = dot_v3v3(vtmp, vtmp);
2764
pos_len_diag0 = len_squared_v3v3(verts[2], verts[0]);
2765
pos_len_diag1 = len_squared_v3v3(verts[3], verts[1]);
2746
2767
if (pos_len_diag1 < pos_len_diag0) {
2747
2768
offs = 1; // alter split
2749
2770
else if (pos_len_diag0 == pos_len_diag1) { /* do UV check instead */
2750
2771
float tex_len_diag0, tex_len_diag1;
2752
sub_v2_v2v2(vtmp, tex_coords[2], tex_coords[0]);
2753
tex_len_diag0 = dot_v2v2(vtmp, vtmp);
2754
sub_v2_v2v2(vtmp, tex_coords[3], tex_coords[1]);
2755
tex_len_diag1 = dot_v2v2(vtmp, vtmp);
2773
tex_len_diag0 = len_squared_v2v2(tex_coords[2], tex_coords[0]);
2774
tex_len_diag1 = len_squared_v2v2(tex_coords[3], tex_coords[1]);
2757
2776
if (tex_len_diag1 < tex_len_diag0) {
2758
2777
offs = 1; /* alter split */
2762
2781
nr_tris_to_pile = nr_verts - 2;
2763
2782
if (nr_tris_to_pile == 1 || nr_tris_to_pile == 2) {
2764
const int indices[] = {offs + 0, offs + 1, offs + 2, offs + 0, offs + 2, (offs + 3) & 0x3 };
2783
const int indices[6] = {offs + 0, offs + 1, offs + 2, offs + 0, offs + 2, (offs + 3) & 0x3 };
2766
2785
for (t = 0; t < nr_tris_to_pile; t++) {
2767
2786
float f2x_area_uv;
2781
2800
cross_v3_v3v3(norm, v0, v1);
2783
2802
f2x_surf_area = len_v3(norm);
2784
fsurf_ratio = f2x_surf_area / f2x_area_uv; // tri area divided by texture area
2803
fsurf_ratio = f2x_surf_area / f2x_area_uv; /* tri area divided by texture area */
2786
2805
nr_accumulated++;
2787
2806
dsum += (double)(fsurf_ratio);
3283
bool DM_is_valid(DerivedMesh *dm)
3285
const bool do_verbose = true;
3286
const bool do_fixes = false;
3288
bool is_valid = true;
3289
bool is_change = true;
3291
is_valid &= BKE_mesh_validate_all_customdata(
3292
dm->getVertDataLayout(dm),
3293
dm->getEdgeDataLayout(dm),
3294
dm->getLoopDataLayout(dm),
3295
dm->getPolyDataLayout(dm),
3296
0, /* setting mask here isn't useful, gives false positives */
3297
do_verbose, do_fixes, &is_change);
3299
is_valid &= BKE_mesh_validate_arrays(
3301
dm->getVertArray(dm), dm->getNumVerts(dm),
3302
dm->getEdgeArray(dm), dm->getNumEdges(dm),
3303
dm->getTessFaceArray(dm), dm->getNumTessFaces(dm),
3304
dm->getLoopArray(dm), dm->getNumLoops(dm),
3305
dm->getPolyArray(dm), dm->getNumPolys(dm),
3306
dm->getVertDataArray(dm, CD_MDEFORMVERT),
3307
do_verbose, do_fixes, &is_change);
3309
BLI_assert(is_change == false);
3264
3314
#endif /* NDEBUG */