2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup modifiers
|
2015-02-05 14:49:44 +01:00
|
|
|
*/
|
|
|
|
|
|
2022-10-05 13:44:02 -05:00
|
|
|
#include <cstring>
|
2015-02-05 14:49:44 +01:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_bitmap.h"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_matrix.h"
|
|
|
|
|
#include "BLI_math_vector.h"
|
2019-02-25 11:39:14 +01:00
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
#include "DNA_defaults.h"
|
2015-02-05 14:49:44 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "DNA_screen_types.h"
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2023-01-10 16:12:14 -05:00
|
|
|
#include "BKE_attribute.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_deform.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
|
|
|
|
#include "BKE_lib_query.h"
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2023-09-25 17:48:21 -04:00
|
|
|
#include "BKE_screen.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface.hh"
|
|
|
|
|
#include "UI_resources.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph_query.hh"
|
2018-12-07 15:45:53 +01:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include "MOD_ui_common.hh"
|
|
|
|
|
#include "MOD_util.hh"
|
2015-02-05 14:49:44 +01:00
|
|
|
|
|
|
|
|
static void generate_vert_coordinates(Mesh *mesh,
|
2018-05-07 14:36:00 +02:00
|
|
|
Object *ob,
|
|
|
|
|
Object *ob_center,
|
|
|
|
|
const float offset[3],
|
2022-03-28 12:29:47 +11:00
|
|
|
const int verts_num,
|
2015-02-05 14:49:44 +01:00
|
|
|
float (*r_cos)[3],
|
|
|
|
|
float r_size[3])
|
|
|
|
|
{
|
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 namespace blender;
|
2015-02-05 14:49:44 +01:00
|
|
|
float min_co[3], max_co[3];
|
|
|
|
|
float diff[3];
|
|
|
|
|
bool do_diff = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
INIT_MINMAX(min_co, max_co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
const Span<float3> positions = mesh->vert_positions();
|
|
|
|
|
for (int i = 0; i < mesh->totvert; i++) {
|
|
|
|
|
copy_v3_v3(r_cos[i], positions[i]);
|
2022-10-02 11:16:14 -05:00
|
|
|
if (r_size != nullptr && ob_center == nullptr) {
|
2018-05-07 14:36:00 +02:00
|
|
|
minmax_v3v3_v3(min_co, max_co, r_cos[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-01 07:40:07 +10:00
|
|
|
/* Get size (i.e. deformation of the spheroid generating normals),
|
|
|
|
|
* either from target object, or own geometry. */
|
2022-10-02 11:16:14 -05:00
|
|
|
if (r_size != nullptr) {
|
|
|
|
|
if (ob_center != nullptr) {
|
2019-02-20 08:25:00 +11:00
|
|
|
/* Using 'scale' as 'size' here. The input object is typically an empty
|
|
|
|
|
* who's scale is used to define an ellipsoid instead of a simple sphere. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-01 07:40:07 +10:00
|
|
|
/* Not we are not interested in signs here - they are even troublesome actually,
|
|
|
|
|
* due to security clamping! */
|
2019-02-18 15:43:06 +11:00
|
|
|
abs_v3_v3(r_size, ob_center->scale);
|
2018-05-07 14:36:00 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Set size. */
|
|
|
|
|
sub_v3_v3v3(r_size, max_co, min_co);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-07 14:36:00 +02:00
|
|
|
/* Error checks - we do not want one or more of our sizes to be null! */
|
|
|
|
|
if (is_zero_v3(r_size)) {
|
|
|
|
|
r_size[0] = r_size[1] = r_size[2] = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
CLAMP_MIN(r_size[0], FLT_EPSILON);
|
|
|
|
|
CLAMP_MIN(r_size[1], FLT_EPSILON);
|
|
|
|
|
CLAMP_MIN(r_size[2], FLT_EPSILON);
|
|
|
|
|
}
|
2015-02-05 14:49:44 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-10-02 11:16:14 -05:00
|
|
|
if (ob_center != nullptr) {
|
2015-05-12 10:56:28 +02:00
|
|
|
float inv_obmat[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
/* Translate our coordinates so that center of ob_center is at (0, 0, 0). */
|
2015-03-17 18:14:38 +01:00
|
|
|
/* Get ob_center (world) coordinates in ob local coordinates.
|
2023-02-12 14:37:16 +11:00
|
|
|
* No need to take into account ob_center's space here, see #44027. */
|
2022-10-24 14:16:37 +02:00
|
|
|
invert_m4_m4(inv_obmat, ob->object_to_world);
|
|
|
|
|
mul_v3_m4v3(diff, inv_obmat, ob_center->object_to_world[3]);
|
2015-03-17 18:14:38 +01:00
|
|
|
negate_v3(diff);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
do_diff = true;
|
|
|
|
|
}
|
2022-10-02 11:16:14 -05:00
|
|
|
else if (offset != nullptr && !is_zero_v3(offset)) {
|
2015-02-05 14:49:44 +01:00
|
|
|
negate_v3_v3(diff, offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
do_diff = true;
|
|
|
|
|
}
|
|
|
|
|
/* Else, no need to change coordinates! */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
if (do_diff) {
|
2022-03-28 12:29:47 +11:00
|
|
|
int i = verts_num;
|
2015-02-05 14:49:44 +01:00
|
|
|
while (i--) {
|
|
|
|
|
add_v3_v3(r_cos[i], diff);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Note this modifies nos_new in-place. */
|
|
|
|
|
static void mix_normals(const float mix_factor,
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
const MDeformVert *dvert,
|
2015-02-05 14:49:44 +01:00
|
|
|
const int defgrp_index,
|
|
|
|
|
const bool use_invert_vgroup,
|
2016-06-06 21:41:17 +02:00
|
|
|
const float mix_limit,
|
|
|
|
|
const short mix_mode,
|
2022-03-28 12:29:47 +11:00
|
|
|
const int verts_num,
|
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 blender::Span<int> corner_verts,
|
2023-03-12 22:29:15 +01:00
|
|
|
blender::float3 *nos_old,
|
|
|
|
|
blender::float3 *nos_new)
|
2015-02-05 14:49:44 +01:00
|
|
|
{
|
|
|
|
|
/* Mix with org normals... */
|
2022-10-02 11:16:14 -05:00
|
|
|
float *facs = nullptr, *wfac;
|
2023-03-12 22:29:15 +01:00
|
|
|
blender::float3 *no_new, *no_old;
|
2015-02-05 14:49:44 +01:00
|
|
|
int i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
if (dvert) {
|
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
|
|
|
facs = static_cast<float *>(
|
|
|
|
|
MEM_malloc_arrayN(size_t(corner_verts.size()), sizeof(*facs), __func__));
|
|
|
|
|
BKE_defvert_extract_vgroup_to_loopweights(dvert,
|
|
|
|
|
defgrp_index,
|
|
|
|
|
verts_num,
|
|
|
|
|
corner_verts.data(),
|
|
|
|
|
corner_verts.size(),
|
|
|
|
|
use_invert_vgroup,
|
|
|
|
|
facs);
|
2015-02-05 14:49:44 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
for (i = corner_verts.size(), no_new = nos_new, no_old = nos_old, wfac = facs; i--;
|
2015-02-05 14:49:44 +01:00
|
|
|
no_new++, no_old++, wfac++)
|
|
|
|
|
{
|
|
|
|
|
const float fac = facs ? *wfac * mix_factor : mix_factor;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
switch (mix_mode) {
|
|
|
|
|
case MOD_NORMALEDIT_MIX_ADD:
|
|
|
|
|
add_v3_v3(*no_new, *no_old);
|
|
|
|
|
normalize_v3(*no_new);
|
|
|
|
|
break;
|
|
|
|
|
case MOD_NORMALEDIT_MIX_SUB:
|
|
|
|
|
sub_v3_v3(*no_new, *no_old);
|
|
|
|
|
normalize_v3(*no_new);
|
|
|
|
|
break;
|
|
|
|
|
case MOD_NORMALEDIT_MIX_MUL:
|
|
|
|
|
mul_v3_v3(*no_new, *no_old);
|
|
|
|
|
normalize_v3(*no_new);
|
|
|
|
|
break;
|
|
|
|
|
case MOD_NORMALEDIT_MIX_COPY:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-22 04:05:38 +10:00
|
|
|
interp_v3_v3v3_slerp_safe(
|
|
|
|
|
*no_new,
|
|
|
|
|
*no_old,
|
|
|
|
|
*no_new,
|
2022-10-03 10:24:06 +11:00
|
|
|
(mix_limit < float(M_PI)) ? min_ff(fac, mix_limit / angle_v3v3(*no_new, *no_old)) : fac);
|
2015-02-05 14:49:44 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
MEM_SAFE_FREE(facs);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
/* Check face normals and new loop normals are compatible, otherwise flip faces
|
|
|
|
|
* (and invert matching face normals). */
|
2023-08-02 14:15:27 +02:00
|
|
|
static void faces_check_flip(Mesh &mesh,
|
|
|
|
|
blender::MutableSpan<blender::float3> nos,
|
2023-07-24 22:06:55 +02:00
|
|
|
const blender::Span<blender::float3> face_normals)
|
2016-02-28 15:48:08 +01:00
|
|
|
{
|
2023-08-02 14:15:27 +02:00
|
|
|
using namespace blender;
|
|
|
|
|
const OffsetIndices faces = mesh.faces();
|
|
|
|
|
IndexMaskMemory memory;
|
|
|
|
|
const IndexMask faces_to_flip = IndexMask::from_predicate(
|
|
|
|
|
faces.index_range(), GrainSize(1024), memory, [&](const int i) {
|
|
|
|
|
const blender::IndexRange face = faces[i];
|
|
|
|
|
float norsum[3] = {0.0f};
|
|
|
|
|
|
|
|
|
|
for (const int64_t j : face) {
|
|
|
|
|
add_v3_v3(norsum, nos[j]);
|
|
|
|
|
}
|
|
|
|
|
if (!normalize_v3(norsum)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If average of new loop normals is opposed to face normal, flip face. */
|
|
|
|
|
if (dot_v3v3(face_normals[i], norsum) < 0.0f) {
|
|
|
|
|
nos.slice(faces[i].drop_front(1)).reverse();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
bke::mesh_flip_faces(mesh, faces_to_flip);
|
2016-02-28 15:48:08 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
static void normalEditModifier_do_radial(NormalEditModifierData *enmd,
|
2022-10-03 17:37:25 -05:00
|
|
|
const ModifierEvalContext * /*ctx*/,
|
2018-12-07 15:45:53 +01:00
|
|
|
Object *ob,
|
|
|
|
|
Mesh *mesh,
|
2023-04-28 13:34:15 -04:00
|
|
|
blender::MutableSpan<blender::short2> clnors,
|
2023-03-12 22:29:15 +01:00
|
|
|
blender::MutableSpan<blender::float3> loop_normals,
|
2016-06-06 21:41:17 +02:00
|
|
|
const short mix_mode,
|
|
|
|
|
const float mix_factor,
|
|
|
|
|
const float mix_limit,
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
const MDeformVert *dvert,
|
2015-02-05 14:49:44 +01:00
|
|
|
const int defgrp_index,
|
|
|
|
|
const bool use_invert_vgroup,
|
2023-03-12 22:29:15 +01:00
|
|
|
blender::Span<blender::float3> vert_positions,
|
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 blender::Span<blender::int2> edges,
|
2023-03-12 22:29:15 +01:00
|
|
|
blender::MutableSpan<bool> sharp_edges,
|
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
|
|
|
blender::MutableSpan<int> corner_verts,
|
|
|
|
|
blender::MutableSpan<int> corner_edges,
|
2023-07-24 22:06:55 +02:00
|
|
|
const blender::OffsetIndices<int> faces)
|
2015-02-05 14:49:44 +01:00
|
|
|
{
|
2019-03-26 11:25:07 +01:00
|
|
|
Object *ob_target = enmd->target;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
const bool do_facenors_fix = (enmd->flag & MOD_NORMALEDIT_NO_POLYNORS_FIX) == 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-10-02 11:16:14 -05:00
|
|
|
float(*cos)[3] = static_cast<float(*)[3]>(
|
2023-03-12 22:29:15 +01:00
|
|
|
MEM_malloc_arrayN(size_t(vert_positions.size()), sizeof(*cos), __func__));
|
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
|
|
|
blender::Array<blender::float3> nos(corner_verts.size());
|
2015-02-05 14:49:44 +01:00
|
|
|
float size[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-03-12 22:29:15 +01:00
|
|
|
BLI_bitmap *done_verts = BLI_BITMAP_NEW(size_t(vert_positions.size()), __func__);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-03-12 22:29:15 +01:00
|
|
|
generate_vert_coordinates(mesh, ob, ob_target, enmd->offset, vert_positions.size(), cos, size);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-06 13:54:38 +11:00
|
|
|
/**
|
2021-07-20 22:52:31 +10:00
|
|
|
* size gives us our spheroid coefficients `(A, B, C)`.
|
2015-02-05 14:49:44 +01:00
|
|
|
* Then, we want to find out for each vert its (a, b, c) triple (proportional to (A, B, C) one).
|
|
|
|
|
*
|
2021-07-20 22:52:31 +10:00
|
|
|
* Ellipsoid basic equation: `(x^2/a^2) + (y^2/b^2) + (z^2/c^2) = 1`.
|
2019-05-01 07:40:07 +10:00
|
|
|
* Since we want to find (a, b, c) matching this equation and proportional to (A, B, C),
|
|
|
|
|
* we can do:
|
2015-02-06 13:54:38 +11:00
|
|
|
* <pre>
|
2015-02-05 14:49:44 +01:00
|
|
|
* m = B / A
|
|
|
|
|
* n = C / A
|
2015-02-06 13:54:38 +11:00
|
|
|
* </pre>
|
|
|
|
|
*
|
2015-02-05 14:49:44 +01:00
|
|
|
* hence:
|
2015-02-06 13:54:38 +11:00
|
|
|
* <pre>
|
2015-02-05 14:49:44 +01:00
|
|
|
* (x^2/a^2) + (y^2/b^2) + (z^2/c^2) = 1
|
|
|
|
|
* -> b^2*c^2*x^2 + a^2*c^2*y^2 + a^2*b^2*z^2 = a^2*b^2*c^2
|
|
|
|
|
* b = ma
|
|
|
|
|
* c = na
|
|
|
|
|
* -> m^2*a^2*n^2*a^2*x^2 + a^2*n^2*a^2*y^2 + a^2*m^2*a^2*z^2 = a^2*m^2*a^2*n^2*a^2
|
|
|
|
|
* -> m^2*n^2*a^4*x^2 + n^2*a^4*y^2 + m^2*a^4*z^2 = m^2*n^2*a^6
|
|
|
|
|
* -> a^2 = (m^2*n^2*x^2 + n^2y^2 + m^2z^2) / (m^2*n^2) = x^2 + (y^2 / m^2) + (z^2 / n^2)
|
|
|
|
|
* -> b^2 = (m^2*n^2*x^2 + n^2y^2 + m^2z^2) / (n^2) = (m^2 * x^2) + y^2 + (m^2 * z^2 / n^2)
|
|
|
|
|
* -> c^2 = (m^2*n^2*x^2 + n^2y^2 + m^2z^2) / (m^2) = (n^2 * x^2) + (n^2 * y^2 / m^2) + z^2
|
2015-02-06 13:54:38 +11:00
|
|
|
* </pre>
|
2015-02-05 14:49:44 +01:00
|
|
|
*
|
|
|
|
|
* All we have to do now is compute normal of the spheroid at that point:
|
2015-02-06 13:54:38 +11:00
|
|
|
* <pre>
|
2015-02-05 14:49:44 +01:00
|
|
|
* n = (x / a^2, y / b^2, z / c^2)
|
2015-02-06 13:54:38 +11:00
|
|
|
* </pre>
|
2015-02-05 14:49:44 +01:00
|
|
|
* And we are done!
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
const float a = size[0], b = size[1], c = size[2];
|
|
|
|
|
const float m2 = (b * b) / (a * a);
|
|
|
|
|
const float n2 = (c * c) / (a * a);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
/* We reuse cos to now store the ellipsoid-normal of the verts! */
|
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
|
|
|
for (const int64_t i : corner_verts.index_range()) {
|
|
|
|
|
const int vidx = corner_verts[i];
|
2015-02-05 14:49:44 +01:00
|
|
|
float *co = cos[vidx];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
if (!BLI_BITMAP_TEST(done_verts, vidx)) {
|
|
|
|
|
const float x2 = co[0] * co[0];
|
|
|
|
|
const float y2 = co[1] * co[1];
|
|
|
|
|
const float z2 = co[2] * co[2];
|
|
|
|
|
const float a2 = x2 + (y2 / m2) + (z2 / n2);
|
|
|
|
|
const float b2 = (m2 * x2) + y2 + (m2 * z2 / n2);
|
|
|
|
|
const float c2 = (n2 * x2) + (n2 * y2 / m2) + z2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
co[0] /= a2;
|
|
|
|
|
co[1] /= b2;
|
|
|
|
|
co[2] /= c2;
|
|
|
|
|
normalize_v3(co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
BLI_BITMAP_ENABLE(done_verts, vidx);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2023-03-12 22:29:15 +01:00
|
|
|
nos[i] = co;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-12 22:29:15 +01:00
|
|
|
if (!loop_normals.is_empty()) {
|
2015-02-05 14:49:44 +01:00
|
|
|
mix_normals(mix_factor,
|
|
|
|
|
dvert,
|
|
|
|
|
defgrp_index,
|
|
|
|
|
use_invert_vgroup,
|
|
|
|
|
mix_limit,
|
2016-06-06 21:41:17 +02:00
|
|
|
mix_mode,
|
2023-03-12 22:29:15 +01:00
|
|
|
vert_positions.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
|
|
|
corner_verts,
|
2023-03-12 22:29:15 +01:00
|
|
|
loop_normals.data(),
|
|
|
|
|
nos.data());
|
2015-02-05 14:49:44 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-02 14:15:27 +02:00
|
|
|
if (do_facenors_fix) {
|
|
|
|
|
faces_check_flip(*mesh, nos, mesh->face_normals());
|
2016-02-28 15:48:08 +01:00
|
|
|
}
|
Mesh: Move face shade smooth flag to a generic attribute
Currently the shade smooth status for mesh faces is stored as part of
`MPoly::flag`. As described in #95967, this moves that information
to a separate boolean attribute. It also flips its status, so the
attribute is now called `sharp_face`, which mirrors the existing
`sharp_edge` attribute. The attribute doesn't need to be allocated
when all faces are smooth. Forward compatibility is kept until
4.0 like the other mesh refactors.
This will reduce memory bandwidth requirements for some operations,
since the array of booleans uses 12 times less memory than `MPoly`.
It also allows faces to be stored more efficiently in the future, since
the flag is now unused. It's also possible to use generic functions to
process the values. For example, finding whether there is a sharp face
is just `sharp_faces.contains(true)`.
The `shade_smooth` attribute is no longer accessible with geometry nodes.
Since there were dedicated accessor nodes for that data, that shouldn't
be a problem. That's difficult to version automatically since the named
attribute nodes could be used in arbitrary combinations.
**Implementation notes:**
- The attribute and array variables in the code use the `sharp_faces`
term, to be consistent with the user-facing "sharp faces" wording,
and to avoid requiring many renames when #101689 is implemented.
- Cycles now accesses smooth face status with the generic attribute,
to avoid overhead.
- Changing the zero-value from "smooth" to "flat" takes some care to
make sure defaults are the same.
- Versioning for the edge mode extrude node is particularly complex.
New nodes are added by versioning to propagate the attribute in its
old inverted state.
- A lot of access is still done through the `CustomData` API rather
than the attribute API because of a few functions. That can be
cleaned up easily in the future.
- In the future we would benefit from a way to store attributes as a
single value for when all faces are sharp.
Pull Request: https://projects.blender.org/blender/blender/pulls/104422
2023-03-08 15:36:18 +01:00
|
|
|
const bool *sharp_faces = static_cast<const bool *>(
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_get_layer_named(&mesh->face_data, CD_PROP_BOOL, "sharp_face"));
|
2023-03-12 22:29:15 +01:00
|
|
|
blender::bke::mesh::normals_loop_custom_set(vert_positions,
|
|
|
|
|
edges,
|
2023-07-24 22:06:55 +02:00
|
|
|
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
|
|
|
corner_verts,
|
|
|
|
|
corner_edges,
|
2023-03-12 22:29:15 +01:00
|
|
|
mesh->vert_normals(),
|
2023-07-24 22:06:55 +02:00
|
|
|
mesh->face_normals(),
|
2023-03-12 22:29:15 +01:00
|
|
|
sharp_faces,
|
|
|
|
|
sharp_edges,
|
|
|
|
|
nos,
|
|
|
|
|
clnors);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
MEM_freeN(cos);
|
|
|
|
|
MEM_freeN(done_verts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void normalEditModifier_do_directional(NormalEditModifierData *enmd,
|
2022-10-03 17:37:25 -05:00
|
|
|
const ModifierEvalContext * /*ctx*/,
|
2018-12-07 15:45:53 +01:00
|
|
|
Object *ob,
|
|
|
|
|
Mesh *mesh,
|
2023-04-28 13:34:15 -04:00
|
|
|
blender::MutableSpan<blender::short2> clnors,
|
2023-03-12 22:29:15 +01:00
|
|
|
blender::MutableSpan<blender::float3> loop_normals,
|
2016-06-06 21:41:17 +02:00
|
|
|
const short mix_mode,
|
|
|
|
|
const float mix_factor,
|
|
|
|
|
const float mix_limit,
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
const MDeformVert *dvert,
|
2015-02-05 14:49:44 +01:00
|
|
|
const int defgrp_index,
|
|
|
|
|
const bool use_invert_vgroup,
|
2023-03-12 22:29:15 +01:00
|
|
|
const blender::Span<blender::float3> positions,
|
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 blender::Span<blender::int2> edges,
|
2023-03-12 22:29:15 +01:00
|
|
|
blender::MutableSpan<bool> sharp_edges,
|
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
|
|
|
blender::MutableSpan<int> corner_verts,
|
|
|
|
|
blender::MutableSpan<int> corner_edges,
|
2023-07-24 22:06:55 +02:00
|
|
|
const blender::OffsetIndices<int> faces)
|
2015-02-05 14:49:44 +01:00
|
|
|
{
|
2019-03-26 11:25:07 +01:00
|
|
|
Object *ob_target = enmd->target;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
const bool do_facenors_fix = (enmd->flag & MOD_NORMALEDIT_NO_POLYNORS_FIX) == 0;
|
2016-09-30 12:15:18 +02:00
|
|
|
const bool use_parallel_normals = (enmd->flag & MOD_NORMALEDIT_USE_DIRECTION_PARALLEL) != 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
blender::Array<blender::float3> nos(corner_verts.size());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
float target_co[3];
|
|
|
|
|
int i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
/* Get target's center coordinates in ob local coordinates. */
|
2018-05-07 14:36:00 +02:00
|
|
|
float mat[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-10-24 14:16:37 +02:00
|
|
|
invert_m4_m4(mat, ob->object_to_world);
|
|
|
|
|
mul_m4_m4m4(mat, mat, ob_target->object_to_world);
|
2018-05-07 14:36:00 +02:00
|
|
|
copy_v3_v3(target_co, mat[3]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-09-30 12:15:18 +02:00
|
|
|
if (use_parallel_normals) {
|
2015-02-05 14:49:44 +01:00
|
|
|
float no[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
sub_v3_v3v3(no, target_co, enmd->offset);
|
|
|
|
|
normalize_v3(no);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
for (i = corner_verts.size(); i--;) {
|
2015-02-05 14:49:44 +01:00
|
|
|
copy_v3_v3(nos[i], no);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-02-05 14:49:44 +01:00
|
|
|
else {
|
2022-10-02 11:16:14 -05:00
|
|
|
float(*cos)[3] = static_cast<float(*)[3]>(
|
2023-03-12 22:29:15 +01:00
|
|
|
MEM_malloc_arrayN(size_t(positions.size()), sizeof(*cos), __func__));
|
|
|
|
|
generate_vert_coordinates(mesh, ob, ob_target, nullptr, positions.size(), cos, nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-03-12 22:29:15 +01:00
|
|
|
BLI_bitmap *done_verts = BLI_BITMAP_NEW(size_t(positions.size()), __func__);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-09-30 12:15:18 +02:00
|
|
|
/* We reuse cos to now store the 'to target' normal of the verts! */
|
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
|
|
|
for (const int64_t i : corner_verts.index_range()) {
|
|
|
|
|
const int vidx = corner_verts[i];
|
2015-02-05 14:49:44 +01:00
|
|
|
float *co = cos[vidx];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
if (!BLI_BITMAP_TEST(done_verts, vidx)) {
|
2016-09-30 12:15:18 +02:00
|
|
|
sub_v3_v3v3(co, target_co, co);
|
2015-02-05 14:49:44 +01:00
|
|
|
normalize_v3(co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
BLI_BITMAP_ENABLE(done_verts, vidx);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2023-03-12 22:29:15 +01:00
|
|
|
nos[i] = co;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
MEM_freeN(done_verts);
|
|
|
|
|
MEM_freeN(cos);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-03-12 22:29:15 +01:00
|
|
|
if (!loop_normals.is_empty()) {
|
2018-05-07 14:36:00 +02:00
|
|
|
mix_normals(mix_factor,
|
2019-04-17 06:17:24 +02:00
|
|
|
dvert,
|
2016-09-30 12:15:18 +02:00
|
|
|
defgrp_index,
|
2018-05-07 14:36:00 +02:00
|
|
|
use_invert_vgroup,
|
2016-06-06 21:41:17 +02:00
|
|
|
mix_limit,
|
2018-05-07 14:36:00 +02:00
|
|
|
mix_mode,
|
2023-03-12 22:29:15 +01:00
|
|
|
positions.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
|
|
|
corner_verts,
|
2023-03-12 22:29:15 +01:00
|
|
|
loop_normals.data(),
|
|
|
|
|
nos.data());
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-02 14:15:27 +02:00
|
|
|
if (do_facenors_fix) {
|
|
|
|
|
faces_check_flip(*mesh, nos, mesh->face_normals());
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
Mesh: Move face shade smooth flag to a generic attribute
Currently the shade smooth status for mesh faces is stored as part of
`MPoly::flag`. As described in #95967, this moves that information
to a separate boolean attribute. It also flips its status, so the
attribute is now called `sharp_face`, which mirrors the existing
`sharp_edge` attribute. The attribute doesn't need to be allocated
when all faces are smooth. Forward compatibility is kept until
4.0 like the other mesh refactors.
This will reduce memory bandwidth requirements for some operations,
since the array of booleans uses 12 times less memory than `MPoly`.
It also allows faces to be stored more efficiently in the future, since
the flag is now unused. It's also possible to use generic functions to
process the values. For example, finding whether there is a sharp face
is just `sharp_faces.contains(true)`.
The `shade_smooth` attribute is no longer accessible with geometry nodes.
Since there were dedicated accessor nodes for that data, that shouldn't
be a problem. That's difficult to version automatically since the named
attribute nodes could be used in arbitrary combinations.
**Implementation notes:**
- The attribute and array variables in the code use the `sharp_faces`
term, to be consistent with the user-facing "sharp faces" wording,
and to avoid requiring many renames when #101689 is implemented.
- Cycles now accesses smooth face status with the generic attribute,
to avoid overhead.
- Changing the zero-value from "smooth" to "flat" takes some care to
make sure defaults are the same.
- Versioning for the edge mode extrude node is particularly complex.
New nodes are added by versioning to propagate the attribute in its
old inverted state.
- A lot of access is still done through the `CustomData` API rather
than the attribute API because of a few functions. That can be
cleaned up easily in the future.
- In the future we would benefit from a way to store attributes as a
single value for when all faces are sharp.
Pull Request: https://projects.blender.org/blender/blender/pulls/104422
2023-03-08 15:36:18 +01:00
|
|
|
const bool *sharp_faces = static_cast<const bool *>(
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_get_layer_named(&mesh->face_data, CD_PROP_BOOL, "sharp_face"));
|
2023-03-12 22:29:15 +01:00
|
|
|
blender::bke::mesh::normals_loop_custom_set(positions,
|
|
|
|
|
edges,
|
2023-07-24 22:06:55 +02:00
|
|
|
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
|
|
|
corner_verts,
|
|
|
|
|
corner_edges,
|
2023-03-12 22:29:15 +01:00
|
|
|
mesh->vert_normals(),
|
2023-07-24 22:06:55 +02:00
|
|
|
mesh->face_normals(),
|
2023-03-12 22:29:15 +01:00
|
|
|
sharp_faces,
|
|
|
|
|
sharp_edges,
|
|
|
|
|
nos,
|
|
|
|
|
clnors);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-05-07 14:36:00 +02:00
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
static bool is_valid_target(NormalEditModifierData *enmd)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
2015-02-05 14:49:44 +01:00
|
|
|
if (enmd->mode == MOD_NORMALEDIT_MODE_RADIAL) {
|
|
|
|
|
return true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-08-07 12:40:29 +02:00
|
|
|
if ((enmd->mode == MOD_NORMALEDIT_MODE_DIRECTIONAL) && enmd->target) {
|
2015-02-05 14:49:44 +01:00
|
|
|
return true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-10-26 17:07:58 +11:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool is_valid_target_with_error(const Object *ob, NormalEditModifierData *enmd)
|
|
|
|
|
{
|
|
|
|
|
if (is_valid_target(enmd)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
BKE_modifier_set_error(ob, (ModifierData *)enmd, "Invalid target settings");
|
2015-02-05 14:49:44 +01:00
|
|
|
return false;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2018-12-07 15:45:53 +01:00
|
|
|
static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
|
2015-02-05 14:49:44 +01:00
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
|
Object *ob,
|
2018-05-07 14:36:00 +02:00
|
|
|
Mesh *mesh)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
2023-01-10 16:12:14 -05:00
|
|
|
using namespace blender;
|
2015-02-05 14:49:44 +01:00
|
|
|
const bool use_invert_vgroup = ((enmd->flag & MOD_NORMALEDIT_INVERT_VGROUP) != 0);
|
2016-09-30 12:15:18 +02:00
|
|
|
const bool use_current_clnors = !((enmd->mix_mode == MOD_NORMALEDIT_MIX_COPY) &&
|
2015-02-05 14:49:44 +01:00
|
|
|
(enmd->mix_factor == 1.0f) && (enmd->defgrp_name[0] == '\0') &&
|
2022-10-03 10:24:06 +11:00
|
|
|
(enmd->mix_limit == float(M_PI)));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-07 15:11:19 +10:00
|
|
|
/* Do not run that modifier at all if auto-smooth is disabled! */
|
2020-10-26 17:07:58 +11:00
|
|
|
if (!is_valid_target_with_error(ctx->object, enmd) || mesh->totloop == 0) {
|
2018-05-07 14:36:00 +02:00
|
|
|
return mesh;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-18 07:52:45 +02:00
|
|
|
Mesh *result;
|
2023-02-23 10:39:51 -05:00
|
|
|
if (mesh->edges().data() == ((Mesh *)ob->data)->edges().data()) {
|
2019-05-01 07:40:07 +10:00
|
|
|
/* We need to duplicate data here, otherwise setting custom normals
|
|
|
|
|
* (which may also affect sharp edges) could
|
2023-02-12 14:37:16 +11:00
|
|
|
* modify original mesh, see #43671. */
|
2022-10-02 11:16:14 -05:00
|
|
|
result = (Mesh *)BKE_id_copy_ex(nullptr, &mesh->id, nullptr, LIB_ID_COPY_LOCALIZE);
|
2019-04-18 07:52:45 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
result = mesh;
|
|
|
|
|
}
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2023-03-12 22:29:15 +01:00
|
|
|
const blender::Span<blender::float3> positions = result->vert_positions();
|
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 blender::Span<int2> edges = result->edges();
|
2023-07-24 22:06:55 +02:00
|
|
|
const OffsetIndices faces = result->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
|
|
|
blender::MutableSpan<int> corner_verts = result->corner_verts_for_write();
|
|
|
|
|
blender::MutableSpan<int> corner_edges = result->corner_edges_for_write();
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2019-04-18 07:52:45 +02:00
|
|
|
int defgrp_index;
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
const MDeformVert *dvert;
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2023-03-12 22:29:15 +01:00
|
|
|
blender::Array<blender::float3> loop_normals;
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData *ldata = &result->loop_data;
|
2016-02-28 15:48:08 +01:00
|
|
|
|
2023-01-10 16:12:14 -05:00
|
|
|
bke::MutableAttributeAccessor attributes = result->attributes_for_write();
|
|
|
|
|
bke::SpanAttributeWriter<bool> sharp_edges = attributes.lookup_or_add_for_write_span<bool>(
|
|
|
|
|
"sharp_edge", ATTR_DOMAIN_EDGE);
|
|
|
|
|
|
2023-04-28 13:34:15 -04:00
|
|
|
blender::short2 *clnors = static_cast<blender::short2 *>(
|
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
|
|
|
CustomData_get_layer_for_write(ldata, CD_CUSTOMLOOPNORMAL, corner_verts.size()));
|
2019-04-18 07:52:45 +02:00
|
|
|
if (use_current_clnors) {
|
2023-04-28 13:34:15 -04:00
|
|
|
clnors = static_cast<blender::short2 *>(
|
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
|
|
|
CustomData_get_layer_for_write(ldata, CD_CUSTOMLOOPNORMAL, corner_verts.size()));
|
|
|
|
|
loop_normals.reinitialize(corner_verts.size());
|
Mesh: Move face shade smooth flag to a generic attribute
Currently the shade smooth status for mesh faces is stored as part of
`MPoly::flag`. As described in #95967, this moves that information
to a separate boolean attribute. It also flips its status, so the
attribute is now called `sharp_face`, which mirrors the existing
`sharp_edge` attribute. The attribute doesn't need to be allocated
when all faces are smooth. Forward compatibility is kept until
4.0 like the other mesh refactors.
This will reduce memory bandwidth requirements for some operations,
since the array of booleans uses 12 times less memory than `MPoly`.
It also allows faces to be stored more efficiently in the future, since
the flag is now unused. It's also possible to use generic functions to
process the values. For example, finding whether there is a sharp face
is just `sharp_faces.contains(true)`.
The `shade_smooth` attribute is no longer accessible with geometry nodes.
Since there were dedicated accessor nodes for that data, that shouldn't
be a problem. That's difficult to version automatically since the named
attribute nodes could be used in arbitrary combinations.
**Implementation notes:**
- The attribute and array variables in the code use the `sharp_faces`
term, to be consistent with the user-facing "sharp faces" wording,
and to avoid requiring many renames when #101689 is implemented.
- Cycles now accesses smooth face status with the generic attribute,
to avoid overhead.
- Changing the zero-value from "smooth" to "flat" takes some care to
make sure defaults are the same.
- Versioning for the edge mode extrude node is particularly complex.
New nodes are added by versioning to propagate the attribute in its
old inverted state.
- A lot of access is still done through the `CustomData` API rather
than the attribute API because of a few functions. That can be
cleaned up easily in the future.
- In the future we would benefit from a way to store attributes as a
single value for when all faces are sharp.
Pull Request: https://projects.blender.org/blender/blender/pulls/104422
2023-03-08 15:36:18 +01:00
|
|
|
const bool *sharp_faces = static_cast<const bool *>(
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_get_layer_named(&result->face_data, CD_PROP_BOOL, "sharp_face"));
|
2023-03-12 22:29:15 +01:00
|
|
|
blender::bke::mesh::normals_calc_loop(positions,
|
|
|
|
|
edges,
|
2023-07-24 22:06:55 +02:00
|
|
|
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
|
|
|
corner_verts,
|
|
|
|
|
corner_edges,
|
2023-08-30 23:41:59 +02:00
|
|
|
result->corner_to_face_map(),
|
2023-03-15 21:38:38 -04:00
|
|
|
result->vert_normals(),
|
2023-07-24 22:06:55 +02:00
|
|
|
result->face_normals(),
|
2023-03-12 22:29:15 +01:00
|
|
|
sharp_edges.span.data(),
|
|
|
|
|
sharp_faces,
|
2023-07-26 17:04:13 +02:00
|
|
|
clnors,
|
2023-03-12 22:29:15 +01:00
|
|
|
nullptr,
|
|
|
|
|
loop_normals);
|
2019-04-18 07:52:45 +02:00
|
|
|
}
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2022-10-02 11:16:14 -05:00
|
|
|
if (clnors == nullptr) {
|
2023-04-28 13:34:15 -04:00
|
|
|
clnors = static_cast<blender::short2 *>(
|
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
|
|
|
CustomData_add_layer(ldata, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, corner_verts.size()));
|
2019-04-18 07:52:45 +02:00
|
|
|
}
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2019-04-18 07:52:45 +02:00
|
|
|
MOD_get_vgroup(ob, result, enmd->defgrp_name, &dvert, &defgrp_index);
|
|
|
|
|
|
|
|
|
|
if (enmd->mode == MOD_NORMALEDIT_MODE_RADIAL) {
|
|
|
|
|
normalEditModifier_do_radial(enmd,
|
|
|
|
|
ctx,
|
|
|
|
|
ob,
|
|
|
|
|
result,
|
2023-04-28 13:34:15 -04:00
|
|
|
{clnors, result->totloop},
|
2022-12-17 12:47:43 +11:00
|
|
|
loop_normals,
|
2019-04-18 07:52:45 +02:00
|
|
|
enmd->mix_mode,
|
|
|
|
|
enmd->mix_factor,
|
|
|
|
|
enmd->mix_limit,
|
|
|
|
|
dvert,
|
|
|
|
|
defgrp_index,
|
|
|
|
|
use_invert_vgroup,
|
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
|
|
|
positions,
|
2023-03-01 12:47:55 -05:00
|
|
|
edges,
|
2023-03-12 22:29:15 +01:00
|
|
|
sharp_edges.span,
|
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
|
|
|
corner_verts,
|
|
|
|
|
corner_edges,
|
2023-07-24 22:06:55 +02:00
|
|
|
faces);
|
2019-04-18 07:52:45 +02:00
|
|
|
}
|
|
|
|
|
else if (enmd->mode == MOD_NORMALEDIT_MODE_DIRECTIONAL) {
|
|
|
|
|
normalEditModifier_do_directional(enmd,
|
|
|
|
|
ctx,
|
|
|
|
|
ob,
|
|
|
|
|
result,
|
2023-04-28 13:34:15 -04:00
|
|
|
{clnors, result->totloop},
|
2022-12-17 12:47:43 +11:00
|
|
|
loop_normals,
|
2019-04-18 07:52:45 +02:00
|
|
|
enmd->mix_mode,
|
|
|
|
|
enmd->mix_factor,
|
|
|
|
|
enmd->mix_limit,
|
|
|
|
|
dvert,
|
|
|
|
|
defgrp_index,
|
|
|
|
|
use_invert_vgroup,
|
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
|
|
|
positions,
|
2023-03-01 12:47:55 -05:00
|
|
|
edges,
|
2023-03-12 22:29:15 +01:00
|
|
|
sharp_edges.span,
|
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
|
|
|
corner_verts,
|
|
|
|
|
corner_edges,
|
2023-07-24 22:06:55 +02:00
|
|
|
faces);
|
2019-04-18 07:52:45 +02:00
|
|
|
}
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2022-10-12 20:55:26 -05:00
|
|
|
result->runtime->is_original_bmesh = false;
|
2020-08-11 21:46:06 +10:00
|
|
|
|
2023-01-10 16:12:14 -05:00
|
|
|
sharp_edges.finish();
|
|
|
|
|
|
2019-04-18 07:52:45 +02:00
|
|
|
return result;
|
2015-02-05 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void init_data(ModifierData *md)
|
2015-02-05 14:49:44 +01:00
|
|
|
{
|
2016-09-30 12:15:18 +02:00
|
|
|
NormalEditModifierData *enmd = (NormalEditModifierData *)md;
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(enmd, modifier));
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
MEMCPY_STRUCT_AFTER(enmd, DNA_struct_default_get(NormalEditModifierData), modifier);
|
2015-02-05 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
|
2015-02-05 14:49:44 +01:00
|
|
|
{
|
2016-09-30 12:15:18 +02:00
|
|
|
NormalEditModifierData *enmd = (NormalEditModifierData *)md;
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
|
|
|
|
|
r_cddata_masks->lmask |= CD_MASK_CUSTOMLOOPNORMAL;
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2023-05-05 09:25:45 +10:00
|
|
|
/* Ask for vertex-groups if we need them. */
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
if (enmd->defgrp_name[0] != '\0') {
|
|
|
|
|
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
|
2015-02-05 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static bool depends_on_normals(ModifierData * /*md*/)
|
2015-02-05 14:49:44 +01:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
|
2015-02-05 14:49:44 +01:00
|
|
|
{
|
2016-09-30 12:15:18 +02:00
|
|
|
NormalEditModifierData *enmd = (NormalEditModifierData *)md;
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
walk(user_data, ob, (ID **)&enmd->target, IDWALK_CB_NOP);
|
2015-02-05 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static bool is_disabled(const Scene * /*scene*/, ModifierData *md, bool /*use_render_params*/)
|
2015-02-05 14:49:44 +01:00
|
|
|
{
|
2016-09-30 12:15:18 +02:00
|
|
|
NormalEditModifierData *enmd = (NormalEditModifierData *)md;
|
2015-02-05 14:49:44 +01:00
|
|
|
|
2016-09-30 12:15:18 +02:00
|
|
|
return !is_valid_target(enmd);
|
2015-02-05 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void update_depsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
{
|
2016-09-30 12:15:18 +02:00
|
|
|
NormalEditModifierData *enmd = (NormalEditModifierData *)md;
|
|
|
|
|
if (enmd->target) {
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(ctx->node, enmd->target, DEG_OB_COMP_TRANSFORM, "NormalEdit Modifier");
|
2022-08-04 12:11:31 +02:00
|
|
|
DEG_add_depends_on_transform_relation(ctx->node, "NormalEdit Modifier");
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
|
2015-02-05 14:49:44 +01:00
|
|
|
{
|
2018-12-07 15:45:53 +01:00
|
|
|
return normalEditModifier_do((NormalEditModifierData *)md, ctx, ctx->object, mesh);
|
2015-02-05 14:49:44 +01:00
|
|
|
}
|
|
|
|
|
|
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 *col;
|
|
|
|
|
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
|
|
|
|
2022-10-02 11:16:14 -05:00
|
|
|
uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
|
UI: Small Tweaks to Modifier Layouts for Consistency
These changes are smaller, made based on feedback and a pass on all
the layouts for clarity and consistency. The Multires modifier UI will
be addressed in a separate patch. Here is an overview of the changes:
Renaming Options:
- Build: "Start" -> "Start Frame"
- Curve: "From Radius" -> "Size from Radius"
- Screw: "Calc Order" -> "Calculate Order"
- Displace, Warp, Wave: "Texture Coordinates Object" -> "Object"
Move Mode Toggle to Top & Expand:
- Bevel, Boolean, Normal Edit, Subdivision
Use Columns for Tighter Spacing:
- Displace, Explode, Ocean, Particle Instance, Remesh, Shrinkwrap,
Solidify, Warp, Weighted Normal, Wave
Misc:
- Bevel: Set inactive properties for vertex bevel
- Mesh Sequence Cache: Remove box for cache file
- Skin: Don't align "Mark Loose" and "Clear Loose"
- Array: Expand relative offset subpanel by default
- Array: Move start cap, end cap to a new subpanel
- Bevel: Move width type above width
Differential Revision: https://developer.blender.org/D8115
2020-07-02 10:47:02 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "target", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
col = uiLayoutColumn(layout, false);
|
|
|
|
|
uiLayoutSetActive(col, mode == MOD_NORMALEDIT_MODE_DIRECTIONAL);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(col, ptr, "use_direction_parallel", 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This panel could be open by default, but it isn't currently. */
|
2022-10-03 17:37:25 -05:00
|
|
|
static void mix_mode_panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *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
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "mix_mode", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "mix_factor", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2022-10-02 11:16:14 -05:00
|
|
|
modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", nullptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
row = uiLayoutRow(layout, true);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(row, ptr, "mix_limit", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
uiItemR(row,
|
2020-09-02 14:13:26 -05:00
|
|
|
ptr,
|
2020-06-05 10:41:03 -04:00
|
|
|
"no_polynors_fix",
|
2023-07-29 15:06:33 +10:00
|
|
|
UI_ITEM_NONE,
|
2020-06-05 10:41:03 -04:00
|
|
|
"",
|
2020-09-02 14:13:26 -05:00
|
|
|
(RNA_boolean_get(ptr, "no_polynors_fix") ? ICON_LOCKED : ICON_UNLOCKED));
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static void offset_panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
2022-10-02 11:16:14 -05:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, nullptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
int mode = RNA_enum_get(ptr, "mode");
|
|
|
|
|
PointerRNA target_ptr = RNA_pointer_get(ptr, "target");
|
2020-06-05 10:41:03 -04:00
|
|
|
bool needs_object_offset = (mode == MOD_NORMALEDIT_MODE_RADIAL &&
|
|
|
|
|
RNA_pointer_is_null(&target_ptr)) ||
|
|
|
|
|
(mode == MOD_NORMALEDIT_MODE_DIRECTIONAL &&
|
2020-09-02 14:13:26 -05:00
|
|
|
RNA_boolean_get(ptr, "use_direction_parallel"));
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
|
|
|
|
uiLayoutSetActive(layout, needs_object_offset);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "offset", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void panel_register(ARegionType *region_type)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
PanelType *panel_type = modifier_panel_register(
|
|
|
|
|
region_type, eModifierType_NormalEdit, panel_draw);
|
2022-10-02 11:16:14 -05:00
|
|
|
modifier_subpanel_register(region_type, "mix", "Mix", nullptr, mix_mode_panel_draw, panel_type);
|
|
|
|
|
modifier_subpanel_register(
|
|
|
|
|
region_type, "offset", "Offset", nullptr, offset_panel_draw, panel_type);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2015-02-05 14:49:44 +01:00
|
|
|
ModifierTypeInfo modifierType_NormalEdit = {
|
2023-07-26 17:08:14 +02:00
|
|
|
/*idname*/ "NormalEdit",
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("NormalEdit"),
|
2023-07-27 12:04:18 +10:00
|
|
|
/*struct_name*/ "NormalEditModifierData",
|
|
|
|
|
/*struct_size*/ sizeof(NormalEditModifierData),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*srna*/ &RNA_NormalEditModifier,
|
2023-11-14 10:03:56 +01:00
|
|
|
/*type*/ ModifierTypeType::Constructive,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*flags*/ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsMapping |
|
2015-02-05 14:49:44 +01:00
|
|
|
eModifierTypeFlag_SupportsEditmode | eModifierTypeFlag_EnableInEditmode,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*icon*/ ICON_MOD_NORMALEDIT,
|
|
|
|
|
|
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*/ depends_on_normals,
|
|
|
|
|
/*foreach_ID_link*/ foreach_ID_link,
|
|
|
|
|
/*foreach_tex_link*/ nullptr,
|
|
|
|
|
/*free_runtime_data*/ nullptr,
|
|
|
|
|
/*panel_register*/ panel_register,
|
|
|
|
|
/*blend_write*/ nullptr,
|
|
|
|
|
/*blend_read*/ nullptr,
|
2015-02-05 14:49:44 +01:00
|
|
|
};
|