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:56:24 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_math.h"
|
2021-02-14 14:20:51 +01:00
|
|
|
#include "BLI_simd.h"
|
2019-02-25 11:56:24 +01:00
|
|
|
#include "BLI_task.h"
|
|
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
#include "DNA_defaults.h"
|
2018-05-08 11:33:31 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_object_types.h"
|
2014-04-15 18:36:24 +06:00
|
|
|
#include "DNA_scene_types.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "DNA_screen_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BKE_context.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_deform.h"
|
|
|
|
|
#include "BKE_editmesh.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
|
|
|
|
#include "BKE_lib_query.h"
|
2018-05-08 11:33:31 +02:00
|
|
|
#include "BKE_mesh.h"
|
2018-12-07 11:17:25 +01:00
|
|
|
#include "BKE_mesh_runtime.h"
|
2020-06-10 22:32:06 +10:00
|
|
|
#include "BKE_mesh_wrapper.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_modifier.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BKE_screen.h"
|
|
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
2020-06-16 17:17:43 +02:00
|
|
|
#include "BLO_read_write.h"
|
|
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "RNA_access.h"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-02-13 20:35:29 +11:00
|
|
|
#include "DEG_depsgraph.h"
|
2018-06-22 15:03:42 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2018-02-13 20:35:29 +11:00
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "MOD_ui_common.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "MOD_util.h"
|
|
|
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(mmd, modifier));
|
|
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(mmd, DNA_struct_default_get(MeshDeformModifierData), modifier);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void freeData(ModifierData *md)
|
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (mmd->bindinfluences) {
|
2012-03-24 06:24:53 +00:00
|
|
|
MEM_freeN(mmd->bindinfluences);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->bindoffsets) {
|
2012-03-24 06:24:53 +00:00
|
|
|
MEM_freeN(mmd->bindoffsets);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->bindcagecos) {
|
2012-03-24 06:24:53 +00:00
|
|
|
MEM_freeN(mmd->bindcagecos);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->dyngrid) {
|
2012-03-24 06:24:53 +00:00
|
|
|
MEM_freeN(mmd->dyngrid);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->dyninfluences) {
|
2012-03-24 06:24:53 +00:00
|
|
|
MEM_freeN(mmd->dyninfluences);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->dynverts) {
|
2012-03-24 06:24:53 +00:00
|
|
|
MEM_freeN(mmd->dynverts);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->bindweights) {
|
2012-05-06 13:38:33 +00:00
|
|
|
MEM_freeN(mmd->bindweights); /* deprecated */
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->bindcos) {
|
2012-05-06 13:38:33 +00:00
|
|
|
MEM_freeN(mmd->bindcos); /* deprecated */
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-04 12:45:30 +02:00
|
|
|
static void copyData(const ModifierData *md, ModifierData *target, const int flag)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-05-08 15:04:10 +02:00
|
|
|
const MeshDeformModifierData *mmd = (const MeshDeformModifierData *)md;
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *tmmd = (MeshDeformModifierData *)target;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_copydata_generic(md, target, flag);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (mmd->bindinfluences) {
|
2014-11-18 11:28:40 +01:00
|
|
|
tmmd->bindinfluences = MEM_dupallocN(mmd->bindinfluences);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->bindoffsets) {
|
2014-11-18 11:28:40 +01:00
|
|
|
tmmd->bindoffsets = MEM_dupallocN(mmd->bindoffsets);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->bindcagecos) {
|
2014-11-18 11:28:40 +01:00
|
|
|
tmmd->bindcagecos = MEM_dupallocN(mmd->bindcagecos);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->dyngrid) {
|
2014-11-18 11:28:40 +01:00
|
|
|
tmmd->dyngrid = MEM_dupallocN(mmd->dyngrid);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->dyninfluences) {
|
2014-11-18 11:28:40 +01:00
|
|
|
tmmd->dyninfluences = MEM_dupallocN(mmd->dyninfluences);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->dynverts) {
|
2014-11-18 11:28:40 +01:00
|
|
|
tmmd->dynverts = MEM_dupallocN(mmd->dynverts);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->bindweights) {
|
2017-06-19 12:55:11 +02:00
|
|
|
tmmd->bindweights = MEM_dupallocN(mmd->bindweights); /* deprecated */
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->bindcos) {
|
2017-06-19 12:55:11 +02:00
|
|
|
tmmd->bindcos = MEM_dupallocN(mmd->bindcos); /* deprecated */
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:49:40 -05:00
|
|
|
static void requiredDataMask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
|
2018-06-17 17:04:27 +02:00
|
|
|
{
|
2010-04-11 22:12:30 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
|
|
|
|
|
|
|
|
|
|
/* ask for vertexgroups if we need them */
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
if (mmd->defgrp_name[0] != '\0') {
|
|
|
|
|
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
|
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-10 12:14:08 +02:00
|
|
|
static bool isDisabled(const struct Scene *UNUSED(scene),
|
|
|
|
|
ModifierData *md,
|
|
|
|
|
bool UNUSED(useRenderParams))
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-08-23 15:50:53 +02:00
|
|
|
/* The object type check is only needed here in case we have a placeholder
|
|
|
|
|
* object assigned (because the library containing the mesh is missing).
|
|
|
|
|
*
|
2019-08-31 01:19:22 +10:00
|
|
|
* In other cases it should be impossible to have a type mismatch.
|
2019-08-23 15:50:53 +02:00
|
|
|
*/
|
|
|
|
|
return !mmd->object || mmd->object->type != OB_MESH;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-01 18:05:23 +02:00
|
|
|
static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2020-10-01 18:05:23 +02:00
|
|
|
walk(userData, ob, (ID **)&mmd->object, IDWALK_CB_NOP);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2018-02-22 12:54:06 +01:00
|
|
|
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
{
|
|
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
|
|
|
|
|
if (mmd->object != NULL) {
|
2019-11-21 12:20:49 +01:00
|
|
|
DEG_add_object_relation(ctx->node, mmd->object, DEG_OB_COMP_TRANSFORM, "Mesh Deform Modifier");
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(ctx->node, mmd->object, DEG_OB_COMP_GEOMETRY, "Mesh Deform Modifier");
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
}
|
2020-04-20 11:08:49 +02:00
|
|
|
/* We need own transformation as well. */
|
2022-08-04 12:11:31 +02:00
|
|
|
DEG_add_depends_on_transform_relation(ctx->node, "Mesh Deform Modifier");
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:08:33 +11:00
|
|
|
static float meshdeform_dynamic_bind(MeshDeformModifierData *mmd, float (*dco)[3], float vec[3])
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
|
MDefCell *cell;
|
|
|
|
|
MDefInfluence *inf;
|
2014-10-21 11:37:29 +02:00
|
|
|
float gridvec[3], dvec[3], ivec[3], wx, wy, wz;
|
2010-04-11 22:12:30 +00:00
|
|
|
float weight, cageweight, totweight, *cageco;
|
|
|
|
|
int i, j, a, x, y, z, size;
|
2021-02-14 14:20:51 +01:00
|
|
|
#ifdef BLI_HAVE_SSE2
|
2014-10-21 11:37:29 +02:00
|
|
|
__m128 co = _mm_setzero_ps();
|
|
|
|
|
#else
|
|
|
|
|
float co[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
#endif
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
totweight = 0.0f;
|
|
|
|
|
size = mmd->dyngridsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
|
gridvec[i] = (vec[i] - mmd->dyncellmin[i] - mmd->dyncellwidth * 0.5f) / mmd->dyncellwidth;
|
2012-05-03 21:35:04 +00:00
|
|
|
ivec[i] = (int)gridvec[i];
|
|
|
|
|
dvec[i] = gridvec[i] - ivec[i];
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
for (i = 0; i < 8; i++) {
|
2012-05-03 21:35:04 +00:00
|
|
|
if (i & 1) {
|
|
|
|
|
x = ivec[0] + 1;
|
|
|
|
|
wx = dvec[0];
|
|
|
|
|
}
|
2012-05-06 13:38:33 +00:00
|
|
|
else {
|
|
|
|
|
x = ivec[0];
|
|
|
|
|
wx = 1.0f - dvec[0];
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-03 21:35:04 +00:00
|
|
|
if (i & 2) {
|
|
|
|
|
y = ivec[1] + 1;
|
|
|
|
|
wy = dvec[1];
|
2012-05-06 13:38:33 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
y = ivec[1];
|
|
|
|
|
wy = 1.0f - dvec[1];
|
2012-05-03 21:35:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-03 21:35:04 +00:00
|
|
|
if (i & 4) {
|
|
|
|
|
z = ivec[2] + 1;
|
|
|
|
|
wz = dvec[2];
|
2012-05-06 13:38:33 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
z = ivec[2];
|
|
|
|
|
wz = 1.0f - dvec[2];
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-03 21:35:04 +00:00
|
|
|
CLAMP(x, 0, size - 1);
|
|
|
|
|
CLAMP(y, 0, size - 1);
|
|
|
|
|
CLAMP(z, 0, size - 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
a = x + y * size + z * size * size;
|
|
|
|
|
weight = wx * wy * wz;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
cell = &mmd->dyngrid[a];
|
|
|
|
|
inf = mmd->dyninfluences + cell->offset;
|
2022-03-28 12:29:47 +11:00
|
|
|
for (j = 0; j < cell->influences_num; j++, inf++) {
|
2012-05-06 13:38:33 +00:00
|
|
|
cageco = dco[inf->vertex];
|
|
|
|
|
cageweight = weight * inf->weight;
|
2021-02-14 14:20:51 +01:00
|
|
|
#ifdef BLI_HAVE_SSE2
|
2014-10-21 11:37:29 +02:00
|
|
|
{
|
|
|
|
|
__m128 cageweight_r = _mm_set1_ps(cageweight);
|
|
|
|
|
/* This will load one extra element, this is ok because
|
2014-10-23 10:38:14 +02:00
|
|
|
* we ignore that part of register anyway.
|
2014-10-21 11:37:29 +02:00
|
|
|
*/
|
|
|
|
|
__m128 cageco_r = _mm_loadu_ps(cageco);
|
|
|
|
|
co = _mm_add_ps(co, _mm_mul_ps(cageco_r, cageweight_r));
|
|
|
|
|
}
|
|
|
|
|
#else
|
2012-05-06 13:38:33 +00:00
|
|
|
co[0] += cageweight * cageco[0];
|
|
|
|
|
co[1] += cageweight * cageco[1];
|
|
|
|
|
co[2] += cageweight * cageco[2];
|
2014-10-21 11:37:29 +02:00
|
|
|
#endif
|
2010-04-11 22:12:30 +00:00
|
|
|
totweight += cageweight;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-14 14:20:51 +01:00
|
|
|
#ifdef BLI_HAVE_SSE2
|
2014-10-23 10:38:14 +02:00
|
|
|
copy_v3_v3(vec, (float *)&co);
|
2014-10-21 11:37:29 +02:00
|
|
|
#else
|
2010-04-12 00:36:50 +00:00
|
|
|
copy_v3_v3(vec, co);
|
2014-10-21 11:37:29 +02:00
|
|
|
#endif
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
|
return totweight;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 11:56:52 +02:00
|
|
|
typedef struct MeshdeformUserdata {
|
|
|
|
|
/*const*/ MeshDeformModifierData *mmd;
|
|
|
|
|
const MDeformVert *dvert;
|
|
|
|
|
/*const*/ float (*dco)[3];
|
|
|
|
|
int defgrp_index;
|
|
|
|
|
float (*vertexCos)[3];
|
|
|
|
|
float (*cagemat)[4];
|
|
|
|
|
float (*icagemat)[3];
|
|
|
|
|
} MeshdeformUserdata;
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void meshdeform_vert_task(void *__restrict userdata,
|
|
|
|
|
const int iter,
|
2019-07-30 14:56:47 +02:00
|
|
|
const TaskParallelTLS *__restrict UNUSED(tls))
|
2014-10-22 11:56:52 +02:00
|
|
|
{
|
|
|
|
|
MeshdeformUserdata *data = userdata;
|
|
|
|
|
/*const*/ MeshDeformModifierData *mmd = data->mmd;
|
|
|
|
|
const MDeformVert *dvert = data->dvert;
|
|
|
|
|
const int defgrp_index = data->defgrp_index;
|
|
|
|
|
const int *offsets = mmd->bindoffsets;
|
2018-06-01 11:02:54 +02:00
|
|
|
const MDefInfluence *__restrict influences = mmd->bindinfluences;
|
|
|
|
|
/*const*/ float(*__restrict dco)[3] = data->dco;
|
2014-10-22 11:56:52 +02:00
|
|
|
float(*vertexCos)[3] = data->vertexCos;
|
|
|
|
|
float co[3];
|
|
|
|
|
float weight, totweight, fac = 1.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) {
|
|
|
|
|
if (!mmd->dynverts[iter]) {
|
2014-10-22 11:56:52 +02:00
|
|
|
return;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-22 11:56:52 +02:00
|
|
|
if (dvert) {
|
2020-03-06 12:50:56 +11:00
|
|
|
fac = BKE_defvert_find_weight(&dvert[iter], defgrp_index);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-22 11:56:52 +02:00
|
|
|
if (mmd->flag & MOD_MDEF_INVERT_VGROUP) {
|
|
|
|
|
fac = 1.0f - fac;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-22 11:56:52 +02:00
|
|
|
if (fac <= 0.0f) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-22 11:56:52 +02:00
|
|
|
if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) {
|
|
|
|
|
/* transform coordinate into cage's local space */
|
|
|
|
|
mul_v3_m4v3(co, data->cagemat, vertexCos[iter]);
|
|
|
|
|
totweight = meshdeform_dynamic_bind(mmd, dco, co);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
totweight = 0.0f;
|
|
|
|
|
zero_v3(co);
|
2018-06-01 11:02:54 +02:00
|
|
|
int start = offsets[iter];
|
|
|
|
|
int end = offsets[iter + 1];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 11:02:54 +02:00
|
|
|
for (int a = start; a < end; a++) {
|
2014-10-22 11:56:52 +02:00
|
|
|
weight = influences[a].weight;
|
|
|
|
|
madd_v3_v3fl(co, dco[influences[a].vertex], weight);
|
|
|
|
|
totweight += weight;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-22 11:56:52 +02:00
|
|
|
if (totweight > 0.0f) {
|
|
|
|
|
mul_v3_fl(co, fac / totweight);
|
|
|
|
|
mul_m3_v3(data->icagemat, co);
|
2020-08-26 21:01:38 +10:00
|
|
|
add_v3_v3(vertexCos[iter], co);
|
2014-10-22 11:56:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
static void meshdeformModifier_do(ModifierData *md,
|
2018-05-30 11:34:08 +02:00
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
|
Mesh *mesh,
|
2012-08-23 16:17:47 +00:00
|
|
|
float (*vertexCos)[3],
|
2022-03-28 12:29:47 +11:00
|
|
|
const int verts_num)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
|
2018-05-30 11:34:08 +02:00
|
|
|
Object *ob = ctx->object;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 11:33:31 +02:00
|
|
|
Mesh *cagemesh;
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
const MDeformVert *dvert = NULL;
|
2010-04-11 22:12:30 +00:00
|
|
|
float imat[4][4], cagemat[4][4], iobmat[4][4], icagemat[3][3], cmat[4][4];
|
2020-08-26 23:20:37 +10:00
|
|
|
float(*dco)[3] = NULL, (*bindcagecos)[3];
|
2022-03-28 12:29:47 +11:00
|
|
|
int a, cage_verts_num, defgrp_index;
|
2014-10-22 11:56:52 +02:00
|
|
|
MeshdeformUserdata data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-07 11:17:25 +01:00
|
|
|
static int recursive_bind_sentinel = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (mmd->object == NULL || (mmd->bindcagecos == NULL && mmd->bindfunc == NULL)) {
|
2010-04-11 22:12:30 +00:00
|
|
|
return;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-22 15:52:14 +02:00
|
|
|
/* Get cage mesh.
|
2014-04-15 18:36:24 +06:00
|
|
|
*
|
|
|
|
|
* Only do this is the target object is in edit mode by itself, meaning
|
|
|
|
|
* we don't allow linked edit meshes here.
|
2018-10-09 16:52:46 +11:00
|
|
|
* This is because editbmesh_get_mesh_cage_and_final() might easily
|
2014-04-15 18:36:24 +06:00
|
|
|
* conflict with the thread which evaluates object which is in the edit
|
|
|
|
|
* mode for this mesh.
|
|
|
|
|
*
|
|
|
|
|
* We'll support this case once granular dependency graph is landed.
|
|
|
|
|
*/
|
2019-03-26 11:25:07 +01:00
|
|
|
Object *ob_target = mmd->object;
|
2022-07-20 15:57:16 +02:00
|
|
|
cagemesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(ob_target);
|
2018-05-30 11:34:08 +02:00
|
|
|
if (cagemesh == NULL) {
|
2020-10-26 17:07:58 +11:00
|
|
|
BKE_modifier_set_error(ctx->object, md, "Cannot get mesh from cage object");
|
2010-04-11 22:12:30 +00:00
|
|
|
return;
|
2010-05-26 18:16:16 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* compute matrices to go in and out of cage object space */
|
2022-10-24 14:16:37 +02:00
|
|
|
invert_m4_m4(imat, ob_target->object_to_world);
|
|
|
|
|
mul_m4_m4m4(cagemat, imat, ob->object_to_world);
|
2013-05-26 18:36:25 +00:00
|
|
|
mul_m4_m4m4(cmat, mmd->bindmat, cagemat);
|
2010-04-11 22:12:30 +00:00
|
|
|
invert_m4_m4(iobmat, cmat);
|
|
|
|
|
copy_m3_m4(icagemat, iobmat);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* bind weights if needed */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (!mmd->bindcagecos) {
|
2021-06-24 15:56:58 +10:00
|
|
|
/* progress bar redraw can make this recursive. */
|
2019-04-04 14:42:33 +02:00
|
|
|
if (!DEG_is_active(ctx->depsgraph)) {
|
2020-10-26 17:07:58 +11:00
|
|
|
BKE_modifier_set_error(ob, md, "Attempt to bind from inactive dependency graph");
|
2019-04-04 14:42:33 +02:00
|
|
|
goto finally;
|
|
|
|
|
}
|
2018-12-07 11:17:25 +01:00
|
|
|
if (!recursive_bind_sentinel) {
|
|
|
|
|
recursive_bind_sentinel = 1;
|
2022-03-28 12:29:47 +11:00
|
|
|
mmd->bindfunc(ob, mmd, cagemesh, (float *)vertexCos, verts_num, cagemat);
|
2018-12-07 11:17:25 +01:00
|
|
|
recursive_bind_sentinel = 0;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-07 11:17:25 +01:00
|
|
|
goto finally;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* verify we have compatible weights */
|
2022-03-28 12:29:47 +11:00
|
|
|
cage_verts_num = BKE_mesh_wrapper_vert_len(cagemesh);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
if (mmd->verts_num != verts_num) {
|
|
|
|
|
BKE_modifier_set_error(ob, md, "Vertices changed from %d to %d", mmd->verts_num, verts_num);
|
2018-12-07 11:17:25 +01:00
|
|
|
goto finally;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2022-03-28 12:29:47 +11:00
|
|
|
else if (mmd->cage_verts_num != cage_verts_num) {
|
2020-07-22 16:21:33 +10:00
|
|
|
BKE_modifier_set_error(
|
2022-03-28 12:29:47 +11:00
|
|
|
ob, md, "Cage vertices changed from %d to %d", mmd->cage_verts_num, cage_verts_num);
|
2018-12-07 11:17:25 +01:00
|
|
|
goto finally;
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
|
else if (mmd->bindcagecos == NULL) {
|
2020-10-26 17:07:58 +11:00
|
|
|
BKE_modifier_set_error(ob, md, "Bind data missing");
|
2018-12-07 11:17:25 +01:00
|
|
|
goto finally;
|
2010-05-26 18:16:16 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-21 11:37:29 +02:00
|
|
|
/* We allocate 1 element extra to make it possible to
|
|
|
|
|
* load the values to SSE registers, which are float4.
|
|
|
|
|
*/
|
2022-03-28 12:29:47 +11:00
|
|
|
dco = MEM_calloc_arrayN((cage_verts_num + 1), sizeof(*dco), "MDefDco");
|
|
|
|
|
zero_v3(dco[cage_verts_num]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-26 23:20:37 +10:00
|
|
|
/* setup deformation data */
|
2022-03-28 12:29:47 +11:00
|
|
|
BKE_mesh_wrapper_vert_coords_copy(cagemesh, dco, cage_verts_num);
|
2020-08-26 23:20:37 +10:00
|
|
|
bindcagecos = (float(*)[3])mmd->bindcagecos;
|
|
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
for (a = 0; a < cage_verts_num; a++) {
|
2021-11-13 13:07:13 +11:00
|
|
|
/* Get cage vertex in world-space with binding transform. */
|
2020-08-26 23:28:44 +10:00
|
|
|
float co[3];
|
|
|
|
|
mul_v3_m4v3(co, mmd->bindmat, dco[a]);
|
2020-08-26 21:01:38 +10:00
|
|
|
/* compute difference with world space bind coord */
|
|
|
|
|
sub_v3_v3v3(dco[a], co, bindcagecos[a]);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-06-29 19:02:19 +02:00
|
|
|
MOD_get_vgroup(ob, mesh, mmd->defgrp_name, &dvert, &defgrp_index);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-22 11:56:52 +02:00
|
|
|
/* Initialize data to be pass to the for body function. */
|
|
|
|
|
data.mmd = mmd;
|
|
|
|
|
data.dvert = dvert;
|
|
|
|
|
data.dco = dco;
|
|
|
|
|
data.defgrp_index = defgrp_index;
|
|
|
|
|
data.vertexCos = vertexCos;
|
|
|
|
|
data.cagemat = cagemat;
|
|
|
|
|
data.icagemat = icagemat;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-22 11:56:52 +02:00
|
|
|
/* Do deformation. */
|
2019-07-30 14:56:47 +02:00
|
|
|
TaskParallelSettings settings;
|
2018-01-08 11:35:48 +01:00
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
2018-01-11 14:51:30 +01:00
|
|
|
settings.min_iter_per_thread = 16;
|
2022-03-28 12:29:47 +11:00
|
|
|
BLI_task_parallel_range(0, verts_num, &data, meshdeform_vert_task, &settings);
|
2014-10-22 11:56:52 +02:00
|
|
|
|
2018-12-07 11:17:25 +01:00
|
|
|
finally:
|
|
|
|
|
MEM_SAFE_FREE(dco);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-12 08:04:56 +02:00
|
|
|
static void deformVerts(ModifierData *md,
|
2018-05-12 08:21:07 +02:00
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
|
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
|
|
|
{
|
2022-08-12 22:08:48 +10:00
|
|
|
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, verts_num, false);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-06-29 19:02:19 +02:00
|
|
|
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
|
2013-11-04 23:33:23 +00:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
meshdeformModifier_do(md, ctx, mesh_src, vertexCos, verts_num);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-11-27 20:10:41 +01:00
|
|
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
2018-05-08 11:33:31 +02:00
|
|
|
BKE_id_free(NULL, mesh_src);
|
|
|
|
|
}
|
2010-04-11 22:12:30 +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-11-27 20:10:41 +01:00
|
|
|
struct BMEditMesh *editData,
|
2018-05-12 08:21:07 +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
|
|
|
{
|
2022-08-12 22:08:48 +10:00
|
|
|
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, verts_num, false);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-02-09 11:30:25 +11:00
|
|
|
/* TODO(@ideasman42): use edit-mode data only (remove this line). */
|
2020-05-25 20:16:42 +10:00
|
|
|
if (mesh_src != NULL) {
|
|
|
|
|
BKE_mesh_wrapper_ensure_mdata(mesh_src);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
meshdeformModifier_do(md, ctx, mesh_src, vertexCos, verts_num);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-11-27 20:10:41 +01:00
|
|
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
2018-05-08 11:33:31 +02:00
|
|
|
BKE_id_free(NULL, mesh_src);
|
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-27 13:49:53 +00:00
|
|
|
#define MESHDEFORM_MIN_INFLUENCE 0.00001f
|
2010-04-23 11:19:06 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
void BKE_modifier_mdef_compact_influences(ModifierData *md)
|
2010-04-23 11:19:06 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
|
2010-04-23 11:19:06 +00:00
|
|
|
float weight, *weights, totweight;
|
2022-03-28 12:29:47 +11:00
|
|
|
int influences_num, verts_num, cage_verts_num, a, b;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
weights = mmd->bindweights;
|
2019-04-22 09:15:10 +10:00
|
|
|
if (!weights) {
|
2010-04-23 11:19:06 +00:00
|
|
|
return;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
verts_num = mmd->verts_num;
|
|
|
|
|
cage_verts_num = mmd->cage_verts_num;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-23 11:19:06 +00:00
|
|
|
/* count number of influences above threshold */
|
2022-03-28 12:29:47 +11:00
|
|
|
for (b = 0; b < verts_num; b++) {
|
|
|
|
|
for (a = 0; a < cage_verts_num; a++) {
|
|
|
|
|
weight = weights[a + b * cage_verts_num];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (weight > MESHDEFORM_MIN_INFLUENCE) {
|
2022-03-28 12:29:47 +11:00
|
|
|
mmd->influences_num++;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-23 11:19:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-23 11:19:06 +00:00
|
|
|
/* allocate bind influences */
|
2018-01-14 22:14:20 +01:00
|
|
|
mmd->bindinfluences = MEM_calloc_arrayN(
|
2022-03-28 12:29:47 +11:00
|
|
|
mmd->influences_num, sizeof(MDefInfluence), "MDefBindInfluence");
|
|
|
|
|
mmd->bindoffsets = MEM_calloc_arrayN((verts_num + 1), sizeof(int), "MDefBindOffset");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-23 11:19:06 +00:00
|
|
|
/* write influences */
|
2022-03-28 12:29:47 +11:00
|
|
|
influences_num = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
for (b = 0; b < verts_num; b++) {
|
|
|
|
|
mmd->bindoffsets[b] = influences_num;
|
2012-05-06 13:38:33 +00:00
|
|
|
totweight = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-23 11:19:06 +00:00
|
|
|
/* sum total weight */
|
2022-03-28 12:29:47 +11:00
|
|
|
for (a = 0; a < cage_verts_num; a++) {
|
|
|
|
|
weight = weights[a + b * cage_verts_num];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (weight > MESHDEFORM_MIN_INFLUENCE) {
|
2010-04-23 11:19:06 +00:00
|
|
|
totweight += weight;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-23 11:19:06 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-23 11:19:06 +00:00
|
|
|
/* assign weights normalized */
|
2022-03-28 12:29:47 +11:00
|
|
|
for (a = 0; a < cage_verts_num; a++) {
|
|
|
|
|
weight = weights[a + b * cage_verts_num];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (weight > MESHDEFORM_MIN_INFLUENCE) {
|
2022-03-28 12:29:47 +11:00
|
|
|
mmd->bindinfluences[influences_num].weight = weight / totweight;
|
|
|
|
|
mmd->bindinfluences[influences_num].vertex = a;
|
|
|
|
|
influences_num++;
|
2010-04-23 11:19:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
mmd->bindoffsets[b] = influences_num;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-23 11:19:06 +00:00
|
|
|
/* free */
|
|
|
|
|
MEM_freeN(mmd->bindweights);
|
2012-05-06 13:38:33 +00:00
|
|
|
mmd->bindweights = NULL;
|
2010-04-23 11:19:06 +00:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *col;
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
|
|
|
|
PointerRNA ob_ptr;
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
bool is_bound = RNA_boolean_get(ptr, "is_bound");
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
|
|
|
|
col = uiLayoutColumn(layout, true);
|
|
|
|
|
uiLayoutSetEnabled(col, !is_bound);
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(col, ptr, "object", 0, NULL, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", NULL);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
col = uiLayoutColumn(layout, false);
|
|
|
|
|
uiLayoutSetEnabled(col, !is_bound);
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(col, ptr, "precision", 0, NULL, ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "use_dynamic_bind", 0, NULL, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiItemO(layout,
|
|
|
|
|
is_bound ? IFACE_("Unbind") : IFACE_("Bind"),
|
|
|
|
|
ICON_NONE,
|
|
|
|
|
"OBJECT_OT_meshdeform_bind");
|
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
modifier_panel_end(layout, ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void panelRegister(ARegionType *region_type)
|
|
|
|
|
{
|
|
|
|
|
modifier_panel_register(region_type, eModifierType_MeshDeform, panel_draw);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-16 16:50:21 +02:00
|
|
|
static void blendWrite(BlendWriter *writer, const ID *id_owner, const ModifierData *md)
|
2020-06-16 17:17:43 +02:00
|
|
|
{
|
2022-05-16 16:50:21 +02:00
|
|
|
MeshDeformModifierData mmd = *(const MeshDeformModifierData *)md;
|
2022-06-07 15:29:01 +02:00
|
|
|
const bool is_undo = BLO_write_is_undo(writer);
|
2022-05-16 16:50:21 +02:00
|
|
|
|
2022-06-07 15:29:01 +02:00
|
|
|
if (ID_IS_OVERRIDE_LIBRARY(id_owner) && !is_undo) {
|
2022-05-16 16:50:21 +02:00
|
|
|
BLI_assert(!ID_IS_LINKED(id_owner));
|
|
|
|
|
const bool is_local = (md->flag & eModifierFlag_OverrideLibrary_Local) != 0;
|
|
|
|
|
if (!is_local) {
|
2022-05-17 15:34:02 +10:00
|
|
|
/* Modifier coming from linked data cannot be bound from an override, so we can remove all
|
|
|
|
|
* binding data, can save a significant amount of memory. */
|
2022-05-16 16:50:21 +02:00
|
|
|
mmd.influences_num = 0;
|
|
|
|
|
mmd.bindinfluences = NULL;
|
|
|
|
|
mmd.verts_num = 0;
|
|
|
|
|
mmd.bindoffsets = NULL;
|
|
|
|
|
mmd.cage_verts_num = 0;
|
|
|
|
|
mmd.bindcagecos = NULL;
|
|
|
|
|
mmd.dyngridsize = 0;
|
|
|
|
|
mmd.dyngrid = NULL;
|
|
|
|
|
mmd.influences_num = 0;
|
|
|
|
|
mmd.dyninfluences = NULL;
|
|
|
|
|
mmd.dynverts = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-16 17:17:43 +02:00
|
|
|
|
2022-05-16 16:50:21 +02:00
|
|
|
const int size = mmd.dyngridsize;
|
2022-05-16 16:00:00 +02:00
|
|
|
|
2022-05-16 16:50:21 +02:00
|
|
|
BLO_write_struct_at_address(writer, MeshDeformModifierData, md, &mmd);
|
|
|
|
|
|
|
|
|
|
BLO_write_struct_array(writer, MDefInfluence, mmd.influences_num, mmd.bindinfluences);
|
2022-05-12 17:19:22 +02:00
|
|
|
|
|
|
|
|
/* NOTE: `bindoffset` is abusing `verts_num + 1` as its size, this becomes an incorrect value in
|
|
|
|
|
* case `verts_num == 0`, since `bindoffset` is then NULL, not a size 1 allocated array. */
|
2022-05-16 16:50:21 +02:00
|
|
|
if (mmd.verts_num > 0) {
|
|
|
|
|
BLO_write_int32_array(writer, mmd.verts_num + 1, mmd.bindoffsets);
|
2022-05-12 17:19:22 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2022-05-16 16:50:21 +02:00
|
|
|
BLI_assert(mmd.bindoffsets == NULL);
|
2022-05-12 17:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-16 16:50:21 +02:00
|
|
|
BLO_write_float3_array(writer, mmd.cage_verts_num, mmd.bindcagecos);
|
|
|
|
|
BLO_write_struct_array(writer, MDefCell, size * size * size, mmd.dyngrid);
|
|
|
|
|
BLO_write_struct_array(writer, MDefInfluence, mmd.influences_num, mmd.dyninfluences);
|
|
|
|
|
BLO_write_int32_array(writer, mmd.verts_num, mmd.dynverts);
|
2020-06-16 17:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void blendRead(BlendDataReader *reader, ModifierData *md)
|
|
|
|
|
{
|
|
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
|
|
|
|
|
|
|
|
|
|
BLO_read_data_address(reader, &mmd->bindinfluences);
|
2022-05-12 17:19:22 +02:00
|
|
|
|
|
|
|
|
/* NOTE: `bindoffset` is abusing `verts_num + 1` as its size, this becomes an incorrect value in
|
|
|
|
|
* case `verts_num == 0`, since `bindoffset` is then NULL, not a size 1 allocated array. */
|
|
|
|
|
if (mmd->verts_num > 0) {
|
|
|
|
|
BLO_read_int32_array(reader, mmd->verts_num + 1, &mmd->bindoffsets);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
BLO_read_float3_array(reader, mmd->cage_verts_num, &mmd->bindcagecos);
|
2020-06-16 17:17:43 +02:00
|
|
|
BLO_read_data_address(reader, &mmd->dyngrid);
|
|
|
|
|
BLO_read_data_address(reader, &mmd->dyninfluences);
|
2022-03-28 12:29:47 +11:00
|
|
|
BLO_read_int32_array(reader, mmd->verts_num, &mmd->dynverts);
|
2020-06-16 17:17:43 +02:00
|
|
|
|
|
|
|
|
/* Deprecated storage. */
|
2022-03-28 12:29:47 +11:00
|
|
|
BLO_read_float_array(reader, mmd->verts_num, &mmd->bindweights);
|
|
|
|
|
BLO_read_float3_array(reader, mmd->cage_verts_num, &mmd->bindcos);
|
2020-06-16 17:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
ModifierTypeInfo modifierType_MeshDeform = {
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("MeshDeform"),
|
|
|
|
|
/*structName*/ "MeshDeformModifierData",
|
|
|
|
|
/*structSize*/ sizeof(MeshDeformModifierData),
|
|
|
|
|
/*srna*/ &RNA_MeshDeformModifier,
|
|
|
|
|
/*type*/ eModifierTypeType_OnlyDeform,
|
|
|
|
|
/*flags*/ eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_AcceptsVertexCosOnly |
|
2012-10-24 05:45:54 +00:00
|
|
|
eModifierTypeFlag_SupportsEditmode,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*icon*/ ICON_MOD_MESHDEFORM,
|
|
|
|
|
|
|
|
|
|
/*copyData*/ copyData,
|
|
|
|
|
|
|
|
|
|
/*deformVerts*/ deformVerts,
|
|
|
|
|
/*deformMatrices*/ NULL,
|
|
|
|
|
/*deformVertsEM*/ deformVertsEM,
|
|
|
|
|
/*deformMatricesEM*/ NULL,
|
|
|
|
|
/*modifyMesh*/ NULL,
|
|
|
|
|
/*modifyGeometrySet*/ NULL,
|
|
|
|
|
|
|
|
|
|
/*initData*/ initData,
|
|
|
|
|
/*requiredDataMask*/ requiredDataMask,
|
|
|
|
|
/*freeData*/ freeData,
|
|
|
|
|
/*isDisabled*/ isDisabled,
|
|
|
|
|
/*updateDepsgraph*/ updateDepsgraph,
|
|
|
|
|
/*dependsOnTime*/ NULL,
|
|
|
|
|
/*dependsOnNormals*/ NULL,
|
|
|
|
|
/*foreachIDLink*/ foreachIDLink,
|
|
|
|
|
/*foreachTexLink*/ NULL,
|
|
|
|
|
/*freeRuntimeData*/ NULL,
|
|
|
|
|
/*panelRegister*/ panelRegister,
|
|
|
|
|
/*blendWrite*/ blendWrite,
|
|
|
|
|
/*blendRead*/ blendRead,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|