2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup modifiers
|
2011-02-25 13:57:17 +00:00
|
|
|
*/
|
|
|
|
|
|
Mesh: Move selection flags to generic attributes
Using the attribute name semantics from T97452, this patch moves the
selection status of mesh elements from the `SELECT` of vertices, and
edges, and the `ME_FACE_SEL` of faces to generic boolean attribute
Storing this data as generic attributes can significantly simplify and
improve code, as described in T95965.
The attributes are called `.select_vert`, `.select_edge`, and
`.select_poly`. The `.` prefix means they are "UI attributes",so they
still contain original data edited by users, but they aren't meant to
be accessed procedurally by the user in arbitrary situations. They are
also be hidden in the spreadsheet and the attribute list.
Until 4.0, the attributes are still written to and read from the mesh
in the old way, so neither forward nor backward compatibility are
affected. This means memory requirements will be increased by one byte
per element when selection is used. When the flags are removed
completely, requirements will decrease.
Further notes:
* The `MVert` flag is empty at runtime now, so it can be ignored.
* `BMesh` is unchanged, otherwise the change would be much larger.
* Many tests have slightly different results, since the selection
attribute uses more generic propagation. Previously you couldn't
really rely on edit mode selections being propagated procedurally.
Now it mostly works as expected.
Similar to 2480b55f216c
Ref T95965
Differential Revision: https://developer.blender.org/D15795
2022-09-23 09:38:37 -05:00
|
|
|
#define DNA_DEPRECATED_ALLOW /* For #ME_FACE_SEL. */
|
|
|
|
|
|
2019-02-25 11:56:24 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_kdtree.h"
|
2023-10-24 18:44:24 +02:00
|
|
|
#include "BLI_map.hh"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_matrix.h"
|
|
|
|
|
#include "BLI_math_rotation.h"
|
|
|
|
|
#include "BLI_math_vector.h"
|
2019-02-25 11:56:24 +01:00
|
|
|
#include "BLI_rand.h"
|
|
|
|
|
|
2024-02-09 18:59:42 +01:00
|
|
|
#include "BLT_translation.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
#include "DNA_defaults.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2012-04-30 08:24:44 +00:00
|
|
|
#include "DNA_object_types.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "DNA_screen_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-12-26 23:21:19 -05:00
|
|
|
#include "BKE_customdata.hh"
|
2024-01-29 18:57:16 -05:00
|
|
|
#include "BKE_deform.hh"
|
2024-01-15 12:44:04 -05:00
|
|
|
#include "BKE_lib_id.hh"
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2023-08-02 22:14:18 +02:00
|
|
|
#include "BKE_mesh_legacy_convert.hh"
|
2023-11-14 09:30:40 +01:00
|
|
|
#include "BKE_modifier.hh"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_particle.h"
|
2024-02-10 19:16:25 +01:00
|
|
|
#include "BKE_scene.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface.hh"
|
|
|
|
|
#include "UI_resources.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2024-07-10 18:30:02 +02:00
|
|
|
#include "RNA_prototypes.hh"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph_query.hh"
|
2018-06-22 15:03:42 +02:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include "MOD_ui_common.hh"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void init_data(ModifierData *md)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
ExplodeModifierData *emd = (ExplodeModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2025-05-20 17:32:49 +02:00
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(emd, modifier));
|
|
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(emd, DNA_struct_default_get(ExplodeModifierData), modifier);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2023-07-27 12:04:18 +10:00
|
|
|
static void free_data(ModifierData *md)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
ExplodeModifierData *emd = (ExplodeModifierData *)md;
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2018-05-08 14:21:02 +02:00
|
|
|
MEM_SAFE_FREE(emd->facepa);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2023-07-27 12:04:18 +10:00
|
|
|
static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2013-12-22 04:35:52 +11:00
|
|
|
#if 0
|
2019-04-17 08:24:14 +02:00
|
|
|
const ExplodeModifierData *emd = (const ExplodeModifierData *)md;
|
2013-12-22 04:35:52 +11:00
|
|
|
#endif
|
2012-05-06 13:38:33 +00:00
|
|
|
ExplodeModifierData *temd = (ExplodeModifierData *)target;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_copydata_generic(md, target, flag);
|
2013-12-22 04:35:52 +11:00
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
temd->facepa = nullptr;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2023-07-27 12:04:18 +10:00
|
|
|
static bool depends_on_time(Scene * /*scene*/, ModifierData * /*md*/)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2013-06-02 03:59:19 +00:00
|
|
|
return true;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2023-07-27 12:04:18 +10:00
|
|
|
static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
ExplodeModifierData *emd = (ExplodeModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
if (emd->vgroup) {
|
|
|
|
|
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
|
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-12 08:04:56 +02:00
|
|
|
static void createFacepa(ExplodeModifierData *emd, ParticleSystemModifierData *psmd, Mesh *mesh)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
|
ParticleSystem *psys = psmd->psys;
|
2023-01-19 15:54:47 -06:00
|
|
|
MFace *fa = nullptr, *mface = nullptr;
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleData *pa;
|
2019-03-20 00:46:33 +11:00
|
|
|
KDTree_3d *tree;
|
2016-12-28 17:30:58 +01:00
|
|
|
RNG *rng;
|
|
|
|
|
float center[3], co[3];
|
2023-01-19 15:54:47 -06:00
|
|
|
int *facepa = nullptr, *vertpa = nullptr, totvert = 0, totface = 0, totpart = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
int i, p, v1, v2, v3, v4 = 0;
|
2020-02-18 17:03:20 +01:00
|
|
|
const bool invert_vgroup = (emd->flag & eExplodeFlag_INVERT_VGROUP) != 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-06-14 11:59:32 -04:00
|
|
|
blender::MutableSpan<blender::float3> positions = mesh->vert_positions_for_write();
|
2023-07-24 22:06:55 +02:00
|
|
|
mface = (MFace *)CustomData_get_layer_for_write(
|
|
|
|
|
&mesh->fdata_legacy, CD_MFACE, mesh->totface_legacy);
|
2023-12-20 02:21:48 +01:00
|
|
|
totvert = mesh->verts_num;
|
2023-07-24 22:06:55 +02:00
|
|
|
totface = mesh->totface_legacy;
|
2016-12-28 17:30:58 +01:00
|
|
|
totpart = psmd->psys->totpart;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
rng = BLI_rng_new_srandom(psys->seed);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
if (emd->facepa) {
|
2016-12-28 17:30:58 +01:00
|
|
|
MEM_freeN(emd->facepa);
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2025-04-12 17:17:24 +02:00
|
|
|
facepa = emd->facepa = MEM_calloc_arrayN<int>(totface, __func__);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-04-12 17:17:24 +02:00
|
|
|
vertpa = MEM_calloc_arrayN<int>(totvert, __func__);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* initialize all faces & verts to no particle */
|
2018-09-25 12:35:43 +02:00
|
|
|
for (i = 0; i < totface; i++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[i] = totpart;
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
|
|
|
|
for (i = 0; i < totvert; i++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
vertpa[i] = totpart;
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* set protected verts */
|
|
|
|
|
if (emd->vgroup) {
|
2023-12-12 20:45:16 -05:00
|
|
|
const MDeformVert *dvert = mesh->deform_verts().data();
|
2016-12-28 17:30:58 +01:00
|
|
|
if (dvert) {
|
|
|
|
|
const int defgrp_index = emd->vgroup - 1;
|
|
|
|
|
for (i = 0; i < totvert; i++, dvert++) {
|
|
|
|
|
float val = BLI_rng_get_float(rng);
|
|
|
|
|
val = (1.0f - emd->protect) * val + emd->protect * 0.5f;
|
2020-03-06 12:50:56 +11:00
|
|
|
const float weight = invert_vgroup ? 1.0f - BKE_defvert_find_weight(dvert, defgrp_index) :
|
|
|
|
|
BKE_defvert_find_weight(dvert, defgrp_index);
|
2020-02-18 17:03:20 +01:00
|
|
|
if (val < weight) {
|
2016-12-28 17:30:58 +01:00
|
|
|
vertpa[i] = -1;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* make tree of emitter locations */
|
2019-03-20 00:46:33 +11:00
|
|
|
tree = BLI_kdtree_3d_new(totpart);
|
2016-12-28 17:30:58 +01:00
|
|
|
for (p = 0, pa = psys->particles; p < totpart; p++, pa++) {
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
psys_particle_on_emitter(psmd,
|
|
|
|
|
psys->part->from,
|
|
|
|
|
pa->num,
|
|
|
|
|
pa->num_dmcache,
|
|
|
|
|
pa->fuv,
|
|
|
|
|
pa->foffset,
|
|
|
|
|
co,
|
2023-01-19 15:54:47 -06:00
|
|
|
nullptr,
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr);
|
2019-03-20 00:46:33 +11:00
|
|
|
BLI_kdtree_3d_insert(tree, p, co);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-03-20 00:46:33 +11:00
|
|
|
BLI_kdtree_3d_balance(tree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* set face-particle-indexes to nearest particle to face center */
|
|
|
|
|
for (i = 0, fa = mface; i < totface; i++, fa++) {
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
add_v3_v3v3(center, positions[fa->v1], positions[fa->v2]);
|
|
|
|
|
add_v3_v3(center, positions[fa->v3]);
|
2016-12-28 17:30:58 +01:00
|
|
|
if (fa->v4) {
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
add_v3_v3(center, positions[fa->v4]);
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_v3_fl(center, 0.25);
|
|
|
|
|
}
|
2018-09-25 12:35:43 +02:00
|
|
|
else {
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_v3_fl(center, 1.0f / 3.0f);
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
p = BLI_kdtree_3d_find_nearest(tree, center, nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
v1 = vertpa[fa->v1];
|
|
|
|
|
v2 = vertpa[fa->v2];
|
|
|
|
|
v3 = vertpa[fa->v3];
|
2018-09-25 12:35:43 +02:00
|
|
|
if (fa->v4) {
|
2016-12-28 17:30:58 +01:00
|
|
|
v4 = vertpa[fa->v4];
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
if (v1 >= 0 && v2 >= 0 && v3 >= 0 && (fa->v4 == 0 || v4 >= 0)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[i] = p;
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
if (v1 >= 0) {
|
|
|
|
|
vertpa[fa->v1] = p;
|
|
|
|
|
}
|
|
|
|
|
if (v2 >= 0) {
|
|
|
|
|
vertpa[fa->v2] = p;
|
|
|
|
|
}
|
|
|
|
|
if (v3 >= 0) {
|
|
|
|
|
vertpa[fa->v3] = p;
|
|
|
|
|
}
|
|
|
|
|
if (fa->v4 && v4 >= 0) {
|
|
|
|
|
vertpa[fa->v4] = p;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
if (vertpa) {
|
|
|
|
|
MEM_freeN(vertpa);
|
|
|
|
|
}
|
2019-03-20 00:46:33 +11:00
|
|
|
BLI_kdtree_3d_free(tree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
BLI_rng_free(rng);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-24 18:44:24 +02:00
|
|
|
static int edgecut_get(const blender::Map<blender::OrderedEdge, int> &edgehash, uint v1, uint v2)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2023-10-24 18:44:24 +02:00
|
|
|
return edgehash.lookup({int(v1), int(v2)});
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const short add_faces[24] = {
|
|
|
|
|
0, 0, 0, 2, 0, 1, 2, 2, 0, 2, 1, 2, 2, 2, 2, 3, 0, 0, 0, 1, 0, 1, 1, 2,
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static MFace *get_dface(Mesh *mesh, Mesh *split, int cur, int i, MFace *mf)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2023-01-19 15:54:47 -06:00
|
|
|
MFace *mfaces = static_cast<MFace *>(
|
2023-07-24 22:06:55 +02:00
|
|
|
CustomData_get_layer_for_write(&split->fdata_legacy, CD_MFACE, split->totface_legacy));
|
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
|
|
|
MFace *df = &mfaces[cur];
|
2023-07-24 22:06:55 +02:00
|
|
|
CustomData_copy_data(&mesh->fdata_legacy, &split->fdata_legacy, i, cur, 1);
|
2016-12-28 17:30:58 +01:00
|
|
|
*df = *mf;
|
|
|
|
|
return df;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define SET_VERTS(a, b, c, d) \
|
|
|
|
|
{ \
|
|
|
|
|
v[0] = mf->v##a; \
|
|
|
|
|
uv[0] = a - 1; \
|
|
|
|
|
v[1] = mf->v##b; \
|
|
|
|
|
uv[1] = b - 1; \
|
|
|
|
|
v[2] = mf->v##c; \
|
|
|
|
|
uv[2] = c - 1; \
|
|
|
|
|
v[3] = mf->v##d; \
|
|
|
|
|
uv[3] = d - 1; \
|
|
|
|
|
} \
|
|
|
|
|
(void)0
|
|
|
|
|
|
|
|
|
|
#define GET_ES(v1, v2) edgecut_get(eh, v1, v2)
|
|
|
|
|
#define INT_UV(uvf, c0, c1) mid_v2_v2v2(uvf, mf->uv[c0], mf->uv[c1])
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static void remap_faces_3_6_9_12(Mesh *mesh,
|
|
|
|
|
Mesh *split,
|
|
|
|
|
MFace *mf,
|
|
|
|
|
int *facepa,
|
2020-07-13 11:27:09 +02:00
|
|
|
const int *vertpa,
|
2018-09-25 12:35:43 +02:00
|
|
|
int i,
|
2023-10-24 18:44:24 +02:00
|
|
|
const blender::Map<blender::OrderedEdge, int> &eh,
|
2018-09-25 12:35:43 +02:00
|
|
|
int cur,
|
|
|
|
|
int v1,
|
|
|
|
|
int v2,
|
|
|
|
|
int v3,
|
|
|
|
|
int v4)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-09-25 12:35:43 +02:00
|
|
|
MFace *df1 = get_dface(mesh, split, cur, i, mf);
|
|
|
|
|
MFace *df2 = get_dface(mesh, split, cur + 1, i, mf);
|
|
|
|
|
MFace *df3 = get_dface(mesh, split, cur + 2, i, mf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur] = vertpa[v1];
|
|
|
|
|
df1->v1 = v1;
|
|
|
|
|
df1->v2 = GET_ES(v1, v2);
|
|
|
|
|
df1->v3 = GET_ES(v2, v3);
|
|
|
|
|
df1->v4 = v3;
|
|
|
|
|
df1->flag |= ME_FACE_SEL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur + 1] = vertpa[v2];
|
|
|
|
|
df2->v1 = GET_ES(v1, v2);
|
|
|
|
|
df2->v2 = v2;
|
|
|
|
|
df2->v3 = GET_ES(v2, v3);
|
|
|
|
|
df2->v4 = 0;
|
|
|
|
|
df2->flag &= ~ME_FACE_SEL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur + 2] = vertpa[v1];
|
|
|
|
|
df3->v1 = v1;
|
|
|
|
|
df3->v2 = v3;
|
|
|
|
|
df3->v3 = v4;
|
|
|
|
|
df3->v4 = 0;
|
|
|
|
|
df3->flag &= ~ME_FACE_SEL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static void remap_uvs_3_6_9_12(
|
2022-03-28 12:29:47 +11:00
|
|
|
Mesh *mesh, Mesh *split, int layers_num, int i, int cur, int c0, int c1, int c2, int c3)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
|
MTFace *mf, *df1, *df2, *df3;
|
|
|
|
|
int l;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
for (l = 0; l < layers_num; l++) {
|
2023-07-24 22:06:55 +02:00
|
|
|
mf = static_cast<MTFace *>(CustomData_get_layer_n_for_write(
|
|
|
|
|
&split->fdata_legacy, CD_MTFACE, l, split->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
df1 = mf + cur;
|
|
|
|
|
df2 = df1 + 1;
|
|
|
|
|
df3 = df1 + 2;
|
2023-01-19 15:54:47 -06:00
|
|
|
mf = static_cast<MTFace *>(
|
2023-07-24 22:06:55 +02:00
|
|
|
CustomData_get_layer_n_for_write(&mesh->fdata_legacy, CD_MTFACE, l, mesh->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
mf += i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v2_v2(df1->uv[0], mf->uv[c0]);
|
|
|
|
|
INT_UV(df1->uv[1], c0, c1);
|
|
|
|
|
INT_UV(df1->uv[2], c1, c2);
|
|
|
|
|
copy_v2_v2(df1->uv[3], mf->uv[c2]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
INT_UV(df2->uv[0], c0, c1);
|
|
|
|
|
copy_v2_v2(df2->uv[1], mf->uv[c1]);
|
|
|
|
|
INT_UV(df2->uv[2], c1, c2);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v2_v2(df3->uv[0], mf->uv[c0]);
|
|
|
|
|
copy_v2_v2(df3->uv[1], mf->uv[c2]);
|
|
|
|
|
copy_v2_v2(df3->uv[2], mf->uv[c3]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static void remap_faces_5_10(Mesh *mesh,
|
|
|
|
|
Mesh *split,
|
|
|
|
|
MFace *mf,
|
|
|
|
|
int *facepa,
|
2020-07-13 11:27:09 +02:00
|
|
|
const int *vertpa,
|
2018-09-25 12:35:43 +02:00
|
|
|
int i,
|
2023-10-24 18:44:24 +02:00
|
|
|
const blender::Map<blender::OrderedEdge, int> &eh,
|
2018-09-25 12:35:43 +02:00
|
|
|
int cur,
|
|
|
|
|
int v1,
|
|
|
|
|
int v2,
|
|
|
|
|
int v3,
|
|
|
|
|
int v4)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-09-25 12:35:43 +02:00
|
|
|
MFace *df1 = get_dface(mesh, split, cur, i, mf);
|
|
|
|
|
MFace *df2 = get_dface(mesh, split, cur + 1, i, mf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur] = vertpa[v1];
|
|
|
|
|
df1->v1 = v1;
|
|
|
|
|
df1->v2 = v2;
|
|
|
|
|
df1->v3 = GET_ES(v2, v3);
|
|
|
|
|
df1->v4 = GET_ES(v1, v4);
|
|
|
|
|
df1->flag |= ME_FACE_SEL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur + 1] = vertpa[v3];
|
|
|
|
|
df2->v1 = GET_ES(v1, v4);
|
|
|
|
|
df2->v2 = GET_ES(v2, v3);
|
|
|
|
|
df2->v3 = v3;
|
|
|
|
|
df2->v4 = v4;
|
|
|
|
|
df2->flag |= ME_FACE_SEL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static void remap_uvs_5_10(
|
2022-03-28 12:29:47 +11:00
|
|
|
Mesh *mesh, Mesh *split, int layers_num, int i, int cur, int c0, int c1, int c2, int c3)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
|
MTFace *mf, *df1, *df2;
|
|
|
|
|
int l;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
for (l = 0; l < layers_num; l++) {
|
2023-07-24 22:06:55 +02:00
|
|
|
mf = static_cast<MTFace *>(CustomData_get_layer_n_for_write(
|
|
|
|
|
&split->fdata_legacy, CD_MTFACE, l, split->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
df1 = mf + cur;
|
|
|
|
|
df2 = df1 + 1;
|
2023-01-19 15:54:47 -06:00
|
|
|
mf = static_cast<MTFace *>(
|
2023-07-24 22:06:55 +02:00
|
|
|
CustomData_get_layer_n_for_write(&mesh->fdata_legacy, CD_MTFACE, l, mesh->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
mf += i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v2_v2(df1->uv[0], mf->uv[c0]);
|
|
|
|
|
copy_v2_v2(df1->uv[1], mf->uv[c1]);
|
|
|
|
|
INT_UV(df1->uv[2], c1, c2);
|
|
|
|
|
INT_UV(df1->uv[3], c0, c3);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
INT_UV(df2->uv[0], c0, c3);
|
|
|
|
|
INT_UV(df2->uv[1], c1, c2);
|
|
|
|
|
copy_v2_v2(df2->uv[2], mf->uv[c2]);
|
|
|
|
|
copy_v2_v2(df2->uv[3], mf->uv[c3]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static void remap_faces_15(Mesh *mesh,
|
|
|
|
|
Mesh *split,
|
|
|
|
|
MFace *mf,
|
|
|
|
|
int *facepa,
|
2020-07-13 11:27:09 +02:00
|
|
|
const int *vertpa,
|
2018-09-25 12:35:43 +02:00
|
|
|
int i,
|
2023-10-24 18:44:24 +02:00
|
|
|
const blender::Map<blender::OrderedEdge, int> &eh,
|
2018-09-25 12:35:43 +02:00
|
|
|
int cur,
|
|
|
|
|
int v1,
|
|
|
|
|
int v2,
|
|
|
|
|
int v3,
|
|
|
|
|
int v4)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-09-25 12:35:43 +02:00
|
|
|
MFace *df1 = get_dface(mesh, split, cur, i, mf);
|
|
|
|
|
MFace *df2 = get_dface(mesh, split, cur + 1, i, mf);
|
|
|
|
|
MFace *df3 = get_dface(mesh, split, cur + 2, i, mf);
|
|
|
|
|
MFace *df4 = get_dface(mesh, split, cur + 3, i, mf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur] = vertpa[v1];
|
|
|
|
|
df1->v1 = v1;
|
|
|
|
|
df1->v2 = GET_ES(v1, v2);
|
|
|
|
|
df1->v3 = GET_ES(v1, v3);
|
|
|
|
|
df1->v4 = GET_ES(v1, v4);
|
|
|
|
|
df1->flag |= ME_FACE_SEL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur + 1] = vertpa[v2];
|
|
|
|
|
df2->v1 = GET_ES(v1, v2);
|
|
|
|
|
df2->v2 = v2;
|
|
|
|
|
df2->v3 = GET_ES(v2, v3);
|
|
|
|
|
df2->v4 = GET_ES(v1, v3);
|
|
|
|
|
df2->flag |= ME_FACE_SEL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur + 2] = vertpa[v3];
|
|
|
|
|
df3->v1 = GET_ES(v1, v3);
|
|
|
|
|
df3->v2 = GET_ES(v2, v3);
|
|
|
|
|
df3->v3 = v3;
|
|
|
|
|
df3->v4 = GET_ES(v3, v4);
|
|
|
|
|
df3->flag |= ME_FACE_SEL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur + 3] = vertpa[v4];
|
|
|
|
|
df4->v1 = GET_ES(v1, v4);
|
|
|
|
|
df4->v2 = GET_ES(v1, v3);
|
|
|
|
|
df4->v3 = GET_ES(v3, v4);
|
|
|
|
|
df4->v4 = v4;
|
|
|
|
|
df4->flag |= ME_FACE_SEL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static void remap_uvs_15(
|
2022-03-28 12:29:47 +11:00
|
|
|
Mesh *mesh, Mesh *split, int layers_num, int i, int cur, int c0, int c1, int c2, int c3)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
|
MTFace *mf, *df1, *df2, *df3, *df4;
|
|
|
|
|
int l;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
for (l = 0; l < layers_num; l++) {
|
2023-07-24 22:06:55 +02:00
|
|
|
mf = static_cast<MTFace *>(CustomData_get_layer_n_for_write(
|
|
|
|
|
&split->fdata_legacy, CD_MTFACE, l, split->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
df1 = mf + cur;
|
|
|
|
|
df2 = df1 + 1;
|
|
|
|
|
df3 = df1 + 2;
|
|
|
|
|
df4 = df1 + 3;
|
2023-01-19 15:54:47 -06:00
|
|
|
mf = static_cast<MTFace *>(
|
2023-07-24 22:06:55 +02:00
|
|
|
CustomData_get_layer_n_for_write(&mesh->fdata_legacy, CD_MTFACE, l, mesh->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
mf += i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v2_v2(df1->uv[0], mf->uv[c0]);
|
|
|
|
|
INT_UV(df1->uv[1], c0, c1);
|
|
|
|
|
INT_UV(df1->uv[2], c0, c2);
|
|
|
|
|
INT_UV(df1->uv[3], c0, c3);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
INT_UV(df2->uv[0], c0, c1);
|
|
|
|
|
copy_v2_v2(df2->uv[1], mf->uv[c1]);
|
|
|
|
|
INT_UV(df2->uv[2], c1, c2);
|
|
|
|
|
INT_UV(df2->uv[3], c0, c2);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
INT_UV(df3->uv[0], c0, c2);
|
|
|
|
|
INT_UV(df3->uv[1], c1, c2);
|
|
|
|
|
copy_v2_v2(df3->uv[2], mf->uv[c2]);
|
|
|
|
|
INT_UV(df3->uv[3], c2, c3);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
INT_UV(df4->uv[0], c0, c3);
|
|
|
|
|
INT_UV(df4->uv[1], c0, c2);
|
|
|
|
|
INT_UV(df4->uv[2], c2, c3);
|
|
|
|
|
copy_v2_v2(df4->uv[3], mf->uv[c3]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static void remap_faces_7_11_13_14(Mesh *mesh,
|
|
|
|
|
Mesh *split,
|
|
|
|
|
MFace *mf,
|
|
|
|
|
int *facepa,
|
2020-07-13 11:27:09 +02:00
|
|
|
const int *vertpa,
|
2018-09-25 12:35:43 +02:00
|
|
|
int i,
|
2023-10-24 18:44:24 +02:00
|
|
|
const blender::Map<blender::OrderedEdge, int> &eh,
|
2018-09-25 12:35:43 +02:00
|
|
|
int cur,
|
|
|
|
|
int v1,
|
|
|
|
|
int v2,
|
|
|
|
|
int v3,
|
|
|
|
|
int v4)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-09-25 12:35:43 +02:00
|
|
|
MFace *df1 = get_dface(mesh, split, cur, i, mf);
|
|
|
|
|
MFace *df2 = get_dface(mesh, split, cur + 1, i, mf);
|
|
|
|
|
MFace *df3 = get_dface(mesh, split, cur + 2, i, mf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur] = vertpa[v1];
|
|
|
|
|
df1->v1 = v1;
|
|
|
|
|
df1->v2 = GET_ES(v1, v2);
|
|
|
|
|
df1->v3 = GET_ES(v2, v3);
|
|
|
|
|
df1->v4 = GET_ES(v1, v4);
|
|
|
|
|
df1->flag |= ME_FACE_SEL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur + 1] = vertpa[v2];
|
|
|
|
|
df2->v1 = GET_ES(v1, v2);
|
|
|
|
|
df2->v2 = v2;
|
|
|
|
|
df2->v3 = GET_ES(v2, v3);
|
|
|
|
|
df2->v4 = 0;
|
|
|
|
|
df2->flag &= ~ME_FACE_SEL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur + 2] = vertpa[v4];
|
|
|
|
|
df3->v1 = GET_ES(v1, v4);
|
|
|
|
|
df3->v2 = GET_ES(v2, v3);
|
|
|
|
|
df3->v3 = v3;
|
|
|
|
|
df3->v4 = v4;
|
|
|
|
|
df3->flag |= ME_FACE_SEL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static void remap_uvs_7_11_13_14(
|
2022-03-28 12:29:47 +11:00
|
|
|
Mesh *mesh, Mesh *split, int layers_num, int i, int cur, int c0, int c1, int c2, int c3)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
|
MTFace *mf, *df1, *df2, *df3;
|
|
|
|
|
int l;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
for (l = 0; l < layers_num; l++) {
|
2023-07-24 22:06:55 +02:00
|
|
|
mf = static_cast<MTFace *>(CustomData_get_layer_n_for_write(
|
|
|
|
|
&split->fdata_legacy, CD_MTFACE, l, split->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
df1 = mf + cur;
|
|
|
|
|
df2 = df1 + 1;
|
|
|
|
|
df3 = df1 + 2;
|
2023-01-19 15:54:47 -06:00
|
|
|
mf = static_cast<MTFace *>(
|
2023-07-24 22:06:55 +02:00
|
|
|
CustomData_get_layer_n_for_write(&mesh->fdata_legacy, CD_MTFACE, l, mesh->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
mf += i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v2_v2(df1->uv[0], mf->uv[c0]);
|
|
|
|
|
INT_UV(df1->uv[1], c0, c1);
|
|
|
|
|
INT_UV(df1->uv[2], c1, c2);
|
|
|
|
|
INT_UV(df1->uv[3], c0, c3);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
INT_UV(df2->uv[0], c0, c1);
|
|
|
|
|
copy_v2_v2(df2->uv[1], mf->uv[c1]);
|
|
|
|
|
INT_UV(df2->uv[2], c1, c2);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
INT_UV(df3->uv[0], c0, c3);
|
|
|
|
|
INT_UV(df3->uv[1], c1, c2);
|
|
|
|
|
copy_v2_v2(df3->uv[2], mf->uv[c2]);
|
|
|
|
|
copy_v2_v2(df3->uv[3], mf->uv[c3]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static void remap_faces_19_21_22(Mesh *mesh,
|
|
|
|
|
Mesh *split,
|
|
|
|
|
MFace *mf,
|
|
|
|
|
int *facepa,
|
2020-07-13 11:27:09 +02:00
|
|
|
const int *vertpa,
|
2018-09-25 12:35:43 +02:00
|
|
|
int i,
|
2023-10-24 18:44:24 +02:00
|
|
|
const blender::Map<blender::OrderedEdge, int> &eh,
|
2018-09-25 12:35:43 +02:00
|
|
|
int cur,
|
|
|
|
|
int v1,
|
|
|
|
|
int v2,
|
|
|
|
|
int v3)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-09-25 12:35:43 +02:00
|
|
|
MFace *df1 = get_dface(mesh, split, cur, i, mf);
|
|
|
|
|
MFace *df2 = get_dface(mesh, split, cur + 1, i, mf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur] = vertpa[v1];
|
|
|
|
|
df1->v1 = v1;
|
|
|
|
|
df1->v2 = GET_ES(v1, v2);
|
|
|
|
|
df1->v3 = GET_ES(v1, v3);
|
|
|
|
|
df1->v4 = 0;
|
|
|
|
|
df1->flag &= ~ME_FACE_SEL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur + 1] = vertpa[v2];
|
|
|
|
|
df2->v1 = GET_ES(v1, v2);
|
|
|
|
|
df2->v2 = v2;
|
|
|
|
|
df2->v3 = v3;
|
|
|
|
|
df2->v4 = GET_ES(v1, v3);
|
|
|
|
|
df2->flag |= ME_FACE_SEL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static void remap_uvs_19_21_22(
|
2022-03-28 12:29:47 +11:00
|
|
|
Mesh *mesh, Mesh *split, int layers_num, int i, int cur, int c0, int c1, int c2)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
|
MTFace *mf, *df1, *df2;
|
|
|
|
|
int l;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
for (l = 0; l < layers_num; l++) {
|
2023-07-24 22:06:55 +02:00
|
|
|
mf = static_cast<MTFace *>(CustomData_get_layer_n_for_write(
|
|
|
|
|
&split->fdata_legacy, CD_MTFACE, l, split->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
df1 = mf + cur;
|
|
|
|
|
df2 = df1 + 1;
|
2023-01-19 15:54:47 -06:00
|
|
|
mf = static_cast<MTFace *>(
|
2023-07-24 22:06:55 +02:00
|
|
|
CustomData_get_layer_n_for_write(&mesh->fdata_legacy, CD_MTFACE, l, mesh->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
mf += i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v2_v2(df1->uv[0], mf->uv[c0]);
|
|
|
|
|
INT_UV(df1->uv[1], c0, c1);
|
|
|
|
|
INT_UV(df1->uv[2], c0, c2);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
INT_UV(df2->uv[0], c0, c1);
|
|
|
|
|
copy_v2_v2(df2->uv[1], mf->uv[c1]);
|
|
|
|
|
copy_v2_v2(df2->uv[2], mf->uv[c2]);
|
|
|
|
|
INT_UV(df2->uv[3], c0, c2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static void remap_faces_23(Mesh *mesh,
|
|
|
|
|
Mesh *split,
|
|
|
|
|
MFace *mf,
|
|
|
|
|
int *facepa,
|
2020-07-13 11:27:09 +02:00
|
|
|
const int *vertpa,
|
2018-09-25 12:35:43 +02:00
|
|
|
int i,
|
2023-10-24 18:44:24 +02:00
|
|
|
const blender::Map<blender::OrderedEdge, int> &eh,
|
2018-09-25 12:35:43 +02:00
|
|
|
int cur,
|
|
|
|
|
int v1,
|
|
|
|
|
int v2,
|
|
|
|
|
int v3)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-09-25 12:35:43 +02:00
|
|
|
MFace *df1 = get_dface(mesh, split, cur, i, mf);
|
|
|
|
|
MFace *df2 = get_dface(mesh, split, cur + 1, i, mf);
|
|
|
|
|
MFace *df3 = get_dface(mesh, split, cur + 2, i, mf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur] = vertpa[v1];
|
|
|
|
|
df1->v1 = v1;
|
|
|
|
|
df1->v2 = GET_ES(v1, v2);
|
|
|
|
|
df1->v3 = GET_ES(v2, v3);
|
|
|
|
|
df1->v4 = GET_ES(v1, v3);
|
|
|
|
|
df1->flag |= ME_FACE_SEL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur + 1] = vertpa[v2];
|
|
|
|
|
df2->v1 = GET_ES(v1, v2);
|
|
|
|
|
df2->v2 = v2;
|
|
|
|
|
df2->v3 = GET_ES(v2, v3);
|
|
|
|
|
df2->v4 = 0;
|
|
|
|
|
df2->flag &= ~ME_FACE_SEL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[cur + 2] = vertpa[v3];
|
|
|
|
|
df3->v1 = GET_ES(v1, v3);
|
|
|
|
|
df3->v2 = GET_ES(v2, v3);
|
|
|
|
|
df3->v3 = v3;
|
|
|
|
|
df3->v4 = 0;
|
|
|
|
|
df3->flag &= ~ME_FACE_SEL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static void remap_uvs_23(
|
2022-03-28 12:29:47 +11:00
|
|
|
Mesh *mesh, Mesh *split, int layers_num, int i, int cur, int c0, int c1, int c2)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
|
MTFace *mf, *df1, *df2;
|
|
|
|
|
int l;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-28 12:29:47 +11:00
|
|
|
for (l = 0; l < layers_num; l++) {
|
2023-07-24 22:06:55 +02:00
|
|
|
mf = static_cast<MTFace *>(CustomData_get_layer_n_for_write(
|
|
|
|
|
&split->fdata_legacy, CD_MTFACE, l, split->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
df1 = mf + cur;
|
|
|
|
|
df2 = df1 + 1;
|
2023-01-19 15:54:47 -06:00
|
|
|
mf = static_cast<MTFace *>(
|
2023-07-24 22:06:55 +02:00
|
|
|
CustomData_get_layer_n_for_write(&mesh->fdata_legacy, CD_MTFACE, l, mesh->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
mf += i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v2_v2(df1->uv[0], mf->uv[c0]);
|
|
|
|
|
INT_UV(df1->uv[1], c0, c1);
|
|
|
|
|
INT_UV(df1->uv[2], c1, c2);
|
|
|
|
|
INT_UV(df1->uv[3], c0, c2);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
INT_UV(df2->uv[0], c0, c1);
|
|
|
|
|
copy_v2_v2(df2->uv[1], mf->uv[c1]);
|
|
|
|
|
INT_UV(df2->uv[2], c1, c2);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
INT_UV(df2->uv[0], c0, c2);
|
|
|
|
|
INT_UV(df2->uv[1], c1, c2);
|
|
|
|
|
copy_v2_v2(df2->uv[2], mf->uv[c2]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-09-25 12:35:43 +02:00
|
|
|
Mesh *split_m;
|
2023-01-19 15:54:47 -06:00
|
|
|
MFace *mf = nullptr, *df1 = nullptr;
|
|
|
|
|
MFace *mface = static_cast<MFace *>(
|
2023-07-24 22:06:55 +02:00
|
|
|
CustomData_get_layer_for_write(&mesh->fdata_legacy, CD_MFACE, mesh->totface_legacy));
|
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 *dupve;
|
2023-12-20 02:21:48 +01:00
|
|
|
int totvert = mesh->verts_num;
|
2023-07-24 22:06:55 +02:00
|
|
|
int totface = mesh->totface_legacy;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-04-12 17:17:24 +02:00
|
|
|
int *facesplit = MEM_calloc_arrayN<int>(totface, __func__);
|
|
|
|
|
int *vertpa = MEM_calloc_arrayN<int>(totvert, __func__);
|
2016-12-28 17:30:58 +01:00
|
|
|
int *facepa = emd->facepa;
|
2023-08-29 17:00:33 +02:00
|
|
|
int *fs, totfsplit = 0, curdupface = 0;
|
|
|
|
|
int i, v1, v2, v3, v4, v[4] = {0, 0, 0, 0}, /* To quite gcc barking... */
|
|
|
|
|
uv[4] = {0, 0, 0, 0}; /* To quite gcc barking... */
|
2022-03-28 12:29:47 +11:00
|
|
|
int layers_num;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-10-24 18:44:24 +02:00
|
|
|
int totesplit = totvert;
|
|
|
|
|
blender::Map<blender::OrderedEdge, int> edgehash;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* recreate vertpa from facepa calculation */
|
|
|
|
|
for (i = 0, mf = mface; i < totface; i++, mf++) {
|
|
|
|
|
vertpa[mf->v1] = facepa[i];
|
|
|
|
|
vertpa[mf->v2] = facepa[i];
|
|
|
|
|
vertpa[mf->v3] = facepa[i];
|
2018-09-25 12:35:43 +02:00
|
|
|
if (mf->v4) {
|
2016-12-28 17:30:58 +01:00
|
|
|
vertpa[mf->v4] = facepa[i];
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* mark edges for splitting and how to split faces */
|
|
|
|
|
for (i = 0, mf = mface, fs = facesplit; i < totface; i++, mf++, fs++) {
|
|
|
|
|
v1 = vertpa[mf->v1];
|
|
|
|
|
v2 = vertpa[mf->v2];
|
|
|
|
|
v3 = vertpa[mf->v3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (v1 != v2) {
|
2023-10-24 18:44:24 +02:00
|
|
|
edgehash.lookup_or_add_cb({mf->v1, mf->v2}, [&]() { return totesplit++; });
|
2016-12-28 17:30:58 +01:00
|
|
|
(*fs) |= 1;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (v2 != v3) {
|
2023-10-24 18:44:24 +02:00
|
|
|
edgehash.lookup_or_add_cb({mf->v2, mf->v3}, [&]() { return totesplit++; });
|
2016-12-28 17:30:58 +01:00
|
|
|
(*fs) |= 2;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (mf->v4) {
|
|
|
|
|
v4 = vertpa[mf->v4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (v3 != v4) {
|
2023-10-24 18:44:24 +02:00
|
|
|
edgehash.lookup_or_add_cb({mf->v3, mf->v4}, [&]() { return totesplit++; });
|
2016-12-28 17:30:58 +01:00
|
|
|
(*fs) |= 4;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (v1 != v4) {
|
2023-10-24 18:44:24 +02:00
|
|
|
edgehash.lookup_or_add_cb({mf->v1, mf->v4}, [&]() { return totesplit++; });
|
2016-12-28 17:30:58 +01:00
|
|
|
(*fs) |= 8;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* mark center vertex as a fake edge split */
|
2018-09-25 12:35:43 +02:00
|
|
|
if (*fs == 15) {
|
2023-10-24 18:44:24 +02:00
|
|
|
edgehash.lookup_or_add_cb({mf->v1, mf->v3}, [&]() { return totesplit++; });
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
else {
|
|
|
|
|
(*fs) |= 16; /* mark face as tri */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (v1 != v3) {
|
2023-10-24 18:44:24 +02:00
|
|
|
edgehash.lookup_or_add_cb({mf->v1, mf->v3}, [&]() { return totesplit++; });
|
2016-12-28 17:30:58 +01:00
|
|
|
(*fs) |= 4;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* count splits & create indexes for new verts */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* count new faces due to splitting */
|
2019-04-22 09:15:10 +10:00
|
|
|
for (i = 0, fs = facesplit; i < totface; i++, fs++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
totfsplit += add_faces[*fs];
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-02-27 15:29:35 -05:00
|
|
|
split_m = BKE_mesh_new_nomain_from_template_ex(
|
2023-10-24 18:44:24 +02:00
|
|
|
mesh, totesplit, 0, totface + totfsplit, 0, 0, CD_MASK_EVERYTHING);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
layers_num = CustomData_number_of_layers(&split_m->fdata_legacy, CD_MTFACE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-25 21:59:47 -04:00
|
|
|
blender::MutableSpan<blender::float3> split_m_positions = split_m->vert_positions_for_write();
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* copy new faces & verts (is it really this painful with custom data??) */
|
|
|
|
|
for (i = 0; i < totvert; i++) {
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_copy_data(&mesh->vert_data, &split_m->vert_data, i, i, 1);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* override original facepa (original pointer is saved in caller function) */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-02-09 11:30:25 +11:00
|
|
|
/* TODO(@ideasman42): `(totfsplit * 2)` over allocation is used since the quads are
|
2023-12-17 16:04:38 +11:00
|
|
|
* later interpreted as triangles, for this to work right I think we probably
|
2021-07-03 23:08:40 +10:00
|
|
|
* have to stop using tessface. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-03-12 14:03:26 +01:00
|
|
|
facepa = MEM_calloc_arrayN<int>(size_t(totface) + (size_t(totfsplit) * 2), __func__);
|
2019-05-01 07:40:07 +10:00
|
|
|
// memcpy(facepa, emd->facepa, totface*sizeof(int));
|
2016-12-28 17:30:58 +01:00
|
|
|
emd->facepa = facepa;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* create new verts */
|
2023-10-24 18:44:24 +02:00
|
|
|
for (const auto [edge, esplit] : edgehash.items()) {
|
|
|
|
|
const int ed_v1 = edge.v_low;
|
|
|
|
|
const int ed_v2 = edge.v_high;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-27 13:47:02 +10:00
|
|
|
CustomData_free_elem(&split_m->vert_data, esplit, 1);
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_copy_data(&split_m->vert_data, &split_m->vert_data, ed_v2, esplit, 1);
|
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
|
|
|
dupve = split_m_positions[esplit];
|
|
|
|
|
copy_v3_v3(dupve, split_m_positions[ed_v2]);
|
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
|
|
|
mid_v3_v3v3(dupve, dupve, split_m_positions[ed_v1]);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* create new faces */
|
|
|
|
|
curdupface = 0; //=totface;
|
2019-05-01 07:40:07 +10:00
|
|
|
// curdupin=totesplit;
|
2016-12-28 17:30:58 +01:00
|
|
|
for (i = 0, fs = facesplit; i < totface; i++, fs++) {
|
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
|
|
|
mf = &mface[i];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
switch (*fs) {
|
|
|
|
|
case 3:
|
|
|
|
|
case 10:
|
|
|
|
|
case 11:
|
|
|
|
|
case 15:
|
|
|
|
|
SET_VERTS(1, 2, 3, 4);
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
case 6:
|
|
|
|
|
case 7:
|
|
|
|
|
SET_VERTS(2, 3, 4, 1);
|
|
|
|
|
break;
|
|
|
|
|
case 9:
|
|
|
|
|
case 13:
|
|
|
|
|
SET_VERTS(4, 1, 2, 3);
|
|
|
|
|
break;
|
|
|
|
|
case 12:
|
|
|
|
|
case 14:
|
|
|
|
|
SET_VERTS(3, 4, 1, 2);
|
|
|
|
|
break;
|
|
|
|
|
case 21:
|
|
|
|
|
case 23:
|
|
|
|
|
SET_VERTS(1, 2, 3, 4);
|
|
|
|
|
break;
|
|
|
|
|
case 19:
|
|
|
|
|
SET_VERTS(2, 3, 1, 4);
|
|
|
|
|
break;
|
|
|
|
|
case 22:
|
|
|
|
|
SET_VERTS(3, 1, 2, 4);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
switch (*fs) {
|
|
|
|
|
case 3:
|
|
|
|
|
case 6:
|
|
|
|
|
case 9:
|
|
|
|
|
case 12:
|
2018-09-25 12:35:43 +02:00
|
|
|
remap_faces_3_6_9_12(
|
|
|
|
|
mesh, split_m, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]);
|
2022-03-28 12:29:47 +11:00
|
|
|
if (layers_num) {
|
|
|
|
|
remap_uvs_3_6_9_12(mesh, split_m, layers_num, i, curdupface, uv[0], uv[1], uv[2], uv[3]);
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
case 10:
|
2018-09-25 12:35:43 +02:00
|
|
|
remap_faces_5_10(
|
|
|
|
|
mesh, split_m, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]);
|
2022-03-28 12:29:47 +11:00
|
|
|
if (layers_num) {
|
|
|
|
|
remap_uvs_5_10(mesh, split_m, layers_num, i, curdupface, uv[0], uv[1], uv[2], uv[3]);
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
|
case 15:
|
2018-09-25 12:35:43 +02:00
|
|
|
remap_faces_15(
|
|
|
|
|
mesh, split_m, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]);
|
2022-03-28 12:29:47 +11:00
|
|
|
if (layers_num) {
|
|
|
|
|
remap_uvs_15(mesh, split_m, layers_num, i, curdupface, uv[0], uv[1], uv[2], uv[3]);
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
|
case 7:
|
|
|
|
|
case 11:
|
|
|
|
|
case 13:
|
|
|
|
|
case 14:
|
2018-09-25 12:35:43 +02:00
|
|
|
remap_faces_7_11_13_14(
|
|
|
|
|
mesh, split_m, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2], v[3]);
|
2022-03-28 12:29:47 +11:00
|
|
|
if (layers_num) {
|
|
|
|
|
remap_uvs_7_11_13_14(
|
|
|
|
|
mesh, split_m, layers_num, i, curdupface, uv[0], uv[1], uv[2], uv[3]);
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
|
case 19:
|
|
|
|
|
case 21:
|
|
|
|
|
case 22:
|
2018-09-25 12:35:43 +02:00
|
|
|
remap_faces_19_21_22(
|
|
|
|
|
mesh, split_m, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2]);
|
2022-03-28 12:29:47 +11:00
|
|
|
if (layers_num) {
|
|
|
|
|
remap_uvs_19_21_22(mesh, split_m, layers_num, i, curdupface, uv[0], uv[1], uv[2]);
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
|
case 23:
|
2018-09-25 12:35:43 +02:00
|
|
|
remap_faces_23(
|
|
|
|
|
mesh, split_m, mf, facepa, vertpa, i, edgehash, curdupface, v[0], v[1], v[2]);
|
2022-03-28 12:29:47 +11:00
|
|
|
if (layers_num) {
|
|
|
|
|
remap_uvs_23(mesh, split_m, layers_num, i, curdupface, uv[0], uv[1], uv[2]);
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
|
case 0:
|
|
|
|
|
case 16:
|
2018-09-25 12:35:43 +02:00
|
|
|
df1 = get_dface(mesh, split_m, curdupface, i, mf);
|
2016-12-28 17:30:58 +01:00
|
|
|
facepa[curdupface] = vertpa[mf->v1];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
if (df1->v4) {
|
2016-12-28 17:30:58 +01:00
|
|
|
df1->flag |= ME_FACE_SEL;
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2016-12-28 17:30:58 +01:00
|
|
|
df1->flag &= ~ME_FACE_SEL;
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
curdupface += add_faces[*fs] + 1;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
MFace *split_mface = static_cast<MFace *>(
|
2023-07-24 22:06:55 +02:00
|
|
|
CustomData_get_layer_for_write(&split_m->fdata_legacy, CD_MFACE, split_m->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
for (i = 0; i < curdupface; i++) {
|
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
|
|
|
mf = &split_mface[i];
|
2023-07-24 22:06:55 +02:00
|
|
|
BKE_mesh_mface_index_validate(
|
|
|
|
|
mf, &split_m->fdata_legacy, i, ((mf->flag & ME_FACE_SEL) ? 4 : 3));
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
MEM_freeN(facesplit);
|
|
|
|
|
MEM_freeN(vertpa);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
BKE_mesh_calc_edges_tessface(split_m);
|
|
|
|
|
BKE_mesh_convert_mfaces_to_mpolys(split_m);
|
Mesh: Replace MPoly struct with offset indices
Implements #95967.
Currently the `MPoly` struct is 12 bytes, and stores the index of a
face's first corner and the number of corners/verts/edges. Polygons
and corners are always created in order by Blender, meaning each
face's corners will be after the previous face's corners. We can take
advantage of this fact and eliminate the redundancy in mesh face
storage by only storing a single integer corner offset for each face.
The size of the face is then encoded by the offset of the next face.
The size of a single integer is 4 bytes, so this reduces memory
usage by 3 times.
The same method is used for `CurvesGeometry`, so Blender already has
an abstraction to simplify using these offsets called `OffsetIndices`.
This class is used to easily retrieve a range of corner indices for
each face. This also gives the opportunity for sharing some logic with
curves.
Another benefit of the change is that the offsets and sizes stored in
`MPoly` can no longer disagree with each other. Storing faces in the
order of their corners can simplify some code too.
Face/polygon variables now use the `IndexRange` type, which comes with
quite a few utilities that can simplify code.
Some:
- The offset integer array has to be one longer than the face count to
avoid a branch for every face, which means the data is no longer part
of the mesh's `CustomData`.
- We lose the ability to "reference" an original mesh's offset array
until more reusable CoW from #104478 is committed. That will be added
in a separate commit.
- Since they aren't part of `CustomData`, poly offsets often have to be
copied manually.
- To simplify using `OffsetIndices` in many places, some functions and
structs in headers were moved to only compile in C++.
- All meshes created by Blender use the same order for faces and face
corners, but just in case, meshes with mismatched order are fixed by
versioning code.
- `MeshPolygon.totloop` is no longer editable in RNA. This API break is
necessary here unfortunately. It should be worth it in 3.6, since
that's the best way to allow loading meshes from 4.0, which is
important for an LTS version.
Pull Request: https://projects.blender.org/blender/blender/pulls/105938
2023-04-04 20:39:28 +02:00
|
|
|
BKE_mesh_legacy_convert_polys_to_offsets(split_m);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-25 12:35:43 +02:00
|
|
|
return split_m;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2018-09-25 12:35:43 +02:00
|
|
|
static Mesh *explodeMesh(ExplodeModifierData *emd,
|
2018-05-01 17:33:04 +02:00
|
|
|
ParticleSystemModifierData *psmd,
|
|
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
|
Scene *scene,
|
2018-09-25 12:35:43 +02:00
|
|
|
Mesh *to_explode)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-09-25 12:35:43 +02:00
|
|
|
Mesh *explode, *mesh = to_explode;
|
2023-01-19 15:54:47 -06:00
|
|
|
MFace *mf = nullptr, *mface;
|
2022-06-03 13:39:37 +10:00
|
|
|
// ParticleSettings *part=psmd->psys->part; /* UNUSED */
|
2023-01-19 15:54:47 -06:00
|
|
|
ParticleSimulationData sim = {nullptr};
|
|
|
|
|
ParticleData *pa = nullptr, *pars = psmd->psys->particles;
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleKey state, birth;
|
2023-01-19 15:54:47 -06:00
|
|
|
float *vertco = nullptr, imat[4][4];
|
2016-12-28 17:30:58 +01:00
|
|
|
float rot[4];
|
2021-07-12 16:15:03 +02:00
|
|
|
float ctime;
|
2022-06-03 13:39:37 +10:00
|
|
|
// float timestep;
|
2016-12-28 17:30:58 +01:00
|
|
|
const int *facepa = emd->facepa;
|
2023-10-24 18:44:24 +02:00
|
|
|
int totdup = 0, totvert = 0, totface = 0, totpart = 0, delface = 0;
|
2023-08-29 17:00:33 +02:00
|
|
|
int i, u;
|
|
|
|
|
uint mindex = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
totface = mesh->totface_legacy;
|
2023-12-20 02:21:48 +01:00
|
|
|
totvert = mesh->verts_num;
|
2023-01-19 15:54:47 -06:00
|
|
|
mface = static_cast<MFace *>(
|
2023-07-24 22:06:55 +02:00
|
|
|
CustomData_get_layer_for_write(&mesh->fdata_legacy, CD_MFACE, mesh->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
totpart = psmd->psys->totpart;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-01 17:33:04 +02:00
|
|
|
sim.depsgraph = ctx->depsgraph;
|
2016-12-28 17:30:58 +01:00
|
|
|
sim.scene = scene;
|
2018-05-01 17:33:04 +02:00
|
|
|
sim.ob = ctx->object;
|
2016-12-28 17:30:58 +01:00
|
|
|
sim.psys = psmd->psys;
|
|
|
|
|
sim.psmd = psmd;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-06-03 13:39:37 +10:00
|
|
|
// timestep = psys_get_timestep(&sim);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-07-12 16:15:03 +02:00
|
|
|
ctime = BKE_scene_ctime_get(scene);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-02 10:05:15 -08:00
|
|
|
/* hash table for vertex <-> particle relations */
|
2023-10-24 18:44:24 +02:00
|
|
|
blender::Map<blender::OrderedEdge, int> vertpahash;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
for (i = 0; i < totface; i++) {
|
|
|
|
|
if (facepa[i] != totpart) {
|
|
|
|
|
pa = pars + facepa[i];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if ((pa->alive == PARS_UNBORN && (emd->flag & eExplodeFlag_Unborn) == 0) ||
|
|
|
|
|
(pa->alive == PARS_ALIVE && (emd->flag & eExplodeFlag_Alive) == 0) ||
|
|
|
|
|
(pa->alive == PARS_DEAD && (emd->flag & eExplodeFlag_Dead) == 0))
|
|
|
|
|
{
|
|
|
|
|
delface++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-09-22 18:48:00 +02:00
|
|
|
else {
|
2023-01-19 15:54:47 -06:00
|
|
|
pa = nullptr;
|
2019-09-22 18:48:00 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-29 17:00:33 +02:00
|
|
|
/* do mindex + totvert to ensure the vertex index to be the first. */
|
2023-01-19 15:54:47 -06:00
|
|
|
if (pa == nullptr || ctime < pa->time) {
|
2016-12-28 17:30:58 +01:00
|
|
|
mindex = totvert + totpart;
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2016-12-28 17:30:58 +01:00
|
|
|
mindex = totvert + facepa[i];
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
mf = &mface[i];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* set face vertices to exist in particle group */
|
2023-10-24 18:44:24 +02:00
|
|
|
vertpahash.lookup_or_add_cb({mf->v1, mindex}, [&]() { return totdup++; });
|
|
|
|
|
vertpahash.lookup_or_add_cb({mf->v2, mindex}, [&]() { return totdup++; });
|
|
|
|
|
vertpahash.lookup_or_add_cb({mf->v3, mindex}, [&]() { return totdup++; });
|
2018-09-25 12:35:43 +02:00
|
|
|
if (mf->v4) {
|
2023-10-24 18:44:24 +02:00
|
|
|
vertpahash.lookup_or_add_cb({mf->v4, mindex}, [&]() { return totdup++; });
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* the final duplicated vertices */
|
2023-02-27 15:29:35 -05:00
|
|
|
explode = BKE_mesh_new_nomain_from_template_ex(
|
2023-10-24 18:44:24 +02:00
|
|
|
mesh, totdup, 0, totface - delface, 0, 0, CD_MASK_EVERYTHING);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
MTFace *mtface = static_cast<MTFace *>(CustomData_get_layer_named_for_write(
|
2023-07-24 22:06:55 +02:00
|
|
|
&explode->fdata_legacy, CD_MTFACE, emd->uvname, explode->totface_legacy));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* getting back to object space */
|
2024-02-14 16:14:49 +01:00
|
|
|
invert_m4_m4(imat, ctx->object->object_to_world().ptr());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-09 20:30:41 +01:00
|
|
|
psys_sim_data_init(&sim);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-06-14 11:59:32 -04:00
|
|
|
const blender::Span<blender::float3> positions = mesh->vert_positions();
|
2023-07-25 21:59:47 -04:00
|
|
|
blender::MutableSpan<blender::float3> explode_positions = explode->vert_positions_for_write();
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
|
2023-10-24 18:44:24 +02:00
|
|
|
for (const auto [edge, v] : vertpahash.items()) {
|
|
|
|
|
int ed_v1 = edge.v_low;
|
|
|
|
|
int ed_v2 = edge.v_high;
|
2016-12-28 17:30:58 +01:00
|
|
|
ed_v2 -= totvert;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
copy_v3_v3(explode_positions[v], positions[ed_v1]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_copy_data(&mesh->vert_data, &explode->vert_data, ed_v1, v, 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
copy_v3_v3(explode_positions[v], positions[ed_v1]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (ed_v2 != totpart) {
|
|
|
|
|
/* get particle */
|
|
|
|
|
pa = pars + ed_v2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
psys_get_birth_coords(&sim, pa, &birth, 0, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-07-12 16:15:03 +02:00
|
|
|
state.time = ctime;
|
2023-07-22 11:36:59 +10:00
|
|
|
psys_get_particle_state(&sim, ed_v2, &state, true);
|
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
|
|
|
vertco = explode_positions[v];
|
2024-02-14 16:14:49 +01:00
|
|
|
mul_m4_v3(ctx->object->object_to_world().ptr(), vertco);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
|
sub_v3_v3(vertco, birth.co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* apply rotation, size & location */
|
|
|
|
|
sub_qt_qtqt(rot, state.rot, birth.rot);
|
|
|
|
|
mul_qt_v3(rot, vertco);
|
|
|
|
|
|
|
|
|
|
if (emd->flag & eExplodeFlag_PaSize) {
|
|
|
|
|
mul_v3_fl(vertco, pa->size);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
|
add_v3_v3(vertco, state.co);
|
|
|
|
|
|
|
|
|
|
mul_m4_v3(imat, vertco);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-09-22 18:48:00 +02:00
|
|
|
else {
|
2023-01-19 15:54:47 -06:00
|
|
|
pa = nullptr;
|
2019-09-22 18:48:00 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-26 21:35:18 +10:00
|
|
|
/* Map new vertices to faces. */
|
2023-01-19 15:54:47 -06:00
|
|
|
MFace *explode_mface = static_cast<MFace *>(
|
2023-07-24 22:06:55 +02:00
|
|
|
CustomData_get_layer_for_write(&explode->fdata_legacy, CD_MFACE, explode->totface_legacy));
|
2016-12-28 17:30:58 +01:00
|
|
|
for (i = 0, u = 0; i < totface; i++) {
|
2018-09-25 12:35:43 +02:00
|
|
|
MFace source;
|
2016-12-28 17:30:58 +01:00
|
|
|
int orig_v4;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (facepa[i] != totpart) {
|
|
|
|
|
pa = pars + facepa[i];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (pa->alive == PARS_UNBORN && (emd->flag & eExplodeFlag_Unborn) == 0) {
|
2016-12-28 17:30:58 +01:00
|
|
|
continue;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (pa->alive == PARS_ALIVE && (emd->flag & eExplodeFlag_Alive) == 0) {
|
2016-12-28 17:30:58 +01:00
|
|
|
continue;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (pa->alive == PARS_DEAD && (emd->flag & eExplodeFlag_Dead) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-09-22 18:48:00 +02:00
|
|
|
else {
|
2023-01-19 15:54:47 -06:00
|
|
|
pa = nullptr;
|
2019-09-22 18:48:00 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01: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
|
|
|
source = mface[i];
|
|
|
|
|
mf = &explode_mface[u];
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
orig_v4 = source.v4;
|
|
|
|
|
|
2019-09-22 18:51:45 +02:00
|
|
|
/* Same as above in the first loop over mesh's faces. */
|
2023-01-19 15:54:47 -06:00
|
|
|
if (pa == nullptr || ctime < pa->time) {
|
2016-12-28 17:30:58 +01:00
|
|
|
mindex = totvert + totpart;
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2016-12-28 17:30:58 +01:00
|
|
|
mindex = totvert + facepa[i];
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
|
source.v1 = edgecut_get(vertpahash, source.v1, mindex);
|
|
|
|
|
source.v2 = edgecut_get(vertpahash, source.v2, mindex);
|
|
|
|
|
source.v3 = edgecut_get(vertpahash, source.v3, mindex);
|
2018-09-25 12:35:43 +02:00
|
|
|
if (source.v4) {
|
2016-12-28 17:30:58 +01:00
|
|
|
source.v4 = edgecut_get(vertpahash, source.v4, mindex);
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
CustomData_copy_data(&mesh->fdata_legacy, &explode->fdata_legacy, i, u, 1);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
|
*mf = source;
|
|
|
|
|
|
|
|
|
|
/* override uv channel for particle age */
|
|
|
|
|
if (mtface) {
|
2023-01-19 15:54:47 -06:00
|
|
|
float age = (pa != nullptr) ? (ctime - pa->time) / pa->lifetime : 0.0f;
|
2016-12-28 17:30:58 +01:00
|
|
|
/* Clamp to this range to avoid flipping to the other side of the coordinates. */
|
|
|
|
|
CLAMP(age, 0.001f, 0.999f);
|
|
|
|
|
|
2022-05-14 18:57:52 +02:00
|
|
|
MTFace *mtf = mtface + u;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
|
mtf->uv[0][0] = mtf->uv[1][0] = mtf->uv[2][0] = mtf->uv[3][0] = age;
|
|
|
|
|
mtf->uv[0][1] = mtf->uv[1][1] = mtf->uv[2][1] = mtf->uv[3][1] = 0.5f;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
BKE_mesh_mface_index_validate(mf, &explode->fdata_legacy, u, (orig_v4 ? 4 : 3));
|
2016-12-28 17:30:58 +01:00
|
|
|
u++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* finalization */
|
2018-09-25 12:35:43 +02:00
|
|
|
BKE_mesh_calc_edges_tessface(explode);
|
|
|
|
|
BKE_mesh_convert_mfaces_to_mpolys(explode);
|
Mesh: Replace MPoly struct with offset indices
Implements #95967.
Currently the `MPoly` struct is 12 bytes, and stores the index of a
face's first corner and the number of corners/verts/edges. Polygons
and corners are always created in order by Blender, meaning each
face's corners will be after the previous face's corners. We can take
advantage of this fact and eliminate the redundancy in mesh face
storage by only storing a single integer corner offset for each face.
The size of the face is then encoded by the offset of the next face.
The size of a single integer is 4 bytes, so this reduces memory
usage by 3 times.
The same method is used for `CurvesGeometry`, so Blender already has
an abstraction to simplify using these offsets called `OffsetIndices`.
This class is used to easily retrieve a range of corner indices for
each face. This also gives the opportunity for sharing some logic with
curves.
Another benefit of the change is that the offsets and sizes stored in
`MPoly` can no longer disagree with each other. Storing faces in the
order of their corners can simplify some code too.
Face/polygon variables now use the `IndexRange` type, which comes with
quite a few utilities that can simplify code.
Some:
- The offset integer array has to be one longer than the face count to
avoid a branch for every face, which means the data is no longer part
of the mesh's `CustomData`.
- We lose the ability to "reference" an original mesh's offset array
until more reusable CoW from #104478 is committed. That will be added
in a separate commit.
- Since they aren't part of `CustomData`, poly offsets often have to be
copied manually.
- To simplify using `OffsetIndices` in many places, some functions and
structs in headers were moved to only compile in C++.
- All meshes created by Blender use the same order for faces and face
corners, but just in case, meshes with mismatched order are fixed by
versioning code.
- `MeshPolygon.totloop` is no longer editable in RNA. This API break is
necessary here unfortunately. It should be worth it in 3.6, since
that's the best way to allow loading meshes from 4.0, which is
important for an LTS version.
Pull Request: https://projects.blender.org/blender/blender/pulls/105938
2023-04-04 20:39:28 +02:00
|
|
|
BKE_mesh_legacy_convert_polys_to_offsets(explode);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2022-11-09 20:30:41 +01:00
|
|
|
psys_sim_data_free(&sim);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
|
return explode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ParticleSystemModifierData *findPrecedingParticlesystem(Object *ob, ModifierData *emd)
|
|
|
|
|
{
|
|
|
|
|
ModifierData *md;
|
2023-02-06 12:46:53 +11:00
|
|
|
ParticleSystemModifierData *psmd = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
for (md = static_cast<ModifierData *>(ob->modifiers.first); emd != md; md = md->next) {
|
2018-09-25 12:35:43 +02:00
|
|
|
if (md->type == eModifierType_ParticleSystem) {
|
2016-12-28 17:30:58 +01:00
|
|
|
psmd = (ParticleSystemModifierData *)md;
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
return psmd;
|
|
|
|
|
}
|
2023-07-27 12:04:18 +10:00
|
|
|
static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2016-12-28 17:30:58 +01:00
|
|
|
ExplodeModifierData *emd = (ExplodeModifierData *)md;
|
2018-05-01 17:33:04 +02:00
|
|
|
ParticleSystemModifierData *psmd = findPrecedingParticlesystem(ctx->object, md);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (psmd) {
|
|
|
|
|
ParticleSystem *psys = psmd->psys;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
if (psys == nullptr || psys->totpart == 0) {
|
2018-09-25 12:35:43 +02:00
|
|
|
return mesh;
|
|
|
|
|
}
|
2023-01-19 15:54:47 -06:00
|
|
|
if (psys->part == nullptr || psys->particles == nullptr) {
|
2018-09-25 12:35:43 +02:00
|
|
|
return mesh;
|
|
|
|
|
}
|
2023-01-19 15:54:47 -06:00
|
|
|
if (psmd->mesh_final == nullptr) {
|
2018-09-25 12:35:43 +02:00
|
|
|
return mesh;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Replace MPoly struct with offset indices
Implements #95967.
Currently the `MPoly` struct is 12 bytes, and stores the index of a
face's first corner and the number of corners/verts/edges. Polygons
and corners are always created in order by Blender, meaning each
face's corners will be after the previous face's corners. We can take
advantage of this fact and eliminate the redundancy in mesh face
storage by only storing a single integer corner offset for each face.
The size of the face is then encoded by the offset of the next face.
The size of a single integer is 4 bytes, so this reduces memory
usage by 3 times.
The same method is used for `CurvesGeometry`, so Blender already has
an abstraction to simplify using these offsets called `OffsetIndices`.
This class is used to easily retrieve a range of corner indices for
each face. This also gives the opportunity for sharing some logic with
curves.
Another benefit of the change is that the offsets and sizes stored in
`MPoly` can no longer disagree with each other. Storing faces in the
order of their corners can simplify some code too.
Face/polygon variables now use the `IndexRange` type, which comes with
quite a few utilities that can simplify code.
Some:
- The offset integer array has to be one longer than the face count to
avoid a branch for every face, which means the data is no longer part
of the mesh's `CustomData`.
- We lose the ability to "reference" an original mesh's offset array
until more reusable CoW from #104478 is committed. That will be added
in a separate commit.
- Since they aren't part of `CustomData`, poly offsets often have to be
copied manually.
- To simplify using `OffsetIndices` in many places, some functions and
structs in headers were moved to only compile in C++.
- All meshes created by Blender use the same order for faces and face
corners, but just in case, meshes with mismatched order are fixed by
versioning code.
- `MeshPolygon.totloop` is no longer editable in RNA. This API break is
necessary here unfortunately. It should be worth it in 3.6, since
that's the best way to allow loading meshes from 4.0, which is
important for an LTS version.
Pull Request: https://projects.blender.org/blender/blender/pulls/105938
2023-04-04 20:39:28 +02:00
|
|
|
BKE_mesh_tessface_ensure(mesh); /* BMESH - UNTIL MODIFIER IS UPDATED FOR POLYGONS */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* 1. find faces to be exploded if needed */
|
2023-01-19 15:54:47 -06:00
|
|
|
if (emd->facepa == nullptr || psmd->flag & eParticleSystemFlag_Pars ||
|
2016-12-28 17:30:58 +01:00
|
|
|
emd->flag & eExplodeFlag_CalcFaces ||
|
2023-07-24 22:06:55 +02:00
|
|
|
MEM_allocN_len(emd->facepa) / sizeof(int) != mesh->totface_legacy)
|
2018-09-25 12:35:43 +02:00
|
|
|
{
|
|
|
|
|
if (psmd->flag & eParticleSystemFlag_Pars) {
|
2016-12-28 17:30:58 +01:00
|
|
|
psmd->flag &= ~eParticleSystemFlag_Pars;
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
|
|
|
|
if (emd->flag & eExplodeFlag_CalcFaces) {
|
2016-12-28 17:30:58 +01:00
|
|
|
emd->flag &= ~eExplodeFlag_CalcFaces;
|
2018-09-25 12:35:43 +02:00
|
|
|
}
|
|
|
|
|
createFacepa(emd, psmd, mesh);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
/* 2. create new mesh */
|
2018-06-22 15:03:42 +02:00
|
|
|
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
|
2016-12-28 17:30:58 +01:00
|
|
|
if (emd->flag & eExplodeFlag_EdgeCut) {
|
|
|
|
|
int *facepa = emd->facepa;
|
2018-09-25 12:35:43 +02:00
|
|
|
Mesh *split_m = cutEdges(emd, mesh);
|
|
|
|
|
Mesh *explode = explodeMesh(emd, psmd, ctx, scene, split_m);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
MEM_freeN(emd->facepa);
|
|
|
|
|
emd->facepa = facepa;
|
2023-01-19 15:54:47 -06:00
|
|
|
BKE_id_free(nullptr, split_m);
|
2016-12-28 17:30:58 +01:00
|
|
|
return explode;
|
|
|
|
|
}
|
2020-08-07 12:40:29 +02:00
|
|
|
|
|
|
|
|
return explodeMesh(emd, psmd, ctx, scene, mesh);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2018-09-25 12:35:43 +02:00
|
|
|
return mesh;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
static void panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
UI: Small Tweaks to Modifier Layouts for Consistency
These changes are smaller, made based on feedback and a pass on all
the layouts for clarity and consistency. The Multires modifier UI will
be addressed in a separate patch. Here is an overview of the changes:
Renaming Options:
- Build: "Start" -> "Start Frame"
- Curve: "From Radius" -> "Size from Radius"
- Screw: "Calc Order" -> "Calculate Order"
- Displace, Warp, Wave: "Texture Coordinates Object" -> "Object"
Move Mode Toggle to Top & Expand:
- Bevel, Boolean, Normal Edit, Subdivision
Use Columns for Tighter Spacing:
- Displace, Explode, Ocean, Particle Instance, Remesh, Shrinkwrap,
Solidify, Warp, Weighted Normal, Wave
Misc:
- Bevel: Set inactive properties for vertex bevel
- Mesh Sequence Cache: Remove box for cache file
- Skin: Don't align "Mark Loose" and "Clear Loose"
- Array: Expand relative offset subpanel by default
- Array: Move start cap, end cap to a new subpanel
- Bevel: Move width type above width
Differential Revision: https://developer.blender.org/D8115
2020-07-02 10:47:02 -04:00
|
|
|
uiLayout *row, *col;
|
2020-06-05 10:41:03 -04:00
|
|
|
uiLayout *layout = panel->layout;
|
2023-07-29 15:06:33 +10:00
|
|
|
const eUI_Item_Flag toggles_flag = UI_ITEM_R_TOGGLE | UI_ITEM_R_FORCE_BLANK_DECORATE;
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data");
|
2020-09-02 14:13:26 -05:00
|
|
|
bool has_vertex_group = RNA_string_length(ptr, "vertex_group") != 0;
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
2024-12-06 14:08:10 +01:00
|
|
|
uiItemPointerR(
|
|
|
|
|
layout, ptr, "particle_uv", &obj_data_ptr, "uv_layers", std::nullopt, ICON_GROUP_UVS);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2025-04-26 02:17:31 +02:00
|
|
|
row = &layout->row(true, IFACE_("Show"));
|
2025-05-08 20:45:37 +02:00
|
|
|
row->prop(ptr, "show_alive", toggles_flag, std::nullopt, ICON_NONE);
|
|
|
|
|
row->prop(ptr, "show_dead", toggles_flag, std::nullopt, ICON_NONE);
|
|
|
|
|
row->prop(ptr, "show_unborn", toggles_flag, std::nullopt, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
2025-04-26 21:07:34 +02:00
|
|
|
col = &layout->column(false);
|
2025-05-08 20:45:37 +02:00
|
|
|
col->prop(ptr, "use_edge_cut", UI_ITEM_NONE, std::nullopt, ICON_NONE);
|
|
|
|
|
col->prop(ptr, "use_size", UI_ITEM_NONE, std::nullopt, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2024-12-08 10:41:18 -05:00
|
|
|
modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", std::nullopt);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2025-04-25 19:45:25 +02:00
|
|
|
row = &layout->row(false);
|
2020-06-05 10:41:03 -04:00
|
|
|
uiLayoutSetActive(row, has_vertex_group);
|
2025-05-08 20:45:37 +02:00
|
|
|
row->prop(ptr, "protect", UI_ITEM_NONE, std::nullopt, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2025-05-12 22:14:38 +02:00
|
|
|
layout->op("OBJECT_OT_explode_refresh", IFACE_("Refresh"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2025-05-13 17:27:30 +02:00
|
|
|
modifier_error_message_draw(layout, ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void panel_register(ARegionType *region_type)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
modifier_panel_register(region_type, eModifierType_Explode, panel_draw);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void blend_read(BlendDataReader * /*reader*/, ModifierData *md)
|
2020-06-23 17:25:44 +02:00
|
|
|
{
|
|
|
|
|
ExplodeModifierData *psmd = (ExplodeModifierData *)md;
|
|
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
psmd->facepa = nullptr;
|
2020-06-23 17:25:44 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
ModifierTypeInfo modifierType_Explode = {
|
2023-07-26 17:08:14 +02:00
|
|
|
/*idname*/ "Explode",
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("Explode"),
|
2023-07-27 12:04:18 +10:00
|
|
|
/*struct_name*/ "ExplodeModifierData",
|
|
|
|
|
/*struct_size*/ sizeof(ExplodeModifierData),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*srna*/ &RNA_ExplodeModifier,
|
2023-11-14 10:03:56 +01:00
|
|
|
/*type*/ ModifierTypeType::Constructive,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*flags*/ eModifierTypeFlag_AcceptsMesh,
|
|
|
|
|
/*icon*/ ICON_MOD_EXPLODE,
|
2023-07-27 12:04:18 +10:00
|
|
|
/*copy_data*/ copy_data,
|
|
|
|
|
|
|
|
|
|
/*deform_verts*/ nullptr,
|
|
|
|
|
/*deform_matrices*/ nullptr,
|
|
|
|
|
/*deform_verts_EM*/ nullptr,
|
|
|
|
|
/*deform_matrices_EM*/ nullptr,
|
|
|
|
|
/*modify_mesh*/ modify_mesh,
|
|
|
|
|
/*modify_geometry_set*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*init_data*/ init_data,
|
|
|
|
|
/*required_data_mask*/ required_data_mask,
|
|
|
|
|
/*free_data*/ free_data,
|
|
|
|
|
/*is_disabled*/ nullptr,
|
|
|
|
|
/*update_depsgraph*/ nullptr,
|
|
|
|
|
/*depends_on_time*/ depends_on_time,
|
|
|
|
|
/*depends_on_normals*/ nullptr,
|
|
|
|
|
/*foreach_ID_link*/ nullptr,
|
|
|
|
|
/*foreach_tex_link*/ nullptr,
|
|
|
|
|
/*free_runtime_data*/ nullptr,
|
|
|
|
|
/*panel_register*/ panel_register,
|
|
|
|
|
/*blend_write*/ nullptr,
|
|
|
|
|
/*blend_read*/ blend_read,
|
2024-01-18 22:51:30 +01:00
|
|
|
/*foreach_cache*/ nullptr,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|