2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup modifiers
|
2011-02-25 13:57:17 +00:00
|
|
|
*/
|
|
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
/* Screw modifier: revolves the edges about an axis */
|
2022-12-12 18:19:32 -06:00
|
|
|
#include <climits>
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2022-01-28 22:40:13 -06:00
|
|
|
#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_geom.h"
|
|
|
|
|
#include "BLI_math_matrix.h"
|
|
|
|
|
#include "BLI_math_rotation.h"
|
|
|
|
|
#include "BLI_math_vector.h"
|
2023-02-23 19:10:01 +01:00
|
|
|
#include "BLI_span.hh"
|
2019-02-25 11:39:14 +01:00
|
|
|
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "BLT_translation.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
#include "DNA_defaults.h"
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "DNA_meshdata_types.h"
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "DNA_object_types.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "DNA_screen_types.h"
|
2010-04-12 22:33:43 +00: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
|
|
|
#include "BKE_attribute.hh"
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "BKE_context.hh"
|
2023-12-26 23:21:19 -05:00
|
|
|
#include "BKE_customdata.hh"
|
2024-01-15 12:44:04 -05:00
|
|
|
#include "BKE_lib_id.hh"
|
2024-01-18 12:20:42 +01:00
|
|
|
#include "BKE_lib_query.hh"
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "BKE_screen.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface.hh"
|
|
|
|
|
#include "UI_resources.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph_build.hh"
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "DEG_depsgraph_query.hh"
|
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
|
|
|
|
2010-04-12 01:09:59 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include "MOD_modifiertypes.hh"
|
|
|
|
|
#include "MOD_ui_common.hh"
|
2010-04-12 01:09:59 +00:00
|
|
|
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "BLI_strict_flags.h"
|
2023-02-23 19:10:01 +01:00
|
|
|
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "GEO_mesh_merge_by_distance.hh"
|
2024-02-14 13:40:31 +11:00
|
|
|
|
2023-02-23 19:10:01 +01:00
|
|
|
using namespace blender;
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void init_data(ModifierData *md)
|
2020-10-01 09:38:00 -05:00
|
|
|
{
|
|
|
|
|
ScrewModifierData *ltmd = (ScrewModifierData *)md;
|
|
|
|
|
|
|
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(ltmd, modifier));
|
|
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(ltmd, DNA_struct_default_get(ScrewModifierData), modifier);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-12 11:18:00 +10:00
|
|
|
/** Used for gathering edge connectivity. */
|
2022-12-12 18:19:32 -06:00
|
|
|
struct ScrewVertConnect {
|
2022-08-12 11:18:00 +10:00
|
|
|
/** Distance from the center axis. */
|
|
|
|
|
float dist_sq;
|
|
|
|
|
/** Location relative to the transformed axis. */
|
|
|
|
|
float co[3];
|
|
|
|
|
/** 2 verts on either side of this one. */
|
|
|
|
|
uint v[2];
|
|
|
|
|
/** Edges on either side, a bit of a waste since each edge ref's 2 edges. */
|
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
|
|
|
blender::int2 *e[2];
|
2010-04-11 22:12:30 +00:00
|
|
|
char flag;
|
2022-12-12 18:19:32 -06:00
|
|
|
};
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
struct ScrewVertIter {
|
2012-05-06 13:38:33 +00:00
|
|
|
ScrewVertConnect *v_array;
|
|
|
|
|
ScrewVertConnect *v_poin;
|
2019-09-19 13:32:36 +10:00
|
|
|
uint v, v_other;
|
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
|
|
|
blender::int2 *e;
|
2022-12-12 18:19:32 -06:00
|
|
|
};
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2013-11-21 10:35:48 +11:00
|
|
|
#define SV_UNUSED (UINT_MAX)
|
|
|
|
|
#define SV_INVALID ((UINT_MAX)-1)
|
2016-06-01 00:19:01 +10:00
|
|
|
#define SV_IS_VALID(v) ((v) < SV_INVALID)
|
2010-08-05 23:40:21 +00:00
|
|
|
|
2013-11-21 10:35:48 +11:00
|
|
|
static void screwvert_iter_init(ScrewVertIter *iter,
|
|
|
|
|
ScrewVertConnect *array,
|
2019-09-19 13:32:36 +10:00
|
|
|
uint v_init,
|
|
|
|
|
uint dir)
|
2010-08-05 23:40:21 +00:00
|
|
|
{
|
|
|
|
|
iter->v_array = array;
|
|
|
|
|
iter->v = v_init;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-21 10:35:48 +11:00
|
|
|
if (SV_IS_VALID(v_init)) {
|
2010-08-05 23:40:21 +00:00
|
|
|
iter->v_poin = &array[v_init];
|
|
|
|
|
iter->v_other = iter->v_poin->v[dir];
|
|
|
|
|
iter->e = iter->v_poin->e[!dir];
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-12-12 18:19:32 -06:00
|
|
|
iter->v_poin = nullptr;
|
|
|
|
|
iter->e = nullptr;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2018-06-17 17:04:27 +02:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-08-05 23:40:21 +00:00
|
|
|
static void screwvert_iter_step(ScrewVertIter *iter)
|
|
|
|
|
{
|
|
|
|
|
if (iter->v_poin->v[0] == iter->v_other) {
|
2012-05-06 13:38:33 +00:00
|
|
|
iter->v_other = iter->v;
|
|
|
|
|
iter->v = iter->v_poin->v[1];
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2010-08-05 23:40:21 +00:00
|
|
|
else if (iter->v_poin->v[1] == iter->v_other) {
|
2012-05-06 13:38:33 +00:00
|
|
|
iter->v_other = iter->v;
|
|
|
|
|
iter->v = iter->v_poin->v[0];
|
2010-08-05 23:40:21 +00:00
|
|
|
}
|
2013-11-21 10:35:48 +11:00
|
|
|
if (SV_IS_VALID(iter->v)) {
|
2012-05-06 13:38:33 +00:00
|
|
|
iter->v_poin = &iter->v_array[iter->v];
|
|
|
|
|
iter->e = iter->v_poin->e[(iter->v_poin->e[0] == iter->e)];
|
2010-08-05 23:40:21 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2022-12-12 18:19:32 -06:00
|
|
|
iter->e = nullptr;
|
|
|
|
|
iter->v_poin = nullptr;
|
2010-08-05 23:40:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-11 11:31:21 +02:00
|
|
|
static Mesh *mesh_remove_doubles_on_axis(Mesh *result,
|
2023-06-14 11:59:32 -04:00
|
|
|
blender::MutableSpan<blender::float3> vert_positions_new,
|
2018-05-11 11:31:21 +02:00
|
|
|
const uint totvert,
|
|
|
|
|
const uint step_tot,
|
2017-09-07 00:10:13 +10:00
|
|
|
const float axis_vec[3],
|
|
|
|
|
const float axis_offset[3],
|
|
|
|
|
const float merge_threshold)
|
|
|
|
|
{
|
2022-01-28 22:40:13 -06:00
|
|
|
BLI_bitmap *vert_tag = BLI_BITMAP_NEW(totvert, __func__);
|
|
|
|
|
|
2020-03-06 17:18:10 +01:00
|
|
|
const float merge_threshold_sq = square_f(merge_threshold);
|
2022-12-12 18:19:32 -06:00
|
|
|
const bool use_offset = axis_offset != nullptr;
|
2017-09-07 00:10:13 +10:00
|
|
|
uint tot_doubles = 0;
|
|
|
|
|
for (uint i = 0; i < totvert; i += 1) {
|
|
|
|
|
float axis_co[3];
|
|
|
|
|
if (use_offset) {
|
|
|
|
|
float offset_co[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
|
|
|
sub_v3_v3v3(offset_co, vert_positions_new[i], axis_offset);
|
2017-09-07 00:10:13 +10:00
|
|
|
project_v3_v3v3_normalized(axis_co, offset_co, axis_vec);
|
|
|
|
|
add_v3_v3(axis_co, axis_offset);
|
|
|
|
|
}
|
|
|
|
|
else {
|
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
|
|
|
project_v3_v3v3_normalized(axis_co, vert_positions_new[i], axis_vec);
|
2017-09-07 00:10:13 +10: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 float dist_sq = len_squared_v3v3(axis_co, vert_positions_new[i]);
|
2017-09-07 00:10:13 +10:00
|
|
|
if (dist_sq <= merge_threshold_sq) {
|
2022-01-28 22:40:13 -06:00
|
|
|
BLI_BITMAP_ENABLE(vert_tag, i);
|
2017-09-07 00:10:13 +10:00
|
|
|
tot_doubles += 1;
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
copy_v3_v3(vert_positions_new[i], axis_co);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2017-09-07 00:10:13 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-09-07 00:10:13 +10:00
|
|
|
if (tot_doubles != 0) {
|
|
|
|
|
uint tot = totvert * step_tot;
|
2022-12-12 18:19:32 -06:00
|
|
|
int *full_doubles_map = static_cast<int *>(MEM_malloc_arrayN(tot, sizeof(int), __func__));
|
|
|
|
|
copy_vn_i(full_doubles_map, int(tot), -1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-09-07 00:10:13 +10:00
|
|
|
uint tot_doubles_left = tot_doubles;
|
|
|
|
|
for (uint i = 0; i < totvert; i += 1) {
|
2022-01-28 22:40:13 -06:00
|
|
|
if (BLI_BITMAP_TEST(vert_tag, i)) {
|
2017-09-07 00:10:13 +10:00
|
|
|
int *doubles_map = &full_doubles_map[totvert + i];
|
|
|
|
|
for (uint step = 1; step < step_tot; step += 1) {
|
2022-12-12 18:19:32 -06:00
|
|
|
*doubles_map = int(i);
|
2017-09-07 00:10:13 +10:00
|
|
|
doubles_map += totvert;
|
|
|
|
|
}
|
|
|
|
|
tot_doubles_left -= 1;
|
|
|
|
|
if (tot_doubles_left == 0) {
|
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2017-09-07 00:10:13 +10:00
|
|
|
}
|
|
|
|
|
}
|
2023-02-23 19:10:01 +01:00
|
|
|
|
|
|
|
|
Mesh *tmp = result;
|
|
|
|
|
|
|
|
|
|
/* TODO(mano-wii): Polygons with all vertices merged are the ones that form duplicates.
|
2023-07-24 22:06:55 +02:00
|
|
|
* Therefore the duplicate face test can be skipped. */
|
2023-02-23 19:10:01 +01:00
|
|
|
result = geometry::mesh_merge_verts(*tmp,
|
2023-12-20 02:21:48 +01:00
|
|
|
MutableSpan<int>{full_doubles_map, result->verts_num},
|
2023-07-06 15:05:33 +02:00
|
|
|
int(tot_doubles * (step_tot - 1)),
|
|
|
|
|
false);
|
2023-02-23 19:10:01 +01:00
|
|
|
|
2023-02-27 21:32:34 +11:00
|
|
|
BKE_id_free(nullptr, tmp);
|
2017-09-07 00:10:13 +10:00
|
|
|
MEM_freeN(full_doubles_map);
|
|
|
|
|
}
|
2022-01-28 22:40:13 -06:00
|
|
|
|
|
|
|
|
MEM_freeN(vert_tag);
|
|
|
|
|
|
2017-09-07 00:10:13 +10:00
|
|
|
return result;
|
|
|
|
|
}
|
2010-08-05 23:40:21 +00:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *meshData)
|
2010-04-11 22:12:30 +00: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
|
|
|
using namespace blender;
|
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 Mesh *mesh = meshData;
|
2018-05-11 11:31:21 +02:00
|
|
|
Mesh *result;
|
2012-05-06 13:38:33 +00:00
|
|
|
ScrewModifierData *ltmd = (ScrewModifierData *)md;
|
2018-05-01 17:33:04 +02:00
|
|
|
const bool use_render_params = (ctx->flag & MOD_APPLY_RENDER) != 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
int face_index = 0;
|
2019-09-19 13:32:36 +10:00
|
|
|
uint step;
|
2023-02-23 10:39:51 -05:00
|
|
|
uint j;
|
2019-09-19 13:32:36 +10:00
|
|
|
uint i1, i2;
|
|
|
|
|
uint step_tot = use_render_params ? ltmd->render_steps : ltmd->steps;
|
2015-06-04 15:28:26 +10:00
|
|
|
const bool do_flip = (ltmd->flag & MOD_SCREW_NORMAL_FLIP) != 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:07:24 +11:00
|
|
|
const int quad_ord[4] = {
|
|
|
|
|
do_flip ? 3 : 0,
|
|
|
|
|
do_flip ? 2 : 1,
|
|
|
|
|
do_flip ? 1 : 2,
|
|
|
|
|
do_flip ? 0 : 3,
|
|
|
|
|
};
|
|
|
|
|
const int quad_ord_ofs[4] = {
|
|
|
|
|
do_flip ? 2 : 0,
|
2015-06-04 15:51:49 +10:00
|
|
|
1,
|
2013-11-26 21:07:24 +11:00
|
|
|
do_flip ? 0 : 2,
|
2015-06-04 15:51:49 +10:00
|
|
|
3,
|
2013-11-26 21:07:24 +11:00
|
|
|
};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-09-19 13:32:36 +10:00
|
|
|
uint maxVerts = 0, maxEdges = 0, maxPolys = 0;
|
2023-12-20 02:21:48 +01:00
|
|
|
const uint totvert = uint(mesh->verts_num);
|
|
|
|
|
const uint totedge = uint(mesh->edges_num);
|
2023-07-24 22:06:55 +02:00
|
|
|
const uint faces_num = uint(mesh->faces_num);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
uint *edge_face_map = nullptr; /* orig edge to orig face */
|
2022-12-12 18:19:32 -06:00
|
|
|
uint *vert_loop_map = nullptr; /* orig vert to orig loop */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:22:56 +11:00
|
|
|
/* UV Coords */
|
2023-07-25 15:23:56 -04:00
|
|
|
const uint mloopuv_layers_tot = uint(
|
2023-12-19 20:38:59 -05:00
|
|
|
CustomData_number_of_layers(&mesh->corner_data, CD_PROP_FLOAT2));
|
Mesh: Move UV layers to generic attributes
Currently the `MLoopUV` struct stores UV coordinates and flags related
to editing UV maps in the UV editor. This patch changes the coordinates
to use the generic 2D vector type, and moves the flags into three
separate boolean attributes. This follows the design in T95965, with
the ultimate intention of simplifying code and improving performance.
Importantly, the change allows exporters and renderers to use UVs
"touched" by geometry nodes, which only creates generic attributes.
It also allows geometry nodes to create "proper" UV maps from scratch,
though only with the Store Named Attribute node for now.
The new design considers any 2D vector attribute on the corner domain
to be a UV map. In the future, they might be distinguished from regular
2D vectors with attribute metadata, which may be helpful because they
are often interpolated differently.
Most of the code changes deal with passing around UV BMesh custom data
offsets and tracking the boolean "sublayers". The boolean layers are
use the following prefixes for attribute names: vert selection: `.vs.`,
edge selection: `.es.`, pinning: `.pn.`. Currently these are short to
avoid using up the maximum length of attribute names. To accommodate
for these 4 extra characters, the name length limit is enlarged to 68
bytes, while the maximum user settable name length is still 64 bytes.
Unfortunately Python/RNA API access to the UV flag data becomes slower.
Accessing the boolean layers directly is be better for performance in
general.
Like the other mesh SoA refactors, backward and forward compatibility
aren't affected, and won't be changed until 4.0. We pay for that by
making mesh reading and writing more expensive with conversions.
Resolves T85962
Differential Revision: https://developer.blender.org/D14365
2023-01-10 00:47:04 -05:00
|
|
|
blender::Array<blender::float2 *> mloopuv_layers(mloopuv_layers_tot);
|
2013-11-26 21:22:56 +11:00
|
|
|
float uv_u_scale;
|
|
|
|
|
float uv_v_minmax[2] = {FLT_MAX, -FLT_MAX};
|
2015-09-04 14:24:22 +10:00
|
|
|
float uv_v_range_inv;
|
2013-11-26 21:22:56 +11:00
|
|
|
float uv_axis_plane[4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-21 10:35:48 +11:00
|
|
|
char axis_char = 'X';
|
|
|
|
|
bool close;
|
2012-05-06 13:38:33 +00:00
|
|
|
float angle = ltmd->angle;
|
|
|
|
|
float screw_ofs = ltmd->screw_ofs;
|
|
|
|
|
float axis_vec[3] = {0.0f, 0.0f, 0.0f};
|
2018-06-17 17:04:27 +02:00
|
|
|
float tmp_vec1[3], tmp_vec2[3];
|
2010-04-11 22:12:30 +00:00
|
|
|
float mat3[3][3];
|
2019-01-08 10:28:20 +11:00
|
|
|
/* transform the coords by an object relative to this objects transformation */
|
|
|
|
|
float mtx_tx[4][4];
|
2010-04-11 22:12:30 +00:00
|
|
|
float mtx_tx_inv[4][4]; /* inverted */
|
|
|
|
|
float mtx_tmp_a[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-09-19 13:32:36 +10:00
|
|
|
uint vc_tot_linked = 0;
|
2010-04-11 22:12:30 +00:00
|
|
|
short other_axis_1, other_axis_2;
|
2014-04-27 00:24:11 +10:00
|
|
|
const float *tmpf1, *tmpf2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-09-19 13:32:36 +10:00
|
|
|
uint edge_offset;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
blender::int2 *edge_new, *med_new_firstloop;
|
2019-03-26 11:25:07 +01:00
|
|
|
Object *ob_axis = ltmd->ob_axis;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
ScrewVertConnect *vc, *vc_tmp, *vert_connect = nullptr;
|
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 use_flat_shading = (ltmd->flag & MOD_SCREW_SMOOTH_SHADING) == 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-18 07:38:51 +00:00
|
|
|
/* don't do anything? */
|
2019-04-22 09:15:10 +10:00
|
|
|
if (!totvert) {
|
2023-02-27 11:09:26 -05:00
|
|
|
return BKE_mesh_new_nomain_from_template(mesh, 0, 0, 0, 0);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (ltmd->axis) {
|
2012-05-06 13:38:33 +00:00
|
|
|
case 0:
|
|
|
|
|
other_axis_1 = 1;
|
|
|
|
|
other_axis_2 = 2;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
other_axis_1 = 0;
|
|
|
|
|
other_axis_2 = 2;
|
|
|
|
|
break;
|
|
|
|
|
default: /* 2, use default to quiet warnings */
|
|
|
|
|
other_axis_1 = 0;
|
|
|
|
|
other_axis_2 = 1;
|
|
|
|
|
break;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
axis_vec[ltmd->axis] = 1.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
if (ob_axis != nullptr) {
|
2022-08-12 11:18:00 +10:00
|
|
|
/* Calculate the matrix relative to the axis object. */
|
2024-02-19 15:54:48 +01:00
|
|
|
invert_m4_m4(mtx_tmp_a, ctx->object->object_to_world);
|
|
|
|
|
copy_m4_m4(mtx_tx_inv, ob_axis->object_to_world);
|
2013-05-26 18:36:25 +00:00
|
|
|
mul_m4_m4m4(mtx_tx, mtx_tmp_a, mtx_tx_inv);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-08-12 11:18:00 +10:00
|
|
|
/* Calculate the axis vector. */
|
2010-08-06 00:13:44 +00:00
|
|
|
mul_mat3_m4_v3(mtx_tx, axis_vec); /* only rotation component */
|
2010-04-11 22:12:30 +00:00
|
|
|
normalize_v3(axis_vec);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* screw */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (ltmd->flag & MOD_SCREW_OBJECT_OFFSET) {
|
2022-08-12 11:18:00 +10:00
|
|
|
/* Find the offset along this axis relative to this objects matrix. */
|
2010-04-11 22:12:30 +00:00
|
|
|
float totlen = len_v3(mtx_tx[3]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (totlen != 0.0f) {
|
2020-08-07 22:36:11 +10:00
|
|
|
const float zero[3] = {0.0f, 0.0f, 0.0f};
|
2012-10-21 05:46:41 +00:00
|
|
|
float cp[3];
|
2012-05-06 13:38:33 +00:00
|
|
|
screw_ofs = closest_to_line_v3(cp, mtx_tx[3], zero, axis_vec);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-06 13:38:33 +00:00
|
|
|
screw_ofs = 0.0f;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* angle */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-03 16:49:08 +02:00
|
|
|
#if 0 /* can't include this, not predictable enough, though quite fun. */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (ltmd->flag & MOD_SCREW_OBJECT_ANGLE) {
|
2010-08-06 00:13:44 +00:00
|
|
|
float mtx3_tx[3][3];
|
|
|
|
|
copy_m3_m4(mtx3_tx, mtx_tx);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
float vec[3] = {0, 1, 0};
|
2010-04-11 22:12:30 +00:00
|
|
|
float cross1[3];
|
|
|
|
|
float cross2[3];
|
|
|
|
|
cross_v3_v3v3(cross1, vec, axis_vec);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
mul_v3_m3v3(cross2, mtx3_tx, cross1);
|
|
|
|
|
{
|
|
|
|
|
float c1[3];
|
|
|
|
|
float c2[3];
|
|
|
|
|
float axis_tmp[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
cross_v3_v3v3(c1, cross2, axis_vec);
|
|
|
|
|
cross_v3_v3v3(c2, axis_vec, c1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
angle = angle_v3v3(cross1, c2);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
cross_v3_v3v3(axis_tmp, cross1, c2);
|
|
|
|
|
normalize_v3(axis_tmp);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 23:21:16 +10:00
|
|
|
if (len_v3v3(axis_tmp, axis_vec) > 1.0f) {
|
2012-05-06 13:38:33 +00:00
|
|
|
angle = -angle;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-12-12 18:19:32 -06:00
|
|
|
axis_char = char(axis_char + ltmd->axis); /* 'X' + axis */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-08-12 11:18:00 +10:00
|
|
|
/* Useful to be able to use the axis vector in some cases still. */
|
2010-04-11 22:12:30 +00:00
|
|
|
zero_v3(axis_vec);
|
2012-05-06 13:38:33 +00:00
|
|
|
axis_vec[ltmd->axis] = 1.0f;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* apply the multiplier */
|
2022-12-12 18:19:32 -06:00
|
|
|
angle *= float(ltmd->iter);
|
|
|
|
|
screw_ofs *= float(ltmd->iter);
|
|
|
|
|
uv_u_scale = 1.0f / float(step_tot);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* multiplying the steps is a bit tricky, this works best */
|
2010-08-05 23:40:21 +00:00
|
|
|
step_tot = ((step_tot + 1) * ltmd->iter) - (ltmd->iter - 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-01 07:40:07 +10:00
|
|
|
/* Will the screw be closed?
|
2021-07-03 23:08:40 +10:00
|
|
|
* NOTE: smaller than `FLT_EPSILON * 100`
|
2019-05-01 07:40:07 +10:00
|
|
|
* gives problems with float precision so its never closed. */
|
2012-05-06 13:38:33 +00:00
|
|
|
if (fabsf(screw_ofs) <= (FLT_EPSILON * 100.0f) &&
|
2022-12-12 18:19:32 -06:00
|
|
|
fabsf(fabsf(angle) - (float(M_PI) * 2.0f)) <= (FLT_EPSILON * 100.0f) && step_tot > 3)
|
|
|
|
|
{
|
2022-12-29 12:01:32 -05:00
|
|
|
close = true;
|
2010-08-05 23:40:21 +00:00
|
|
|
step_tot--;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-23 23:22:19 +00:00
|
|
|
maxVerts = totvert * step_tot; /* -1 because we're joining back up */
|
|
|
|
|
maxEdges = (totvert * step_tot) + /* these are the edges between new verts */
|
|
|
|
|
(totedge * step_tot); /* -1 because vert edges join */
|
|
|
|
|
maxPolys = totedge * step_tot;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
screw_ofs = 0.0f;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2022-12-29 12:01:32 -05:00
|
|
|
close = false;
|
2020-03-29 20:23:24 +11:00
|
|
|
if (step_tot < 2) {
|
|
|
|
|
step_tot = 2;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
maxVerts = totvert * step_tot; /* -1 because we're joining back up */
|
|
|
|
|
maxEdges = (totvert * (step_tot - 1)) + /* these are the edges between new verts */
|
|
|
|
|
(totedge * step_tot); /* -1 because vert edges join */
|
|
|
|
|
maxPolys = totedge * (step_tot - 1);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:22:56 +11:00
|
|
|
if ((ltmd->flag & MOD_SCREW_UV_STRETCH_U) == 0) {
|
2022-12-12 18:19:32 -06:00
|
|
|
uv_u_scale = (uv_u_scale / float(ltmd->iter)) * (angle / (float(M_PI) * 2.0f));
|
2013-11-26 21:22:56 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-05-12 19:51:56 +10:00
|
|
|
/* The `screw_ofs` cannot change from now on. */
|
|
|
|
|
const bool do_remove_doubles = (ltmd->flag & MOD_SCREW_MERGE) && (screw_ofs == 0.0f);
|
|
|
|
|
|
2018-05-11 11:31:21 +02:00
|
|
|
result = BKE_mesh_new_nomain_from_template(
|
2023-04-19 15:28:53 -04:00
|
|
|
mesh, int(maxVerts), int(maxEdges), int(maxPolys), int(maxPolys) * 4);
|
2023-02-20 11:51:16 +01:00
|
|
|
/* The modifier doesn't support original index mapping on the edge or face domains. Remove
|
|
|
|
|
* original index layers, since otherwise edges aren't displayed at all in wireframe view. */
|
2023-12-20 02:21:48 +01:00
|
|
|
CustomData_free_layers(&result->edge_data, CD_ORIGINDEX, result->edges_num);
|
|
|
|
|
CustomData_free_layers(&result->face_data, CD_ORIGINDEX, result->edges_num);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-06-14 11:59:32 -04:00
|
|
|
const blender::Span<float3> vert_positions_orig = mesh->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_orig = mesh->edges();
|
2023-07-24 22:06:55 +02:00
|
|
|
const OffsetIndices faces_orig = mesh->faces();
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
const blender::Span<int> corner_verts_orig = mesh->corner_verts();
|
|
|
|
|
const blender::Span<int> corner_edges_orig = mesh->corner_edges();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-06-14 11:59:32 -04:00
|
|
|
blender::MutableSpan<float3> vert_positions_new = result->vert_positions_for_write();
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
blender::MutableSpan<int2> edges_new = result->edges_for_write();
|
2023-07-24 22:06:55 +02:00
|
|
|
MutableSpan<int> face_offests_new = result->face_offsets_for_write();
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
blender::MutableSpan<int> corner_verts_new = result->corner_verts_for_write();
|
|
|
|
|
blender::MutableSpan<int> corner_edges_new = result->corner_edges_for_write();
|
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
|
|
|
bke::MutableAttributeAccessor attributes = result->attributes_for_write();
|
|
|
|
|
bke::SpanAttributeWriter<bool> sharp_faces = attributes.lookup_or_add_for_write_span<bool>(
|
2023-12-20 13:13:16 -05:00
|
|
|
"sharp_face", bke::AttrDomain::Face);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-25 21:15:52 +02:00
|
|
|
if (!CustomData_has_layer(&result->face_data, CD_ORIGINDEX)) {
|
|
|
|
|
CustomData_add_layer(&result->face_data, CD_ORIGINDEX, CD_SET_DEFAULT, int(maxPolys));
|
2012-01-04 20:11:08 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-13 17:21:20 -06:00
|
|
|
int *origindex = static_cast<int *>(
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_get_layer_for_write(&result->face_data, CD_ORIGINDEX, result->faces_num));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_copy_data(&mesh->vert_data, &result->vert_data, 0, 0, int(totvert));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:22:56 +11:00
|
|
|
if (mloopuv_layers_tot) {
|
2020-08-07 22:36:11 +10:00
|
|
|
const float zero_co[3] = {0};
|
2013-11-26 21:22:56 +11:00
|
|
|
plane_from_point_normal_v3(uv_axis_plane, zero_co, axis_vec);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:22:56 +11:00
|
|
|
if (mloopuv_layers_tot) {
|
2019-09-19 13:32:36 +10:00
|
|
|
uint uv_lay;
|
2013-11-26 21:22:56 +11:00
|
|
|
for (uv_lay = 0; uv_lay < mloopuv_layers_tot; uv_lay++) {
|
2023-01-13 17:21:20 -06:00
|
|
|
mloopuv_layers[uv_lay] = static_cast<blender::float2 *>(CustomData_get_layer_n_for_write(
|
2023-12-19 20:38:59 -05:00
|
|
|
&result->corner_data, CD_PROP_FLOAT2, int(uv_lay), result->corners_num));
|
2013-11-26 21:22:56 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:22:56 +11:00
|
|
|
if (ltmd->flag & MOD_SCREW_UV_STRETCH_V) {
|
2023-02-23 10:39:51 -05:00
|
|
|
for (uint i = 0; i < totvert; i++) {
|
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 float v = dist_signed_squared_to_plane_v3(vert_positions_orig[i], uv_axis_plane);
|
2013-11-26 21:22:56 +11:00
|
|
|
uv_v_minmax[0] = min_ff(v, uv_v_minmax[0]);
|
|
|
|
|
uv_v_minmax[1] = max_ff(v, uv_v_minmax[1]);
|
|
|
|
|
}
|
|
|
|
|
uv_v_minmax[0] = sqrtf_signed(uv_v_minmax[0]);
|
|
|
|
|
uv_v_minmax[1] = sqrtf_signed(uv_v_minmax[1]);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:22:56 +11:00
|
|
|
uv_v_range_inv = uv_v_minmax[1] - uv_v_minmax[0];
|
|
|
|
|
uv_v_range_inv = uv_v_range_inv ? 1.0f / uv_v_range_inv : 0.0f;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* Set the locations of the first set of verts */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* Copy the first set of edges */
|
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::int2 *edge_orig = edges_orig.data();
|
2023-03-01 15:57:50 -05:00
|
|
|
edge_new = edges_new.data();
|
|
|
|
|
for (uint i = 0; i < totedge; i++, edge_orig++, edge_new++) {
|
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
|
|
|
*edge_new = *edge_orig;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
/* build face -> edge map */
|
|
|
|
|
if (faces_num) {
|
2023-04-06 10:22:25 +12:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
edge_face_map = static_cast<uint *>(
|
|
|
|
|
MEM_malloc_arrayN(totedge, sizeof(*edge_face_map), __func__));
|
|
|
|
|
memset(edge_face_map, 0xff, sizeof(*edge_face_map) * totedge);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
vert_loop_map = static_cast<uint *>(
|
|
|
|
|
MEM_malloc_arrayN(totvert, sizeof(*vert_loop_map), __func__));
|
2013-11-26 21:22:56 +11:00
|
|
|
memset(vert_loop_map, 0xff, sizeof(*vert_loop_map) * totvert);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
for (const int64_t i : faces_orig.index_range()) {
|
|
|
|
|
for (const int64_t corner : faces_orig[i]) {
|
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 int vert_i = corner_verts_orig[corner];
|
|
|
|
|
const int edge_i = corner_edges_orig[corner];
|
2023-07-24 22:06:55 +02:00
|
|
|
edge_face_map[edge_i] = uint(i);
|
Mesh: Replace MPoly struct with offset indices
Implements #95967.
Currently the `MPoly` struct is 12 bytes, and stores the index of a
face's first corner and the number of corners/verts/edges. Polygons
and corners are always created in order by Blender, meaning each
face's corners will be after the previous face's corners. We can take
advantage of this fact and eliminate the redundancy in mesh face
storage by only storing a single integer corner offset for each face.
The size of the face is then encoded by the offset of the next face.
The size of a single integer is 4 bytes, so this reduces memory
usage by 3 times.
The same method is used for `CurvesGeometry`, so Blender already has
an abstraction to simplify using these offsets called `OffsetIndices`.
This class is used to easily retrieve a range of corner indices for
each face. This also gives the opportunity for sharing some logic with
curves.
Another benefit of the change is that the offsets and sizes stored in
`MPoly` can no longer disagree with each other. Storing faces in the
order of their corners can simplify some code too.
Face/polygon variables now use the `IndexRange` type, which comes with
quite a few utilities that can simplify code.
Some:
- The offset integer array has to be one longer than the face count to
avoid a branch for every face, which means the data is no longer part
of the mesh's `CustomData`.
- We lose the ability to "reference" an original mesh's offset array
until more reusable CoW from #104478 is committed. That will be added
in a separate commit.
- Since they aren't part of `CustomData`, poly offsets often have to be
copied manually.
- To simplify using `OffsetIndices` in many places, some functions and
structs in headers were moved to only compile in C++.
- All meshes created by Blender use the same order for faces and face
corners, but just in case, meshes with mismatched order are fixed by
versioning code.
- `MeshPolygon.totloop` is no longer editable in RNA. This API break is
necessary here unfortunately. It should be worth it in 3.6, since
that's the best way to allow loading meshes from 4.0, which is
important for an LTS version.
Pull Request: https://projects.blender.org/blender/blender/pulls/105938
2023-04-04 20:39:28 +02:00
|
|
|
vert_loop_map[vert_i] = uint(corner);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-19 13:11:31 +11:00
|
|
|
/* also order edges based on faces */
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
if (edges_new[edge_i][0] != vert_i) {
|
|
|
|
|
std::swap(edges_new[edge_i][0], edges_new[edge_i][1]);
|
2013-11-19 13:11:31 +11:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (ltmd->flag & MOD_SCREW_NORMAL_CALC) {
|
2022-05-12 19:51:56 +10:00
|
|
|
|
2022-08-12 11:18:00 +10:00
|
|
|
/* Normal Calculation (for face flipping)
|
2010-04-11 22:12:30 +00:00
|
|
|
* Sort edge verts for correct face flipping
|
2021-01-20 15:15:38 +11:00
|
|
|
* NOT REALLY NEEDED but face flipping is nice. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
vert_connect = static_cast<ScrewVertConnect *>(
|
|
|
|
|
MEM_malloc_arrayN(totvert, sizeof(ScrewVertConnect), __func__));
|
2019-05-01 07:40:07 +10:00
|
|
|
/* skip the first slice of verts. */
|
|
|
|
|
// vert_connect = (ScrewVertConnect *) &medge_new[totvert];
|
2012-05-06 13:38:33 +00:00
|
|
|
vc = vert_connect;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* Copy Vert Locations */
|
2022-09-26 17:59:44 -05:00
|
|
|
if (totedge != 0) {
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("\n\n\n\n\nStarting Modifier\n");
|
2010-04-11 22:12:30 +00:00
|
|
|
/* set edge users */
|
2023-03-01 15:57:50 -05:00
|
|
|
edge_new = edges_new.data();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
if (ob_axis != nullptr) {
|
2022-04-13 13:46:22 +10:00
|
|
|
/* `mtx_tx` is initialized early on. */
|
2023-02-23 10:39:51 -05:00
|
|
|
for (uint i = 0; i < totvert; i++, vc++) {
|
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
|
|
|
vc->co[0] = vert_positions_new[i][0] = vert_positions_orig[i][0];
|
|
|
|
|
vc->co[1] = vert_positions_new[i][1] = vert_positions_orig[i][1];
|
|
|
|
|
vc->co[2] = vert_positions_new[i][2] = vert_positions_orig[i][2];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
vc->flag = 0;
|
2022-12-12 18:19:32 -06:00
|
|
|
vc->e[0] = vc->e[1] = nullptr;
|
2013-11-21 10:35:48 +11:00
|
|
|
vc->v[0] = vc->v[1] = SV_UNUSED;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
mul_m4_v3(mtx_tx, vc->co);
|
2022-08-12 11:18:00 +10:00
|
|
|
/* Length in 2D, don't `sqrt` because this is only for comparison. */
|
|
|
|
|
vc->dist_sq = vc->co[other_axis_1] * vc->co[other_axis_1] +
|
|
|
|
|
vc->co[other_axis_2] * vc->co[other_axis_2];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-08-12 11:18:00 +10:00
|
|
|
// printf("location %f %f %f -- %f\n", vc->co[0], vc->co[1], vc->co[2], vc->dist_sq);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
else {
|
2023-02-23 10:39:51 -05:00
|
|
|
for (uint i = 0; i < totvert; i++, vc++) {
|
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
|
|
|
vc->co[0] = vert_positions_new[i][0] = vert_positions_orig[i][0];
|
|
|
|
|
vc->co[1] = vert_positions_new[i][1] = vert_positions_orig[i][1];
|
|
|
|
|
vc->co[2] = vert_positions_new[i][2] = vert_positions_orig[i][2];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
vc->flag = 0;
|
2022-12-12 18:19:32 -06:00
|
|
|
vc->e[0] = vc->e[1] = nullptr;
|
2013-11-21 10:35:48 +11:00
|
|
|
vc->v[0] = vc->v[1] = SV_UNUSED;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-03 08:56:59 +10:00
|
|
|
/* Length in 2D, don't `sqrt` because this is only for comparison. */
|
2022-08-12 11:18:00 +10:00
|
|
|
vc->dist_sq = vc->co[other_axis_1] * vc->co[other_axis_1] +
|
|
|
|
|
vc->co[other_axis_2] * vc->co[other_axis_2];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-08-12 11:18:00 +10:00
|
|
|
// printf("location %f %f %f -- %f\n", vc->co[0], vc->co[1], vc->co[2], vc->dist_sq);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* this loop builds connectivity info for verts */
|
2023-03-01 15:57:50 -05:00
|
|
|
for (uint i = 0; i < totedge; i++, edge_new++) {
|
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
|
|
|
vc = &vert_connect[(*edge_new)[0]];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-21 10:35:48 +11:00
|
|
|
if (vc->v[0] == SV_UNUSED) { /* unused */
|
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
|
|
|
vc->v[0] = uint((*edge_new)[1]);
|
2023-03-01 15:57:50 -05:00
|
|
|
vc->e[0] = edge_new;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2013-11-21 10:35:48 +11:00
|
|
|
else if (vc->v[1] == SV_UNUSED) {
|
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
|
|
|
vc->v[1] = uint((*edge_new)[1]);
|
2023-03-01 15:57:50 -05:00
|
|
|
vc->e[1] = edge_new;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-11-21 10:35:48 +11:00
|
|
|
vc->v[0] = vc->v[1] = SV_INVALID; /* error value - don't use, 3 edges on vert */
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
vc = &vert_connect[(*edge_new)[1]];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* same as above but swap v1/2 */
|
2013-11-21 10:35:48 +11:00
|
|
|
if (vc->v[0] == SV_UNUSED) { /* unused */
|
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
|
|
|
vc->v[0] = uint((*edge_new)[0]);
|
2023-03-01 15:57:50 -05:00
|
|
|
vc->e[0] = edge_new;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2013-11-21 10:35:48 +11:00
|
|
|
else if (vc->v[1] == SV_UNUSED) {
|
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
|
|
|
vc->v[1] = uint((*edge_new)[0]);
|
2023-03-01 15:57:50 -05:00
|
|
|
vc->e[1] = edge_new;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-11-21 10:35:48 +11:00
|
|
|
vc->v[0] = vc->v[1] = SV_INVALID; /* error value - don't use, 3 edges on vert */
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* find the first vert */
|
2012-05-06 13:38:33 +00:00
|
|
|
vc = vert_connect;
|
2023-02-23 10:39:51 -05:00
|
|
|
for (uint i = 0; i < totvert; i++, vc++) {
|
2010-04-11 22:12:30 +00:00
|
|
|
/* Now do search for connected verts, order all edges and flip them
|
|
|
|
|
* so resulting faces are flipped the right way */
|
2012-05-06 13:38:33 +00:00
|
|
|
vc_tot_linked = 0; /* count the number of linked verts for this loop */
|
2010-08-05 23:40:21 +00:00
|
|
|
if (vc->flag == 0) {
|
2019-09-19 13:32:36 +10:00
|
|
|
uint v_best = SV_UNUSED, ed_loop_closed = 0; /* vert and vert new */
|
2011-02-13 03:21:27 +00:00
|
|
|
ScrewVertIter lt_iter;
|
2012-05-06 13:38:33 +00:00
|
|
|
float fl = -1.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
/* compiler complains if not initialized, but it should be initialized below */
|
2013-11-21 10:35:48 +11:00
|
|
|
bool ed_loop_flip = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("Loop on connected vert: %i\n", i);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
for (j = 0; j < 2; j++) {
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("\tSide: %i\n", j);
|
2010-08-05 23:40:21 +00:00
|
|
|
screwvert_iter_init(<_iter, vert_connect, i, j);
|
|
|
|
|
if (j == 1) {
|
|
|
|
|
screwvert_iter_step(<_iter);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
while (lt_iter.v_poin) {
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("\t\tVERT: %i\n", lt_iter.v);
|
2010-04-11 22:12:30 +00:00
|
|
|
if (lt_iter.v_poin->flag) {
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("\t\t\tBreaking Found end\n");
|
2019-05-01 07:40:07 +10:00
|
|
|
// endpoints[0] = endpoints[1] = SV_UNUSED;
|
2012-05-06 13:38:33 +00:00
|
|
|
ed_loop_closed = 1; /* circle */
|
2010-04-11 22:12:30 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2012-05-06 13:38:33 +00:00
|
|
|
lt_iter.v_poin->flag = 1;
|
2010-04-11 22:12:30 +00:00
|
|
|
vc_tot_linked++;
|
2022-08-12 11:18:00 +10:00
|
|
|
// printf("Testing 2 floats %f : %f\n", fl, lt_iter.v_poin->dist_sq);
|
|
|
|
|
if (fl <= lt_iter.v_poin->dist_sq) {
|
|
|
|
|
fl = lt_iter.v_poin->dist_sq;
|
2012-05-06 13:38:33 +00:00
|
|
|
v_best = lt_iter.v;
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("\t\t\tVERT BEST: %i\n", v_best);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2010-08-05 23:40:21 +00:00
|
|
|
screwvert_iter_step(<_iter);
|
2010-04-11 22:12:30 +00:00
|
|
|
if (!lt_iter.v_poin) {
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("\t\t\tFound End Also Num %i\n", j);
|
|
|
|
|
// endpoints[j] = lt_iter.v_other; /* other is still valid */
|
2010-04-11 22:12:30 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-26 21:35:18 +10:00
|
|
|
/* Now we have a collection of used edges. flip their edges the right way. */
|
|
|
|
|
/* if (v_best != SV_UNUSED) - */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("Done Looking - vc_tot_linked: %i\n", vc_tot_linked);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
if (vc_tot_linked > 1) {
|
2010-04-11 22:12:30 +00:00
|
|
|
float vf_1, vf_2, vf_best;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
vc_tmp = &vert_connect[v_best];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
tmpf1 = vert_connect[vc_tmp->v[0]].co;
|
|
|
|
|
tmpf2 = vert_connect[vc_tmp->v[1]].co;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* edge connects on each side! */
|
2013-11-21 10:35:48 +11:00
|
|
|
if (SV_IS_VALID(vc_tmp->v[0]) && SV_IS_VALID(vc_tmp->v[1])) {
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("Verts on each side (%i %i)\n", vc_tmp->v[0], vc_tmp->v[1]);
|
|
|
|
|
/* Find out which is higher. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
vf_1 = tmpf1[ltmd->axis];
|
|
|
|
|
vf_2 = tmpf2[ltmd->axis];
|
|
|
|
|
vf_best = vc_tmp->co[ltmd->axis];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
if (vf_1 < vf_best && vf_best < vf_2) {
|
2022-12-29 12:01:32 -05:00
|
|
|
ed_loop_flip = false;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
else if (vf_1 > vf_best && vf_best > vf_2) {
|
2022-12-29 12:01:32 -05:00
|
|
|
ed_loop_flip = true;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* not so simple to work out which edge is higher */
|
|
|
|
|
sub_v3_v3v3(tmp_vec1, tmpf1, vc_tmp->co);
|
2010-08-06 00:13:44 +00:00
|
|
|
sub_v3_v3v3(tmp_vec2, tmpf2, vc_tmp->co);
|
2010-04-11 22:12:30 +00:00
|
|
|
normalize_v3(tmp_vec1);
|
|
|
|
|
normalize_v3(tmp_vec2);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
if (tmp_vec1[ltmd->axis] < tmp_vec2[ltmd->axis]) {
|
2022-12-29 12:01:32 -05:00
|
|
|
ed_loop_flip = true;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2022-12-29 12:01:32 -05:00
|
|
|
ed_loop_flip = false;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2021-06-26 21:35:18 +10:00
|
|
|
else if (SV_IS_VALID(vc_tmp->v[0])) { /* Vertex only connected on 1 side. */
|
|
|
|
|
// printf("Verts on ONE side (%i %i)\n", vc_tmp->v[0], vc_tmp->v[1]);
|
2010-04-11 22:12:30 +00:00
|
|
|
if (tmpf1[ltmd->axis] < vc_tmp->co[ltmd->axis]) { /* best is above */
|
2022-12-29 12:01:32 -05:00
|
|
|
ed_loop_flip = true;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2018-09-03 16:49:08 +02:00
|
|
|
else { /* best is below or even... in even case we can't know what to do. */
|
2022-12-29 12:01:32 -05:00
|
|
|
ed_loop_flip = false;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2012-03-09 18:28:30 +00:00
|
|
|
}
|
|
|
|
|
#if 0
|
|
|
|
|
else {
|
2010-04-11 22:12:30 +00:00
|
|
|
printf("No Connected ___\n");
|
2012-03-09 18:28:30 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("flip direction %i\n", ed_loop_flip);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2020-12-11 14:51:43 +11:00
|
|
|
/* Switch the flip option if set
|
|
|
|
|
* NOTE: flip is now done at face level so copying group slices is easier. */
|
2012-03-09 18:28:30 +00:00
|
|
|
#if 0
|
2019-05-31 23:21:16 +10:00
|
|
|
if (do_flip) {
|
2012-05-06 13:38:33 +00:00
|
|
|
ed_loop_flip = !ed_loop_flip;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2012-03-09 18:28:30 +00:00
|
|
|
#endif
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (angle < 0.0f) {
|
2012-05-06 13:38:33 +00:00
|
|
|
ed_loop_flip = !ed_loop_flip;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* if its closed, we only need 1 loop */
|
2012-05-06 13:38:33 +00:00
|
|
|
for (j = ed_loop_closed; j < 2; j++) {
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("Ordering Side J %i\n", j);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-08-05 23:40:21 +00:00
|
|
|
screwvert_iter_init(<_iter, vert_connect, v_best, j);
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("\n\nStarting - Loop\n");
|
2012-05-06 13:38:33 +00:00
|
|
|
lt_iter.v_poin->flag = 1; /* so a non loop will traverse the other side */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* If this is the vert off the best vert and
|
|
|
|
|
* the best vert has 2 edges connected too it
|
|
|
|
|
* then swap the flip direction */
|
2019-04-22 09:15:10 +10:00
|
|
|
if (j == 1 && SV_IS_VALID(vc_tmp->v[0]) && SV_IS_VALID(vc_tmp->v[1])) {
|
2012-05-06 13:38:33 +00:00
|
|
|
ed_loop_flip = !ed_loop_flip;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
while (lt_iter.v_poin && lt_iter.v_poin->flag != 2) {
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("\tOrdering Vert V %i\n", lt_iter.v);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
lt_iter.v_poin->flag = 2;
|
2010-04-11 22:12:30 +00:00
|
|
|
if (lt_iter.e) {
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
if (lt_iter.v == uint((*lt_iter.e)[0])) {
|
2010-08-05 23:40:21 +00:00
|
|
|
if (ed_loop_flip == 0) {
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("\t\t\tFlipping 0\n");
|
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
|
|
|
std::swap((*lt_iter.e)[0], (*lt_iter.e)[1]);
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
2019-04-18 07:21:26 +02:00
|
|
|
#if 0
|
|
|
|
|
else {
|
|
|
|
|
printf("\t\t\tFlipping Not 0\n");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
else if (lt_iter.v == uint((*lt_iter.e)[1])) {
|
2010-08-05 23:40:21 +00:00
|
|
|
if (ed_loop_flip == 1) {
|
2021-06-26 21:35:18 +10:00
|
|
|
// printf("\t\t\tFlipping 1\n");
|
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
|
|
|
std::swap((*lt_iter.e)[0], (*lt_iter.e)[1]);
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
2019-04-18 07:21:26 +02:00
|
|
|
#if 0
|
|
|
|
|
else {
|
|
|
|
|
printf("\t\t\tFlipping Not 1\n");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
2019-04-18 07:21:26 +02:00
|
|
|
#if 0
|
|
|
|
|
else {
|
|
|
|
|
printf("\t\tIncorrect edge topology");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#if 0
|
|
|
|
|
else {
|
|
|
|
|
printf("\t\tNo Edge at this point\n");
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
2019-04-18 07:21:26 +02:00
|
|
|
#endif
|
2010-08-05 23:40:21 +00:00
|
|
|
screwvert_iter_step(<_iter);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2023-02-23 10:39:51 -05:00
|
|
|
for (uint i = 0; i < totvert; i++) {
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
copy_v3_v3(vert_positions_new[i], vert_positions_orig[i]);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
/* done with edge connectivity based normal flipping */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* Add Faces */
|
2012-05-06 13:38:33 +00:00
|
|
|
for (step = 1; step < step_tot; step++) {
|
2019-09-19 13:32:36 +10:00
|
|
|
const uint varray_stride = totvert * step;
|
2010-04-11 22:12:30 +00:00
|
|
|
float step_angle;
|
2010-11-28 06:03:30 +00:00
|
|
|
float mat[4][4];
|
2010-04-11 22:12:30 +00:00
|
|
|
/* Rotation Matrix */
|
2022-12-12 18:19:32 -06:00
|
|
|
step_angle = (angle / float(step_tot - (!close))) * float(step);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
if (ob_axis != nullptr) {
|
2013-04-15 15:16:11 +00:00
|
|
|
axis_angle_normalized_to_mat3(mat3, axis_vec, step_angle);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2016-11-25 16:20:30 +11:00
|
|
|
axis_angle_to_mat3_single(mat3, axis_char, step_angle);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2016-11-25 16:20:30 +11:00
|
|
|
copy_m4_m3(mat, mat3);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (screw_ofs) {
|
2022-12-12 18:19:32 -06:00
|
|
|
madd_v3_v3fl(mat[3], axis_vec, screw_ofs * (float(step) / float(step_tot - 1)));
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-08-05 23:40:21 +00:00
|
|
|
/* copy a slice */
|
2023-07-25 15:23:56 -04:00
|
|
|
CustomData_copy_data(
|
|
|
|
|
&mesh->vert_data, &result->vert_data, 0, int(varray_stride), int(totvert));
|
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
|
|
|
/* set location */
|
|
|
|
|
for (j = 0; j < totvert; j++) {
|
|
|
|
|
const int vert_new = int(varray_stride) + int(j);
|
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
|
|
|
copy_v3_v3(vert_positions_new[vert_new], vert_positions_new[j]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* only need to set these if using non cleared memory */
|
2022-04-13 13:46:22 +10:00
|
|
|
// mv_new->mat_nr = mv_new->flag = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
if (ob_axis != nullptr) {
|
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
|
|
|
sub_v3_v3(vert_positions_new[vert_new], mtx_tx[3]);
|
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
|
|
|
mul_m4_v3(mat, vert_positions_new[vert_new]);
|
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
|
|
|
add_v3_v3(vert_positions_new[vert_new], mtx_tx[3]);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
else {
|
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
|
|
|
mul_m4_v3(mat, vert_positions_new[vert_new]);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* add the new edge */
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
(*edge_new)[0] = int(varray_stride + j);
|
|
|
|
|
(*edge_new)[1] = (*edge_new)[0] - int(totvert);
|
2023-03-01 15:57:50 -05:00
|
|
|
edge_new++;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* we can avoid if using vert alloc trick */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (vert_connect) {
|
2010-04-11 22:12:30 +00:00
|
|
|
MEM_freeN(vert_connect);
|
2022-12-12 18:19:32 -06:00
|
|
|
vert_connect = nullptr;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
if (close) {
|
2018-09-03 16:49:08 +02:00
|
|
|
/* last loop of edges, previous loop doesn't account for the last set of edges */
|
2019-09-19 13:32:36 +10:00
|
|
|
const uint varray_stride = (step_tot - 1) * totvert;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-02-23 10:39:51 -05:00
|
|
|
for (uint i = 0; i < totvert; i++) {
|
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
|
|
|
(*edge_new)[0] = int(i);
|
|
|
|
|
(*edge_new)[1] = int(varray_stride + i);
|
2023-03-01 15:57:50 -05:00
|
|
|
edge_new++;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-04-11 22:12:30 +00: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
|
|
|
int new_loop_index = 0;
|
2023-02-23 10:39:51 -05:00
|
|
|
med_new_firstloop = edges_new.data();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-04 20:11:08 +00:00
|
|
|
/* more of an offset in this case */
|
|
|
|
|
edge_offset = totedge + (totvert * (step_tot - (close ? 0 : 1)));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-12-12 20:45:16 -05:00
|
|
|
const bke::AttributeAccessor src_attributes = mesh->attributes();
|
|
|
|
|
const VArraySpan src_material_index = *src_attributes.lookup<int>("material_index",
|
2023-12-20 13:13:16 -05:00
|
|
|
bke::AttrDomain::Face);
|
2023-12-12 20:45:16 -05:00
|
|
|
|
|
|
|
|
bke::MutableAttributeAccessor dst_attributes = result->attributes_for_write();
|
|
|
|
|
bke::SpanAttributeWriter dst_material_index = dst_attributes.lookup_or_add_for_write_span<int>(
|
2023-12-20 13:13:16 -05:00
|
|
|
"material_index", bke::AttrDomain::Face);
|
2022-08-31 09:09:01 -05:00
|
|
|
|
2023-02-23 10:39:51 -05:00
|
|
|
for (uint i = 0; i < totedge; i++, med_new_firstloop++) {
|
2019-09-19 13:32:36 +10:00
|
|
|
const uint step_last = step_tot - (close ? 1 : 2);
|
2023-07-24 22:06:55 +02:00
|
|
|
const uint face_index_orig = faces_num ? edge_face_map[i] : UINT_MAX;
|
|
|
|
|
const bool has_mpoly_orig = (face_index_orig != UINT_MAX);
|
2015-09-04 14:24:22 +10:00
|
|
|
float uv_v_offset_a, uv_v_offset_b;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-09-19 13:32:36 +10:00
|
|
|
const uint mloop_index_orig[2] = {
|
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
|
|
|
vert_loop_map ? vert_loop_map[edges_new[i][0]] : UINT_MAX,
|
|
|
|
|
vert_loop_map ? vert_loop_map[edges_new[i][1]] : UINT_MAX,
|
2013-11-26 21:22:56 +11:00
|
|
|
};
|
|
|
|
|
const bool has_mloop_orig = mloop_index_orig[0] != UINT_MAX;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-08-31 09:09:01 -05:00
|
|
|
int mat_nr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* for each edge, make a cylinder of quads */
|
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
|
|
|
i1 = uint((*med_new_firstloop)[0]);
|
|
|
|
|
i2 = uint((*med_new_firstloop)[1]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:07:24 +11:00
|
|
|
if (has_mpoly_orig) {
|
2023-12-12 20:45:16 -05:00
|
|
|
mat_nr = src_material_index.is_empty() ? 0 : src_material_index[face_index_orig];
|
2013-11-19 13:11:31 +11:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
mat_nr = 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:22:56 +11:00
|
|
|
if (has_mloop_orig == false && mloopuv_layers_tot) {
|
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
|
|
|
uv_v_offset_a = dist_signed_to_plane_v3(vert_positions_new[edges_new[i][0]], uv_axis_plane);
|
|
|
|
|
uv_v_offset_b = dist_signed_to_plane_v3(vert_positions_new[edges_new[i][1]], uv_axis_plane);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:22:56 +11:00
|
|
|
if (ltmd->flag & MOD_SCREW_UV_STRETCH_V) {
|
|
|
|
|
uv_v_offset_a = (uv_v_offset_a - uv_v_minmax[0]) * uv_v_range_inv;
|
|
|
|
|
uv_v_offset_b = (uv_v_offset_b - uv_v_minmax[0]) * uv_v_range_inv;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-11-26 21:22:56 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:07:24 +11:00
|
|
|
for (step = 0; step <= step_last; step++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:07:24 +11:00
|
|
|
/* Polygon */
|
|
|
|
|
if (has_mpoly_orig) {
|
2018-05-11 11:31:21 +02:00
|
|
|
CustomData_copy_data(
|
2023-07-25 21:15:52 +02:00
|
|
|
&mesh->face_data, &result->face_data, int(face_index_orig), int(face_index), 1);
|
2023-07-24 22:06:55 +02:00
|
|
|
origindex[face_index] = int(face_index_orig);
|
2010-08-05 23:40:21 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2023-07-24 22:06:55 +02:00
|
|
|
origindex[face_index] = ORIGINDEX_NONE;
|
2023-12-12 20:45:16 -05:00
|
|
|
dst_material_index.span[face_index] = mat_nr;
|
2023-07-24 22:06:55 +02:00
|
|
|
sharp_faces.span[face_index] = use_flat_shading;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2023-07-24 22:06:55 +02:00
|
|
|
face_offests_new[face_index] = face_index * 4;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:22:56 +11:00
|
|
|
/* Loop-Custom-Data */
|
|
|
|
|
if (has_mloop_orig) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-12-19 20:38:59 -05:00
|
|
|
CustomData_copy_data(&mesh->corner_data,
|
|
|
|
|
&result->corner_data,
|
|
|
|
|
int(mloop_index_orig[0]),
|
|
|
|
|
new_loop_index + 0,
|
|
|
|
|
1);
|
|
|
|
|
CustomData_copy_data(&mesh->corner_data,
|
|
|
|
|
&result->corner_data,
|
|
|
|
|
int(mloop_index_orig[1]),
|
|
|
|
|
new_loop_index + 1,
|
|
|
|
|
1);
|
|
|
|
|
CustomData_copy_data(&mesh->corner_data,
|
|
|
|
|
&result->corner_data,
|
|
|
|
|
int(mloop_index_orig[1]),
|
|
|
|
|
new_loop_index + 2,
|
|
|
|
|
1);
|
|
|
|
|
CustomData_copy_data(&mesh->corner_data,
|
|
|
|
|
&result->corner_data,
|
|
|
|
|
int(mloop_index_orig[0]),
|
|
|
|
|
new_loop_index + 3,
|
|
|
|
|
1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:22:56 +11:00
|
|
|
if (mloopuv_layers_tot) {
|
2019-09-19 13:32:36 +10:00
|
|
|
uint uv_lay;
|
2022-12-12 18:19:32 -06:00
|
|
|
const float uv_u_offset_a = float(step) * uv_u_scale;
|
|
|
|
|
const float uv_u_offset_b = float(step + 1) * uv_u_scale;
|
2013-11-26 21:22:56 +11:00
|
|
|
for (uv_lay = 0; uv_lay < mloopuv_layers_tot; uv_lay++) {
|
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::float2 *mluv = &mloopuv_layers[uv_lay][new_loop_index];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Move UV layers to generic attributes
Currently the `MLoopUV` struct stores UV coordinates and flags related
to editing UV maps in the UV editor. This patch changes the coordinates
to use the generic 2D vector type, and moves the flags into three
separate boolean attributes. This follows the design in T95965, with
the ultimate intention of simplifying code and improving performance.
Importantly, the change allows exporters and renderers to use UVs
"touched" by geometry nodes, which only creates generic attributes.
It also allows geometry nodes to create "proper" UV maps from scratch,
though only with the Store Named Attribute node for now.
The new design considers any 2D vector attribute on the corner domain
to be a UV map. In the future, they might be distinguished from regular
2D vectors with attribute metadata, which may be helpful because they
are often interpolated differently.
Most of the code changes deal with passing around UV BMesh custom data
offsets and tracking the boolean "sublayers". The boolean layers are
use the following prefixes for attribute names: vert selection: `.vs.`,
edge selection: `.es.`, pinning: `.pn.`. Currently these are short to
avoid using up the maximum length of attribute names. To accommodate
for these 4 extra characters, the name length limit is enlarged to 68
bytes, while the maximum user settable name length is still 64 bytes.
Unfortunately Python/RNA API access to the UV flag data becomes slower.
Accessing the boolean layers directly is be better for performance in
general.
Like the other mesh SoA refactors, backward and forward compatibility
aren't affected, and won't be changed until 4.0. We pay for that by
making mesh reading and writing more expensive with conversions.
Resolves T85962
Differential Revision: https://developer.blender.org/D14365
2023-01-10 00:47:04 -05:00
|
|
|
mluv[quad_ord[0]][0] += uv_u_offset_a;
|
|
|
|
|
mluv[quad_ord[1]][0] += uv_u_offset_a;
|
|
|
|
|
mluv[quad_ord[2]][0] += uv_u_offset_b;
|
|
|
|
|
mluv[quad_ord[3]][0] += uv_u_offset_b;
|
2013-11-26 21:22:56 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (mloopuv_layers_tot) {
|
2019-09-19 13:32:36 +10:00
|
|
|
uint uv_lay;
|
2022-12-12 18:19:32 -06:00
|
|
|
const float uv_u_offset_a = float(step) * uv_u_scale;
|
|
|
|
|
const float uv_u_offset_b = float(step + 1) * uv_u_scale;
|
2013-11-26 21:22:56 +11:00
|
|
|
for (uv_lay = 0; uv_lay < mloopuv_layers_tot; uv_lay++) {
|
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::float2 *mluv = &mloopuv_layers[uv_lay][new_loop_index];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Move UV layers to generic attributes
Currently the `MLoopUV` struct stores UV coordinates and flags related
to editing UV maps in the UV editor. This patch changes the coordinates
to use the generic 2D vector type, and moves the flags into three
separate boolean attributes. This follows the design in T95965, with
the ultimate intention of simplifying code and improving performance.
Importantly, the change allows exporters and renderers to use UVs
"touched" by geometry nodes, which only creates generic attributes.
It also allows geometry nodes to create "proper" UV maps from scratch,
though only with the Store Named Attribute node for now.
The new design considers any 2D vector attribute on the corner domain
to be a UV map. In the future, they might be distinguished from regular
2D vectors with attribute metadata, which may be helpful because they
are often interpolated differently.
Most of the code changes deal with passing around UV BMesh custom data
offsets and tracking the boolean "sublayers". The boolean layers are
use the following prefixes for attribute names: vert selection: `.vs.`,
edge selection: `.es.`, pinning: `.pn.`. Currently these are short to
avoid using up the maximum length of attribute names. To accommodate
for these 4 extra characters, the name length limit is enlarged to 68
bytes, while the maximum user settable name length is still 64 bytes.
Unfortunately Python/RNA API access to the UV flag data becomes slower.
Accessing the boolean layers directly is be better for performance in
general.
Like the other mesh SoA refactors, backward and forward compatibility
aren't affected, and won't be changed until 4.0. We pay for that by
making mesh reading and writing more expensive with conversions.
Resolves T85962
Differential Revision: https://developer.blender.org/D14365
2023-01-10 00:47:04 -05:00
|
|
|
copy_v2_fl2(mluv[quad_ord[0]], uv_u_offset_a, uv_v_offset_a);
|
|
|
|
|
copy_v2_fl2(mluv[quad_ord[1]], uv_u_offset_a, uv_v_offset_b);
|
|
|
|
|
copy_v2_fl2(mluv[quad_ord[2]], uv_u_offset_b, uv_v_offset_b);
|
|
|
|
|
copy_v2_fl2(mluv[quad_ord[3]], uv_u_offset_b, uv_v_offset_a);
|
2013-11-26 21:22:56 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:07:24 +11:00
|
|
|
/* Loop-Data */
|
|
|
|
|
if (!(close && step == step_last)) {
|
|
|
|
|
/* regular segments */
|
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_new[new_loop_index + quad_ord[0]] = int(i1);
|
|
|
|
|
corner_verts_new[new_loop_index + quad_ord[1]] = int(i2);
|
|
|
|
|
corner_verts_new[new_loop_index + quad_ord[2]] = int(i2 + totvert);
|
|
|
|
|
corner_verts_new[new_loop_index + quad_ord[3]] = int(i1 + totvert);
|
|
|
|
|
|
|
|
|
|
corner_edges_new[new_loop_index + quad_ord_ofs[0]] = int(
|
|
|
|
|
step == 0 ? i : (edge_offset + step + (i * (step_tot - 1))) - 1);
|
|
|
|
|
corner_edges_new[new_loop_index + quad_ord_ofs[1]] = int(totedge + i2);
|
|
|
|
|
corner_edges_new[new_loop_index + quad_ord_ofs[2]] = int(edge_offset + step +
|
|
|
|
|
(i * (step_tot - 1)));
|
|
|
|
|
corner_edges_new[new_loop_index + quad_ord_ofs[3]] = int(totedge + i1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:07:24 +11:00
|
|
|
/* new vertical edge */
|
|
|
|
|
if (step) { /* The first set is already done */
|
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
|
|
|
(*edge_new)[0] = int(i1);
|
|
|
|
|
(*edge_new)[1] = int(i2);
|
2023-03-01 15:57:50 -05:00
|
|
|
edge_new++;
|
2013-11-26 21:07:24 +11:00
|
|
|
}
|
|
|
|
|
i1 += totvert;
|
|
|
|
|
i2 += totvert;
|
2010-08-05 23:40:21 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-11-26 21:07:24 +11:00
|
|
|
/* last segment */
|
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_new[new_loop_index + quad_ord[0]] = int(i1);
|
|
|
|
|
corner_verts_new[new_loop_index + quad_ord[1]] = int(i2);
|
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
|
|
|
corner_verts_new[new_loop_index + quad_ord[2]] = int((*med_new_firstloop)[1]);
|
|
|
|
|
corner_verts_new[new_loop_index + quad_ord[3]] = int((*med_new_firstloop)[0]);
|
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_edges_new[new_loop_index + quad_ord_ofs[0]] = int(
|
|
|
|
|
(edge_offset + step + (i * (step_tot - 1))) - 1);
|
|
|
|
|
corner_edges_new[new_loop_index + quad_ord_ofs[1]] = int(totedge + i2);
|
|
|
|
|
corner_edges_new[new_loop_index + quad_ord_ofs[2]] = int(i);
|
|
|
|
|
corner_edges_new[new_loop_index + quad_ord_ofs[3]] = int(totedge + i1);
|
2010-08-05 23:40:21 +00: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
|
|
|
new_loop_index += 4;
|
2023-07-24 22:06:55 +02:00
|
|
|
face_index++;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* new vertical edge */
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
(*edge_new)[0] = int(i1);
|
|
|
|
|
(*edge_new)[1] = int(i2);
|
2023-03-01 15:57:50 -05:00
|
|
|
edge_new++;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
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
|
|
|
/* validate loop edges */
|
2012-01-04 20:11:08 +00:00
|
|
|
#if 0
|
|
|
|
|
{
|
2020-02-08 01:02:18 +11:00
|
|
|
uint i = 0;
|
2012-01-04 20:11:08 +00:00
|
|
|
printf("\n");
|
2012-05-06 13:38:33 +00:00
|
|
|
for (; i < maxPolys * 4; i += 4) {
|
2019-09-19 13:32:36 +10:00
|
|
|
uint ii;
|
2012-01-04 20:11:08 +00:00
|
|
|
ml_new = mloop_new + i;
|
Mesh: Replace MPoly struct with offset indices
Implements #95967.
Currently the `MPoly` struct is 12 bytes, and stores the index of a
face's first corner and the number of corners/verts/edges. Polygons
and corners are always created in order by Blender, meaning each
face's corners will be after the previous face's corners. We can take
advantage of this fact and eliminate the redundancy in mesh face
storage by only storing a single integer corner offset for each face.
The size of the face is then encoded by the offset of the next face.
The size of a single integer is 4 bytes, so this reduces memory
usage by 3 times.
The same method is used for `CurvesGeometry`, so Blender already has
an abstraction to simplify using these offsets called `OffsetIndices`.
This class is used to easily retrieve a range of corner indices for
each face. This also gives the opportunity for sharing some logic with
curves.
Another benefit of the change is that the offsets and sizes stored in
`MPoly` can no longer disagree with each other. Storing faces in the
order of their corners can simplify some code too.
Face/polygon variables now use the `IndexRange` type, which comes with
quite a few utilities that can simplify code.
Some:
- The offset integer array has to be one longer than the face count to
avoid a branch for every face, which means the data is no longer part
of the mesh's `CustomData`.
- We lose the ability to "reference" an original mesh's offset array
until more reusable CoW from #104478 is committed. That will be added
in a separate commit.
- Since they aren't part of `CustomData`, poly offsets often have to be
copied manually.
- To simplify using `OffsetIndices` in many places, some functions and
structs in headers were moved to only compile in C++.
- All meshes created by Blender use the same order for faces and face
corners, but just in case, meshes with mismatched order are fixed by
versioning code.
- `MeshPolygon.totloop` is no longer editable in RNA. This API break is
necessary here unfortunately. It should be worth it in 3.6, since
that's the best way to allow loading meshes from 4.0, which is
important for an LTS version.
Pull Request: https://projects.blender.org/blender/blender/pulls/105938
2023-04-04 20:39:28 +02:00
|
|
|
ii = findEd(edges_new, maxEdges, ml_new[0].v, ml_new[1].v);
|
2012-01-04 20:11:08 +00:00
|
|
|
printf("%d %d -- ", ii, ml_new[0].e);
|
|
|
|
|
ml_new[0].e = ii;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Replace MPoly struct with offset indices
Implements #95967.
Currently the `MPoly` struct is 12 bytes, and stores the index of a
face's first corner and the number of corners/verts/edges. Polygons
and corners are always created in order by Blender, meaning each
face's corners will be after the previous face's corners. We can take
advantage of this fact and eliminate the redundancy in mesh face
storage by only storing a single integer corner offset for each face.
The size of the face is then encoded by the offset of the next face.
The size of a single integer is 4 bytes, so this reduces memory
usage by 3 times.
The same method is used for `CurvesGeometry`, so Blender already has
an abstraction to simplify using these offsets called `OffsetIndices`.
This class is used to easily retrieve a range of corner indices for
each face. This also gives the opportunity for sharing some logic with
curves.
Another benefit of the change is that the offsets and sizes stored in
`MPoly` can no longer disagree with each other. Storing faces in the
order of their corners can simplify some code too.
Face/polygon variables now use the `IndexRange` type, which comes with
quite a few utilities that can simplify code.
Some:
- The offset integer array has to be one longer than the face count to
avoid a branch for every face, which means the data is no longer part
of the mesh's `CustomData`.
- We lose the ability to "reference" an original mesh's offset array
until more reusable CoW from #104478 is committed. That will be added
in a separate commit.
- Since they aren't part of `CustomData`, poly offsets often have to be
copied manually.
- To simplify using `OffsetIndices` in many places, some functions and
structs in headers were moved to only compile in C++.
- All meshes created by Blender use the same order for faces and face
corners, but just in case, meshes with mismatched order are fixed by
versioning code.
- `MeshPolygon.totloop` is no longer editable in RNA. This API break is
necessary here unfortunately. It should be worth it in 3.6, since
that's the best way to allow loading meshes from 4.0, which is
important for an LTS version.
Pull Request: https://projects.blender.org/blender/blender/pulls/105938
2023-04-04 20:39:28 +02:00
|
|
|
ii = findEd(edges_new, maxEdges, ml_new[1].v, ml_new[2].v);
|
2012-01-04 20:11:08 +00:00
|
|
|
printf("%d %d -- ", ii, ml_new[1].e);
|
|
|
|
|
ml_new[1].e = ii;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Replace MPoly struct with offset indices
Implements #95967.
Currently the `MPoly` struct is 12 bytes, and stores the index of a
face's first corner and the number of corners/verts/edges. Polygons
and corners are always created in order by Blender, meaning each
face's corners will be after the previous face's corners. We can take
advantage of this fact and eliminate the redundancy in mesh face
storage by only storing a single integer corner offset for each face.
The size of the face is then encoded by the offset of the next face.
The size of a single integer is 4 bytes, so this reduces memory
usage by 3 times.
The same method is used for `CurvesGeometry`, so Blender already has
an abstraction to simplify using these offsets called `OffsetIndices`.
This class is used to easily retrieve a range of corner indices for
each face. This also gives the opportunity for sharing some logic with
curves.
Another benefit of the change is that the offsets and sizes stored in
`MPoly` can no longer disagree with each other. Storing faces in the
order of their corners can simplify some code too.
Face/polygon variables now use the `IndexRange` type, which comes with
quite a few utilities that can simplify code.
Some:
- The offset integer array has to be one longer than the face count to
avoid a branch for every face, which means the data is no longer part
of the mesh's `CustomData`.
- We lose the ability to "reference" an original mesh's offset array
until more reusable CoW from #104478 is committed. That will be added
in a separate commit.
- Since they aren't part of `CustomData`, poly offsets often have to be
copied manually.
- To simplify using `OffsetIndices` in many places, some functions and
structs in headers were moved to only compile in C++.
- All meshes created by Blender use the same order for faces and face
corners, but just in case, meshes with mismatched order are fixed by
versioning code.
- `MeshPolygon.totloop` is no longer editable in RNA. This API break is
necessary here unfortunately. It should be worth it in 3.6, since
that's the best way to allow loading meshes from 4.0, which is
important for an LTS version.
Pull Request: https://projects.blender.org/blender/blender/pulls/105938
2023-04-04 20:39:28 +02:00
|
|
|
ii = findEd(edges_new, maxEdges, ml_new[2].v, ml_new[3].v);
|
2012-01-04 20:11:08 +00:00
|
|
|
printf("%d %d -- ", ii, ml_new[2].e);
|
|
|
|
|
ml_new[2].e = ii;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Replace MPoly struct with offset indices
Implements #95967.
Currently the `MPoly` struct is 12 bytes, and stores the index of a
face's first corner and the number of corners/verts/edges. Polygons
and corners are always created in order by Blender, meaning each
face's corners will be after the previous face's corners. We can take
advantage of this fact and eliminate the redundancy in mesh face
storage by only storing a single integer corner offset for each face.
The size of the face is then encoded by the offset of the next face.
The size of a single integer is 4 bytes, so this reduces memory
usage by 3 times.
The same method is used for `CurvesGeometry`, so Blender already has
an abstraction to simplify using these offsets called `OffsetIndices`.
This class is used to easily retrieve a range of corner indices for
each face. This also gives the opportunity for sharing some logic with
curves.
Another benefit of the change is that the offsets and sizes stored in
`MPoly` can no longer disagree with each other. Storing faces in the
order of their corners can simplify some code too.
Face/polygon variables now use the `IndexRange` type, which comes with
quite a few utilities that can simplify code.
Some:
- The offset integer array has to be one longer than the face count to
avoid a branch for every face, which means the data is no longer part
of the mesh's `CustomData`.
- We lose the ability to "reference" an original mesh's offset array
until more reusable CoW from #104478 is committed. That will be added
in a separate commit.
- Since they aren't part of `CustomData`, poly offsets often have to be
copied manually.
- To simplify using `OffsetIndices` in many places, some functions and
structs in headers were moved to only compile in C++.
- All meshes created by Blender use the same order for faces and face
corners, but just in case, meshes with mismatched order are fixed by
versioning code.
- `MeshPolygon.totloop` is no longer editable in RNA. This API break is
necessary here unfortunately. It should be worth it in 3.6, since
that's the best way to allow loading meshes from 4.0, which is
important for an LTS version.
Pull Request: https://projects.blender.org/blender/blender/pulls/105938
2023-04-04 20:39:28 +02:00
|
|
|
ii = findEd(edges_new, maxEdges, ml_new[3].v, ml_new[0].v);
|
2012-01-04 20:11:08 +00:00
|
|
|
printf("%d %d\n", ii, ml_new[3].e);
|
|
|
|
|
ml_new[3].e = ii;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
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
|
|
|
sharp_faces.finish();
|
|
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
if (edge_face_map) {
|
|
|
|
|
MEM_freeN(edge_face_map);
|
2013-11-19 13:11:31 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 21:22:56 +11:00
|
|
|
if (vert_loop_map) {
|
|
|
|
|
MEM_freeN(vert_loop_map);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-05-12 19:51:56 +10:00
|
|
|
if (do_remove_doubles) {
|
2018-05-11 11:31:21 +02:00
|
|
|
result = mesh_remove_doubles_on_axis(result,
|
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
|
|
|
vert_positions_new,
|
2017-09-07 00:10:13 +10:00
|
|
|
totvert,
|
|
|
|
|
step_tot,
|
2018-12-07 15:45:53 +01:00
|
|
|
axis_vec,
|
2022-12-12 18:19:32 -06:00
|
|
|
ob_axis != nullptr ? mtx_tx[3] : nullptr,
|
2018-12-07 15:45:53 +01:00
|
|
|
ltmd->merge_dist);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-12 20:45:16 -05:00
|
|
|
dst_material_index.finish();
|
|
|
|
|
|
2011-09-07 02:00:44 +00:00
|
|
|
return result;
|
2010-04-11 22:12:30 +00: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
|
|
|
{
|
|
|
|
|
ScrewModifierData *ltmd = (ScrewModifierData *)md;
|
2022-12-12 18:19:32 -06:00
|
|
|
if (ltmd->ob_axis != nullptr) {
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(ctx->node, ltmd->ob_axis, DEG_OB_COMP_TRANSFORM, "Screw Modifier");
|
2022-08-04 12:11:31 +02:00
|
|
|
DEG_add_depends_on_transform_relation(ctx->node, "Screw 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 void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
ScrewModifierData *ltmd = (ScrewModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
walk(user_data, ob, (ID **)<md->ob_axis, IDWALK_CB_NOP);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
static void panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *sub, *row, *col;
|
|
|
|
|
uiLayout *layout = panel->layout;
|
2023-07-29 15:06:33 +10:00
|
|
|
const eUI_Item_Flag toggles_flag = UI_ITEM_R_TOGGLE | UI_ITEM_R_FORCE_BLANK_DECORATE;
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2022-12-12 18:19:32 -06: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
|
|
|
PointerRNA screw_obj_ptr = RNA_pointer_get(ptr, "object");
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
|
|
|
|
col = uiLayoutColumn(layout, false);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(col, ptr, "angle", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
row = uiLayoutRow(col, false);
|
|
|
|
|
uiLayoutSetActive(row,
|
|
|
|
|
RNA_pointer_is_null(&screw_obj_ptr) ||
|
2020-09-02 14:13:26 -05:00
|
|
|
!RNA_boolean_get(ptr, "use_object_screw_offset"));
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(row, ptr, "screw_offset", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "iterations", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiItemS(layout);
|
|
|
|
|
col = uiLayoutColumn(layout, false);
|
|
|
|
|
row = uiLayoutRow(col, false);
|
2022-12-12 18:19:32 -06:00
|
|
|
uiItemR(row, ptr, "axis", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(col, ptr, "object", UI_ITEM_NONE, IFACE_("Axis Object"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
sub = uiLayoutColumn(col, false);
|
|
|
|
|
uiLayoutSetActive(sub, !RNA_pointer_is_null(&screw_obj_ptr));
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(sub, ptr, "use_object_screw_offset", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiItemS(layout);
|
|
|
|
|
|
|
|
|
|
col = uiLayoutColumn(layout, true);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(col, ptr, "steps", UI_ITEM_NONE, IFACE_("Steps Viewport"), ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "render_steps", UI_ITEM_NONE, IFACE_("Render"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiItemS(layout);
|
|
|
|
|
|
|
|
|
|
row = uiLayoutRowWithHeading(layout, true, IFACE_("Merge"));
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(row, ptr, "use_merge_vertices", UI_ITEM_NONE, "", ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
sub = uiLayoutRow(row, true);
|
2020-09-02 14:13:26 -05:00
|
|
|
uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_merge_vertices"));
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(sub, ptr, "merge_threshold", UI_ITEM_NONE, "", ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiItemS(layout);
|
|
|
|
|
|
|
|
|
|
row = uiLayoutRowWithHeading(layout, true, IFACE_("Stretch UVs"));
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(row, ptr, "use_stretch_u", toggles_flag, IFACE_("U"), ICON_NONE);
|
|
|
|
|
uiItemR(row, ptr, "use_stretch_v", toggles_flag, IFACE_("V"), 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
|
|
|
}
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
static void normals_panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *col;
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, nullptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
|
|
|
|
col = uiLayoutColumn(layout, false);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(col, ptr, "use_smooth_shade", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "use_normal_calculate", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "use_normal_flip", 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_Screw, panel_draw);
|
|
|
|
|
modifier_subpanel_register(
|
2022-12-12 18:19:32 -06:00
|
|
|
region_type, "normals", "Normals", nullptr, normals_panel_draw, panel_type);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
ModifierTypeInfo modifierType_Screw = {
|
2023-07-26 17:08:14 +02:00
|
|
|
/*idname*/ "Screw",
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("Screw"),
|
2023-07-27 12:04:18 +10:00
|
|
|
/*struct_name*/ "ScrewModifierData",
|
|
|
|
|
/*struct_size*/ sizeof(ScrewModifierData),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*srna*/ &RNA_ScrewModifier,
|
2023-11-14 10:03:56 +01:00
|
|
|
/*type*/ ModifierTypeType::Constructive,
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-16 12:41:11 +11:00
|
|
|
/*flags*/ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_AcceptsCVs |
|
2012-05-06 13:38:33 +00:00
|
|
|
eModifierTypeFlag_SupportsEditmode | eModifierTypeFlag_EnableInEditmode,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*icon*/ ICON_MOD_SCREW,
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
/*copy_data*/ BKE_modifier_copydata_generic,
|
|
|
|
|
|
|
|
|
|
/*deform_verts*/ nullptr,
|
|
|
|
|
/*deform_matrices*/ nullptr,
|
|
|
|
|
/*deform_verts_EM*/ nullptr,
|
|
|
|
|
/*deform_matrices_EM*/ nullptr,
|
|
|
|
|
/*modify_mesh*/ modify_mesh,
|
|
|
|
|
/*modify_geometry_set*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*init_data*/ init_data,
|
|
|
|
|
/*required_data_mask*/ nullptr,
|
|
|
|
|
/*free_data*/ nullptr,
|
|
|
|
|
/*is_disabled*/ nullptr,
|
|
|
|
|
/*update_depsgraph*/ update_depsgraph,
|
|
|
|
|
/*depends_on_time*/ nullptr,
|
|
|
|
|
/*depends_on_normals*/ nullptr,
|
|
|
|
|
/*foreach_ID_link*/ foreach_ID_link,
|
|
|
|
|
/*foreach_tex_link*/ nullptr,
|
|
|
|
|
/*free_runtime_data*/ nullptr,
|
|
|
|
|
/*panel_register*/ panel_register,
|
|
|
|
|
/*blend_write*/ nullptr,
|
|
|
|
|
/*blend_read*/ nullptr,
|
2024-01-18 22:51:30 +01:00
|
|
|
/*foreach_cache*/ nullptr,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|