2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02: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
|
|
|
*/
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include <cstdio>
|
2013-01-21 15:41:00 +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_rotation.h"
|
|
|
|
|
#include "BLI_math_vector.h"
|
2019-02-25 11:56:24 +01:00
|
|
|
#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
|
|
|
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2024-01-29 18:57:16 -05:00
|
|
|
#include "BKE_deform.hh"
|
2024-01-15 12:44:04 -05:00
|
|
|
#include "BKE_lib_id.hh"
|
2023-12-01 19:43:16 +01:00
|
|
|
#include "BKE_main.hh"
|
2023-06-14 11:59:32 -04:00
|
|
|
#include "BKE_mesh.hh"
|
2023-08-02 22:14:18 +02:00
|
|
|
#include "BKE_mesh_wrapper.hh"
|
2018-11-07 15:37:31 +01:00
|
|
|
#include "BKE_scene.h"
|
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-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2013-01-21 15:41:00 +00:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph_query.hh"
|
2018-06-22 15:03:42 +02:00
|
|
|
|
2013-01-21 16:43:04 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include "MOD_meshcache_util.hh" /* utility functions */
|
|
|
|
|
#include "MOD_modifiertypes.hh"
|
|
|
|
|
#include "MOD_ui_common.hh"
|
|
|
|
|
#include "MOD_util.hh"
|
2013-01-21 15:41:00 +00:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void init_data(ModifierData *md)
|
2013-01-21 15:41:00 +00:00
|
|
|
{
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static bool depends_on_time(Scene * /*scene*/, ModifierData *md)
|
2013-01-21 15:41:00 +00:00
|
|
|
{
|
|
|
|
|
MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md;
|
|
|
|
|
return (mcmd->play_mode == MOD_MESHCACHE_PLAY_CFEA);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static bool is_disabled(const Scene * /*scene*/, ModifierData *md, bool /*use_render_params*/)
|
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)) ?
|
2023-05-04 18:35:37 +02:00
|
|
|
static_cast<float(*)[3]>(MEM_malloc_arrayN(
|
|
|
|
|
verts_num, sizeof(*vertexCos_Store), __func__)) :
|
|
|
|
|
nullptr;
|
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];
|
2023-05-04 18:35:37 +02:00
|
|
|
const char *err_str = nullptr;
|
2013-01-21 15:41:00 +00:00
|
|
|
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
|
|
|
/* -------------------------------------------------------------------- */
|
2023-09-14 13:25:24 +10:00
|
|
|
/* Interpret Time (the reading functions also do some of this). */
|
2013-01-21 15:41:00 +00:00
|
|
|
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 */
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(filepath, mcmd->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) {
|
2023-12-08 16:40:06 -05:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(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
|
|
|
}
|
2023-12-20 02:21:48 +01:00
|
|
|
else if (UNLIKELY(mesh->verts_num != 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
|
|
|
}
|
2023-12-08 16:40:06 -05:00
|
|
|
else if (UNLIKELY(mesh->faces_num == 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 {
|
2023-05-04 18:35:37 +02:00
|
|
|
float(*vertexCos_New)[3] = static_cast<float(*)[3]>(
|
|
|
|
|
MEM_malloc_arrayN(verts_num, sizeof(*vertexCos_New), __func__));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-24 05:54:17 +00:00
|
|
|
BKE_mesh_calc_relative_deform(
|
2023-12-08 16:40:06 -05:00
|
|
|
mesh->face_offsets().data(),
|
|
|
|
|
mesh->faces_num,
|
|
|
|
|
mesh->corner_verts().data(),
|
2023-12-20 02:21:48 +01:00
|
|
|
mesh->verts_num,
|
2023-12-20 09:56:15 +11:00
|
|
|
/* From the original Mesh. */
|
|
|
|
|
reinterpret_cast<const float(*)[3]>(mesh->vert_positions().data()),
|
|
|
|
|
/* the input we've been given (shape keys!) */
|
|
|
|
|
const_cast<const float(*)[3]>(vertexCos_Real),
|
|
|
|
|
/* The result of this modifier. */
|
|
|
|
|
const_cast<const float(*)[3]>(vertexCos),
|
|
|
|
|
/* The result of this function. */
|
|
|
|
|
vertexCos_New);
|
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_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;
|
2023-12-12 20:45:16 -05:00
|
|
|
if (!mesh->deform_verts().is_empty()) {
|
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
|
|
|
}
|
|
|
|
|
|
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)
|
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
|
|
|
|
2023-11-14 10:54:57 +01:00
|
|
|
meshcache_do(mcmd,
|
|
|
|
|
scene,
|
|
|
|
|
ctx->object,
|
|
|
|
|
mesh,
|
|
|
|
|
reinterpret_cast<float(*)[3]>(positions.data()),
|
|
|
|
|
positions.size());
|
2013-01-21 15:41:00 +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 *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);
|
|
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "cache_format", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "filepath", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
uiItemR(layout, ptr, "factor", UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "deform_mode", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "interpolation", UI_ITEM_NONE, nullptr, ICON_NONE);
|
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
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
modifier_panel_end(layout, ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
static void time_remapping_panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, nullptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
uiItemR(layout, ptr, "time_mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
uiItemR(layout, ptr, "play_mode", UI_ITEM_R_EXPAND, nullptr, 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) {
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "frame_start", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "frame_scale", UI_ITEM_NONE, nullptr, 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) {
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "eval_frame", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
else if (time_mode == MOD_MESHCACHE_TIME_SECONDS) {
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "eval_time", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
else { /* time_mode == MOD_MESHCACHE_TIME_FACTOR */
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "eval_factor", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
static void axis_mapping_panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *col;
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, nullptr);
|
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"));
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(col, ptr, "forward_axis", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "up_axis", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
uiItemR(layout, ptr, "flip_axis", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
|
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
|
|
|
{
|
|
|
|
|
PanelType *panel_type = modifier_panel_register(
|
|
|
|
|
region_type, eModifierType_MeshCache, panel_draw);
|
|
|
|
|
modifier_subpanel_register(region_type,
|
|
|
|
|
"time_remapping",
|
|
|
|
|
"Time Remapping",
|
2023-05-04 18:35:37 +02:00
|
|
|
nullptr,
|
2020-06-05 10:41:03 -04:00
|
|
|
time_remapping_panel_draw,
|
|
|
|
|
panel_type);
|
|
|
|
|
modifier_subpanel_register(
|
2023-05-04 18:35:37 +02:00
|
|
|
region_type, "axis_mapping", "Axis Mapping", nullptr, axis_mapping_panel_draw, panel_type);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2013-01-21 15:41:00 +00:00
|
|
|
ModifierTypeInfo modifierType_MeshCache = {
|
2023-07-26 17:08:14 +02:00
|
|
|
/*idname*/ "MeshCache",
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("MeshCache"),
|
2023-07-27 12:04:18 +10:00
|
|
|
/*struct_name*/ "MeshCacheModifierData",
|
|
|
|
|
/*struct_size*/ sizeof(MeshCacheModifierData),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*srna*/ &RNA_MeshCacheModifier,
|
2023-11-14 10:03:56 +01:00
|
|
|
/*type*/ ModifierTypeType::OnlyDeform,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*flags*/ eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_AcceptsVertexCosOnly |
|
2013-01-21 15:41:00 +00:00
|
|
|
eModifierTypeFlag_SupportsEditmode,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*icon*/ ICON_MOD_MESHDEFORM, /* TODO: Use correct icon. */
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
/*copy_data*/ BKE_modifier_copydata_generic,
|
|
|
|
|
|
|
|
|
|
/*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*/ nullptr,
|
|
|
|
|
/*free_data*/ nullptr,
|
|
|
|
|
/*is_disabled*/ is_disabled,
|
|
|
|
|
/*update_depsgraph*/ nullptr,
|
|
|
|
|
/*depends_on_time*/ depends_on_time,
|
|
|
|
|
/*depends_on_normals*/ nullptr,
|
|
|
|
|
/*foreach_ID_link*/ nullptr,
|
|
|
|
|
/*foreach_tex_link*/ nullptr,
|
|
|
|
|
/*free_runtime_data*/ nullptr,
|
|
|
|
|
/*panel_register*/ panel_register,
|
|
|
|
|
/*blend_write*/ nullptr,
|
|
|
|
|
/*blend_read*/ nullptr,
|
2024-01-18 22:51:30 +01:00
|
|
|
/*foreach_cache*/ nullptr,
|
2013-01-21 15:41:00 +00:00
|
|
|
};
|