2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
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"
|
|
|
|
|
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_matrix.h"
|
|
|
|
|
#include "BLI_math_vector.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
|
|
|
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2024-01-29 18:57:16 -05:00
|
|
|
#include "BKE_deform.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_editmesh.hh"
|
2024-01-15 12:44:04 -05:00
|
|
|
#include "BKE_lib_id.hh"
|
2024-01-18 12:20:42 +01:00
|
|
|
#include "BKE_lib_query.hh"
|
2023-08-02 22:14:18 +02:00
|
|
|
#include "BKE_mesh.hh"
|
|
|
|
|
#include "BKE_mesh_runtime.hh"
|
|
|
|
|
#include "BKE_mesh_wrapper.hh"
|
2023-11-14 09:30:40 +01:00
|
|
|
#include "BKE_modifier.hh"
|
2023-09-25 17:48:21 -04:00
|
|
|
#include "BKE_screen.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface.hh"
|
|
|
|
|
#include "UI_resources.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-28 15:01:05 +02:00
|
|
|
#include "BLO_read_write.hh"
|
2020-06-16 17:17:43 +02:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
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
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph.hh"
|
|
|
|
|
#include "DEG_depsgraph_query.hh"
|
2018-02-13 20:35:29 +11:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include "MOD_ui_common.hh"
|
|
|
|
|
#include "MOD_util.hh"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void init_data(ModifierData *md)
|
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 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
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void free_data(ModifierData *md)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void copy_data(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) {
|
2023-05-04 18:35:37 +02:00
|
|
|
tmmd->bindinfluences = static_cast<MDefInfluence *>(MEM_dupallocN(mmd->bindinfluences));
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->bindoffsets) {
|
2023-05-04 18:35:37 +02:00
|
|
|
tmmd->bindoffsets = static_cast<int *>(MEM_dupallocN(mmd->bindoffsets));
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->bindcagecos) {
|
2023-05-04 18:35:37 +02:00
|
|
|
tmmd->bindcagecos = static_cast<float *>(MEM_dupallocN(mmd->bindcagecos));
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->dyngrid) {
|
2023-05-04 18:35:37 +02:00
|
|
|
tmmd->dyngrid = static_cast<MDefCell *>(MEM_dupallocN(mmd->dyngrid));
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->dyninfluences) {
|
2023-05-04 18:35:37 +02:00
|
|
|
tmmd->dyninfluences = static_cast<MDefInfluence *>(MEM_dupallocN(mmd->dyninfluences));
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->dynverts) {
|
2023-05-04 18:35:37 +02:00
|
|
|
tmmd->dynverts = static_cast<int *>(MEM_dupallocN(mmd->dynverts));
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->bindweights) {
|
2023-05-04 18:35:37 +02:00
|
|
|
tmmd->bindweights = static_cast<float *>(MEM_dupallocN(mmd->bindweights)); /* deprecated */
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mmd->bindcos) {
|
2023-05-04 18:35:37 +02:00
|
|
|
tmmd->bindcos = static_cast<float *>(MEM_dupallocN(mmd->bindcos)); /* deprecated */
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void required_data_mask(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;
|
|
|
|
|
|
2023-05-05 09:25:45 +10:00
|
|
|
/* Ask for vertex-groups 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
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static bool is_disabled(const Scene * /*scene*/, ModifierData *md, bool /*use_render_params*/)
|
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
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
|
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
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
walk(user_data, ob, (ID **)&mmd->object, IDWALK_CB_NOP);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void update_depsgraph(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;
|
2023-05-04 18:35:37 +02:00
|
|
|
if (mmd->object != nullptr) {
|
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;
|
2023-07-03 17:04:13 +02:00
|
|
|
#if 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;
|
2023-05-04 18:35:37 +02:00
|
|
|
ivec[i] = int(gridvec[i]);
|
2012-05-03 21:35:04 +00:00
|
|
|
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;
|
2023-07-03 17:04:13 +02:00
|
|
|
#if 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-03 17:04:13 +02:00
|
|
|
#if 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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
struct MeshdeformUserdata {
|
2014-10-22 11:56:52 +02:00
|
|
|
/*const*/ MeshDeformModifierData *mmd;
|
|
|
|
|
const MDeformVert *dvert;
|
|
|
|
|
/*const*/ float (*dco)[3];
|
|
|
|
|
int defgrp_index;
|
|
|
|
|
float (*vertexCos)[3];
|
|
|
|
|
float (*cagemat)[4];
|
|
|
|
|
float (*icagemat)[3];
|
2023-05-04 18:35:37 +02:00
|
|
|
};
|
2014-10-22 11:56:52 +02:00
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void meshdeform_vert_task(void *__restrict userdata,
|
|
|
|
|
const int iter,
|
2023-05-04 18:35:37 +02:00
|
|
|
const TaskParallelTLS *__restrict /*tls*/)
|
2014-10-22 11:56:52 +02:00
|
|
|
{
|
2023-05-04 18:35:37 +02:00
|
|
|
MeshdeformUserdata *data = static_cast<MeshdeformUserdata *>(userdata);
|
2014-10-22 11:56:52 +02:00
|
|
|
/*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;
|
2023-05-04 18:35:37 +02:00
|
|
|
const MDeformVert *dvert = nullptr;
|
2010-04-11 22:12:30 +00:00
|
|
|
float imat[4][4], cagemat[4][4], iobmat[4][4], icagemat[3][3], cmat[4][4];
|
2023-11-16 18:29:52 +01:00
|
|
|
float(*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
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
if (mmd->object == nullptr || (mmd->bindcagecos == nullptr && mmd->bindfunc == nullptr)) {
|
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);
|
2023-05-04 18:35:37 +02:00
|
|
|
if (cagemesh == nullptr) {
|
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");
|
2023-11-16 18:29:52 +01:00
|
|
|
return;
|
2019-04-04 14:42:33 +02:00
|
|
|
}
|
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
|
|
|
|
2023-11-16 18:29:52 +01:00
|
|
|
return;
|
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);
|
2023-11-16 18:29:52 +01:00
|
|
|
return;
|
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);
|
2023-11-16 18:29:52 +01:00
|
|
|
return;
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
2023-05-04 18:35:37 +02:00
|
|
|
else if (mmd->bindcagecos == nullptr) {
|
2020-10-26 17:07:58 +11:00
|
|
|
BKE_modifier_set_error(ob, md, "Bind data missing");
|
2023-11-16 18:29:52 +01:00
|
|
|
return;
|
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.
|
|
|
|
|
*/
|
2023-11-16 18:29:52 +01:00
|
|
|
blender::Array<blender::float3> dco(cage_verts_num + 1);
|
2022-03-28 12:29:47 +11:00
|
|
|
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 */
|
2023-11-17 13:07:29 +01:00
|
|
|
BKE_mesh_wrapper_vert_coords_copy(cagemesh, dco.as_mutable_span().take_front(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;
|
2023-11-16 18:29:52 +01:00
|
|
|
data.dco = reinterpret_cast<float(*)[3]>(dco.data());
|
2014-10-22 11:56:52 +02:00
|
|
|
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);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void deform_verts(ModifierData *md,
|
|
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
|
Mesh *mesh,
|
2023-11-14 10:54:57 +01:00
|
|
|
blender::MutableSpan<blender::float3> positions)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2023-11-14 10:54:57 +01:00
|
|
|
/* if next modifier needs original vertices */
|
|
|
|
|
MOD_previous_vcos_store(md, reinterpret_cast<float(*)[3]>(positions.data()));
|
|
|
|
|
meshdeformModifier_do(
|
|
|
|
|
md, ctx, mesh, reinterpret_cast<float(*)[3]>(positions.data()), positions.size());
|
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 */
|
2023-05-04 18:35:37 +02:00
|
|
|
mmd->bindinfluences = static_cast<MDefInfluence *>(
|
|
|
|
|
MEM_calloc_arrayN(mmd->influences_num, sizeof(MDefInfluence), __func__));
|
|
|
|
|
mmd->bindoffsets = static_cast<int *>(MEM_calloc_arrayN((verts_num + 1), sizeof(int), __func__));
|
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);
|
2023-05-04 18:35:37 +02:00
|
|
|
mmd->bindweights = nullptr;
|
2010-04-23 11:19:06 +00:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
static void panel_draw(const bContext * /*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);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(col, ptr, "object", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", nullptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
col = uiLayoutColumn(layout, false);
|
|
|
|
|
uiLayoutSetEnabled(col, !is_bound);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(col, ptr, "precision", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "use_dynamic_bind", UI_ITEM_NONE, nullptr, 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
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void panel_register(ARegionType *region_type)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
modifier_panel_register(region_type, eModifierType_MeshDeform, panel_draw);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void blend_write(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;
|
2023-05-04 18:35:37 +02:00
|
|
|
mmd.bindinfluences = nullptr;
|
2022-05-16 16:50:21 +02:00
|
|
|
mmd.verts_num = 0;
|
2023-05-04 18:35:37 +02:00
|
|
|
mmd.bindoffsets = nullptr;
|
2022-05-16 16:50:21 +02:00
|
|
|
mmd.cage_verts_num = 0;
|
2023-05-04 18:35:37 +02:00
|
|
|
mmd.bindcagecos = nullptr;
|
2022-05-16 16:50:21 +02:00
|
|
|
mmd.dyngridsize = 0;
|
2023-05-04 18:35:37 +02:00
|
|
|
mmd.dyngrid = nullptr;
|
2022-05-16 16:50:21 +02:00
|
|
|
mmd.influences_num = 0;
|
2023-05-04 18:35:37 +02:00
|
|
|
mmd.dyninfluences = nullptr;
|
|
|
|
|
mmd.dynverts = nullptr;
|
2022-05-16 16:50:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
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
|
2023-05-04 18:35:37 +02:00
|
|
|
* case `verts_num == 0`, since `bindoffset` is then nullptr, 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 {
|
2023-05-04 18:35:37 +02:00
|
|
|
BLI_assert(mmd.bindoffsets == nullptr);
|
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
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void blend_read(BlendDataReader *reader, ModifierData *md)
|
2020-06-16 17:17:43 +02:00
|
|
|
{
|
|
|
|
|
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
|
2023-05-04 18:35:37 +02:00
|
|
|
* case `verts_num == 0`, since `bindoffset` is then nullptr, not a size 1 allocated array. */
|
2022-05-12 17:19:22 +02:00
|
|
|
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-07-26 17:08:14 +02:00
|
|
|
/*idname*/ "MeshDeform",
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("MeshDeform"),
|
2023-07-27 12:04:18 +10:00
|
|
|
/*struct_name*/ "MeshDeformModifierData",
|
|
|
|
|
/*struct_size*/ sizeof(MeshDeformModifierData),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*srna*/ &RNA_MeshDeformModifier,
|
2023-11-14 10:03:56 +01:00
|
|
|
/*type*/ ModifierTypeType::OnlyDeform,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*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,
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
/*copy_data*/ copy_data,
|
|
|
|
|
|
|
|
|
|
/*deform_verts*/ deform_verts,
|
|
|
|
|
/*deform_matrices*/ nullptr,
|
|
|
|
|
/*deform_verts_EM*/ nullptr,
|
|
|
|
|
/*deform_matrices_EM*/ nullptr,
|
|
|
|
|
/*modify_mesh*/ nullptr,
|
|
|
|
|
/*modify_geometry_set*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*init_data*/ init_data,
|
|
|
|
|
/*required_data_mask*/ required_data_mask,
|
|
|
|
|
/*free_data*/ free_data,
|
|
|
|
|
/*is_disabled*/ is_disabled,
|
|
|
|
|
/*update_depsgraph*/ update_depsgraph,
|
|
|
|
|
/*depends_on_time*/ nullptr,
|
|
|
|
|
/*depends_on_normals*/ nullptr,
|
|
|
|
|
/*foreach_ID_link*/ foreach_ID_link,
|
|
|
|
|
/*foreach_tex_link*/ nullptr,
|
|
|
|
|
/*free_runtime_data*/ nullptr,
|
|
|
|
|
/*panel_register*/ panel_register,
|
|
|
|
|
/*blend_write*/ blend_write,
|
|
|
|
|
/*blend_read*/ blend_read,
|
2024-01-18 22:51:30 +01:00
|
|
|
/*foreach_cache*/ nullptr,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|