2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2005 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
|
|
|
|
2022-07-15 14:12:34 +02:00
|
|
|
#include "BLT_translation.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"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2020-09-25 12:49:18 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "MOD_modifiertypes.h"
|
|
|
|
|
|
2020-09-25 12:45:30 +02:00
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
2018-05-12 08:21:07 +02:00
|
|
|
static void deformVerts(ModifierData *UNUSED(md),
|
|
|
|
|
const ModifierEvalContext *ctx,
|
2018-06-22 15:45:46 +02:00
|
|
|
Mesh *UNUSED(mesh),
|
2018-05-12 08:04:56 +02:00
|
|
|
float (*vertexCos)[3],
|
2022-03-28 12:29:47 +11:00
|
|
|
int verts_num)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-05-01 17:33:04 +02:00
|
|
|
Key *key = BKE_key_from_object(ctx->object);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2013-01-03 06:47:44 +00:00
|
|
|
if (key && key->block.first) {
|
|
|
|
|
int deformedVerts_tot;
|
2015-01-07 02:02:55 +11:00
|
|
|
BKE_key_evaluate_object_ex(
|
2022-07-20 10:45:23 +02:00
|
|
|
ctx->object, &deformedVerts_tot, (float *)vertexCos, sizeof(*vertexCos) * verts_num, NULL);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-12 08:04:56 +02:00
|
|
|
static void deformMatrices(ModifierData *md,
|
2018-06-22 15:45:46 +02:00
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
|
Mesh *mesh,
|
2018-05-12 08:04:56 +02:00
|
|
|
float (*vertexCos)[3],
|
|
|
|
|
float (*defMats)[3][3],
|
2022-03-28 12:29:47 +11:00
|
|
|
int verts_num)
|
2011-01-31 20:02:51 +00:00
|
|
|
{
|
2018-05-01 17:33:04 +02:00
|
|
|
Key *key = BKE_key_from_object(ctx->object);
|
|
|
|
|
KeyBlock *kb = BKE_keyblock_from_object(ctx->object);
|
2011-01-31 20:02:51 +00:00
|
|
|
|
|
|
|
|
(void)vertexCos; /* unused */
|
|
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
if (kb && kb->totelem == verts_num && kb != key->refkey) {
|
2022-08-26 12:51:46 +10:00
|
|
|
float scale[3][3];
|
2011-02-13 03:21:27 +00:00
|
|
|
int a;
|
|
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (ctx->object->shapeflag & OB_SHAPE_LOCK) {
|
2018-05-01 17:33:04 +02:00
|
|
|
scale_m3_fl(scale, 1);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2011-01-31 20:02:51 +00:00
|
|
|
scale_m3_fl(scale, kb->curval);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2011-01-31 20:02:51 +00:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
for (a = 0; a < verts_num; a++) {
|
2011-01-31 20:02:51 +00:00
|
|
|
copy_m3_m3(defMats[a], scale);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2011-01-31 20:02:51 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
deformVerts(md, ctx, mesh, vertexCos, verts_num);
|
2011-01-31 20:02:51 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-12 08:04:56 +02:00
|
|
|
static void deformVertsEM(ModifierData *md,
|
2018-05-12 08:21:07 +02:00
|
|
|
const ModifierEvalContext *ctx,
|
2018-05-12 08:04:56 +02:00
|
|
|
struct BMEditMesh *UNUSED(editData),
|
2018-06-22 15:45:46 +02:00
|
|
|
Mesh *mesh,
|
2018-05-12 08:04:56 +02:00
|
|
|
float (*vertexCos)[3],
|
2022-03-28 12:29:47 +11:00
|
|
|
int verts_num)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-05-01 17:33:04 +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) {
|
2022-03-28 12:29:47 +11:00
|
|
|
deformVerts(md, ctx, mesh, vertexCos, verts_num);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-12 08:04:56 +02:00
|
|
|
static void deformMatricesEM(ModifierData *UNUSED(md),
|
2018-05-12 08:21:07 +02:00
|
|
|
const ModifierEvalContext *ctx,
|
2018-05-12 08:04:56 +02:00
|
|
|
struct BMEditMesh *UNUSED(editData),
|
2018-06-22 15:45:46 +02:00
|
|
|
Mesh *UNUSED(mesh),
|
2018-05-12 08:04:56 +02:00
|
|
|
float (*vertexCos)[3],
|
|
|
|
|
float (*defMats)[3][3],
|
2022-03-28 12:29:47 +11:00
|
|
|
int verts_num)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-05-01 17:33:04 +02:00
|
|
|
Key *key = BKE_key_from_object(ctx->object);
|
|
|
|
|
KeyBlock *kb = BKE_keyblock_from_object(ctx->object);
|
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
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
if (kb && kb->totelem == verts_num && kb != key->refkey) {
|
2022-08-26 12:51:46 +10:00
|
|
|
float scale[3][3];
|
2010-04-11 22:12:30 +00:00
|
|
|
scale_m3_fl(scale, kb->curval);
|
|
|
|
|
|
2022-08-26 12:51:46 +10:00
|
|
|
for (int a = 0; a < verts_num; a++) {
|
2010-04-11 22:12:30 +00:00
|
|
|
copy_m3_m3(defMats[a], scale);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_ShapeKey = {
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("ShapeKey"),
|
|
|
|
|
/*structName*/ "ShapeKeyModifierData",
|
|
|
|
|
/*structSize*/ sizeof(ShapeKeyModifierData),
|
|
|
|
|
/*srna*/ &RNA_Modifier,
|
|
|
|
|
/*type*/ eModifierTypeType_OnlyDeform,
|
|
|
|
|
/*flags*/ eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_AcceptsVertexCosOnly |
|
2012-05-06 13:38:33 +00:00
|
|
|
eModifierTypeFlag_SupportsEditmode,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*icon*/ ICON_DOT,
|
|
|
|
|
|
|
|
|
|
/*copyData*/ NULL,
|
|
|
|
|
|
|
|
|
|
/*deformVerts*/ deformVerts,
|
|
|
|
|
/*deformMatrices*/ deformMatrices,
|
|
|
|
|
/*deformVertsEM*/ deformVertsEM,
|
|
|
|
|
/*deformMatricesEM*/ deformMatricesEM,
|
|
|
|
|
/*modifyMesh*/ NULL,
|
|
|
|
|
/*modifyGeometrySet*/ NULL,
|
|
|
|
|
|
|
|
|
|
/*initData*/ NULL,
|
|
|
|
|
/*requiredDataMask*/ NULL,
|
|
|
|
|
/*freeData*/ NULL,
|
|
|
|
|
/*isDisabled*/ NULL,
|
|
|
|
|
/*updateDepsgraph*/ NULL,
|
|
|
|
|
/*dependsOnTime*/ NULL,
|
|
|
|
|
/*dependsOnNormals*/ NULL,
|
|
|
|
|
/*foreachIDLink*/ NULL,
|
|
|
|
|
/*foreachTexLink*/ NULL,
|
|
|
|
|
/*freeRuntimeData*/ NULL,
|
|
|
|
|
/*panelRegister*/ NULL,
|
|
|
|
|
/*blendWrite*/ NULL,
|
|
|
|
|
/*blendRead*/ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|