2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2020-02-20 10:05:47 +01:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup modifiers
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2023-01-03 22:59:25 -05:00
|
|
|
#include "BLI_array_utils.hh"
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "BLI_ghash.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_listbase.h"
|
2020-02-20 10:05:47 +01:00
|
|
|
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "BLT_translation.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-02-20 10:05:47 +01:00
|
|
|
#include "DNA_armature_types.h"
|
2020-10-01 09:38:00 -05:00
|
|
|
#include "DNA_defaults.h"
|
2020-02-20 10:05:47 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#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"
|
2020-02-20 10:05:47 +01:00
|
|
|
|
|
|
|
|
#include "BKE_action.h" /* BKE_pose_channel_find_name */
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "BKE_context.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_customdata.hh"
|
2024-01-29 18:57:16 -05:00
|
|
|
#include "BKE_deform.hh"
|
2024-01-18 12:20:42 +01:00
|
|
|
#include "BKE_lib_query.hh"
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2023-11-14 09:30:40 +01:00
|
|
|
#include "BKE_modifier.hh"
|
2024-02-19 15:54:48 +01: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-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph_build.hh"
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "DEG_depsgraph_query.hh"
|
2020-02-20 10:05:47 +01:00
|
|
|
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "MOD_modifiertypes.hh"
|
2023-05-04 18:35:37 +02:00
|
|
|
#include "MOD_ui_common.hh"
|
2020-02-20 10:05:47 +01:00
|
|
|
|
2020-04-21 17:31:56 +02:00
|
|
|
#include "BLI_array.hh"
|
|
|
|
|
#include "BLI_listbase_wrapper.hh"
|
|
|
|
|
#include "BLI_vector.hh"
|
2020-02-20 10:05:47 +01:00
|
|
|
|
2020-06-09 10:27:24 +02:00
|
|
|
using blender::Array;
|
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
|
|
|
using blender::float3;
|
2020-06-09 10:27:24 +02:00
|
|
|
using blender::IndexRange;
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
using blender::int2;
|
2020-06-09 10:27:24 +02:00
|
|
|
using blender::ListBaseWrapper;
|
2020-06-09 11:58:47 +02:00
|
|
|
using blender::MutableSpan;
|
|
|
|
|
using blender::Span;
|
2020-06-09 10:27:24 +02:00
|
|
|
using blender::Vector;
|
2020-02-20 10:05:47 +01:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void init_data(ModifierData *md)
|
2020-10-01 09:38:00 -05:00
|
|
|
{
|
|
|
|
|
MaskModifierData *mmd = (MaskModifierData *)md;
|
|
|
|
|
|
|
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(mmd, modifier));
|
|
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(mmd, DNA_struct_default_get(MaskModifierData), modifier);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void required_data_mask(ModifierData * /*md*/, CustomData_MeshMasks *r_cddata_masks)
|
2020-02-20 10:05:47 +01:00
|
|
|
{
|
|
|
|
|
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
|
2020-02-20 10:05:47 +01:00
|
|
|
{
|
2020-08-07 18:24:59 +02:00
|
|
|
MaskModifierData *mmd = reinterpret_cast<MaskModifierData *>(md);
|
2023-07-27 12:04:18 +10:00
|
|
|
walk(user_data, ob, (ID **)&mmd->ob_arm, IDWALK_CB_NOP);
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void update_depsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
|
2020-02-20 10:05:47 +01:00
|
|
|
{
|
2020-08-07 18:24:59 +02:00
|
|
|
MaskModifierData *mmd = reinterpret_cast<MaskModifierData *>(md);
|
2020-02-20 10:05:47 +01:00
|
|
|
if (mmd->ob_arm) {
|
|
|
|
|
bArmature *arm = (bArmature *)mmd->ob_arm->data;
|
|
|
|
|
/* Tag relationship in depsgraph, but also on the armature. */
|
|
|
|
|
/* TODO(sergey): Is it a proper relation here? */
|
|
|
|
|
DEG_add_object_relation(ctx->node, mmd->ob_arm, DEG_OB_COMP_TRANSFORM, "Mask Modifier");
|
|
|
|
|
arm->flag |= ARM_HAS_VIZ_DEPS;
|
2022-08-04 12:11:31 +02:00
|
|
|
DEG_add_depends_on_transform_relation(ctx->node, "Mask Modifier");
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* A vertex will be in the mask if a selected bone influences it more than a certain threshold. */
|
2022-05-13 18:31:29 +02:00
|
|
|
static void compute_vertex_mask__armature_mode(const MDeformVert *dvert,
|
2021-07-13 12:10:34 -04:00
|
|
|
Mesh *mesh,
|
2020-02-20 10:05:47 +01:00
|
|
|
Object *armature_ob,
|
|
|
|
|
float threshold,
|
2020-06-09 11:58:47 +02:00
|
|
|
MutableSpan<bool> r_vertex_mask)
|
2020-02-20 10:05:47 +01:00
|
|
|
{
|
|
|
|
|
/* Element i is true if there is a selected bone that uses vertex group i. */
|
|
|
|
|
Vector<bool> selected_bone_uses_group;
|
|
|
|
|
|
2021-07-13 12:10:34 -04:00
|
|
|
LISTBASE_FOREACH (bDeformGroup *, def, &mesh->vertex_group_names) {
|
2020-02-20 10:05:47 +01:00
|
|
|
bPoseChannel *pchan = BKE_pose_channel_find_name(armature_ob->pose, def->name);
|
|
|
|
|
bool bone_for_group_exists = pchan && pchan->bone && (pchan->bone->flag & BONE_SELECTED);
|
|
|
|
|
selected_bone_uses_group.append(bone_for_group_exists);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-09 11:58:47 +02:00
|
|
|
Span<bool> use_vertex_group = selected_bone_uses_group;
|
2020-02-20 10:05:47 +01:00
|
|
|
|
|
|
|
|
for (int i : r_vertex_mask.index_range()) {
|
2020-06-09 11:58:47 +02:00
|
|
|
Span<MDeformWeight> weights(dvert[i].dw, dvert[i].totweight);
|
2020-02-20 10:05:47 +01:00
|
|
|
r_vertex_mask[i] = false;
|
|
|
|
|
|
|
|
|
|
/* check the groups that vertex is assigned to, and see if it was any use */
|
|
|
|
|
for (const MDeformWeight &dw : weights) {
|
|
|
|
|
if (use_vertex_group.get(dw.def_nr, false)) {
|
|
|
|
|
if (dw.weight > threshold) {
|
|
|
|
|
r_vertex_mask[i] = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* A vertex will be in the mask if the vertex group influences it more than a certain threshold. */
|
2022-05-13 18:31:29 +02:00
|
|
|
static void compute_vertex_mask__vertex_group_mode(const MDeformVert *dvert,
|
2020-02-20 10:05:47 +01:00
|
|
|
int defgrp_index,
|
|
|
|
|
float threshold,
|
2020-06-09 11:58:47 +02:00
|
|
|
MutableSpan<bool> r_vertex_mask)
|
2020-02-20 10:05:47 +01:00
|
|
|
{
|
|
|
|
|
for (int i : r_vertex_mask.index_range()) {
|
2020-03-06 12:50:56 +11:00
|
|
|
const bool found = BKE_defvert_find_weight(&dvert[i], defgrp_index) > threshold;
|
2020-02-20 10:05:47 +01:00
|
|
|
r_vertex_mask[i] = found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-08 11:22:30 +10:00
|
|
|
static void compute_masked_verts(Span<bool> vertex_mask,
|
|
|
|
|
MutableSpan<int> r_vertex_map,
|
|
|
|
|
uint *r_verts_masked_num)
|
2020-02-20 10:05:47 +01:00
|
|
|
{
|
|
|
|
|
BLI_assert(vertex_mask.size() == r_vertex_map.size());
|
|
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
uint verts_masked_num = 0;
|
2020-02-20 10:05:47 +01:00
|
|
|
for (uint i_src : r_vertex_map.index_range()) {
|
|
|
|
|
if (vertex_mask[i_src]) {
|
2022-03-28 12:29:47 +11:00
|
|
|
r_vertex_map[i_src] = verts_masked_num;
|
|
|
|
|
verts_masked_num++;
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
r_vertex_map[i_src] = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
*r_verts_masked_num = verts_masked_num;
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void computed_masked_edges(const Mesh *mesh,
|
2020-06-09 11:58:47 +02:00
|
|
|
Span<bool> vertex_mask,
|
|
|
|
|
MutableSpan<int> r_edge_map,
|
2022-03-28 12:29:47 +11:00
|
|
|
uint *r_edges_masked_num)
|
2020-02-20 10:05:47 +01:00
|
|
|
{
|
2023-12-20 02:21:48 +01:00
|
|
|
BLI_assert(mesh->edges_num == r_edge_map.size());
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
const Span<int2> edges = mesh->edges();
|
2020-02-20 10:05:47 +01:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
uint edges_masked_num = 0;
|
2023-12-20 02:21:48 +01:00
|
|
|
for (int i : IndexRange(mesh->edges_num)) {
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
const int2 &edge = edges[i];
|
2020-02-20 10:05:47 +01:00
|
|
|
|
|
|
|
|
/* only add if both verts will be in new mesh */
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
if (vertex_mask[edge[0]] && vertex_mask[edge[1]]) {
|
2022-03-28 12:29:47 +11:00
|
|
|
r_edge_map[i] = edges_masked_num;
|
|
|
|
|
edges_masked_num++;
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
r_edge_map[i] = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
*r_edges_masked_num = edges_masked_num;
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-27 11:32:44 +10:00
|
|
|
static void computed_masked_edges_smooth(const Mesh *mesh,
|
|
|
|
|
Span<bool> vertex_mask,
|
|
|
|
|
MutableSpan<int> r_edge_map,
|
2022-03-28 12:29:47 +11:00
|
|
|
uint *r_edges_masked_num,
|
|
|
|
|
uint *r_verts_add_num)
|
2021-08-27 11:32:44 +10:00
|
|
|
{
|
2023-12-20 02:21:48 +01:00
|
|
|
BLI_assert(mesh->edges_num == r_edge_map.size());
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
const Span<int2> edges = mesh->edges();
|
2021-08-27 11:32:44 +10:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
uint edges_masked_num = 0;
|
|
|
|
|
uint verts_add_num = 0;
|
2023-12-20 02:21:48 +01:00
|
|
|
for (int i : IndexRange(mesh->edges_num)) {
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
const int2 &edge = edges[i];
|
2021-08-27 11:32:44 +10:00
|
|
|
|
|
|
|
|
/* only add if both verts will be in new mesh */
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
bool v1 = vertex_mask[edge[0]];
|
|
|
|
|
bool v2 = vertex_mask[edge[1]];
|
2021-08-27 11:32:44 +10:00
|
|
|
if (v1 && v2) {
|
2022-03-28 12:29:47 +11:00
|
|
|
r_edge_map[i] = edges_masked_num;
|
|
|
|
|
edges_masked_num++;
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
|
|
|
|
else if (v1 != v2) {
|
|
|
|
|
r_edge_map[i] = -2;
|
2022-03-28 12:29:47 +11:00
|
|
|
verts_add_num++;
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
r_edge_map[i] = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
edges_masked_num += verts_add_num;
|
|
|
|
|
*r_edges_masked_num = edges_masked_num;
|
|
|
|
|
*r_verts_add_num = verts_add_num;
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
|
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
static void computed_masked_faces(const Mesh *mesh,
|
2022-09-08 11:22:30 +10:00
|
|
|
Span<bool> vertex_mask,
|
2023-07-24 22:06:55 +02:00
|
|
|
Vector<int> &r_masked_face_indices,
|
2022-09-08 11:22:30 +10:00
|
|
|
Vector<int> &r_loop_starts,
|
2023-07-24 22:06:55 +02:00
|
|
|
uint *r_faces_masked_num,
|
2022-09-08 11:22:30 +10:00
|
|
|
uint *r_loops_masked_num)
|
2020-02-20 10:05:47 +01:00
|
|
|
{
|
2023-12-20 02:21:48 +01:00
|
|
|
BLI_assert(mesh->verts_num == vertex_mask.size());
|
2023-07-24 22:06:55 +02:00
|
|
|
const blender::OffsetIndices faces = mesh->faces();
|
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
|
|
|
const Span<int> corner_verts = mesh->corner_verts();
|
2020-02-20 10:05:47 +01:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
r_masked_face_indices.reserve(mesh->faces_num);
|
|
|
|
|
r_loop_starts.reserve(mesh->faces_num);
|
2020-02-20 10:05:47 +01:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
uint loops_masked_num = 0;
|
2023-07-24 22:06:55 +02:00
|
|
|
for (int i : IndexRange(mesh->faces_num)) {
|
|
|
|
|
const blender::IndexRange face = faces[i];
|
2020-02-20 10:05:47 +01:00
|
|
|
|
|
|
|
|
bool all_verts_in_mask = true;
|
2023-07-24 22:06:55 +02:00
|
|
|
for (const int vert_i : corner_verts.slice(face)) {
|
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
|
|
|
if (!vertex_mask[vert_i]) {
|
2020-02-20 10:05:47 +01:00
|
|
|
all_verts_in_mask = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (all_verts_in_mask) {
|
2023-07-24 22:06:55 +02:00
|
|
|
r_masked_face_indices.append_unchecked(i);
|
2022-03-28 12:29:47 +11:00
|
|
|
r_loop_starts.append_unchecked(loops_masked_num);
|
2023-07-24 22:06:55 +02:00
|
|
|
loops_masked_num += face.size();
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
*r_faces_masked_num = r_masked_face_indices.size();
|
2022-03-28 12:29:47 +11:00
|
|
|
*r_loops_masked_num = loops_masked_num;
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
static void compute_interpolated_faces(const Mesh *mesh,
|
2022-09-08 11:22:30 +10:00
|
|
|
Span<bool> vertex_mask,
|
|
|
|
|
uint verts_add_num,
|
|
|
|
|
uint loops_masked_num,
|
2023-07-24 22:06:55 +02:00
|
|
|
Vector<int> &r_masked_face_indices,
|
2022-09-08 11:22:30 +10:00
|
|
|
Vector<int> &r_loop_starts,
|
|
|
|
|
uint *r_edges_add_num,
|
2023-07-24 22:06:55 +02:00
|
|
|
uint *r_faces_add_num,
|
2022-09-08 11:22:30 +10:00
|
|
|
uint *r_loops_add_num)
|
2021-08-27 11:32:44 +10:00
|
|
|
{
|
2023-12-20 02:21:48 +01:00
|
|
|
BLI_assert(mesh->verts_num == vertex_mask.size());
|
2021-08-27 11:32:44 +10:00
|
|
|
|
|
|
|
|
/* Can't really know ahead of time how much space to use exactly. Estimate limit instead. */
|
|
|
|
|
/* NOTE: this reserve can only lift the capacity if there are ngons, which get split. */
|
2023-07-24 22:06:55 +02:00
|
|
|
r_masked_face_indices.reserve(r_masked_face_indices.size() + verts_add_num);
|
2022-03-28 12:29:47 +11:00
|
|
|
r_loop_starts.reserve(r_loop_starts.size() + verts_add_num);
|
2023-07-24 22:06:55 +02:00
|
|
|
const blender::OffsetIndices faces = mesh->faces();
|
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
|
|
|
const Span<int> corner_verts = mesh->corner_verts();
|
2021-08-27 11:32:44 +10:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
uint edges_add_num = 0;
|
2023-07-24 22:06:55 +02:00
|
|
|
uint faces_add_num = 0;
|
2022-03-28 12:29:47 +11:00
|
|
|
uint loops_add_num = 0;
|
2023-07-24 22:06:55 +02:00
|
|
|
for (int i : IndexRange(mesh->faces_num)) {
|
|
|
|
|
const blender::IndexRange face_src = faces[i];
|
2021-08-27 11:32:44 +10:00
|
|
|
|
|
|
|
|
int in_count = 0;
|
|
|
|
|
int start = -1;
|
|
|
|
|
int dst_totloop = -1;
|
2023-07-24 22:06:55 +02:00
|
|
|
const Span<int> face_verts_src = corner_verts.slice(face_src);
|
|
|
|
|
for (const int j : face_verts_src.index_range()) {
|
|
|
|
|
const int vert_i = face_verts_src[j];
|
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
|
|
|
if (vertex_mask[vert_i]) {
|
2021-08-27 11:32:44 +10:00
|
|
|
in_count++;
|
|
|
|
|
}
|
|
|
|
|
else if (start == -1) {
|
|
|
|
|
start = j;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-24 22:06:55 +02:00
|
|
|
if (0 < in_count && in_count < face_src.size()) {
|
2021-08-27 11:32:44 +10:00
|
|
|
/* Ring search starting at a vertex which is not included in the mask. */
|
2023-07-24 22:06:55 +02:00
|
|
|
int last_corner_vert = face_verts_src[start];
|
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
|
|
|
bool v_loop_in_mask_last = vertex_mask[last_corner_vert];
|
2023-07-24 22:06:55 +02:00
|
|
|
for (const int j : face_verts_src.index_range()) {
|
|
|
|
|
const int corner_vert = face_verts_src[(start + 1 + j) % face_src.size()];
|
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
|
|
|
const bool v_loop_in_mask = vertex_mask[corner_vert];
|
2021-08-27 11:32:44 +10:00
|
|
|
if (v_loop_in_mask && !v_loop_in_mask_last) {
|
|
|
|
|
dst_totloop = 3;
|
|
|
|
|
}
|
|
|
|
|
else if (!v_loop_in_mask && v_loop_in_mask_last) {
|
|
|
|
|
BLI_assert(dst_totloop > 2);
|
2023-07-24 22:06:55 +02:00
|
|
|
r_masked_face_indices.append(i);
|
2022-03-28 12:29:47 +11:00
|
|
|
r_loop_starts.append(loops_masked_num + loops_add_num);
|
|
|
|
|
loops_add_num += dst_totloop;
|
2023-07-24 22:06:55 +02:00
|
|
|
faces_add_num++;
|
2022-03-28 12:29:47 +11:00
|
|
|
edges_add_num++;
|
2021-08-27 11:32:44 +10:00
|
|
|
dst_totloop = -1;
|
|
|
|
|
}
|
|
|
|
|
else if (v_loop_in_mask && v_loop_in_mask_last) {
|
|
|
|
|
BLI_assert(dst_totloop > 2);
|
|
|
|
|
dst_totloop++;
|
|
|
|
|
}
|
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
|
|
|
last_corner_vert = corner_vert;
|
2021-08-27 11:32:44 +10:00
|
|
|
v_loop_in_mask_last = v_loop_in_mask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
*r_edges_add_num = edges_add_num;
|
2023-07-24 22:06:55 +02:00
|
|
|
*r_faces_add_num = faces_add_num;
|
2022-03-28 12:29:47 +11:00
|
|
|
*r_loops_add_num = loops_add_num;
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
|
|
|
|
|
2022-09-08 11:22:30 +10:00
|
|
|
static void copy_masked_verts_to_new_mesh(const Mesh &src_mesh,
|
|
|
|
|
Mesh &dst_mesh,
|
|
|
|
|
Span<int> vertex_map)
|
2020-02-20 10:05:47 +01:00
|
|
|
{
|
2023-12-20 02:21:48 +01:00
|
|
|
BLI_assert(src_mesh.verts_num == vertex_map.size());
|
2020-02-20 10:05:47 +01:00
|
|
|
for (const int i_src : vertex_map.index_range()) {
|
|
|
|
|
const int i_dst = vertex_map[i_src];
|
|
|
|
|
if (i_dst == -1) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_copy_data(&src_mesh.vert_data, &dst_mesh.vert_data, i_src, i_dst, 1);
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 11:32:44 +10:00
|
|
|
static float get_interp_factor_from_vgroup(
|
2022-05-13 18:31:29 +02:00
|
|
|
const MDeformVert *dvert, int defgrp_index, float threshold, uint v1, uint v2)
|
2021-08-27 11:32:44 +10:00
|
|
|
{
|
|
|
|
|
/* NOTE: this calculation is done twice for every vertex,
|
|
|
|
|
* instead of storing it the first time and then reusing it. */
|
|
|
|
|
float value1 = BKE_defvert_find_weight(&dvert[v1], defgrp_index);
|
|
|
|
|
float value2 = BKE_defvert_find_weight(&dvert[v2], defgrp_index);
|
|
|
|
|
return (threshold - value1) / (value2 - value1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void add_interp_verts_copy_edges_to_new_mesh(const Mesh &src_mesh,
|
|
|
|
|
Mesh &dst_mesh,
|
|
|
|
|
Span<bool> vertex_mask,
|
|
|
|
|
Span<int> vertex_map,
|
2022-05-13 18:31:29 +02:00
|
|
|
const MDeformVert *dvert,
|
2021-08-27 11:32:44 +10:00
|
|
|
int defgrp_index,
|
|
|
|
|
float threshold,
|
2022-03-28 12:29:47 +11:00
|
|
|
uint edges_masked_num,
|
|
|
|
|
uint verts_add_num,
|
2021-08-27 11:32:44 +10:00
|
|
|
MutableSpan<int> r_edge_map)
|
|
|
|
|
{
|
2023-12-20 02:21:48 +01:00
|
|
|
BLI_assert(src_mesh.verts_num == vertex_mask.size());
|
|
|
|
|
BLI_assert(src_mesh.edges_num == r_edge_map.size());
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
const Span<int2> src_edges = src_mesh.edges();
|
|
|
|
|
MutableSpan<int2> dst_edges = dst_mesh.edges_for_write();
|
2021-08-27 11:32:44 +10:00
|
|
|
|
2023-12-20 02:21:48 +01:00
|
|
|
uint vert_index = dst_mesh.verts_num - verts_add_num;
|
2022-03-28 12:29:47 +11:00
|
|
|
uint edge_index = edges_masked_num - verts_add_num;
|
2023-12-20 02:21:48 +01:00
|
|
|
for (int i_src : IndexRange(src_mesh.edges_num)) {
|
2021-08-27 11:32:44 +10:00
|
|
|
if (r_edge_map[i_src] != -1) {
|
|
|
|
|
int i_dst = r_edge_map[i_src];
|
|
|
|
|
if (i_dst == -2) {
|
|
|
|
|
i_dst = edge_index;
|
|
|
|
|
}
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
const int2 &e_src = src_edges[i_src];
|
|
|
|
|
int2 &e_dst = dst_edges[i_dst];
|
2021-08-27 11:32:44 +10:00
|
|
|
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_copy_data(&src_mesh.edge_data, &dst_mesh.edge_data, i_src, i_dst, 1);
|
2021-08-27 11:32:44 +10:00
|
|
|
e_dst = e_src;
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
e_dst[0] = vertex_map[e_src[0]];
|
|
|
|
|
e_dst[1] = vertex_map[e_src[1]];
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
|
|
|
|
if (r_edge_map[i_src] == -2) {
|
|
|
|
|
const int i_dst = edge_index++;
|
|
|
|
|
r_edge_map[i_src] = i_dst;
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
const int2 &e_src = src_edges[i_src];
|
2021-08-27 11:32:44 +10:00
|
|
|
/* Cut destination edge and make v1 the new vertex. */
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
int2 &e_dst = dst_edges[i_dst];
|
|
|
|
|
if (!vertex_mask[e_src[0]]) {
|
|
|
|
|
e_dst[0] = vert_index;
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
|
|
|
|
else {
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
BLI_assert(!vertex_mask[e_src[1]]);
|
|
|
|
|
e_dst[1] = e_dst[0];
|
|
|
|
|
e_dst[0] = vert_index;
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
|
|
|
|
/* Create the new vertex. */
|
|
|
|
|
float fac = get_interp_factor_from_vgroup(
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
dvert, defgrp_index, threshold, e_src[0], e_src[1]);
|
2021-08-27 11:32:44 +10:00
|
|
|
|
|
|
|
|
float weights[2] = {1.0f - fac, fac};
|
2023-07-25 15:23:56 -04:00
|
|
|
CustomData_interp(&src_mesh.vert_data,
|
|
|
|
|
&dst_mesh.vert_data,
|
|
|
|
|
(int *)&e_src[0],
|
|
|
|
|
weights,
|
|
|
|
|
nullptr,
|
|
|
|
|
2,
|
|
|
|
|
vert_index);
|
2021-08-27 11:32:44 +10:00
|
|
|
vert_index++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-20 02:21:48 +01:00
|
|
|
BLI_assert(vert_index == dst_mesh.verts_num);
|
2022-03-28 12:29:47 +11:00
|
|
|
BLI_assert(edge_index == edges_masked_num);
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
|
|
|
|
|
2022-01-13 12:39:12 +01:00
|
|
|
static void copy_masked_edges_to_new_mesh(const Mesh &src_mesh,
|
|
|
|
|
Mesh &dst_mesh,
|
|
|
|
|
Span<int> vertex_map,
|
|
|
|
|
Span<int> edge_map)
|
2020-02-20 10:05:47 +01:00
|
|
|
{
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
const Span<int2> src_edges = src_mesh.edges();
|
|
|
|
|
MutableSpan<int2> dst_edges = dst_mesh.edges_for_write();
|
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
|
|
|
|
2023-12-20 02:21:48 +01:00
|
|
|
BLI_assert(src_mesh.verts_num == vertex_map.size());
|
|
|
|
|
BLI_assert(src_mesh.edges_num == edge_map.size());
|
|
|
|
|
for (const int i_src : IndexRange(src_mesh.edges_num)) {
|
2020-02-20 10:05:47 +01:00
|
|
|
const int i_dst = edge_map[i_src];
|
2021-10-20 10:45:59 +11:00
|
|
|
if (ELEM(i_dst, -1, -2)) {
|
2020-02-20 10:05:47 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_copy_data(&src_mesh.edge_data, &dst_mesh.edge_data, i_src, i_dst, 1);
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
dst_edges[i_dst][0] = vertex_map[src_edges[i_src][0]];
|
|
|
|
|
dst_edges[i_dst][1] = vertex_map[src_edges[i_src][1]];
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
static void copy_masked_faces_to_new_mesh(const Mesh &src_mesh,
|
2021-08-27 11:32:44 +10:00
|
|
|
Mesh &dst_mesh,
|
|
|
|
|
Span<int> vertex_map,
|
|
|
|
|
Span<int> edge_map,
|
2023-07-24 22:06:55 +02:00
|
|
|
Span<int> masked_face_indices,
|
2021-08-27 11:32:44 +10:00
|
|
|
Span<int> new_loop_starts,
|
2023-07-24 22:06:55 +02:00
|
|
|
int faces_masked_num)
|
2021-08-27 11:32:44 +10:00
|
|
|
{
|
2023-07-24 22:06:55 +02:00
|
|
|
const blender::OffsetIndices src_faces = src_mesh.faces();
|
|
|
|
|
MutableSpan<int> dst_face_offsets = dst_mesh.face_offsets_for_write();
|
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
|
|
|
const Span<int> src_corner_verts = src_mesh.corner_verts();
|
|
|
|
|
const Span<int> src_corner_edges = src_mesh.corner_edges();
|
|
|
|
|
MutableSpan<int> dst_corner_verts = dst_mesh.corner_verts_for_write();
|
|
|
|
|
MutableSpan<int> dst_corner_edges = dst_mesh.corner_edges_for_write();
|
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
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
for (const int i_dst : IndexRange(faces_masked_num)) {
|
|
|
|
|
const int i_src = masked_face_indices[i_dst];
|
|
|
|
|
const blender::IndexRange src_face = src_faces[i_src];
|
2021-08-27 11:32:44 +10:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
dst_face_offsets[i_dst] = new_loop_starts[i_dst];
|
2020-02-20 10:05:47 +01:00
|
|
|
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_copy_data(&src_mesh.face_data, &dst_mesh.face_data, i_src, i_dst, 1);
|
2023-12-19 20:38:59 -05:00
|
|
|
CustomData_copy_data(&src_mesh.corner_data,
|
|
|
|
|
&dst_mesh.corner_data,
|
2023-07-24 22:06:55 +02:00
|
|
|
src_face.start(),
|
|
|
|
|
dst_face_offsets[i_dst],
|
|
|
|
|
src_face.size());
|
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
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
for (int i : IndexRange(src_face.size())) {
|
|
|
|
|
dst_corner_verts[new_loop_starts[i_dst] + i] = vertex_map[src_corner_verts[src_face[i]]];
|
|
|
|
|
dst_corner_edges[new_loop_starts[i_dst] + i] = edge_map[src_corner_edges[src_face[i]]];
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
static void add_interpolated_faces_to_new_mesh(const Mesh &src_mesh,
|
2021-08-27 11:32:44 +10:00
|
|
|
Mesh &dst_mesh,
|
|
|
|
|
Span<bool> vertex_mask,
|
|
|
|
|
Span<int> vertex_map,
|
|
|
|
|
Span<int> edge_map,
|
2022-05-13 18:31:29 +02:00
|
|
|
const MDeformVert *dvert,
|
2021-08-27 11:32:44 +10:00
|
|
|
int defgrp_index,
|
|
|
|
|
float threshold,
|
2023-07-24 22:06:55 +02:00
|
|
|
Span<int> masked_face_indices,
|
2021-08-27 11:32:44 +10:00
|
|
|
Span<int> new_loop_starts,
|
2023-07-24 22:06:55 +02:00
|
|
|
int faces_masked_num,
|
2022-03-28 12:29:47 +11:00
|
|
|
int edges_add_num)
|
2021-08-27 11:32:44 +10:00
|
|
|
{
|
2023-07-24 22:06:55 +02:00
|
|
|
const blender::OffsetIndices src_faces = src_mesh.faces();
|
|
|
|
|
MutableSpan<int> dst_face_offsets = dst_mesh.face_offsets_for_write();
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
MutableSpan<int2> dst_edges = dst_mesh.edges_for_write();
|
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
|
|
|
const Span<int> src_corner_verts = src_mesh.corner_verts();
|
|
|
|
|
const Span<int> src_corner_edges = src_mesh.corner_edges();
|
|
|
|
|
MutableSpan<int> dst_corner_verts = dst_mesh.corner_verts_for_write();
|
|
|
|
|
MutableSpan<int> dst_corner_edges = dst_mesh.corner_edges_for_write();
|
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
|
|
|
|
2023-12-20 02:21:48 +01:00
|
|
|
int edge_index = dst_mesh.edges_num - edges_add_num;
|
2023-07-24 22:06:55 +02:00
|
|
|
int sub_face_index = 0;
|
2021-08-27 11:32:44 +10:00
|
|
|
int last_i_src = -1;
|
|
|
|
|
for (const int i_dst :
|
2024-01-02 18:12:54 +01:00
|
|
|
IndexRange(faces_masked_num, masked_face_indices.size() - faces_masked_num))
|
|
|
|
|
{
|
2023-07-24 22:06:55 +02:00
|
|
|
const int i_src = masked_face_indices[i_dst];
|
2021-08-27 11:32:44 +10:00
|
|
|
if (i_src == last_i_src) {
|
2023-07-24 22:06:55 +02:00
|
|
|
sub_face_index++;
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2023-07-24 22:06:55 +02:00
|
|
|
sub_face_index = 0;
|
2021-08-27 11:32:44 +10:00
|
|
|
last_i_src = i_src;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
const blender::IndexRange src_face = src_faces[i_src];
|
|
|
|
|
const int i_ml_src = src_face.start();
|
2021-08-27 11:32:44 +10:00
|
|
|
int i_ml_dst = new_loop_starts[i_dst];
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_copy_data(&src_mesh.face_data, &dst_mesh.face_data, i_src, i_dst, 1);
|
2021-08-27 11:32:44 +10:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
dst_face_offsets[i_dst] = i_ml_dst;
|
2021-08-27 11:32:44 +10:00
|
|
|
|
|
|
|
|
/* Ring search starting at a vertex which is not included in the mask. */
|
2023-07-24 22:06:55 +02:00
|
|
|
int start = -sub_face_index - 1;
|
2021-08-27 11:32:44 +10:00
|
|
|
bool skip = false;
|
2023-07-24 22:06:55 +02:00
|
|
|
const Span<int> face_verts_src = src_corner_verts.slice(src_face);
|
|
|
|
|
const Span<int> face_edges_src = src_corner_edges.slice(src_face);
|
|
|
|
|
for (const int j : face_verts_src.index_range()) {
|
|
|
|
|
if (!vertex_mask[face_verts_src[j]]) {
|
2021-08-27 11:32:44 +10:00
|
|
|
if (start == -1) {
|
|
|
|
|
start = j;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-08-27 17:29:05 +10:00
|
|
|
if (!skip) {
|
2021-08-27 11:32:44 +10:00
|
|
|
skip = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (skip) {
|
|
|
|
|
skip = false;
|
|
|
|
|
start++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_assert(start >= 0);
|
2023-12-20 02:21:48 +01:00
|
|
|
BLI_assert(edge_index < dst_mesh.edges_num);
|
2021-08-27 11:32:44 +10:00
|
|
|
|
|
|
|
|
int last_index = start;
|
2023-07-24 22:06:55 +02:00
|
|
|
bool v_loop_in_mask_last = vertex_mask[face_verts_src[last_index]];
|
|
|
|
|
for (const int j : face_verts_src.index_range()) {
|
|
|
|
|
const int index = (start + 1 + j) % src_face.size();
|
|
|
|
|
const bool v_loop_in_mask = vertex_mask[face_verts_src[index]];
|
2021-08-27 11:32:44 +10:00
|
|
|
if (v_loop_in_mask && !v_loop_in_mask_last) {
|
|
|
|
|
/* Start new cut. */
|
2023-06-16 13:38:00 -04:00
|
|
|
float fac = get_interp_factor_from_vgroup(
|
2023-07-24 22:06:55 +02:00
|
|
|
dvert, defgrp_index, threshold, face_verts_src[last_index], face_verts_src[index]);
|
2021-08-27 11:32:44 +10:00
|
|
|
float weights[2] = {1.0f - fac, fac};
|
|
|
|
|
int indices[2] = {i_ml_src + last_index, i_ml_src + index};
|
2021-08-27 17:29:05 +10:00
|
|
|
CustomData_interp(
|
2023-12-19 20:38:59 -05:00
|
|
|
&src_mesh.corner_data, &dst_mesh.corner_data, indices, weights, nullptr, 2, i_ml_dst);
|
2023-07-24 22:06:55 +02:00
|
|
|
dst_corner_edges[i_ml_dst] = edge_map[face_edges_src[last_index]];
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
dst_corner_verts[i_ml_dst] = dst_edges[dst_corner_edges[i_ml_dst]][0];
|
2021-08-27 11:32:44 +10:00
|
|
|
i_ml_dst++;
|
|
|
|
|
|
2023-07-25 15:23:56 -04:00
|
|
|
CustomData_copy_data(
|
2023-12-19 20:38:59 -05:00
|
|
|
&src_mesh.corner_data, &dst_mesh.corner_data, i_ml_src + index, i_ml_dst, 1);
|
2023-07-24 22:06:55 +02:00
|
|
|
dst_corner_verts[i_ml_dst] = vertex_map[face_verts_src[index]];
|
|
|
|
|
dst_corner_edges[i_ml_dst] = edge_map[face_edges_src[index]];
|
2021-08-27 11:32:44 +10:00
|
|
|
i_ml_dst++;
|
|
|
|
|
}
|
|
|
|
|
else if (!v_loop_in_mask && v_loop_in_mask_last) {
|
2023-07-24 22:06:55 +02:00
|
|
|
BLI_assert(i_ml_dst != dst_face_offsets[i_dst]);
|
2021-08-27 11:32:44 +10:00
|
|
|
/* End active cut. */
|
2023-06-16 13:38:00 -04:00
|
|
|
float fac = get_interp_factor_from_vgroup(
|
2023-07-24 22:06:55 +02:00
|
|
|
dvert, defgrp_index, threshold, face_verts_src[last_index], face_verts_src[index]);
|
2021-08-27 11:32:44 +10:00
|
|
|
float weights[2] = {1.0f - fac, fac};
|
|
|
|
|
int indices[2] = {i_ml_src + last_index, i_ml_src + index};
|
2021-08-27 17:29:05 +10:00
|
|
|
CustomData_interp(
|
2023-12-19 20:38:59 -05:00
|
|
|
&src_mesh.corner_data, &dst_mesh.corner_data, indices, weights, nullptr, 2, i_ml_dst);
|
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
|
|
|
dst_corner_edges[i_ml_dst] = edge_index;
|
2023-07-24 22:06:55 +02:00
|
|
|
dst_corner_verts[i_ml_dst] = dst_edges[edge_map[face_edges_src[last_index]]][0];
|
2021-08-27 11:32:44 +10:00
|
|
|
|
|
|
|
|
/* Create closing edge. */
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
int2 &cut_edge = dst_edges[edge_index];
|
2023-07-24 22:06:55 +02:00
|
|
|
cut_edge[0] = dst_corner_verts[dst_face_offsets[i_dst]];
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
cut_edge[1] = dst_corner_verts[i_ml_dst];
|
|
|
|
|
BLI_assert(cut_edge[0] != cut_edge[1]);
|
2021-08-27 11:32:44 +10:00
|
|
|
edge_index++;
|
2023-06-16 13:38:00 -04:00
|
|
|
i_ml_dst++;
|
2021-08-27 11:32:44 +10:00
|
|
|
|
|
|
|
|
/* Only handle one of the cuts per iteration. */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (v_loop_in_mask && v_loop_in_mask_last) {
|
2023-07-24 22:06:55 +02:00
|
|
|
BLI_assert(i_ml_dst != dst_face_offsets[i_dst]);
|
|
|
|
|
/* Extend active face. */
|
2023-07-25 15:23:56 -04:00
|
|
|
CustomData_copy_data(
|
2023-12-19 20:38:59 -05:00
|
|
|
&src_mesh.corner_data, &dst_mesh.corner_data, i_ml_src + index, i_ml_dst, 1);
|
2023-07-24 22:06:55 +02:00
|
|
|
dst_corner_verts[i_ml_dst] = vertex_map[face_verts_src[index]];
|
|
|
|
|
dst_corner_edges[i_ml_dst] = edge_map[face_edges_src[index]];
|
2021-08-27 11:32:44 +10:00
|
|
|
i_ml_dst++;
|
|
|
|
|
}
|
|
|
|
|
last_index = index;
|
|
|
|
|
v_loop_in_mask_last = v_loop_in_mask;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-20 02:21:48 +01:00
|
|
|
BLI_assert(edge_index == dst_mesh.edges_num);
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
|
|
|
|
|
2020-02-20 10:05:47 +01:00
|
|
|
/* Components of the algorithm:
|
|
|
|
|
* 1. Figure out which vertices should be present in the output mesh.
|
2023-07-24 22:06:55 +02:00
|
|
|
* 2. Find edges and faces only using those vertices.
|
|
|
|
|
* 3. Create a new mesh that only uses the found vertices, edges and faces.
|
2020-02-20 10:05:47 +01:00
|
|
|
*/
|
2023-07-27 12:04:18 +10:00
|
|
|
static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext * /*ctx*/, Mesh *mesh)
|
2020-02-20 10:05:47 +01:00
|
|
|
{
|
2020-08-07 18:24:59 +02:00
|
|
|
MaskModifierData *mmd = reinterpret_cast<MaskModifierData *>(md);
|
2020-02-20 10:05:47 +01:00
|
|
|
const bool invert_mask = mmd->flag & MOD_MASK_INV;
|
2021-08-27 11:32:44 +10:00
|
|
|
const bool use_interpolation = mmd->mode == MOD_MASK_MODE_VGROUP &&
|
|
|
|
|
(mmd->flag & MOD_MASK_SMOOTH);
|
2020-02-20 10:05:47 +01:00
|
|
|
|
|
|
|
|
/* Return empty or input mesh when there are no vertex groups. */
|
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 Span<MDeformVert> dverts = mesh->deform_verts();
|
|
|
|
|
if (dverts.is_empty()) {
|
2023-02-27 11:09:26 -05:00
|
|
|
return invert_mask ? mesh : BKE_mesh_new_nomain_from_template(mesh, 0, 0, 0, 0);
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Quick test to see if we can return early. */
|
2023-12-20 02:21:48 +01:00
|
|
|
if (!ELEM(mmd->mode, MOD_MASK_MODE_ARM, MOD_MASK_MODE_VGROUP) || (mesh->verts_num == 0) ||
|
2021-07-13 12:10:34 -04:00
|
|
|
BLI_listbase_is_empty(&mesh->vertex_group_names))
|
|
|
|
|
{
|
2020-02-20 10:05:47 +01:00
|
|
|
return mesh;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 11:32:44 +10:00
|
|
|
int defgrp_index = -1;
|
|
|
|
|
|
2020-02-20 10:05:47 +01:00
|
|
|
Array<bool> vertex_mask;
|
|
|
|
|
if (mmd->mode == MOD_MASK_MODE_ARM) {
|
|
|
|
|
Object *armature_ob = mmd->ob_arm;
|
|
|
|
|
|
|
|
|
|
/* Return input mesh if there is no armature with bones. */
|
2022-01-03 13:52:39 -06:00
|
|
|
if (ELEM(nullptr, armature_ob, armature_ob->pose)) {
|
2020-02-20 10:05:47 +01:00
|
|
|
return mesh;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-20 02:21:48 +01:00
|
|
|
vertex_mask = Array<bool>(mesh->verts_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
|
|
|
compute_vertex_mask__armature_mode(
|
|
|
|
|
dverts.data(), mesh, armature_ob, mmd->threshold, vertex_mask);
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2021-08-27 11:32:44 +10:00
|
|
|
BLI_assert(mmd->mode == MOD_MASK_MODE_VGROUP);
|
|
|
|
|
defgrp_index = BKE_id_defgroup_name_index(&mesh->id, mmd->vgroup);
|
2020-02-20 10:05:47 +01:00
|
|
|
|
|
|
|
|
/* Return input mesh if the vertex group does not exist. */
|
|
|
|
|
if (defgrp_index == -1) {
|
|
|
|
|
return mesh;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-20 02:21:48 +01:00
|
|
|
vertex_mask = Array<bool>(mesh->verts_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
|
|
|
compute_vertex_mask__vertex_group_mode(
|
|
|
|
|
dverts.data(), defgrp_index, mmd->threshold, vertex_mask);
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (invert_mask) {
|
2023-01-03 22:59:25 -05:00
|
|
|
blender::array_utils::invert_booleans(vertex_mask);
|
2020-02-20 10:05:47 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-20 02:21:48 +01:00
|
|
|
Array<int> vertex_map(mesh->verts_num);
|
2022-03-28 12:29:47 +11:00
|
|
|
uint verts_masked_num;
|
2022-09-08 11:22:30 +10:00
|
|
|
compute_masked_verts(vertex_mask, vertex_map, &verts_masked_num);
|
2020-02-20 10:05:47 +01:00
|
|
|
|
2023-12-20 02:21:48 +01:00
|
|
|
Array<int> edge_map(mesh->edges_num);
|
2022-03-28 12:29:47 +11:00
|
|
|
uint edges_masked_num;
|
|
|
|
|
uint verts_add_num;
|
2021-08-27 11:32:44 +10:00
|
|
|
if (use_interpolation) {
|
2022-03-28 12:29:47 +11:00
|
|
|
computed_masked_edges_smooth(mesh, vertex_mask, edge_map, &edges_masked_num, &verts_add_num);
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2022-03-28 12:29:47 +11:00
|
|
|
computed_masked_edges(mesh, vertex_mask, edge_map, &edges_masked_num);
|
|
|
|
|
verts_add_num = 0;
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
2020-02-20 10:05:47 +01:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
Vector<int> masked_face_indices;
|
2020-02-20 10:05:47 +01:00
|
|
|
Vector<int> new_loop_starts;
|
2023-07-24 22:06:55 +02:00
|
|
|
uint faces_masked_num;
|
2022-03-28 12:29:47 +11:00
|
|
|
uint loops_masked_num;
|
2023-07-24 22:06:55 +02:00
|
|
|
computed_masked_faces(mesh,
|
2022-09-08 11:22:30 +10:00
|
|
|
vertex_mask,
|
2023-07-24 22:06:55 +02:00
|
|
|
masked_face_indices,
|
2022-09-08 11:22:30 +10:00
|
|
|
new_loop_starts,
|
2023-07-24 22:06:55 +02:00
|
|
|
&faces_masked_num,
|
2022-09-08 11:22:30 +10:00
|
|
|
&loops_masked_num);
|
2020-02-20 10:05:47 +01:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
uint edges_add_num = 0;
|
2023-07-24 22:06:55 +02:00
|
|
|
uint faces_add_num = 0;
|
2022-03-28 12:29:47 +11:00
|
|
|
uint loops_add_num = 0;
|
2021-08-27 11:32:44 +10:00
|
|
|
if (use_interpolation) {
|
2023-07-24 22:06:55 +02:00
|
|
|
compute_interpolated_faces(mesh,
|
2022-09-08 11:22:30 +10:00
|
|
|
vertex_mask,
|
|
|
|
|
verts_add_num,
|
|
|
|
|
loops_masked_num,
|
2023-07-24 22:06:55 +02:00
|
|
|
masked_face_indices,
|
2022-09-08 11:22:30 +10:00
|
|
|
new_loop_starts,
|
|
|
|
|
&edges_add_num,
|
2023-07-24 22:06:55 +02:00
|
|
|
&faces_add_num,
|
2022-09-08 11:22:30 +10:00
|
|
|
&loops_add_num);
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Mesh *result = BKE_mesh_new_nomain_from_template(mesh,
|
2022-03-28 12:29:47 +11:00
|
|
|
verts_masked_num + verts_add_num,
|
|
|
|
|
edges_masked_num + edges_add_num,
|
2023-07-24 22:06:55 +02:00
|
|
|
faces_masked_num + faces_add_num,
|
2023-04-19 15:28:53 -04:00
|
|
|
loops_masked_num + loops_add_num);
|
2020-02-20 10:05:47 +01:00
|
|
|
|
2022-09-08 11:22:30 +10:00
|
|
|
copy_masked_verts_to_new_mesh(*mesh, *result, vertex_map);
|
2021-08-27 11:32:44 +10:00
|
|
|
if (use_interpolation) {
|
|
|
|
|
add_interp_verts_copy_edges_to_new_mesh(*mesh,
|
|
|
|
|
*result,
|
|
|
|
|
vertex_mask,
|
|
|
|
|
vertex_map,
|
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
|
|
|
dverts.data(),
|
2021-08-27 11:32:44 +10:00
|
|
|
defgrp_index,
|
|
|
|
|
mmd->threshold,
|
2022-03-28 12:29:47 +11:00
|
|
|
edges_masked_num,
|
|
|
|
|
verts_add_num,
|
2021-08-27 11:32:44 +10:00
|
|
|
edge_map);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_masked_edges_to_new_mesh(*mesh, *result, vertex_map, edge_map);
|
|
|
|
|
}
|
2023-07-24 22:06:55 +02:00
|
|
|
copy_masked_faces_to_new_mesh(*mesh,
|
2021-08-27 11:32:44 +10:00
|
|
|
*result,
|
|
|
|
|
vertex_map,
|
|
|
|
|
edge_map,
|
2023-07-24 22:06:55 +02:00
|
|
|
masked_face_indices,
|
2021-08-27 11:32:44 +10:00
|
|
|
new_loop_starts,
|
2023-07-24 22:06:55 +02:00
|
|
|
faces_masked_num);
|
2021-08-27 11:32:44 +10:00
|
|
|
if (use_interpolation) {
|
2023-07-24 22:06:55 +02:00
|
|
|
add_interpolated_faces_to_new_mesh(*mesh,
|
2021-08-27 11:32:44 +10:00
|
|
|
*result,
|
|
|
|
|
vertex_mask,
|
|
|
|
|
vertex_map,
|
|
|
|
|
edge_map,
|
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
|
|
|
dverts.data(),
|
2021-08-27 11:32:44 +10:00
|
|
|
defgrp_index,
|
|
|
|
|
mmd->threshold,
|
2023-07-24 22:06:55 +02:00
|
|
|
masked_face_indices,
|
2021-08-27 11:32:44 +10:00
|
|
|
new_loop_starts,
|
2023-07-24 22:06:55 +02:00
|
|
|
faces_masked_num,
|
2022-03-28 12:29:47 +11:00
|
|
|
edges_add_num);
|
2021-08-27 11:32:44 +10:00
|
|
|
}
|
2020-02-20 10:05:47 +01:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static bool is_disabled(const Scene * /*scene*/, ModifierData *md, bool /*use_render_params*/)
|
2020-02-20 10:05:47 +01:00
|
|
|
{
|
2020-08-07 18:24:59 +02:00
|
|
|
MaskModifierData *mmd = reinterpret_cast<MaskModifierData *>(md);
|
2020-02-20 10:05:47 +01:00
|
|
|
|
|
|
|
|
/* The object type check is only needed here in case we have a placeholder
|
|
|
|
|
* object assigned (because the library containing the armature is missing).
|
|
|
|
|
*
|
|
|
|
|
* In other cases it should be impossible to have a type mismatch.
|
|
|
|
|
*/
|
|
|
|
|
return mmd->ob_arm && mmd->ob_arm->type != OB_ARMATURE;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static void panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *sub, *row;
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-11-06 17:49:09 +01:00
|
|
|
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
|
|
|
|
if (mode == MOD_MASK_MODE_ARM) {
|
|
|
|
|
row = uiLayoutRow(layout, true);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(row, ptr, "armature", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
sub = uiLayoutRow(row, true);
|
|
|
|
|
uiLayoutSetPropDecorate(sub, false);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(sub, ptr, "invert_vertex_group", UI_ITEM_NONE, "", ICON_ARROW_LEFTRIGHT);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
else if (mode == MOD_MASK_MODE_VGROUP) {
|
2020-09-02 14:13:26 -05:00
|
|
|
modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", nullptr);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "use_smooth", 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, "threshold", 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
|
|
|
}
|
|
|
|
|
|
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_Mask, panel_draw);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-20 10:05:47 +01:00
|
|
|
ModifierTypeInfo modifierType_Mask = {
|
2023-07-26 17:08:14 +02:00
|
|
|
/*idname*/ "Mask",
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("Mask"),
|
2023-07-27 12:04:18 +10:00
|
|
|
/*struct_name*/ "MaskModifierData",
|
|
|
|
|
/*struct_size*/ sizeof(MaskModifierData),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*srna*/ &RNA_MaskModifier,
|
2023-11-14 10:03:56 +01:00
|
|
|
/*type*/ ModifierTypeType::Nonconstructive,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*flags*/
|
2020-02-20 10:05:47 +01:00
|
|
|
(ModifierTypeFlag)(eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsMapping |
|
|
|
|
|
eModifierTypeFlag_SupportsEditmode),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*icon*/ ICON_MOD_MASK,
|
|
|
|
|
|
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*/ required_data_mask,
|
|
|
|
|
/*free_data*/ nullptr,
|
|
|
|
|
/*is_disabled*/ is_disabled,
|
|
|
|
|
/*update_depsgraph*/ update_depsgraph,
|
|
|
|
|
/*depends_on_time*/ nullptr,
|
|
|
|
|
/*depends_on_normals*/ nullptr,
|
|
|
|
|
/*foreach_ID_link*/ foreach_ID_link,
|
|
|
|
|
/*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,
|
2020-02-20 10:05:47 +01:00
|
|
|
};
|