2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2011 by Nicholas Bishop. */
|
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"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
2011-12-30 21:11:40 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
#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
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BKE_context.h"
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2020-03-31 17:06:17 +02:00
|
|
|
#include "BKE_mesh_remesh_voxel.h"
|
2018-06-05 15:59:53 +02:00
|
|
|
#include "BKE_mesh_runtime.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"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
#include "MOD_modifiertypes.h"
|
|
|
|
|
#include "MOD_ui_common.h"
|
2018-05-12 09:31:44 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
|
{
|
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-01-19 15:54:47 -06:00
|
|
|
input->co = (DualConCo)BKE_mesh_vert_positions(mesh);
|
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
|
|
|
input->co_stride = sizeof(float[3]);
|
2018-05-12 09:31:44 +02:00
|
|
|
input->totco = mesh->totvert;
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2023-02-23 10:39:51 -05:00
|
|
|
input->mloop = (DualConLoop)mesh->loops().data();
|
2018-05-12 09:31:44 +02:00
|
|
|
input->loop_stride = sizeof(MLoop);
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2023-02-28 14:52:31 +01:00
|
|
|
input->looptri = (DualConTri)mesh->looptris().data();
|
2018-05-12 09:31:44 +02:00
|
|
|
input->tri_stride = sizeof(MLoopTri);
|
2022-10-12 20:55:26 -05:00
|
|
|
input->tottri = BKE_mesh_runtime_looptri_len(mesh);
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
INIT_MINMAX(input->min, input->max);
|
|
|
|
|
BKE_mesh_minmax(mesh, input->min, input->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 */
|
2011-12-30 21:11:40 +00:00
|
|
|
typedef struct {
|
2018-05-12 09:31:44 +02:00
|
|
|
Mesh *mesh;
|
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
|
|
|
float (*vert_positions)[3];
|
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
|
|
|
MPoly *polys;
|
|
|
|
|
MLoop *loops;
|
2011-12-30 21:11:40 +00:00
|
|
|
int curvert, curface;
|
|
|
|
|
} DualConOutput;
|
|
|
|
|
|
|
|
|
|
/* 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-02-27 11:09:26 -05:00
|
|
|
output->mesh = BKE_mesh_new_nomain(totvert, 0, 4 * totquad, totquad);
|
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
|
|
|
output->vert_positions = BKE_mesh_vert_positions_for_write(output->mesh);
|
2023-02-23 10:39:51 -05:00
|
|
|
output->polys = output->mesh->polys_for_write().data();
|
|
|
|
|
output->loops = output->mesh->loops_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
|
|
|
|
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
|
|
|
BLI_assert(output->curvert < output->mesh->totvert);
|
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
|
|
|
|
2019-08-26 14:32:35 +10:00
|
|
|
BLI_assert(output->curface < mesh->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
|
|
|
UNUSED_VARS_NDEBUG(mesh);
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2023-03-03 11:40:34 -05:00
|
|
|
output->polys[output->curface].loopstart = output->curface * 4;
|
|
|
|
|
output->polys[output->curface].totloop = 4;
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2023-03-03 11:40:34 -05:00
|
|
|
MLoop *mloop = output->loops;
|
2019-05-31 22:51:19 +10:00
|
|
|
for (i = 0; i < 4; i++) {
|
2012-02-07 01:20:49 +00:00
|
|
|
mloop[output->curface * 4 + i].v = 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-01-19 15:54:47 -06:00
|
|
|
static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext * /*ctx*/, Mesh *mesh)
|
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-02-23 10:39:51 -05:00
|
|
|
BKE_mesh_smooth_flag_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);
|
2018-05-12 09:31:44 +02:00
|
|
|
BKE_mesh_calc_edges(result, true, false);
|
2011-12-30 21:11:40 +00:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-31 03:34:44 +00:00
|
|
|
#else /* !WITH_MOD_REMESH */
|
|
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
static Mesh *modifyMesh(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-01-19 15:54:47 -06:00
|
|
|
uiItemR(col, ptr, "voxel_size", 0, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "adaptivity", 0, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
else {
|
2023-01-19 15:54:47 -06:00
|
|
|
uiItemR(col, ptr, "octree_depth", 0, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "scale", 0, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
if (mode == MOD_REMESH_SHARP_FEATURES) {
|
2023-01-19 15:54:47 -06:00
|
|
|
uiItemR(col, ptr, "sharpness", 0, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
uiItemR(layout, ptr, "use_remove_disconnected", 0, 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-01-19 15:54:47 -06:00
|
|
|
uiItemR(layout, ptr, "threshold", 0, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
2023-01-19 15:54:47 -06:00
|
|
|
uiItemR(layout, ptr, "use_smooth_shade", 0, 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 */
|
2021-11-02 17:50:18 +01:00
|
|
|
uiItemL(layout, TIP_("Built without Remesh modifier"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
#endif /* WITH_MOD_REMESH */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void panelRegister(ARegionType *region_type)
|
|
|
|
|
{
|
|
|
|
|
modifier_panel_register(region_type, eModifierType_Remesh, panel_draw);
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-30 21:11:40 +00:00
|
|
|
ModifierTypeInfo modifierType_Remesh = {
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("Remesh"),
|
|
|
|
|
/*structName*/ "RemeshModifierData",
|
|
|
|
|
/*structSize*/ sizeof(RemeshModifierData),
|
|
|
|
|
/*srna*/ &RNA_RemeshModifier,
|
|
|
|
|
/*type*/ eModifierTypeType_Nonconstructive,
|
|
|
|
|
/*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,
|
|
|
|
|
|
|
|
|
|
/*copyData*/ BKE_modifier_copydata_generic,
|
|
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
/*deformVerts*/ nullptr,
|
|
|
|
|
/*deformMatrices*/ nullptr,
|
|
|
|
|
/*deformVertsEM*/ nullptr,
|
|
|
|
|
/*deformMatricesEM*/ nullptr,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*modifyMesh*/ modifyMesh,
|
2023-01-19 15:54:47 -06:00
|
|
|
/*modifyGeometrySet*/ nullptr,
|
2023-01-16 12:41:11 +11:00
|
|
|
|
|
|
|
|
/*initData*/ initData,
|
2023-01-19 15:54:47 -06:00
|
|
|
/*requiredDataMask*/ nullptr,
|
|
|
|
|
/*freeData*/ nullptr,
|
|
|
|
|
/*isDisabled*/ nullptr,
|
|
|
|
|
/*updateDepsgraph*/ nullptr,
|
|
|
|
|
/*dependsOnTime*/ nullptr,
|
|
|
|
|
/*dependsOnNormals*/ nullptr,
|
|
|
|
|
/*foreachIDLink*/ nullptr,
|
|
|
|
|
/*foreachTexLink*/ nullptr,
|
|
|
|
|
/*freeRuntimeData*/ nullptr,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*panelRegister*/ panelRegister,
|
2023-01-19 15:54:47 -06:00
|
|
|
/*blendWrite*/ nullptr,
|
|
|
|
|
/*blendRead*/ nullptr,
|
2011-12-30 21:11:40 +00:00
|
|
|
};
|