2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2013-12-12 16:26:11 +11:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2013-12-12 16:26:11 +11:00
|
|
|
*
|
|
|
|
|
* Functions for accessing mesh connectivity data.
|
2023-01-10 14:49:51 -05:00
|
|
|
* eg: polys connected to verts, UVs connected to verts.
|
2013-12-12 16:26:11 +11:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
2015-04-09 16:12:20 +02:00
|
|
|
#include "DNA_vec_types.h"
|
2013-12-12 16:26:11 +11:00
|
|
|
|
2022-09-19 18:44:51 -05:00
|
|
|
#include "BLI_array.hh"
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
#include "BLI_bitmap.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_buffer.h"
|
2023-02-09 21:55:32 -05:00
|
|
|
#include "BLI_function_ref.hh"
|
2013-12-12 16:26:11 +11:00
|
|
|
#include "BLI_math.h"
|
2022-09-28 14:31:32 -05:00
|
|
|
#include "BLI_task.hh"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2013-12-12 16:26:11 +11:00
|
|
|
|
2013-12-12 17:11:27 +11:00
|
|
|
#include "BKE_customdata.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_mesh_mapping.h"
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
#include "BLI_memarena.h"
|
2013-12-12 16:26:11 +11:00
|
|
|
|
|
|
|
|
#include "BLI_strict_flags.h"
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Mesh Connectivity Mapping
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2023-03-01 15:57:50 -05:00
|
|
|
UvVertMap *BKE_mesh_uv_vert_map_create(const MPoly *polys,
|
Mesh: Move hide flags to generic attributes
This commit moves the hide status of mesh vertices, edges, and faces
from the `ME_FLAG` to optional generic boolean attributes. Storing this
data as generic attributes can significantly simplify and improve code,
as described in T95965.
The attributes are called `.hide_vert`, `.hide_edge`, and `.hide_poly`,
using the attribute name semantics discussed in T97452. 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 by default,
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 the hide status is used. When the flags are removed
completely, requirements will decrease when hiding is unused.
Further notes:
* Some code can be further simplified to skip some processing when the
hide attributes don't exist.
* The data is still stored in flags for `BMesh`, necessitating some
complexity in the conversion to and from `Mesh`.
* Access to the "hide" property of mesh elements in RNA is slower.
The separate boolean arrays should be used where possible.
Ref T95965
Differential Revision: https://developer.blender.org/D14685
2022-08-11 12:54:24 -04:00
|
|
|
const bool *hide_poly,
|
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
|
|
|
const bool *select_poly,
|
2018-07-16 15:58:12 +02:00
|
|
|
const MLoop *mloop,
|
Mesh: Move UV layers to generic attributes
Currently the `MLoopUV` struct stores UV coordinates and flags related
to editing UV maps in the UV editor. This patch changes the coordinates
to use the generic 2D vector type, and moves the flags into three
separate boolean attributes. This follows the design in T95965, with
the ultimate intention of simplifying code and improving performance.
Importantly, the change allows exporters and renderers to use UVs
"touched" by geometry nodes, which only creates generic attributes.
It also allows geometry nodes to create "proper" UV maps from scratch,
though only with the Store Named Attribute node for now.
The new design considers any 2D vector attribute on the corner domain
to be a UV map. In the future, they might be distinguished from regular
2D vectors with attribute metadata, which may be helpful because they
are often interpolated differently.
Most of the code changes deal with passing around UV BMesh custom data
offsets and tracking the boolean "sublayers". The boolean layers are
use the following prefixes for attribute names: vert selection: `.vs.`,
edge selection: `.es.`, pinning: `.pn.`. Currently these are short to
avoid using up the maximum length of attribute names. To accommodate
for these 4 extra characters, the name length limit is enlarged to 68
bytes, while the maximum user settable name length is still 64 bytes.
Unfortunately Python/RNA API access to the UV flag data becomes slower.
Accessing the boolean layers directly is be better for performance in
general.
Like the other mesh SoA refactors, backward and forward compatibility
aren't affected, and won't be changed until 4.0. We pay for that by
making mesh reading and writing more expensive with conversions.
Resolves T85962
Differential Revision: https://developer.blender.org/D14365
2023-01-10 00:47:04 -05:00
|
|
|
const float (*mloopuv)[2],
|
2021-06-18 14:27:41 +10:00
|
|
|
uint totpoly,
|
|
|
|
|
uint totvert,
|
2015-05-17 23:04:34 +10:00
|
|
|
const float limit[2],
|
|
|
|
|
const bool selected,
|
|
|
|
|
const bool use_winding)
|
2013-12-12 16:26:11 +11:00
|
|
|
{
|
2023-01-31 14:22:22 +11:00
|
|
|
/* NOTE: N-gon version WIP, based on #BM_uv_vert_map_create. */
|
|
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
UvVertMap *vmap;
|
|
|
|
|
UvMapVert *buf;
|
|
|
|
|
int i, totuv, nverts;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-09 16:12:20 +02:00
|
|
|
BLI_buffer_declare_static(vec2f, tf_uv_buf, BLI_BUFFER_NOP, 32);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-09 16:17:51 +02:00
|
|
|
totuv = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
/* generate UvMapVert array */
|
2023-03-03 10:50:54 -05:00
|
|
|
for (const int64_t a : blender::IndexRange(totpoly)) {
|
|
|
|
|
const MPoly &poly = polys[a];
|
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
|
|
|
if (!selected || (!(hide_poly && hide_poly[a]) && (select_poly && select_poly[a]))) {
|
2023-03-03 10:50:54 -05:00
|
|
|
totuv += poly.totloop;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (totuv == 0) {
|
2022-10-05 13:44:02 -05:00
|
|
|
return nullptr;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
vmap = (UvVertMap *)MEM_callocN(sizeof(*vmap), "UvVertMap");
|
2022-09-25 18:33:28 +10:00
|
|
|
buf = vmap->buf = (UvMapVert *)MEM_callocN(sizeof(*vmap->buf) * size_t(totuv), "UvMapVert");
|
2015-06-20 19:28:51 +10:00
|
|
|
vmap->vert = (UvMapVert **)MEM_callocN(sizeof(*vmap->vert) * totvert, "UvMapVert*");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
if (!vmap->vert || !vmap->buf) {
|
|
|
|
|
BKE_mesh_uv_vert_map_free(vmap);
|
2022-10-05 13:44:02 -05:00
|
|
|
return nullptr;
|
2013-12-12 16:26:11 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-28 10:50:59 +13:00
|
|
|
bool *winding = nullptr;
|
|
|
|
|
if (use_winding) {
|
|
|
|
|
winding = static_cast<bool *>(MEM_callocN(sizeof(*winding) * totpoly, "winding"));
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-03 10:50:54 -05:00
|
|
|
for (const int64_t a : blender::IndexRange(totpoly)) {
|
|
|
|
|
const MPoly &poly = polys[a];
|
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
|
|
|
if (!selected || (!(hide_poly && hide_poly[a]) && (select_poly && select_poly[a]))) {
|
2022-10-05 13:44:02 -05:00
|
|
|
float(*tf_uv)[2] = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-06-20 19:28:51 +10:00
|
|
|
if (use_winding) {
|
2023-03-03 10:50:54 -05:00
|
|
|
tf_uv = (float(*)[2])BLI_buffer_reinit_data(&tf_uv_buf, vec2f, size_t(poly.totloop));
|
2015-06-20 19:28:51 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-03-03 10:50:54 -05:00
|
|
|
nverts = poly.totloop;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
for (i = 0; i < nverts; i++) {
|
2022-09-25 18:33:28 +10:00
|
|
|
buf->loop_of_poly_index = ushort(i);
|
2023-03-03 10:50:54 -05:00
|
|
|
buf->poly_index = uint(a);
|
2022-10-05 13:44:02 -05:00
|
|
|
buf->separate = false;
|
2023-03-03 10:50:54 -05:00
|
|
|
buf->next = vmap->vert[mloop[poly.loopstart + i].v];
|
|
|
|
|
vmap->vert[mloop[poly.loopstart + i].v] = buf;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-06-20 19:28:51 +10:00
|
|
|
if (use_winding) {
|
2023-03-03 10:50:54 -05:00
|
|
|
copy_v2_v2(tf_uv[i], mloopuv[poly.loopstart + i]);
|
2015-06-20 19:28:51 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
buf++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-06-20 19:28:51 +10:00
|
|
|
if (use_winding) {
|
2022-09-25 18:33:28 +10:00
|
|
|
winding[a] = cross_poly_v2(tf_uv, uint(nverts)) > 0;
|
2015-06-20 19:28:51 +10:00
|
|
|
}
|
2013-12-12 16:26:11 +11:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
/* sort individual uvs for each vert */
|
2023-03-03 10:50:54 -05:00
|
|
|
for (uint a = 0; a < totvert; a++) {
|
2022-10-05 13:44:02 -05:00
|
|
|
UvMapVert *newvlist = nullptr, *vlist = vmap->vert[a];
|
2013-12-12 16:26:11 +11:00
|
|
|
UvMapVert *iterv, *v, *lastv, *next;
|
2018-07-16 15:58:12 +02:00
|
|
|
const float *uv, *uv2;
|
|
|
|
|
float uvdiff[2];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
while (vlist) {
|
|
|
|
|
v = vlist;
|
|
|
|
|
vlist = vlist->next;
|
|
|
|
|
v->next = newvlist;
|
|
|
|
|
newvlist = v;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-03-01 15:57:50 -05:00
|
|
|
uv = mloopuv[polys[v->poly_index].loopstart + v->loop_of_poly_index];
|
2022-10-05 13:44:02 -05:00
|
|
|
lastv = nullptr;
|
2013-12-12 16:26:11 +11:00
|
|
|
iterv = vlist;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
while (iterv) {
|
|
|
|
|
next = iterv->next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-03-01 15:57:50 -05:00
|
|
|
uv2 = mloopuv[polys[iterv->poly_index].loopstart + iterv->loop_of_poly_index];
|
2013-12-12 16:26:11 +11:00
|
|
|
sub_v2_v2v2(uvdiff, uv2, uv);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-09 16:12:20 +02:00
|
|
|
if (fabsf(uv[0] - uv2[0]) < limit[0] && fabsf(uv[1] - uv2[1]) < limit[1] &&
|
2018-07-16 15:37:27 +02:00
|
|
|
(!use_winding || winding[iterv->poly_index] == winding[v->poly_index])) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (lastv) {
|
2013-12-12 16:26:11 +11:00
|
|
|
lastv->next = next;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2013-12-12 16:26:11 +11:00
|
|
|
vlist = next;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-12-12 16:26:11 +11:00
|
|
|
iterv->next = newvlist;
|
|
|
|
|
newvlist = iterv;
|
|
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
else {
|
2013-12-12 16:26:11 +11:00
|
|
|
lastv = iterv;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
iterv = next;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-10-05 13:44:02 -05:00
|
|
|
newvlist->separate = true;
|
2013-12-12 16:26:11 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
vmap->vert[a] = newvlist;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-06-02 15:38:04 +10:00
|
|
|
if (use_winding) {
|
2015-06-20 19:28:51 +10:00
|
|
|
MEM_freeN(winding);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-09 16:12:20 +02:00
|
|
|
BLI_buffer_free(&tf_uv_buf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
return vmap;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-18 14:27:41 +10:00
|
|
|
UvMapVert *BKE_mesh_uv_vert_map_get_vert(UvVertMap *vmap, uint v)
|
2013-12-12 16:26:11 +11:00
|
|
|
{
|
|
|
|
|
return vmap->vert[v];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_mesh_uv_vert_map_free(UvVertMap *vmap)
|
|
|
|
|
{
|
|
|
|
|
if (vmap) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (vmap->vert) {
|
2013-12-12 16:26:11 +11:00
|
|
|
MEM_freeN(vmap->vert);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (vmap->buf) {
|
2013-12-12 16:26:11 +11:00
|
|
|
MEM_freeN(vmap->buf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-12-12 16:26:11 +11:00
|
|
|
MEM_freeN(vmap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
/**
|
|
|
|
|
* Generates a map where the key is the vertex and the value is a list
|
|
|
|
|
* of polys or loops that use that vertex as a corner. The lists are allocated
|
|
|
|
|
* from one memory pool.
|
|
|
|
|
*
|
|
|
|
|
* Wrapped by #BKE_mesh_vert_poly_map_create & BKE_mesh_vert_loop_map_create
|
|
|
|
|
*/
|
|
|
|
|
static void mesh_vert_poly_or_loop_map_create(MeshElemMap **r_map,
|
|
|
|
|
int **r_mem,
|
2023-03-01 15:57:50 -05:00
|
|
|
const MPoly *polys,
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
const MLoop *mloop,
|
|
|
|
|
int totvert,
|
|
|
|
|
int totpoly,
|
|
|
|
|
int totloop,
|
|
|
|
|
const bool do_loops)
|
2013-12-12 16:26:11 +11:00
|
|
|
{
|
2022-09-25 18:33:28 +10:00
|
|
|
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(size_t(totvert), __func__);
|
2013-12-12 16:26:11 +11:00
|
|
|
int *indices, *index_iter;
|
|
|
|
|
int i, j;
|
|
|
|
|
|
2022-09-25 18:33:28 +10:00
|
|
|
indices = static_cast<int *>(MEM_mallocN(sizeof(int) * size_t(totloop), __func__));
|
2022-09-19 18:44:51 -05:00
|
|
|
index_iter = indices;
|
2013-12-12 16:26:11 +11:00
|
|
|
|
|
|
|
|
/* Count number of polys for each vertex */
|
|
|
|
|
for (i = 0; i < totpoly; i++) {
|
2023-03-03 11:40:34 -05:00
|
|
|
const MPoly &poly = polys[i];
|
2013-12-12 16:26:11 +11:00
|
|
|
|
2023-03-03 11:40:34 -05:00
|
|
|
for (j = 0; j < poly.totloop; j++) {
|
|
|
|
|
map[mloop[poly.loopstart + j].v].count++;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-12-12 16:26:11 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Assign indices mem */
|
|
|
|
|
for (i = 0; i < totvert; i++) {
|
|
|
|
|
map[i].indices = index_iter;
|
|
|
|
|
index_iter += map[i].count;
|
|
|
|
|
|
|
|
|
|
/* Reset 'count' for use as index in last loop */
|
|
|
|
|
map[i].count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find the users */
|
|
|
|
|
for (i = 0; i < totpoly; i++) {
|
2023-03-03 11:40:34 -05:00
|
|
|
const MPoly &poly = polys[i];
|
2013-12-12 16:26:11 +11:00
|
|
|
|
2023-03-03 11:40:34 -05:00
|
|
|
for (j = 0; j < poly.totloop; j++) {
|
|
|
|
|
uint v = mloop[poly.loopstart + j].v;
|
2013-12-12 16:26:11 +11:00
|
|
|
|
2023-03-03 11:40:34 -05:00
|
|
|
map[v].indices[map[v].count] = do_loops ? poly.loopstart + j : i;
|
2013-12-12 16:26:11 +11:00
|
|
|
map[v].count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*r_map = map;
|
|
|
|
|
*r_mem = indices;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 08:36:10 +02:00
|
|
|
void BKE_mesh_vert_poly_map_create(MeshElemMap **r_map,
|
|
|
|
|
int **r_mem,
|
2023-03-01 15:57:50 -05:00
|
|
|
const MPoly *polys,
|
2018-07-13 08:36:10 +02:00
|
|
|
const MLoop *mloop,
|
|
|
|
|
int totvert,
|
|
|
|
|
int totpoly,
|
|
|
|
|
int totloop)
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
{
|
2023-03-01 15:57:50 -05:00
|
|
|
mesh_vert_poly_or_loop_map_create(r_map, r_mem, polys, mloop, totvert, totpoly, totloop, false);
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
}
|
|
|
|
|
|
2018-07-13 08:36:10 +02:00
|
|
|
void BKE_mesh_vert_loop_map_create(MeshElemMap **r_map,
|
|
|
|
|
int **r_mem,
|
2023-03-01 15:57:50 -05:00
|
|
|
const MPoly *polys,
|
2018-07-13 08:36:10 +02:00
|
|
|
const MLoop *mloop,
|
|
|
|
|
int totvert,
|
|
|
|
|
int totpoly,
|
|
|
|
|
int totloop)
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
{
|
2023-03-01 15:57:50 -05:00
|
|
|
mesh_vert_poly_or_loop_map_create(r_map, r_mem, polys, mloop, totvert, totpoly, totloop, true);
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
}
|
|
|
|
|
|
2016-05-21 12:38:02 +02:00
|
|
|
void BKE_mesh_vert_looptri_map_create(MeshElemMap **r_map,
|
|
|
|
|
int **r_mem,
|
|
|
|
|
const int totvert,
|
|
|
|
|
const MLoopTri *mlooptri,
|
|
|
|
|
const int totlooptri,
|
|
|
|
|
const MLoop *mloop,
|
2022-10-03 17:37:25 -05:00
|
|
|
const int /*totloop*/)
|
2016-05-21 12:38:02 +02:00
|
|
|
{
|
2022-09-25 18:33:28 +10:00
|
|
|
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(size_t(totvert), __func__);
|
|
|
|
|
int *indices = static_cast<int *>(MEM_mallocN(sizeof(int) * size_t(totlooptri) * 3, __func__));
|
2016-05-21 12:38:02 +02:00
|
|
|
int *index_step;
|
|
|
|
|
const MLoopTri *mlt;
|
|
|
|
|
int i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-21 12:38:02 +02:00
|
|
|
/* count face users */
|
|
|
|
|
for (i = 0, mlt = mlooptri; i < totlooptri; mlt++, i++) {
|
|
|
|
|
for (int j = 3; j--;) {
|
|
|
|
|
map[mloop[mlt->tri[j]].v].count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-21 12:38:02 +02:00
|
|
|
/* create offsets */
|
|
|
|
|
index_step = indices;
|
|
|
|
|
for (i = 0; i < totvert; i++) {
|
|
|
|
|
map[i].indices = index_step;
|
|
|
|
|
index_step += map[i].count;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-21 12:38:02 +02:00
|
|
|
/* re-count, using this as an index below */
|
|
|
|
|
map[i].count = 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-21 12:38:02 +02:00
|
|
|
/* assign looptri-edge users */
|
|
|
|
|
for (i = 0, mlt = mlooptri; i < totlooptri; mlt++, i++) {
|
|
|
|
|
for (int j = 3; j--;) {
|
|
|
|
|
MeshElemMap *map_ele = &map[mloop[mlt->tri[j]].v];
|
|
|
|
|
map_ele->indices[map_ele->count++] = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-21 12:38:02 +02:00
|
|
|
*r_map = map;
|
|
|
|
|
*r_mem = indices;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 08:36:10 +02:00
|
|
|
void BKE_mesh_vert_edge_map_create(
|
2023-03-01 15:57:50 -05:00
|
|
|
MeshElemMap **r_map, int **r_mem, const MEdge *edges, int totvert, int totedge)
|
2013-12-12 16:26:11 +11:00
|
|
|
{
|
2022-09-25 18:33:28 +10:00
|
|
|
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(size_t(totvert), __func__);
|
|
|
|
|
int *indices = static_cast<int *>(MEM_mallocN(sizeof(int[2]) * size_t(totedge), __func__));
|
2013-12-12 16:26:11 +11:00
|
|
|
int *i_pt = indices;
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* Count number of edges for each vertex */
|
|
|
|
|
for (i = 0; i < totedge; i++) {
|
2023-03-01 15:57:50 -05:00
|
|
|
map[edges[i].v1].count++;
|
|
|
|
|
map[edges[i].v2].count++;
|
2013-12-12 16:26:11 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Assign indices mem */
|
|
|
|
|
for (i = 0; i < totvert; i++) {
|
|
|
|
|
map[i].indices = i_pt;
|
|
|
|
|
i_pt += map[i].count;
|
|
|
|
|
|
|
|
|
|
/* Reset 'count' for use as index in last loop */
|
|
|
|
|
map[i].count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find the users */
|
|
|
|
|
for (i = 0; i < totedge; i++) {
|
2023-03-01 15:57:50 -05:00
|
|
|
const uint v[2] = {edges[i].v1, edges[i].v2};
|
2013-12-12 16:26:11 +11:00
|
|
|
|
|
|
|
|
map[v[0]].indices[map[v[0]].count] = i;
|
|
|
|
|
map[v[1]].indices[map[v[1]].count] = i;
|
|
|
|
|
|
|
|
|
|
map[v[0]].count++;
|
|
|
|
|
map[v[1]].count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*r_map = map;
|
|
|
|
|
*r_mem = indices;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 22:07:45 +11:00
|
|
|
void BKE_mesh_vert_edge_vert_map_create(
|
2023-03-01 15:57:50 -05:00
|
|
|
MeshElemMap **r_map, int **r_mem, const MEdge *edges, int totvert, int totedge)
|
2016-03-22 22:07:45 +11:00
|
|
|
{
|
2022-09-25 18:33:28 +10:00
|
|
|
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(size_t(totvert), __func__);
|
|
|
|
|
int *indices = static_cast<int *>(MEM_mallocN(sizeof(int[2]) * size_t(totedge), __func__));
|
2016-03-22 22:07:45 +11:00
|
|
|
int *i_pt = indices;
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* Count number of edges for each vertex */
|
|
|
|
|
for (i = 0; i < totedge; i++) {
|
2023-03-01 15:57:50 -05:00
|
|
|
map[edges[i].v1].count++;
|
|
|
|
|
map[edges[i].v2].count++;
|
2016-03-22 22:07:45 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Assign indices mem */
|
|
|
|
|
for (i = 0; i < totvert; i++) {
|
|
|
|
|
map[i].indices = i_pt;
|
|
|
|
|
i_pt += map[i].count;
|
|
|
|
|
|
|
|
|
|
/* Reset 'count' for use as index in last loop */
|
|
|
|
|
map[i].count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find the users */
|
|
|
|
|
for (i = 0; i < totedge; i++) {
|
2023-03-01 15:57:50 -05:00
|
|
|
const uint v[2] = {edges[i].v1, edges[i].v2};
|
2016-03-22 22:07:45 +11:00
|
|
|
|
2022-09-25 18:33:28 +10:00
|
|
|
map[v[0]].indices[map[v[0]].count] = int(v[1]);
|
|
|
|
|
map[v[1]].indices[map[v[1]].count] = int(v[0]);
|
2016-03-22 22:07:45 +11:00
|
|
|
|
|
|
|
|
map[v[0]].count++;
|
|
|
|
|
map[v[1]].count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*r_map = map;
|
|
|
|
|
*r_mem = indices;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 08:36:10 +02:00
|
|
|
void BKE_mesh_edge_loop_map_create(MeshElemMap **r_map,
|
|
|
|
|
int **r_mem,
|
|
|
|
|
const int totedge,
|
2023-03-01 15:57:50 -05:00
|
|
|
const MPoly *polys,
|
2018-07-13 08:36:10 +02:00
|
|
|
const int totpoly,
|
|
|
|
|
const MLoop *mloop,
|
|
|
|
|
const int totloop)
|
2016-07-21 16:30:57 +02:00
|
|
|
{
|
2022-09-25 18:33:28 +10:00
|
|
|
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(size_t(totedge), __func__);
|
|
|
|
|
int *indices = static_cast<int *>(MEM_mallocN(sizeof(int) * size_t(totloop) * 2, __func__));
|
2016-07-21 16:30:57 +02:00
|
|
|
int *index_step;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-21 16:30:57 +02:00
|
|
|
/* count face users */
|
2023-03-03 10:50:54 -05:00
|
|
|
for (const int64_t i : blender::IndexRange(totpoly)) {
|
|
|
|
|
const MPoly &poly = polys[i];
|
2016-07-21 16:30:57 +02:00
|
|
|
const MLoop *ml;
|
2023-03-03 10:50:54 -05:00
|
|
|
int j = poly.totloop;
|
|
|
|
|
for (ml = &mloop[poly.loopstart]; j--; ml++) {
|
2016-07-21 16:30:57 +02:00
|
|
|
map[ml->e].count += 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-21 16:30:57 +02:00
|
|
|
/* create offsets */
|
|
|
|
|
index_step = indices;
|
2023-03-03 10:50:54 -05:00
|
|
|
for (int i = 0; i < totedge; i++) {
|
2016-07-21 16:30:57 +02:00
|
|
|
map[i].indices = index_step;
|
|
|
|
|
index_step += map[i].count;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-21 16:30:57 +02:00
|
|
|
/* re-count, using this as an index below */
|
|
|
|
|
map[i].count = 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-21 16:30:57 +02:00
|
|
|
/* assign loop-edge users */
|
2023-03-03 10:50:54 -05:00
|
|
|
for (const int64_t i : blender::IndexRange(totpoly)) {
|
|
|
|
|
const MPoly &poly = polys[i];
|
2016-07-21 16:30:57 +02:00
|
|
|
const MLoop *ml;
|
|
|
|
|
MeshElemMap *map_ele;
|
2023-03-03 10:50:54 -05:00
|
|
|
const int max_loop = poly.loopstart + poly.totloop;
|
|
|
|
|
int j = poly.loopstart;
|
2016-07-21 16:30:57 +02:00
|
|
|
for (ml = &mloop[j]; j < max_loop; j++, ml++) {
|
|
|
|
|
map_ele = &map[ml->e];
|
|
|
|
|
map_ele->indices[map_ele->count++] = j;
|
|
|
|
|
map_ele->indices[map_ele->count++] = j + 1;
|
|
|
|
|
}
|
|
|
|
|
/* last edge/loop of poly, must point back to first loop! */
|
2023-03-03 10:50:54 -05:00
|
|
|
map_ele->indices[map_ele->count - 1] = poly.loopstart;
|
2016-07-21 16:30:57 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-21 16:30:57 +02:00
|
|
|
*r_map = map;
|
|
|
|
|
*r_mem = indices;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 08:36:10 +02:00
|
|
|
void BKE_mesh_edge_poly_map_create(MeshElemMap **r_map,
|
|
|
|
|
int **r_mem,
|
|
|
|
|
const int totedge,
|
2023-03-01 15:57:50 -05:00
|
|
|
const MPoly *polys,
|
2018-07-13 08:36:10 +02:00
|
|
|
const int totpoly,
|
|
|
|
|
const MLoop *mloop,
|
|
|
|
|
const int totloop)
|
2013-12-12 16:26:11 +11:00
|
|
|
{
|
2022-09-25 18:33:28 +10:00
|
|
|
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(size_t(totedge), __func__);
|
|
|
|
|
int *indices = static_cast<int *>(MEM_mallocN(sizeof(int) * size_t(totloop), __func__));
|
2013-12-12 16:26:11 +11:00
|
|
|
int *index_step;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
/* count face users */
|
2023-03-03 10:50:54 -05:00
|
|
|
for (const int64_t i : blender::IndexRange(totpoly)) {
|
|
|
|
|
const MPoly &poly = polys[i];
|
2013-12-12 16:26:11 +11:00
|
|
|
const MLoop *ml;
|
2023-03-03 10:50:54 -05:00
|
|
|
int j = poly.totloop;
|
|
|
|
|
for (ml = &mloop[poly.loopstart]; j--; ml++) {
|
2013-12-12 16:26:11 +11:00
|
|
|
map[ml->e].count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
/* create offsets */
|
|
|
|
|
index_step = indices;
|
2023-03-03 10:50:54 -05:00
|
|
|
for (int i = 0; i < totedge; i++) {
|
2013-12-12 16:26:11 +11:00
|
|
|
map[i].indices = index_step;
|
|
|
|
|
index_step += map[i].count;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
/* re-count, using this as an index below */
|
|
|
|
|
map[i].count = 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
/* assign poly-edge users */
|
2023-03-03 10:50:54 -05:00
|
|
|
for (const int64_t i : blender::IndexRange(totpoly)) {
|
|
|
|
|
const MPoly &poly = polys[i];
|
2013-12-12 16:26:11 +11:00
|
|
|
const MLoop *ml;
|
2023-03-03 10:50:54 -05:00
|
|
|
int j = poly.totloop;
|
|
|
|
|
for (ml = &mloop[poly.loopstart]; j--; ml++) {
|
2013-12-12 16:26:11 +11:00
|
|
|
MeshElemMap *map_ele = &map[ml->e];
|
2023-03-03 10:50:54 -05:00
|
|
|
map_ele->indices[map_ele->count++] = int(i);
|
2013-12-12 16:26:11 +11:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
*r_map = map;
|
|
|
|
|
*r_mem = indices;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 08:36:10 +02:00
|
|
|
void BKE_mesh_origindex_map_create(MeshElemMap **r_map,
|
|
|
|
|
int **r_mem,
|
|
|
|
|
const int totsource,
|
|
|
|
|
const int *final_origindex,
|
|
|
|
|
const int totfinal)
|
2013-12-12 17:11:27 +11:00
|
|
|
{
|
2022-09-25 18:33:28 +10:00
|
|
|
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(size_t(totsource), __func__);
|
|
|
|
|
int *indices = static_cast<int *>(MEM_mallocN(sizeof(int) * size_t(totfinal), __func__));
|
2013-12-12 17:11:27 +11:00
|
|
|
int *index_step;
|
|
|
|
|
int i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 17:11:27 +11:00
|
|
|
/* count face users */
|
|
|
|
|
for (i = 0; i < totfinal; i++) {
|
|
|
|
|
if (final_origindex[i] != ORIGINDEX_NONE) {
|
|
|
|
|
BLI_assert(final_origindex[i] < totsource);
|
|
|
|
|
map[final_origindex[i]].count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 17:11:27 +11:00
|
|
|
/* create offsets */
|
|
|
|
|
index_step = indices;
|
|
|
|
|
for (i = 0; i < totsource; i++) {
|
|
|
|
|
map[i].indices = index_step;
|
|
|
|
|
index_step += map[i].count;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 17:11:27 +11:00
|
|
|
/* re-count, using this as an index below */
|
|
|
|
|
map[i].count = 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 17:11:27 +11:00
|
|
|
/* assign poly-tessface users */
|
|
|
|
|
for (i = 0; i < totfinal; i++) {
|
|
|
|
|
if (final_origindex[i] != ORIGINDEX_NONE) {
|
|
|
|
|
MeshElemMap *map_ele = &map[final_origindex[i]];
|
|
|
|
|
map_ele->indices[map_ele->count++] = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 17:11:27 +11:00
|
|
|
*r_map = map;
|
|
|
|
|
*r_mem = indices;
|
|
|
|
|
}
|
2013-12-12 16:26:11 +11:00
|
|
|
|
2015-07-23 15:08:27 +10:00
|
|
|
void BKE_mesh_origindex_map_create_looptri(MeshElemMap **r_map,
|
|
|
|
|
int **r_mem,
|
2023-03-01 15:57:50 -05:00
|
|
|
const MPoly *polys,
|
|
|
|
|
const int polys_num,
|
2015-07-23 15:08:27 +10:00
|
|
|
const MLoopTri *looptri,
|
|
|
|
|
const int looptri_num)
|
|
|
|
|
{
|
2023-03-01 15:57:50 -05:00
|
|
|
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(size_t(polys_num), __func__);
|
2022-09-25 18:33:28 +10:00
|
|
|
int *indices = static_cast<int *>(MEM_mallocN(sizeof(int) * size_t(looptri_num), __func__));
|
2015-07-23 15:08:27 +10:00
|
|
|
int *index_step;
|
|
|
|
|
int i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-07-23 15:08:27 +10:00
|
|
|
/* create offsets */
|
|
|
|
|
index_step = indices;
|
2023-03-01 15:57:50 -05:00
|
|
|
for (i = 0; i < polys_num; i++) {
|
2015-07-23 15:08:27 +10:00
|
|
|
map[i].indices = index_step;
|
2023-03-01 15:57:50 -05:00
|
|
|
index_step += ME_POLY_TRI_TOT(&polys[i]);
|
2015-07-23 15:08:27 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-07-23 15:08:27 +10:00
|
|
|
/* assign poly-tessface users */
|
|
|
|
|
for (i = 0; i < looptri_num; i++) {
|
|
|
|
|
MeshElemMap *map_ele = &map[looptri[i].poly];
|
|
|
|
|
map_ele->indices[map_ele->count++] = i;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-07-23 15:08:27 +10:00
|
|
|
*r_map = map;
|
|
|
|
|
*r_mem = indices;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-12 17:41:35 -05:00
|
|
|
namespace blender::bke::mesh_topology {
|
2022-09-28 14:31:32 -05:00
|
|
|
|
2022-10-06 17:34:53 -05:00
|
|
|
Array<int> build_loop_to_poly_map(const Span<MPoly> polys, const int loops_num)
|
2022-09-28 14:31:32 -05:00
|
|
|
{
|
|
|
|
|
Array<int> map(loops_num);
|
|
|
|
|
threading::parallel_for(polys.index_range(), 1024, [&](IndexRange range) {
|
|
|
|
|
for (const int64_t poly_i : range) {
|
|
|
|
|
const MPoly &poly = polys[poly_i];
|
|
|
|
|
map.as_mutable_span().slice(poly.loopstart, poly.totloop).fill(int(poly_i));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Array<Vector<int>> build_vert_to_edge_map(const Span<MEdge> edges, const int verts_num)
|
|
|
|
|
{
|
|
|
|
|
Array<Vector<int>> map(verts_num);
|
|
|
|
|
for (const int64_t i : edges.index_range()) {
|
|
|
|
|
map[edges[i].v1].append(int(i));
|
|
|
|
|
map[edges[i].v2].append(int(i));
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-27 23:03:38 -06:00
|
|
|
Array<Vector<int>> build_vert_to_poly_map(const Span<MPoly> polys,
|
|
|
|
|
const Span<MLoop> loops,
|
|
|
|
|
int verts_num)
|
|
|
|
|
{
|
|
|
|
|
Array<Vector<int>> map(verts_num);
|
|
|
|
|
for (const int64_t i : polys.index_range()) {
|
|
|
|
|
const MPoly &poly = polys[i];
|
|
|
|
|
for (const MLoop &loop : loops.slice(poly.loopstart, poly.totloop)) {
|
|
|
|
|
map[loop.v].append(int(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-06 17:34:53 -05:00
|
|
|
Array<Vector<int>> build_vert_to_loop_map(const Span<MLoop> loops, const int verts_num)
|
2022-09-28 14:31:32 -05:00
|
|
|
{
|
|
|
|
|
Array<Vector<int>> map(verts_num);
|
|
|
|
|
for (const int64_t i : loops.index_range()) {
|
|
|
|
|
map[loops[i].v].append(int(i));
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-20 15:42:10 -06:00
|
|
|
Array<Vector<int>> build_edge_to_loop_map(const Span<MLoop> loops, const int edges_num)
|
|
|
|
|
{
|
|
|
|
|
Array<Vector<int>> map(edges_num);
|
|
|
|
|
for (const int64_t i : loops.index_range()) {
|
|
|
|
|
map[loops[i].e].append(int(i));
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-09 16:27:20 +01:00
|
|
|
Array<Vector<int, 2>> build_edge_to_poly_map(const Span<MPoly> polys,
|
|
|
|
|
const Span<MLoop> loops,
|
|
|
|
|
const int edges_num)
|
|
|
|
|
{
|
|
|
|
|
Array<Vector<int, 2>> map(edges_num);
|
|
|
|
|
for (const int64_t i : polys.index_range()) {
|
|
|
|
|
const MPoly &poly = polys[i];
|
|
|
|
|
for (const MLoop &loop : loops.slice(poly.loopstart, poly.totloop)) {
|
|
|
|
|
map[loop.e].append(int(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-20 15:42:10 -06:00
|
|
|
Vector<Vector<int>> build_edge_to_loop_map_resizable(const Span<MLoop> loops, const int edges_num)
|
|
|
|
|
{
|
|
|
|
|
Vector<Vector<int>> map(edges_num);
|
|
|
|
|
for (const int64_t i : loops.index_range()) {
|
|
|
|
|
map[loops[i].e].append(int(i));
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-12 17:41:35 -05:00
|
|
|
} // namespace blender::bke::mesh_topology
|
2022-09-28 14:31:32 -05:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
/** \name Mesh loops/poly islands.
|
|
|
|
|
* Used currently for UVs and 'smooth groups'.
|
2013-12-12 16:26:11 +11:00
|
|
|
* \{ */
|
|
|
|
|
|
2015-04-28 14:15:27 +02:00
|
|
|
/**
|
|
|
|
|
* Callback deciding whether the given poly/loop/edge define an island boundary or not.
|
2013-12-12 16:26:11 +11:00
|
|
|
*/
|
2023-02-09 21:55:32 -05:00
|
|
|
using MeshRemap_CheckIslandBoundary =
|
|
|
|
|
blender::FunctionRef<bool(int poly_index,
|
|
|
|
|
int loop_index,
|
|
|
|
|
int edge_index,
|
|
|
|
|
int edge_user_count,
|
|
|
|
|
const MeshElemMap &edge_poly_map_elem)>;
|
|
|
|
|
|
|
|
|
|
static void poly_edge_loop_islands_calc(const int totedge,
|
|
|
|
|
const blender::Span<MPoly> polys,
|
|
|
|
|
const blender::Span<MLoop> loops,
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
MeshElemMap *edge_poly_map,
|
2016-07-21 16:53:00 +02:00
|
|
|
const bool use_bitflags,
|
|
|
|
|
MeshRemap_CheckIslandBoundary edge_boundary_check,
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
int **r_poly_groups,
|
|
|
|
|
int *r_totgroup,
|
|
|
|
|
BLI_bitmap **r_edge_borders,
|
|
|
|
|
int *r_totedgeborder)
|
2013-12-12 16:26:11 +11:00
|
|
|
{
|
|
|
|
|
int *poly_groups;
|
|
|
|
|
int *poly_stack;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-10-05 13:44:02 -05:00
|
|
|
BLI_bitmap *edge_borders = nullptr;
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
int num_edgeborders = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
int poly_prev = 0;
|
|
|
|
|
const int temp_poly_group_id = 3; /* Placeholder value. */
|
2019-07-02 22:17:22 +10:00
|
|
|
|
|
|
|
|
/* Group we could not find any available bit, will be reset to 0 at end. */
|
|
|
|
|
const int poly_group_id_overflowed = 5;
|
|
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
int tot_group = 0;
|
|
|
|
|
bool group_id_overflow = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
/* map vars */
|
2022-10-05 13:44:02 -05:00
|
|
|
int *edge_poly_mem = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-02-09 21:55:32 -05:00
|
|
|
if (polys.size() == 0) {
|
2013-12-12 16:26:11 +11:00
|
|
|
*r_totgroup = 0;
|
2022-10-05 13:44:02 -05:00
|
|
|
*r_poly_groups = nullptr;
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
if (r_edge_borders) {
|
2022-10-05 13:44:02 -05:00
|
|
|
*r_edge_borders = nullptr;
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
*r_totedgeborder = 0;
|
|
|
|
|
}
|
|
|
|
|
return;
|
2013-12-12 16:26:11 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
if (r_edge_borders) {
|
|
|
|
|
edge_borders = BLI_BITMAP_NEW(totedge, __func__);
|
|
|
|
|
*r_totedgeborder = 0;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
if (!edge_poly_map) {
|
2023-02-09 21:55:32 -05:00
|
|
|
BKE_mesh_edge_poly_map_create(&edge_poly_map,
|
|
|
|
|
&edge_poly_mem,
|
|
|
|
|
totedge,
|
|
|
|
|
polys.data(),
|
|
|
|
|
int(polys.size()),
|
|
|
|
|
loops.data(),
|
|
|
|
|
int(loops.size()));
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-02-09 21:55:32 -05:00
|
|
|
poly_groups = static_cast<int *>(MEM_callocN(sizeof(int) * size_t(polys.size()), __func__));
|
|
|
|
|
poly_stack = static_cast<int *>(MEM_mallocN(sizeof(int) * size_t(polys.size()), __func__));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
while (true) {
|
|
|
|
|
int poly;
|
|
|
|
|
int bit_poly_group_mask = 0;
|
|
|
|
|
int poly_group_id;
|
|
|
|
|
int ps_curr_idx = 0, ps_end_idx = 0; /* stack indices */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-02-09 21:55:32 -05:00
|
|
|
for (poly = poly_prev; poly < int(polys.size()); poly++) {
|
2013-12-12 16:26:11 +11:00
|
|
|
if (poly_groups[poly] == 0) {
|
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-12-12 16:26:11 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-02-09 21:55:32 -05:00
|
|
|
if (poly == int(polys.size())) {
|
2013-12-12 16:26:11 +11:00
|
|
|
/* all done */
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
poly_group_id = use_bitflags ? temp_poly_group_id : ++tot_group;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
/* start searching from here next time */
|
|
|
|
|
poly_prev = poly + 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
poly_groups[poly] = poly_group_id;
|
|
|
|
|
poly_stack[ps_end_idx++] = poly;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
while (ps_curr_idx != ps_end_idx) {
|
|
|
|
|
poly = poly_stack[ps_curr_idx++];
|
|
|
|
|
BLI_assert(poly_groups[poly] == poly_group_id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-02-09 21:55:32 -05:00
|
|
|
for (const int64_t loop : blender::IndexRange(polys[poly].loopstart, polys[poly].totloop)) {
|
|
|
|
|
const int edge = int(loops[loop].e);
|
2013-12-12 16:26:11 +11:00
|
|
|
/* loop over poly users */
|
2023-02-09 21:55:32 -05:00
|
|
|
const MeshElemMap &map_ele = edge_poly_map[edge];
|
|
|
|
|
const int *p = map_ele.indices;
|
|
|
|
|
int i = map_ele.count;
|
|
|
|
|
if (!edge_boundary_check(poly, int(loop), edge, i, map_ele)) {
|
2013-12-12 16:26:11 +11:00
|
|
|
for (; i--; p++) {
|
|
|
|
|
/* if we meet other non initialized its a bug */
|
|
|
|
|
BLI_assert(ELEM(poly_groups[*p], 0, poly_group_id));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
if (poly_groups[*p] == 0) {
|
|
|
|
|
poly_groups[*p] = poly_group_id;
|
|
|
|
|
poly_stack[ps_end_idx++] = *p;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-12-12 16:26:11 +11:00
|
|
|
}
|
|
|
|
|
}
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
else {
|
2023-02-09 21:55:32 -05:00
|
|
|
if (edge_borders && !BLI_BITMAP_TEST(edge_borders, edge)) {
|
|
|
|
|
BLI_BITMAP_ENABLE(edge_borders, edge);
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
num_edgeborders++;
|
|
|
|
|
}
|
|
|
|
|
if (use_bitflags) {
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Find contiguous smooth groups already assigned,
|
|
|
|
|
* these are the values we can't reuse! */
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
for (; i--; p++) {
|
|
|
|
|
int bit = poly_groups[*p];
|
|
|
|
|
if (!ELEM(bit, 0, poly_group_id, poly_group_id_overflowed) &&
|
|
|
|
|
!(bit_poly_group_mask & bit)) {
|
|
|
|
|
bit_poly_group_mask |= bit;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
}
|
2013-12-12 16:26:11 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-27 12:07:07 +10:00
|
|
|
/* And now, we have all our poly from current group in poly_stack
|
|
|
|
|
* (from 0 to (ps_end_idx - 1)),
|
|
|
|
|
* as well as all smoothgroups bits we can't use in bit_poly_group_mask.
|
2013-12-12 16:26:11 +11:00
|
|
|
*/
|
|
|
|
|
if (use_bitflags) {
|
|
|
|
|
int i, *p, gid_bit = 0;
|
|
|
|
|
poly_group_id = 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
/* Find first bit available! */
|
|
|
|
|
for (; (poly_group_id & bit_poly_group_mask) && (gid_bit < 32); gid_bit++) {
|
|
|
|
|
poly_group_id <<= 1; /* will 'overflow' on last possible iteration. */
|
|
|
|
|
}
|
|
|
|
|
if (UNLIKELY(gid_bit > 31)) {
|
|
|
|
|
/* All bits used in contiguous smooth groups, we can't do much!
|
2021-07-03 23:08:40 +10:00
|
|
|
* NOTE: this is *very* unlikely - theoretically, four groups are enough,
|
2020-11-20 11:39:03 +11:00
|
|
|
* I don't think we can reach this goal with such a simple algorithm,
|
2019-04-27 12:07:07 +10:00
|
|
|
* but I don't think either we'll never need all 32 groups!
|
2013-12-12 16:26:11 +11:00
|
|
|
*/
|
|
|
|
|
printf(
|
|
|
|
|
"Warning, could not find an available id for current smooth group, faces will me "
|
|
|
|
|
"marked "
|
|
|
|
|
"as out of any smooth group...\n");
|
2019-07-02 22:17:22 +10:00
|
|
|
|
|
|
|
|
/* Can't use 0, will have to set them to this value later. */
|
|
|
|
|
poly_group_id = poly_group_id_overflowed;
|
|
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
group_id_overflow = true;
|
|
|
|
|
}
|
|
|
|
|
if (gid_bit > tot_group) {
|
|
|
|
|
tot_group = gid_bit;
|
|
|
|
|
}
|
|
|
|
|
/* And assign the final smooth group id to that poly group! */
|
|
|
|
|
for (i = ps_end_idx, p = poly_stack; i--; p++) {
|
|
|
|
|
poly_groups[*p] = poly_group_id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-13 10:32:59 +02:00
|
|
|
if (use_bitflags) {
|
|
|
|
|
/* used bits are zero-based. */
|
|
|
|
|
tot_group++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
if (UNLIKELY(group_id_overflow)) {
|
2023-02-09 21:55:32 -05:00
|
|
|
int i = int(polys.size()), *gid = poly_groups;
|
2013-12-12 16:26:11 +11:00
|
|
|
for (; i--; gid++) {
|
|
|
|
|
if (*gid == poly_group_id_overflowed) {
|
|
|
|
|
*gid = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-13 10:32:59 +02:00
|
|
|
/* Using 0 as group id adds one more group! */
|
|
|
|
|
tot_group++;
|
2013-12-12 16:26:11 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
if (edge_poly_mem) {
|
|
|
|
|
MEM_freeN(edge_poly_map);
|
|
|
|
|
MEM_freeN(edge_poly_mem);
|
|
|
|
|
}
|
2013-12-12 16:26:11 +11:00
|
|
|
MEM_freeN(poly_stack);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-13 10:32:59 +02:00
|
|
|
*r_totgroup = tot_group;
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
*r_poly_groups = poly_groups;
|
|
|
|
|
if (r_edge_borders) {
|
|
|
|
|
*r_edge_borders = edge_borders;
|
|
|
|
|
*r_totedgeborder = num_edgeborders;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-09 21:55:32 -05:00
|
|
|
int *BKE_mesh_calc_smoothgroups(const int totedge,
|
2023-03-01 15:57:50 -05:00
|
|
|
const MPoly *polys,
|
2018-07-13 08:36:10 +02:00
|
|
|
const int totpoly,
|
|
|
|
|
const MLoop *mloop,
|
|
|
|
|
const int totloop,
|
2023-01-10 16:12:14 -05:00
|
|
|
const bool *sharp_edges,
|
Mesh: Move face shade smooth flag to a generic attribute
Currently the shade smooth status for mesh faces is stored as part of
`MPoly::flag`. As described in #95967, this moves that information
to a separate boolean attribute. It also flips its status, so the
attribute is now called `sharp_face`, which mirrors the existing
`sharp_edge` attribute. The attribute doesn't need to be allocated
when all faces are smooth. Forward compatibility is kept until
4.0 like the other mesh refactors.
This will reduce memory bandwidth requirements for some operations,
since the array of booleans uses 12 times less memory than `MPoly`.
It also allows faces to be stored more efficiently in the future, since
the flag is now unused. It's also possible to use generic functions to
process the values. For example, finding whether there is a sharp face
is just `sharp_faces.contains(true)`.
The `shade_smooth` attribute is no longer accessible with geometry nodes.
Since there were dedicated accessor nodes for that data, that shouldn't
be a problem. That's difficult to version automatically since the named
attribute nodes could be used in arbitrary combinations.
**Implementation notes:**
- The attribute and array variables in the code use the `sharp_faces`
term, to be consistent with the user-facing "sharp faces" wording,
and to avoid requiring many renames when #101689 is implemented.
- Cycles now accesses smooth face status with the generic attribute,
to avoid overhead.
- Changing the zero-value from "smooth" to "flat" takes some care to
make sure defaults are the same.
- Versioning for the edge mode extrude node is particularly complex.
New nodes are added by versioning to propagate the attribute in its
old inverted state.
- A lot of access is still done through the `CustomData` API rather
than the attribute API because of a few functions. That can be
cleaned up easily in the future.
- In the future we would benefit from a way to store attributes as a
single value for when all faces are sharp.
Pull Request: https://projects.blender.org/blender/blender/pulls/104422
2023-03-08 15:36:18 +01:00
|
|
|
const bool *sharp_faces,
|
2018-07-13 08:36:10 +02:00
|
|
|
int *r_totgroup,
|
|
|
|
|
const bool use_bitflags)
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
{
|
2022-10-05 13:44:02 -05:00
|
|
|
int *poly_groups = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Move face shade smooth flag to a generic attribute
Currently the shade smooth status for mesh faces is stored as part of
`MPoly::flag`. As described in #95967, this moves that information
to a separate boolean attribute. It also flips its status, so the
attribute is now called `sharp_face`, which mirrors the existing
`sharp_edge` attribute. The attribute doesn't need to be allocated
when all faces are smooth. Forward compatibility is kept until
4.0 like the other mesh refactors.
This will reduce memory bandwidth requirements for some operations,
since the array of booleans uses 12 times less memory than `MPoly`.
It also allows faces to be stored more efficiently in the future, since
the flag is now unused. It's also possible to use generic functions to
process the values. For example, finding whether there is a sharp face
is just `sharp_faces.contains(true)`.
The `shade_smooth` attribute is no longer accessible with geometry nodes.
Since there were dedicated accessor nodes for that data, that shouldn't
be a problem. That's difficult to version automatically since the named
attribute nodes could be used in arbitrary combinations.
**Implementation notes:**
- The attribute and array variables in the code use the `sharp_faces`
term, to be consistent with the user-facing "sharp faces" wording,
and to avoid requiring many renames when #101689 is implemented.
- Cycles now accesses smooth face status with the generic attribute,
to avoid overhead.
- Changing the zero-value from "smooth" to "flat" takes some care to
make sure defaults are the same.
- Versioning for the edge mode extrude node is particularly complex.
New nodes are added by versioning to propagate the attribute in its
old inverted state.
- A lot of access is still done through the `CustomData` API rather
than the attribute API because of a few functions. That can be
cleaned up easily in the future.
- In the future we would benefit from a way to store attributes as a
single value for when all faces are sharp.
Pull Request: https://projects.blender.org/blender/blender/pulls/104422
2023-03-08 15:36:18 +01:00
|
|
|
auto poly_is_smooth = [&](const int i) { return !(sharp_faces && sharp_faces[i]); };
|
|
|
|
|
|
2023-02-09 21:55:32 -05:00
|
|
|
auto poly_is_island_boundary_smooth = [&](const int poly_index,
|
|
|
|
|
const int /*loop_index*/,
|
|
|
|
|
const int edge_index,
|
|
|
|
|
const int edge_user_count,
|
|
|
|
|
const MeshElemMap &edge_poly_map_elem) {
|
|
|
|
|
/* Edge is sharp if one of its polys is flat, or edge itself is sharp,
|
|
|
|
|
* or edge is not used by exactly two polygons. */
|
Mesh: Move face shade smooth flag to a generic attribute
Currently the shade smooth status for mesh faces is stored as part of
`MPoly::flag`. As described in #95967, this moves that information
to a separate boolean attribute. It also flips its status, so the
attribute is now called `sharp_face`, which mirrors the existing
`sharp_edge` attribute. The attribute doesn't need to be allocated
when all faces are smooth. Forward compatibility is kept until
4.0 like the other mesh refactors.
This will reduce memory bandwidth requirements for some operations,
since the array of booleans uses 12 times less memory than `MPoly`.
It also allows faces to be stored more efficiently in the future, since
the flag is now unused. It's also possible to use generic functions to
process the values. For example, finding whether there is a sharp face
is just `sharp_faces.contains(true)`.
The `shade_smooth` attribute is no longer accessible with geometry nodes.
Since there were dedicated accessor nodes for that data, that shouldn't
be a problem. That's difficult to version automatically since the named
attribute nodes could be used in arbitrary combinations.
**Implementation notes:**
- The attribute and array variables in the code use the `sharp_faces`
term, to be consistent with the user-facing "sharp faces" wording,
and to avoid requiring many renames when #101689 is implemented.
- Cycles now accesses smooth face status with the generic attribute,
to avoid overhead.
- Changing the zero-value from "smooth" to "flat" takes some care to
make sure defaults are the same.
- Versioning for the edge mode extrude node is particularly complex.
New nodes are added by versioning to propagate the attribute in its
old inverted state.
- A lot of access is still done through the `CustomData` API rather
than the attribute API because of a few functions. That can be
cleaned up easily in the future.
- In the future we would benefit from a way to store attributes as a
single value for when all faces are sharp.
Pull Request: https://projects.blender.org/blender/blender/pulls/104422
2023-03-08 15:36:18 +01:00
|
|
|
if ((poly_is_smooth(poly_index)) && !(sharp_edges && sharp_edges[edge_index]) &&
|
2023-02-09 21:55:32 -05:00
|
|
|
(edge_user_count == 2)) {
|
|
|
|
|
/* In that case, edge appears to be smooth, but we need to check its other poly too. */
|
|
|
|
|
const int other_poly_index = (poly_index == edge_poly_map_elem.indices[0]) ?
|
|
|
|
|
edge_poly_map_elem.indices[1] :
|
|
|
|
|
edge_poly_map_elem.indices[0];
|
Mesh: Move face shade smooth flag to a generic attribute
Currently the shade smooth status for mesh faces is stored as part of
`MPoly::flag`. As described in #95967, this moves that information
to a separate boolean attribute. It also flips its status, so the
attribute is now called `sharp_face`, which mirrors the existing
`sharp_edge` attribute. The attribute doesn't need to be allocated
when all faces are smooth. Forward compatibility is kept until
4.0 like the other mesh refactors.
This will reduce memory bandwidth requirements for some operations,
since the array of booleans uses 12 times less memory than `MPoly`.
It also allows faces to be stored more efficiently in the future, since
the flag is now unused. It's also possible to use generic functions to
process the values. For example, finding whether there is a sharp face
is just `sharp_faces.contains(true)`.
The `shade_smooth` attribute is no longer accessible with geometry nodes.
Since there were dedicated accessor nodes for that data, that shouldn't
be a problem. That's difficult to version automatically since the named
attribute nodes could be used in arbitrary combinations.
**Implementation notes:**
- The attribute and array variables in the code use the `sharp_faces`
term, to be consistent with the user-facing "sharp faces" wording,
and to avoid requiring many renames when #101689 is implemented.
- Cycles now accesses smooth face status with the generic attribute,
to avoid overhead.
- Changing the zero-value from "smooth" to "flat" takes some care to
make sure defaults are the same.
- Versioning for the edge mode extrude node is particularly complex.
New nodes are added by versioning to propagate the attribute in its
old inverted state.
- A lot of access is still done through the `CustomData` API rather
than the attribute API because of a few functions. That can be
cleaned up easily in the future.
- In the future we would benefit from a way to store attributes as a
single value for when all faces are sharp.
Pull Request: https://projects.blender.org/blender/blender/pulls/104422
2023-03-08 15:36:18 +01:00
|
|
|
return !poly_is_smooth(other_poly_index);
|
2023-02-09 21:55:32 -05:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
poly_edge_loop_islands_calc(totedge,
|
2023-03-01 15:57:50 -05:00
|
|
|
{polys, totpoly},
|
2023-02-09 21:55:32 -05:00
|
|
|
{mloop, totloop},
|
2022-10-05 13:44:02 -05:00
|
|
|
nullptr,
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
use_bitflags,
|
2023-02-09 21:55:32 -05:00
|
|
|
poly_is_island_boundary_smooth,
|
2016-07-21 16:53:00 +02:00
|
|
|
&poly_groups,
|
|
|
|
|
r_totgroup,
|
2022-10-05 13:44:02 -05:00
|
|
|
nullptr,
|
|
|
|
|
nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
return poly_groups;
|
|
|
|
|
}
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
|
|
|
|
|
#define MISLAND_DEFAULT_BUFSIZE 64
|
|
|
|
|
|
|
|
|
|
void BKE_mesh_loop_islands_init(MeshIslandStore *island_store,
|
|
|
|
|
const short item_type,
|
|
|
|
|
const int items_num,
|
|
|
|
|
const short island_type,
|
|
|
|
|
const short innercut_type)
|
|
|
|
|
{
|
|
|
|
|
MemArena *mem = island_store->mem;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-10-05 13:44:02 -05:00
|
|
|
if (mem == nullptr) {
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
mem = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
|
|
|
|
|
island_store->mem = mem;
|
|
|
|
|
}
|
|
|
|
|
/* else memarena should be cleared */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
BLI_assert(
|
|
|
|
|
ELEM(item_type, MISLAND_TYPE_VERT, MISLAND_TYPE_EDGE, MISLAND_TYPE_POLY, MISLAND_TYPE_LOOP));
|
|
|
|
|
BLI_assert(ELEM(
|
|
|
|
|
island_type, MISLAND_TYPE_VERT, MISLAND_TYPE_EDGE, MISLAND_TYPE_POLY, MISLAND_TYPE_LOOP));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
island_store->item_type = item_type;
|
|
|
|
|
island_store->items_to_islands_num = items_num;
|
2022-09-19 18:44:51 -05:00
|
|
|
island_store->items_to_islands = static_cast<int *>(
|
2022-09-25 20:27:46 +10:00
|
|
|
BLI_memarena_alloc(mem, sizeof(*island_store->items_to_islands) * size_t(items_num)));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
island_store->island_type = island_type;
|
|
|
|
|
island_store->islands_num_alloc = MISLAND_DEFAULT_BUFSIZE;
|
2022-09-19 18:44:51 -05:00
|
|
|
island_store->islands = static_cast<MeshElemMap **>(
|
|
|
|
|
BLI_memarena_alloc(mem, sizeof(*island_store->islands) * island_store->islands_num_alloc));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
island_store->innercut_type = innercut_type;
|
2022-09-19 18:44:51 -05:00
|
|
|
island_store->innercuts = static_cast<MeshElemMap **>(
|
|
|
|
|
BLI_memarena_alloc(mem, sizeof(*island_store->innercuts) * island_store->islands_num_alloc));
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_mesh_loop_islands_clear(MeshIslandStore *island_store)
|
|
|
|
|
{
|
|
|
|
|
island_store->item_type = MISLAND_TYPE_NONE;
|
|
|
|
|
island_store->items_to_islands_num = 0;
|
2022-10-05 13:44:02 -05:00
|
|
|
island_store->items_to_islands = nullptr;
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
|
|
|
|
|
island_store->island_type = MISLAND_TYPE_NONE;
|
|
|
|
|
island_store->islands_num = 0;
|
2022-10-05 13:44:02 -05:00
|
|
|
island_store->islands = nullptr;
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
|
|
|
|
|
island_store->innercut_type = MISLAND_TYPE_NONE;
|
2022-10-05 13:44:02 -05:00
|
|
|
island_store->innercuts = nullptr;
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
|
|
|
|
|
if (island_store->mem) {
|
|
|
|
|
BLI_memarena_clear(island_store->mem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
island_store->islands_num_alloc = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_mesh_loop_islands_free(MeshIslandStore *island_store)
|
|
|
|
|
{
|
|
|
|
|
if (island_store->mem) {
|
|
|
|
|
BLI_memarena_free(island_store->mem);
|
2022-10-05 13:44:02 -05:00
|
|
|
island_store->mem = nullptr;
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_mesh_loop_islands_add(MeshIslandStore *island_store,
|
|
|
|
|
const int item_num,
|
2020-07-13 11:27:09 +02:00
|
|
|
const int *items_indices,
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
const int num_island_items,
|
|
|
|
|
int *island_item_indices,
|
|
|
|
|
const int num_innercut_items,
|
|
|
|
|
int *innercut_item_indices)
|
|
|
|
|
{
|
|
|
|
|
MemArena *mem = island_store->mem;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
MeshElemMap *isld, *innrcut;
|
|
|
|
|
const int curr_island_idx = island_store->islands_num++;
|
2022-09-25 20:27:46 +10:00
|
|
|
const size_t curr_num_islands = size_t(island_store->islands_num);
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
int i = item_num;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
while (i--) {
|
|
|
|
|
island_store->items_to_islands[items_indices[i]] = curr_island_idx;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
if (UNLIKELY(curr_num_islands > island_store->islands_num_alloc)) {
|
|
|
|
|
MeshElemMap **islds, **innrcuts;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
island_store->islands_num_alloc *= 2;
|
2022-09-19 18:44:51 -05:00
|
|
|
islds = static_cast<MeshElemMap **>(
|
|
|
|
|
BLI_memarena_alloc(mem, sizeof(*islds) * island_store->islands_num_alloc));
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
memcpy(islds, island_store->islands, sizeof(*islds) * (curr_num_islands - 1));
|
|
|
|
|
island_store->islands = islds;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-19 18:44:51 -05:00
|
|
|
innrcuts = static_cast<MeshElemMap **>(
|
|
|
|
|
BLI_memarena_alloc(mem, sizeof(*innrcuts) * island_store->islands_num_alloc));
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
memcpy(innrcuts, island_store->innercuts, sizeof(*innrcuts) * (curr_num_islands - 1));
|
|
|
|
|
island_store->innercuts = innrcuts;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-19 18:44:51 -05:00
|
|
|
island_store->islands[curr_island_idx] = isld = static_cast<MeshElemMap *>(
|
|
|
|
|
BLI_memarena_alloc(mem, sizeof(*isld)));
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
isld->count = num_island_items;
|
2022-09-19 18:44:51 -05:00
|
|
|
isld->indices = static_cast<int *>(
|
2022-09-25 20:27:46 +10:00
|
|
|
BLI_memarena_alloc(mem, sizeof(*isld->indices) * size_t(num_island_items)));
|
|
|
|
|
memcpy(isld->indices, island_item_indices, sizeof(*isld->indices) * size_t(num_island_items));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-19 18:44:51 -05:00
|
|
|
island_store->innercuts[curr_island_idx] = innrcut = static_cast<MeshElemMap *>(
|
|
|
|
|
BLI_memarena_alloc(mem, sizeof(*innrcut)));
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
innrcut->count = num_innercut_items;
|
2022-09-19 18:44:51 -05:00
|
|
|
innrcut->indices = static_cast<int *>(
|
2022-09-25 20:27:46 +10:00
|
|
|
BLI_memarena_alloc(mem, sizeof(*innrcut->indices) * size_t(num_innercut_items)));
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
memcpy(innrcut->indices,
|
|
|
|
|
innercut_item_indices,
|
2022-09-25 20:27:46 +10:00
|
|
|
sizeof(*innrcut->indices) * size_t(num_innercut_items));
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-01 14:13:05 +01:00
|
|
|
static bool mesh_calc_islands_loop_poly_uv(const int totedge,
|
|
|
|
|
const bool *uv_seams,
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
const MPoly *polys,
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
const int totpoly,
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
const MLoop *loops,
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
const int totloop,
|
Mesh: Move UV layers to generic attributes
Currently the `MLoopUV` struct stores UV coordinates and flags related
to editing UV maps in the UV editor. This patch changes the coordinates
to use the generic 2D vector type, and moves the flags into three
separate boolean attributes. This follows the design in T95965, with
the ultimate intention of simplifying code and improving performance.
Importantly, the change allows exporters and renderers to use UVs
"touched" by geometry nodes, which only creates generic attributes.
It also allows geometry nodes to create "proper" UV maps from scratch,
though only with the Store Named Attribute node for now.
The new design considers any 2D vector attribute on the corner domain
to be a UV map. In the future, they might be distinguished from regular
2D vectors with attribute metadata, which may be helpful because they
are often interpolated differently.
Most of the code changes deal with passing around UV BMesh custom data
offsets and tracking the boolean "sublayers". The boolean layers are
use the following prefixes for attribute names: vert selection: `.vs.`,
edge selection: `.es.`, pinning: `.pn.`. Currently these are short to
avoid using up the maximum length of attribute names. To accommodate
for these 4 extra characters, the name length limit is enlarged to 68
bytes, while the maximum user settable name length is still 64 bytes.
Unfortunately Python/RNA API access to the UV flag data becomes slower.
Accessing the boolean layers directly is be better for performance in
general.
Like the other mesh SoA refactors, backward and forward compatibility
aren't affected, and won't be changed until 4.0. We pay for that by
making mesh reading and writing more expensive with conversions.
Resolves T85962
Differential Revision: https://developer.blender.org/D14365
2023-01-10 00:47:04 -05:00
|
|
|
const float (*luvs)[2],
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
MeshIslandStore *r_island_store)
|
|
|
|
|
{
|
2022-10-05 13:44:02 -05:00
|
|
|
int *poly_groups = nullptr;
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
int num_poly_groups;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
/* map vars */
|
|
|
|
|
MeshElemMap *edge_poly_map;
|
|
|
|
|
int *edge_poly_mem;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-21 16:53:00 +02:00
|
|
|
MeshElemMap *edge_loop_map;
|
|
|
|
|
int *edge_loop_mem;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-20 17:09:40 +11:00
|
|
|
int *poly_indices;
|
|
|
|
|
int *loop_indices;
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
int num_pidx, num_lidx;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Those are used to detect 'inner cuts', i.e. edges that are borders,
|
|
|
|
|
* and yet have two or more polys of a same group using them
|
|
|
|
|
* (typical case: seam used to unwrap properly a cylinder). */
|
2022-10-05 13:44:02 -05:00
|
|
|
BLI_bitmap *edge_borders = nullptr;
|
2015-07-24 05:04:33 +10:00
|
|
|
int num_edge_borders = 0;
|
2022-10-05 13:44:02 -05:00
|
|
|
char *edge_border_count = nullptr;
|
|
|
|
|
int *edge_innercut_indices = nullptr;
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
int num_einnercuts = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
int grp_idx, p_idx, pl_idx, l_idx;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
BKE_mesh_loop_islands_clear(r_island_store);
|
|
|
|
|
BKE_mesh_loop_islands_init(
|
|
|
|
|
r_island_store, MISLAND_TYPE_LOOP, totloop, MISLAND_TYPE_POLY, MISLAND_TYPE_EDGE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-13 08:36:10 +02:00
|
|
|
BKE_mesh_edge_poly_map_create(
|
2023-02-09 21:55:32 -05:00
|
|
|
&edge_poly_map, &edge_poly_mem, totedge, polys, totpoly, loops, totloop);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-21 16:53:00 +02:00
|
|
|
if (luvs) {
|
2018-07-13 08:36:10 +02:00
|
|
|
BKE_mesh_edge_loop_map_create(
|
2023-02-09 21:55:32 -05:00
|
|
|
&edge_loop_map, &edge_loop_mem, totedge, polys, totpoly, loops, totloop);
|
2016-07-21 16:53:00 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-02-09 21:55:32 -05:00
|
|
|
/* TODO: I'm not sure edge seam flag is enough to define UV islands?
|
|
|
|
|
* Maybe we should also consider UV-maps values
|
|
|
|
|
* themselves (i.e. different UV-edges for a same mesh-edge => boundary edge too?).
|
|
|
|
|
* Would make things much more complex though,
|
|
|
|
|
* and each UVMap would then need its own mesh mapping, not sure we want that at all!
|
|
|
|
|
*/
|
|
|
|
|
auto mesh_check_island_boundary_uv = [&](const int /*poly_index*/,
|
|
|
|
|
const int loop_index,
|
|
|
|
|
const int edge_index,
|
|
|
|
|
const int /*edge_user_count*/,
|
|
|
|
|
const MeshElemMap & /*edge_poly_map_elem*/) -> bool {
|
|
|
|
|
if (luvs) {
|
|
|
|
|
const MeshElemMap &edge_to_loops = edge_loop_map[loops[loop_index].e];
|
|
|
|
|
|
|
|
|
|
BLI_assert(edge_to_loops.count >= 2 && (edge_to_loops.count % 2) == 0);
|
|
|
|
|
|
|
|
|
|
const uint v1 = loops[edge_to_loops.indices[0]].v;
|
|
|
|
|
const uint v2 = loops[edge_to_loops.indices[1]].v;
|
|
|
|
|
const float *uvco_v1 = luvs[edge_to_loops.indices[0]];
|
|
|
|
|
const float *uvco_v2 = luvs[edge_to_loops.indices[1]];
|
|
|
|
|
for (int i = 2; i < edge_to_loops.count; i += 2) {
|
|
|
|
|
if (loops[edge_to_loops.indices[i]].v == v1) {
|
|
|
|
|
if (!equals_v2v2(uvco_v1, luvs[edge_to_loops.indices[i]]) ||
|
|
|
|
|
!equals_v2v2(uvco_v2, luvs[edge_to_loops.indices[i + 1]])) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_assert(loops[edge_to_loops.indices[i]].v == v2);
|
|
|
|
|
UNUSED_VARS_NDEBUG(v2);
|
|
|
|
|
if (!equals_v2v2(uvco_v2, luvs[edge_to_loops.indices[i]]) ||
|
|
|
|
|
!equals_v2v2(uvco_v1, luvs[edge_to_loops.indices[i + 1]])) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Edge is UV boundary if tagged as seam. */
|
2023-03-01 14:13:05 +01:00
|
|
|
return uv_seams && uv_seams[edge_index];
|
2023-02-09 21:55:32 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
poly_edge_loop_islands_calc(totedge,
|
|
|
|
|
{polys, totpoly},
|
|
|
|
|
{loops, totloop},
|
2018-07-13 08:36:10 +02:00
|
|
|
edge_poly_map,
|
|
|
|
|
false,
|
|
|
|
|
mesh_check_island_boundary_uv,
|
|
|
|
|
&poly_groups,
|
|
|
|
|
&num_poly_groups,
|
|
|
|
|
&edge_borders,
|
|
|
|
|
&num_edge_borders);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
if (!num_poly_groups) {
|
|
|
|
|
/* Should never happen... */
|
2015-07-24 05:04:33 +10:00
|
|
|
MEM_freeN(edge_poly_map);
|
|
|
|
|
MEM_freeN(edge_poly_mem);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-07-24 05:04:33 +10:00
|
|
|
if (edge_borders) {
|
|
|
|
|
MEM_freeN(edge_borders);
|
|
|
|
|
}
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
if (num_edge_borders) {
|
2022-09-19 18:44:51 -05:00
|
|
|
edge_border_count = static_cast<char *>(
|
2022-09-25 20:27:46 +10:00
|
|
|
MEM_mallocN(sizeof(*edge_border_count) * size_t(totedge), __func__));
|
2022-09-19 18:44:51 -05:00
|
|
|
edge_innercut_indices = static_cast<int *>(
|
2022-09-25 20:27:46 +10:00
|
|
|
MEM_mallocN(sizeof(*edge_innercut_indices) * size_t(num_edge_borders), __func__));
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-19 18:44:51 -05:00
|
|
|
poly_indices = static_cast<int *>(
|
2022-09-25 20:27:46 +10:00
|
|
|
MEM_mallocN(sizeof(*poly_indices) * size_t(totpoly), __func__));
|
2022-09-19 18:44:51 -05:00
|
|
|
loop_indices = static_cast<int *>(
|
2022-09-25 20:27:46 +10:00
|
|
|
MEM_mallocN(sizeof(*loop_indices) * size_t(totloop), __func__));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE: here we ignore '0' invalid group - this should *never* happen in this case anyway? */
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
for (grp_idx = 1; grp_idx <= num_poly_groups; grp_idx++) {
|
|
|
|
|
num_pidx = num_lidx = 0;
|
|
|
|
|
if (num_edge_borders) {
|
|
|
|
|
num_einnercuts = 0;
|
2022-09-25 20:27:46 +10:00
|
|
|
memset(edge_border_count, 0, sizeof(*edge_border_count) * size_t(totedge));
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
for (p_idx = 0; p_idx < totpoly; p_idx++) {
|
|
|
|
|
if (poly_groups[p_idx] != grp_idx) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-03-03 11:40:34 -05:00
|
|
|
const MPoly &poly = polys[p_idx];
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
poly_indices[num_pidx++] = p_idx;
|
2023-03-03 11:40:34 -05:00
|
|
|
for (l_idx = poly.loopstart, pl_idx = 0; pl_idx < poly.totloop; l_idx++, pl_idx++) {
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
const MLoop *ml = &loops[l_idx];
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
loop_indices[num_lidx++] = l_idx;
|
|
|
|
|
if (num_edge_borders && BLI_BITMAP_TEST(edge_borders, ml->e) &&
|
|
|
|
|
(edge_border_count[ml->e] < 2)) {
|
|
|
|
|
edge_border_count[ml->e]++;
|
|
|
|
|
if (edge_border_count[ml->e] == 2) {
|
2022-09-25 18:33:28 +10:00
|
|
|
edge_innercut_indices[num_einnercuts++] = int(ml->e);
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-13 08:36:10 +02:00
|
|
|
BKE_mesh_loop_islands_add(r_island_store,
|
|
|
|
|
num_lidx,
|
|
|
|
|
loop_indices,
|
|
|
|
|
num_pidx,
|
|
|
|
|
poly_indices,
|
|
|
|
|
num_einnercuts,
|
|
|
|
|
edge_innercut_indices);
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-07-24 05:04:33 +10:00
|
|
|
MEM_freeN(edge_poly_map);
|
|
|
|
|
MEM_freeN(edge_poly_mem);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-21 16:53:00 +02:00
|
|
|
if (luvs) {
|
|
|
|
|
MEM_freeN(edge_loop_map);
|
|
|
|
|
MEM_freeN(edge_loop_mem);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
MEM_freeN(poly_indices);
|
|
|
|
|
MEM_freeN(loop_indices);
|
|
|
|
|
MEM_freeN(poly_groups);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-07-24 05:04:33 +10:00
|
|
|
if (edge_borders) {
|
|
|
|
|
MEM_freeN(edge_borders);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
BKE: Add 'mesh remap' code.
This is the (big!) core of mesh transfer data, it defines a set of structures
to represent a mapping of mesh elements (verts, edges, polys of loops) between
two arbitrary meshes, and code to compute such mappings.
No similarity is required between source and destination meshes (though results
when using complete different meshes are rather unlikely to be useful!).
This code is not bound to data transfer, it is defined to be as generic as possible,
and easy to reuse or extend as needs arise.
Several methods of mapping generation are defined for each element type,
we probably will have to adjust that in future (remove useless ones, add
new ones...).
For loops, you can also define islands (for UVs e.g.) so that loops of a same
destination polygon do not 'spread' across several source islands.
Heavily reviewed and enhanced by Campbell, thanks a lot!
2015-01-09 18:23:17 +01:00
|
|
|
if (num_edge_borders) {
|
|
|
|
|
MEM_freeN(edge_border_count);
|
|
|
|
|
MEM_freeN(edge_innercut_indices);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
bool BKE_mesh_calc_islands_loop_poly_edgeseam(const float (*vert_positions)[3],
|
2016-07-21 16:53:00 +02:00
|
|
|
const int totvert,
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
const MEdge *edges,
|
2016-07-21 16:53:00 +02:00
|
|
|
const int totedge,
|
2023-03-01 14:13:05 +01:00
|
|
|
const bool *uv_seams,
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
const MPoly *polys,
|
2016-07-21 16:53:00 +02:00
|
|
|
const int totpoly,
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
const MLoop *loops,
|
2016-07-21 16:53:00 +02:00
|
|
|
const int totloop,
|
|
|
|
|
MeshIslandStore *r_island_store)
|
|
|
|
|
{
|
2023-03-01 14:13:05 +01:00
|
|
|
UNUSED_VARS(vert_positions, totvert, edges);
|
2016-07-21 16:53:00 +02:00
|
|
|
return mesh_calc_islands_loop_poly_uv(
|
2023-03-01 14:13:05 +01:00
|
|
|
totedge, uv_seams, polys, totpoly, loops, totloop, nullptr, r_island_store);
|
2016-07-21 16:53:00 +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
|
|
|
bool BKE_mesh_calc_islands_loop_poly_uvmap(float (*vert_positions)[3],
|
2016-07-21 16:53:00 +02:00
|
|
|
const int totvert,
|
|
|
|
|
MEdge *edges,
|
|
|
|
|
const int totedge,
|
2023-03-01 14:13:05 +01:00
|
|
|
const bool *uv_seams,
|
2016-07-21 16:53:00 +02:00
|
|
|
MPoly *polys,
|
|
|
|
|
const int totpoly,
|
|
|
|
|
MLoop *loops,
|
|
|
|
|
const int totloop,
|
Mesh: Move UV layers to generic attributes
Currently the `MLoopUV` struct stores UV coordinates and flags related
to editing UV maps in the UV editor. This patch changes the coordinates
to use the generic 2D vector type, and moves the flags into three
separate boolean attributes. This follows the design in T95965, with
the ultimate intention of simplifying code and improving performance.
Importantly, the change allows exporters and renderers to use UVs
"touched" by geometry nodes, which only creates generic attributes.
It also allows geometry nodes to create "proper" UV maps from scratch,
though only with the Store Named Attribute node for now.
The new design considers any 2D vector attribute on the corner domain
to be a UV map. In the future, they might be distinguished from regular
2D vectors with attribute metadata, which may be helpful because they
are often interpolated differently.
Most of the code changes deal with passing around UV BMesh custom data
offsets and tracking the boolean "sublayers". The boolean layers are
use the following prefixes for attribute names: vert selection: `.vs.`,
edge selection: `.es.`, pinning: `.pn.`. Currently these are short to
avoid using up the maximum length of attribute names. To accommodate
for these 4 extra characters, the name length limit is enlarged to 68
bytes, while the maximum user settable name length is still 64 bytes.
Unfortunately Python/RNA API access to the UV flag data becomes slower.
Accessing the boolean layers directly is be better for performance in
general.
Like the other mesh SoA refactors, backward and forward compatibility
aren't affected, and won't be changed until 4.0. We pay for that by
making mesh reading and writing more expensive with conversions.
Resolves T85962
Differential Revision: https://developer.blender.org/D14365
2023-01-10 00:47:04 -05:00
|
|
|
const float (*luvs)[2],
|
2016-07-21 16:53:00 +02:00
|
|
|
MeshIslandStore *r_island_store)
|
|
|
|
|
{
|
2023-03-01 14:13:05 +01:00
|
|
|
UNUSED_VARS(vert_positions, totvert, edges);
|
2022-10-05 13:44:02 -05:00
|
|
|
BLI_assert(luvs != nullptr);
|
2016-07-21 16:53:00 +02:00
|
|
|
return mesh_calc_islands_loop_poly_uv(
|
2023-03-01 14:13:05 +01:00
|
|
|
totedge, uv_seams, polys, totpoly, loops, totloop, luvs, r_island_store);
|
2016-07-21 16:53:00 +02:00
|
|
|
}
|
|
|
|
|
|
2013-12-12 16:26:11 +11:00
|
|
|
/** \} */
|