~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
* $Id: modifier.c 14856 2008-05-15 20:07:07Z blendix $
 
2
* $Id: modifier.c 16966 2008-10-08 01:04:07Z theeth $
3
3
*
4
4
* ***** BEGIN GPL LICENSE BLOCK *****
5
5
*
40
40
#include "stdarg.h"
41
41
#include "math.h"
42
42
#include "float.h"
 
43
#include "ctype.h"
43
44
 
44
45
#include "BLI_arithb.h"
45
46
#include "BLI_blenlib.h"
 
47
#include "BLI_kdopbvh.h"
46
48
#include "BLI_kdtree.h"
47
49
#include "BLI_linklist.h"
48
50
#include "BLI_rand.h"
52
54
 
53
55
#include "MEM_guardedalloc.h"
54
56
 
 
57
#include "DNA_action_types.h"
55
58
#include "DNA_armature_types.h"
 
59
#include "DNA_camera_types.h"
56
60
#include "DNA_cloth_types.h"
 
61
#include "DNA_curve_types.h"
57
62
#include "DNA_effect_types.h"
58
63
#include "DNA_material_types.h"
59
64
#include "DNA_mesh_types.h"
64
69
#include "DNA_particle_types.h"
65
70
#include "DNA_scene_types.h"
66
71
#include "DNA_texture_types.h"
67
 
#include "DNA_curve_types.h"
68
 
#include "DNA_camera_types.h"
69
72
 
70
73
#include "BLI_editVert.h"
71
74
 
75
78
#include "BKE_main.h"
76
79
#include "BKE_anim.h"
77
80
#include "BKE_bad_level_calls.h"
 
81
#include "BKE_bmesh.h"
 
82
#include "BKE_booleanops.h"
78
83
#include "BKE_cloth.h"
 
84
#include "BKE_collision.h"
 
85
#include "BKE_cdderivedmesh.h"
79
86
#include "BKE_curve.h"
80
87
#include "BKE_customdata.h"
81
 
#include "BKE_global.h"
82
 
#include "BKE_cdderivedmesh.h"
83
88
#include "BKE_DerivedMesh.h"
84
 
#include "BKE_booleanops.h"
85
89
#include "BKE_displist.h"
86
 
#include "BKE_modifier.h"
 
90
#include "BKE_fluidsim.h"
 
91
#include "BKE_global.h"
87
92
#include "BKE_lattice.h"
88
93
#include "BKE_library.h"
89
 
#include "BKE_subsurf.h"
 
94
#include "BKE_material.h"
 
95
#include "BKE_mesh.h"
 
96
#include "BKE_modifier.h"
90
97
#include "BKE_object.h"
91
 
#include "BKE_mesh.h"
92
 
#include "BKE_softbody.h"
93
 
#include "BKE_cloth.h"
94
 
#include "BKE_material.h"
95
98
#include "BKE_particle.h"
96
99
#include "BKE_pointcache.h"
 
100
#include "BKE_softbody.h"
 
101
#include "BKE_subsurf.h"
 
102
#include "BKE_texture.h"
97
103
#include "BKE_utildefines.h"
 
104
 
98
105
#include "depsgraph_private.h"
99
 
#include "BKE_bmesh.h"
 
106
#include "BKE_deform.h"
 
107
#include "BKE_shrinkwrap.h"
 
108
#include "BKE_simple_deform.h"
100
109
 
101
110
#include "LOD_DependKludge.h"
102
111
#include "LOD_decimation.h"
580
589
                   return result;
581
590
}
582
591
 
 
592
/* Mask */
 
593
 
 
594
static void maskModifier_copyData(ModifierData *md, ModifierData *target)
 
595
{
 
596
        MaskModifierData *mmd = (MaskModifierData*) md;
 
597
        MaskModifierData *tmmd = (MaskModifierData*) target;
 
598
        
 
599
        strcpy(tmmd->vgroup, mmd->vgroup);
 
600
}
 
601
 
 
602
static CustomDataMask maskModifier_requiredDataMask(ModifierData *md)
 
603
{
 
604
        return (1 << CD_MDEFORMVERT);
 
605
}
 
606
 
 
607
static void maskModifier_foreachObjectLink(
 
608
                                              ModifierData *md, Object *ob,
 
609
           void (*walk)(void *userData, Object *ob, Object **obpoin),
 
610
                  void *userData)
 
611
{
 
612
        MaskModifierData *mmd = (MaskModifierData *)md;
 
613
        walk(userData, ob, &mmd->ob_arm);
 
614
}
 
615
 
 
616
static void maskModifier_updateDepgraph(ModifierData *md, DagForest *forest,
 
617
                                           Object *ob, DagNode *obNode)
 
618
{
 
619
        MaskModifierData *mmd = (MaskModifierData *)md;
 
620
 
 
621
        if (mmd->ob_arm) 
 
622
        {
 
623
                DagNode *armNode = dag_get_node(forest, mmd->ob_arm);
 
624
                
 
625
                dag_add_relation(forest, armNode, obNode,
 
626
                                DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Mask Modifier");
 
627
        }
 
628
}
 
629
 
 
630
static DerivedMesh *maskModifier_applyModifier(ModifierData *md, Object *ob,
 
631
                DerivedMesh *derivedData,
 
632
  int useRenderParams, int isFinalCalc)
 
633
{
 
634
        MaskModifierData *mmd= (MaskModifierData *)md;
 
635
        DerivedMesh *dm= derivedData, *result= NULL;
 
636
        GHash *vertHash=NULL, *edgeHash, *faceHash;
 
637
        GHashIterator *hashIter;
 
638
        MDeformVert *dvert= NULL;
 
639
        int numFaces=0, numEdges=0, numVerts=0;
 
640
        int maxVerts, maxEdges, maxFaces;
 
641
        int i;
 
642
        
 
643
        /* Overview of Method:
 
644
         *      1. Get the vertices that are in the vertexgroup of interest 
 
645
         *      2. Filter out unwanted geometry (i.e. not in vertexgroup), by populating mappings with new vs old indices
 
646
         *      3. Make a new mesh containing only the mapping data
 
647
         */
 
648
        
 
649
        /* get original number of verts, edges, and faces */
 
650
        maxVerts= dm->getNumVerts(dm);
 
651
        maxEdges= dm->getNumEdges(dm);
 
652
        maxFaces= dm->getNumFaces(dm);
 
653
        
 
654
        /* check if we can just return the original mesh 
 
655
         *      - must have verts and therefore verts assigned to vgroups to do anything useful
 
656
         */
 
657
        if ( !(ELEM(mmd->mode, MOD_MASK_MODE_ARM, MOD_MASK_MODE_VGROUP)) ||
 
658
                 (maxVerts == 0) || (ob->defbase.first == NULL) )
 
659
        {
 
660
                return derivedData;
 
661
        }
 
662
        
 
663
        /* if mode is to use selected armature bones, aggregate the bone groups */
 
664
        if (mmd->mode == MOD_MASK_MODE_ARM) /* --- using selected bones --- */
 
665
        {
 
666
                GHash *vgroupHash, *boneHash;
 
667
                Object *oba= mmd->ob_arm;
 
668
                bPoseChannel *pchan;
 
669
                bDeformGroup *def;
 
670
                
 
671
                /* check that there is armature object with bones to use, otherwise return original mesh */
 
672
                if (ELEM(NULL, mmd->ob_arm, mmd->ob_arm->pose))
 
673
                        return derivedData;             
 
674
                
 
675
                /* hashes for finding mapping of:
 
676
                 *      - vgroups to indicies -> vgroupHash  (string, int)
 
677
                 *      - bones to vgroup indices -> boneHash (index of vgroup, dummy)
 
678
                 */
 
679
                vgroupHash= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp);
 
680
                boneHash= BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp);
 
681
                
 
682
                /* build mapping of names of vertex groups to indices */
 
683
                for (i = 0, def = ob->defbase.first; def; def = def->next, i++) 
 
684
                        BLI_ghash_insert(vgroupHash, def->name, SET_INT_IN_POINTER(i));
 
685
                
 
686
                /* get selected-posechannel <-> vertexgroup index mapping */
 
687
                for (pchan= oba->pose->chanbase.first; pchan; pchan= pchan->next) 
 
688
                {
 
689
                        /* check if bone is selected */
 
690
                        // TODO: include checks for visibility too?
 
691
                        // FIXME: the depsgraph needs extensions to make this work in realtime...
 
692
                        if ( (pchan->bone) && (pchan->bone->flag & BONE_SELECTED) ) 
 
693
                        {
 
694
                                /* check if hash has group for this bone */
 
695
                                if (BLI_ghash_haskey(vgroupHash, pchan->name)) 
 
696
                                {
 
697
                                        int defgrp_index= GET_INT_FROM_POINTER(BLI_ghash_lookup(vgroupHash, pchan->name));
 
698
                                        
 
699
                                        /* add index to hash (store under key only) */
 
700
                                        BLI_ghash_insert(boneHash, SET_INT_IN_POINTER(defgrp_index), pchan);
 
701
                                }
 
702
                        }
 
703
                }
 
704
                
 
705
                /* if no bones selected, free hashes and return original mesh */
 
706
                if (BLI_ghash_size(boneHash) == 0)
 
707
                {
 
708
                        BLI_ghash_free(vgroupHash, NULL, NULL);
 
709
                        BLI_ghash_free(boneHash, NULL, NULL);
 
710
                        
 
711
                        return derivedData;
 
712
                }
 
713
                
 
714
                /* repeat the previous check, but for dverts */
 
715
                dvert= dm->getVertDataArray(dm, CD_MDEFORMVERT);
 
716
                if (dvert == NULL)
 
717
                {
 
718
                        BLI_ghash_free(vgroupHash, NULL, NULL);
 
719
                        BLI_ghash_free(boneHash, NULL, NULL);
 
720
                        
 
721
                        return derivedData;
 
722
                }
 
723
                
 
724
                /* hashes for quickly providing a mapping from old to new - use key=oldindex, value=newindex */
 
725
                vertHash= BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp);
 
726
                
 
727
                /* add vertices which exist in vertexgroups into vertHash for filtering */
 
728
                for (i = 0; i < maxVerts; i++) 
 
729
                {
 
730
                        MDeformWeight *def_weight = NULL;
 
731
                        int j;
 
732
                        
 
733
                        for (j= 0; j < dvert[i].totweight; j++) 
 
734
                        {
 
735
                                if (BLI_ghash_haskey(boneHash, SET_INT_IN_POINTER(dvert[i].dw[j].def_nr))) 
 
736
                                {
 
737
                                        def_weight = &dvert[i].dw[j];
 
738
                                        break;
 
739
                                }
 
740
                        }
 
741
                        
 
742
                        /* check if include vert in vertHash */
 
743
                        if (mmd->flag & MOD_MASK_INV) {
 
744
                                /* if this vert is in the vgroup, don't include it in vertHash */
 
745
                                if (def_weight) continue;
 
746
                        }
 
747
                        else {
 
748
                                /* if this vert isn't in the vgroup, don't include it in vertHash */
 
749
                                if (!def_weight) continue;
 
750
                        }
 
751
                        
 
752
                        /* add to ghash for verts (numVerts acts as counter for mapping) */
 
753
                        BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(i), SET_INT_IN_POINTER(numVerts));
 
754
                        numVerts++;
 
755
                }
 
756
                
 
757
                /* free temp hashes */
 
758
                BLI_ghash_free(vgroupHash, NULL, NULL);
 
759
                BLI_ghash_free(boneHash, NULL, NULL);
 
760
        }
 
761
        else            /* --- Using Nominated VertexGroup only --- */ 
 
762
        {
 
763
                int defgrp_index = -1;
 
764
                
 
765
                /* get index of vertex group */
 
766
                if (mmd->vgroup[0]) 
 
767
                {
 
768
                        bDeformGroup *def;
 
769
                        
 
770
                        /* find index by comparing names - SLOW... */
 
771
                        for (i = 0, def = ob->defbase.first; def; def = def->next, i++) 
 
772
                        {
 
773
                                if (!strcmp(def->name, mmd->vgroup)) 
 
774
                                {
 
775
                                        defgrp_index = i;
 
776
                                        break;
 
777
                                }
 
778
                        }
 
779
                }
 
780
                
 
781
                /* get dverts */
 
782
                if (defgrp_index >= 0)
 
783
                        dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
 
784
                        
 
785
                /* if no vgroup (i.e. dverts) found, return the initial mesh */
 
786
                if ((defgrp_index < 0) || (dvert == NULL))
 
787
                        return dm;
 
788
                        
 
789
                /* hashes for quickly providing a mapping from old to new - use key=oldindex, value=newindex */
 
790
                vertHash= BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp);
 
791
                
 
792
                /* add vertices which exist in vertexgroup into ghash for filtering */
 
793
                for (i = 0; i < maxVerts; i++) 
 
794
                {
 
795
                        MDeformWeight *def_weight = NULL;
 
796
                        int j;
 
797
                        
 
798
                        for (j= 0; j < dvert[i].totweight; j++) 
 
799
                        {
 
800
                                if (dvert[i].dw[j].def_nr == defgrp_index) 
 
801
                                {
 
802
                                        def_weight = &dvert[i].dw[j];
 
803
                                        break;
 
804
                                }
 
805
                        }
 
806
                        
 
807
                        /* check if include vert in vertHash */
 
808
                        if (mmd->flag & MOD_MASK_INV) {
 
809
                                /* if this vert is in the vgroup, don't include it in vertHash */
 
810
                                if (def_weight) continue;
 
811
                        }
 
812
                        else {
 
813
                                /* if this vert isn't in the vgroup, don't include it in vertHash */
 
814
                                if (!def_weight) continue;
 
815
                        }
 
816
                        
 
817
                        /* add to ghash for verts (numVerts acts as counter for mapping) */
 
818
                        BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(i), SET_INT_IN_POINTER(numVerts));
 
819
                        numVerts++;
 
820
                }
 
821
        }
 
822
        
 
823
        /* hashes for quickly providing a mapping from old to new - use key=oldindex, value=newindex */
 
824
        edgeHash= BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp);
 
825
        faceHash= BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp);
 
826
        
 
827
        /* loop over edges and faces, and do the same thing to 
 
828
         * ensure that they only reference existing verts 
 
829
         */
 
830
        for (i = 0; i < maxEdges; i++) 
 
831
        {
 
832
                MEdge me;
 
833
                dm->getEdge(dm, i, &me);
 
834
                
 
835
                /* only add if both verts will be in new mesh */
 
836
                if ( BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v1)) &&
 
837
                         BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me.v2)) )
 
838
                {
 
839
                        BLI_ghash_insert(edgeHash, SET_INT_IN_POINTER(i), SET_INT_IN_POINTER(numEdges));
 
840
                        numEdges++;
 
841
                }
 
842
        }
 
843
        for (i = 0; i < maxFaces; i++) 
 
844
        {
 
845
                MFace mf;
 
846
                dm->getFace(dm, i, &mf);
 
847
                
 
848
                /* all verts must be available */
 
849
                if ( BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v1)) &&
 
850
                         BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v2)) &&
 
851
                         BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v3)) &&
 
852
                        (mf.v4==0 || BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(mf.v4))) )
 
853
                {
 
854
                        BLI_ghash_insert(faceHash, SET_INT_IN_POINTER(i), SET_INT_IN_POINTER(numFaces));
 
855
                        numFaces++;
 
856
                }
 
857
        }
 
858
        
 
859
        
 
860
        /* now we know the number of verts, edges and faces, 
 
861
         * we can create the new (reduced) mesh
 
862
         */
 
863
        result = CDDM_from_template(dm, numVerts, numEdges, numFaces);
 
864
        
 
865
        
 
866
        /* using ghash-iterators, map data into new mesh */
 
867
                /* vertices */
 
868
        for ( hashIter = BLI_ghashIterator_new(vertHash);
 
869
                  !BLI_ghashIterator_isDone(hashIter);
 
870
                  BLI_ghashIterator_step(hashIter) ) 
 
871
        {
 
872
                MVert source;
 
873
                MVert *dest;
 
874
                int oldIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(hashIter));
 
875
                int newIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(hashIter));
 
876
                
 
877
                dm->getVert(dm, oldIndex, &source);
 
878
                dest = CDDM_get_vert(result, newIndex);
 
879
                
 
880
                DM_copy_vert_data(dm, result, oldIndex, newIndex, 1);
 
881
                *dest = source;
 
882
        }
 
883
        BLI_ghashIterator_free(hashIter);
 
884
                
 
885
                /* edges */
 
886
        for ( hashIter = BLI_ghashIterator_new(edgeHash);
 
887
                  !BLI_ghashIterator_isDone(hashIter);
 
888
                  BLI_ghashIterator_step(hashIter) ) 
 
889
        {
 
890
                MEdge source;
 
891
                MEdge *dest;
 
892
                int oldIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(hashIter));
 
893
                int newIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(hashIter));
 
894
                
 
895
                dm->getEdge(dm, oldIndex, &source);
 
896
                dest = CDDM_get_edge(result, newIndex);
 
897
                
 
898
                source.v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v1)));
 
899
                source.v2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v2)));
 
900
                
 
901
                DM_copy_edge_data(dm, result, oldIndex, newIndex, 1);
 
902
                *dest = source;
 
903
        }
 
904
        BLI_ghashIterator_free(hashIter);
 
905
        
 
906
                /* faces */
 
907
        for ( hashIter = BLI_ghashIterator_new(faceHash);
 
908
                  !BLI_ghashIterator_isDone(hashIter);
 
909
                  BLI_ghashIterator_step(hashIter) ) 
 
910
        {
 
911
                MFace source;
 
912
                MFace *dest;
 
913
                int oldIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(hashIter));
 
914
                int newIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(hashIter));
 
915
                int orig_v4;
 
916
                
 
917
                dm->getFace(dm, oldIndex, &source);
 
918
                dest = CDDM_get_face(result, newIndex);
 
919
                
 
920
                orig_v4 = source.v4;
 
921
                
 
922
                source.v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v1)));
 
923
                source.v2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v2)));
 
924
                source.v3 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v3)));
 
925
                if (source.v4)
 
926
                   source.v4 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v4)));
 
927
                
 
928
                DM_copy_face_data(dm, result, oldIndex, newIndex, 1);
 
929
                *dest = source;
 
930
                
 
931
                test_index_face(dest, &result->faceData, newIndex, (orig_v4 ? 4 : 3));
 
932
        }
 
933
        BLI_ghashIterator_free(hashIter);
 
934
        
 
935
        /* recalculate normals */
 
936
        CDDM_calc_normals(result);
 
937
        
 
938
        /* free hashes */
 
939
        BLI_ghash_free(vertHash, NULL, NULL);
 
940
        BLI_ghash_free(edgeHash, NULL, NULL);
 
941
        BLI_ghash_free(faceHash, NULL, NULL);
 
942
        
 
943
        /* return the new mesh */
 
944
        return result;
 
945
}
 
946
 
583
947
/* Array */
584
948
/* Array modifier: duplicates the object multiple times along an axis
585
949
*/
787
1151
        if(amd->fit_type == MOD_ARR_FITCURVE && amd->curve_ob) {
788
1152
                Curve *cu = amd->curve_ob->data;
789
1153
                if(cu) {
 
1154
                        float tmp_mat[3][3];
 
1155
                        float scale;
 
1156
                        
 
1157
                        object_to_mat3(amd->curve_ob, tmp_mat);
 
1158
                        scale = Mat3ToScalef(tmp_mat);
 
1159
                                
790
1160
                        if(!cu->path) {
791
1161
                                cu->flag |= CU_PATH; // needed for path & bevlist
792
1162
                                makeDispListCurveTypes(amd->curve_ob, 0);
793
1163
                        }
794
1164
                        if(cu->path)
795
 
                                length = cu->path->totdist;
 
1165
                                length = scale*cu->path->totdist;
796
1166
                }
797
1167
        }
798
1168
 
1127
1497
                                  mface[numFaces].v1 = vert_map[mface[numFaces].v1];
1128
1498
                                  mface[numFaces].v2 = vert_map[mface[numFaces].v2];
1129
1499
                                  mface[numFaces].v3 = vert_map[mface[numFaces].v3];
1130
 
                                  if(mface[numFaces].v4)
 
1500
                                  if(mface[numFaces].v4) {
1131
1501
                                          mface[numFaces].v4 = vert_map[mface[numFaces].v4];
 
1502
 
 
1503
                                          test_index_face(&mface[numFaces], &result->faceData,
 
1504
                                                          numFaces, 4);
 
1505
                                  }
 
1506
                                  else
 
1507
                                  {
 
1508
                                          test_index_face(&mface[numFaces], &result->faceData,
 
1509
                                                          numFaces, 3);
 
1510
                                  }
 
1511
 
1132
1512
                                  origindex[numFaces] = ORIGINDEX_NONE;
1133
1513
 
1134
1514
                                  numFaces++;
1218
1598
                                  mface[numFaces].v1 = vert_map[mface[numFaces].v1];
1219
1599
                                  mface[numFaces].v2 = vert_map[mface[numFaces].v2];
1220
1600
                                  mface[numFaces].v3 = vert_map[mface[numFaces].v3];
1221
 
                                  if(mface[numFaces].v4)
 
1601
                                  if(mface[numFaces].v4) {
1222
1602
                                          mface[numFaces].v4 = vert_map[mface[numFaces].v4];
 
1603
 
 
1604
                                          test_index_face(&mface[numFaces], &result->faceData,
 
1605
                                                          numFaces, 4);
 
1606
                                  }
 
1607
                                  else
 
1608
                                  {
 
1609
                                          test_index_face(&mface[numFaces], &result->faceData,
 
1610
                                                          numFaces, 3);
 
1611
                                  }
1223
1612
                                  origindex[numFaces] = ORIGINDEX_NONE;
1224
1613
 
1225
1614
                                  numFaces++;
1267
1656
{
1268
1657
        MirrorModifierData *mmd = (MirrorModifierData*) md;
1269
1658
 
1270
 
        mmd->flag |= MOD_MIR_AXIS_X;
 
1659
        mmd->flag |= (MOD_MIR_AXIS_X | MOD_MIR_VGROUP);
1271
1660
        mmd->tolerance = 0.001;
1272
1661
        mmd->mirror_ob = NULL;
1273
1662
}
1306
1695
        }
1307
1696
}
1308
1697
 
 
1698
/* finds the best possible flipped name. For renaming; check for unique names afterwards */
 
1699
/* if strip_number: removes number extensions */
 
1700
void vertgroup_flip_name (char *name, int strip_number)
 
1701
{
 
1702
        int     len;
 
1703
        char    prefix[128]={""};   /* The part before the facing */
 
1704
        char    suffix[128]={""};   /* The part after the facing */
 
1705
        char    replace[128]={""};  /* The replacement string */
 
1706
        char    number[128]={""};   /* The number extension string */
 
1707
        char    *index=NULL;
 
1708
 
 
1709
        len= strlen(name);
 
1710
        if(len<3) return; // we don't do names like .R or .L
 
1711
 
 
1712
        /* We first check the case with a .### extension, let's find the last period */
 
1713
        if(isdigit(name[len-1])) {
 
1714
                index= strrchr(name, '.'); // last occurrance
 
1715
                if (index && isdigit(index[1]) ) { // doesnt handle case bone.1abc2 correct..., whatever!
 
1716
                        if(strip_number==0) 
 
1717
                                strcpy(number, index);
 
1718
                        *index= 0;
 
1719
                        len= strlen(name);
 
1720
                }
 
1721
        }
 
1722
 
 
1723
        strcpy (prefix, name);
 
1724
 
 
1725
#define IS_SEPARATOR(a) ((a)=='.' || (a)==' ' || (a)=='-' || (a)=='_')
 
1726
 
 
1727
        /* first case; separator . - _ with extensions r R l L  */
 
1728
        if( IS_SEPARATOR(name[len-2]) ) {
 
1729
                switch(name[len-1]) {
 
1730
                        case 'l':
 
1731
                                prefix[len-1]= 0;
 
1732
                                strcpy(replace, "r");
 
1733
                                break;
 
1734
                        case 'r':
 
1735
                                prefix[len-1]= 0;
 
1736
                                strcpy(replace, "l");
 
1737
                                break;
 
1738
                        case 'L':
 
1739
                                prefix[len-1]= 0;
 
1740
                                strcpy(replace, "R");
 
1741
                                break;
 
1742
                        case 'R':
 
1743
                                prefix[len-1]= 0;
 
1744
                                strcpy(replace, "L");
 
1745
                                break;
 
1746
                }
 
1747
        }
 
1748
        /* case; beginning with r R l L , with separator after it */
 
1749
        else if( IS_SEPARATOR(name[1]) ) {
 
1750
                switch(name[0]) {
 
1751
                        case 'l':
 
1752
                                strcpy(replace, "r");
 
1753
                                strcpy(suffix, name+1);
 
1754
                                prefix[0]= 0;
 
1755
                                break;
 
1756
                        case 'r':
 
1757
                                strcpy(replace, "l");
 
1758
                                strcpy(suffix, name+1);
 
1759
                                prefix[0]= 0;
 
1760
                                break;
 
1761
                        case 'L':
 
1762
                                strcpy(replace, "R");
 
1763
                                strcpy(suffix, name+1);
 
1764
                                prefix[0]= 0;
 
1765
                                break;
 
1766
                        case 'R':
 
1767
                                strcpy(replace, "L");
 
1768
                                strcpy(suffix, name+1);
 
1769
                                prefix[0]= 0;
 
1770
                                break;
 
1771
                }
 
1772
        }
 
1773
        else if(len > 5) {
 
1774
                /* hrms, why test for a separator? lets do the rule 'ultimate left or right' */
 
1775
                index = BLI_strcasestr(prefix, "right");
 
1776
                if (index==prefix || index==prefix+len-5) {
 
1777
                        if(index[0]=='r') 
 
1778
                                strcpy (replace, "left");
 
1779
                        else {
 
1780
                                if(index[1]=='I') 
 
1781
                                        strcpy (replace, "LEFT");
 
1782
                                else
 
1783
                                        strcpy (replace, "Left");
 
1784
                        }
 
1785
                        *index= 0;
 
1786
                        strcpy (suffix, index+5);
 
1787
                }
 
1788
                else {
 
1789
                        index = BLI_strcasestr(prefix, "left");
 
1790
                        if (index==prefix || index==prefix+len-4) {
 
1791
                                if(index[0]=='l') 
 
1792
                                        strcpy (replace, "right");
 
1793
                                else {
 
1794
                                        if(index[1]=='E') 
 
1795
                                                strcpy (replace, "RIGHT");
 
1796
                                        else
 
1797
                                                strcpy (replace, "Right");
 
1798
                                }
 
1799
                                *index= 0;
 
1800
                                strcpy (suffix, index+4);
 
1801
                        }
 
1802
                }
 
1803
        }
 
1804
 
 
1805
#undef IS_SEPARATOR
 
1806
 
 
1807
        sprintf (name, "%s%s%s%s", prefix, replace, suffix, number);
 
1808
}
 
1809
 
1309
1810
static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
1310
 
                                   Object *ob,
1311
 
       DerivedMesh *dm,
1312
 
       int initFlags,
1313
 
       int axis)
 
1811
                Object *ob,
 
1812
                DerivedMesh *dm,
 
1813
                int initFlags,
 
1814
                int axis)
1314
1815
{
1315
1816
        int i;
1316
1817
        float tolerance = mmd->tolerance;
1319
1820
        int maxVerts = dm->getNumVerts(dm);
1320
1821
        int maxEdges = dm->getNumEdges(dm);
1321
1822
        int maxFaces = dm->getNumFaces(dm);
 
1823
        int vector_size=0, j, a, b;
 
1824
        bDeformGroup *def, *defb;
 
1825
        bDeformGroup **vector_def = NULL;
1322
1826
        int (*indexMap)[2];
1323
1827
        float mtx[4][4], imtx[4][4];
1324
1828
 
1328
1832
 
1329
1833
        result = CDDM_from_template(dm, maxVerts * 2, maxEdges * 2, maxFaces * 2);
1330
1834
 
 
1835
 
 
1836
        if (mmd->flag & MOD_MIR_VGROUP) {
 
1837
                /* calculate the number of deformedGroups */
 
1838
                for(vector_size = 0, def = ob->defbase.first; def;
 
1839
                    def = def->next, vector_size++);
 
1840
 
 
1841
                /* load the deformedGroups for fast access */
 
1842
                vector_def =
 
1843
                    (bDeformGroup **)MEM_mallocN(sizeof(bDeformGroup*) * vector_size,
 
1844
                                                 "group_index");
 
1845
                for(a = 0, def = ob->defbase.first; def; def = def->next, a++) {
 
1846
                        vector_def[a] = def;
 
1847
                }
 
1848
        }
 
1849
 
1331
1850
        if (mmd->mirror_ob) {
1332
1851
                float obinv[4][4];
1333
 
 
 
1852
                
1334
1853
                Mat4Invert(obinv, mmd->mirror_ob->obmat);
1335
1854
                Mat4MulMat4(mtx, ob->obmat, obinv);
1336
1855
                Mat4Invert(imtx, mtx);
1341
1860
                MVert *mv = CDDM_get_vert(result, numVerts);
1342
1861
                int isShared;
1343
1862
                float co[3];
1344
 
 
 
1863
                
1345
1864
                dm->getVert(dm, i, &inMV);
1346
 
 
 
1865
                
1347
1866
                VecCopyf(co, inMV.co);
1348
 
 
 
1867
                
1349
1868
                if (mmd->mirror_ob) {
1350
1869
                        VecMat4MulVecfl(co, mtx, co);
1351
1870
                }
1352
1871
                isShared = ABS(co[axis])<=tolerance;
1353
 
 
 
1872
                
1354
1873
                /* Because the topology result (# of vertices) must be the same if
1355
1874
                * the mesh data is overridden by vertex cos, have to calc sharedness
1356
1875
                * based on original coordinates. This is why we test before copy.
1358
1877
                DM_copy_vert_data(dm, result, i, numVerts, 1);
1359
1878
                *mv = inMV;
1360
1879
                numVerts++;
1361
 
 
 
1880
                
1362
1881
                indexMap[i][0] = numVerts - 1;
1363
1882
                indexMap[i][1] = !isShared;
1364
 
 
 
1883
                
1365
1884
                if(isShared) {
1366
1885
                        co[axis] = 0;
1367
1886
                        if (mmd->mirror_ob) {
1372
1891
                        mv->flag |= ME_VERT_MERGED;
1373
1892
                } else {
1374
1893
                        MVert *mv2 = CDDM_get_vert(result, numVerts);
1375
 
 
 
1894
                        MDeformVert *dvert = NULL;
 
1895
                        
1376
1896
                        DM_copy_vert_data(dm, result, i, numVerts, 1);
1377
1897
                        *mv2 = *mv;
1378
 
                        numVerts++;
1379
 
 
 
1898
                        
1380
1899
                        co[axis] = -co[axis];
1381
1900
                        if (mmd->mirror_ob) {
1382
1901
                                VecMat4MulVecfl(co, imtx, co);
1383
1902
                        }
1384
1903
                        VecCopyf(mv2->co, co);
 
1904
                        
 
1905
                        if (mmd->flag & MOD_MIR_VGROUP){
 
1906
                                dvert = DM_get_vert_data(result, numVerts, CD_MDEFORMVERT);
 
1907
                                
 
1908
                                if (dvert)
 
1909
                                {
 
1910
                                        for(j = 0; j < dvert[0].totweight; ++j)
 
1911
                                        {
 
1912
                                                char tmpname[32];
 
1913
                                                
 
1914
                                                if(dvert->dw[j].def_nr < 0 ||
 
1915
                                                   dvert->dw[j].def_nr >= vector_size)
 
1916
                                                        continue;
 
1917
                                                
 
1918
                                                def = vector_def[dvert->dw[j].def_nr];
 
1919
                                                strcpy(tmpname, def->name);
 
1920
                                                vertgroup_flip_name(tmpname,0);
 
1921
                                                
 
1922
                                                for(b = 0, defb = ob->defbase.first; defb;
 
1923
                                                    defb = defb->next, b++)
 
1924
                                                {
 
1925
                                                        if(!strcmp(defb->name, tmpname))
 
1926
                                                        {
 
1927
                                                                dvert->dw[j].def_nr = b;
 
1928
                                                                break;
 
1929
                                                        }
 
1930
                                                }
 
1931
                                        }
 
1932
                                }
 
1933
                        }
 
1934
                        
 
1935
                        numVerts++;
1385
1936
                }
1386
1937
        }
1387
1938
 
1388
1939
        for(i = 0; i < maxEdges; i++) {
1389
1940
                MEdge inMED;
1390
1941
                MEdge *med = CDDM_get_edge(result, numEdges);
1391
 
 
 
1942
                
1392
1943
                dm->getEdge(dm, i, &inMED);
1393
 
 
 
1944
                
1394
1945
                DM_copy_edge_data(dm, result, i, numEdges, 1);
1395
1946
                *med = inMED;
1396
1947
                numEdges++;
1397
 
 
 
1948
                
1398
1949
                med->v1 = indexMap[inMED.v1][0];
1399
1950
                med->v2 = indexMap[inMED.v2][0];
1400
1951
                if(initFlags)
1401
1952
                        med->flag |= ME_EDGEDRAW | ME_EDGERENDER;
1402
 
 
 
1953
                
1403
1954
                if(indexMap[inMED.v1][1] || indexMap[inMED.v2][1]) {
1404
1955
                        MEdge *med2 = CDDM_get_edge(result, numEdges);
1405
 
 
 
1956
                        
1406
1957
                        DM_copy_edge_data(dm, result, i, numEdges, 1);
1407
1958
                        *med2 = *med;
1408
1959
                        numEdges++;
1409
 
 
 
1960
                        
1410
1961
                        med2->v1 += indexMap[inMED.v1][1];
1411
1962
                        med2->v2 += indexMap[inMED.v2][1];
1412
1963
                }
1415
1966
        for(i = 0; i < maxFaces; i++) {
1416
1967
                MFace inMF;
1417
1968
                MFace *mf = CDDM_get_face(result, numFaces);
1418
 
 
 
1969
                
1419
1970
                dm->getFace(dm, i, &inMF);
1420
 
 
 
1971
                
1421
1972
                DM_copy_face_data(dm, result, i, numFaces, 1);
1422
1973
                *mf = inMF;
1423
1974
                numFaces++;
1424
 
 
 
1975
                
1425
1976
                mf->v1 = indexMap[inMF.v1][0];
1426
1977
                mf->v2 = indexMap[inMF.v2][0];
1427
1978
                mf->v3 = indexMap[inMF.v3][0];
1433
1984
                                 || (mf->v4 && indexMap[inMF.v4][1])) {
1434
1985
                        MFace *mf2 = CDDM_get_face(result, numFaces);
1435
1986
                        static int corner_indices[4] = {2, 1, 0, 3};
1436
 
 
 
1987
                        
1437
1988
                        DM_copy_face_data(dm, result, i, numFaces, 1);
1438
1989
                        *mf2 = *mf;
1439
 
 
 
1990
                        
1440
1991
                        mf2->v1 += indexMap[inMF.v1][1];
1441
1992
                        mf2->v2 += indexMap[inMF.v2][1];
1442
1993
                        mf2->v3 += indexMap[inMF.v3][1];
1443
1994
                        if(inMF.v4) mf2->v4 += indexMap[inMF.v4][1];
1444
 
 
 
1995
                        
1445
1996
                        /* mirror UVs if enabled */
1446
1997
                        if(mmd->flag & (MOD_MIR_MIRROR_U | MOD_MIR_MIRROR_V)) {
1447
1998
                                MTFace *tf = result->getFaceData(result, numFaces, CD_MTFACE);
1455
2006
                                        }
1456
2007
                                }
1457
2008
                        }
1458
 
 
 
2009
                        
1459
2010
                        /* Flip face normal */
1460
2011
                        SWAP(int, mf2->v1, mf2->v3);
1461
2012
                        DM_swap_face_data(result, numFaces, corner_indices);
1462
 
 
 
2013
                        
1463
2014
                        test_index_face(mf2, &result->faceData, numFaces, inMF.v4?4:3);
1464
2015
                        numFaces++;
1465
 
                                 }
 
2016
                }
1466
2017
        }
1467
2018
 
 
2019
        if (vector_def) MEM_freeN(vector_def);
 
2020
 
1468
2021
        MEM_freeN(indexMap);
1469
2022
 
1470
2023
        CDDM_lower_num_verts(result, numVerts);
1475
2028
}
1476
2029
 
1477
2030
static DerivedMesh *mirrorModifier__doMirror(MirrorModifierData *mmd,
1478
 
                                             Object *ob, DerivedMesh *dm,
1479
 
          int initFlags)
 
2031
                                            Object *ob, DerivedMesh *dm,
 
2032
                                                int initFlags)
1480
2033
{
1481
2034
        DerivedMesh *result = dm;
1482
2035
 
1586
2139
        DerivedMesh *dm;
1587
2140
        float threshold; /* the cosine of the smoothing angle */
1588
2141
        int flags;
 
2142
        MemArena *arena;
 
2143
        ListBase propagatestack, reusestack;
1589
2144
} SmoothMesh;
1590
2145
 
1591
2146
static SmoothVert *smoothvert_copy(SmoothVert *vert, SmoothMesh *mesh)
1668
2223
 
1669
2224
        for(i = 0; i < mesh->num_edges; ++i)
1670
2225
                BLI_linklist_free(mesh->edges[i].faces, NULL);
 
2226
        
 
2227
        if(mesh->arena)
 
2228
                BLI_memarena_free(mesh->arena);
1671
2229
 
1672
2230
        MEM_freeN(mesh->verts);
1673
2231
        MEM_freeN(mesh->edges);
2319
2877
        face_replace_vert(face, &repdata);
2320
2878
}
2321
2879
 
 
2880
typedef struct PropagateEdge {
 
2881
        struct PropagateEdge *next, *prev;
 
2882
        SmoothEdge *edge;
 
2883
        SmoothVert *vert;
 
2884
} PropagateEdge;
 
2885
 
 
2886
static void push_propagate_stack(SmoothEdge *edge, SmoothVert *vert, SmoothMesh *mesh)
 
2887
{
 
2888
        PropagateEdge *pedge = mesh->reusestack.first;
 
2889
 
 
2890
        if(pedge) {
 
2891
                BLI_remlink(&mesh->reusestack, pedge);
 
2892
        }
 
2893
        else {
 
2894
                if(!mesh->arena) {
 
2895
                        mesh->arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE);
 
2896
                        BLI_memarena_use_calloc(mesh->arena);
 
2897
                }
 
2898
 
 
2899
                pedge = BLI_memarena_alloc(mesh->arena, sizeof(PropagateEdge));
 
2900
        }
 
2901
 
 
2902
        pedge->edge = edge;
 
2903
        pedge->vert = vert;
 
2904
        BLI_addhead(&mesh->propagatestack, pedge);
 
2905
}
 
2906
 
 
2907
static void pop_propagate_stack(SmoothEdge **edge, SmoothVert **vert, SmoothMesh *mesh)
 
2908
{
 
2909
        PropagateEdge *pedge = mesh->propagatestack.first;
 
2910
 
 
2911
        if(pedge) {
 
2912
                *edge = pedge->edge;
 
2913
                *vert = pedge->vert;
 
2914
                BLI_remlink(&mesh->propagatestack, pedge);
 
2915
                BLI_addhead(&mesh->reusestack, pedge);
 
2916
        }
 
2917
        else {
 
2918
                *edge = NULL;
 
2919
                *vert = NULL;
 
2920
        }
 
2921
}
 
2922
 
2322
2923
static void split_edge(SmoothEdge *edge, SmoothVert *vert, SmoothMesh *mesh);
2323
2924
 
2324
2925
static void propagate_split(SmoothEdge *edge, SmoothVert *vert,
2396
2997
        if(!edge2) {
2397
2998
                /* didn't find a sharp or loose edge, so try the other vert */
2398
2999
                vert2 = other_vert(edge, vert);
2399
 
                propagate_split(edge, vert2, mesh);
 
3000
                push_propagate_stack(edge, vert2, mesh);
2400
3001
        } else if(!edge_is_loose(edge2)) {
2401
3002
                /* edge2 is not loose, so it must be sharp */
2402
3003
                SmoothEdge *copy_edge = smoothedge_copy(edge, mesh);
2425
3026
                /* all copying and replacing is done; the mesh should be consistent.
2426
3027
                * now propagate the split to the vertices at either end
2427
3028
                */
2428
 
                propagate_split(copy_edge, other_vert(copy_edge, vert2), mesh);
2429
 
                propagate_split(copy_edge2, other_vert(copy_edge2, vert2), mesh);
 
3029
                push_propagate_stack(copy_edge, other_vert(copy_edge, vert2), mesh);
 
3030
                push_propagate_stack(copy_edge2, other_vert(copy_edge2, vert2), mesh);
2430
3031
 
2431
3032
                if(smoothedge_has_vert(edge, vert))
2432
 
                        propagate_split(edge, vert, mesh);
 
3033
                        push_propagate_stack(edge, vert, mesh);
2433
3034
        } else {
2434
3035
                /* edge2 is loose */
2435
3036
                SmoothEdge *copy_edge = smoothedge_copy(edge, mesh);
2452
3053
                /* copying and replacing is done; the mesh should be consistent.
2453
3054
                * now propagate the split to the vertex at the other end
2454
3055
                */
2455
 
                propagate_split(copy_edge, other_vert(copy_edge, vert2), mesh);
 
3056
                push_propagate_stack(copy_edge, other_vert(copy_edge, vert2), mesh);
2456
3057
 
2457
3058
                if(smoothedge_has_vert(edge, vert))
2458
 
                        propagate_split(edge, vert, mesh);
 
3059
                        push_propagate_stack(edge, vert, mesh);
2459
3060
        }
2460
3061
 
2461
3062
        BLI_linklist_free(visited_faces, NULL);
2527
3128
 
2528
3129
static void split_sharp_edges(SmoothMesh *mesh, float split_angle, int flags)
2529
3130
{
 
3131
        SmoothVert *vert;
2530
3132
        int i;
2531
3133
        /* if normal1 dot normal2 < threshold, angle is greater, so split */
2532
3134
        /* FIXME not sure if this always works */
2539
3141
        for(i = 0; i < mesh->num_edges; i++) {
2540
3142
                SmoothEdge *edge = &mesh->edges[i];
2541
3143
 
2542
 
                if(edge_is_sharp(edge, flags, mesh->threshold))
 
3144
                if(edge_is_sharp(edge, flags, mesh->threshold)) {
2543
3145
                        split_edge(edge, edge->verts[0], mesh);
 
3146
 
 
3147
                        do {
 
3148
                                pop_propagate_stack(&edge, &vert, mesh);
 
3149
                                if(edge && smoothedge_has_vert(edge, vert))
 
3150
                                        propagate_split(edge, vert, mesh);
 
3151
                        } while(edge);
 
3152
                }
2544
3153
        }
2545
 
 
2546
3154
}
2547
3155
 
2548
3156
static int count_bridge_verts(SmoothMesh *mesh)
2736
3344
{
2737
3345
        DerivedMesh *result;
2738
3346
        BME_Mesh *bm;
 
3347
 
2739
3348
        /*bDeformGroup *def;*/
2740
3349
        int /*i,*/ options, defgrp_index = -1;
2741
3350
        BevelModifierData *bmd = (BevelModifierData*) md;
2754
3363
                //~ }
2755
3364
        //~ }
2756
3365
 
2757
 
        bm = BME_make_mesh();
2758
 
        bm = BME_derivedmesh_to_bmesh(derivedData, bm);
 
3366
        bm = BME_derivedmesh_to_bmesh(derivedData);
2759
3367
        BME_bevel(bm,bmd->value,bmd->res,options,defgrp_index,bmd->bevel_angle,NULL);
2760
3368
        result = BME_bmesh_to_derivedmesh(bm,derivedData);
2761
3369
        BME_free_mesh(bm);
2813
3421
        return dataMask;
2814
3422
}
2815
3423
 
 
3424
static int displaceModifier_dependsOnTime(ModifierData *md)
 
3425
{
 
3426
        DisplaceModifierData *dmd = (DisplaceModifierData *)md;
 
3427
 
 
3428
        if(dmd->texture)
 
3429
        {
 
3430
                return BKE_texture_dependsOnTime(dmd->texture);
 
3431
        }
 
3432
        else
 
3433
        {
 
3434
                return 0;
 
3435
        }
 
3436
}
 
3437
 
2816
3438
static void displaceModifier_foreachObjectLink(ModifierData *md, Object *ob,
2817
3439
                                               ObjectWalkFunc walk, void *userData)
2818
3440
{
4358
4980
 
4359
4981
/* Wave */
4360
4982
 
4361
 
static void waveModifier_initData(ModifierData *md) 
 
4983
static void waveModifier_initData(ModifierData *md)
4362
4984
{
4363
4985
        WaveModifierData *wmd = (WaveModifierData*) md; // whadya know, moved here from Iraq
4364
 
                
 
4986
 
4365
4987
        wmd->flag |= (MOD_WAVE_X | MOD_WAVE_Y | MOD_WAVE_CYCL
4366
4988
                        | MOD_WAVE_NORM_X | MOD_WAVE_NORM_Y | MOD_WAVE_NORM_Z);
4367
 
        
 
4989
 
4368
4990
        wmd->objectcenter = NULL;
4369
4991
        wmd->texture = NULL;
4370
4992
        wmd->map_object = NULL;
4374
4996
        wmd->narrow= 1.5f;
4375
4997
        wmd->lifetime= 0.0f;
4376
4998
        wmd->damp= 10.0f;
 
4999
        wmd->falloff= 0.0f;
4377
5000
        wmd->texmapping = MOD_WAV_MAP_LOCAL;
4378
5001
        wmd->defgrp_name[0] = 0;
4379
5002
}
4393
5016
        twmd->starty = wmd->starty;
4394
5017
        twmd->timeoffs = wmd->timeoffs;
4395
5018
        twmd->width = wmd->width;
 
5019
        twmd->falloff = wmd->falloff;
4396
5020
        twmd->objectcenter = wmd->objectcenter;
4397
5021
        twmd->texture = wmd->texture;
4398
5022
        twmd->map_object = wmd->map_object;
4603
5227
 
4604
5228
                if(x > wmd->lifetime) {
4605
5229
                        lifefac = x - wmd->lifetime;
4606
 
                        
 
5230
 
4607
5231
                        if(lifefac > wmd->damp) lifefac = 0.0;
4608
5232
                        else lifefac =
4609
5233
                                (float)(wmd->height * (1.0 - sqrt(lifefac / wmd->damp)));
4624
5248
                        float x = co[0] - wmd->startx;
4625
5249
                        float y = co[1] - wmd->starty;
4626
5250
                        float amplit= 0.0f;
 
5251
                        float dist = 0.0f;
 
5252
                        float falloff_fac = 0.0f;
4627
5253
                        TexResult texres;
4628
5254
                        MDeformWeight *def_weight = NULL;
4629
5255
 
4646
5272
                                get_texture_value(wmd->texture, tex_co[i], &texres);
4647
5273
                        }
4648
5274
 
 
5275
                        /*get dist*/
 
5276
                        if(wmd->flag & MOD_WAVE_X) {
 
5277
                                if(wmd->flag & MOD_WAVE_Y){
 
5278
                                        dist = (float)sqrt(x*x + y*y);
 
5279
                                }
 
5280
                                else{
 
5281
                                        dist = fabs(x);
 
5282
                                }
 
5283
                        }
 
5284
                        else if(wmd->flag & MOD_WAVE_Y) {
 
5285
                                dist = fabs(y);
 
5286
                        }
 
5287
 
 
5288
                        falloff_fac = (1.0-(dist / wmd->falloff));
 
5289
                        CLAMP(falloff_fac,0,1);
4649
5290
 
4650
5291
                        if(wmd->flag & MOD_WAVE_X) {
4651
5292
                                if(wmd->flag & MOD_WAVE_Y) amplit = (float)sqrt(x*x + y*y);
4652
5293
                                else amplit = x;
4653
5294
                        }
4654
 
                        else if(wmd->flag & MOD_WAVE_Y) 
 
5295
                        else if(wmd->flag & MOD_WAVE_Y)
4655
5296
                                amplit= y;
4656
 
                        
 
5297
 
4657
5298
                        /* this way it makes nice circles */
4658
5299
                        amplit -= (ctime - wmd->timeoffs) * wmd->speed;
4659
5300
 
4666
5307
                        if(amplit > -wmd->width && amplit < wmd->width) {
4667
5308
                                amplit = amplit * wmd->narrow;
4668
5309
                                amplit = (float)(1.0 / exp(amplit * amplit) - minfac);
 
5310
 
 
5311
                                /*apply texture*/
4669
5312
                                if(wmd->texture)
4670
5313
                                        amplit = amplit * texres.tin;
4671
5314
 
 
5315
                                /*apply weight*/
4672
5316
                                if(def_weight)
4673
5317
                                        amplit = amplit * def_weight->weight;
4674
5318
 
 
5319
                                /*apply falloff*/
 
5320
                                if (wmd->falloff > 0)
 
5321
                                        amplit = amplit * falloff_fac;
 
5322
 
4675
5323
                                if(mvert) {
4676
5324
                                        /* move along normals */
4677
5325
                                        if(wmd->flag & MOD_WAVE_NORM_X) {
4727
5375
 
4728
5376
        if(!wmd->texture && !wmd->defgrp_name[0] && !(wmd->flag & MOD_WAVE_NORM))
4729
5377
                dm = derivedData;
4730
 
        else if(derivedData) dm = derivedData;
 
5378
        else if(derivedData) dm = CDDM_copy(derivedData);
4731
5379
        else dm = CDDM_from_editmesh(editData, ob->data);
4732
5380
 
4733
5381
        if(wmd->flag & MOD_WAVE_NORM) {
5058
5706
        sbObjectStep(ob, (float)G.scene->r.cfra, vertexCos, numVerts);
5059
5707
}
5060
5708
 
 
5709
static int softbodyModifier_dependsOnTime(ModifierData *md)
 
5710
{
 
5711
        return 1;
 
5712
}
 
5713
 
5061
5714
 
5062
5715
/* Cloth */
5063
5716
 
5193
5846
        collmd->current_v = NULL;
5194
5847
        collmd->time = -1;
5195
5848
        collmd->numverts = 0;
5196
 
        collmd->bvh = NULL;
 
5849
        collmd->bvhtree = NULL;
5197
5850
}
5198
5851
 
5199
5852
static void collisionModifier_freeData(ModifierData *md)
5202
5855
        
5203
5856
        if (collmd) 
5204
5857
        {
5205
 
                if(collmd->bvh)
5206
 
                        bvh_free(collmd->bvh);
 
5858
                if(collmd->bvhtree)
 
5859
                        BLI_bvhtree_free(collmd->bvhtree);
5207
5860
                if(collmd->x)
5208
5861
                        MEM_freeN(collmd->x);
5209
5862
                if(collmd->xnew)
5214
5867
                        MEM_freeN(collmd->current_xnew);
5215
5868
                if(collmd->current_v)
5216
5869
                        MEM_freeN(collmd->current_v);
5217
 
                
5218
5870
                if(collmd->mfaces)
5219
5871
                        MEM_freeN(collmd->mfaces);
5220
5872
                
5225
5877
                collmd->current_v = NULL;
5226
5878
                collmd->time = -1;
5227
5879
                collmd->numverts = 0;
5228
 
                collmd->bvh = NULL;
 
5880
                collmd->bvhtree = NULL;
5229
5881
                collmd->mfaces = NULL;
5230
5882
        }
5231
5883
}
5267
5919
                
5268
5920
                numverts = dm->getNumVerts ( dm );
5269
5921
                
5270
 
                if(current_time > collmd->time)
 
5922
                if((current_time > collmd->time)|| (BKE_ptcache_get_continue_physics()))
5271
5923
                {       
5272
5924
                        // check if mesh has changed
5273
5925
                        if(collmd->x && (numverts != collmd->numverts))
5293
5945
                                collmd->mfaces = dm->dupFaceArray(dm);
5294
5946
                                collmd->numfaces = dm->getNumFaces(dm);
5295
5947
                                
5296
 
                                // TODO: epsilon
5297
5948
                                // create bounding box hierarchy
5298
 
                                collmd->bvh = bvh_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->x, numverts, ob->pd->pdef_sboft);
 
5949
                                collmd->bvhtree = bvhtree_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->x, numverts, ob->pd->pdef_sboft);
5299
5950
                                
5300
5951
                                collmd->time = current_time;
5301
5952
                        }
5318
5969
                                memcpy(collmd->current_x, collmd->x, numverts*sizeof(MVert));
5319
5970
                                
5320
5971
                                /* check if GUI setting has changed for bvh */
5321
 
                                if(collmd->bvh)
 
5972
                                if(collmd->bvhtree) 
5322
5973
                                {
5323
 
                                        if(ob->pd->pdef_sboft != collmd->bvh->epsilon)
 
5974
                                        if(ob->pd->pdef_sboft != BLI_bvhtree_getepsilon(collmd->bvhtree))
5324
5975
                                        {
5325
 
                                                bvh_free(collmd->bvh);
5326
 
                                                collmd->bvh = bvh_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->current_x, numverts, ob->pd->pdef_sboft);
 
5976
                                                BLI_bvhtree_free(collmd->bvhtree);
 
5977
                                                collmd->bvhtree = bvhtree_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->current_x, numverts, ob->pd->pdef_sboft);
5327
5978
                                        }
5328
5979
                        
5329
5980
                                }
5330
5981
                                
5331
 
                                /* happens on file load (ONLY when i decomment changes in readfile.c */
5332
 
                                if(!collmd->bvh)
 
5982
                                /* happens on file load (ONLY when i decomment changes in readfile.c) */
 
5983
                                if(!collmd->bvhtree)
5333
5984
                                {
5334
 
                                        collmd->bvh = bvh_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->current_x, numverts, ob->pd->pdef_sboft);
 
5985
                                        collmd->bvhtree = bvhtree_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->current_x, numverts, ob->pd->pdef_sboft);
5335
5986
                                }
5336
5987
                                else
5337
5988
                                {
5338
5989
                                        // recalc static bounding boxes
5339
 
                                        bvh_update_from_mvert(collmd->bvh, collmd->current_x, numverts, NULL, 0);
 
5990
                                        bvhtree_update_from_mvert ( collmd->bvhtree, collmd->mfaces, collmd->numfaces, collmd->current_x, collmd->current_xnew, collmd->numverts, 1 );
5340
5991
                                }
5341
5992
                                
5342
5993
                                collmd->time = current_time;
5895
6546
        return dataMask;
5896
6547
}
5897
6548
 
5898
 
/* this should really be put somewhere permanently */
5899
 
static float vert_weight(MDeformVert *dvert, int group)
5900
 
{
5901
 
        MDeformWeight *dw;
5902
 
        int i;
5903
 
        
5904
 
        if(dvert) {
5905
 
                dw= dvert->dw;
5906
 
                for(i= dvert->totweight; i>0; i--, dw++) {
5907
 
                        if(dw->def_nr == group) return dw->weight;
5908
 
                        if(i==1) break; /*otherwise dw will point to somewhere it shouldn't*/
5909
 
                }
5910
 
        }
5911
 
        return 0.0;
5912
 
}
5913
 
 
5914
6549
static void explodeModifier_createFacepa(ExplodeModifierData *emd,
5915
6550
                                         ParticleSystemModifierData *psmd,
5916
6551
      Object *ob, DerivedMesh *dm)
5954
6589
                        for(i=0; i<totvert; i++){
5955
6590
                                val = BLI_frand();
5956
6591
                                val = (1.0f-emd->protect)*val + emd->protect*0.5f;
5957
 
                                if(val < vert_weight(dvert+i,emd->vgroup-1))
 
6592
                                if(val < deformvert_get_weight(dvert+i,emd->vgroup-1))
5958
6593
                                        vertpa[i] = -1;
5959
6594
                        }
5960
6595
                }
5963
6598
        /* make tree of emitter locations */
5964
6599
        tree=BLI_kdtree_new(totpart);
5965
6600
        for(p=0,pa=psys->particles; p<totpart; p++,pa++){
5966
 
                psys_particle_on_dm(ob,psmd->dm,psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,0,0,0,0,0);
 
6601
                psys_particle_on_dm(psmd->dm,psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,0,0,0,0,0);
5967
6602
                BLI_kdtree_insert(tree, p, co, NULL);
5968
6603
        }
5969
6604
        BLI_kdtree_balance(tree);
6483
7118
{
6484
7119
        DerivedMesh *explode, *dm=to_explode;
6485
7120
        MFace *mf=0;
6486
 
        MVert *dupvert=0;
6487
7121
        ParticleSettings *part=psmd->psys->part;
6488
 
        ParticleData *pa, *pars=psmd->psys->particles;
 
7122
        ParticleData *pa=NULL, *pars=psmd->psys->particles;
6489
7123
        ParticleKey state;
 
7124
        EdgeHash *vertpahash;
 
7125
        EdgeHashIterator *ehi;
6490
7126
        float *vertco=0, imat[4][4];
6491
7127
        float loc0[3], nor[3];
6492
7128
        float timestep, cfra;
6493
 
        int *facepa=emd->facepa, *vertpa=0;
 
7129
        int *facepa=emd->facepa;
6494
7130
        int totdup=0,totvert=0,totface=0,totpart=0;
6495
7131
        int i, j, v, mindex=0;
6496
7132
 
6505
7141
        else
6506
7142
                cfra=bsystem_time(ob,(float)G.scene->r.cfra,0.0);
6507
7143
 
6508
 
        /* table for vertice <-> particle relations (row totpart+1 is for yet unexploded verts) */
6509
 
        vertpa = MEM_callocN(sizeof(int)*(totpart+1)*totvert, "explode_vertpatab");
6510
 
        for(i=0; i<(totpart+1)*totvert; i++)
6511
 
                vertpa[i] = -1;
 
7144
        /* hash table for vertice <-> particle relations */
 
7145
        vertpahash= BLI_edgehash_new();
6512
7146
 
6513
7147
        for (i=0; i<totface; i++) {
 
7148
                /* do mindex + totvert to ensure the vertex index to be the first
 
7149
                 * with BLI_edgehashIterator_getKey */
6514
7150
                if(facepa[i]==totpart || cfra <= (pars+facepa[i])->time)
6515
 
                        mindex = totpart*totvert;
 
7151
                        mindex = totvert+totpart;
6516
7152
                else 
6517
 
                        mindex = facepa[i]*totvert;
 
7153
                        mindex = totvert+facepa[i];
6518
7154
 
6519
7155
                mf=CDDM_get_face(dm,i);
6520
7156
 
6521
 
                /*set face vertices to exist in particle group*/
6522
 
                vertpa[mindex+mf->v1] = 1;
6523
 
                vertpa[mindex+mf->v2] = 1;
6524
 
                vertpa[mindex+mf->v3] = 1;
 
7157
                /* set face vertices to exist in particle group */
 
7158
                BLI_edgehash_insert(vertpahash, mf->v1, mindex, NULL);
 
7159
                BLI_edgehash_insert(vertpahash, mf->v2, mindex, NULL);
 
7160
                BLI_edgehash_insert(vertpahash, mf->v3, mindex, NULL);
6525
7161
                if(mf->v4)
6526
 
                        vertpa[mindex+mf->v4] = 1;
6527
 
        }
6528
 
 
6529
 
        /*make new vertice indexes & count total vertices after duplication*/
6530
 
        for(i=0; i<(totpart+1)*totvert; i++){
6531
 
                if(vertpa[i] != -1)
6532
 
                        vertpa[i] = totdup++;
6533
 
        }
6534
 
 
6535
 
        /*the final duplicated vertices*/
 
7162
                        BLI_edgehash_insert(vertpahash, mf->v4, mindex, NULL);
 
7163
        }
 
7164
 
 
7165
        /* make new vertice indexes & count total vertices after duplication */
 
7166
        ehi= BLI_edgehashIterator_new(vertpahash);
 
7167
        for(; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) {
 
7168
                BLI_edgehashIterator_setValue(ehi, SET_INT_IN_POINTER(totdup));
 
7169
                totdup++;
 
7170
        }
 
7171
        BLI_edgehashIterator_free(ehi);
 
7172
 
 
7173
        /* the final duplicated vertices */
6536
7174
        explode= CDDM_from_template(dm, totdup, 0,totface);
6537
 
        dupvert= CDDM_get_verts(explode);
 
7175
        /*dupvert= CDDM_get_verts(explode);*/
6538
7176
 
6539
7177
        /* getting back to object space */
6540
7178
        Mat4Invert(imat,ob->obmat);
6541
7179
 
6542
7180
        psmd->psys->lattice = psys_get_lattice(ob, psmd->psys);
6543
7181
 
6544
 
        /*duplicate & displace vertices*/
6545
 
        for(i=0, pa=pars; i<=totpart; i++, pa++){
6546
 
                if(i!=totpart){
6547
 
                        psys_particle_on_emitter(ob, psmd,part->from,pa->num,-1,pa->fuv,pa->foffset,loc0,nor,0,0,0,0);
 
7182
        /* duplicate & displace vertices */
 
7183
        ehi= BLI_edgehashIterator_new(vertpahash);
 
7184
        for(; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) {
 
7185
                MVert source;
 
7186
                MVert *dest;
 
7187
 
 
7188
                /* get particle + vertex from hash */
 
7189
                BLI_edgehashIterator_getKey(ehi, &j, &i);
 
7190
                i -= totvert;
 
7191
                v= GET_INT_FROM_POINTER(BLI_edgehashIterator_getValue(ehi));
 
7192
 
 
7193
                dm->getVert(dm, j, &source);
 
7194
                dest = CDDM_get_vert(explode,v);
 
7195
 
 
7196
                DM_copy_vert_data(dm,explode,j,v,1);
 
7197
                *dest = source;
 
7198
 
 
7199
                if(i!=totpart) {
 
7200
                        /* get particle */
 
7201
                        pa= pars+i;
 
7202
 
 
7203
                        /* get particle state */
 
7204
                        psys_particle_on_emitter(psmd,part->from,pa->num,-1,pa->fuv,pa->foffset,loc0,nor,0,0,0,0);
6548
7205
                        Mat4MulVecfl(ob->obmat,loc0);
6549
7206
 
6550
7207
                        state.time=cfra;
6551
7208
                        psys_get_particle_state(ob,psmd->psys,i,&state,1);
6552
 
                }
6553
 
 
6554
 
                for(j=0; j<totvert; j++){
6555
 
                        v=vertpa[i*totvert+j];
6556
 
                        if(v != -1) {
6557
 
                                MVert source;
6558
 
                                MVert *dest;
6559
 
 
6560
 
                                dm->getVert(dm, j, &source);
6561
 
                                dest = CDDM_get_vert(explode,v);
6562
 
 
6563
 
                                DM_copy_vert_data(dm,explode,j,v,1);
6564
 
                                *dest = source;
6565
 
 
6566
 
                                if(i!=totpart){
6567
 
                                        vertco=CDDM_get_vert(explode,v)->co;
6568
 
                                        
6569
 
                                        Mat4MulVecfl(ob->obmat,vertco);
6570
 
 
6571
 
                                        VECSUB(vertco,vertco,loc0);
6572
 
 
6573
 
                                        /* apply rotation, size & location */
6574
 
                                        QuatMulVecf(state.rot,vertco);
6575
 
                                        VecMulf(vertco,pa->size);
6576
 
                                        VECADD(vertco,vertco,state.co);
6577
 
 
6578
 
                                        Mat4MulVecfl(imat,vertco);
6579
 
                                }
6580
 
                        }
 
7209
 
 
7210
                        vertco=CDDM_get_vert(explode,v)->co;
 
7211
                        
 
7212
                        Mat4MulVecfl(ob->obmat,vertco);
 
7213
 
 
7214
                        VECSUB(vertco,vertco,loc0);
 
7215
 
 
7216
                        /* apply rotation, size & location */
 
7217
                        QuatMulVecf(state.rot,vertco);
 
7218
                        VecMulf(vertco,pa->size);
 
7219
                        VECADD(vertco,vertco,state.co);
 
7220
 
 
7221
                        Mat4MulVecfl(imat,vertco);
6581
7222
                }
6582
7223
        }
 
7224
        BLI_edgehashIterator_free(ehi);
6583
7225
 
6584
7226
        /*map new vertices to faces*/
6585
7227
        for (i=0; i<totface; i++) {
6601
7243
                orig_v4 = source.v4;
6602
7244
 
6603
7245
                if(facepa[i]!=totpart && cfra <= pa->time)
6604
 
                        mindex = totpart*totvert;
 
7246
                        mindex = totvert+totpart;
6605
7247
                else 
6606
 
                        mindex = facepa[i]*totvert;
 
7248
                        mindex = totvert+facepa[i];
6607
7249
 
6608
 
                source.v1 = vertpa[mindex+source.v1];
6609
 
                source.v2 = vertpa[mindex+source.v2];
6610
 
                source.v3 = vertpa[mindex+source.v3];
 
7250
                source.v1 = edgesplit_get(vertpahash, source.v1, mindex);
 
7251
                source.v2 = edgesplit_get(vertpahash, source.v2, mindex);
 
7252
                source.v3 = edgesplit_get(vertpahash, source.v3, mindex);
6611
7253
                if(source.v4)
6612
 
                        source.v4 = vertpa[mindex+source.v4];
 
7254
                        source.v4 = edgesplit_get(vertpahash, source.v4, mindex);
6613
7255
 
6614
7256
                DM_copy_face_data(dm,explode,i,i,1);
6615
7257
 
6618
7260
                test_index_face(mf, &explode->faceData, i, (mf->v4 ? 4 : 3));
6619
7261
        }
6620
7262
 
 
7263
        MEM_printmemlist_stats();
6621
7264
 
6622
7265
        /* cleanup */
6623
 
        if(vertpa) MEM_freeN(vertpa);
 
7266
        BLI_edgehash_free(vertpahash, NULL);
6624
7267
 
6625
7268
        /* finalization */
6626
7269
        CDDM_calc_edges(explode);
6690
7333
        }
6691
7334
        return derivedData;
6692
7335
}
 
7336
 
 
7337
/* Fluidsim */
 
7338
static void fluidsimModifier_initData(ModifierData *md)
 
7339
{
 
7340
        FluidsimModifierData *fluidmd= (FluidsimModifierData*) md;
 
7341
        
 
7342
        fluidsim_init(fluidmd);
 
7343
}
 
7344
static void fluidsimModifier_freeData(ModifierData *md)
 
7345
{
 
7346
        FluidsimModifierData *fluidmd= (FluidsimModifierData*) md;
 
7347
        
 
7348
        fluidsim_free(fluidmd);
 
7349
}
 
7350
 
 
7351
static void fluidsimModifier_copyData(ModifierData *md, ModifierData *target)
 
7352
{
 
7353
        FluidsimModifierData *fluidmd= (FluidsimModifierData*) md;
 
7354
        FluidsimModifierData *tfluidmd= (FluidsimModifierData*) target;
 
7355
        
 
7356
        if(tfluidmd->fss)
 
7357
                MEM_freeN(tfluidmd->fss);
 
7358
        
 
7359
        tfluidmd->fss = MEM_dupallocN(fluidmd->fss);
 
7360
}
 
7361
 
 
7362
static DerivedMesh * fluidsimModifier_applyModifier(
 
7363
                ModifierData *md, Object *ob, DerivedMesh *derivedData,
 
7364
  int useRenderParams, int isFinalCalc)
 
7365
{
 
7366
        FluidsimModifierData *fluidmd= (FluidsimModifierData*) md;
 
7367
        DerivedMesh *result = NULL;
 
7368
        
 
7369
        /* check for alloc failing */
 
7370
        if(!fluidmd->fss)
 
7371
        {
 
7372
                fluidsimModifier_initData(md);
 
7373
                
 
7374
                if(!fluidmd->fss)
 
7375
                        return derivedData;
 
7376
        }
 
7377
 
 
7378
        result = fluidsimModifier_do(fluidmd, ob, derivedData, useRenderParams, isFinalCalc);
 
7379
 
 
7380
        if(result) 
 
7381
        { 
 
7382
                return result; 
 
7383
        }
 
7384
        
 
7385
        return derivedData;
 
7386
}
 
7387
 
 
7388
static void fluidsimModifier_updateDepgraph(
 
7389
                ModifierData *md, DagForest *forest,
 
7390
      Object *ob, DagNode *obNode)
 
7391
{
 
7392
        FluidsimModifierData *fluidmd= (FluidsimModifierData*) md;
 
7393
        Base *base;
 
7394
 
 
7395
        if(fluidmd && fluidmd->fss)
 
7396
        {
 
7397
                if(fluidmd->fss->type == OB_FLUIDSIM_DOMAIN)
 
7398
                {
 
7399
                        for(base = G.scene->base.first; base; base= base->next) 
 
7400
                        {
 
7401
                                Object *ob1= base->object;
 
7402
                                if(ob1 != ob)
 
7403
                                {
 
7404
                                        FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(ob1, eModifierType_Fluidsim);
 
7405
                                        
 
7406
                                        // only put dependancies from NON-DOMAIN fluids in here
 
7407
                                        if(fluidmdtmp && fluidmdtmp->fss && (fluidmdtmp->fss->type!=OB_FLUIDSIM_DOMAIN))
 
7408
                                        {
 
7409
                                                DagNode *curNode = dag_get_node(forest, ob1);
 
7410
                                                dag_add_relation(forest, curNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Fluidsim Object");
 
7411
                                        }
 
7412
                                }
 
7413
                        }
 
7414
                }
 
7415
        }
 
7416
}
 
7417
 
 
7418
static int fluidsimModifier_dependsOnTime(ModifierData *md) 
 
7419
{
 
7420
        return 1;
 
7421
}
 
7422
 
6693
7423
/* MeshDeform */
6694
7424
 
6695
7425
static void meshdeformModifier_initData(ModifierData *md)
6850
7580
        Mat3CpyMat4(icagemat, iobmat);
6851
7581
 
6852
7582
        /* bind weights if needed */
6853
 
        if(!mmd->bindcos)
6854
 
                harmonic_coordinates_bind(mmd, vertexCos, numVerts, cagemat);
 
7583
        if(!mmd->bindcos) {
 
7584
                static int recursive = 0;
 
7585
 
 
7586
                /* progress bar redraw can make this recursive .. */
 
7587
                if(!recursive) {
 
7588
                        recursive = 1;
 
7589
                        harmonic_coordinates_bind(mmd, vertexCos, numVerts, cagemat);
 
7590
                        recursive = 0;
 
7591
                }
 
7592
        }
6855
7593
 
6856
7594
        /* verify we have compatible weights */
6857
7595
        totvert= numVerts;
6994
7732
                dm->release(dm);
6995
7733
}
6996
7734
 
 
7735
 
 
7736
/* Shrinkwrap */
 
7737
 
 
7738
static void shrinkwrapModifier_initData(ModifierData *md)
 
7739
{
 
7740
        ShrinkwrapModifierData *smd = (ShrinkwrapModifierData*) md;
 
7741
        smd->shrinkType = MOD_SHRINKWRAP_NEAREST_SURFACE;
 
7742
        smd->shrinkOpts = MOD_SHRINKWRAP_PROJECT_ALLOW_POS_DIR;
 
7743
        smd->keepDist   = 0.0f;
 
7744
 
 
7745
        smd->target             = NULL;
 
7746
        smd->auxTarget  = NULL;
 
7747
}
 
7748
 
 
7749
static void shrinkwrapModifier_copyData(ModifierData *md, ModifierData *target)
 
7750
{
 
7751
        ShrinkwrapModifierData *smd  = (ShrinkwrapModifierData*)md;
 
7752
        ShrinkwrapModifierData *tsmd = (ShrinkwrapModifierData*)target;
 
7753
 
 
7754
        tsmd->target    = smd->target;
 
7755
        tsmd->auxTarget = smd->auxTarget;
 
7756
 
 
7757
        strcpy(tsmd->vgroup_name, smd->vgroup_name);
 
7758
 
 
7759
        tsmd->keepDist  = smd->keepDist;
 
7760
        tsmd->shrinkType= smd->shrinkType;
 
7761
        tsmd->shrinkOpts= smd->shrinkOpts;
 
7762
        tsmd->projAxis = smd->projAxis;
 
7763
        tsmd->subsurfLevels = smd->subsurfLevels;
 
7764
}
 
7765
 
 
7766
CustomDataMask shrinkwrapModifier_requiredDataMask(ModifierData *md)
 
7767
{
 
7768
        ShrinkwrapModifierData *smd = (ShrinkwrapModifierData *)md;
 
7769
        CustomDataMask dataMask = 0;
 
7770
 
 
7771
        /* ask for vertexgroups if we need them */
 
7772
        if(smd->vgroup_name[0])
 
7773
                dataMask |= (1 << CD_MDEFORMVERT);
 
7774
 
 
7775
        if(smd->shrinkType == MOD_SHRINKWRAP_PROJECT
 
7776
        && smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL)
 
7777
                dataMask |= (1 << CD_MVERT);
 
7778
                
 
7779
        return dataMask;
 
7780
}
 
7781
 
 
7782
static int shrinkwrapModifier_isDisabled(ModifierData *md)
 
7783
{
 
7784
        ShrinkwrapModifierData *smd = (ShrinkwrapModifierData*) md;
 
7785
        return !smd->target;
 
7786
}
 
7787
 
 
7788
 
 
7789
static void shrinkwrapModifier_foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData)
 
7790
{
 
7791
        ShrinkwrapModifierData *smd = (ShrinkwrapModifierData*) md;
 
7792
 
 
7793
        walk(userData, ob, &smd->target);
 
7794
        walk(userData, ob, &smd->auxTarget);
 
7795
}
 
7796
 
 
7797
static void shrinkwrapModifier_deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 
7798
{
 
7799
        DerivedMesh *dm = NULL;
 
7800
        CustomDataMask dataMask = shrinkwrapModifier_requiredDataMask(md);
 
7801
 
 
7802
        /* We implement requiredDataMask but thats not really usefull since mesh_calc_modifiers pass a NULL derivedData or without the modified vertexs applied */
 
7803
        if(dataMask)
 
7804
        {
 
7805
                if(derivedData) dm = CDDM_copy(derivedData);
 
7806
                else if(ob->type==OB_MESH) dm = CDDM_from_mesh(ob->data, ob);
 
7807
                else return;
 
7808
 
 
7809
                if(dataMask & CD_MVERT)
 
7810
                {
 
7811
                        CDDM_apply_vert_coords(dm, vertexCos);
 
7812
                        CDDM_calc_normals(dm);
 
7813
                }
 
7814
        }
 
7815
 
 
7816
        shrinkwrapModifier_deform((ShrinkwrapModifierData*)md, ob, dm, vertexCos, numVerts);
 
7817
 
 
7818
        if(dm)
 
7819
                dm->release(dm);
 
7820
}
 
7821
 
 
7822
static void shrinkwrapModifier_deformVertsEM(ModifierData *md, Object *ob, EditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 
7823
{
 
7824
        DerivedMesh *dm = NULL;
 
7825
        CustomDataMask dataMask = shrinkwrapModifier_requiredDataMask(md);
 
7826
 
 
7827
        if(dataMask)
 
7828
        {
 
7829
                if(derivedData) dm = CDDM_copy(derivedData);
 
7830
                else if(ob->type==OB_MESH) dm = CDDM_from_editmesh(editData, ob->data);
 
7831
                else return;
 
7832
 
 
7833
                if(dataMask & CD_MVERT)
 
7834
                {
 
7835
                        CDDM_apply_vert_coords(dm, vertexCos);
 
7836
                        CDDM_calc_normals(dm);
 
7837
                }
 
7838
        }
 
7839
 
 
7840
        shrinkwrapModifier_deform((ShrinkwrapModifierData*)md, ob, dm, vertexCos, numVerts);
 
7841
 
 
7842
        if(dm)
 
7843
                dm->release(dm);
 
7844
}
 
7845
 
 
7846
static void shrinkwrapModifier_updateDepgraph(ModifierData *md, DagForest *forest, Object *ob, DagNode *obNode)
 
7847
{
 
7848
        ShrinkwrapModifierData *smd = (ShrinkwrapModifierData*) md;
 
7849
 
 
7850
        if (smd->target)
 
7851
                dag_add_relation(forest, dag_get_node(forest, smd->target),   obNode, DAG_RL_OB_DATA | DAG_RL_DATA_DATA, "Shrinkwrap Modifier");
 
7852
 
 
7853
        if (smd->auxTarget)
 
7854
                dag_add_relation(forest, dag_get_node(forest, smd->auxTarget), obNode, DAG_RL_OB_DATA | DAG_RL_DATA_DATA, "Shrinkwrap Modifier");
 
7855
}
 
7856
 
 
7857
/* SimpleDeform */
 
7858
static void simpledeformModifier_initData(ModifierData *md)
 
7859
{
 
7860
        SimpleDeformModifierData *smd = (SimpleDeformModifierData*) md;
 
7861
 
 
7862
        smd->mode = MOD_SIMPLEDEFORM_MODE_TWIST;
 
7863
        smd->axis = 0;
 
7864
 
 
7865
        smd->origin   =  NULL;
 
7866
        smd->factor   =  0.35f;
 
7867
        smd->limit[0] =  0.0f;
 
7868
        smd->limit[1] =  1.0f;
 
7869
}
 
7870
 
 
7871
static void simpledeformModifier_copyData(ModifierData *md, ModifierData *target)
 
7872
{
 
7873
        SimpleDeformModifierData *smd  = (SimpleDeformModifierData*)md;
 
7874
        SimpleDeformModifierData *tsmd = (SimpleDeformModifierData*)target;
 
7875
 
 
7876
        tsmd->mode      = smd->mode;
 
7877
        tsmd->axis  = smd->axis;
 
7878
        tsmd->origin= smd->origin;
 
7879
        tsmd->factor= smd->factor;
 
7880
        memcpy(tsmd->limit, smd->limit, sizeof(tsmd->limit));
 
7881
}
 
7882
 
 
7883
static CustomDataMask simpledeformModifier_requiredDataMask(ModifierData *md)
 
7884
{
 
7885
        SimpleDeformModifierData *smd = (SimpleDeformModifierData *)md;
 
7886
        CustomDataMask dataMask = 0;
 
7887
 
 
7888
        /* ask for vertexgroups if we need them */
 
7889
        if(smd->vgroup_name[0])
 
7890
                dataMask |= (1 << CD_MDEFORMVERT);
 
7891
 
 
7892
        return dataMask;
 
7893
}
 
7894
 
 
7895
static void simpledeformModifier_foreachObjectLink(ModifierData *md, Object *ob, void (*walk)(void *userData, Object *ob, Object **obpoin), void *userData)
 
7896
{
 
7897
        SimpleDeformModifierData *smd  = (SimpleDeformModifierData*)md;
 
7898
        walk(userData, ob, &smd->origin);
 
7899
}
 
7900
 
 
7901
static void simpledeformModifier_updateDepgraph(ModifierData *md, DagForest *forest, Object *ob, DagNode *obNode)
 
7902
{
 
7903
        SimpleDeformModifierData *smd  = (SimpleDeformModifierData*)md;
 
7904
 
 
7905
        if (smd->origin)
 
7906
                dag_add_relation(forest, dag_get_node(forest, smd->origin), obNode, DAG_RL_OB_DATA, "SimpleDeform Modifier");
 
7907
}
 
7908
 
 
7909
static void simpledeformModifier_deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 
7910
{
 
7911
        DerivedMesh *dm = NULL;
 
7912
        CustomDataMask dataMask = simpledeformModifier_requiredDataMask(md);
 
7913
 
 
7914
        /* We implement requiredDataMask but thats not really usefull since mesh_calc_modifiers pass a NULL derivedData or without the modified vertexs applied */
 
7915
        if(dataMask)
 
7916
        {
 
7917
                if(derivedData) dm = CDDM_copy(derivedData);
 
7918
                else if(ob->type==OB_MESH) dm = CDDM_from_mesh(ob->data, ob);
 
7919
                else return;
 
7920
 
 
7921
                if(dataMask & CD_MVERT)
 
7922
                {
 
7923
                        CDDM_apply_vert_coords(dm, vertexCos);
 
7924
                        CDDM_calc_normals(dm);
 
7925
                }
 
7926
        }
 
7927
 
 
7928
        SimpleDeformModifier_do((SimpleDeformModifierData*)md, ob, dm, vertexCos, numVerts);
 
7929
 
 
7930
        if(dm)
 
7931
                dm->release(dm);
 
7932
 
 
7933
}
 
7934
 
 
7935
static void simpledeformModifier_deformVertsEM(ModifierData *md, Object *ob, EditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
 
7936
{
 
7937
        DerivedMesh *dm = NULL;
 
7938
        CustomDataMask dataMask = simpledeformModifier_requiredDataMask(md);
 
7939
 
 
7940
        /* We implement requiredDataMask but thats not really usefull since mesh_calc_modifiers pass a NULL derivedData or without the modified vertexs applied */
 
7941
        if(dataMask)
 
7942
        {
 
7943
                if(derivedData) dm = CDDM_copy(derivedData);
 
7944
                else if(ob->type==OB_MESH) dm = CDDM_from_editmesh(editData, ob->data);
 
7945
                else return;
 
7946
 
 
7947
                if(dataMask & CD_MVERT)
 
7948
                {
 
7949
                        CDDM_apply_vert_coords(dm, vertexCos);
 
7950
                        CDDM_calc_normals(dm);
 
7951
                }
 
7952
        }
 
7953
 
 
7954
        SimpleDeformModifier_do((SimpleDeformModifierData*)md, ob, dm, vertexCos, numVerts);
 
7955
 
 
7956
        if(dm)
 
7957
                dm->release(dm);
 
7958
}
 
7959
 
6997
7960
/***/
6998
7961
 
6999
7962
static ModifierTypeInfo typeArr[NUM_MODIFIER_TYPES];
7072
8035
                mti->copyData = buildModifier_copyData;
7073
8036
                mti->dependsOnTime = buildModifier_dependsOnTime;
7074
8037
                mti->applyModifier = buildModifier_applyModifier;
 
8038
                
 
8039
                mti = INIT_TYPE(Mask);
 
8040
                mti->type = eModifierTypeType_Nonconstructive;
 
8041
                mti->flags = eModifierTypeFlag_AcceptsMesh;
 
8042
                mti->copyData = maskModifier_copyData;
 
8043
                mti->requiredDataMask= maskModifier_requiredDataMask;
 
8044
                mti->foreachObjectLink = maskModifier_foreachObjectLink;
 
8045
                mti->updateDepgraph = maskModifier_updateDepgraph;
 
8046
                mti->applyModifier = maskModifier_applyModifier;
7075
8047
 
7076
8048
                mti = INIT_TYPE(Array);
7077
8049
                mti->type = eModifierTypeType_Constructive;
7127
8099
                mti->initData = displaceModifier_initData;
7128
8100
                mti->copyData = displaceModifier_copyData;
7129
8101
                mti->requiredDataMask = displaceModifier_requiredDataMask;
 
8102
                mti->dependsOnTime = displaceModifier_dependsOnTime;
7130
8103
                mti->foreachObjectLink = displaceModifier_foreachObjectLink;
7131
8104
                mti->foreachIDLink = displaceModifier_foreachIDLink;
7132
8105
                mti->updateDepgraph = displaceModifier_updateDepgraph;
7225
8198
                mti->flags = eModifierTypeFlag_AcceptsCVs
7226
8199
                                | eModifierTypeFlag_RequiresOriginalData;
7227
8200
                mti->deformVerts = softbodyModifier_deformVerts;
 
8201
                mti->dependsOnTime = softbodyModifier_dependsOnTime;
7228
8202
        
7229
8203
                mti = INIT_TYPE(Cloth);
7230
8204
                mti->type = eModifierTypeType_Nonconstructive;
7313
8287
                mti->dependsOnTime = explodeModifier_dependsOnTime;
7314
8288
                mti->requiredDataMask = explodeModifier_requiredDataMask;
7315
8289
                mti->applyModifier = explodeModifier_applyModifier;
 
8290
                
 
8291
                mti = INIT_TYPE(Fluidsim);
 
8292
                mti->type = eModifierTypeType_Nonconstructive
 
8293
                                | eModifierTypeFlag_RequiresOriginalData;
 
8294
                mti->flags = eModifierTypeFlag_AcceptsMesh;
 
8295
                mti->initData = fluidsimModifier_initData;
 
8296
                mti->freeData = fluidsimModifier_freeData;
 
8297
                mti->copyData = fluidsimModifier_copyData;
 
8298
                mti->dependsOnTime = fluidsimModifier_dependsOnTime;
 
8299
                mti->applyModifier = fluidsimModifier_applyModifier;
 
8300
                mti->updateDepgraph = fluidsimModifier_updateDepgraph;
 
8301
 
 
8302
                mti = INIT_TYPE(Shrinkwrap);
 
8303
                mti->type = eModifierTypeType_OnlyDeform;
 
8304
                mti->flags = eModifierTypeFlag_AcceptsMesh
 
8305
                                | eModifierTypeFlag_AcceptsCVs
 
8306
                                | eModifierTypeFlag_SupportsEditmode
 
8307
                                | eModifierTypeFlag_EnableInEditmode;
 
8308
                mti->initData = shrinkwrapModifier_initData;
 
8309
                mti->copyData = shrinkwrapModifier_copyData;
 
8310
                mti->requiredDataMask = shrinkwrapModifier_requiredDataMask;
 
8311
                mti->isDisabled = shrinkwrapModifier_isDisabled;
 
8312
                mti->foreachObjectLink = shrinkwrapModifier_foreachObjectLink;
 
8313
                mti->deformVerts = shrinkwrapModifier_deformVerts;
 
8314
                mti->deformVertsEM = shrinkwrapModifier_deformVertsEM;
 
8315
                mti->updateDepgraph = shrinkwrapModifier_updateDepgraph;
 
8316
 
 
8317
                mti = INIT_TYPE(SimpleDeform);
 
8318
                mti->type = eModifierTypeType_OnlyDeform;
 
8319
                mti->flags = eModifierTypeFlag_AcceptsMesh
 
8320
                                | eModifierTypeFlag_AcceptsCVs                          
 
8321
                                | eModifierTypeFlag_SupportsEditmode
 
8322
                                | eModifierTypeFlag_EnableInEditmode;
 
8323
                mti->initData = simpledeformModifier_initData;
 
8324
                mti->copyData = simpledeformModifier_copyData;
 
8325
                mti->requiredDataMask = simpledeformModifier_requiredDataMask;
 
8326
                mti->deformVerts = simpledeformModifier_deformVerts;
 
8327
                mti->deformVertsEM = simpledeformModifier_deformVertsEM;
 
8328
                mti->foreachObjectLink = simpledeformModifier_foreachObjectLink;
 
8329
                mti->updateDepgraph = simpledeformModifier_updateDepgraph;
7316
8330
 
7317
8331
                typeArrInit = 0;
7318
8332
#undef INIT_TYPE
7736
8750
}
7737
8751
 
7738
8752
 
 
8753