SVN maintenance.
[blender.git] / source / blender / modifiers / intern / MOD_shapekey.c
1 /*
2 * $Id$
3 *
4 * ***** BEGIN GPL LICENSE BLOCK *****
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software  Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 * The Original Code is Copyright (C) 2005 by the Blender Foundation.
21 * All rights reserved.
22 *
23 * Contributor(s): Daniel Dunbar
24 *                 Ton Roosendaal,
25 *                 Ben Batt,
26 *                 Brecht Van Lommel,
27 *                 Campbell Barton
28 *
29 * ***** END GPL LICENSE BLOCK *****
30 *
31 */
32
33 #include "stddef.h"
34 #include "string.h"
35 #include "stdarg.h"
36 #include "math.h"
37 #include "float.h"
38
39 #include "BLI_kdtree.h"
40 #include "BLI_rand.h"
41 #include "BLI_uvproject.h"
42
43 #include "MEM_guardedalloc.h"
44
45 #include "DNA_armature_types.h"
46 #include "DNA_camera_types.h"
47 #include "DNA_curve_types.h"
48 #include "DNA_key_types.h"
49 #include "DNA_material_types.h"
50 #include "DNA_object_fluidsim.h"
51
52
53 #include "BKE_action.h"
54 #include "BKE_bmesh.h"
55 #include "BKE_cloth.h"
56 #include "BKE_cdderivedmesh.h"
57 #include "BKE_displist.h"
58 #include "BKE_fluidsim.h"
59 #include "BKE_global.h"
60 #include "BKE_multires.h"
61 #include "BKE_key.h"
62 #include "BKE_lattice.h"
63 #include "BKE_material.h"
64 #include "BKE_mesh.h"
65 #include "BKE_modifier.h"
66 #include "BKE_object.h"
67 #include "BKE_paint.h"
68 #include "BKE_particle.h"
69 #include "BKE_pointcache.h"
70 #include "BKE_scene.h"
71 #include "BKE_smoke.h"
72 #include "BKE_softbody.h"
73 #include "BKE_subsurf.h"
74 #include "BKE_texture.h"
75
76 #include "depsgraph_private.h"
77 #include "BKE_deform.h"
78 #include "BKE_shrinkwrap.h"
79
80 #include "LOD_decimation.h"
81
82 #include "CCGSubSurf.h"
83
84 #include "RE_shader_ext.h"
85
86 #include "MOD_modifiertypes.h"
87
88
89 static void deformVerts(
90                                          ModifierData *md, Object *ob, DerivedMesh *derivedData,
91           float (*vertexCos)[3], int numVerts, int useRenderParams, int isFinalCalc)
92 {
93         KeyBlock *kb= ob_get_keyblock(ob);
94         float (*deformedVerts)[3];
95
96         if(kb && kb->totelem == numVerts) {
97                 deformedVerts= (float(*)[3])do_ob_key(md->scene, ob);
98                 if(deformedVerts) {
99                         memcpy(vertexCos, deformedVerts, sizeof(float)*3*numVerts);
100                         MEM_freeN(deformedVerts);
101                 }
102         }
103 }
104
105 static void deformVertsEM(
106                                            ModifierData *md, Object *ob, EditMesh *editData,
107         DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
108 {
109         Key *key= ob_get_key(ob);
110
111         if(key && key->type == KEY_RELATIVE)
112                 deformVerts(md, ob, derivedData, vertexCos, numVerts, 0, 0);
113 }
114
115 static void deformMatricesEM(
116                                                   ModifierData *md, Object *ob, EditMesh *editData,
117            DerivedMesh *derivedData, float (*vertexCos)[3],
118                                                  float (*defMats)[3][3], int numVerts)
119 {
120         Key *key= ob_get_key(ob);
121         KeyBlock *kb= ob_get_keyblock(ob);
122         float scale[3][3];
123         int a;
124
125         if(kb && kb->totelem==numVerts && kb!=key->refkey) {
126                 scale_m3_fl(scale, kb->curval);
127
128                 for(a=0; a<numVerts; a++)
129                         copy_m3_m3(defMats[a], scale);
130         }
131 }
132
133
134 ModifierTypeInfo modifierType_ShapeKey = {
135         /* name */              "ShapeKey",
136         /* structName */        "ShapeKeyModifierData",
137         /* structSize */        sizeof(ShapeKeyModifierData),
138         /* type */              eModifierTypeType_OnlyDeform,
139         /* flags */             eModifierTypeFlag_AcceptsCVs
140                                                         | eModifierTypeFlag_SupportsEditmode,
141
142         /* copyData */          0,
143         /* deformVerts */       deformVerts,
144         /* deformVertsEM */     deformVertsEM,
145         /* deformMatricesEM */  deformMatricesEM,
146         /* applyModifier */     0,
147         /* applyModifierEM */   0,
148         /* initData */          0,
149         /* requiredDataMask */  0,
150         /* freeData */          0,
151         /* isDisabled */        0,
152         /* updateDepgraph */    0,
153         /* dependsOnTime */     0,
154         /* foreachObjectLink */ 0,
155         /* foreachIDLink */     0,
156 };