2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2005 Blender Foundation. All rights reserved. */
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup modifiers
|
2014-08-12 13:52:17 +10:00
|
|
|
*
|
|
|
|
|
* Array modifier: duplicates the object multiple times along an axis.
|
2011-12-29 04:04:27 +00:00
|
|
|
*/
|
|
|
|
|
|
2010-08-16 05:46:10 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-05-09 04:06:48 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-25 11:56:24 +01:00
|
|
|
#include "BLI_math.h"
|
|
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2010-08-16 05:46:10 +00:00
|
|
|
#include "DNA_curve_types.h"
|
2020-10-01 09:38:00 -05:00
|
|
|
#include "DNA_defaults.h"
|
2018-04-25 16:47:52 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2010-08-16 05:46:10 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
2012-02-11 10:15:11 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "DNA_screen_types.h"
|
2010-08-16 05:46:10 +00:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
#include "BKE_anim_path.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BKE_context.h"
|
2013-08-19 09:25:24 +00:00
|
|
|
#include "BKE_curve.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_displist.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
|
|
|
|
#include "BKE_lib_query.h"
|
2017-06-08 09:17:08 +02:00
|
|
|
#include "BKE_mesh.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_modifier.h"
|
2018-03-06 09:57:41 +11:00
|
|
|
#include "BKE_object_deform.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BKE_screen.h"
|
|
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2012-10-24 07:24:11 +00:00
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "MOD_ui_common.h"
|
2013-12-26 17:24:42 +06:00
|
|
|
#include "MOD_util.h"
|
|
|
|
|
|
2017-04-06 15:37:46 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
2018-12-07 15:45:53 +01:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2017-04-06 15:37:46 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
static void initData(ModifierData *md)
|
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
ArrayModifierData *amd = (ArrayModifierData *)md;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(amd, modifier));
|
|
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(amd, DNA_struct_default_get(ArrayModifierData), modifier);
|
UI: Small Tweaks to Modifier Layouts for Consistency
These changes are smaller, made based on feedback and a pass on all
the layouts for clarity and consistency. The Multires modifier UI will
be addressed in a separate patch. Here is an overview of the changes:
Renaming Options:
- Build: "Start" -> "Start Frame"
- Curve: "From Radius" -> "Size from Radius"
- Screw: "Calc Order" -> "Calculate Order"
- Displace, Warp, Wave: "Texture Coordinates Object" -> "Object"
Move Mode Toggle to Top & Expand:
- Bevel, Boolean, Normal Edit, Subdivision
Use Columns for Tighter Spacing:
- Displace, Explode, Ocean, Particle Instance, Remesh, Shrinkwrap,
Solidify, Warp, Weighted Normal, Wave
Misc:
- Bevel: Set inactive properties for vertex bevel
- Mesh Sequence Cache: Remove box for cache file
- Skin: Don't align "Mark Loose" and "Clear Loose"
- Array: Expand relative offset subpanel by default
- Array: Move start cap, end cap to a new subpanel
- Bevel: Move width type above width
Differential Revision: https://developer.blender.org/D8115
2020-07-02 10:47:02 -04:00
|
|
|
|
2021-02-05 16:23:34 +11:00
|
|
|
/* Open the first sub-panel by default,
|
|
|
|
|
* it corresponds to Relative offset which is enabled too. */
|
2020-10-29 19:34:29 -05:00
|
|
|
md->ui_expand_flag = UI_PANEL_DATA_EXPAND_ROOT | UI_SUBPANEL_DATA_EXPAND_1;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-01 18:05:23 +02:00
|
|
|
static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
ArrayModifierData *amd = (ArrayModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2020-10-01 18:05:23 +02:00
|
|
|
walk(userData, ob, (ID **)&amd->start_cap, IDWALK_CB_NOP);
|
|
|
|
|
walk(userData, ob, (ID **)&amd->end_cap, IDWALK_CB_NOP);
|
|
|
|
|
walk(userData, ob, (ID **)&amd->curve_ob, IDWALK_CB_NOP);
|
|
|
|
|
walk(userData, ob, (ID **)&amd->offset_ob, IDWALK_CB_NOP);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2018-02-22 12:54:06 +01:00
|
|
|
static void updateDepsgraph(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
|
|
|
{
|
|
|
|
|
ArrayModifierData *amd = (ArrayModifierData *)md;
|
2019-11-04 14:14:03 +01:00
|
|
|
bool need_transform_dependency = false;
|
2022-12-12 18:19:32 -06:00
|
|
|
if (amd->start_cap != nullptr) {
|
2018-04-25 16:34:01 +02:00
|
|
|
DEG_add_object_relation(
|
|
|
|
|
ctx->node, amd->start_cap, DEG_OB_COMP_GEOMETRY, "Array Modifier Start Cap");
|
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
|
|
|
}
|
2022-12-12 18:19:32 -06:00
|
|
|
if (amd->end_cap != nullptr) {
|
2018-04-25 16:34:01 +02:00
|
|
|
DEG_add_object_relation(
|
|
|
|
|
ctx->node, amd->end_cap, DEG_OB_COMP_GEOMETRY, "Array Modifier End Cap");
|
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
|
|
|
}
|
|
|
|
|
if (amd->curve_ob) {
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(
|
|
|
|
|
ctx->node, amd->curve_ob, DEG_OB_COMP_GEOMETRY, "Array Modifier Curve");
|
2018-10-24 12:31:24 +03:00
|
|
|
DEG_add_special_eval_flag(ctx->node, &amd->curve_ob->id, DAG_EVAL_NEED_CURVE_PATH);
|
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
|
|
|
}
|
2022-12-12 18:19:32 -06:00
|
|
|
if (amd->offset_ob != nullptr) {
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(
|
|
|
|
|
ctx->node, amd->offset_ob, DEG_OB_COMP_TRANSFORM, "Array Modifier Offset");
|
2019-11-04 14:14:03 +01:00
|
|
|
need_transform_dependency = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (need_transform_dependency) {
|
2022-08-04 12:11:31 +02:00
|
|
|
DEG_add_depends_on_transform_relation(ctx->node, "Array 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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
BLI_INLINE float sum_v3(const float v[3])
|
2012-03-28 22:03:46 +00:00
|
|
|
{
|
2014-08-12 13:52:17 +10:00
|
|
|
return v[0] + v[1] + v[2];
|
|
|
|
|
}
|
2012-03-28 22:03:46 +00:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* Structure used for sorting vertices, when processing doubles */
|
2022-12-12 18:19:32 -06:00
|
|
|
struct SortVertsElem {
|
2014-08-12 13:52:17 +10:00
|
|
|
int vertex_num; /* The original index of the vertex, prior to sorting */
|
|
|
|
|
float co[3]; /* Its coordinates */
|
2021-06-24 15:56:58 +10:00
|
|
|
float sum_co; /* `sum_v3(co)`: just so we don't do the sum many times. */
|
2022-12-12 18:19:32 -06:00
|
|
|
};
|
2012-03-28 22:03:46 +00:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
static int svert_sum_cmp(const void *e1, const void *e2)
|
|
|
|
|
{
|
2022-12-12 18:19:32 -06:00
|
|
|
const SortVertsElem *sv1 = static_cast<const SortVertsElem *>(e1);
|
|
|
|
|
const SortVertsElem *sv2 = static_cast<const SortVertsElem *>(e2);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (sv1->sum_co > sv2->sum_co) {
|
2014-08-12 13:52:17 +10:00
|
|
|
return 1;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2020-08-07 12:40:29 +02:00
|
|
|
if (sv1->sum_co < sv2->sum_co) {
|
2014-08-12 13:52:17 +10:00
|
|
|
return -1;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2020-08-07 12:40:29 +02:00
|
|
|
|
|
|
|
|
return 0;
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2012-03-28 22:03:46 +00:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
static void svert_from_mvert(SortVertsElem *sv,
|
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 (*vert_positions)[3],
|
2014-08-12 13:52:17 +10:00
|
|
|
const int i_begin,
|
|
|
|
|
const int i_end)
|
|
|
|
|
{
|
|
|
|
|
int 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
|
|
|
for (i = i_begin; i < i_end; i++, sv++) {
|
2014-08-12 13:52:17 +10:00
|
|
|
sv->vertex_num = 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(sv->co, vert_positions[i]);
|
|
|
|
|
sv->sum_co = sum_v3(vert_positions[i]);
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2012-03-28 22:03:46 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/**
|
|
|
|
|
* Take as inputs two sets of verts, to be processed for detection of doubles and mapping.
|
2022-03-28 12:29:47 +11:00
|
|
|
* Each set of verts is defined by its start within mverts array and its verts_num;
|
2019-05-01 07:40:07 +10:00
|
|
|
* It builds a mapping for all vertices within source,
|
|
|
|
|
* to vertices within target, or -1 if no double found.
|
2022-03-28 12:29:47 +11:00
|
|
|
* The `int doubles_map[verts_source_num]` array must have been allocated by caller.
|
2012-03-30 17:30:56 +00:00
|
|
|
*/
|
2014-08-12 13:52:17 +10:00
|
|
|
static void dm_mvert_map_doubles(int *doubles_map,
|
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 (*vert_positions)[3],
|
2014-08-12 13:52:17 +10:00
|
|
|
const int target_start,
|
2022-03-28 12:29:47 +11:00
|
|
|
const int target_verts_num,
|
2014-08-12 13:52:17 +10:00
|
|
|
const int source_start,
|
2022-03-28 12:29:47 +11:00
|
|
|
const int source_verts_num,
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
const float dist)
|
2012-03-30 17:30:56 +00:00
|
|
|
{
|
2022-12-12 18:19:32 -06:00
|
|
|
const float dist3 = (float(M_SQRT3) + 0.00005f) * dist; /* Just above sqrt(3) */
|
2014-08-12 13:52:17 +10:00
|
|
|
int i_source, i_target, i_target_low_bound, target_end, source_end;
|
|
|
|
|
SortVertsElem *sve_source, *sve_target, *sve_target_low_bound;
|
|
|
|
|
bool target_scan_completed;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
target_end = target_start + target_verts_num;
|
|
|
|
|
source_end = source_start + source_verts_num;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* build array of MVerts to be tested for merging */
|
2022-12-12 18:19:32 -06:00
|
|
|
SortVertsElem *sorted_verts_target = static_cast<SortVertsElem *>(
|
|
|
|
|
MEM_malloc_arrayN(target_verts_num, sizeof(SortVertsElem), __func__));
|
|
|
|
|
SortVertsElem *sorted_verts_source = static_cast<SortVertsElem *>(
|
|
|
|
|
MEM_malloc_arrayN(source_verts_num, sizeof(SortVertsElem), __func__));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* Copy target vertices index and cos into SortVertsElem array */
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
svert_from_mvert(sorted_verts_target, vert_positions, target_start, target_end);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* Copy source vertices index and cos into SortVertsElem array */
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
svert_from_mvert(sorted_verts_source, vert_positions, source_start, source_end);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* sort arrays according to sum of vertex coordinates (sumco) */
|
2022-03-28 12:29:47 +11:00
|
|
|
qsort(sorted_verts_target, target_verts_num, sizeof(SortVertsElem), svert_sum_cmp);
|
|
|
|
|
qsort(sorted_verts_source, source_verts_num, sizeof(SortVertsElem), svert_sum_cmp);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
sve_target_low_bound = sorted_verts_target;
|
|
|
|
|
i_target_low_bound = 0;
|
|
|
|
|
target_scan_completed = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-07-23 16:56:00 +10:00
|
|
|
/* Scan source vertices, in #SortVertsElem sorted array,
|
|
|
|
|
* all the while maintaining the lower bound of possible doubles in target vertices. */
|
2022-03-28 12:29:47 +11:00
|
|
|
for (i_source = 0, sve_source = sorted_verts_source; i_source < source_verts_num;
|
2014-08-12 13:52:17 +10:00
|
|
|
i_source++, sve_source++) {
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
int best_target_vertex = -1;
|
|
|
|
|
float best_dist_sq = dist * dist;
|
2014-08-12 13:52:17 +10:00
|
|
|
float sve_source_sumco;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* If source has already been assigned to a target (in an earlier call, with other chunks) */
|
|
|
|
|
if (doubles_map[sve_source->vertex_num] != -1) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* If target fully scanned already, then all remaining source vertices cannot have a double */
|
|
|
|
|
if (target_scan_completed) {
|
|
|
|
|
doubles_map[sve_source->vertex_num] = -1;
|
|
|
|
|
continue;
|
2012-11-19 14:58:31 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
sve_source_sumco = sum_v3(sve_source->co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* Skip all target vertices that are more than dist3 lower in terms of sumco */
|
|
|
|
|
/* and advance the overall lower bound, applicable to all remaining vertices as well. */
|
2022-03-28 12:29:47 +11:00
|
|
|
while ((i_target_low_bound < target_verts_num) &&
|
2014-08-12 13:52:17 +10:00
|
|
|
(sve_target_low_bound->sum_co < sve_source_sumco - dist3)) {
|
|
|
|
|
i_target_low_bound++;
|
|
|
|
|
sve_target_low_bound++;
|
2012-11-19 14:58:31 +00:00
|
|
|
}
|
2014-08-12 13:52:17 +10:00
|
|
|
/* If end of target list reached, then no more possible doubles */
|
2022-03-28 12:29:47 +11:00
|
|
|
if (i_target_low_bound >= target_verts_num) {
|
2014-08-12 13:52:17 +10:00
|
|
|
doubles_map[sve_source->vertex_num] = -1;
|
|
|
|
|
target_scan_completed = true;
|
|
|
|
|
continue;
|
2012-11-19 14:58:31 +00:00
|
|
|
}
|
2019-05-01 07:40:07 +10:00
|
|
|
/* Test target candidates starting at the low bound of possible doubles,
|
|
|
|
|
* ordered in terms of sumco. */
|
2014-08-12 13:52:17 +10:00
|
|
|
i_target = i_target_low_bound;
|
|
|
|
|
sve_target = sve_target_low_bound;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-01 07:40:07 +10:00
|
|
|
/* i_target will scan vertices in the
|
|
|
|
|
* [v_source_sumco - dist3; v_source_sumco + dist3] range */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
while ((i_target < target_verts_num) && (sve_target->sum_co <= sve_source_sumco + dist3)) {
|
2014-08-12 13:52:17 +10:00
|
|
|
/* Testing distance for candidate double in target */
|
|
|
|
|
/* v_target is within dist3 of v_source in terms of sumco; check real distance */
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
float dist_sq;
|
|
|
|
|
if ((dist_sq = len_squared_v3v3(sve_source->co, sve_target->co)) <= best_dist_sq) {
|
|
|
|
|
/* Potential double found */
|
|
|
|
|
best_dist_sq = dist_sq;
|
|
|
|
|
best_target_vertex = sve_target->vertex_num;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
/* If target is already mapped, we only follow that mapping if final target remains
|
|
|
|
|
* close enough from current vert (otherwise no mapping at all).
|
2019-05-01 07:40:07 +10:00
|
|
|
* Note that if we later find another target closer than this one, then we check it.
|
|
|
|
|
* But if other potential targets are farther,
|
|
|
|
|
* then there will be no mapping at all for this source. */
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
while (best_target_vertex != -1 &&
|
|
|
|
|
!ELEM(doubles_map[best_target_vertex], -1, best_target_vertex)) {
|
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
|
|
|
if (compare_len_v3v3(vert_positions[sve_source->vertex_num],
|
|
|
|
|
vert_positions[doubles_map[best_target_vertex]],
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
dist)) {
|
|
|
|
|
best_target_vertex = doubles_map[best_target_vertex];
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
|
|
|
|
else {
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
best_target_vertex = -1;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2012-03-30 17:30:56 +00:00
|
|
|
}
|
2014-08-12 13:52:17 +10:00
|
|
|
i_target++;
|
|
|
|
|
sve_target++;
|
|
|
|
|
}
|
|
|
|
|
/* End of candidate scan: if none found then no doubles */
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
doubles_map[sve_source->vertex_num] = best_target_vertex;
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
MEM_freeN(sorted_verts_source);
|
|
|
|
|
MEM_freeN(sorted_verts_target);
|
|
|
|
|
}
|
2012-03-30 17:30:56 +00:00
|
|
|
|
2018-04-25 16:47:52 +02:00
|
|
|
static void mesh_merge_transform(Mesh *result,
|
|
|
|
|
Mesh *cap_mesh,
|
2019-09-14 08:10:50 +10:00
|
|
|
const float cap_offset[4][4],
|
2019-09-19 13:32:36 +10:00
|
|
|
uint cap_verts_index,
|
|
|
|
|
uint cap_edges_index,
|
2014-08-12 13:52:17 +10:00
|
|
|
int cap_loops_index,
|
|
|
|
|
int cap_polys_index,
|
2018-03-06 09:57:41 +11:00
|
|
|
int cap_nverts,
|
|
|
|
|
int cap_nedges,
|
|
|
|
|
int cap_nloops,
|
|
|
|
|
int cap_npolys,
|
|
|
|
|
int *remap,
|
2021-12-28 16:57:36 +01:00
|
|
|
int remap_len,
|
|
|
|
|
const bool recalc_normals_later)
|
2014-08-12 13:52:17 +10:00
|
|
|
{
|
|
|
|
|
int *index_orig;
|
|
|
|
|
int i;
|
|
|
|
|
MEdge *me;
|
|
|
|
|
MLoop *ml;
|
|
|
|
|
MPoly *mp;
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
float(*result_positions)[3] = BKE_mesh_vert_positions_for_write(result);
|
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
|
|
|
MEdge *result_edges = BKE_mesh_edges_for_write(result);
|
2022-09-07 00:06:31 -05:00
|
|
|
MPoly *result_polys = BKE_mesh_polys_for_write(result);
|
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
|
|
|
MLoop *result_loops = BKE_mesh_loops_for_write(result);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-25 16:47:52 +02:00
|
|
|
CustomData_copy_data(&cap_mesh->vdata, &result->vdata, 0, cap_verts_index, cap_nverts);
|
|
|
|
|
CustomData_copy_data(&cap_mesh->edata, &result->edata, 0, cap_edges_index, cap_nedges);
|
|
|
|
|
CustomData_copy_data(&cap_mesh->ldata, &result->ldata, 0, cap_loops_index, cap_nloops);
|
|
|
|
|
CustomData_copy_data(&cap_mesh->pdata, &result->pdata, 0, cap_polys_index, cap_npolys);
|
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
|
|
|
for (i = 0; i < cap_nverts; i++) {
|
|
|
|
|
mul_m4_v3(cap_offset, result_positions[cap_verts_index + i]);
|
Refactor: Move normals out of MVert, lazy calculation
As described in T91186, this commit moves mesh vertex normals into a
contiguous array of float vectors in a custom data layer, how face
normals are currently stored.
The main interface is documented in `BKE_mesh.h`. Vertex and face
normals are now calculated on-demand and cached, retrieved with an
"ensure" function. Since the logical state of a mesh is now "has
normals when necessary", they can be retrieved from a `const` mesh.
The goal is to use on-demand calculation for all derived data, but
leave room for eager calculation for performance purposes (modifier
evaluation is threaded, but viewport data generation is not).
**Benefits**
This moves us closer to a SoA approach rather than the current AoS
paradigm. Accessing a contiguous `float3` is much more efficient than
retrieving data from a larger struct. The memory requirements for
accessing only normals or vertex locations are smaller, and at the
cost of more memory usage for just normals, they now don't have to
be converted between float and short, which also simplifies code
In the future, the remaining items can be removed from `MVert`,
leaving only `float3`, which has similar benefits (see T93602).
Removing the combination of derived and original data makes it
conceptually simpler to only calculate normals when necessary.
This is especially important now that we have more opportunities
for temporary meshes in geometry nodes.
**Performance**
In addition to the theoretical future performance improvements by
making `MVert == float3`, I've done some basic performance testing
on this patch directly. The data is fairly rough, but it gives an idea
about where things stand generally.
- Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms),
showing that accessing just `MVert` is now more efficient.
- Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight
change that at least shows there is no regression.
- Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small
but observable speedup.
- Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms),
shows that using normals in geometry nodes is faster.
- Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms),
shows that calculating normals is slightly faster now.
- File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB),
Normals are not saved in files, which can help with large meshes.
As for memory usage, it may be slightly more in some cases, but
I didn't observe any difference in the production files I tested.
**Tests**
Some modifiers and cycles test results need to be updated with this
commit, for two reasons:
- The subdivision surface modifier is not responsible for calculating
normals anymore. In master, the modifier creates different normals
than the result of the `Mesh` normal calculation, so this is a bug
fix.
- There are small differences in the results of some modifiers that
use normals because they are not converted to and from `short`
anymore.
**Future improvements**
- Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier
already retrieves normals if they are needed anyway.
- Copy normals as part of a better CoW system for attributes.
- Make more areas use lazy instead of eager normal calculation.
- Remove `BKE_mesh_normals_tag_dirty` in more places since that is
now the default state of a new mesh.
- Possibly apply a similar change to derived face corner normals.
Differential Revision: https://developer.blender.org/D12770
2022-01-13 14:37:58 -06:00
|
|
|
}
|
2021-12-28 16:57:36 +01:00
|
|
|
|
Refactor: Move normals out of MVert, lazy calculation
As described in T91186, this commit moves mesh vertex normals into a
contiguous array of float vectors in a custom data layer, how face
normals are currently stored.
The main interface is documented in `BKE_mesh.h`. Vertex and face
normals are now calculated on-demand and cached, retrieved with an
"ensure" function. Since the logical state of a mesh is now "has
normals when necessary", they can be retrieved from a `const` mesh.
The goal is to use on-demand calculation for all derived data, but
leave room for eager calculation for performance purposes (modifier
evaluation is threaded, but viewport data generation is not).
**Benefits**
This moves us closer to a SoA approach rather than the current AoS
paradigm. Accessing a contiguous `float3` is much more efficient than
retrieving data from a larger struct. The memory requirements for
accessing only normals or vertex locations are smaller, and at the
cost of more memory usage for just normals, they now don't have to
be converted between float and short, which also simplifies code
In the future, the remaining items can be removed from `MVert`,
leaving only `float3`, which has similar benefits (see T93602).
Removing the combination of derived and original data makes it
conceptually simpler to only calculate normals when necessary.
This is especially important now that we have more opportunities
for temporary meshes in geometry nodes.
**Performance**
In addition to the theoretical future performance improvements by
making `MVert == float3`, I've done some basic performance testing
on this patch directly. The data is fairly rough, but it gives an idea
about where things stand generally.
- Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms),
showing that accessing just `MVert` is now more efficient.
- Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight
change that at least shows there is no regression.
- Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small
but observable speedup.
- Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms),
shows that using normals in geometry nodes is faster.
- Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms),
shows that calculating normals is slightly faster now.
- File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB),
Normals are not saved in files, which can help with large meshes.
As for memory usage, it may be slightly more in some cases, but
I didn't observe any difference in the production files I tested.
**Tests**
Some modifiers and cycles test results need to be updated with this
commit, for two reasons:
- The subdivision surface modifier is not responsible for calculating
normals anymore. In master, the modifier creates different normals
than the result of the `Mesh` normal calculation, so this is a bug
fix.
- There are small differences in the results of some modifiers that
use normals because they are not converted to and from `short`
anymore.
**Future improvements**
- Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier
already retrieves normals if they are needed anyway.
- Copy normals as part of a better CoW system for attributes.
- Make more areas use lazy instead of eager normal calculation.
- Remove `BKE_mesh_normals_tag_dirty` in more places since that is
now the default state of a new mesh.
- Possibly apply a similar change to derived face corner normals.
Differential Revision: https://developer.blender.org/D12770
2022-01-13 14:37:58 -06:00
|
|
|
/* We have to correct normals too, if we do not tag them as dirty later! */
|
|
|
|
|
if (!recalc_normals_later) {
|
|
|
|
|
float(*dst_vert_normals)[3] = BKE_mesh_vertex_normals_for_write(result);
|
|
|
|
|
for (i = 0; i < cap_nverts; i++) {
|
|
|
|
|
mul_mat3_m4_v3(cap_offset, dst_vert_normals[cap_verts_index + i]);
|
|
|
|
|
normalize_v3(dst_vert_normals[cap_verts_index + i]);
|
2021-12-28 16:57:36 +01:00
|
|
|
}
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-06 09:57:41 +11:00
|
|
|
/* remap the vertex groups if necessary */
|
2022-12-12 18:19:32 -06:00
|
|
|
if (BKE_mesh_deform_verts(result) != nullptr) {
|
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
|
|
|
MDeformVert *dvert = BKE_mesh_deform_verts_for_write(result);
|
|
|
|
|
BKE_object_defgroup_index_map_apply(&dvert[cap_verts_index], cap_nverts, remap, remap_len);
|
2018-03-06 09:57:41 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* adjust cap edge vertex indices */
|
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
|
|
|
me = result_edges + cap_edges_index;
|
2014-08-12 13:52:17 +10:00
|
|
|
for (i = 0; i < cap_nedges; i++, me++) {
|
|
|
|
|
me->v1 += cap_verts_index;
|
|
|
|
|
me->v2 += cap_verts_index;
|
2012-03-30 17:30:56 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* adjust cap poly loopstart indices */
|
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
|
|
|
mp = result_polys + cap_polys_index;
|
2014-08-12 13:52:17 +10:00
|
|
|
for (i = 0; i < cap_npolys; i++, mp++) {
|
|
|
|
|
mp->loopstart += cap_loops_index;
|
2012-03-30 17:30:56 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* adjust cap loop vertex and edge indices */
|
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
|
|
|
ml = result_loops + cap_loops_index;
|
2014-08-12 13:52:17 +10:00
|
|
|
for (i = 0; i < cap_nloops; i++, ml++) {
|
|
|
|
|
ml->v += cap_verts_index;
|
|
|
|
|
ml->e += cap_edges_index;
|
2012-03-30 17:30:56 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-06-01 15:11:56 +10:00
|
|
|
/* Set #CD_ORIGINDEX. */
|
2023-01-13 17:21:20 -06:00
|
|
|
index_orig = static_cast<int *>(
|
|
|
|
|
CustomData_get_layer_for_write(&result->vdata, CD_ORIGINDEX, result->totvert));
|
2014-08-12 13:52:17 +10:00
|
|
|
if (index_orig) {
|
2015-05-05 17:08:29 +10:00
|
|
|
copy_vn_i(index_orig + cap_verts_index, cap_nverts, ORIGINDEX_NONE);
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-13 17:21:20 -06:00
|
|
|
index_orig = static_cast<int *>(
|
|
|
|
|
CustomData_get_layer_for_write(&result->edata, CD_ORIGINDEX, result->totedge));
|
2014-08-12 13:52:17 +10:00
|
|
|
if (index_orig) {
|
2015-05-05 17:08:29 +10:00
|
|
|
copy_vn_i(index_orig + cap_edges_index, cap_nedges, ORIGINDEX_NONE);
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-13 17:21:20 -06:00
|
|
|
index_orig = static_cast<int *>(
|
|
|
|
|
CustomData_get_layer_for_write(&result->pdata, CD_ORIGINDEX, result->totpoly));
|
2014-08-12 13:52:17 +10:00
|
|
|
if (index_orig) {
|
2015-05-05 17:08:29 +10:00
|
|
|
copy_vn_i(index_orig + cap_polys_index, cap_npolys, ORIGINDEX_NONE);
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-13 17:21:20 -06:00
|
|
|
index_orig = static_cast<int *>(
|
|
|
|
|
CustomData_get_layer_for_write(&result->ldata, CD_ORIGINDEX, result->totloop));
|
2014-08-12 13:52:17 +10:00
|
|
|
if (index_orig) {
|
2015-05-05 17:08:29 +10:00
|
|
|
copy_vn_i(index_orig + cap_loops_index, cap_nloops, ORIGINDEX_NONE);
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2012-03-30 17:30:56 +00:00
|
|
|
}
|
2012-03-28 22:03:46 +00:00
|
|
|
|
2018-04-25 16:47:52 +02:00
|
|
|
static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
|
2018-05-01 17:33:04 +02:00
|
|
|
const ModifierEvalContext *ctx,
|
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)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2014-08-12 13:52:17 +10:00
|
|
|
MEdge *me;
|
|
|
|
|
MLoop *ml;
|
|
|
|
|
MPoly *mp;
|
|
|
|
|
int i, j, c, count;
|
|
|
|
|
float length = amd->length;
|
2010-04-11 22:12:30 +00:00
|
|
|
/* offset matrix */
|
|
|
|
|
float offset[4][4];
|
2014-08-12 13:52:17 +10:00
|
|
|
float scale[3];
|
|
|
|
|
bool offset_has_scale;
|
|
|
|
|
float current_offset[4][4];
|
2012-02-13 08:06:44 +00:00
|
|
|
float final_offset[4][4];
|
2022-12-12 18:19:32 -06:00
|
|
|
int *full_doubles_map = nullptr;
|
2014-08-12 13:52:17 +10:00
|
|
|
int tot_doubles;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-07 11:41:45 +11:00
|
|
|
const bool use_merge = (amd->flags & MOD_ARR_MERGE) != 0;
|
2022-02-18 13:21:36 -06:00
|
|
|
const bool use_recalc_normals = BKE_mesh_vertex_normals_are_dirty(mesh) || use_merge;
|
2022-12-12 18:19:32 -06:00
|
|
|
const bool use_offset_ob = ((amd->offset_type & MOD_ARR_OFF_OBJ) && amd->offset_ob != nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
int start_cap_nverts = 0, start_cap_nedges = 0, start_cap_npolys = 0, start_cap_nloops = 0;
|
|
|
|
|
int end_cap_nverts = 0, end_cap_nedges = 0, end_cap_npolys = 0, end_cap_nloops = 0;
|
|
|
|
|
int result_nverts = 0, result_nedges = 0, result_npolys = 0, result_nloops = 0;
|
|
|
|
|
int chunk_nverts, chunk_nedges, chunk_nloops, chunk_npolys;
|
|
|
|
|
int first_chunk_start, first_chunk_nverts, last_chunk_start, last_chunk_nverts;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
Mesh *result, *start_cap_mesh = nullptr, *end_cap_mesh = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
int *vgroup_start_cap_remap = nullptr;
|
2018-03-06 09:57:41 +11:00
|
|
|
int vgroup_start_cap_remap_len = 0;
|
2022-12-12 18:19:32 -06:00
|
|
|
int *vgroup_end_cap_remap = nullptr;
|
2018-03-06 09:57:41 +11:00
|
|
|
int vgroup_end_cap_remap_len = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-25 16:47:52 +02:00
|
|
|
chunk_nverts = mesh->totvert;
|
|
|
|
|
chunk_nedges = mesh->totedge;
|
|
|
|
|
chunk_nloops = mesh->totloop;
|
|
|
|
|
chunk_npolys = mesh->totpoly;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
count = amd->count;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 11:25:07 +01:00
|
|
|
Object *start_cap_ob = amd->start_cap;
|
2019-08-23 15:50:53 +02:00
|
|
|
if (start_cap_ob && start_cap_ob != ctx->object) {
|
2022-03-21 14:44:39 -05:00
|
|
|
if (start_cap_ob->type == OB_MESH && ctx->object->type == OB_MESH) {
|
|
|
|
|
vgroup_start_cap_remap = BKE_object_defgroup_index_map_create(
|
|
|
|
|
start_cap_ob, ctx->object, &vgroup_start_cap_remap_len);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-07-20 15:57:16 +02:00
|
|
|
start_cap_mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(start_cap_ob);
|
2018-04-25 16:47:52 +02:00
|
|
|
if (start_cap_mesh) {
|
|
|
|
|
start_cap_nverts = start_cap_mesh->totvert;
|
|
|
|
|
start_cap_nedges = start_cap_mesh->totedge;
|
|
|
|
|
start_cap_nloops = start_cap_mesh->totloop;
|
|
|
|
|
start_cap_npolys = start_cap_mesh->totpoly;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2019-03-26 11:25:07 +01:00
|
|
|
Object *end_cap_ob = amd->end_cap;
|
2019-08-23 15:50:53 +02:00
|
|
|
if (end_cap_ob && end_cap_ob != ctx->object) {
|
2022-03-22 11:25:54 +01:00
|
|
|
if (end_cap_ob->type == OB_MESH && ctx->object->type == OB_MESH) {
|
2022-03-21 14:44:39 -05:00
|
|
|
vgroup_end_cap_remap = BKE_object_defgroup_index_map_create(
|
|
|
|
|
end_cap_ob, ctx->object, &vgroup_end_cap_remap_len);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-07-20 15:57:16 +02:00
|
|
|
end_cap_mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(end_cap_ob);
|
2018-04-25 16:47:52 +02:00
|
|
|
if (end_cap_mesh) {
|
|
|
|
|
end_cap_nverts = end_cap_mesh->totvert;
|
|
|
|
|
end_cap_nedges = end_cap_mesh->totedge;
|
|
|
|
|
end_cap_nloops = end_cap_mesh->totloop;
|
|
|
|
|
end_cap_npolys = end_cap_mesh->totpoly;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-07-05 22:26:25 +10:00
|
|
|
/* Build up offset array, accumulating all settings options. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
unit_m4(offset);
|
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 MEdge *src_edges = BKE_mesh_edges(mesh);
|
2022-09-07 00:06:31 -05:00
|
|
|
const MPoly *src_polys = BKE_mesh_polys(mesh);
|
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 MLoop *src_loops = BKE_mesh_loops(mesh);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-06-08 09:17:08 +02:00
|
|
|
if (amd->offset_type & MOD_ARR_OFF_CONST) {
|
|
|
|
|
add_v3_v3(offset[3], amd->offset);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (amd->offset_type & MOD_ARR_OFF_RELATIVE) {
|
2017-06-08 09:17:08 +02:00
|
|
|
float min[3], max[3];
|
|
|
|
|
INIT_MINMAX(min, max);
|
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
|
|
|
BKE_mesh_minmax(mesh, min, max);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-06-08 09:17:08 +02:00
|
|
|
for (j = 3; j--;) {
|
|
|
|
|
offset[3][j] += amd->scale[j] * (max[j] - min[j]);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2017-06-08 09:17:08 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-03 14:33:50 +02:00
|
|
|
if (use_offset_ob) {
|
2010-04-11 22:12:30 +00:00
|
|
|
float obinv[4][4];
|
|
|
|
|
float result_mat[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (ctx->object) {
|
2022-10-24 14:16:37 +02:00
|
|
|
invert_m4_m4(obinv, ctx->object->object_to_world);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2010-04-11 22:12:30 +00:00
|
|
|
unit_m4(obinv);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-10-24 14:16:37 +02:00
|
|
|
mul_m4_series(result_mat, offset, obinv, amd->offset_ob->object_to_world);
|
2010-04-11 22:12:30 +00:00
|
|
|
copy_m4_m4(offset, result_mat);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-06-07 14:53:20 +10:00
|
|
|
/* Check if there is some scaling. If scaling, then we will not translate mapping */
|
2014-08-12 13:52:17 +10:00
|
|
|
mat4_to_size(scale, offset);
|
|
|
|
|
offset_has_scale = !is_one_v3(scale);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
if (amd->fit_type == MOD_ARR_FITCURVE && amd->curve_ob != nullptr) {
|
2019-03-26 11:25:07 +01:00
|
|
|
Object *curve_ob = amd->curve_ob;
|
2019-08-23 15:50:53 +02:00
|
|
|
CurveCache *curve_cache = curve_ob->runtime.curve_cache;
|
2022-12-12 18:19:32 -06:00
|
|
|
if (curve_cache != nullptr && curve_cache->anim_path_accum_length != nullptr) {
|
2022-10-24 14:16:37 +02:00
|
|
|
float scale_fac = mat4_to_scale(curve_ob->object_to_world);
|
2021-04-08 15:51:08 +02:00
|
|
|
length = scale_fac * BKE_anim_path_get_length(curve_cache);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-11-18 14:02:49 +13:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-23 14:47:06 +02:00
|
|
|
/* About 67 million vertices max seems a decent limit for now. */
|
2022-09-08 11:22:30 +10:00
|
|
|
const size_t max_verts_num = 1 << 26;
|
2020-04-23 14:47:06 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* calculate the maximum number of copies which will fit within the
|
2012-03-09 18:28:30 +00:00
|
|
|
* prescribed length */
|
2020-11-06 12:30:59 +11:00
|
|
|
if (ELEM(amd->fit_type, MOD_ARR_FITLENGTH, MOD_ARR_FITCURVE)) {
|
2020-04-23 14:47:06 +02:00
|
|
|
const float float_epsilon = 1e-6f;
|
|
|
|
|
bool offset_is_too_small = false;
|
2013-09-03 22:32:03 +00:00
|
|
|
float dist = len_v3(offset[3]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-23 14:47:06 +02:00
|
|
|
if (dist > float_epsilon) {
|
2010-04-11 22:12:30 +00:00
|
|
|
/* this gives length = first copy start to last copy end
|
2012-03-09 18:28:30 +00:00
|
|
|
* add a tiny offset for floating point rounding errors */
|
2020-04-23 14:47:06 +02:00
|
|
|
count = (length + float_epsilon) / dist + 1;
|
|
|
|
|
|
|
|
|
|
/* Ensure we keep things to a reasonable level, in terms of rough total amount of generated
|
|
|
|
|
* vertices.
|
|
|
|
|
*/
|
2023-01-03 11:04:16 +11:00
|
|
|
if ((size_t(count) * size_t(chunk_nverts) + size_t(start_cap_nverts) +
|
|
|
|
|
size_t(end_cap_nverts)) > max_verts_num) {
|
2020-04-23 14:47:06 +02:00
|
|
|
count = 1;
|
|
|
|
|
offset_is_too_small = true;
|
|
|
|
|
}
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2010-04-11 22:12:30 +00:00
|
|
|
/* if the offset has no translation, just make one copy */
|
|
|
|
|
count = 1;
|
2020-04-23 14:47:06 +02:00
|
|
|
offset_is_too_small = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset_is_too_small) {
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_set_error(
|
2020-10-26 17:07:58 +11:00
|
|
|
ctx->object,
|
2020-04-23 14:47:06 +02:00
|
|
|
&amd->modifier,
|
|
|
|
|
"The offset is too small, we cannot generate the amount of geometry it would require");
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2020-04-23 14:47:06 +02:00
|
|
|
/* Ensure we keep things to a reasonable level, in terms of rough total amount of generated
|
|
|
|
|
* vertices.
|
|
|
|
|
*/
|
2023-01-03 11:04:16 +11:00
|
|
|
else if ((size_t(count) * size_t(chunk_nverts) + size_t(start_cap_nverts) +
|
|
|
|
|
size_t(end_cap_nverts)) > max_verts_num) {
|
2020-04-23 14:47:06 +02:00
|
|
|
count = 1;
|
2020-10-26 17:07:58 +11:00
|
|
|
BKE_modifier_set_error(ctx->object,
|
|
|
|
|
&amd->modifier,
|
2020-05-08 19:02:03 +10:00
|
|
|
"The amount of copies is too high, we cannot generate the amount of "
|
|
|
|
|
"geometry it would require");
|
2020-04-23 14:47:06 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (count < 1) {
|
2010-07-19 04:44:37 +00:00
|
|
|
count = 1;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* The number of verts, edges, loops, polys, before eventually merging doubles */
|
|
|
|
|
result_nverts = chunk_nverts * count + start_cap_nverts + end_cap_nverts;
|
|
|
|
|
result_nedges = chunk_nedges * count + start_cap_nedges + end_cap_nedges;
|
|
|
|
|
result_nloops = chunk_nloops * count + start_cap_nloops + end_cap_nloops;
|
|
|
|
|
result_npolys = chunk_npolys * count + start_cap_npolys + end_cap_npolys;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* Initialize a result dm */
|
2018-05-08 17:06:30 +02:00
|
|
|
result = BKE_mesh_new_nomain_from_template(
|
|
|
|
|
mesh, result_nverts, result_nedges, 0, result_nloops, result_npolys);
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
float(*result_positions)[3] = BKE_mesh_vert_positions_for_write(result);
|
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
|
|
|
MEdge *result_edges = BKE_mesh_edges_for_write(result);
|
2022-09-07 00:06:31 -05:00
|
|
|
MPoly *result_polys = BKE_mesh_polys_for_write(result);
|
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
|
|
|
MLoop *result_loops = BKE_mesh_loops_for_write(result);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-09-21 10:12:26 +02:00
|
|
|
if (use_merge) {
|
2014-08-12 13:52:17 +10:00
|
|
|
/* Will need full_doubles_map for handling merge */
|
2022-12-12 18:19:32 -06:00
|
|
|
full_doubles_map = static_cast<int *>(MEM_malloc_arrayN(result_nverts, sizeof(int), __func__));
|
2015-05-05 17:08:29 +10:00
|
|
|
copy_vn_i(full_doubles_map, result_nverts, -1);
|
2012-03-26 19:50:45 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* copy customdata to original geometry */
|
2018-04-25 16:47:52 +02:00
|
|
|
CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, chunk_nverts);
|
|
|
|
|
CustomData_copy_data(&mesh->edata, &result->edata, 0, 0, chunk_nedges);
|
|
|
|
|
CustomData_copy_data(&mesh->ldata, &result->ldata, 0, 0, chunk_nloops);
|
|
|
|
|
CustomData_copy_data(&mesh->pdata, &result->pdata, 0, 0, chunk_npolys);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-09 15:37:33 +10:00
|
|
|
/* Subdivision-surface for eg won't have mesh data in the custom-data arrays.
|
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
|
|
|
* Now add #position/#MEdge/#MPoly layers. */
|
2018-04-25 16:47:52 +02:00
|
|
|
if (!CustomData_has_layer(&mesh->edata, CD_MEDGE)) {
|
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
|
|
|
memcpy(result_edges, src_edges, sizeof(MEdge) * mesh->totedge);
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2018-04-25 16:47:52 +02:00
|
|
|
if (!CustomData_has_layer(&mesh->pdata, CD_MPOLY)) {
|
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
|
|
|
memcpy(result_loops, src_loops, sizeof(MLoop) * mesh->totloop);
|
|
|
|
|
memcpy(result_polys, src_polys, sizeof(MPoly) * mesh->totpoly);
|
2012-11-20 13:29:27 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* Remember first chunk, in case of cap merge */
|
|
|
|
|
first_chunk_start = 0;
|
|
|
|
|
first_chunk_nverts = chunk_nverts;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
unit_m4(current_offset);
|
2022-12-12 18:19:32 -06:00
|
|
|
const float(*src_vert_normals)[3] = nullptr;
|
|
|
|
|
float(*dst_vert_normals)[3] = nullptr;
|
Refactor: Move normals out of MVert, lazy calculation
As described in T91186, this commit moves mesh vertex normals into a
contiguous array of float vectors in a custom data layer, how face
normals are currently stored.
The main interface is documented in `BKE_mesh.h`. Vertex and face
normals are now calculated on-demand and cached, retrieved with an
"ensure" function. Since the logical state of a mesh is now "has
normals when necessary", they can be retrieved from a `const` mesh.
The goal is to use on-demand calculation for all derived data, but
leave room for eager calculation for performance purposes (modifier
evaluation is threaded, but viewport data generation is not).
**Benefits**
This moves us closer to a SoA approach rather than the current AoS
paradigm. Accessing a contiguous `float3` is much more efficient than
retrieving data from a larger struct. The memory requirements for
accessing only normals or vertex locations are smaller, and at the
cost of more memory usage for just normals, they now don't have to
be converted between float and short, which also simplifies code
In the future, the remaining items can be removed from `MVert`,
leaving only `float3`, which has similar benefits (see T93602).
Removing the combination of derived and original data makes it
conceptually simpler to only calculate normals when necessary.
This is especially important now that we have more opportunities
for temporary meshes in geometry nodes.
**Performance**
In addition to the theoretical future performance improvements by
making `MVert == float3`, I've done some basic performance testing
on this patch directly. The data is fairly rough, but it gives an idea
about where things stand generally.
- Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms),
showing that accessing just `MVert` is now more efficient.
- Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight
change that at least shows there is no regression.
- Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small
but observable speedup.
- Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms),
shows that using normals in geometry nodes is faster.
- Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms),
shows that calculating normals is slightly faster now.
- File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB),
Normals are not saved in files, which can help with large meshes.
As for memory usage, it may be slightly more in some cases, but
I didn't observe any difference in the production files I tested.
**Tests**
Some modifiers and cycles test results need to be updated with this
commit, for two reasons:
- The subdivision surface modifier is not responsible for calculating
normals anymore. In master, the modifier creates different normals
than the result of the `Mesh` normal calculation, so this is a bug
fix.
- There are small differences in the results of some modifiers that
use normals because they are not converted to and from `short`
anymore.
**Future improvements**
- Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier
already retrieves normals if they are needed anyway.
- Copy normals as part of a better CoW system for attributes.
- Make more areas use lazy instead of eager normal calculation.
- Remove `BKE_mesh_normals_tag_dirty` in more places since that is
now the default state of a new mesh.
- Possibly apply a similar change to derived face corner normals.
Differential Revision: https://developer.blender.org/D12770
2022-01-13 14:37:58 -06:00
|
|
|
if (!use_recalc_normals) {
|
|
|
|
|
src_vert_normals = BKE_mesh_vertex_normals_ensure(mesh);
|
|
|
|
|
dst_vert_normals = BKE_mesh_vertex_normals_for_write(result);
|
|
|
|
|
BKE_mesh_vertex_normals_clear_dirty(result);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
for (c = 1; c < count; c++) {
|
|
|
|
|
/* copy customdata to new geometry */
|
2018-04-25 16:47:52 +02:00
|
|
|
CustomData_copy_data(&mesh->vdata, &result->vdata, 0, c * chunk_nverts, chunk_nverts);
|
|
|
|
|
CustomData_copy_data(&mesh->edata, &result->edata, 0, c * chunk_nedges, chunk_nedges);
|
|
|
|
|
CustomData_copy_data(&mesh->ldata, &result->ldata, 0, c * chunk_nloops, chunk_nloops);
|
|
|
|
|
CustomData_copy_data(&mesh->pdata, &result->pdata, 0, c * chunk_npolys, chunk_npolys);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Refactor: Move normals out of MVert, lazy calculation
As described in T91186, this commit moves mesh vertex normals into a
contiguous array of float vectors in a custom data layer, how face
normals are currently stored.
The main interface is documented in `BKE_mesh.h`. Vertex and face
normals are now calculated on-demand and cached, retrieved with an
"ensure" function. Since the logical state of a mesh is now "has
normals when necessary", they can be retrieved from a `const` mesh.
The goal is to use on-demand calculation for all derived data, but
leave room for eager calculation for performance purposes (modifier
evaluation is threaded, but viewport data generation is not).
**Benefits**
This moves us closer to a SoA approach rather than the current AoS
paradigm. Accessing a contiguous `float3` is much more efficient than
retrieving data from a larger struct. The memory requirements for
accessing only normals or vertex locations are smaller, and at the
cost of more memory usage for just normals, they now don't have to
be converted between float and short, which also simplifies code
In the future, the remaining items can be removed from `MVert`,
leaving only `float3`, which has similar benefits (see T93602).
Removing the combination of derived and original data makes it
conceptually simpler to only calculate normals when necessary.
This is especially important now that we have more opportunities
for temporary meshes in geometry nodes.
**Performance**
In addition to the theoretical future performance improvements by
making `MVert == float3`, I've done some basic performance testing
on this patch directly. The data is fairly rough, but it gives an idea
about where things stand generally.
- Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms),
showing that accessing just `MVert` is now more efficient.
- Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight
change that at least shows there is no regression.
- Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small
but observable speedup.
- Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms),
shows that using normals in geometry nodes is faster.
- Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms),
shows that calculating normals is slightly faster now.
- File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB),
Normals are not saved in files, which can help with large meshes.
As for memory usage, it may be slightly more in some cases, but
I didn't observe any difference in the production files I tested.
**Tests**
Some modifiers and cycles test results need to be updated with this
commit, for two reasons:
- The subdivision surface modifier is not responsible for calculating
normals anymore. In master, the modifier creates different normals
than the result of the `Mesh` normal calculation, so this is a bug
fix.
- There are small differences in the results of some modifiers that
use normals because they are not converted to and from `short`
anymore.
**Future improvements**
- Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier
already retrieves normals if they are needed anyway.
- Copy normals as part of a better CoW system for attributes.
- Make more areas use lazy instead of eager normal calculation.
- Remove `BKE_mesh_normals_tag_dirty` in more places since that is
now the default state of a new mesh.
- Possibly apply a similar change to derived face corner normals.
Differential Revision: https://developer.blender.org/D12770
2022-01-13 14:37:58 -06:00
|
|
|
const int vert_offset = c * chunk_nverts;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* recalculate cumulative offset here */
|
|
|
|
|
mul_m4_m4m4(current_offset, current_offset, offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* apply offset to all new verts */
|
Refactor: Move normals out of MVert, lazy calculation
As described in T91186, this commit moves mesh vertex normals into a
contiguous array of float vectors in a custom data layer, how face
normals are currently stored.
The main interface is documented in `BKE_mesh.h`. Vertex and face
normals are now calculated on-demand and cached, retrieved with an
"ensure" function. Since the logical state of a mesh is now "has
normals when necessary", they can be retrieved from a `const` mesh.
The goal is to use on-demand calculation for all derived data, but
leave room for eager calculation for performance purposes (modifier
evaluation is threaded, but viewport data generation is not).
**Benefits**
This moves us closer to a SoA approach rather than the current AoS
paradigm. Accessing a contiguous `float3` is much more efficient than
retrieving data from a larger struct. The memory requirements for
accessing only normals or vertex locations are smaller, and at the
cost of more memory usage for just normals, they now don't have to
be converted between float and short, which also simplifies code
In the future, the remaining items can be removed from `MVert`,
leaving only `float3`, which has similar benefits (see T93602).
Removing the combination of derived and original data makes it
conceptually simpler to only calculate normals when necessary.
This is especially important now that we have more opportunities
for temporary meshes in geometry nodes.
**Performance**
In addition to the theoretical future performance improvements by
making `MVert == float3`, I've done some basic performance testing
on this patch directly. The data is fairly rough, but it gives an idea
about where things stand generally.
- Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms),
showing that accessing just `MVert` is now more efficient.
- Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight
change that at least shows there is no regression.
- Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small
but observable speedup.
- Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms),
shows that using normals in geometry nodes is faster.
- Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms),
shows that calculating normals is slightly faster now.
- File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB),
Normals are not saved in files, which can help with large meshes.
As for memory usage, it may be slightly more in some cases, but
I didn't observe any difference in the production files I tested.
**Tests**
Some modifiers and cycles test results need to be updated with this
commit, for two reasons:
- The subdivision surface modifier is not responsible for calculating
normals anymore. In master, the modifier creates different normals
than the result of the `Mesh` normal calculation, so this is a bug
fix.
- There are small differences in the results of some modifiers that
use normals because they are not converted to and from `short`
anymore.
**Future improvements**
- Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier
already retrieves normals if they are needed anyway.
- Copy normals as part of a better CoW system for attributes.
- Make more areas use lazy instead of eager normal calculation.
- Remove `BKE_mesh_normals_tag_dirty` in more places since that is
now the default state of a new mesh.
- Possibly apply a similar change to derived face corner normals.
Differential Revision: https://developer.blender.org/D12770
2022-01-13 14:37:58 -06:00
|
|
|
for (i = 0; i < chunk_nverts; i++) {
|
|
|
|
|
const int i_dst = vert_offset + 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
|
|
|
mul_m4_v3(current_offset, result_positions[i_dst]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-09-21 10:12:26 +02:00
|
|
|
/* We have to correct normals too, if we do not tag them as dirty! */
|
|
|
|
|
if (!use_recalc_normals) {
|
Refactor: Move normals out of MVert, lazy calculation
As described in T91186, this commit moves mesh vertex normals into a
contiguous array of float vectors in a custom data layer, how face
normals are currently stored.
The main interface is documented in `BKE_mesh.h`. Vertex and face
normals are now calculated on-demand and cached, retrieved with an
"ensure" function. Since the logical state of a mesh is now "has
normals when necessary", they can be retrieved from a `const` mesh.
The goal is to use on-demand calculation for all derived data, but
leave room for eager calculation for performance purposes (modifier
evaluation is threaded, but viewport data generation is not).
**Benefits**
This moves us closer to a SoA approach rather than the current AoS
paradigm. Accessing a contiguous `float3` is much more efficient than
retrieving data from a larger struct. The memory requirements for
accessing only normals or vertex locations are smaller, and at the
cost of more memory usage for just normals, they now don't have to
be converted between float and short, which also simplifies code
In the future, the remaining items can be removed from `MVert`,
leaving only `float3`, which has similar benefits (see T93602).
Removing the combination of derived and original data makes it
conceptually simpler to only calculate normals when necessary.
This is especially important now that we have more opportunities
for temporary meshes in geometry nodes.
**Performance**
In addition to the theoretical future performance improvements by
making `MVert == float3`, I've done some basic performance testing
on this patch directly. The data is fairly rough, but it gives an idea
about where things stand generally.
- Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms),
showing that accessing just `MVert` is now more efficient.
- Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight
change that at least shows there is no regression.
- Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small
but observable speedup.
- Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms),
shows that using normals in geometry nodes is faster.
- Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms),
shows that calculating normals is slightly faster now.
- File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB),
Normals are not saved in files, which can help with large meshes.
As for memory usage, it may be slightly more in some cases, but
I didn't observe any difference in the production files I tested.
**Tests**
Some modifiers and cycles test results need to be updated with this
commit, for two reasons:
- The subdivision surface modifier is not responsible for calculating
normals anymore. In master, the modifier creates different normals
than the result of the `Mesh` normal calculation, so this is a bug
fix.
- There are small differences in the results of some modifiers that
use normals because they are not converted to and from `short`
anymore.
**Future improvements**
- Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier
already retrieves normals if they are needed anyway.
- Copy normals as part of a better CoW system for attributes.
- Make more areas use lazy instead of eager normal calculation.
- Remove `BKE_mesh_normals_tag_dirty` in more places since that is
now the default state of a new mesh.
- Possibly apply a similar change to derived face corner normals.
Differential Revision: https://developer.blender.org/D12770
2022-01-13 14:37:58 -06:00
|
|
|
copy_v3_v3(dst_vert_normals[i_dst], src_vert_normals[i]);
|
|
|
|
|
mul_mat3_m4_v3(current_offset, dst_vert_normals[i_dst]);
|
|
|
|
|
normalize_v3(dst_vert_normals[i_dst]);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-09-21 10:12:26 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* adjust edge vertex indices */
|
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
|
|
|
me = result_edges + c * chunk_nedges;
|
2014-08-12 13:52:17 +10:00
|
|
|
for (i = 0; i < chunk_nedges; i++, me++) {
|
|
|
|
|
me->v1 += c * chunk_nverts;
|
|
|
|
|
me->v2 += c * chunk_nverts;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
mp = result_polys + c * chunk_npolys;
|
2014-08-12 13:52:17 +10:00
|
|
|
for (i = 0; i < chunk_npolys; i++, mp++) {
|
|
|
|
|
mp->loopstart += c * chunk_nloops;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* adjust loop vertex and edge indices */
|
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
|
|
|
ml = result_loops + c * chunk_nloops;
|
2014-08-12 13:52:17 +10:00
|
|
|
for (i = 0; i < chunk_nloops; i++, ml++) {
|
|
|
|
|
ml->v += c * chunk_nverts;
|
|
|
|
|
ml->e += c * chunk_nedges;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* Handle merge between chunk n and n-1 */
|
2014-09-21 10:12:26 +02:00
|
|
|
if (use_merge && (c >= 1)) {
|
2014-08-12 13:52:17 +10:00
|
|
|
if (!offset_has_scale && (c >= 2)) {
|
|
|
|
|
/* Mapping chunk 3 to chunk 2 is a translation of mapping 2 to 1
|
|
|
|
|
* ... that is except if scaling makes the distance grow */
|
|
|
|
|
int k;
|
|
|
|
|
int this_chunk_index = c * chunk_nverts;
|
|
|
|
|
int prev_chunk_index = (c - 1) * chunk_nverts;
|
|
|
|
|
for (k = 0; k < chunk_nverts; k++, this_chunk_index++, prev_chunk_index++) {
|
|
|
|
|
int target = full_doubles_map[prev_chunk_index];
|
|
|
|
|
if (target != -1) {
|
|
|
|
|
target += chunk_nverts; /* translate mapping */
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
while (target != -1 && !ELEM(full_doubles_map[target], -1, target)) {
|
|
|
|
|
/* If target is already mapped, we only follow that mapping if final target remains
|
|
|
|
|
* close enough from current vert (otherwise no mapping at all). */
|
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
|
|
|
if (compare_len_v3v3(result_positions[this_chunk_index],
|
|
|
|
|
result_positions[full_doubles_map[target]],
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
amd->merge_dist)) {
|
2014-10-05 23:10:44 +02:00
|
|
|
target = full_doubles_map[target];
|
|
|
|
|
}
|
|
|
|
|
else {
|
2014-10-03 14:33:50 +02:00
|
|
|
target = -1;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-10-03 14:33:50 +02:00
|
|
|
}
|
2014-08-12 13:52:17 +10:00
|
|
|
full_doubles_map[this_chunk_index] = target;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-04-21 12:51:47 +00:00
|
|
|
}
|
2014-08-12 13:52:17 +10:00
|
|
|
else {
|
|
|
|
|
dm_mvert_map_doubles(full_doubles_map,
|
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
|
|
|
result_positions,
|
2014-08-12 13:52:17 +10:00
|
|
|
(c - 1) * chunk_nverts,
|
|
|
|
|
chunk_nverts,
|
|
|
|
|
c * chunk_nverts,
|
|
|
|
|
chunk_nverts,
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
amd->merge_dist);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-12-07 04:33:52 +11:00
|
|
|
/* handle UVs */
|
|
|
|
|
if (chunk_nloops > 0 && is_zero_v2(amd->uv_offset) == false) {
|
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
|
|
|
const int totuv = CustomData_number_of_layers(&result->ldata, CD_PROP_FLOAT2);
|
2017-12-07 04:33:52 +11:00
|
|
|
for (i = 0; i < totuv; i++) {
|
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::float2 *dmloopuv = static_cast<blender::float2 *>(
|
2023-01-13 17:21:20 -06:00
|
|
|
CustomData_get_layer_n_for_write(&result->ldata, CD_PROP_FLOAT2, i, result->totloop));
|
2017-12-07 04:33:52 +11:00
|
|
|
dmloopuv += chunk_nloops;
|
|
|
|
|
for (c = 1; c < count; c++) {
|
|
|
|
|
const float uv_offset[2] = {
|
2022-12-12 18:19:32 -06:00
|
|
|
amd->uv_offset[0] * float(c),
|
|
|
|
|
amd->uv_offset[1] * float(c),
|
2017-12-07 04:33:52 +11:00
|
|
|
};
|
|
|
|
|
int l_index = chunk_nloops;
|
|
|
|
|
for (; l_index-- != 0; dmloopuv++) {
|
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
|
|
|
(*dmloopuv)[0] += uv_offset[0];
|
|
|
|
|
(*dmloopuv)[1] += uv_offset[1];
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-07 04:33:52 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
last_chunk_start = (count - 1) * chunk_nverts;
|
|
|
|
|
last_chunk_nverts = chunk_nverts;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
copy_m4_m4(final_offset, current_offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-09-21 10:12:26 +02:00
|
|
|
if (use_merge && (amd->flags & MOD_ARR_MERGEFINAL) && (count > 1)) {
|
2014-08-12 13:52:17 +10:00
|
|
|
/* Merge first and last copies */
|
|
|
|
|
dm_mvert_map_doubles(full_doubles_map,
|
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
|
|
|
result_positions,
|
2014-08-12 13:52:17 +10:00
|
|
|
last_chunk_start,
|
|
|
|
|
last_chunk_nverts,
|
|
|
|
|
first_chunk_start,
|
|
|
|
|
first_chunk_nverts,
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
amd->merge_dist);
|
2012-03-30 17:30:56 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-02-13 08:06:44 +00:00
|
|
|
/* start capping */
|
2018-04-25 16:47:52 +02:00
|
|
|
if (start_cap_mesh) {
|
2014-08-12 13:52:17 +10:00
|
|
|
float start_offset[4][4];
|
|
|
|
|
int start_cap_start = result_nverts - start_cap_nverts - end_cap_nverts;
|
|
|
|
|
invert_m4_m4(start_offset, offset);
|
2018-04-25 16:47:52 +02:00
|
|
|
mesh_merge_transform(result,
|
|
|
|
|
start_cap_mesh,
|
|
|
|
|
start_offset,
|
2014-08-12 13:52:17 +10:00
|
|
|
result_nverts - start_cap_nverts - end_cap_nverts,
|
|
|
|
|
result_nedges - start_cap_nedges - end_cap_nedges,
|
|
|
|
|
result_nloops - start_cap_nloops - end_cap_nloops,
|
|
|
|
|
result_npolys - start_cap_npolys - end_cap_npolys,
|
2018-03-06 09:57:41 +11:00
|
|
|
start_cap_nverts,
|
|
|
|
|
start_cap_nedges,
|
|
|
|
|
start_cap_nloops,
|
|
|
|
|
start_cap_npolys,
|
|
|
|
|
vgroup_start_cap_remap,
|
2021-12-28 16:57:36 +01:00
|
|
|
vgroup_start_cap_remap_len,
|
|
|
|
|
use_recalc_normals);
|
2014-08-12 13:52:17 +10:00
|
|
|
/* Identify doubles with first chunk */
|
2014-09-21 10:12:26 +02:00
|
|
|
if (use_merge) {
|
2014-08-12 13:52:17 +10:00
|
|
|
dm_mvert_map_doubles(full_doubles_map,
|
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
|
|
|
result_positions,
|
2014-08-12 13:52:17 +10:00
|
|
|
first_chunk_start,
|
|
|
|
|
first_chunk_nverts,
|
|
|
|
|
start_cap_start,
|
|
|
|
|
start_cap_nverts,
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
amd->merge_dist);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-02-13 08:06:44 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-25 16:47:52 +02:00
|
|
|
if (end_cap_mesh) {
|
2014-08-12 13:52:17 +10:00
|
|
|
float end_offset[4][4];
|
|
|
|
|
int end_cap_start = result_nverts - end_cap_nverts;
|
|
|
|
|
mul_m4_m4m4(end_offset, current_offset, offset);
|
2018-04-25 16:47:52 +02:00
|
|
|
mesh_merge_transform(result,
|
|
|
|
|
end_cap_mesh,
|
|
|
|
|
end_offset,
|
2014-08-12 13:52:17 +10:00
|
|
|
result_nverts - end_cap_nverts,
|
|
|
|
|
result_nedges - end_cap_nedges,
|
|
|
|
|
result_nloops - end_cap_nloops,
|
|
|
|
|
result_npolys - end_cap_npolys,
|
2018-03-06 09:57:41 +11:00
|
|
|
end_cap_nverts,
|
|
|
|
|
end_cap_nedges,
|
|
|
|
|
end_cap_nloops,
|
|
|
|
|
end_cap_npolys,
|
|
|
|
|
vgroup_end_cap_remap,
|
2021-12-28 16:57:36 +01:00
|
|
|
vgroup_end_cap_remap_len,
|
|
|
|
|
use_recalc_normals);
|
2014-08-12 13:52:17 +10:00
|
|
|
/* Identify doubles with last chunk */
|
2014-09-21 10:12:26 +02:00
|
|
|
if (use_merge) {
|
2014-08-12 13:52:17 +10:00
|
|
|
dm_mvert_map_doubles(full_doubles_map,
|
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
|
|
|
result_positions,
|
2014-08-12 13:52:17 +10:00
|
|
|
last_chunk_start,
|
|
|
|
|
last_chunk_nverts,
|
|
|
|
|
end_cap_start,
|
|
|
|
|
end_cap_nverts,
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
amd->merge_dist);
|
2012-02-13 08:06:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* done capping */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-12 13:52:17 +10:00
|
|
|
/* Handle merging */
|
|
|
|
|
tot_doubles = 0;
|
2014-09-21 10:12:26 +02:00
|
|
|
if (use_merge) {
|
2014-08-12 13:52:17 +10:00
|
|
|
for (i = 0; i < result_nverts; i++) {
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
int new_i = full_doubles_map[i];
|
|
|
|
|
if (new_i != -1) {
|
2019-05-01 07:40:07 +10:00
|
|
|
/* We have to follow chains of doubles
|
|
|
|
|
* (merge start/end especially is likely to create some),
|
2018-10-15 18:11:37 +11:00
|
|
|
* those are not supported at all by BKE_mesh_merge_verts! */
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
while (!ELEM(full_doubles_map[new_i], -1, new_i)) {
|
|
|
|
|
new_i = full_doubles_map[new_i];
|
|
|
|
|
}
|
|
|
|
|
if (i == new_i) {
|
2014-10-03 14:33:50 +02:00
|
|
|
full_doubles_map[i] = -1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
Fix T46455: Array modifier could generate chained mapping of vertices, leading to corrupted geometry.
That was the main issue (in both T46455 and T46690), solved by 'flattening' those chains (v1 -> v2 ->v3 etc.)
before calling `CDDM_merge_verts()`.
Also added note to `CDDM_merge_verts()` that it does not support chained mapping, along with
a basic assert that should catch most of those cases in future.
The logic of 'following mapping' was also rather broken, making a special case here when using
object-controlled offset is very weak. Further more, blindly following mapping in this case
was far from ideal, this could end to merging vertices rather far from each other.
To address this issue, we now always follow mapping, but only as long as 'final' vertex remains
close enough from mapped one.
Finally, the search of 'closest' vertex to merge with was also quite bad, would just pick the first
one matching distance limit, instead of using the actual closest one - could lead to rather ugly
geometry deformations in case one would use not-so-small merge threashold!
2016-01-30 17:17:05 +01:00
|
|
|
full_doubles_map[i] = new_i;
|
2014-10-03 14:33:50 +02:00
|
|
|
tot_doubles++;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-10-03 14:33:50 +02:00
|
|
|
}
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
|
|
|
|
if (tot_doubles > 0) {
|
2018-04-25 16:47:52 +02:00
|
|
|
result = BKE_mesh_merge_verts(
|
|
|
|
|
result, full_doubles_map, tot_doubles, MESH_MERGE_VERTS_DUMP_IF_EQUAL);
|
2014-08-12 13:52:17 +10:00
|
|
|
}
|
|
|
|
|
MEM_freeN(full_doubles_map);
|
2012-03-27 13:08:40 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-06 09:57:41 +11:00
|
|
|
if (vgroup_start_cap_remap) {
|
|
|
|
|
MEM_freeN(vgroup_start_cap_remap);
|
|
|
|
|
}
|
|
|
|
|
if (vgroup_end_cap_remap) {
|
|
|
|
|
MEM_freeN(vgroup_end_cap_remap);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-02-12 15:02:33 +00:00
|
|
|
return result;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-21 13:09:41 +02:00
|
|
|
static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
ArrayModifierData *amd = (ArrayModifierData *)md;
|
2018-05-01 17:33:04 +02:00
|
|
|
return arrayModifier_doArray(amd, ctx, mesh);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
static bool isDisabled(const Scene * /*scene*/, ModifierData *md, bool /*useRenderParams*/)
|
2019-08-23 15:50:53 +02:00
|
|
|
{
|
|
|
|
|
ArrayModifierData *amd = (ArrayModifierData *)md;
|
|
|
|
|
|
|
|
|
|
/* The object type check is only needed here in case we have a placeholder
|
|
|
|
|
* object assigned (because the library containing the curve/mesh is missing).
|
|
|
|
|
*
|
2019-08-31 01:19:22 +10:00
|
|
|
* In other cases it should be impossible to have a type mismatch.
|
2019-08-23 15:50:53 +02:00
|
|
|
*/
|
|
|
|
|
|
2022-02-18 09:50:29 -06:00
|
|
|
if (amd->curve_ob && amd->curve_ob->type != OB_CURVES_LEGACY) {
|
2019-08-23 15:50:53 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2020-08-07 12:40:29 +02:00
|
|
|
if (amd->start_cap && amd->start_cap->type != OB_MESH) {
|
2019-08-23 15:50:53 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2020-08-07 12:40:29 +02:00
|
|
|
if (amd->end_cap && amd->end_cap->type != OB_MESH) {
|
2019-08-23 15:50:53 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
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 *layout = panel->layout;
|
|
|
|
|
|
|
|
|
|
PointerRNA ob_ptr;
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
uiItemR(layout, ptr, "fit_type", 0, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
int fit_type = RNA_enum_get(ptr, "fit_type");
|
2020-06-05 10:41:03 -04:00
|
|
|
if (fit_type == MOD_ARR_FIXEDCOUNT) {
|
2022-12-12 18:19:32 -06:00
|
|
|
uiItemR(layout, ptr, "count", 0, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
else if (fit_type == MOD_ARR_FITLENGTH) {
|
2022-12-12 18:19:32 -06:00
|
|
|
uiItemR(layout, ptr, "fit_length", 0, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
else if (fit_type == MOD_ARR_FITCURVE) {
|
2022-12-12 18:19:32 -06:00
|
|
|
uiItemR(layout, ptr, "curve", 0, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
modifier_panel_end(layout, ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
static void relative_offset_header_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
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
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
uiItemR(layout, ptr, "use_relative_offset", 0, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
static void relative_offset_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
uiLayout *col = uiLayoutColumn(layout, false);
|
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_relative_offset"));
|
|
|
|
|
uiItemR(col, ptr, "relative_offset_displace", 0, IFACE_("Factor"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
static void constant_offset_header_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
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
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
uiItemR(layout, ptr, "use_constant_offset", 0, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
static void constant_offset_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
uiLayout *col = uiLayoutColumn(layout, false);
|
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_constant_offset"));
|
|
|
|
|
uiItemR(col, ptr, "constant_offset_displace", 0, IFACE_("Distance"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Object offset in a subpanel for consistency with the other offset types.
|
|
|
|
|
*/
|
2022-12-12 18:19:32 -06:00
|
|
|
static void object_offset_header_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
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
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
uiItemR(layout, ptr, "use_object_offset", 0, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
static void object_offset_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
uiLayout *col = uiLayoutColumn(layout, false);
|
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_object_offset"));
|
|
|
|
|
uiItemR(col, ptr, "offset_object", 0, IFACE_("Object"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
static void symmetry_panel_header_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
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
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(layout, ptr, "use_merge_vertices", 0, IFACE_("Merge"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
static void symmetry_panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
uiLayout *col = uiLayoutColumn(layout, false);
|
2020-09-02 14:13:26 -05:00
|
|
|
uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_merge_vertices"));
|
|
|
|
|
uiItemR(col, ptr, "merge_threshold", 0, IFACE_("Distance"), ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "use_merge_vertices_cap", 0, IFACE_("First and Last Copies"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
static void uv_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, true);
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(col, ptr, "offset_u", UI_ITEM_R_EXPAND, IFACE_("Offset U"), ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "offset_v", UI_ITEM_R_EXPAND, IFACE_("V"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
static void caps_panel_draw(const bContext * /*C*/, Panel *panel)
|
UI: Small Tweaks to Modifier Layouts for Consistency
These changes are smaller, made based on feedback and a pass on all
the layouts for clarity and consistency. The Multires modifier UI will
be addressed in a separate patch. Here is an overview of the changes:
Renaming Options:
- Build: "Start" -> "Start Frame"
- Curve: "From Radius" -> "Size from Radius"
- Screw: "Calc Order" -> "Calculate Order"
- Displace, Warp, Wave: "Texture Coordinates Object" -> "Object"
Move Mode Toggle to Top & Expand:
- Bevel, Boolean, Normal Edit, Subdivision
Use Columns for Tighter Spacing:
- Displace, Explode, Ocean, Particle Instance, Remesh, Shrinkwrap,
Solidify, Warp, Weighted Normal, Wave
Misc:
- Bevel: Set inactive properties for vertex bevel
- Mesh Sequence Cache: Remove box for cache file
- Skin: Don't align "Mark Loose" and "Clear Loose"
- Array: Expand relative offset subpanel by default
- Array: Move start cap, end cap to a new subpanel
- Bevel: Move width type above width
Differential Revision: https://developer.blender.org/D8115
2020-07-02 10:47:02 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *col;
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
2022-12-12 18:19:32 -06:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, nullptr);
|
UI: Small Tweaks to Modifier Layouts for Consistency
These changes are smaller, made based on feedback and a pass on all
the layouts for clarity and consistency. The Multires modifier UI will
be addressed in a separate patch. Here is an overview of the changes:
Renaming Options:
- Build: "Start" -> "Start Frame"
- Curve: "From Radius" -> "Size from Radius"
- Screw: "Calc Order" -> "Calculate Order"
- Displace, Warp, Wave: "Texture Coordinates Object" -> "Object"
Move Mode Toggle to Top & Expand:
- Bevel, Boolean, Normal Edit, Subdivision
Use Columns for Tighter Spacing:
- Displace, Explode, Ocean, Particle Instance, Remesh, Shrinkwrap,
Solidify, Warp, Weighted Normal, Wave
Misc:
- Bevel: Set inactive properties for vertex bevel
- Mesh Sequence Cache: Remove box for cache file
- Skin: Don't align "Mark Loose" and "Clear Loose"
- Array: Expand relative offset subpanel by default
- Array: Move start cap, end cap to a new subpanel
- Bevel: Move width type above width
Differential Revision: https://developer.blender.org/D8115
2020-07-02 10:47:02 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
|
|
|
|
col = uiLayoutColumn(layout, false);
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(col, ptr, "start_cap", 0, IFACE_("Cap Start"), ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "end_cap", 0, IFACE_("End"), ICON_NONE);
|
UI: Small Tweaks to Modifier Layouts for Consistency
These changes are smaller, made based on feedback and a pass on all
the layouts for clarity and consistency. The Multires modifier UI will
be addressed in a separate patch. Here is an overview of the changes:
Renaming Options:
- Build: "Start" -> "Start Frame"
- Curve: "From Radius" -> "Size from Radius"
- Screw: "Calc Order" -> "Calculate Order"
- Displace, Warp, Wave: "Texture Coordinates Object" -> "Object"
Move Mode Toggle to Top & Expand:
- Bevel, Boolean, Normal Edit, Subdivision
Use Columns for Tighter Spacing:
- Displace, Explode, Ocean, Particle Instance, Remesh, Shrinkwrap,
Solidify, Warp, Weighted Normal, Wave
Misc:
- Bevel: Set inactive properties for vertex bevel
- Mesh Sequence Cache: Remove box for cache file
- Skin: Don't align "Mark Loose" and "Clear Loose"
- Array: Expand relative offset subpanel by default
- Array: Move start cap, end cap to a new subpanel
- Bevel: Move width type above width
Differential Revision: https://developer.blender.org/D8115
2020-07-02 10:47:02 -04:00
|
|
|
}
|
|
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
static void panelRegister(ARegionType *region_type)
|
|
|
|
|
{
|
|
|
|
|
PanelType *panel_type = modifier_panel_register(region_type, eModifierType_Array, panel_draw);
|
|
|
|
|
modifier_subpanel_register(region_type,
|
|
|
|
|
"relative_offset",
|
|
|
|
|
"",
|
|
|
|
|
relative_offset_header_draw,
|
|
|
|
|
relative_offset_draw,
|
|
|
|
|
panel_type);
|
|
|
|
|
modifier_subpanel_register(region_type,
|
|
|
|
|
"constant_offset",
|
|
|
|
|
"",
|
|
|
|
|
constant_offset_header_draw,
|
|
|
|
|
constant_offset_draw,
|
|
|
|
|
panel_type);
|
|
|
|
|
modifier_subpanel_register(
|
|
|
|
|
region_type, "object_offset", "", object_offset_header_draw, object_offset_draw, panel_type);
|
|
|
|
|
modifier_subpanel_register(
|
|
|
|
|
region_type, "merge", "", symmetry_panel_header_draw, symmetry_panel_draw, panel_type);
|
2022-12-12 18:19:32 -06:00
|
|
|
modifier_subpanel_register(region_type, "uv", "UVs", nullptr, uv_panel_draw, panel_type);
|
|
|
|
|
modifier_subpanel_register(region_type, "caps", "Caps", nullptr, caps_panel_draw, panel_type);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
ModifierTypeInfo modifierType_Array = {
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("Array"),
|
|
|
|
|
/*structName*/ "ArrayModifierData",
|
|
|
|
|
/*structSize*/ sizeof(ArrayModifierData),
|
|
|
|
|
/*srna*/ &RNA_ArrayModifier,
|
|
|
|
|
/*type*/ eModifierTypeType_Constructive,
|
|
|
|
|
/*flags*/ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsMapping |
|
2012-05-06 13:38:33 +00:00
|
|
|
eModifierTypeFlag_SupportsEditmode | eModifierTypeFlag_EnableInEditmode |
|
|
|
|
|
eModifierTypeFlag_AcceptsCVs,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*icon*/ ICON_MOD_ARRAY,
|
|
|
|
|
|
|
|
|
|
/*copyData*/ BKE_modifier_copydata_generic,
|
|
|
|
|
|
|
|
|
|
/*deformVerts*/ nullptr,
|
|
|
|
|
/*deformMatrices*/ nullptr,
|
|
|
|
|
/*deformVertsEM*/ nullptr,
|
|
|
|
|
/*deformMatricesEM*/ nullptr,
|
|
|
|
|
/*modifyMesh*/ modifyMesh,
|
|
|
|
|
/*modifyGeometrySet*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*initData*/ initData,
|
|
|
|
|
/*requiredDataMask*/ nullptr,
|
|
|
|
|
/*freeData*/ nullptr,
|
|
|
|
|
/*isDisabled*/ isDisabled,
|
|
|
|
|
/*updateDepsgraph*/ updateDepsgraph,
|
|
|
|
|
/*dependsOnTime*/ nullptr,
|
|
|
|
|
/*dependsOnNormals*/ nullptr,
|
|
|
|
|
/*foreachIDLink*/ foreachIDLink,
|
|
|
|
|
/*foreachTexLink*/ nullptr,
|
|
|
|
|
/*freeRuntimeData*/ nullptr,
|
|
|
|
|
/*panelRegister*/ panelRegister,
|
|
|
|
|
/*blendWrite*/ nullptr,
|
|
|
|
|
/*blendRead*/ nullptr,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|