~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/intern/DerivedMesh.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
#include "BLI_blenlib.h"
47
47
#include "BLI_math.h"
48
48
#include "BLI_memarena.h"
49
 
#include "BLI_array.h"
50
49
#include "BLI_utildefines.h"
51
50
#include "BLI_linklist.h"
52
51
 
83
82
#include "GPU_extensions.h"
84
83
#include "GPU_material.h"
85
84
 
 
85
/* very slow! enable for testing only! */
 
86
// #define USE_MODIFIER_VALIDATE
 
87
 
 
88
#ifdef USE_MODIFIER_VALIDATE
 
89
#  define ASSERT_IS_VALID_DM(dm) (BLI_assert((dm == NULL) || (DM_is_valid(dm) == true)))
 
90
#else
 
91
#  define ASSERT_IS_VALID_DM(dm)
 
92
#endif
 
93
 
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);
88
96
 
89
 
///////////////////////////////////
90
 
///////////////////////////////////
 
97
 
 
98
/* -------------------------------------------------------------------- */
91
99
 
92
100
static MVert *dm_getVertArray(DerivedMesh *dm)
93
101
{
430
438
 
431
439
        int *polyindex = CustomData_get_layer(fdata, CD_ORIGINDEX);
432
440
 
433
 
        int mf_idx,
434
 
            totface = dm->getNumTessFaces(dm),
435
 
            ml_idx[4];
 
441
        const int totface = dm->getNumTessFaces(dm);
 
442
        int mf_idx;
 
443
        int ml_idx[4];
436
444
 
437
445
        /* Should never occure, but better abort than segfault! */
438
446
        if (!polyindex)
531
539
        }
532
540
 
533
541
        /* copy texture space */
534
 
        BKE_mesh_texspace_copy_from_object(&tmp, ob);
 
542
        if (ob) {
 
543
                BKE_mesh_texspace_copy_from_object(&tmp, ob);
 
544
        }
535
545
        
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);
879
889
                
880
890
                dm = modwrap_applyModifier(md, ob, tdm, 0);
 
891
                ASSERT_IS_VALID_DM(dm);
881
892
 
882
893
                if (tdm != dm) tdm->release(tdm);
883
894
        }
1439
1450
        /* XXX Same as above... For now, only weights preview in WPaint mode. */
1440
1451
        const int do_mod_wmcol = do_init_wmcol;
1441
1452
 
 
1453
        VirtualModifierData virtualModifierData;
 
1454
 
1442
1455
        ModifierApplyFlag app_flags = useRenderParams ? MOD_APPLY_RENDER : 0;
1443
1456
        ModifierApplyFlag deform_app_flags = app_flags;
1444
1457
        if (useCache)
1450
1463
                has_multires = 0;
1451
1464
 
1452
1465
        if (!skipVirtualArmature) {
1453
 
                firstmd = modifiers_getVirtualModifierList(ob);
 
1466
                firstmd = modifiers_getVirtualModifierList(ob, &virtualModifierData);
1454
1467
        }
1455
1468
        else {
1456
1469
                /* game engine exception */
1647
1660
                        }
1648
1661
                        else {
1649
1662
                                dm = CDDM_from_mesh(me, ob);
 
1663
                                ASSERT_IS_VALID_DM(dm);
1650
1664
 
1651
1665
                                if (build_shapekey_layers)
1652
1666
                                        add_shapekey_layers(dm, me, ob);
1671
1685
                                        DM_add_edge_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
1672
1686
                                        DM_add_poly_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
1673
1687
 
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)
1675
1689
                                        {
1676
1690
#pragma omp section
1677
1691
                                                { range_vn_i(DM_get_vert_data_layer(dm, CD_ORIGINDEX), dm->numVertData, 0); }
1704
1718
                        }
1705
1719
 
1706
1720
                        ndm = modwrap_applyModifier(md, ob, dm, app_flags);
 
1721
                        ASSERT_IS_VALID_DM(ndm);
1707
1722
 
1708
1723
                        if (ndm) {
1709
1724
                                /* if the modifier returned a new dm, release the old one */
1730
1745
                                                  mti->requiredDataMask(ob, md) : 0));
1731
1746
 
1732
1747
                                ndm = modwrap_applyModifier(md, ob, orcodm, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO);
 
1748
                                ASSERT_IS_VALID_DM(ndm);
1733
1749
 
1734
1750
                                if (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);
1748
1764
 
1749
1765
                                ndm = modwrap_applyModifier(md, ob, clothorcodm, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO);
 
1766
                                ASSERT_IS_VALID_DM(ndm);
1750
1767
 
1751
1768
                                if (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;
1963
1981
 
1964
1982
        modifiers_clearErrors(ob);
1965
1983
 
1968
1986
        }
1969
1987
 
1970
1988
        dm = NULL;
1971
 
        md = modifiers_getVirtualModifierList(ob);
 
1989
        md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
1972
1990
 
1973
1991
        /* copied from mesh_calc_modifiers */
1974
1992
        if (do_mod_wmcol) {
2048
2066
                        }
2049
2067
                        else {
2050
2068
                                dm = CDDM_from_editbmesh(em, FALSE, FALSE);
 
2069
                                ASSERT_IS_VALID_DM(dm);
2051
2070
 
2052
2071
                                if (deformedVerts) {
2053
2072
                                        CDDM_apply_vert_coords(dm, deformedVerts);
2067
2086
                                mask &= ~CD_MASK_ORCO;
2068
2087
                                DM_set_only_copy(orcodm, mask | CD_MASK_ORIGINDEX);
2069
2088
 
2070
 
                                if (mti->applyModifierEM)
 
2089
                                if (mti->applyModifierEM) {
2071
2090
                                        ndm = modwrap_applyModifierEM(md, ob, em, orcodm, MOD_APPLY_ORCO);
2072
 
                                else
 
2091
                                }
 
2092
                                else {
2073
2093
                                        ndm = modwrap_applyModifier(md, ob, orcodm, MOD_APPLY_ORCO);
 
2094
                                }
 
2095
                                ASSERT_IS_VALID_DM(ndm);
2074
2096
 
2075
2097
                                if (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);
2097
2119
                        else
2098
2120
                                ndm = modwrap_applyModifier(md, ob, dm, MOD_APPLY_USECACHE);
 
2121
                        ASSERT_IS_VALID_DM(ndm);
2099
2122
 
2100
2123
                        if (ndm) {
2101
2124
                                if (dm && dm != ndm)
2634
2657
        
2635
2658
        /* new computation method */
2636
2659
        {
2637
 
                SGLSLMeshToTangent mesh2tangent = {0};
2638
 
                SMikkTSpaceContext sContext = {0};
2639
 
                SMikkTSpaceInterface sInterface = {0};
 
2660
                SGLSLMeshToTangent mesh2tangent = {NULL};
 
2661
                SMikkTSpaceContext sContext = {NULL};
 
2662
                SMikkTSpaceInterface sInterface = {NULL};
2640
2663
 
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;
2740
 
                                                float vtmp[3];
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);
 
2763
 
 
2764
                                                pos_len_diag0 = len_squared_v3v3(verts[2], verts[0]);
 
2765
                                                pos_len_diag1 = len_squared_v3v3(verts[3], verts[1]);
2745
2766
 
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;
2751
2772
 
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]);
2756
2775
 
2757
2776
                                                        if (tex_len_diag1 < tex_len_diag0) {
2758
2777
                                                                offs = 1; /* alter split */
2761
2780
                                        }
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 };
2765
2784
                                                int t;
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);
2782
2801
 
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 */
2785
2804
 
2786
2805
                                                                nr_accumulated++;
2787
2806
                                                                dsum += (double)(fsurf_ratio);
3103
3122
                }
3104
3123
        }
3105
3124
        else {
3106
 
                printf("%s: Error during creation polygon infos\n", __func__);
 
3125
                printf("Navmesh: Unable to generate valid Navmesh");
3107
3126
        }
3108
3127
 
3109
3128
        /* clean up */
3261
3280
        printf("}\n");
3262
3281
}
3263
3282
 
 
3283
bool DM_is_valid(DerivedMesh *dm)
 
3284
{
 
3285
        const bool do_verbose = true;
 
3286
        const bool do_fixes = false;
 
3287
 
 
3288
        bool is_valid = true;
 
3289
        bool is_change = true;
 
3290
 
 
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);
 
3298
 
 
3299
        is_valid &= BKE_mesh_validate_arrays(
 
3300
                NULL,
 
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);
 
3308
 
 
3309
        BLI_assert(is_change == false);
 
3310
 
 
3311
        return is_valid;
 
3312
}
 
3313
 
3264
3314
#endif /* NDEBUG */