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
|
|
|
*/
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
#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"
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
static bool dependsOnTime(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-05-04 18:35:37 +02:00
|
|
|
static bool isDisabled(const Scene * /*scene*/, ModifierData *md, bool /*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)) ?
|
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
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/* 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 */
|
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-05-04 18:35:37 +02:00
|
|
|
Mesh *me = 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
|
|
|
}
|
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 {
|
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(
|
Mesh: Replace MPoly struct with offset indices
Implements #95967.
Currently the `MPoly` struct is 12 bytes, and stores the index of a
face's first corner and the number of corners/verts/edges. Polygons
and corners are always created in order by Blender, meaning each
face's corners will be after the previous face's corners. We can take
advantage of this fact and eliminate the redundancy in mesh face
storage by only storing a single integer corner offset for each face.
The size of the face is then encoded by the offset of the next face.
The size of a single integer is 4 bytes, so this reduces memory
usage by 3 times.
The same method is used for `CurvesGeometry`, so Blender already has
an abstraction to simplify using these offsets called `OffsetIndices`.
This class is used to easily retrieve a range of corner indices for
each face. This also gives the opportunity for sharing some logic with
curves.
Another benefit of the change is that the offsets and sizes stored in
`MPoly` can no longer disagree with each other. Storing faces in the
order of their corners can simplify some code too.
Face/polygon variables now use the `IndexRange` type, which comes with
quite a few utilities that can simplify code.
Some:
- The offset integer array has to be one longer than the face count to
avoid a branch for every face, which means the data is no longer part
of the mesh's `CustomData`.
- We lose the ability to "reference" an original mesh's offset array
until more reusable CoW from #104478 is committed. That will be added
in a separate commit.
- Since they aren't part of `CustomData`, poly offsets often have to be
copied manually.
- To simplify using `OffsetIndices` in many places, some functions and
structs in headers were moved to only compile in C++.
- All meshes created by Blender use the same order for faces and face
corners, but just in case, meshes with mismatched order are fixed by
versioning code.
- `MeshPolygon.totloop` is no longer editable in RNA. This API break is
necessary here unfortunately. It should be worth it in 3.6, since
that's the best way to allow loading meshes from 4.0, which is
important for an LTS version.
Pull Request: https://projects.blender.org/blender/blender/pulls/105938
2023-04-04 20:39:28 +02:00
|
|
|
BKE_mesh_poly_offsets(me),
|
2013-01-24 05:54:17 +00:00
|
|
|
me->totpoly,
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
BKE_mesh_corner_verts(me),
|
2013-01-24 05:54:17 +00:00
|
|
|
me->totvert,
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
BKE_mesh_vert_positions(me), /* From the original Mesh. */
|
|
|
|
|
(const float(*)[3])vertexCos_Real, /* the input we've been given (shape keys!) */
|
|
|
|
|
(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_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-05-04 18:35:37 +02:00
|
|
|
if (BKE_mesh_deform_verts(mesh) != nullptr) {
|
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
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
Mesh *mesh_src = nullptr;
|
2021-09-09 14:01:15 +10:00
|
|
|
|
|
|
|
|
if (ctx->object->type == OB_MESH && mcmd->defgrp_name[0] != '\0') {
|
|
|
|
|
/* `mesh_src` is only needed for vertex groups. */
|
2023-05-04 18:35:37 +02:00
|
|
|
mesh_src = MOD_deform_mesh_eval_get(ctx->object, nullptr, mesh, nullptr, 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
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
if (!ELEM(mesh_src, nullptr, mesh)) {
|
|
|
|
|
BKE_id_free(nullptr, mesh_src);
|
2021-09-09 14:01:15 +10:00
|
|
|
}
|
2013-01-21 15:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void deformVertsEM(ModifierData *md,
|
2018-08-15 16:21:43 +02:00
|
|
|
const ModifierEvalContext *ctx,
|
2023-05-04 18:35:37 +02:00
|
|
|
BMEditMesh *editData,
|
2021-09-09 14:01:15 +10:00
|
|
|
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
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
Mesh *mesh_src = nullptr;
|
2021-09-09 14:01:15 +10:00
|
|
|
|
|
|
|
|
if (ctx->object->type == OB_MESH && mcmd->defgrp_name[0] != '\0') {
|
|
|
|
|
/* `mesh_src` is only needed for vertex groups. */
|
2023-05-04 18:35:37 +02:00
|
|
|
mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, nullptr, verts_num, false);
|
2021-09-09 14:01:15 +10:00
|
|
|
}
|
2023-05-04 18:35:37 +02:00
|
|
|
if (mesh_src != nullptr) {
|
2021-09-09 14:01:15 +10:00
|
|
|
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
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
if (!ELEM(mesh_src, nullptr, mesh)) {
|
|
|
|
|
BKE_id_free(nullptr, mesh_src);
|
2021-09-09 14:01:15 +10:00
|
|
|
}
|
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-05-04 18:35:37 +02:00
|
|
|
uiItemR(layout, ptr, "cache_format", 0, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "filepath", 0, 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);
|
|
|
|
|
uiItemR(layout, ptr, "deform_mode", 0, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "interpolation", 0, nullptr, ICON_NONE);
|
|
|
|
|
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-05-04 18:35:37 +02:00
|
|
|
uiItemR(layout, ptr, "frame_start", 0, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "frame_scale", 0, 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-05-04 18:35:37 +02:00
|
|
|
uiItemR(layout, ptr, "eval_frame", 0, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
else if (time_mode == MOD_MESHCACHE_TIME_SECONDS) {
|
2023-05-04 18:35:37 +02:00
|
|
|
uiItemR(layout, ptr, "eval_time", 0, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
else { /* time_mode == MOD_MESHCACHE_TIME_FACTOR */
|
2023-05-04 18:35:37 +02:00
|
|
|
uiItemR(layout, ptr, "eval_factor", 0, 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-05-04 18:35:37 +02:00
|
|
|
uiItemR(col, ptr, "forward_axis", 0, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "up_axis", 0, 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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",
|
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-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("MeshCache"),
|
|
|
|
|
/*structName*/ "MeshCacheModifierData",
|
|
|
|
|
/*structSize*/ sizeof(MeshCacheModifierData),
|
|
|
|
|
/*srna*/ &RNA_MeshCacheModifier,
|
|
|
|
|
/*type*/ eModifierTypeType_OnlyDeform,
|
|
|
|
|
/*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. */
|
|
|
|
|
|
|
|
|
|
/*copyData*/ BKE_modifier_copydata_generic,
|
|
|
|
|
|
|
|
|
|
/*deformVerts*/ deformVerts,
|
2023-05-04 18:35:37 +02:00
|
|
|
/*deformMatrices*/ nullptr,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*deformVertsEM*/ deformVertsEM,
|
2023-05-04 18:35:37 +02:00
|
|
|
/*deformMatricesEM*/ nullptr,
|
|
|
|
|
/*modifyMesh*/ nullptr,
|
|
|
|
|
/*modifyGeometrySet*/ nullptr,
|
2023-01-16 12:41:11 +11:00
|
|
|
|
|
|
|
|
/*initData*/ initData,
|
2023-05-04 18:35:37 +02:00
|
|
|
/*requiredDataMask*/ nullptr,
|
|
|
|
|
/*freeData*/ nullptr,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*isDisabled*/ isDisabled,
|
2023-05-04 18:35:37 +02:00
|
|
|
/*updateDepsgraph*/ nullptr,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*dependsOnTime*/ dependsOnTime,
|
2023-05-04 18:35:37 +02:00
|
|
|
/*dependsOnNormals*/ nullptr,
|
|
|
|
|
/*foreachIDLink*/ nullptr,
|
|
|
|
|
/*foreachTexLink*/ nullptr,
|
|
|
|
|
/*freeRuntimeData*/ nullptr,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*panelRegister*/ panelRegister,
|
2023-05-04 18:35:37 +02:00
|
|
|
/*blendWrite*/ nullptr,
|
|
|
|
|
/*blendRead*/ nullptr,
|
2013-01-21 15:41:00 +00:00
|
|
|
};
|