2010-04-11 22:12:30 +00:00
|
|
|
/*
|
2011-10-23 17:52:20 +00:00
|
|
|
* 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
|
2020-05-09 17:14:35 +10:00
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2011-10-23 17:52:20 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup modifiers
|
2011-02-25 13:57:17 +00:00
|
|
|
*/
|
|
|
|
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
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"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
2020-12-15 10:47:58 +11:00
|
|
|
#include "DNA_object_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
#include "BKE_key.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_particle.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2020-09-25 12:49:18 +02:00
|
|
|
#include "RNA_access.h"
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "MOD_modifiertypes.h"
|
|
|
|
|
2020-09-25 12:45:30 +02:00
|
|
|
#include "UI_resources.h"
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void deformVerts(ModifierData *UNUSED(md),
|
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
Mesh *UNUSED(mesh),
|
|
|
|
float (*vertexCos)[3],
|
|
|
|
int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Key *key = BKE_key_from_object(ctx->object);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (key && key->block.first) {
|
|
|
|
int deformedVerts_tot;
|
|
|
|
BKE_key_evaluate_object_ex(
|
|
|
|
ctx->object, &deformedVerts_tot, (float *)vertexCos, sizeof(*vertexCos) * numVerts);
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void deformMatrices(ModifierData *md,
|
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
Mesh *mesh,
|
|
|
|
float (*vertexCos)[3],
|
|
|
|
float (*defMats)[3][3],
|
|
|
|
int numVerts)
|
2011-01-31 20:02:51 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Key *key = BKE_key_from_object(ctx->object);
|
|
|
|
KeyBlock *kb = BKE_keyblock_from_object(ctx->object);
|
|
|
|
float scale[3][3];
|
2011-01-31 20:02:51 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
(void)vertexCos; /* unused */
|
2011-01-31 20:02:51 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (kb && kb->totelem == numVerts && kb != key->refkey) {
|
|
|
|
int a;
|
2011-02-13 03:21:27 +00:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (ctx->object->shapeflag & OB_SHAPE_LOCK) {
|
2019-04-17 06:17:24 +02:00
|
|
|
scale_m3_fl(scale, 1);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
scale_m3_fl(scale, kb->curval);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2011-01-31 20:02:51 +00:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
for (a = 0; a < numVerts; a++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
copy_m3_m3(defMats[a], scale);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-01-31 20:02:51 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
deformVerts(md, ctx, mesh, vertexCos, numVerts);
|
2011-01-31 20:02:51 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void deformVertsEM(ModifierData *md,
|
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
struct BMEditMesh *UNUSED(editData),
|
|
|
|
Mesh *mesh,
|
|
|
|
float (*vertexCos)[3],
|
|
|
|
int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Key *key = BKE_key_from_object(ctx->object);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (key && key->type == KEY_RELATIVE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
deformVerts(md, ctx, mesh, vertexCos, numVerts);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void deformMatricesEM(ModifierData *UNUSED(md),
|
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
struct BMEditMesh *UNUSED(editData),
|
|
|
|
Mesh *UNUSED(mesh),
|
|
|
|
float (*vertexCos)[3],
|
|
|
|
float (*defMats)[3][3],
|
|
|
|
int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Key *key = BKE_key_from_object(ctx->object);
|
|
|
|
KeyBlock *kb = BKE_keyblock_from_object(ctx->object);
|
|
|
|
float scale[3][3];
|
2011-01-31 20:02:51 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
(void)vertexCos; /* unused */
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (kb && kb->totelem == numVerts && kb != key->refkey) {
|
|
|
|
int a;
|
|
|
|
scale_m3_fl(scale, kb->curval);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
for (a = 0; a < numVerts; a++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
copy_m3_m3(defMats[a], scale);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_ShapeKey = {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* name */ "ShapeKey",
|
|
|
|
/* structName */ "ShapeKeyModifierData",
|
|
|
|
/* structSize */ sizeof(ShapeKeyModifierData),
|
2020-09-25 12:49:18 +02:00
|
|
|
/* srna */ &RNA_Modifier,
|
2019-04-17 06:17:24 +02:00
|
|
|
/* type */ eModifierTypeType_OnlyDeform,
|
2020-04-21 13:09:41 +02:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_AcceptsVertexCosOnly |
|
2019-04-17 06:17:24 +02:00
|
|
|
eModifierTypeFlag_SupportsEditmode,
|
2020-09-25 12:45:30 +02:00
|
|
|
/* icon */ ICON_DOT,
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* copyData */ NULL,
|
|
|
|
|
|
|
|
/* deformVerts */ deformVerts,
|
|
|
|
/* deformMatrices */ deformMatrices,
|
|
|
|
/* deformVertsEM */ deformVertsEM,
|
|
|
|
/* deformMatricesEM */ deformMatricesEM,
|
2020-04-21 13:09:41 +02:00
|
|
|
/* modifyMesh */ NULL,
|
|
|
|
/* modifyHair */ NULL,
|
2020-12-10 14:35:02 +01:00
|
|
|
/* modifyGeometrySet */ NULL,
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* initData */ NULL,
|
|
|
|
/* requiredDataMask */ NULL,
|
|
|
|
/* freeData */ NULL,
|
|
|
|
/* isDisabled */ NULL,
|
|
|
|
/* updateDepsgraph */ NULL,
|
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
/* dependsOnNormals */ NULL,
|
|
|
|
/* foreachIDLink */ NULL,
|
|
|
|
/* foreachTexLink */ NULL,
|
|
|
|
/* freeRuntimeData */ NULL,
|
2020-06-05 10:41:03 -04:00
|
|
|
/* panelRegister */ NULL,
|
2020-06-15 17:37:07 +02:00
|
|
|
/* blendWrite */ NULL,
|
|
|
|
/* blendRead */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|