2010-04-11 22:12:30 +00:00
|
|
|
/*
|
2011-10-23 17:52:20 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 by the Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Daniel Dunbar
|
|
|
|
* Ton Roosendaal,
|
|
|
|
* Ben Batt,
|
|
|
|
* Brecht Van Lommel,
|
|
|
|
* Campbell Barton
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-02-25 13:57:17 +00:00
|
|
|
/** \file blender/modifiers/intern/MOD_shapekey.c
|
|
|
|
* \ingroup modifiers
|
|
|
|
*/
|
|
|
|
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "BLI_math.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
#include "DNA_key_types.h"
|
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
|
|
|
#include "BKE_key.h"
|
|
|
|
#include "BKE_particle.h"
|
|
|
|
|
|
|
|
#include "MOD_modifiertypes.h"
|
|
|
|
|
2010-10-14 06:29:17 +00:00
|
|
|
static void deformVerts(ModifierData *md, Object *ob,
|
2012-05-06 13:38:33 +00:00
|
|
|
DerivedMesh *UNUSED(derivedData),
|
|
|
|
float (*vertexCos)[3],
|
|
|
|
int numVerts,
|
2012-05-09 15:00:26 +00:00
|
|
|
ModifierApplyFlag UNUSED(flag))
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2013-01-03 06:47:44 +00:00
|
|
|
Key *key = BKE_key_from_object(ob);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2013-01-03 06:47:44 +00:00
|
|
|
if (key && key->block.first) {
|
|
|
|
int deformedVerts_tot;
|
2013-07-19 10:40:20 +00:00
|
|
|
BKE_key_evaluate_object_ex(md->scene, ob, &deformedVerts_tot,
|
|
|
|
(float *)vertexCos, sizeof(*vertexCos) * numVerts);
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-31 20:02:51 +00:00
|
|
|
static void deformMatrices(ModifierData *md, Object *ob, DerivedMesh *derivedData,
|
2012-05-06 13:38:33 +00:00
|
|
|
float (*vertexCos)[3], float (*defMats)[3][3], int numVerts)
|
2011-01-31 20:02:51 +00:00
|
|
|
{
|
2012-09-19 10:12:07 +00:00
|
|
|
Key *key = BKE_key_from_object(ob);
|
|
|
|
KeyBlock *kb = BKE_keyblock_from_object(ob);
|
2011-01-31 20:02:51 +00:00
|
|
|
float scale[3][3];
|
|
|
|
|
|
|
|
(void)vertexCos; /* unused */
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
if (kb && kb->totelem == numVerts && kb != key->refkey) {
|
2011-02-13 03:21:27 +00:00
|
|
|
int a;
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (ob->shapeflag & OB_SHAPE_LOCK) scale_m3_fl(scale, 1);
|
2011-01-31 20:02:51 +00:00
|
|
|
else scale_m3_fl(scale, kb->curval);
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
for (a = 0; a < numVerts; a++)
|
2011-01-31 20:02:51 +00:00
|
|
|
copy_m3_m3(defMats[a], scale);
|
|
|
|
}
|
|
|
|
|
2012-05-09 15:00:26 +00:00
|
|
|
deformVerts(md, ob, derivedData, vertexCos, numVerts, 0);
|
2011-01-31 20:02:51 +00:00
|
|
|
}
|
|
|
|
|
2010-10-14 06:29:17 +00:00
|
|
|
static void deformVertsEM(ModifierData *md, Object *ob,
|
2012-05-06 13:38:33 +00:00
|
|
|
struct BMEditMesh *UNUSED(editData),
|
|
|
|
DerivedMesh *derivedData,
|
|
|
|
float (*vertexCos)[3],
|
|
|
|
int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-09-19 10:12:07 +00:00
|
|
|
Key *key = BKE_key_from_object(ob);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (key && key->type == KEY_RELATIVE)
|
2012-05-09 15:00:26 +00:00
|
|
|
deformVerts(md, ob, derivedData, vertexCos, numVerts, 0);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2010-10-14 06:29:17 +00:00
|
|
|
static void deformMatricesEM(ModifierData *UNUSED(md), Object *ob,
|
2012-05-06 13:38:33 +00:00
|
|
|
struct BMEditMesh *UNUSED(editData),
|
|
|
|
DerivedMesh *UNUSED(derivedData),
|
|
|
|
float (*vertexCos)[3],
|
|
|
|
float (*defMats)[3][3],
|
|
|
|
int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-09-19 10:12:07 +00:00
|
|
|
Key *key = BKE_key_from_object(ob);
|
|
|
|
KeyBlock *kb = BKE_keyblock_from_object(ob);
|
2010-04-11 22:12:30 +00:00
|
|
|
float scale[3][3];
|
2011-01-31 20:02:51 +00:00
|
|
|
|
2010-10-17 06:38:56 +00:00
|
|
|
(void)vertexCos; /* unused */
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
if (kb && kb->totelem == numVerts && kb != key->refkey) {
|
2011-02-13 03:21:27 +00:00
|
|
|
int a;
|
2010-04-11 22:12:30 +00:00
|
|
|
scale_m3_fl(scale, kb->curval);
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
for (a = 0; a < numVerts; a++)
|
2010-04-11 22:12:30 +00:00
|
|
|
copy_m3_m3(defMats[a], scale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-24 05:45:54 +00:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
ModifierTypeInfo modifierType_ShapeKey = {
|
|
|
|
/* name */ "ShapeKey",
|
|
|
|
/* structName */ "ShapeKeyModifierData",
|
|
|
|
/* structSize */ sizeof(ShapeKeyModifierData),
|
|
|
|
/* type */ eModifierTypeType_OnlyDeform,
|
2012-05-06 13:38:33 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsCVs |
|
|
|
|
eModifierTypeFlag_SupportsEditmode,
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-02-13 10:52:18 +00:00
|
|
|
/* copyData */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* deformVerts */ deformVerts,
|
2011-01-31 20:02:51 +00:00
|
|
|
/* deformMatrices */ deformMatrices,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* deformVertsEM */ deformVertsEM,
|
|
|
|
/* deformMatricesEM */ deformMatricesEM,
|
2011-02-13 10:52:18 +00:00
|
|
|
/* applyModifier */ NULL,
|
|
|
|
/* applyModifierEM */ NULL,
|
|
|
|
/* initData */ NULL,
|
|
|
|
/* requiredDataMask */ NULL,
|
|
|
|
/* freeData */ NULL,
|
|
|
|
/* isDisabled */ NULL,
|
|
|
|
/* updateDepgraph */ NULL,
|
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
/* dependsOnNormals */ NULL,
|
|
|
|
/* foreachObjectLink */ NULL,
|
2011-08-12 18:11:22 +00:00
|
|
|
/* foreachIDLink */ NULL,
|
|
|
|
/* foreachTexLink */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|