2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2013-01-21 15:41:00 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup modifiers
|
2013-01-21 15:41:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2019-02-25 11:56:24 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_math.h"
|
|
|
|
|
#include "BLI_path_util.h"
|
|
|
|
|
#include "BLI_string.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"
|
2013-01-24 04:02:30 +00:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "DNA_screen_types.h"
|
2013-01-21 15:41:00 +00:00
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BKE_context.h"
|
2021-09-09 14:01:15 +10:00
|
|
|
#include "BKE_deform.h"
|
|
|
|
|
#include "BKE_lib_id.h"
|
2013-01-21 15:41:00 +00:00
|
|
|
#include "BKE_main.h"
|
2018-11-07 15:37:31 +01:00
|
|
|
#include "BKE_mesh.h"
|
2021-09-09 14:01:15 +10:00
|
|
|
#include "BKE_mesh_wrapper.h"
|
2018-11-07 15:37:31 +01:00
|
|
|
#include "BKE_scene.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BKE_screen.h"
|
|
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2013-01-21 15:41:00 +00:00
|
|
|
|
2018-06-22 15:03:42 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
|
|
|
|
|
2013-01-21 16:43:04 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
#include "MOD_meshcache_util.h" /* utility functions */
|
|
|
|
|
#include "MOD_modifiertypes.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "MOD_ui_common.h"
|
2021-09-09 14:01:15 +10:00
|
|
|
#include "MOD_util.h"
|
2013-01-21 15:41:00 +00:00
|
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
|
{
|
|
|
|
|
MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md;
|
|
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(mcmd, modifier));
|
2013-01-21 15:41:00 +00:00
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
MEMCPY_STRUCT_AFTER(mcmd, DNA_struct_default_get(MeshCacheModifierData), modifier);
|
2013-01-21 15:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-01 15:27:11 +02:00
|
|
|
static bool dependsOnTime(struct Scene *UNUSED(scene), ModifierData *md)
|
2013-01-21 15:41:00 +00:00
|
|
|
{
|
|
|
|
|
MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md;
|
|
|
|
|
return (mcmd->play_mode == MOD_MESHCACHE_PLAY_CFEA);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-10 12:14:08 +02:00
|
|
|
static bool isDisabled(const struct Scene *UNUSED(scene),
|
|
|
|
|
ModifierData *md,
|
|
|
|
|
bool UNUSED(useRenderParams))
|
2013-01-21 15:41:00 +00:00
|
|
|
{
|
|
|
|
|
MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md;
|
|
|
|
|
|
|
|
|
|
/* leave it up to the modifier to check the file is valid on calculation */
|
2013-01-21 16:43:04 +00:00
|
|
|
return (mcmd->factor <= 0.0f) || (mcmd->filepath[0] == '\0');
|
2013-01-21 15:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
2018-08-15 16:21:43 +02:00
|
|
|
static void meshcache_do(MeshCacheModifierData *mcmd,
|
|
|
|
|
Scene *scene,
|
|
|
|
|
Object *ob,
|
2021-09-09 14:01:15 +10:00
|
|
|
Mesh *mesh,
|
2013-01-21 18:45:31 +00:00
|
|
|
float (*vertexCos_Real)[3],
|
2022-03-28 12:29:47 +11:00
|
|
|
int verts_num)
|
2013-01-21 15:41:00 +00:00
|
|
|
{
|
2013-01-24 04:02:30 +00:00
|
|
|
const bool use_factor = mcmd->factor < 1.0f;
|
2021-09-09 14:01:15 +10:00
|
|
|
int influence_group_index;
|
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;
|
2021-09-09 14:01:15 +10:00
|
|
|
MOD_get_vgroup(ob, mesh, mcmd->defgrp_name, &dvert, &influence_group_index);
|
|
|
|
|
|
|
|
|
|
float(*vertexCos_Store)[3] = (use_factor || influence_group_index != -1 ||
|
2013-01-24 04:02:30 +00:00
|
|
|
(mcmd->deform_mode == MOD_MESHCACHE_DEFORM_INTEGRATE)) ?
|
2018-01-14 22:14:20 +01:00
|
|
|
MEM_malloc_arrayN(
|
2022-03-28 12:29:47 +11:00
|
|
|
verts_num, sizeof(*vertexCos_Store), __func__) :
|
2018-01-14 22:14:20 +01:00
|
|
|
NULL;
|
2013-01-21 16:43:04 +00:00
|
|
|
float(*vertexCos)[3] = vertexCos_Store ? vertexCos_Store : vertexCos_Real;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
const float fps = FPS;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
char filepath[FILE_MAX];
|
|
|
|
|
const char *err_str = NULL;
|
|
|
|
|
bool ok;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
float time;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/* Interpret Time (the reading functions also do some of this ) */
|
|
|
|
|
if (mcmd->play_mode == MOD_MESHCACHE_PLAY_CFEA) {
|
2021-07-12 16:15:03 +02:00
|
|
|
const float ctime = BKE_scene_ctime_get(scene);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
switch (mcmd->time_mode) {
|
|
|
|
|
case MOD_MESHCACHE_TIME_FRAME: {
|
2021-07-12 16:15:03 +02:00
|
|
|
time = ctime;
|
2013-01-21 15:41:00 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case MOD_MESHCACHE_TIME_SECONDS: {
|
2021-07-12 16:15:03 +02:00
|
|
|
time = ctime / fps;
|
2013-01-21 15:41:00 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case MOD_MESHCACHE_TIME_FACTOR:
|
|
|
|
|
default: {
|
2021-07-12 16:15:03 +02:00
|
|
|
time = ctime / fps;
|
2013-01-21 15:41:00 +00:00
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-01-21 15:41:00 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
/* apply offset and scale */
|
|
|
|
|
time = (mcmd->frame_scale * time) - mcmd->frame_start;
|
|
|
|
|
}
|
|
|
|
|
else { /* if (mcmd->play_mode == MOD_MESHCACHE_PLAY_EVAL) { */
|
|
|
|
|
switch (mcmd->time_mode) {
|
|
|
|
|
case MOD_MESHCACHE_TIME_FRAME: {
|
|
|
|
|
time = mcmd->eval_frame;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case MOD_MESHCACHE_TIME_SECONDS: {
|
|
|
|
|
time = mcmd->eval_time;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case MOD_MESHCACHE_TIME_FACTOR:
|
|
|
|
|
default: {
|
|
|
|
|
time = mcmd->eval_factor;
|
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2013-01-21 15:41:00 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/* Read the File (or error out when the file is bad) */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
/* would be nice if we could avoid doing this _every_ frame */
|
|
|
|
|
BLI_strncpy(filepath, mcmd->filepath, sizeof(filepath));
|
2018-06-09 15:16:44 +02:00
|
|
|
BLI_path_abs(filepath, ID_BLEND_PATH_FROM_GLOBAL((ID *)ob));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
switch (mcmd->type) {
|
|
|
|
|
case MOD_MESHCACHE_TYPE_MDD:
|
|
|
|
|
ok = MOD_meshcache_read_mdd_times(
|
2022-03-28 12:29:47 +11:00
|
|
|
filepath, vertexCos, verts_num, mcmd->interp, time, fps, mcmd->time_mode, &err_str);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2013-01-21 15:41:00 +00:00
|
|
|
case MOD_MESHCACHE_TYPE_PC2:
|
|
|
|
|
ok = MOD_meshcache_read_pc2_times(
|
2022-03-28 12:29:47 +11:00
|
|
|
filepath, vertexCos, verts_num, mcmd->interp, time, fps, mcmd->time_mode, &err_str);
|
2013-01-21 15:41:00 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ok = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
2013-01-24 04:02:30 +00:00
|
|
|
/* tricky shape key integration (slow!) */
|
|
|
|
|
if (mcmd->deform_mode == MOD_MESHCACHE_DEFORM_INTEGRATE) {
|
2013-01-24 05:54:17 +00:00
|
|
|
Mesh *me = ob->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-24 04:02:30 +00:00
|
|
|
/* we could support any object type */
|
2013-01-24 05:54:17 +00:00
|
|
|
if (UNLIKELY(ob->type != OB_MESH)) {
|
2020-10-26 17:07:58 +11:00
|
|
|
BKE_modifier_set_error(ob, &mcmd->modifier, "'Integrate' only valid for Mesh objects");
|
2013-01-24 04:02:30 +00:00
|
|
|
}
|
2022-03-28 12:29:47 +11:00
|
|
|
else if (UNLIKELY(me->totvert != verts_num)) {
|
2020-10-26 17:07:58 +11:00
|
|
|
BKE_modifier_set_error(ob, &mcmd->modifier, "'Integrate' original mesh vertex mismatch");
|
2013-01-24 05:54:17 +00:00
|
|
|
}
|
|
|
|
|
else if (UNLIKELY(me->totpoly == 0)) {
|
2020-10-26 17:07:58 +11:00
|
|
|
BKE_modifier_set_error(ob, &mcmd->modifier, "'Integrate' requires faces");
|
2013-01-24 05:54:17 +00:00
|
|
|
}
|
2013-01-24 04:02:30 +00:00
|
|
|
else {
|
2013-01-24 05:54:17 +00:00
|
|
|
/* the moons align! */
|
|
|
|
|
int i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-14 22:14:20 +01:00
|
|
|
float(*vertexCos_Source)[3] = MEM_malloc_arrayN(
|
2022-03-28 12:29:47 +11:00
|
|
|
verts_num, sizeof(*vertexCos_Source), __func__);
|
|
|
|
|
float(*vertexCos_New)[3] = MEM_malloc_arrayN(verts_num, sizeof(*vertexCos_New), __func__);
|
2022-09-07 00:06:31 -05:00
|
|
|
const MVert *mv = BKE_mesh_verts(me);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
for (i = 0; i < verts_num; i++, mv++) {
|
2013-01-24 05:54:17 +00:00
|
|
|
copy_v3_v3(vertexCos_Source[i], mv->co);
|
2013-01-24 04:02:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-24 05:54:17 +00:00
|
|
|
BKE_mesh_calc_relative_deform(
|
2022-09-07 00:06:31 -05:00
|
|
|
BKE_mesh_polys(me),
|
2013-01-24 05:54:17 +00:00
|
|
|
me->totpoly,
|
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
|
|
|
BKE_mesh_loops(me),
|
2013-01-24 05:54:17 +00:00
|
|
|
me->totvert,
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-26 21:35:18 +10:00
|
|
|
(const float(*)[3])vertexCos_Source, /* From the original Mesh. */
|
2013-01-24 05:54:17 +00:00
|
|
|
(const float(*)[3])vertexCos_Real, /* the input we've been given (shape keys!) */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-26 21:35:18 +10:00
|
|
|
(const float(*)[3])vertexCos, /* The result of this modifier. */
|
|
|
|
|
vertexCos_New /* The result of this function. */
|
2013-01-24 05:54:17 +00:00
|
|
|
);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-24 05:54:17 +00:00
|
|
|
/* write the corrected locations back into the result */
|
2022-03-28 12:29:47 +11:00
|
|
|
memcpy(vertexCos, vertexCos_New, sizeof(*vertexCos) * verts_num);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-24 05:54:17 +00:00
|
|
|
MEM_freeN(vertexCos_Source);
|
|
|
|
|
MEM_freeN(vertexCos_New);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-01-24 04:02:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-24 14:36:02 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/* Apply the transformation matrix (if needed) */
|
|
|
|
|
if (UNLIKELY(err_str)) {
|
2020-10-26 17:07:58 +11:00
|
|
|
BKE_modifier_set_error(ob, &mcmd->modifier, "%s", err_str);
|
2013-01-24 14:36:02 +00:00
|
|
|
}
|
|
|
|
|
else if (ok) {
|
|
|
|
|
bool use_matrix = false;
|
|
|
|
|
float mat[3][3];
|
|
|
|
|
unit_m3(mat);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-24 14:36:02 +00:00
|
|
|
if (mat3_from_axis_conversion(mcmd->forward_axis, mcmd->up_axis, 1, 2, mat)) {
|
|
|
|
|
use_matrix = true;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-24 14:36:02 +00:00
|
|
|
if (mcmd->flip_axis) {
|
|
|
|
|
float tmat[3][3];
|
|
|
|
|
unit_m3(tmat);
|
2019-04-22 09:15:10 +10:00
|
|
|
if (mcmd->flip_axis & (1 << 0)) {
|
2013-01-24 14:36:02 +00:00
|
|
|
tmat[0][0] = -1.0f;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mcmd->flip_axis & (1 << 1)) {
|
2013-01-24 14:36:02 +00:00
|
|
|
tmat[1][1] = -1.0f;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (mcmd->flip_axis & (1 << 2)) {
|
2013-01-24 14:36:02 +00:00
|
|
|
tmat[2][2] = -1.0f;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2013-01-24 14:36:02 +00:00
|
|
|
mul_m3_m3m3(mat, tmat, mat);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-24 14:36:02 +00:00
|
|
|
use_matrix = true;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-24 14:36:02 +00:00
|
|
|
if (use_matrix) {
|
|
|
|
|
int i;
|
2022-03-28 12:29:47 +11:00
|
|
|
for (i = 0; i < verts_num; i++) {
|
2013-01-24 14:36:02 +00:00
|
|
|
mul_m3_v3(mat, vertexCos[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-24 14:36:02 +00:00
|
|
|
if (vertexCos_Store) {
|
|
|
|
|
if (ok) {
|
2021-09-09 14:01:15 +10:00
|
|
|
if (influence_group_index != -1) {
|
|
|
|
|
const float global_factor = (mcmd->flag & MOD_MESHCACHE_INVERT_VERTEX_GROUP) ?
|
|
|
|
|
-mcmd->factor :
|
|
|
|
|
mcmd->factor;
|
|
|
|
|
const float global_offset = (mcmd->flag & MOD_MESHCACHE_INVERT_VERTEX_GROUP) ?
|
|
|
|
|
mcmd->factor :
|
|
|
|
|
0.0f;
|
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
|
|
|
if (BKE_mesh_deform_verts(mesh) != NULL) {
|
2022-03-28 12:29:47 +11:00
|
|
|
for (int i = 0; i < verts_num; i++) {
|
2021-09-09 14:01:15 +10:00
|
|
|
/* For each vertex, compute its blending factor between the mesh cache (for `fac = 0`)
|
|
|
|
|
* and the former position of the vertex (for `fac = 1`). */
|
|
|
|
|
const MDeformVert *currentIndexDVert = dvert + i;
|
|
|
|
|
const float local_vertex_fac = global_offset +
|
|
|
|
|
BKE_defvert_find_weight(currentIndexDVert,
|
|
|
|
|
influence_group_index) *
|
|
|
|
|
global_factor;
|
|
|
|
|
interp_v3_v3v3(
|
|
|
|
|
vertexCos_Real[i], vertexCos_Real[i], vertexCos_Store[i], local_vertex_fac);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (use_factor) {
|
|
|
|
|
/* Influence_group_index is -1. */
|
2022-03-28 12:29:47 +11:00
|
|
|
interp_vn_vn(*vertexCos_Real, *vertexCos_Store, mcmd->factor, verts_num * 3);
|
2013-01-24 14:36:02 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2022-03-28 12:29:47 +11:00
|
|
|
memcpy(vertexCos_Real, vertexCos_Store, sizeof(*vertexCos_Store) * verts_num);
|
2013-01-24 14:36:02 +00:00
|
|
|
}
|
2013-01-21 16:43:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 16:43:04 +00:00
|
|
|
MEM_freeN(vertexCos_Store);
|
|
|
|
|
}
|
2013-01-21 15:41:00 +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,
|
2021-09-09 14:01:15 +10: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)
|
2013-01-21 15:41:00 +00:00
|
|
|
{
|
|
|
|
|
MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md;
|
2018-06-22 15:03:42 +02:00
|
|
|
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
|
2013-01-21 15:41:00 +00:00
|
|
|
|
2021-09-09 14:01:15 +10:00
|
|
|
Mesh *mesh_src = NULL;
|
|
|
|
|
|
|
|
|
|
if (ctx->object->type == OB_MESH && mcmd->defgrp_name[0] != '\0') {
|
|
|
|
|
/* `mesh_src` is only needed for vertex groups. */
|
2022-08-12 22:08:48 +10:00
|
|
|
mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, verts_num, false);
|
2021-09-09 14:01:15 +10:00
|
|
|
}
|
2022-03-28 12:29:47 +11:00
|
|
|
meshcache_do(mcmd, scene, ctx->object, mesh_src, vertexCos, verts_num);
|
2021-09-09 14:01:15 +10:00
|
|
|
|
|
|
|
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
|
|
|
|
BKE_id_free(NULL, mesh_src);
|
|
|
|
|
}
|
2013-01-21 15:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void deformVertsEM(ModifierData *md,
|
2018-08-15 16:21:43 +02:00
|
|
|
const ModifierEvalContext *ctx,
|
2021-09-09 14:01:15 +10:00
|
|
|
struct BMEditMesh *editData,
|
|
|
|
|
Mesh *mesh,
|
2018-08-15 16:21:43 +02:00
|
|
|
float (*vertexCos)[3],
|
2022-03-28 12:29:47 +11:00
|
|
|
int verts_num)
|
2013-01-21 15:41:00 +00:00
|
|
|
{
|
|
|
|
|
MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md;
|
2018-06-22 15:03:42 +02:00
|
|
|
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
|
2013-01-21 15:41:00 +00:00
|
|
|
|
2021-09-09 14:01:15 +10:00
|
|
|
Mesh *mesh_src = NULL;
|
|
|
|
|
|
|
|
|
|
if (ctx->object->type == OB_MESH && mcmd->defgrp_name[0] != '\0') {
|
|
|
|
|
/* `mesh_src` is only needed for vertex groups. */
|
2022-08-12 22:08:48 +10:00
|
|
|
mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, verts_num, false);
|
2021-09-09 14:01:15 +10:00
|
|
|
}
|
|
|
|
|
if (mesh_src != NULL) {
|
|
|
|
|
BKE_mesh_wrapper_ensure_mdata(mesh_src);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
meshcache_do(mcmd, scene, ctx->object, mesh_src, vertexCos, verts_num);
|
2021-09-09 14:01:15 +10:00
|
|
|
|
|
|
|
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
|
|
|
|
BKE_id_free(NULL, mesh_src);
|
|
|
|
|
}
|
2013-01-21 15:41:00 +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 *layout = panel->layout;
|
|
|
|
|
|
2021-09-09 14:01:15 +10:00
|
|
|
PointerRNA ob_ptr;
|
|
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(layout, ptr, "cache_format", 0, NULL, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "filepath", 0, NULL, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(layout, ptr, "factor", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "deform_mode", 0, NULL, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "interpolation", 0, NULL, ICON_NONE);
|
2021-09-09 14:01:15 +10:00
|
|
|
modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", NULL);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
modifier_panel_end(layout, ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
static void time_remapping_panel_draw(const bContext *UNUSED(C), Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, NULL);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(layout, ptr, "time_mode", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(layout, ptr, "play_mode", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
if (RNA_enum_get(ptr, "play_mode") == MOD_MESHCACHE_PLAY_CFEA) {
|
|
|
|
|
uiItemR(layout, ptr, "frame_start", 0, NULL, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "frame_scale", 0, NULL, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
else { /* play_mode == MOD_MESHCACHE_PLAY_EVAL */
|
2020-09-02 14:13:26 -05:00
|
|
|
int time_mode = RNA_enum_get(ptr, "time_mode");
|
2020-06-05 10:41:03 -04:00
|
|
|
if (time_mode == MOD_MESHCACHE_TIME_FRAME) {
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(layout, ptr, "eval_frame", 0, NULL, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
else if (time_mode == MOD_MESHCACHE_TIME_SECONDS) {
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(layout, ptr, "eval_time", 0, NULL, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
else { /* time_mode == MOD_MESHCACHE_TIME_FACTOR */
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(layout, ptr, "eval_factor", 0, NULL, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
static void axis_mapping_panel_draw(const bContext *UNUSED(C), Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *col;
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, NULL);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
|
|
|
|
col = uiLayoutColumn(layout, true);
|
2020-09-02 14:13:26 -05:00
|
|
|
uiLayoutSetRedAlert(col, RNA_enum_get(ptr, "forward_axis") == RNA_enum_get(ptr, "up_axis"));
|
|
|
|
|
uiItemR(col, ptr, "forward_axis", 0, NULL, ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "up_axis", 0, NULL, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(layout, ptr, "flip_axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void panelRegister(ARegionType *region_type)
|
|
|
|
|
{
|
|
|
|
|
PanelType *panel_type = modifier_panel_register(
|
|
|
|
|
region_type, eModifierType_MeshCache, panel_draw);
|
|
|
|
|
modifier_subpanel_register(region_type,
|
|
|
|
|
"time_remapping",
|
|
|
|
|
"Time Remapping",
|
|
|
|
|
NULL,
|
|
|
|
|
time_remapping_panel_draw,
|
|
|
|
|
panel_type);
|
|
|
|
|
modifier_subpanel_register(
|
|
|
|
|
region_type, "axis_mapping", "Axis Mapping", NULL, axis_mapping_panel_draw, panel_type);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
ModifierTypeInfo modifierType_MeshCache = {
|
2022-07-15 14:12:34 +02:00
|
|
|
/* name */ N_("MeshCache"),
|
2013-01-21 15:41:00 +00:00
|
|
|
/* structName */ "MeshCacheModifierData",
|
|
|
|
|
/* structSize */ sizeof(MeshCacheModifierData),
|
2020-09-25 12:49:18 +02:00
|
|
|
/* srna */ &RNA_MeshCacheModifier,
|
2013-01-21 15:41:00 +00:00
|
|
|
/* type */ eModifierTypeType_OnlyDeform,
|
2020-04-21 13:09:41 +02:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_AcceptsVertexCosOnly |
|
2013-01-21 15:41:00 +00:00
|
|
|
eModifierTypeFlag_SupportsEditmode,
|
2020-09-25 12:45:30 +02:00
|
|
|
/* icon */ ICON_MOD_MESHDEFORM, /* TODO: Use correct icon. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
/* copyData */ BKE_modifier_copydata_generic,
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-15 16:21:43 +02:00
|
|
|
/* deformVerts */ deformVerts,
|
2013-01-21 15:41:00 +00:00
|
|
|
/* deformMatrices */ NULL,
|
2018-08-15 16:21:43 +02:00
|
|
|
/* deformVertsEM */ deformVertsEM,
|
2013-01-21 15:41:00 +00:00
|
|
|
/* deformMatricesEM */ NULL,
|
2020-04-21 13:09:41 +02:00
|
|
|
/* modifyMesh */ NULL,
|
2020-12-10 14:35:02 +01:00
|
|
|
/* modifyGeometrySet */ NULL,
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
/* initData */ initData,
|
|
|
|
|
/* requiredDataMask */ NULL,
|
|
|
|
|
/* freeData */ NULL,
|
|
|
|
|
/* isDisabled */ isDisabled,
|
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
|
|
|
/* updateDepsgraph */ NULL,
|
2013-01-21 15:41:00 +00:00
|
|
|
/* dependsOnTime */ dependsOnTime,
|
|
|
|
|
/* dependsOnNormals */ NULL,
|
|
|
|
|
/* foreachIDLink */ NULL,
|
|
|
|
|
/* foreachTexLink */ NULL,
|
2019-03-18 15:56:16 +01:00
|
|
|
/* freeRuntimeData */ NULL,
|
2020-06-05 10:41:03 -04:00
|
|
|
/* panelRegister */ panelRegister,
|
2020-06-15 17:37:07 +02:00
|
|
|
/* blendWrite */ NULL,
|
|
|
|
|
/* blendRead */ NULL,
|
2013-01-21 15:41:00 +00:00
|
|
|
};
|