2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2011 by Nicholas Bishop.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup modifiers
|
2011-12-30 21:11:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "BLI_math_base.h"
|
2020-05-11 10:16:29 +02:00
|
|
|
#include "BLI_threads.h"
|
2023-01-19 15:54:47 -06:00
|
|
|
#include "BLI_utildefines.h"
|
2019-02-25 11:39:14 +01:00
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
#include "DNA_defaults.h"
|
2011-12-30 21:11:40 +00:00
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "DNA_screen_types.h"
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2023-08-02 22:14:18 +02:00
|
|
|
#include "BKE_mesh_remesh_voxel.hh"
|
|
|
|
|
#include "BKE_mesh_runtime.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-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include "MOD_modifiertypes.hh"
|
|
|
|
|
#include "MOD_ui_common.hh"
|
2018-05-12 09:31:44 +02:00
|
|
|
|
Geometry: add utility to check for bad geometry element index dependence
Sometimes .blend files have compatibility issues between Blender versions,
because .blend files depended on the specific order of geometry elements
generated by some nodes/modifiers (#112746, #113018). While we make
guarantees about the order in some places, that is relatively rare, because it
makes future improvements much harder. The functionality in this patch
makes it easier for users to notice when they depend on things that are not
expected to be stable between Blender builds.
This is achieved by adding a new global flag which indicates whether some
algorithms should randomize their output. The functionality can be toggled
on or off by searching for `Set Geometry Randomization`. If there are no
differences (or acceptable minor ones) when the flag is on or off, one can
be reasonably sure that one does not on unspecified behavior (can't be 100%
sure though, because randomization might be missing in some places). If
there are big differences, one should consider fixing the file before it comes
to an actual breakage in the next Blender version.
Currently, the setting is only available when `Developer Extras` is turned on,
because the setting is in no menu.
With this patch, if we get bug reports with compatibility issues caused by
depending on indices, one of the following three cases should always apply:
* We actually accidentally broke something, which requires a fix commit.
* Turning on geometry randomization shows that the .blend file depends on
things it shouldn't depend on. In this case the user has to fix the file.
* We are missing geometry randomization somewhere, which requires a fix
commit.
Pull Request: https://projects.blender.org/blender/blender/pulls/113030
2023-09-29 21:44:36 +02:00
|
|
|
#include "GEO_randomize.hh"
|
|
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstring>
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2011-12-31 03:34:44 +00:00
|
|
|
#ifdef WITH_MOD_REMESH
|
2019-01-26 20:41:52 +11:00
|
|
|
# include "BLI_math_vector.h"
|
|
|
|
|
|
2011-12-31 03:34:44 +00:00
|
|
|
# include "dualcon.h"
|
|
|
|
|
#endif
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void init_data(ModifierData *md)
|
2011-12-30 21:11:40 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
RemeshModifierData *rmd = (RemeshModifierData *)md;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(rmd, modifier));
|
|
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(rmd, DNA_struct_default_get(RemeshModifierData), modifier);
|
2011-12-30 21:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-31 03:34:44 +00:00
|
|
|
#ifdef WITH_MOD_REMESH
|
|
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
static void init_dualcon_mesh(DualConInput *input, Mesh *mesh)
|
2011-12-30 21:11:40 +00:00
|
|
|
{
|
2018-05-12 09:31:44 +02:00
|
|
|
memset(input, 0, sizeof(DualConInput));
|
|
|
|
|
|
2023-06-14 11:59:32 -04:00
|
|
|
input->co = (DualConCo)mesh->vert_positions().data();
|
|
|
|
|
input->co_stride = sizeof(blender::float3);
|
2023-12-20 02:21:48 +01:00
|
|
|
input->totco = mesh->verts_num;
|
2011-12-30 21:11:40 +00:00
|
|
|
|
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
|
|
|
input->mloop = (DualConLoop)mesh->corner_verts().data();
|
|
|
|
|
input->loop_stride = sizeof(int);
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2023-12-19 14:57:49 +01:00
|
|
|
input->corner_tris = (DualConTri)mesh->corner_tris().data();
|
|
|
|
|
input->tri_stride = sizeof(blender::int3);
|
|
|
|
|
input->tottri = BKE_mesh_runtime_corner_tris_len(mesh);
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2023-06-16 08:08:18 -04:00
|
|
|
const blender::Bounds<blender::float3> bounds = *mesh->bounds_min_max();
|
|
|
|
|
copy_v3_v3(input->min, bounds.min);
|
|
|
|
|
copy_v3_v3(input->max, bounds.max);
|
2011-12-30 21:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* simple structure to hold the output: a CDDM and two counters to
|
2012-03-09 18:28:30 +00:00
|
|
|
* keep track of the current elements */
|
2023-07-02 19:37:19 +10:00
|
|
|
struct DualConOutput {
|
2018-05-12 09:31:44 +02:00
|
|
|
Mesh *mesh;
|
2023-06-14 11:59:32 -04:00
|
|
|
blender::float3 *vert_positions;
|
2023-07-24 22:06:55 +02:00
|
|
|
int *face_offsets;
|
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
|
|
|
int *corner_verts;
|
2011-12-30 21:11:40 +00:00
|
|
|
int curvert, curface;
|
2023-07-02 19:37:19 +10:00
|
|
|
};
|
2011-12-30 21:11:40 +00:00
|
|
|
|
|
|
|
|
/* allocate and initialize a DualConOutput */
|
2011-12-31 03:34:44 +00:00
|
|
|
static void *dualcon_alloc_output(int totvert, int totquad)
|
2011-12-30 21:11:40 +00:00
|
|
|
{
|
|
|
|
|
DualConOutput *output;
|
|
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
if (!(output = MEM_cnew<DualConOutput>(__func__))) {
|
|
|
|
|
return nullptr;
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2023-04-19 15:28:53 -04:00
|
|
|
output->mesh = BKE_mesh_new_nomain(totvert, 0, totquad, 4 * totquad);
|
2023-06-14 11:59:32 -04:00
|
|
|
output->vert_positions = output->mesh->vert_positions_for_write().data();
|
2023-07-24 22:06:55 +02:00
|
|
|
output->face_offsets = output->mesh->face_offsets_for_write().data();
|
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
|
|
|
output->corner_verts = output->mesh->corner_verts_for_write().data();
|
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
|
|
|
|
2011-12-30 21:11:40 +00:00
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-31 03:34:44 +00:00
|
|
|
static void dualcon_add_vert(void *output_v, const float co[3])
|
2011-12-30 21:11:40 +00:00
|
|
|
{
|
2023-01-19 15:54:47 -06:00
|
|
|
DualConOutput *output = static_cast<DualConOutput *>(output_v);
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2023-12-20 02:21:48 +01:00
|
|
|
BLI_assert(output->curvert < output->mesh->verts_num);
|
2018-06-17 17:04:27 +02:00
|
|
|
|
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
|
|
|
copy_v3_v3(output->vert_positions[output->curvert], co);
|
2011-12-30 21:11:40 +00:00
|
|
|
output->curvert++;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-31 03:34:44 +00:00
|
|
|
static void dualcon_add_quad(void *output_v, const int vert_indices[4])
|
2011-12-30 21:11:40 +00:00
|
|
|
{
|
2023-01-19 15:54:47 -06:00
|
|
|
DualConOutput *output = static_cast<DualConOutput *>(output_v);
|
2018-05-12 09:31:44 +02:00
|
|
|
Mesh *mesh = output->mesh;
|
2012-02-07 01:20:49 +00:00
|
|
|
int i;
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
BLI_assert(output->curface < mesh->faces_num);
|
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
|
|
|
UNUSED_VARS_NDEBUG(mesh);
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
output->face_offsets[output->curface] = output->curface * 4;
|
2019-05-31 22:51:19 +10:00
|
|
|
for (i = 0; i < 4; i++) {
|
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
|
|
|
output->corner_verts[output->curface * 4 + i] = vert_indices[i];
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2012-02-07 01:20:49 +00:00
|
|
|
output->curface++;
|
2011-12-30 21:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext * /*ctx*/, Mesh *mesh)
|
2011-12-30 21:11:40 +00:00
|
|
|
{
|
2023-12-13 09:50:24 -05:00
|
|
|
using namespace blender;
|
2011-12-30 21:11:40 +00:00
|
|
|
RemeshModifierData *rmd;
|
|
|
|
|
DualConOutput *output;
|
|
|
|
|
DualConInput input;
|
2018-05-12 09:31:44 +02:00
|
|
|
Mesh *result;
|
2023-01-19 15:54:47 -06:00
|
|
|
DualConFlags flags = DualConFlags(0);
|
|
|
|
|
DualConMode mode = DualConMode(0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
rmd = (RemeshModifierData *)md;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-31 17:06:17 +02:00
|
|
|
if (rmd->mode == MOD_REMESH_VOXEL) {
|
|
|
|
|
/* OpenVDB modes. */
|
|
|
|
|
if (rmd->voxel_size == 0.0f) {
|
2023-01-19 15:54:47 -06:00
|
|
|
return nullptr;
|
2020-03-31 17:06:17 +02:00
|
|
|
}
|
2021-07-30 22:18:44 -04:00
|
|
|
result = BKE_mesh_remesh_voxel(mesh, rmd->voxel_size, rmd->adaptivity, 0.0f);
|
2023-01-19 15:54:47 -06:00
|
|
|
if (result == nullptr) {
|
|
|
|
|
return nullptr;
|
2020-09-03 13:28:15 +10:00
|
|
|
}
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2020-03-31 17:06:17 +02:00
|
|
|
else {
|
|
|
|
|
/* Dualcon modes. */
|
|
|
|
|
init_dualcon_mesh(&input, mesh);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-31 17:06:17 +02:00
|
|
|
if (rmd->flag & MOD_REMESH_FLOOD_FILL) {
|
2023-01-19 15:54:47 -06:00
|
|
|
flags = DualConFlags(flags | DUALCON_FLOOD_FILL);
|
2020-03-31 17:06:17 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-31 17:06:17 +02:00
|
|
|
switch (rmd->mode) {
|
|
|
|
|
case MOD_REMESH_CENTROID:
|
|
|
|
|
mode = DUALCON_CENTROID;
|
|
|
|
|
break;
|
|
|
|
|
case MOD_REMESH_MASS_POINT:
|
|
|
|
|
mode = DUALCON_MASS_POINT;
|
|
|
|
|
break;
|
|
|
|
|
case MOD_REMESH_SHARP_FEATURES:
|
|
|
|
|
mode = DUALCON_SHARP_FEATURES;
|
|
|
|
|
break;
|
|
|
|
|
case MOD_REMESH_VOXEL:
|
|
|
|
|
/* Should have been processed before as an OpenVDB operation. */
|
|
|
|
|
BLI_assert(false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-05-11 10:16:29 +02:00
|
|
|
/* TODO(jbakker): Dualcon crashes when run in parallel. Could be related to incorrect
|
2020-07-01 13:12:24 +10:00
|
|
|
* input data or that the library isn't thread safe.
|
2023-02-12 14:37:16 +11:00
|
|
|
* This was identified when changing the task isolation's during #76553. */
|
2020-05-11 10:16:29 +02:00
|
|
|
static ThreadMutex dualcon_mutex = BLI_MUTEX_INITIALIZER;
|
|
|
|
|
BLI_mutex_lock(&dualcon_mutex);
|
2023-01-19 15:54:47 -06:00
|
|
|
output = static_cast<DualConOutput *>(dualcon(&input,
|
|
|
|
|
dualcon_alloc_output,
|
|
|
|
|
dualcon_add_vert,
|
|
|
|
|
dualcon_add_quad,
|
|
|
|
|
flags,
|
|
|
|
|
mode,
|
|
|
|
|
rmd->threshold,
|
|
|
|
|
rmd->hermite_num,
|
|
|
|
|
rmd->scale,
|
|
|
|
|
rmd->depth));
|
2020-05-11 10:16:29 +02:00
|
|
|
BLI_mutex_unlock(&dualcon_mutex);
|
2020-03-31 17:06:17 +02:00
|
|
|
result = output->mesh;
|
|
|
|
|
MEM_freeN(output);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-12-13 09:50:24 -05:00
|
|
|
bke::mesh_smooth_set(*result, rmd->flag & MOD_REMESH_SMOOTH_SHADING);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-17 14:56:39 +10:00
|
|
|
BKE_mesh_copy_parameters_for_eval(result, mesh);
|
2023-12-20 17:47:10 -05:00
|
|
|
bke::mesh_calc_edges(*result, true, false);
|
Geometry: add utility to check for bad geometry element index dependence
Sometimes .blend files have compatibility issues between Blender versions,
because .blend files depended on the specific order of geometry elements
generated by some nodes/modifiers (#112746, #113018). While we make
guarantees about the order in some places, that is relatively rare, because it
makes future improvements much harder. The functionality in this patch
makes it easier for users to notice when they depend on things that are not
expected to be stable between Blender builds.
This is achieved by adding a new global flag which indicates whether some
algorithms should randomize their output. The functionality can be toggled
on or off by searching for `Set Geometry Randomization`. If there are no
differences (or acceptable minor ones) when the flag is on or off, one can
be reasonably sure that one does not on unspecified behavior (can't be 100%
sure though, because randomization might be missing in some places). If
there are big differences, one should consider fixing the file before it comes
to an actual breakage in the next Blender version.
Currently, the setting is only available when `Developer Extras` is turned on,
because the setting is in no menu.
With this patch, if we get bug reports with compatibility issues caused by
depending on indices, one of the following three cases should always apply:
* We actually accidentally broke something, which requires a fix commit.
* Turning on geometry randomization shows that the .blend file depends on
things it shouldn't depend on. In this case the user has to fix the file.
* We are missing geometry randomization somewhere, which requires a fix
commit.
Pull Request: https://projects.blender.org/blender/blender/pulls/113030
2023-09-29 21:44:36 +02:00
|
|
|
|
|
|
|
|
blender::geometry::debug_randomize_mesh_order(result);
|
|
|
|
|
|
2011-12-30 21:11:40 +00:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-31 03:34:44 +00:00
|
|
|
#else /* !WITH_MOD_REMESH */
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static Mesh *modify_mesh(ModifierData * /*md*/, const ModifierEvalContext * /*ctx*/, Mesh *mesh)
|
2011-12-31 03:34:44 +00:00
|
|
|
{
|
2018-05-12 09:31:44 +02:00
|
|
|
return mesh;
|
2011-12-31 03:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* !WITH_MOD_REMESH */
|
|
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
static void panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
#ifdef WITH_MOD_REMESH
|
UI: Small Tweaks to Modifier Layouts for Consistency
These changes are smaller, made based on feedback and a pass on all
the layouts for clarity and consistency. The Multires modifier UI will
be addressed in a separate patch. Here is an overview of the changes:
Renaming Options:
- Build: "Start" -> "Start Frame"
- Curve: "From Radius" -> "Size from Radius"
- Screw: "Calc Order" -> "Calculate Order"
- Displace, Warp, Wave: "Texture Coordinates Object" -> "Object"
Move Mode Toggle to Top & Expand:
- Bevel, Boolean, Normal Edit, Subdivision
Use Columns for Tighter Spacing:
- Displace, Explode, Ocean, Particle Instance, Remesh, Shrinkwrap,
Solidify, Warp, Weighted Normal, Wave
Misc:
- Bevel: Set inactive properties for vertex bevel
- Mesh Sequence Cache: Remove box for cache file
- Skin: Don't align "Mark Loose" and "Clear Loose"
- Array: Expand relative offset subpanel by default
- Array: Move start cap, end cap to a new subpanel
- Bevel: Move width type above width
Differential Revision: https://developer.blender.org/D8115
2020-07-02 10:47:02 -04:00
|
|
|
uiLayout *row, *col;
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
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
|
|
|
int mode = RNA_enum_get(ptr, "mode");
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
UI: Small Tweaks to Modifier Layouts for Consistency
These changes are smaller, made based on feedback and a pass on all
the layouts for clarity and consistency. The Multires modifier UI will
be addressed in a separate patch. Here is an overview of the changes:
Renaming Options:
- Build: "Start" -> "Start Frame"
- Curve: "From Radius" -> "Size from Radius"
- Screw: "Calc Order" -> "Calculate Order"
- Displace, Warp, Wave: "Texture Coordinates Object" -> "Object"
Move Mode Toggle to Top & Expand:
- Bevel, Boolean, Normal Edit, Subdivision
Use Columns for Tighter Spacing:
- Displace, Explode, Ocean, Particle Instance, Remesh, Shrinkwrap,
Solidify, Warp, Weighted Normal, Wave
Misc:
- Bevel: Set inactive properties for vertex bevel
- Mesh Sequence Cache: Remove box for cache file
- Skin: Don't align "Mark Loose" and "Clear Loose"
- Array: Expand relative offset subpanel by default
- Array: Move start cap, end cap to a new subpanel
- Bevel: Move width type above width
Differential Revision: https://developer.blender.org/D8115
2020-07-02 10:47:02 -04:00
|
|
|
col = uiLayoutColumn(layout, false);
|
2020-06-05 10:41:03 -04:00
|
|
|
if (mode == MOD_REMESH_VOXEL) {
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(col, ptr, "voxel_size", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "adaptivity", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
else {
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(col, ptr, "octree_depth", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "scale", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
if (mode == MOD_REMESH_SHARP_FEATURES) {
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(col, ptr, "sharpness", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "use_remove_disconnected", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
row = uiLayoutRow(layout, false);
|
2020-09-02 14:13:26 -05:00
|
|
|
uiLayoutSetActive(row, RNA_boolean_get(ptr, "use_remove_disconnected"));
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "threshold", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "use_smooth_shade", UI_ITEM_NONE, nullptr, ICON_NONE);
|
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
|
|
|
|
|
|
|
|
#else /* WITH_MOD_REMESH */
|
2024-01-11 19:49:03 +01:00
|
|
|
uiItemL(layout, RPT_("Built without Remesh modifier"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
#endif /* WITH_MOD_REMESH */
|
|
|
|
|
}
|
|
|
|
|
|
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_Remesh, panel_draw);
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-30 21:11:40 +00:00
|
|
|
ModifierTypeInfo modifierType_Remesh = {
|
2023-07-26 17:08:14 +02:00
|
|
|
/*idname*/ "Remesh",
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("Remesh"),
|
2023-07-27 12:04:18 +10:00
|
|
|
/*struct_name*/ "RemeshModifierData",
|
|
|
|
|
/*struct_size*/ sizeof(RemeshModifierData),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*srna*/ &RNA_RemeshModifier,
|
2023-11-14 10:03:56 +01:00
|
|
|
/*type*/ ModifierTypeType::Nonconstructive,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*flags*/ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_AcceptsCVs |
|
2012-05-06 13:38:33 +00:00
|
|
|
eModifierTypeFlag_SupportsEditmode,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*icon*/ ICON_MOD_REMESH,
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
/*copy_data*/ BKE_modifier_copydata_generic,
|
|
|
|
|
|
|
|
|
|
/*deform_verts*/ nullptr,
|
|
|
|
|
/*deform_matrices*/ nullptr,
|
|
|
|
|
/*deform_verts_EM*/ nullptr,
|
|
|
|
|
/*deform_matrices_EM*/ nullptr,
|
|
|
|
|
/*modify_mesh*/ modify_mesh,
|
|
|
|
|
/*modify_geometry_set*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*init_data*/ init_data,
|
|
|
|
|
/*required_data_mask*/ nullptr,
|
|
|
|
|
/*free_data*/ nullptr,
|
|
|
|
|
/*is_disabled*/ nullptr,
|
|
|
|
|
/*update_depsgraph*/ nullptr,
|
|
|
|
|
/*depends_on_time*/ nullptr,
|
|
|
|
|
/*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,
|
2011-12-30 21:11:40 +00:00
|
|
|
};
|