2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2018-05-08 17:44:54 +02:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2018-05-08 17:44:54 +02:00
|
|
|
*/
|
|
|
|
|
|
2019-02-01 12:44:19 +11:00
|
|
|
#include "CLG_log.h"
|
2018-05-08 19:09:35 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_curve_types.h"
|
2018-06-01 17:05:21 +02:00
|
|
|
#include "DNA_key_types.h"
|
2018-05-08 17:44:54 +02:00
|
|
|
#include "DNA_material_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
2022-05-15 20:27:28 +02:00
|
|
|
#include "DNA_meshdata_types.h"
|
2018-05-08 17:44:54 +02:00
|
|
|
#include "DNA_meta_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
2020-04-09 18:49:40 +02:00
|
|
|
#include "DNA_pointcloud_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_scene_types.h"
|
2018-05-08 17:44:54 +02:00
|
|
|
|
|
|
|
|
#include "BLI_edgehash.h"
|
Refactor: Move normals out of MVert, lazy calculation
As described in T91186, this commit moves mesh vertex normals into a
contiguous array of float vectors in a custom data layer, how face
normals are currently stored.
The main interface is documented in `BKE_mesh.h`. Vertex and face
normals are now calculated on-demand and cached, retrieved with an
"ensure" function. Since the logical state of a mesh is now "has
normals when necessary", they can be retrieved from a `const` mesh.
The goal is to use on-demand calculation for all derived data, but
leave room for eager calculation for performance purposes (modifier
evaluation is threaded, but viewport data generation is not).
**Benefits**
This moves us closer to a SoA approach rather than the current AoS
paradigm. Accessing a contiguous `float3` is much more efficient than
retrieving data from a larger struct. The memory requirements for
accessing only normals or vertex locations are smaller, and at the
cost of more memory usage for just normals, they now don't have to
be converted between float and short, which also simplifies code
In the future, the remaining items can be removed from `MVert`,
leaving only `float3`, which has similar benefits (see T93602).
Removing the combination of derived and original data makes it
conceptually simpler to only calculate normals when necessary.
This is especially important now that we have more opportunities
for temporary meshes in geometry nodes.
**Performance**
In addition to the theoretical future performance improvements by
making `MVert == float3`, I've done some basic performance testing
on this patch directly. The data is fairly rough, but it gives an idea
about where things stand generally.
- Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms),
showing that accessing just `MVert` is now more efficient.
- Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight
change that at least shows there is no regression.
- Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small
but observable speedup.
- Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms),
shows that using normals in geometry nodes is faster.
- Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms),
shows that calculating normals is slightly faster now.
- File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB),
Normals are not saved in files, which can help with large meshes.
As for memory usage, it may be slightly more in some cases, but
I didn't observe any difference in the production files I tested.
**Tests**
Some modifiers and cycles test results need to be updated with this
commit, for two reasons:
- The subdivision surface modifier is not responsible for calculating
normals anymore. In master, the modifier creates different normals
than the result of the `Mesh` normal calculation, so this is a bug
fix.
- There are small differences in the results of some modifiers that
use normals because they are not converted to and from `short`
anymore.
**Future improvements**
- Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier
already retrieves normals if they are needed anyway.
- Copy normals as part of a better CoW system for attributes.
- Make more areas use lazy instead of eager normal calculation.
- Remove `BKE_mesh_normals_tag_dirty` in more places since that is
now the default state of a new mesh.
- Possibly apply a similar change to derived face corner normals.
Differential Revision: https://developer.blender.org/D12770
2022-01-13 14:37:58 -06:00
|
|
|
#include "BLI_index_range.hh"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_listbase.h"
|
|
|
|
|
#include "BLI_math.h"
|
2019-05-16 17:59:45 +02:00
|
|
|
#include "BLI_string.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2018-05-08 17:44:54 +02:00
|
|
|
|
|
|
|
|
#include "BKE_DerivedMesh.h"
|
2022-04-15 10:14:54 -05:00
|
|
|
#include "BKE_curves.hh"
|
2021-08-05 18:27:07 -05:00
|
|
|
#include "BKE_deform.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_displist.h"
|
2019-05-16 17:59:45 +02:00
|
|
|
#include "BKE_editmesh.h"
|
2021-09-23 11:41:46 -05:00
|
|
|
#include "BKE_geometry_set.hh"
|
2018-06-01 17:05:21 +02:00
|
|
|
#include "BKE_key.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_query.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_material.h"
|
|
|
|
|
#include "BKE_mball.h"
|
2018-05-08 17:44:54 +02:00
|
|
|
#include "BKE_mesh.h"
|
2018-06-05 16:58:08 +02:00
|
|
|
#include "BKE_mesh_runtime.h"
|
2020-06-10 22:32:06 +10:00
|
|
|
#include "BKE_mesh_wrapper.h"
|
2018-06-01 17:05:21 +02:00
|
|
|
#include "BKE_modifier.h"
|
2018-05-08 19:09:35 +02:00
|
|
|
/* these 2 are only used by conversion functions */
|
2018-05-08 17:44:54 +02:00
|
|
|
#include "BKE_curve.h"
|
|
|
|
|
/* -- */
|
|
|
|
|
#include "BKE_object.h"
|
2020-04-09 18:49:40 +02:00
|
|
|
/* -- */
|
|
|
|
|
#include "BKE_pointcloud.h"
|
2018-05-08 17:44:54 +02:00
|
|
|
|
2021-09-23 11:41:46 -05:00
|
|
|
#include "BKE_curve_to_mesh.hh"
|
|
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
2018-05-08 19:09:35 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2018-05-08 17:44:54 +02:00
|
|
|
|
Refactor: Move normals out of MVert, lazy calculation
As described in T91186, this commit moves mesh vertex normals into a
contiguous array of float vectors in a custom data layer, how face
normals are currently stored.
The main interface is documented in `BKE_mesh.h`. Vertex and face
normals are now calculated on-demand and cached, retrieved with an
"ensure" function. Since the logical state of a mesh is now "has
normals when necessary", they can be retrieved from a `const` mesh.
The goal is to use on-demand calculation for all derived data, but
leave room for eager calculation for performance purposes (modifier
evaluation is threaded, but viewport data generation is not).
**Benefits**
This moves us closer to a SoA approach rather than the current AoS
paradigm. Accessing a contiguous `float3` is much more efficient than
retrieving data from a larger struct. The memory requirements for
accessing only normals or vertex locations are smaller, and at the
cost of more memory usage for just normals, they now don't have to
be converted between float and short, which also simplifies code
In the future, the remaining items can be removed from `MVert`,
leaving only `float3`, which has similar benefits (see T93602).
Removing the combination of derived and original data makes it
conceptually simpler to only calculate normals when necessary.
This is especially important now that we have more opportunities
for temporary meshes in geometry nodes.
**Performance**
In addition to the theoretical future performance improvements by
making `MVert == float3`, I've done some basic performance testing
on this patch directly. The data is fairly rough, but it gives an idea
about where things stand generally.
- Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms),
showing that accessing just `MVert` is now more efficient.
- Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight
change that at least shows there is no regression.
- Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small
but observable speedup.
- Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms),
shows that using normals in geometry nodes is faster.
- Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms),
shows that calculating normals is slightly faster now.
- File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB),
Normals are not saved in files, which can help with large meshes.
As for memory usage, it may be slightly more in some cases, but
I didn't observe any difference in the production files I tested.
**Tests**
Some modifiers and cycles test results need to be updated with this
commit, for two reasons:
- The subdivision surface modifier is not responsible for calculating
normals anymore. In master, the modifier creates different normals
than the result of the `Mesh` normal calculation, so this is a bug
fix.
- There are small differences in the results of some modifiers that
use normals because they are not converted to and from `short`
anymore.
**Future improvements**
- Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier
already retrieves normals if they are needed anyway.
- Copy normals as part of a better CoW system for attributes.
- Make more areas use lazy instead of eager normal calculation.
- Remove `BKE_mesh_normals_tag_dirty` in more places since that is
now the default state of a new mesh.
- Possibly apply a similar change to derived face corner normals.
Differential Revision: https://developer.blender.org/D12770
2022-01-13 14:37:58 -06:00
|
|
|
using blender::IndexRange;
|
|
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* Define for cases when you want extra validation of mesh
|
|
|
|
|
* after certain modifications.
|
|
|
|
|
*/
|
|
|
|
|
// #undef VALIDATE_MESH
|
|
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
#ifdef VALIDATE_MESH
|
|
|
|
|
# define ASSERT_IS_VALID_MESH(mesh) \
|
2021-09-16 15:44:43 -05:00
|
|
|
(BLI_assert((mesh == nullptr) || (BKE_mesh_is_valid(mesh) == true)))
|
2018-06-01 17:05:21 +02:00
|
|
|
#else
|
|
|
|
|
# define ASSERT_IS_VALID_MESH(mesh)
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-02-01 12:44:19 +11:00
|
|
|
static CLG_LogRef LOG = {"bke.mesh_convert"};
|
|
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
void BKE_mesh_from_metaball(ListBase *lb, Mesh *me)
|
|
|
|
|
{
|
|
|
|
|
DispList *dl;
|
|
|
|
|
MVert *mvert;
|
|
|
|
|
MLoop *mloop, *allloop;
|
|
|
|
|
MPoly *mpoly;
|
|
|
|
|
int a, *index;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
dl = (DispList *)lb->first;
|
|
|
|
|
if (dl == nullptr) {
|
2018-05-08 17:44:54 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
if (dl->type == DL_INDEX4) {
|
2021-09-16 15:44:43 -05:00
|
|
|
mvert = (MVert *)CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, nullptr, dl->nr);
|
|
|
|
|
allloop = mloop = (MLoop *)CustomData_add_layer(
|
|
|
|
|
&me->ldata, CD_MLOOP, CD_CALLOC, nullptr, dl->parts * 4);
|
|
|
|
|
mpoly = (MPoly *)CustomData_add_layer(&me->pdata, CD_MPOLY, CD_CALLOC, nullptr, dl->parts);
|
2018-05-08 17:44:54 +02:00
|
|
|
me->mvert = mvert;
|
|
|
|
|
me->mloop = mloop;
|
|
|
|
|
me->mpoly = mpoly;
|
|
|
|
|
me->totvert = dl->nr;
|
|
|
|
|
me->totpoly = dl->parts;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Refactor: Move normals out of MVert, lazy calculation
As described in T91186, this commit moves mesh vertex normals into a
contiguous array of float vectors in a custom data layer, how face
normals are currently stored.
The main interface is documented in `BKE_mesh.h`. Vertex and face
normals are now calculated on-demand and cached, retrieved with an
"ensure" function. Since the logical state of a mesh is now "has
normals when necessary", they can be retrieved from a `const` mesh.
The goal is to use on-demand calculation for all derived data, but
leave room for eager calculation for performance purposes (modifier
evaluation is threaded, but viewport data generation is not).
**Benefits**
This moves us closer to a SoA approach rather than the current AoS
paradigm. Accessing a contiguous `float3` is much more efficient than
retrieving data from a larger struct. The memory requirements for
accessing only normals or vertex locations are smaller, and at the
cost of more memory usage for just normals, they now don't have to
be converted between float and short, which also simplifies code
In the future, the remaining items can be removed from `MVert`,
leaving only `float3`, which has similar benefits (see T93602).
Removing the combination of derived and original data makes it
conceptually simpler to only calculate normals when necessary.
This is especially important now that we have more opportunities
for temporary meshes in geometry nodes.
**Performance**
In addition to the theoretical future performance improvements by
making `MVert == float3`, I've done some basic performance testing
on this patch directly. The data is fairly rough, but it gives an idea
about where things stand generally.
- Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms),
showing that accessing just `MVert` is now more efficient.
- Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight
change that at least shows there is no regression.
- Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small
but observable speedup.
- Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms),
shows that using normals in geometry nodes is faster.
- Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms),
shows that calculating normals is slightly faster now.
- File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB),
Normals are not saved in files, which can help with large meshes.
As for memory usage, it may be slightly more in some cases, but
I didn't observe any difference in the production files I tested.
**Tests**
Some modifiers and cycles test results need to be updated with this
commit, for two reasons:
- The subdivision surface modifier is not responsible for calculating
normals anymore. In master, the modifier creates different normals
than the result of the `Mesh` normal calculation, so this is a bug
fix.
- There are small differences in the results of some modifiers that
use normals because they are not converted to and from `short`
anymore.
**Future improvements**
- Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier
already retrieves normals if they are needed anyway.
- Copy normals as part of a better CoW system for attributes.
- Make more areas use lazy instead of eager normal calculation.
- Remove `BKE_mesh_normals_tag_dirty` in more places since that is
now the default state of a new mesh.
- Possibly apply a similar change to derived face corner normals.
Differential Revision: https://developer.blender.org/D12770
2022-01-13 14:37:58 -06:00
|
|
|
for (const int i : IndexRange(dl->nr)) {
|
|
|
|
|
copy_v3_v3(me->mvert[i].co, &dl->verts[3 * i]);
|
2018-05-08 17:44:54 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
a = dl->parts;
|
|
|
|
|
index = dl->index;
|
|
|
|
|
while (a--) {
|
|
|
|
|
int count = index[2] != index[3] ? 4 : 3;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
mloop[0].v = index[0];
|
|
|
|
|
mloop[1].v = index[1];
|
|
|
|
|
mloop[2].v = index[2];
|
2019-04-22 09:39:35 +10:00
|
|
|
if (count == 4) {
|
2018-05-08 17:44:54 +02:00
|
|
|
mloop[3].v = index[3];
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
mpoly->totloop = count;
|
|
|
|
|
mpoly->loopstart = (int)(mloop - allloop);
|
|
|
|
|
mpoly->flag = ME_SMOOTH;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
mpoly++;
|
|
|
|
|
mloop += count;
|
|
|
|
|
me->totloop += count;
|
|
|
|
|
index += 4;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
BKE_mesh_update_customdata_pointers(me, true);
|
|
|
|
|
BKE_mesh_calc_edges(me, true, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Specialized function to use when we _know_ existing edges don't overlap with poly edges.
|
|
|
|
|
*/
|
2018-07-13 08:36:10 +02:00
|
|
|
static void make_edges_mdata_extend(
|
|
|
|
|
MEdge **r_alledge, int *r_totedge, const MPoly *mpoly, MLoop *mloop, const int totpoly)
|
2018-05-08 17:44:54 +02:00
|
|
|
{
|
|
|
|
|
int totedge = *r_totedge;
|
|
|
|
|
int totedge_new;
|
|
|
|
|
EdgeHash *eh;
|
2021-06-18 14:27:41 +10:00
|
|
|
uint eh_reserve;
|
2018-05-08 17:44:54 +02:00
|
|
|
const MPoly *mp;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
eh_reserve = max_ii(totedge, BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS(totpoly));
|
|
|
|
|
eh = BLI_edgehash_new_ex(__func__, eh_reserve);
|
|
|
|
|
|
|
|
|
|
for (i = 0, mp = mpoly; i < totpoly; i++, mp++) {
|
|
|
|
|
BKE_mesh_poly_edgehash_insert(eh, mp, mloop + mp->loopstart);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
totedge_new = BLI_edgehash_len(eh);
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2018-09-24 17:27:41 +02:00
|
|
|
/* ensure that there's no overlap! */
|
2018-05-08 17:44:54 +02:00
|
|
|
if (totedge_new) {
|
|
|
|
|
MEdge *medge = *r_alledge;
|
|
|
|
|
for (i = 0; i < totedge; i++, medge++) {
|
|
|
|
|
BLI_assert(BLI_edgehash_haskey(eh, medge->v1, medge->v2) == false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (totedge_new) {
|
|
|
|
|
EdgeHashIterator *ehi;
|
|
|
|
|
MEdge *medge;
|
2021-06-18 14:27:41 +10:00
|
|
|
uint e_index = totedge;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
*r_alledge = medge = (MEdge *)(*r_alledge ?
|
|
|
|
|
MEM_reallocN(*r_alledge,
|
|
|
|
|
sizeof(MEdge) * (totedge + totedge_new)) :
|
|
|
|
|
MEM_calloc_arrayN(totedge_new, sizeof(MEdge), __func__));
|
2018-05-08 17:44:54 +02:00
|
|
|
medge += totedge;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
totedge += totedge_new;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* --- */
|
|
|
|
|
for (ehi = BLI_edgehashIterator_new(eh); BLI_edgehashIterator_isDone(ehi) == false;
|
|
|
|
|
BLI_edgehashIterator_step(ehi), ++medge, e_index++) {
|
|
|
|
|
BLI_edgehashIterator_getKey(ehi, &medge->v1, &medge->v2);
|
2018-09-19 12:05:58 +10:00
|
|
|
BLI_edgehashIterator_setValue(ehi, POINTER_FROM_UINT(e_index));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
medge->crease = medge->bweight = 0;
|
|
|
|
|
medge->flag = ME_EDGEDRAW | ME_EDGERENDER;
|
|
|
|
|
}
|
|
|
|
|
BLI_edgehashIterator_free(ehi);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
*r_totedge = totedge;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
for (i = 0, mp = mpoly; i < totpoly; i++, mp++) {
|
|
|
|
|
MLoop *l = &mloop[mp->loopstart];
|
|
|
|
|
MLoop *l_prev = (l + (mp->totloop - 1));
|
|
|
|
|
int j;
|
|
|
|
|
for (j = 0; j < mp->totloop; j++, l++) {
|
|
|
|
|
/* lookup hashed edge index */
|
2018-09-19 12:05:58 +10:00
|
|
|
l_prev->e = POINTER_AS_UINT(BLI_edgehash_lookup(eh, l_prev->v, l->v));
|
2018-05-08 17:44:54 +02:00
|
|
|
l_prev = l;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
BLI_edgehash_free(eh, nullptr);
|
2018-05-08 17:44:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize mverts, medges and, faces for converting nurbs to mesh and derived mesh */
|
|
|
|
|
/* use specified dispbase */
|
2021-07-19 21:19:59 -04:00
|
|
|
static int mesh_nurbs_displist_to_mdata(const Curve *cu,
|
|
|
|
|
const ListBase *dispbase,
|
|
|
|
|
MVert **r_allvert,
|
|
|
|
|
int *r_totvert,
|
|
|
|
|
MEdge **r_alledge,
|
|
|
|
|
int *r_totedge,
|
|
|
|
|
MLoop **r_allloop,
|
|
|
|
|
MPoly **r_allpoly,
|
|
|
|
|
MLoopUV **r_alluv,
|
|
|
|
|
int *r_totloop,
|
|
|
|
|
int *r_totpoly)
|
2018-05-08 17:44:54 +02:00
|
|
|
{
|
|
|
|
|
MVert *mvert;
|
|
|
|
|
MPoly *mpoly;
|
|
|
|
|
MLoop *mloop;
|
2021-09-16 15:44:43 -05:00
|
|
|
MLoopUV *mloopuv = nullptr;
|
2018-05-08 17:44:54 +02:00
|
|
|
MEdge *medge;
|
|
|
|
|
const float *data;
|
|
|
|
|
int a, b, ofs, vertcount, startvert, totvert = 0, totedge = 0, totloop = 0, totpoly = 0;
|
|
|
|
|
int p1, p2, p3, p4, *index;
|
2019-09-12 18:58:43 +10:00
|
|
|
const bool conv_polys = (
|
2021-09-23 15:02:10 +10:00
|
|
|
/* 2D polys are filled with #DispList.type == #DL_INDEX3. */
|
2019-09-12 18:58:43 +10:00
|
|
|
(CU_DO_2DFILL(cu) == false) ||
|
|
|
|
|
/* surf polys are never filled */
|
2021-07-19 21:19:59 -04:00
|
|
|
BKE_curve_type_get(cu) == OB_SURF);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* count */
|
2021-06-28 13:47:48 -05:00
|
|
|
LISTBASE_FOREACH (const DispList *, dl, dispbase) {
|
2018-05-08 17:44:54 +02:00
|
|
|
if (dl->type == DL_SEGM) {
|
|
|
|
|
totvert += dl->parts * dl->nr;
|
|
|
|
|
totedge += dl->parts * (dl->nr - 1);
|
|
|
|
|
}
|
|
|
|
|
else if (dl->type == DL_POLY) {
|
|
|
|
|
if (conv_polys) {
|
|
|
|
|
totvert += dl->parts * dl->nr;
|
|
|
|
|
totedge += dl->parts * dl->nr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (dl->type == DL_SURF) {
|
2020-07-30 17:37:35 +10:00
|
|
|
if (dl->parts != 0) {
|
|
|
|
|
int tot;
|
|
|
|
|
totvert += dl->parts * dl->nr;
|
|
|
|
|
tot = (((dl->flag & DL_CYCL_U) ? 1 : 0) + (dl->nr - 1)) *
|
|
|
|
|
(((dl->flag & DL_CYCL_V) ? 1 : 0) + (dl->parts - 1));
|
|
|
|
|
totpoly += tot;
|
|
|
|
|
totloop += tot * 4;
|
|
|
|
|
}
|
2018-05-08 17:44:54 +02:00
|
|
|
}
|
|
|
|
|
else if (dl->type == DL_INDEX3) {
|
|
|
|
|
int tot;
|
|
|
|
|
totvert += dl->nr;
|
|
|
|
|
tot = dl->parts;
|
|
|
|
|
totpoly += tot;
|
|
|
|
|
totloop += tot * 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
if (totvert == 0) {
|
2021-08-12 14:34:41 +10:00
|
|
|
/* Make Sure you check ob->data is a curve. */
|
|
|
|
|
// error("can't convert");
|
2018-05-08 17:44:54 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
*r_allvert = mvert = (MVert *)MEM_calloc_arrayN(totvert, sizeof(MVert), "nurbs_init mvert");
|
|
|
|
|
*r_alledge = medge = (MEdge *)MEM_calloc_arrayN(totedge, sizeof(MEdge), "nurbs_init medge");
|
|
|
|
|
*r_allloop = mloop = (MLoop *)MEM_calloc_arrayN(
|
2020-08-08 13:29:21 +10:00
|
|
|
totpoly, sizeof(MLoop[4]), "nurbs_init mloop"); /* totloop */
|
2021-09-16 15:44:43 -05:00
|
|
|
*r_allpoly = mpoly = (MPoly *)MEM_calloc_arrayN(totpoly, sizeof(MPoly), "nurbs_init mloop");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (r_alluv) {
|
2021-09-16 15:44:43 -05:00
|
|
|
*r_alluv = mloopuv = (MLoopUV *)MEM_calloc_arrayN(
|
|
|
|
|
totpoly, sizeof(MLoopUV[4]), "nurbs_init mloopuv");
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* verts and faces */
|
|
|
|
|
vertcount = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-28 13:47:48 -05:00
|
|
|
LISTBASE_FOREACH (const DispList *, dl, dispbase) {
|
2018-05-08 17:44:54 +02:00
|
|
|
const bool is_smooth = (dl->rt & CU_SMOOTH) != 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
if (dl->type == DL_SEGM) {
|
|
|
|
|
startvert = vertcount;
|
|
|
|
|
a = dl->parts * dl->nr;
|
|
|
|
|
data = dl->verts;
|
|
|
|
|
while (a--) {
|
|
|
|
|
copy_v3_v3(mvert->co, data);
|
|
|
|
|
data += 3;
|
|
|
|
|
vertcount++;
|
|
|
|
|
mvert++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
for (a = 0; a < dl->parts; a++) {
|
|
|
|
|
ofs = a * dl->nr;
|
|
|
|
|
for (b = 1; b < dl->nr; b++) {
|
|
|
|
|
medge->v1 = startvert + ofs + b - 1;
|
|
|
|
|
medge->v2 = startvert + ofs + b;
|
|
|
|
|
medge->flag = ME_LOOSEEDGE | ME_EDGERENDER | ME_EDGEDRAW;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
medge++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-05-08 17:44:54 +02:00
|
|
|
}
|
|
|
|
|
else if (dl->type == DL_POLY) {
|
|
|
|
|
if (conv_polys) {
|
|
|
|
|
startvert = vertcount;
|
|
|
|
|
a = dl->parts * dl->nr;
|
|
|
|
|
data = dl->verts;
|
|
|
|
|
while (a--) {
|
|
|
|
|
copy_v3_v3(mvert->co, data);
|
|
|
|
|
data += 3;
|
|
|
|
|
vertcount++;
|
|
|
|
|
mvert++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
for (a = 0; a < dl->parts; a++) {
|
|
|
|
|
ofs = a * dl->nr;
|
|
|
|
|
for (b = 0; b < dl->nr; b++) {
|
|
|
|
|
medge->v1 = startvert + ofs + b;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (b == dl->nr - 1) {
|
2018-05-08 17:44:54 +02:00
|
|
|
medge->v2 = startvert + ofs;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2018-05-08 17:44:54 +02:00
|
|
|
medge->v2 = startvert + ofs + b + 1;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-05-08 17:44:54 +02:00
|
|
|
medge->flag = ME_LOOSEEDGE | ME_EDGERENDER | ME_EDGEDRAW;
|
|
|
|
|
medge++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-05-08 17:44:54 +02:00
|
|
|
else if (dl->type == DL_INDEX3) {
|
|
|
|
|
startvert = vertcount;
|
|
|
|
|
a = dl->nr;
|
|
|
|
|
data = dl->verts;
|
|
|
|
|
while (a--) {
|
|
|
|
|
copy_v3_v3(mvert->co, data);
|
|
|
|
|
data += 3;
|
|
|
|
|
vertcount++;
|
|
|
|
|
mvert++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
a = dl->parts;
|
|
|
|
|
index = dl->index;
|
|
|
|
|
while (a--) {
|
|
|
|
|
mloop[0].v = startvert + index[0];
|
|
|
|
|
mloop[1].v = startvert + index[2];
|
|
|
|
|
mloop[2].v = startvert + index[1];
|
|
|
|
|
mpoly->loopstart = (int)(mloop - (*r_allloop));
|
|
|
|
|
mpoly->totloop = 3;
|
|
|
|
|
mpoly->mat_nr = dl->col;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
if (mloopuv) {
|
2020-09-09 16:35:20 +02:00
|
|
|
for (int i = 0; i < 3; i++, mloopuv++) {
|
2018-05-08 17:44:54 +02:00
|
|
|
mloopuv->uv[0] = (mloop[i].v - startvert) / (float)(dl->nr - 1);
|
|
|
|
|
mloopuv->uv[1] = 0.0f;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (is_smooth) {
|
2018-05-08 17:44:54 +02:00
|
|
|
mpoly->flag |= ME_SMOOTH;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-05-08 17:44:54 +02:00
|
|
|
mpoly++;
|
|
|
|
|
mloop += 3;
|
|
|
|
|
index += 3;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-05-08 17:44:54 +02:00
|
|
|
else if (dl->type == DL_SURF) {
|
|
|
|
|
startvert = vertcount;
|
|
|
|
|
a = dl->parts * dl->nr;
|
|
|
|
|
data = dl->verts;
|
|
|
|
|
while (a--) {
|
|
|
|
|
copy_v3_v3(mvert->co, data);
|
|
|
|
|
data += 3;
|
|
|
|
|
vertcount++;
|
|
|
|
|
mvert++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
for (a = 0; a < dl->parts; a++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if ((dl->flag & DL_CYCL_V) == 0 && a == dl->parts - 1) {
|
2018-05-08 17:44:54 +02:00
|
|
|
break;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
if (dl->flag & DL_CYCL_U) { /* p2 -> p1 -> */
|
|
|
|
|
p1 = startvert + dl->nr * a; /* p4 -> p3 -> */
|
|
|
|
|
p2 = p1 + dl->nr - 1; /* -----> next row */
|
|
|
|
|
p3 = p1 + dl->nr;
|
|
|
|
|
p4 = p2 + dl->nr;
|
|
|
|
|
b = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
p2 = startvert + dl->nr * a;
|
|
|
|
|
p1 = p2 + 1;
|
|
|
|
|
p4 = p2 + dl->nr;
|
|
|
|
|
p3 = p1 + dl->nr;
|
|
|
|
|
b = 1;
|
|
|
|
|
}
|
|
|
|
|
if ((dl->flag & DL_CYCL_V) && a == dl->parts - 1) {
|
|
|
|
|
p3 -= dl->parts * dl->nr;
|
|
|
|
|
p4 -= dl->parts * dl->nr;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
for (; b < dl->nr; b++) {
|
|
|
|
|
mloop[0].v = p1;
|
|
|
|
|
mloop[1].v = p3;
|
|
|
|
|
mloop[2].v = p4;
|
|
|
|
|
mloop[3].v = p2;
|
|
|
|
|
mpoly->loopstart = (int)(mloop - (*r_allloop));
|
|
|
|
|
mpoly->totloop = 4;
|
|
|
|
|
mpoly->mat_nr = dl->col;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
if (mloopuv) {
|
|
|
|
|
int orco_sizeu = dl->nr - 1;
|
|
|
|
|
int orco_sizev = dl->parts - 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* exception as handled in convertblender.c too */
|
|
|
|
|
if (dl->flag & DL_CYCL_U) {
|
|
|
|
|
orco_sizeu++;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (dl->flag & DL_CYCL_V) {
|
2018-05-08 17:44:54 +02:00
|
|
|
orco_sizev++;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-05-08 17:44:54 +02:00
|
|
|
}
|
|
|
|
|
else if (dl->flag & DL_CYCL_V) {
|
|
|
|
|
orco_sizev++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-09 16:35:20 +02:00
|
|
|
for (int i = 0; i < 4; i++, mloopuv++) {
|
2018-05-08 17:44:54 +02:00
|
|
|
/* find uv based on vertex index into grid array */
|
|
|
|
|
int v = mloop[i].v - startvert;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
mloopuv->uv[0] = (v / dl->nr) / (float)orco_sizev;
|
|
|
|
|
mloopuv->uv[1] = (v % dl->nr) / (float)orco_sizeu;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* cyclic correction */
|
2021-10-20 10:45:59 +11:00
|
|
|
if ((ELEM(i, 1, 2)) && mloopuv->uv[0] == 0.0f) {
|
2018-05-08 17:44:54 +02:00
|
|
|
mloopuv->uv[0] = 1.0f;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2021-10-20 10:45:59 +11:00
|
|
|
if ((ELEM(i, 0, 1)) && mloopuv->uv[1] == 0.0f) {
|
2018-05-08 17:44:54 +02:00
|
|
|
mloopuv->uv[1] = 1.0f;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-05-08 17:44:54 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (is_smooth) {
|
2018-05-08 17:44:54 +02:00
|
|
|
mpoly->flag |= ME_SMOOTH;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-05-08 17:44:54 +02:00
|
|
|
mpoly++;
|
|
|
|
|
mloop += 4;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
p4 = p3;
|
|
|
|
|
p3++;
|
|
|
|
|
p2 = p1;
|
|
|
|
|
p1++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-05-08 17:44:54 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
if (totpoly) {
|
|
|
|
|
make_edges_mdata_extend(r_alledge, &totedge, *r_allpoly, *r_allloop, totpoly);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
*r_totpoly = totpoly;
|
|
|
|
|
*r_totloop = totloop;
|
|
|
|
|
*r_totedge = totedge;
|
|
|
|
|
*r_totvert = totvert;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
Geometry Nodes: Support modifier on curve objects
With this commit, curve objects support the geometry nodes modifier.
Curves objects now evaluate to `CurveEval` unless there was a previous
implicit conversion (tessellating modifiers, mesh modifiers, or the
settings in the curve "Geometry" panel). In the new code, curves are
only considered to be the wire edges-- any generated surface is a mesh
instead, stored in the evaluated geometry set.
The consolidation of concepts mentioned above allows remove a lot of
code that had to do with maintaining the `DispList` type temporarily
for modifiers and rendering. Instead, render engines see a separate
object for the mesh from the mesh geometry component, and when the
curve object evaluates to a curve, the `CurveEval` is always used for
drawing wire edges.
However, currently the `DispList` type is still maintained and used as
an intermediate step in implicit mesh conversion. In the future, more
uses of it could be changed to use `CurveEval` and `Mesh` instead.
This is mostly not changed behavior, it is just a formalization of
existing logic after recent fixes for 2.8 versions last year and two
years ago. Also, in the future more functionality can be converted
to nodes, removing cases of implicit conversions. For more discussion
on that topic, see T89676.
The `use_fill_deform` option is removed. It has not worked properly
since 2.62, and the choice for filling a curve before or after
deformation will work much better and be clearer with a node system.
Applying the geometry nodes modifier to generate a curve is not
implemented with this commit, so applying the modifier won't work
at all. This is a separate technical challenge, and should be solved
in a separate step.
Differential Revision: https://developer.blender.org/D11597
2021-09-11 13:54:40 -05:00
|
|
|
/**
|
|
|
|
|
* Copy evaluated texture space from curve to mesh.
|
|
|
|
|
*
|
|
|
|
|
* \note We disable auto texture space feature since that will cause texture space to evaluate
|
|
|
|
|
* differently for curve and mesh, since curves use control points and handles to calculate the
|
|
|
|
|
* bounding box, and mesh uses the tessellated curve.
|
|
|
|
|
*/
|
|
|
|
|
static void mesh_copy_texture_space_from_curve_type(const Curve *cu, Mesh *me)
|
|
|
|
|
{
|
|
|
|
|
me->texflag = cu->texflag & ~CU_AUTOSPACE;
|
|
|
|
|
copy_v3_v3(me->loc, cu->loc);
|
|
|
|
|
copy_v3_v3(me->size, cu->size);
|
|
|
|
|
BKE_mesh_texspace_calc(me);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-28 13:47:48 -05:00
|
|
|
Mesh *BKE_mesh_new_nomain_from_curve_displist(const Object *ob, const ListBase *dispbase)
|
2018-05-08 19:09:35 +02:00
|
|
|
{
|
2021-09-16 15:44:43 -05:00
|
|
|
const Curve *cu = (const Curve *)ob->data;
|
2018-05-08 19:09:35 +02:00
|
|
|
Mesh *mesh;
|
|
|
|
|
MVert *allvert;
|
|
|
|
|
MEdge *alledge;
|
|
|
|
|
MLoop *allloop;
|
|
|
|
|
MPoly *allpoly;
|
2021-09-16 15:44:43 -05:00
|
|
|
MLoopUV *alluv = nullptr;
|
2018-05-08 19:09:35 +02:00
|
|
|
int totvert, totedge, totloop, totpoly;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Geometry Nodes: Support modifier on curve objects
With this commit, curve objects support the geometry nodes modifier.
Curves objects now evaluate to `CurveEval` unless there was a previous
implicit conversion (tessellating modifiers, mesh modifiers, or the
settings in the curve "Geometry" panel). In the new code, curves are
only considered to be the wire edges-- any generated surface is a mesh
instead, stored in the evaluated geometry set.
The consolidation of concepts mentioned above allows remove a lot of
code that had to do with maintaining the `DispList` type temporarily
for modifiers and rendering. Instead, render engines see a separate
object for the mesh from the mesh geometry component, and when the
curve object evaluates to a curve, the `CurveEval` is always used for
drawing wire edges.
However, currently the `DispList` type is still maintained and used as
an intermediate step in implicit mesh conversion. In the future, more
uses of it could be changed to use `CurveEval` and `Mesh` instead.
This is mostly not changed behavior, it is just a formalization of
existing logic after recent fixes for 2.8 versions last year and two
years ago. Also, in the future more functionality can be converted
to nodes, removing cases of implicit conversions. For more discussion
on that topic, see T89676.
The `use_fill_deform` option is removed. It has not worked properly
since 2.62, and the choice for filling a curve before or after
deformation will work much better and be clearer with a node system.
Applying the geometry nodes modifier to generate a curve is not
implemented with this commit, so applying the modifier won't work
at all. This is a separate technical challenge, and should be solved
in a separate step.
Differential Revision: https://developer.blender.org/D11597
2021-09-11 13:54:40 -05:00
|
|
|
if (mesh_nurbs_displist_to_mdata(cu,
|
2021-07-19 21:19:59 -04:00
|
|
|
dispbase,
|
|
|
|
|
&allvert,
|
|
|
|
|
&totvert,
|
|
|
|
|
&alledge,
|
|
|
|
|
&totedge,
|
|
|
|
|
&allloop,
|
|
|
|
|
&allpoly,
|
|
|
|
|
&alluv,
|
|
|
|
|
&totloop,
|
|
|
|
|
&totpoly) != 0) {
|
2018-05-08 19:09:35 +02:00
|
|
|
/* Error initializing mdata. This often happens when curve is empty */
|
|
|
|
|
return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 19:09:35 +02:00
|
|
|
mesh = BKE_mesh_new_nomain(totvert, totedge, 0, totloop, totpoly);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-28 16:56:30 -05:00
|
|
|
if (totvert != 0) {
|
|
|
|
|
memcpy(mesh->mvert, allvert, totvert * sizeof(MVert));
|
|
|
|
|
}
|
|
|
|
|
if (totedge != 0) {
|
|
|
|
|
memcpy(mesh->medge, alledge, totedge * sizeof(MEdge));
|
|
|
|
|
}
|
|
|
|
|
if (totloop != 0) {
|
|
|
|
|
memcpy(mesh->mloop, allloop, totloop * sizeof(MLoop));
|
|
|
|
|
}
|
|
|
|
|
if (totpoly != 0) {
|
|
|
|
|
memcpy(mesh->mpoly, allpoly, totpoly * sizeof(MPoly));
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 19:09:35 +02:00
|
|
|
if (alluv) {
|
2019-09-14 23:16:38 +02:00
|
|
|
const char *uvname = "UVMap";
|
2018-05-08 19:09:35 +02:00
|
|
|
CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_ASSIGN, alluv, totloop, uvname);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Geometry Nodes: Support modifier on curve objects
With this commit, curve objects support the geometry nodes modifier.
Curves objects now evaluate to `CurveEval` unless there was a previous
implicit conversion (tessellating modifiers, mesh modifiers, or the
settings in the curve "Geometry" panel). In the new code, curves are
only considered to be the wire edges-- any generated surface is a mesh
instead, stored in the evaluated geometry set.
The consolidation of concepts mentioned above allows remove a lot of
code that had to do with maintaining the `DispList` type temporarily
for modifiers and rendering. Instead, render engines see a separate
object for the mesh from the mesh geometry component, and when the
curve object evaluates to a curve, the `CurveEval` is always used for
drawing wire edges.
However, currently the `DispList` type is still maintained and used as
an intermediate step in implicit mesh conversion. In the future, more
uses of it could be changed to use `CurveEval` and `Mesh` instead.
This is mostly not changed behavior, it is just a formalization of
existing logic after recent fixes for 2.8 versions last year and two
years ago. Also, in the future more functionality can be converted
to nodes, removing cases of implicit conversions. For more discussion
on that topic, see T89676.
The `use_fill_deform` option is removed. It has not worked properly
since 2.62, and the choice for filling a curve before or after
deformation will work much better and be clearer with a node system.
Applying the geometry nodes modifier to generate a curve is not
implemented with this commit, so applying the modifier won't work
at all. This is a separate technical challenge, and should be solved
in a separate step.
Differential Revision: https://developer.blender.org/D11597
2021-09-11 13:54:40 -05:00
|
|
|
mesh_copy_texture_space_from_curve_type(cu, mesh);
|
|
|
|
|
|
|
|
|
|
/* Copy curve materials. */
|
|
|
|
|
mesh->mat = (Material **)MEM_dupallocN(cu->mat);
|
|
|
|
|
mesh->totcol = cu->totcol;
|
|
|
|
|
|
2018-05-08 19:09:35 +02:00
|
|
|
MEM_freeN(allvert);
|
|
|
|
|
MEM_freeN(alledge);
|
|
|
|
|
MEM_freeN(allloop);
|
|
|
|
|
MEM_freeN(allpoly);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 19:09:35 +02:00
|
|
|
return mesh;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-19 21:19:59 -04:00
|
|
|
Mesh *BKE_mesh_new_nomain_from_curve(const Object *ob)
|
2018-05-08 19:09:35 +02:00
|
|
|
{
|
2021-09-16 15:44:43 -05:00
|
|
|
ListBase disp = {nullptr, nullptr};
|
2018-05-08 19:09:35 +02:00
|
|
|
|
2018-07-30 16:54:40 +02:00
|
|
|
if (ob->runtime.curve_cache) {
|
|
|
|
|
disp = ob->runtime.curve_cache->disp;
|
2018-05-08 19:09:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BKE_mesh_new_nomain_from_curve_displist(ob, &disp);
|
|
|
|
|
}
|
2018-05-08 17:44:54 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
struct EdgeLink {
|
2018-05-08 17:44:54 +02:00
|
|
|
struct EdgeLink *next, *prev;
|
|
|
|
|
void *edge;
|
2021-09-16 15:44:43 -05:00
|
|
|
};
|
2018-05-08 17:44:54 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
struct VertLink {
|
2018-05-08 17:44:54 +02:00
|
|
|
Link *next, *prev;
|
2021-06-18 14:27:41 +10:00
|
|
|
uint index;
|
2021-09-16 15:44:43 -05:00
|
|
|
};
|
2018-05-08 17:44:54 +02:00
|
|
|
|
2021-06-18 14:27:41 +10:00
|
|
|
static void prependPolyLineVert(ListBase *lb, uint index)
|
2018-05-08 17:44:54 +02:00
|
|
|
{
|
2021-12-24 22:17:49 -05:00
|
|
|
VertLink *vl = MEM_cnew<VertLink>("VertLink");
|
2018-05-08 17:44:54 +02:00
|
|
|
vl->index = index;
|
|
|
|
|
BLI_addhead(lb, vl);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-18 14:27:41 +10:00
|
|
|
static void appendPolyLineVert(ListBase *lb, uint index)
|
2018-05-08 17:44:54 +02:00
|
|
|
{
|
2021-12-24 22:17:49 -05:00
|
|
|
VertLink *vl = MEM_cnew<VertLink>("VertLink");
|
2018-05-08 17:44:54 +02:00
|
|
|
vl->index = index;
|
|
|
|
|
BLI_addtail(lb, vl);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-01 13:48:39 +02:00
|
|
|
void BKE_mesh_to_curve_nurblist(const Mesh *me, ListBase *nurblist, const int edge_users_test)
|
2018-05-08 17:44:54 +02:00
|
|
|
{
|
2018-06-01 13:48:39 +02:00
|
|
|
MVert *mvert = me->mvert;
|
|
|
|
|
MEdge *med, *medge = me->medge;
|
|
|
|
|
MPoly *mp, *mpoly = me->mpoly;
|
|
|
|
|
MLoop *mloop = me->mloop;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 13:58:28 +02:00
|
|
|
int medge_len = me->totedge;
|
|
|
|
|
int mpoly_len = me->totpoly;
|
2018-05-08 17:44:54 +02:00
|
|
|
int totedges = 0;
|
|
|
|
|
int i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* only to detect edge polylines */
|
|
|
|
|
int *edge_users;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
ListBase edges = {nullptr, nullptr};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* get boundary edges */
|
2021-09-16 15:44:43 -05:00
|
|
|
edge_users = (int *)MEM_calloc_arrayN(medge_len, sizeof(int), __func__);
|
2018-06-01 13:58:28 +02:00
|
|
|
for (i = 0, mp = mpoly; i < mpoly_len; i++, mp++) {
|
2018-05-08 17:44:54 +02:00
|
|
|
MLoop *ml = &mloop[mp->loopstart];
|
|
|
|
|
int j;
|
|
|
|
|
for (j = 0; j < mp->totloop; j++, ml++) {
|
|
|
|
|
edge_users[ml->e]++;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-05-08 17:44:54 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* create edges from all faces (so as to find edges not in any faces) */
|
|
|
|
|
med = medge;
|
2018-06-01 13:58:28 +02:00
|
|
|
for (i = 0; i < medge_len; i++, med++) {
|
2018-05-08 17:44:54 +02:00
|
|
|
if (edge_users[i] == edge_users_test) {
|
2021-12-24 22:17:49 -05:00
|
|
|
EdgeLink *edl = MEM_cnew<EdgeLink>("EdgeLink");
|
2018-05-08 17:44:54 +02:00
|
|
|
edl->edge = med;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
BLI_addtail(&edges, edl);
|
|
|
|
|
totedges++;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-05-08 17:44:54 +02:00
|
|
|
}
|
|
|
|
|
MEM_freeN(edge_users);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
if (edges.first) {
|
|
|
|
|
while (edges.first) {
|
|
|
|
|
/* each iteration find a polyline and add this as a nurbs poly spline */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
ListBase polyline = {nullptr, nullptr}; /* store a list of VertLink's */
|
2018-05-08 17:44:54 +02:00
|
|
|
bool closed = false;
|
|
|
|
|
int totpoly = 0;
|
2021-09-16 15:44:43 -05:00
|
|
|
MEdge *med_current = (MEdge *)((EdgeLink *)edges.last)->edge;
|
2021-06-18 14:27:41 +10:00
|
|
|
uint startVert = med_current->v1;
|
|
|
|
|
uint endVert = med_current->v2;
|
2018-05-08 17:44:54 +02:00
|
|
|
bool ok = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
appendPolyLineVert(&polyline, startVert);
|
|
|
|
|
totpoly++;
|
|
|
|
|
appendPolyLineVert(&polyline, endVert);
|
|
|
|
|
totpoly++;
|
|
|
|
|
BLI_freelinkN(&edges, edges.last);
|
|
|
|
|
totedges--;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
while (ok) { /* while connected edges are found... */
|
2021-09-16 15:44:43 -05:00
|
|
|
EdgeLink *edl = (EdgeLink *)edges.last;
|
2018-05-08 17:44:54 +02:00
|
|
|
ok = false;
|
|
|
|
|
while (edl) {
|
|
|
|
|
EdgeLink *edl_prev = edl->prev;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
med = (MEdge *)edl->edge;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
if (med->v1 == endVert) {
|
|
|
|
|
endVert = med->v2;
|
|
|
|
|
appendPolyLineVert(&polyline, med->v2);
|
|
|
|
|
totpoly++;
|
|
|
|
|
BLI_freelinkN(&edges, edl);
|
|
|
|
|
totedges--;
|
|
|
|
|
ok = true;
|
|
|
|
|
}
|
|
|
|
|
else if (med->v2 == endVert) {
|
|
|
|
|
endVert = med->v1;
|
|
|
|
|
appendPolyLineVert(&polyline, endVert);
|
|
|
|
|
totpoly++;
|
|
|
|
|
BLI_freelinkN(&edges, edl);
|
|
|
|
|
totedges--;
|
|
|
|
|
ok = true;
|
|
|
|
|
}
|
|
|
|
|
else if (med->v1 == startVert) {
|
|
|
|
|
startVert = med->v2;
|
|
|
|
|
prependPolyLineVert(&polyline, startVert);
|
|
|
|
|
totpoly++;
|
|
|
|
|
BLI_freelinkN(&edges, edl);
|
|
|
|
|
totedges--;
|
|
|
|
|
ok = true;
|
|
|
|
|
}
|
|
|
|
|
else if (med->v2 == startVert) {
|
|
|
|
|
startVert = med->v1;
|
|
|
|
|
prependPolyLineVert(&polyline, startVert);
|
|
|
|
|
totpoly++;
|
|
|
|
|
BLI_freelinkN(&edges, edl);
|
|
|
|
|
totedges--;
|
|
|
|
|
ok = true;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
edl = edl_prev;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* Now we have a polyline, make into a curve */
|
|
|
|
|
if (startVert == endVert) {
|
|
|
|
|
BLI_freelinkN(&polyline, polyline.last);
|
|
|
|
|
totpoly--;
|
|
|
|
|
closed = true;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* --- nurbs --- */
|
|
|
|
|
{
|
|
|
|
|
Nurb *nu;
|
|
|
|
|
BPoint *bp;
|
|
|
|
|
VertLink *vl;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* create new 'nurb' within the curve */
|
2022-04-13 15:19:16 +02:00
|
|
|
nu = MEM_new<Nurb>("MeshNurb", blender::dna::shallow_zero_initialize());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
nu->pntsu = totpoly;
|
|
|
|
|
nu->pntsv = 1;
|
|
|
|
|
nu->orderu = 4;
|
|
|
|
|
nu->flagu = CU_NURB_ENDPOINT | (closed ? CU_NURB_CYCLIC : 0); /* endpoint */
|
|
|
|
|
nu->resolu = 12;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
nu->bp = (BPoint *)MEM_calloc_arrayN(totpoly, sizeof(BPoint), "bpoints");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* add points */
|
2021-09-16 15:44:43 -05:00
|
|
|
vl = (VertLink *)polyline.first;
|
2018-05-08 17:44:54 +02:00
|
|
|
for (i = 0, bp = nu->bp; i < totpoly; i++, bp++, vl = (VertLink *)vl->next) {
|
|
|
|
|
copy_v3_v3(bp->vec, mvert[vl->index].co);
|
|
|
|
|
bp->f1 = SELECT;
|
|
|
|
|
bp->radius = bp->weight = 1.0;
|
|
|
|
|
}
|
|
|
|
|
BLI_freelistN(&polyline);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 17:44:54 +02:00
|
|
|
/* add nurb to curve */
|
|
|
|
|
BLI_addtail(nurblist, nu);
|
|
|
|
|
}
|
|
|
|
|
/* --- done with nurbs --- */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-01 19:06:44 +03:00
|
|
|
void BKE_mesh_to_curve(Main *bmain, Depsgraph *depsgraph, Scene *UNUSED(scene), Object *ob)
|
2018-05-08 17:44:54 +02:00
|
|
|
{
|
|
|
|
|
/* make new mesh data from the original copy */
|
2018-12-01 19:06:44 +03:00
|
|
|
Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
|
|
|
|
|
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_MESH);
|
2021-09-16 15:44:43 -05:00
|
|
|
ListBase nurblist = {nullptr, nullptr};
|
2018-05-08 17:44:54 +02:00
|
|
|
|
2018-06-01 13:48:39 +02:00
|
|
|
BKE_mesh_to_curve_nurblist(me_eval, &nurblist, 0);
|
|
|
|
|
BKE_mesh_to_curve_nurblist(me_eval, &nurblist, 1);
|
2018-05-08 17:44:54 +02:00
|
|
|
|
|
|
|
|
if (nurblist.first) {
|
2022-02-18 09:50:29 -06:00
|
|
|
Curve *cu = BKE_curve_add(bmain, ob->id.name + 2, OB_CURVES_LEGACY);
|
2018-05-08 17:44:54 +02:00
|
|
|
cu->flag |= CU_3D;
|
|
|
|
|
|
|
|
|
|
cu->nurb = nurblist;
|
|
|
|
|
|
|
|
|
|
id_us_min(&((Mesh *)ob->data)->id);
|
|
|
|
|
ob->data = cu;
|
2022-02-18 09:50:29 -06:00
|
|
|
ob->type = OB_CURVES_LEGACY;
|
2018-05-08 17:44:54 +02:00
|
|
|
|
2018-06-22 16:58:44 +02:00
|
|
|
BKE_object_free_derived_caches(ob);
|
2018-05-08 17:44:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 18:49:40 +02:00
|
|
|
void BKE_pointcloud_from_mesh(Mesh *me, PointCloud *pointcloud)
|
|
|
|
|
{
|
2021-09-16 15:44:43 -05:00
|
|
|
BLI_assert(me != nullptr);
|
2020-04-09 18:49:40 +02:00
|
|
|
|
|
|
|
|
pointcloud->totpoint = me->totvert;
|
|
|
|
|
CustomData_realloc(&pointcloud->pdata, pointcloud->totpoint);
|
|
|
|
|
|
|
|
|
|
/* Copy over all attributes. */
|
2021-09-16 15:44:43 -05:00
|
|
|
CustomData_merge(&me->vdata, &pointcloud->pdata, CD_MASK_PROP_ALL, CD_DUPLICATE, me->totvert);
|
2020-04-09 18:49:40 +02:00
|
|
|
BKE_pointcloud_update_customdata_pointers(pointcloud);
|
|
|
|
|
CustomData_update_typemap(&pointcloud->pdata);
|
|
|
|
|
|
|
|
|
|
MVert *mvert;
|
|
|
|
|
mvert = me->mvert;
|
|
|
|
|
for (int i = 0; i < me->totvert; i++, mvert++) {
|
|
|
|
|
copy_v3_v3(pointcloud->co[i], mvert->co);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_mesh_to_pointcloud(Main *bmain, Depsgraph *depsgraph, Scene *UNUSED(scene), Object *ob)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
|
|
|
|
|
Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
|
|
|
|
|
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
|
|
|
|
|
Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_MESH);
|
|
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
PointCloud *pointcloud = (PointCloud *)BKE_pointcloud_add(bmain, ob->id.name + 2);
|
2020-04-09 18:49:40 +02:00
|
|
|
|
|
|
|
|
BKE_pointcloud_from_mesh(me_eval, pointcloud);
|
|
|
|
|
|
|
|
|
|
BKE_id_materials_copy(bmain, (ID *)ob->data, (ID *)pointcloud);
|
|
|
|
|
|
|
|
|
|
id_us_min(&((Mesh *)ob->data)->id);
|
|
|
|
|
ob->data = pointcloud;
|
|
|
|
|
ob->type = OB_POINTCLOUD;
|
|
|
|
|
|
|
|
|
|
BKE_object_free_derived_caches(ob);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-26 23:12:22 -05:00
|
|
|
void BKE_mesh_from_pointcloud(const PointCloud *pointcloud, Mesh *me)
|
2020-04-09 18:49:40 +02:00
|
|
|
{
|
2021-09-16 15:44:43 -05:00
|
|
|
BLI_assert(pointcloud != nullptr);
|
2020-04-09 18:49:40 +02:00
|
|
|
|
|
|
|
|
me->totvert = pointcloud->totpoint;
|
|
|
|
|
|
|
|
|
|
/* Merge over all attributes. */
|
2021-09-16 15:44:43 -05:00
|
|
|
CustomData_merge(
|
|
|
|
|
&pointcloud->pdata, &me->vdata, CD_MASK_PROP_ALL, CD_DUPLICATE, pointcloud->totpoint);
|
2020-04-09 18:49:40 +02:00
|
|
|
|
|
|
|
|
/* Convert the Position attribute to a mesh vertex. */
|
2021-09-16 15:44:43 -05:00
|
|
|
me->mvert = (MVert *)CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, nullptr, me->totvert);
|
2020-04-09 18:49:40 +02:00
|
|
|
CustomData_update_typemap(&me->vdata);
|
|
|
|
|
|
|
|
|
|
const int layer_idx = CustomData_get_named_layer_index(
|
|
|
|
|
&me->vdata, CD_PROP_FLOAT3, POINTCLOUD_ATTR_POSITION);
|
|
|
|
|
CustomDataLayer *pos_layer = &me->vdata.layers[layer_idx];
|
2021-09-16 15:44:43 -05:00
|
|
|
float(*positions)[3] = (float(*)[3])pos_layer->data;
|
2020-04-09 18:49:40 +02:00
|
|
|
|
|
|
|
|
MVert *mvert;
|
|
|
|
|
mvert = me->mvert;
|
|
|
|
|
for (int i = 0; i < me->totvert; i++, mvert++) {
|
|
|
|
|
copy_v3_v3(mvert->co, positions[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Delete Position attribute since it is now in vertex coordinates. */
|
|
|
|
|
CustomData_free_layer(&me->vdata, CD_PROP_FLOAT3, me->totvert, layer_idx);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-23 22:27:46 +02:00
|
|
|
void BKE_mesh_edges_set_draw_render(Mesh *mesh)
|
|
|
|
|
{
|
|
|
|
|
MEdge *med = mesh->medge;
|
|
|
|
|
for (int i = 0; i < mesh->totedge; i++, med++) {
|
|
|
|
|
med->flag |= ME_EDGEDRAW | ME_EDGERENDER;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 18:49:40 +02:00
|
|
|
void BKE_pointcloud_to_mesh(Main *bmain, Depsgraph *depsgraph, Scene *UNUSED(scene), Object *ob)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(ob->type == OB_POINTCLOUD);
|
|
|
|
|
|
|
|
|
|
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
|
|
|
|
|
PointCloud *pointcloud_eval = (PointCloud *)ob_eval->runtime.data_eval;
|
|
|
|
|
|
|
|
|
|
Mesh *me = BKE_mesh_add(bmain, ob->id.name + 2);
|
|
|
|
|
|
|
|
|
|
BKE_mesh_from_pointcloud(pointcloud_eval, me);
|
|
|
|
|
|
|
|
|
|
BKE_id_materials_copy(bmain, (ID *)ob->data, (ID *)me);
|
|
|
|
|
|
|
|
|
|
id_us_min(&((PointCloud *)ob->data)->id);
|
|
|
|
|
ob->data = me;
|
|
|
|
|
ob->type = OB_MESH;
|
|
|
|
|
|
|
|
|
|
BKE_object_free_derived_caches(ob);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 11:41:46 -05:00
|
|
|
/* Create a temporary object to be used for nurbs-to-mesh conversion. */
|
|
|
|
|
static Object *object_for_curve_to_mesh_create(const Object *object)
|
2018-05-08 17:44:54 +02:00
|
|
|
{
|
2021-09-23 11:41:46 -05:00
|
|
|
const Curve *curve = (const Curve *)object->data;
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
|
2021-09-24 11:31:23 +10:00
|
|
|
/* Create a temporary object which can be evaluated and modified by generic
|
|
|
|
|
* curve evaluation (hence the #LIB_ID_COPY_SET_COPIED_ON_WRITE flag). */
|
2021-09-16 15:44:43 -05:00
|
|
|
Object *temp_object = (Object *)BKE_id_copy_ex(
|
2021-09-23 11:41:46 -05:00
|
|
|
nullptr, &object->id, nullptr, LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_SET_COPIED_ON_WRITE);
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
|
|
|
|
|
/* Remove all modifiers, since we don't want them to be applied. */
|
|
|
|
|
BKE_object_free_modifiers(temp_object, LIB_ID_CREATE_NO_USER_REFCOUNT);
|
|
|
|
|
|
2021-09-23 11:41:46 -05:00
|
|
|
/* Need to create copy of curve itself as well, since it will be changed by the curve evaluation
|
2021-09-24 11:31:23 +10:00
|
|
|
* process. NOTE: Copies the data, but not the shape-keys. */
|
2021-09-23 11:41:46 -05:00
|
|
|
temp_object->data = BKE_id_copy_ex(nullptr,
|
|
|
|
|
(const ID *)object->data,
|
|
|
|
|
nullptr,
|
|
|
|
|
LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_SET_COPIED_ON_WRITE);
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
Curve *temp_curve = (Curve *)temp_object->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
/* Make sure texture space is calculated for a copy of curve, it will be used for the final
|
|
|
|
|
* result. */
|
|
|
|
|
BKE_curve_texspace_calc(temp_curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-24 11:31:23 +10:00
|
|
|
/* Temporarily set edit so we get updates from edit mode, but also because for text data-blocks
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
* copying it while in edit mode gives invalid data structures. */
|
|
|
|
|
temp_curve->editfont = curve->editfont;
|
|
|
|
|
temp_curve->editnurb = curve->editnurb;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
return temp_object;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-29 16:53:02 -06:00
|
|
|
static void object_for_curve_to_mesh_free(Object *temp_object)
|
|
|
|
|
{
|
|
|
|
|
/* Clear edit mode pointers that were explicitly copied to the temporary curve. */
|
|
|
|
|
ID *final_object_data = static_cast<ID *>(temp_object->data);
|
2022-02-18 09:50:29 -06:00
|
|
|
if (GS(final_object_data->name) == ID_CU_LEGACY) {
|
2021-12-29 16:53:02 -06:00
|
|
|
Curve &curve = *reinterpret_cast<Curve *>(final_object_data);
|
|
|
|
|
curve.editfont = nullptr;
|
|
|
|
|
curve.editnurb = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-19 11:10:17 +02:00
|
|
|
/* Only free the final object data if it is *not* stored in the #data_eval field. This is still
|
|
|
|
|
* necessary because #temp_object's data could be replaced by a #Curve data-block that isn't also
|
|
|
|
|
* assigned to #data_eval. */
|
|
|
|
|
const bool object_data_stored_in_data_eval = final_object_data == temp_object->runtime.data_eval;
|
|
|
|
|
|
2021-12-29 16:53:02 -06:00
|
|
|
BKE_id_free(nullptr, temp_object);
|
2022-05-19 11:10:17 +02:00
|
|
|
if (!object_data_stored_in_data_eval) {
|
|
|
|
|
BKE_id_free(nullptr, final_object_data);
|
|
|
|
|
}
|
2021-12-29 16:53:02 -06:00
|
|
|
}
|
|
|
|
|
|
2021-05-05 08:05:10 +10:00
|
|
|
/**
|
|
|
|
|
* Populate `object->runtime.curve_cache` which is then used to create the mesh.
|
|
|
|
|
*/
|
2021-09-23 11:41:46 -05:00
|
|
|
static void curve_to_mesh_eval_ensure(Object &object)
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
{
|
2022-02-18 09:50:29 -06:00
|
|
|
BLI_assert(GS(static_cast<ID *>(object.data)->name) == ID_CU_LEGACY);
|
2021-09-23 11:41:46 -05:00
|
|
|
Curve &curve = *static_cast<Curve *>(object.data);
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
/* Clear all modifiers for the bevel object.
|
|
|
|
|
*
|
|
|
|
|
* This is because they can not be reliably evaluated for an original object (at least because
|
|
|
|
|
* the state of dependencies is not know).
|
|
|
|
|
*
|
|
|
|
|
* So we create temporary copy of the object which will use same data as the original bevel, but
|
|
|
|
|
* will have no modifiers. */
|
2022-03-31 10:06:33 +02:00
|
|
|
Object bevel_object = blender::dna::shallow_zero_initialize();
|
2021-09-23 11:41:46 -05:00
|
|
|
if (curve.bevobj != nullptr) {
|
2022-03-29 10:06:34 +02:00
|
|
|
bevel_object = blender::dna::shallow_copy(*curve.bevobj);
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
BLI_listbase_clear(&bevel_object.modifiers);
|
2021-04-30 16:22:51 +10:00
|
|
|
BKE_object_runtime_reset(&bevel_object);
|
2021-09-23 11:41:46 -05:00
|
|
|
curve.bevobj = &bevel_object;
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
/* Same thing for taper. */
|
2022-03-31 10:06:33 +02:00
|
|
|
Object taper_object = blender::dna::shallow_zero_initialize();
|
2021-09-23 11:41:46 -05:00
|
|
|
if (curve.taperobj != nullptr) {
|
2022-03-29 10:06:34 +02:00
|
|
|
taper_object = blender::dna::shallow_copy(*curve.taperobj);
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
BLI_listbase_clear(&taper_object.modifiers);
|
2021-04-30 16:22:51 +10:00
|
|
|
BKE_object_runtime_reset(&taper_object);
|
2021-09-23 11:41:46 -05:00
|
|
|
curve.taperobj = &taper_object;
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
/* NOTE: We don't have dependency graph or scene here, so we pass nullptr. This is all fine since
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
* they are only used for modifier stack, which we have explicitly disabled for all objects.
|
|
|
|
|
*
|
|
|
|
|
* TODO(sergey): This is a very fragile logic, but proper solution requires re-writing quite a
|
2021-09-23 11:41:46 -05:00
|
|
|
* bit of internal functions (#BKE_mesh_nomain_to_mesh) and also Mesh From Curve operator.
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
* Brecht says hold off with that. */
|
2021-09-23 11:41:46 -05:00
|
|
|
BKE_displist_make_curveTypes(nullptr, nullptr, &object, true);
|
2019-06-09 21:11:37 +02:00
|
|
|
|
2021-09-23 11:41:46 -05:00
|
|
|
BKE_object_runtime_free_data(&bevel_object);
|
2021-04-30 22:35:47 +10:00
|
|
|
BKE_object_runtime_free_data(&taper_object);
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-02-28 10:46:34 -05:00
|
|
|
static const Curves *get_evaluated_curves_from_object(const Object *object)
|
2021-09-23 11:41:46 -05:00
|
|
|
{
|
2022-05-19 14:08:54 +02:00
|
|
|
if (GeometrySet *geometry_set_eval = object->runtime.geometry_set_eval) {
|
2022-02-28 10:53:30 -05:00
|
|
|
return geometry_set_eval->get_curves_for_read();
|
2021-09-23 11:41:46 -05:00
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Mesh *mesh_new_from_evaluated_curve_type_object(const Object *evaluated_object)
|
|
|
|
|
{
|
2022-05-19 14:08:54 +02:00
|
|
|
if (const Mesh *mesh = BKE_object_get_evaluated_mesh(evaluated_object)) {
|
2021-09-23 11:41:46 -05:00
|
|
|
return BKE_mesh_copy_for_eval(mesh, false);
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
}
|
2022-05-19 14:08:54 +02:00
|
|
|
if (const Curves *curves = get_evaluated_curves_from_object(evaluated_object)) {
|
2022-04-15 10:14:54 -05:00
|
|
|
return blender::bke::curve_to_wire_mesh(blender::bke::CurvesGeometry::wrap(curves->geometry));
|
2021-09-23 11:41:46 -05:00
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-23 11:41:46 -05:00
|
|
|
static Mesh *mesh_new_from_curve_type_object(const Object *object)
|
|
|
|
|
{
|
|
|
|
|
/* If the object is evaluated, it should either have an evaluated mesh or curve data already.
|
|
|
|
|
* The mesh can be duplicated, or the curve converted to wire mesh edges. */
|
|
|
|
|
if (DEG_is_evaluated_object(object)) {
|
|
|
|
|
return mesh_new_from_evaluated_curve_type_object(object);
|
|
|
|
|
}
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
|
2021-09-23 11:41:46 -05:00
|
|
|
/* Otherwise, create a temporary "fake" evaluated object and try again. This might have
|
|
|
|
|
* different results, since in order to avoid having adverse affects to other original objects,
|
|
|
|
|
* modifiers are cleared. An alternative would be to create a temporary depsgraph only for this
|
|
|
|
|
* object and its dependencies. */
|
|
|
|
|
Object *temp_object = object_for_curve_to_mesh_create(object);
|
|
|
|
|
ID *temp_data = static_cast<ID *>(temp_object->data);
|
|
|
|
|
curve_to_mesh_eval_ensure(*temp_object);
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
|
2021-09-23 11:41:46 -05:00
|
|
|
/* If evaluating the curve replaced object data with different data, free the original data. */
|
|
|
|
|
if (temp_data != temp_object->data) {
|
|
|
|
|
BKE_id_free(nullptr, temp_data);
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-23 11:41:46 -05:00
|
|
|
Mesh *mesh = mesh_new_from_evaluated_curve_type_object(temp_object);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-29 16:53:02 -06:00
|
|
|
object_for_curve_to_mesh_free(temp_object);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-23 11:41:46 -05:00
|
|
|
return mesh;
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-16 13:49:21 +02:00
|
|
|
static Mesh *mesh_new_from_mball_object(Object *object)
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
{
|
|
|
|
|
MetaBall *mball = (MetaBall *)object->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
/* NOTE: We can only create mesh for a polygonized meta ball. This figures out all original meta
|
|
|
|
|
* balls and all evaluated child meta balls (since polygonization is only stored in the mother
|
|
|
|
|
* ball).
|
|
|
|
|
*
|
2021-09-22 14:48:01 +10:00
|
|
|
* Create empty mesh so script-authors don't run into None objects. */
|
2021-09-16 15:44:43 -05:00
|
|
|
if (!DEG_is_evaluated_object(object) || object->runtime.curve_cache == nullptr ||
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
BLI_listbase_is_empty(&object->runtime.curve_cache->disp)) {
|
2021-09-16 15:44:43 -05:00
|
|
|
return (Mesh *)BKE_id_new_nomain(ID_ME, ((ID *)object->data)->name + 2);
|
2018-05-08 17:44:54 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
Mesh *mesh_result = (Mesh *)BKE_id_new_nomain(ID_ME, ((ID *)object->data)->name + 2);
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
BKE_mesh_from_metaball(&object->runtime.curve_cache->disp, mesh_result);
|
2019-09-19 17:23:16 +02:00
|
|
|
BKE_mesh_texspace_copy_from_object(mesh_result, object);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
/* Copy materials. */
|
|
|
|
|
mesh_result->totcol = mball->totcol;
|
2021-09-16 15:44:43 -05:00
|
|
|
mesh_result->mat = (Material **)MEM_dupallocN(mball->mat);
|
|
|
|
|
if (mball->mat != nullptr) {
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
for (int i = mball->totcol; i-- > 0;) {
|
2020-02-05 11:23:58 +01:00
|
|
|
mesh_result->mat[i] = BKE_object_material_get(object, i + 1);
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
return mesh_result;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-24 14:37:47 +02:00
|
|
|
static Mesh *mesh_new_from_mesh(Object *object, Mesh *mesh)
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
{
|
2020-05-25 20:16:42 +10:00
|
|
|
/* While we could copy this into the new mesh,
|
|
|
|
|
* add the data to 'mesh' so future calls to this function don't need to re-convert the data. */
|
2022-02-14 16:35:25 +01:00
|
|
|
if (mesh->runtime.wrapper_type == ME_WRAPPER_TYPE_BMESH) {
|
|
|
|
|
BKE_mesh_wrapper_ensure_mdata(mesh);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-06-24 16:16:43 -05:00
|
|
|
mesh = BKE_mesh_wrapper_ensure_subdivision(mesh);
|
2022-02-14 16:35:25 +01:00
|
|
|
}
|
2020-05-25 20:16:42 +10:00
|
|
|
|
2020-10-07 14:27:33 +02:00
|
|
|
Mesh *mesh_result = (Mesh *)BKE_id_copy_ex(
|
2021-09-16 15:44:43 -05:00
|
|
|
nullptr, &mesh->id, nullptr, LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT);
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
/* NOTE: Materials should already be copied. */
|
2019-05-16 17:59:45 +02:00
|
|
|
/* Copy original mesh name. This is because edit meshes might not have one properly set name. */
|
|
|
|
|
BLI_strncpy(mesh_result->id.name, ((ID *)object->data)->name, sizeof(mesh_result->id.name));
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
return mesh_result;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-05-12 23:14:58 +02:00
|
|
|
static Mesh *mesh_new_from_mesh_object_with_layers(Depsgraph *depsgraph,
|
|
|
|
|
Object *object,
|
|
|
|
|
const bool preserve_origindex)
|
2019-05-24 14:37:47 +02:00
|
|
|
{
|
|
|
|
|
if (DEG_is_original_id(&object->id)) {
|
|
|
|
|
return mesh_new_from_mesh(object, (Mesh *)object->data);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
if (depsgraph == nullptr) {
|
|
|
|
|
return nullptr;
|
2019-05-24 14:37:47 +02:00
|
|
|
}
|
|
|
|
|
|
2022-03-29 10:06:34 +02:00
|
|
|
Object object_for_eval = blender::dna::shallow_copy(*object);
|
2021-09-16 15:44:43 -05:00
|
|
|
if (object_for_eval.runtime.data_orig != nullptr) {
|
2020-02-27 11:23:15 +01:00
|
|
|
object_for_eval.data = object_for_eval.runtime.data_orig;
|
2019-05-24 14:37:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
|
|
|
|
CustomData_MeshMasks mask = CD_MASK_MESH;
|
2021-05-12 23:14:58 +02:00
|
|
|
if (preserve_origindex) {
|
|
|
|
|
mask.vmask |= CD_MASK_ORIGINDEX;
|
|
|
|
|
mask.emask |= CD_MASK_ORIGINDEX;
|
|
|
|
|
mask.lmask |= CD_MASK_ORIGINDEX;
|
|
|
|
|
mask.pmask |= CD_MASK_ORIGINDEX;
|
|
|
|
|
}
|
2020-08-18 12:58:48 +02:00
|
|
|
Mesh *result = mesh_create_eval_final(depsgraph, scene, &object_for_eval, &mask);
|
2022-06-24 16:16:43 -05:00
|
|
|
return BKE_mesh_wrapper_ensure_subdivision(result);
|
2019-05-24 14:37:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Mesh *mesh_new_from_mesh_object(Depsgraph *depsgraph,
|
|
|
|
|
Object *object,
|
2021-05-12 23:14:58 +02:00
|
|
|
const bool preserve_all_data_layers,
|
|
|
|
|
const bool preserve_origindex)
|
2019-05-24 14:37:47 +02:00
|
|
|
{
|
2021-05-12 23:14:58 +02:00
|
|
|
if (preserve_all_data_layers || preserve_origindex) {
|
|
|
|
|
return mesh_new_from_mesh_object_with_layers(depsgraph, object, preserve_origindex);
|
2019-05-24 14:37:47 +02:00
|
|
|
}
|
2021-09-16 15:44:43 -05:00
|
|
|
Mesh *mesh_input = (Mesh *)object->data;
|
2019-05-24 14:37:47 +02:00
|
|
|
/* If we are in edit mode, use evaluated mesh from edit structure, matching to what
|
|
|
|
|
* viewport is using for visualization. */
|
2022-01-11 15:42:07 +01:00
|
|
|
if (mesh_input->edit_mesh != nullptr) {
|
|
|
|
|
Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object);
|
|
|
|
|
if (editmesh_eval_final != nullptr) {
|
|
|
|
|
mesh_input = editmesh_eval_final;
|
|
|
|
|
}
|
2019-05-24 14:37:47 +02:00
|
|
|
}
|
|
|
|
|
return mesh_new_from_mesh(object, mesh_input);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-12 23:14:58 +02:00
|
|
|
Mesh *BKE_mesh_new_from_object(Depsgraph *depsgraph,
|
|
|
|
|
Object *object,
|
|
|
|
|
const bool preserve_all_data_layers,
|
|
|
|
|
const bool preserve_origindex)
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
{
|
2021-09-16 15:44:43 -05:00
|
|
|
Mesh *new_mesh = nullptr;
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
switch (object->type) {
|
|
|
|
|
case OB_FONT:
|
2022-02-18 09:50:29 -06:00
|
|
|
case OB_CURVES_LEGACY:
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
case OB_SURF:
|
2019-05-16 13:49:21 +02:00
|
|
|
new_mesh = mesh_new_from_curve_type_object(object);
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
break;
|
|
|
|
|
case OB_MBALL:
|
2019-05-16 13:49:21 +02:00
|
|
|
new_mesh = mesh_new_from_mball_object(object);
|
2018-05-08 17:44:54 +02:00
|
|
|
break;
|
|
|
|
|
case OB_MESH:
|
2021-05-12 23:14:58 +02:00
|
|
|
new_mesh = mesh_new_from_mesh_object(
|
|
|
|
|
depsgraph, object, preserve_all_data_layers, preserve_origindex);
|
2018-05-08 17:44:54 +02:00
|
|
|
break;
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
default:
|
|
|
|
|
/* Object does not have geometry data. */
|
2021-09-16 15:44:43 -05:00
|
|
|
return nullptr;
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
}
|
2021-09-16 15:44:43 -05:00
|
|
|
if (new_mesh == nullptr) {
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
/* Happens in special cases like request of mesh for non-mother meta ball. */
|
2021-09-16 15:44:43 -05:00
|
|
|
return nullptr;
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
}
|
2020-04-07 11:36:59 +02:00
|
|
|
|
2019-05-16 13:49:21 +02:00
|
|
|
/* The result must have 0 users, since it's just a mesh which is free-dangling data-block.
|
|
|
|
|
* All the conversion functions are supposed to ensure mesh is not counted. */
|
|
|
|
|
BLI_assert(new_mesh->id.us == 0);
|
2020-04-07 11:36:59 +02:00
|
|
|
|
|
|
|
|
/* It is possible that mesh came from modifier stack evaluation, which preserves edit_mesh
|
|
|
|
|
* pointer (which allows draw manager to access edit mesh when drawing). Normally this does
|
|
|
|
|
* not cause ownership problems because evaluated object runtime is keeping track of the real
|
|
|
|
|
* ownership.
|
|
|
|
|
*
|
2020-04-08 10:33:56 +10:00
|
|
|
* Here we are constructing a mesh which is supposed to be independent, which means no shared
|
2021-09-16 15:44:43 -05:00
|
|
|
* ownership is allowed, so we make sure edit mesh is reset to nullptr (which is similar to as if
|
2020-04-07 11:36:59 +02:00
|
|
|
* one duplicates the objects and applies all the modifiers). */
|
2021-09-16 15:44:43 -05:00
|
|
|
new_mesh->edit_mesh = nullptr;
|
2020-04-07 11:36:59 +02:00
|
|
|
|
Dependency graph API changes
Main goal here is to make it obvious and predictable about
what is going on.
Summary of changes.
- Access to dependency graph is now only possible to a fully evaluated
graph. This is now done via context.evaluated_depsgraph_get().
The call will ensure both relations and datablocks are updated.
This way we don't allow access to some known bad state of the graph,
and also making explicit that getting update dependency graph is not
cheap.
- Access to evaluated ID is now possible via id.evaluated_get().
It was already possible to get evaluated ID via dependency graph,
but that was a bit confusing why access to original is done via ID
and to evaluated via depsgraph.
If datablock is not covered by dependency graph it will be returned
as-is.
- Similarly, request for original from an ID which is not evaluated
will return ID as-is.
- Removed scene.update().
This is very expensive to update all the view layers.
- Added depsgraph.update().
Now when temporary changes to objects are to be done, this is to
happen on original object and then dependency graph is to be
updated.
- Changed object.to_mesh() to behave the following way:
* When is used for original object modifiers are ignored.
For meshes this acts similar to mesh-copy, not very useful but
allows to keep code paths similar (i.e. for exporter which has
Apply Modifiers option it's only matter choosing between original
and evaluated object, the to_mesh() part can stay the same).
For curves this gives a mesh which is constructed from displist
without taking own modifiers and modifiers of bevel/taper objects
into account.
For metaballs this gives empty mesh.
Polygonization of metaball is not possible from a single object.
* When is used for evaluated object modifiers are always applied.
In fact, no evaluation is happening, the mesh is either copied
as-is, or constructed from current state of curve cache.
Arguments to apply modifiers and calculate original coordinates (ORCO,
aka undeformed coordinates) are removed. The ORCO is to be calculated
as part of dependency graph evaluation.
File used to regression-test (a packed Python script into .blend):
{F7033464}
Patch to make addons tests to pass:
{F7033466}
NOTE: I've included changes to FBX exporter, and those are addressing
report T63689.
NOTE: All the enabled-by-default addons are to be ported still, but
first want to have agreement on this part of changes.
NOTE: Also need to work on documentation for Python API, but, again,
better be done after having agreement on this work.
Reviewers: brecht, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D4834
2019-05-09 11:26:49 +02:00
|
|
|
return new_mesh;
|
2018-05-08 17:44:54 +02:00
|
|
|
}
|
2018-06-01 17:05:21 +02:00
|
|
|
|
2020-02-13 12:56:10 +01:00
|
|
|
static int foreach_libblock_make_original_callback(LibraryIDLinkCallbackData *cb_data)
|
2019-05-16 13:49:21 +02:00
|
|
|
{
|
2020-02-13 12:56:10 +01:00
|
|
|
ID **id_p = cb_data->id_pointer;
|
2021-09-16 15:44:43 -05:00
|
|
|
if (*id_p == nullptr) {
|
2019-05-16 13:49:21 +02:00
|
|
|
return IDWALK_RET_NOP;
|
|
|
|
|
}
|
|
|
|
|
*id_p = DEG_get_original_id(*id_p);
|
2019-05-27 16:46:45 +02:00
|
|
|
|
2019-06-03 20:59:13 +02:00
|
|
|
return IDWALK_RET_NOP;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-13 12:56:10 +01:00
|
|
|
static int foreach_libblock_make_usercounts_callback(LibraryIDLinkCallbackData *cb_data)
|
2019-06-03 20:59:13 +02:00
|
|
|
{
|
2020-02-13 12:56:10 +01:00
|
|
|
ID **id_p = cb_data->id_pointer;
|
2021-09-16 15:44:43 -05:00
|
|
|
if (*id_p == nullptr) {
|
2019-06-03 20:59:13 +02:00
|
|
|
return IDWALK_RET_NOP;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-13 12:56:10 +01:00
|
|
|
const int cb_flag = cb_data->cb_flag;
|
2019-05-27 16:46:45 +02:00
|
|
|
if (cb_flag & IDWALK_CB_USER) {
|
|
|
|
|
id_us_plus(*id_p);
|
|
|
|
|
}
|
|
|
|
|
else if (cb_flag & IDWALK_CB_USER_ONE) {
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE: in that context, that one should not be needed (since there should be at least already
|
2019-05-27 16:46:45 +02:00
|
|
|
* one USER_ONE user of that ID), but better be consistent. */
|
|
|
|
|
id_us_ensure_real(*id_p);
|
|
|
|
|
}
|
2019-05-16 13:49:21 +02:00
|
|
|
return IDWALK_RET_NOP;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-24 14:37:47 +02:00
|
|
|
Mesh *BKE_mesh_new_from_object_to_bmain(Main *bmain,
|
|
|
|
|
Depsgraph *depsgraph,
|
|
|
|
|
Object *object,
|
|
|
|
|
bool preserve_all_data_layers)
|
2019-05-16 13:49:21 +02:00
|
|
|
{
|
2022-02-18 09:50:29 -06:00
|
|
|
BLI_assert(ELEM(object->type, OB_FONT, OB_CURVES_LEGACY, OB_SURF, OB_MBALL, OB_MESH));
|
2019-08-02 17:45:32 +02:00
|
|
|
|
2021-05-12 23:14:58 +02:00
|
|
|
Mesh *mesh = BKE_mesh_new_from_object(depsgraph, object, preserve_all_data_layers, false);
|
2021-09-16 15:44:43 -05:00
|
|
|
if (mesh == nullptr) {
|
2019-08-02 17:45:32 +02:00
|
|
|
/* Unable to convert the object to a mesh, return an empty one. */
|
|
|
|
|
Mesh *mesh_in_bmain = BKE_mesh_add(bmain, ((ID *)object->data)->name + 2);
|
|
|
|
|
id_us_min(&mesh_in_bmain->id);
|
|
|
|
|
return mesh_in_bmain;
|
2019-07-10 12:58:39 +02:00
|
|
|
}
|
2019-05-16 13:49:21 +02:00
|
|
|
|
2021-09-24 11:31:23 +10:00
|
|
|
/* Make sure mesh only points original data-blocks, also increase users of materials and other
|
2019-05-16 13:49:21 +02:00
|
|
|
* possibly referenced data-blocks.
|
|
|
|
|
*
|
|
|
|
|
* Going to original data-blocks is required to have bmain in a consistent state, where
|
|
|
|
|
* everything is only allowed to reference original data-blocks.
|
|
|
|
|
*
|
2019-06-03 20:59:13 +02:00
|
|
|
* Note that user-count updates has to be done *after* mesh has been transferred to Main database
|
|
|
|
|
* (since doing refcounting on non-Main IDs is forbidden). */
|
2019-05-16 13:49:21 +02:00
|
|
|
BKE_library_foreach_ID_link(
|
2021-09-16 15:44:43 -05:00
|
|
|
nullptr, &mesh->id, foreach_libblock_make_original_callback, nullptr, IDWALK_NOP);
|
2019-05-16 13:49:21 +02:00
|
|
|
|
2019-08-02 12:00:07 +10:00
|
|
|
/* Append the mesh to 'bmain'.
|
|
|
|
|
* We do it a bit longer way since there is no simple and clear way of adding existing data-block
|
|
|
|
|
* to the 'bmain'. So we allocate new empty mesh in the 'bmain' (which guarantees all the naming
|
|
|
|
|
* and orders and flags) and move the temporary mesh in place there. */
|
2019-05-16 13:49:21 +02:00
|
|
|
Mesh *mesh_in_bmain = BKE_mesh_add(bmain, mesh->id.name + 2);
|
2019-05-17 18:23:06 +02:00
|
|
|
|
|
|
|
|
/* NOTE: BKE_mesh_nomain_to_mesh() does not copy materials and instead it preserves them in the
|
2019-08-02 12:00:07 +10:00
|
|
|
* destination mesh. So we "steal" all related fields before calling it.
|
2019-05-17 18:23:06 +02:00
|
|
|
*
|
|
|
|
|
* TODO(sergey): We really better have a function which gets and ID and accepts it for the bmain.
|
|
|
|
|
*/
|
|
|
|
|
mesh_in_bmain->mat = mesh->mat;
|
|
|
|
|
mesh_in_bmain->totcol = mesh->totcol;
|
|
|
|
|
mesh_in_bmain->flag = mesh->flag;
|
|
|
|
|
mesh_in_bmain->smoothresh = mesh->smoothresh;
|
2021-09-16 15:44:43 -05:00
|
|
|
mesh->mat = nullptr;
|
2019-05-17 18:23:06 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
BKE_mesh_nomain_to_mesh(mesh, mesh_in_bmain, nullptr, &CD_MASK_MESH, true);
|
2019-05-16 13:49:21 +02:00
|
|
|
|
2022-02-16 15:58:27 +01:00
|
|
|
/* Anonymous attributes shouldn't exist on original data. */
|
2022-04-26 08:06:04 -05:00
|
|
|
MeshComponent component;
|
|
|
|
|
component.replace(mesh_in_bmain, GeometryOwnershipType::Editable);
|
|
|
|
|
component.attributes_remove_anonymous();
|
2022-02-16 15:58:27 +01:00
|
|
|
|
2019-06-03 20:59:13 +02:00
|
|
|
/* User-count is required because so far mesh was in a limbo, where library management does
|
|
|
|
|
* not perform any user management (i.e. copy of a mesh will not increase users of materials). */
|
|
|
|
|
BKE_library_foreach_ID_link(
|
2021-09-16 15:44:43 -05:00
|
|
|
nullptr, &mesh_in_bmain->id, foreach_libblock_make_usercounts_callback, nullptr, IDWALK_NOP);
|
2019-06-03 20:59:13 +02:00
|
|
|
|
2019-05-16 13:49:21 +02:00
|
|
|
/* Make sure user count from BKE_mesh_add() is the one we expect here and bring it down to 0. */
|
|
|
|
|
BLI_assert(mesh_in_bmain->id.us == 1);
|
|
|
|
|
id_us_min(&mesh_in_bmain->id);
|
|
|
|
|
|
|
|
|
|
return mesh_in_bmain;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
static void add_shapekey_layers(Mesh *mesh_dest, Mesh *mesh_src)
|
|
|
|
|
{
|
|
|
|
|
KeyBlock *kb;
|
|
|
|
|
Key *key = mesh_src->key;
|
|
|
|
|
int i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!mesh_src->key) {
|
2018-06-01 17:05:21 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
/* ensure we can use mesh vertex count for derived mesh custom data */
|
|
|
|
|
if (mesh_src->totvert != mesh_dest->totvert) {
|
2019-02-01 12:44:19 +11:00
|
|
|
CLOG_ERROR(&LOG,
|
|
|
|
|
"vertex size mismatch (mesh/dm) '%s' (%d != %d)",
|
|
|
|
|
mesh_src->id.name + 2,
|
|
|
|
|
mesh_src->totvert,
|
|
|
|
|
mesh_dest->totvert);
|
2018-06-01 17:05:21 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
for (i = 0, kb = (KeyBlock *)key->block.first; kb; kb = kb->next, i++) {
|
2018-06-01 17:05:21 +02:00
|
|
|
int ci;
|
|
|
|
|
float *array;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
if (mesh_src->totvert != kb->totelem) {
|
2019-02-01 12:44:19 +11:00
|
|
|
CLOG_ERROR(&LOG,
|
|
|
|
|
"vertex size mismatch (Mesh '%s':%d != KeyBlock '%s':%d)",
|
|
|
|
|
mesh_src->id.name + 2,
|
|
|
|
|
mesh_src->totvert,
|
|
|
|
|
kb->name,
|
|
|
|
|
kb->totelem);
|
2021-09-16 15:44:43 -05:00
|
|
|
array = (float *)MEM_calloc_arrayN((size_t)mesh_src->totvert, sizeof(float[3]), __func__);
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2021-09-16 15:44:43 -05:00
|
|
|
array = (float *)MEM_malloc_arrayN((size_t)mesh_src->totvert, sizeof(float[3]), __func__);
|
2020-08-08 13:29:21 +10:00
|
|
|
memcpy(array, kb->data, sizeof(float[3]) * (size_t)mesh_src->totvert);
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
CustomData_add_layer_named(
|
|
|
|
|
&mesh_dest->vdata, CD_SHAPEKEY, CD_ASSIGN, array, mesh_dest->totvert, kb->name);
|
|
|
|
|
ci = CustomData_get_layer_index_n(&mesh_dest->vdata, CD_SHAPEKEY, i);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
mesh_dest->vdata.layers[ci].uid = kb->uid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Mesh *BKE_mesh_create_derived_for_modifier(struct Depsgraph *depsgraph,
|
|
|
|
|
Scene *scene,
|
2019-04-28 15:41:30 +02:00
|
|
|
Object *ob_eval,
|
|
|
|
|
ModifierData *md_eval,
|
2021-11-10 00:33:22 +11:00
|
|
|
const bool use_virtual_modifiers,
|
2021-01-09 19:00:05 +11:00
|
|
|
const bool build_shapekey_layers)
|
2018-06-01 17:05:21 +02:00
|
|
|
{
|
2021-09-16 15:44:43 -05:00
|
|
|
Mesh *me = ob_eval->runtime.data_orig ? (Mesh *)ob_eval->runtime.data_orig :
|
|
|
|
|
(Mesh *)ob_eval->data;
|
|
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info((ModifierType)md_eval->type);
|
|
|
|
|
Mesh *result = nullptr;
|
2018-06-01 17:05:21 +02:00
|
|
|
KeyBlock *kb;
|
2020-03-26 14:36:39 +01:00
|
|
|
ModifierEvalContext mectx = {depsgraph, ob_eval, MOD_APPLY_TO_BASE_MESH};
|
2018-06-01 17:05:21 +02:00
|
|
|
|
2019-04-28 15:41:30 +02:00
|
|
|
if (!(md_eval->mode & eModifierMode_Realtime)) {
|
2020-10-07 14:27:33 +02:00
|
|
|
return result;
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
if (mti->isDisabled && mti->isDisabled(scene, md_eval, false)) {
|
2020-10-07 14:27:33 +02:00
|
|
|
return result;
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-28 15:41:30 +02:00
|
|
|
if (build_shapekey_layers && me->key &&
|
2021-09-16 15:44:43 -05:00
|
|
|
(kb = (KeyBlock *)BLI_findlink(&me->key->block, ob_eval->shapenr - 1))) {
|
2022-03-22 09:43:02 -05:00
|
|
|
BKE_keyblock_convert_to_mesh(kb, me->mvert, me->totvert);
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
2021-11-10 00:33:22 +11:00
|
|
|
Mesh *mesh_temp = (Mesh *)BKE_id_copy_ex(nullptr, &me->id, nullptr, LIB_ID_COPY_LOCALIZE);
|
|
|
|
|
int numVerts = 0;
|
|
|
|
|
float(*deformedVerts)[3] = nullptr;
|
|
|
|
|
|
|
|
|
|
if (use_virtual_modifiers) {
|
|
|
|
|
VirtualModifierData virtualModifierData;
|
|
|
|
|
for (ModifierData *md_eval_virt =
|
|
|
|
|
BKE_modifiers_get_virtual_modifierlist(ob_eval, &virtualModifierData);
|
|
|
|
|
md_eval_virt && (md_eval_virt != ob_eval->modifiers.first);
|
|
|
|
|
md_eval_virt = md_eval_virt->next) {
|
|
|
|
|
if (!BKE_modifier_is_enabled(scene, md_eval_virt, eModifierMode_Realtime)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
/* All virtual modifiers are deform modifiers. */
|
|
|
|
|
const ModifierTypeInfo *mti_virt = BKE_modifier_get_info((ModifierType)md_eval_virt->type);
|
|
|
|
|
BLI_assert(mti_virt->type == eModifierTypeType_OnlyDeform);
|
|
|
|
|
if (mti_virt->type != eModifierTypeType_OnlyDeform) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (deformedVerts == nullptr) {
|
|
|
|
|
deformedVerts = BKE_mesh_vert_coords_alloc(me, &numVerts);
|
|
|
|
|
}
|
|
|
|
|
mti_virt->deformVerts(md_eval_virt, &mectx, mesh_temp, deformedVerts, numVerts);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-01 17:05:21 +02:00
|
|
|
|
2021-11-10 00:33:22 +11:00
|
|
|
if (mti->type == eModifierTypeType_OnlyDeform) {
|
|
|
|
|
if (deformedVerts == nullptr) {
|
|
|
|
|
deformedVerts = BKE_mesh_vert_coords_alloc(me, &numVerts);
|
|
|
|
|
}
|
|
|
|
|
result = mesh_temp;
|
2019-04-29 09:34:20 +02:00
|
|
|
mti->deformVerts(md_eval, &mectx, result, deformedVerts, numVerts);
|
2019-08-22 06:28:35 +10:00
|
|
|
BKE_mesh_vert_coords_apply(result, deformedVerts);
|
2018-06-01 17:05:21 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (build_shapekey_layers) {
|
2018-06-01 17:05:21 +02:00
|
|
|
add_shapekey_layers(result, me);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2021-11-10 00:33:22 +11:00
|
|
|
if (deformedVerts != nullptr) {
|
|
|
|
|
BKE_mesh_vert_coords_apply(mesh_temp, deformedVerts);
|
|
|
|
|
}
|
2018-06-01 17:05:21 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (build_shapekey_layers) {
|
2018-06-01 17:05:21 +02:00
|
|
|
add_shapekey_layers(mesh_temp, me);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-01 17:05:21 +02:00
|
|
|
|
2020-04-21 13:09:41 +02:00
|
|
|
result = mti->modifyMesh(md_eval, &mectx, mesh_temp);
|
2018-06-01 17:05:21 +02:00
|
|
|
ASSERT_IS_VALID_MESH(result);
|
|
|
|
|
|
|
|
|
|
if (mesh_temp != result) {
|
2021-09-16 15:44:43 -05:00
|
|
|
BKE_id_free(nullptr, mesh_temp);
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-10 00:33:22 +11:00
|
|
|
if (deformedVerts != nullptr) {
|
|
|
|
|
MEM_freeN(deformedVerts);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 13:00:28 +01:00
|
|
|
/* This is a Mesh-based copy of the same function in DerivedMesh.cc */
|
2018-06-01 17:05:21 +02:00
|
|
|
static void shapekey_layers_to_keyblocks(Mesh *mesh_src, Mesh *mesh_dst, int actshape_uid)
|
|
|
|
|
{
|
|
|
|
|
KeyBlock *kb;
|
|
|
|
|
int i, j, tot;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!mesh_dst->key) {
|
2018-06-01 17:05:21 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
tot = CustomData_number_of_layers(&mesh_src->vdata, CD_SHAPEKEY);
|
|
|
|
|
for (i = 0; i < tot; i++) {
|
|
|
|
|
CustomDataLayer *layer =
|
|
|
|
|
&mesh_src->vdata.layers[CustomData_get_layer_index_n(&mesh_src->vdata, CD_SHAPEKEY, i)];
|
2022-05-14 18:57:52 +02:00
|
|
|
float(*kbcos)[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
for (kb = (KeyBlock *)mesh_dst->key->block.first; kb; kb = kb->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (kb->uid == layer->uid) {
|
2018-06-01 17:05:21 +02:00
|
|
|
break;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
if (!kb) {
|
|
|
|
|
kb = BKE_keyblock_add(mesh_dst->key, layer->name);
|
|
|
|
|
kb->uid = layer->uid;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (kb->data) {
|
2018-06-01 17:05:21 +02:00
|
|
|
MEM_freeN(kb->data);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-05-14 18:57:52 +02:00
|
|
|
const float(*cos)[3] = (const float(*)[3])CustomData_get_layer_n(
|
|
|
|
|
&mesh_src->vdata, CD_SHAPEKEY, i);
|
2018-06-01 17:05:21 +02:00
|
|
|
kb->totelem = mesh_src->totvert;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
kb->data = kbcos = (float(*)[3])MEM_malloc_arrayN(kb->totelem, sizeof(float[3]), __func__);
|
2018-06-01 17:05:21 +02:00
|
|
|
if (kb->uid == actshape_uid) {
|
|
|
|
|
MVert *mvert = mesh_src->mvert;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
for (j = 0; j < mesh_src->totvert; j++, kbcos++, mvert++) {
|
|
|
|
|
copy_v3_v3(*kbcos, mvert->co);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (j = 0; j < kb->totelem; j++, cos++, kbcos++) {
|
|
|
|
|
copy_v3_v3(*kbcos, *cos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
for (kb = (KeyBlock *)mesh_dst->key->block.first; kb; kb = kb->next) {
|
2018-06-01 17:05:21 +02:00
|
|
|
if (kb->totelem != mesh_src->totvert) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (kb->data) {
|
2018-06-01 17:05:21 +02:00
|
|
|
MEM_freeN(kb->data);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
kb->totelem = mesh_src->totvert;
|
2020-08-08 13:29:21 +10:00
|
|
|
kb->data = MEM_calloc_arrayN(kb->totelem, sizeof(float[3]), __func__);
|
2019-02-01 12:44:19 +11:00
|
|
|
CLOG_ERROR(&LOG, "lost a shapekey layer: '%s'! (bmesh internal error)", kb->name);
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
void BKE_mesh_nomain_to_mesh(Mesh *mesh_src,
|
|
|
|
|
Mesh *mesh_dst,
|
|
|
|
|
Object *ob,
|
|
|
|
|
const CustomData_MeshMasks *mask,
|
|
|
|
|
bool take_ownership)
|
2018-06-01 17:05:21 +02:00
|
|
|
{
|
2020-03-13 17:16:38 +01:00
|
|
|
BLI_assert(mesh_src->id.tag & LIB_TAG_NO_MAIN);
|
|
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
/* mesh_src might depend on mesh_dst, so we need to do everything with a local copy */
|
2019-08-25 13:12:42 +10:00
|
|
|
/* TODO(Sybren): the above claim came from 2.7x derived-mesh code (DM_to_mesh);
|
2019-04-27 12:07:07 +10:00
|
|
|
* check whether it is still true with Mesh */
|
2022-04-12 10:56:51 +02:00
|
|
|
Mesh tmp = blender::dna::shallow_copy(*mesh_dst);
|
2018-06-01 17:05:21 +02:00
|
|
|
int totvert, totedge /*, totface */ /* UNUSED */, totloop, totpoly;
|
2021-04-20 15:28:27 +10:00
|
|
|
bool did_shapekeys = false;
|
2018-06-01 17:05:21 +02:00
|
|
|
eCDAllocType alloctype = CD_DUPLICATE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
if (take_ownership /* && dm->type == DM_TYPE_CDDM && dm->needsFree */) {
|
|
|
|
|
bool has_any_referenced_layers = CustomData_has_referenced(&mesh_src->vdata) ||
|
|
|
|
|
CustomData_has_referenced(&mesh_src->edata) ||
|
|
|
|
|
CustomData_has_referenced(&mesh_src->ldata) ||
|
|
|
|
|
CustomData_has_referenced(&mesh_src->fdata) ||
|
|
|
|
|
CustomData_has_referenced(&mesh_src->pdata);
|
|
|
|
|
if (!has_any_referenced_layers) {
|
|
|
|
|
alloctype = CD_ASSIGN;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
|
|
|
|
CustomData_reset(&tmp.vdata);
|
|
|
|
|
CustomData_reset(&tmp.edata);
|
|
|
|
|
CustomData_reset(&tmp.fdata);
|
|
|
|
|
CustomData_reset(&tmp.ldata);
|
|
|
|
|
CustomData_reset(&tmp.pdata);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
totvert = tmp.totvert = mesh_src->totvert;
|
|
|
|
|
totedge = tmp.totedge = mesh_src->totedge;
|
|
|
|
|
totloop = tmp.totloop = mesh_src->totloop;
|
|
|
|
|
totpoly = tmp.totpoly = mesh_src->totpoly;
|
|
|
|
|
tmp.totface = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
CustomData_copy(&mesh_src->vdata, &tmp.vdata, mask->vmask, alloctype, totvert);
|
|
|
|
|
CustomData_copy(&mesh_src->edata, &tmp.edata, mask->emask, alloctype, totedge);
|
|
|
|
|
CustomData_copy(&mesh_src->ldata, &tmp.ldata, mask->lmask, alloctype, totloop);
|
|
|
|
|
CustomData_copy(&mesh_src->pdata, &tmp.pdata, mask->pmask, alloctype, totpoly);
|
2018-06-01 17:05:21 +02:00
|
|
|
tmp.cd_flag = mesh_src->cd_flag;
|
|
|
|
|
tmp.runtime.deformed_only = mesh_src->runtime.deformed_only;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-02-22 12:43:53 -05:00
|
|
|
/* Clear the normals completely, since the new vertex / polygon count might be different. */
|
|
|
|
|
BKE_mesh_clear_derived_normals(&tmp);
|
Refactor: Move normals out of MVert, lazy calculation
As described in T91186, this commit moves mesh vertex normals into a
contiguous array of float vectors in a custom data layer, how face
normals are currently stored.
The main interface is documented in `BKE_mesh.h`. Vertex and face
normals are now calculated on-demand and cached, retrieved with an
"ensure" function. Since the logical state of a mesh is now "has
normals when necessary", they can be retrieved from a `const` mesh.
The goal is to use on-demand calculation for all derived data, but
leave room for eager calculation for performance purposes (modifier
evaluation is threaded, but viewport data generation is not).
**Benefits**
This moves us closer to a SoA approach rather than the current AoS
paradigm. Accessing a contiguous `float3` is much more efficient than
retrieving data from a larger struct. The memory requirements for
accessing only normals or vertex locations are smaller, and at the
cost of more memory usage for just normals, they now don't have to
be converted between float and short, which also simplifies code
In the future, the remaining items can be removed from `MVert`,
leaving only `float3`, which has similar benefits (see T93602).
Removing the combination of derived and original data makes it
conceptually simpler to only calculate normals when necessary.
This is especially important now that we have more opportunities
for temporary meshes in geometry nodes.
**Performance**
In addition to the theoretical future performance improvements by
making `MVert == float3`, I've done some basic performance testing
on this patch directly. The data is fairly rough, but it gives an idea
about where things stand generally.
- Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms),
showing that accessing just `MVert` is now more efficient.
- Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight
change that at least shows there is no regression.
- Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small
but observable speedup.
- Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms),
shows that using normals in geometry nodes is faster.
- Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms),
shows that calculating normals is slightly faster now.
- File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB),
Normals are not saved in files, which can help with large meshes.
As for memory usage, it may be slightly more in some cases, but
I didn't observe any difference in the production files I tested.
**Tests**
Some modifiers and cycles test results need to be updated with this
commit, for two reasons:
- The subdivision surface modifier is not responsible for calculating
normals anymore. In master, the modifier creates different normals
than the result of the `Mesh` normal calculation, so this is a bug
fix.
- There are small differences in the results of some modifiers that
use normals because they are not converted to and from `short`
anymore.
**Future improvements**
- Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier
already retrieves normals if they are needed anyway.
- Copy normals as part of a better CoW system for attributes.
- Make more areas use lazy instead of eager normal calculation.
- Remove `BKE_mesh_normals_tag_dirty` in more places since that is
now the default state of a new mesh.
- Possibly apply a similar change to derived face corner normals.
Differential Revision: https://developer.blender.org/D12770
2022-01-13 14:37:58 -06:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
if (CustomData_has_layer(&mesh_src->vdata, CD_SHAPEKEY)) {
|
|
|
|
|
KeyBlock *kb;
|
|
|
|
|
int uid;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
if (ob) {
|
2021-09-16 15:44:43 -05:00
|
|
|
kb = (KeyBlock *)BLI_findlink(&mesh_dst->key->block, ob->shapenr - 1);
|
2018-06-01 17:05:21 +02:00
|
|
|
if (kb) {
|
|
|
|
|
uid = kb->uid;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2019-02-01 12:44:19 +11:00
|
|
|
CLOG_ERROR(&LOG, "could not find active shapekey %d!", ob->shapenr - 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
uid = INT_MAX;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* if no object, set to INT_MAX so we don't mess up any shapekey layers */
|
|
|
|
|
uid = INT_MAX;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
shapekey_layers_to_keyblocks(mesh_src, mesh_dst, uid);
|
2021-04-20 15:28:27 +10:00
|
|
|
did_shapekeys = true;
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
/* copy texture space */
|
|
|
|
|
if (ob) {
|
|
|
|
|
BKE_mesh_texspace_copy_from_object(&tmp, ob);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
/* not all DerivedMeshes store their verts/edges/faces in CustomData, so
|
|
|
|
|
* we set them here in case they are missing */
|
2019-04-27 12:07:07 +10:00
|
|
|
/* TODO(Sybren): we could probably replace CD_ASSIGN with alloctype and
|
|
|
|
|
* always directly pass mesh_src->mxxx, instead of using a ternary operator. */
|
2018-06-01 17:05:21 +02:00
|
|
|
if (!CustomData_has_layer(&tmp.vdata, CD_MVERT)) {
|
2018-07-13 08:37:20 +02:00
|
|
|
CustomData_add_layer(&tmp.vdata,
|
|
|
|
|
CD_MVERT,
|
|
|
|
|
CD_ASSIGN,
|
|
|
|
|
(alloctype == CD_ASSIGN) ? mesh_src->mvert :
|
|
|
|
|
MEM_dupallocN(mesh_src->mvert),
|
|
|
|
|
totvert);
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
|
|
|
|
if (!CustomData_has_layer(&tmp.edata, CD_MEDGE)) {
|
2018-07-13 08:37:20 +02:00
|
|
|
CustomData_add_layer(&tmp.edata,
|
|
|
|
|
CD_MEDGE,
|
|
|
|
|
CD_ASSIGN,
|
|
|
|
|
(alloctype == CD_ASSIGN) ? mesh_src->medge :
|
|
|
|
|
MEM_dupallocN(mesh_src->medge),
|
|
|
|
|
totedge);
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
|
|
|
|
if (!CustomData_has_layer(&tmp.pdata, CD_MPOLY)) {
|
2021-04-20 15:28:27 +10:00
|
|
|
CustomData_add_layer(&tmp.ldata,
|
|
|
|
|
CD_MLOOP,
|
|
|
|
|
CD_ASSIGN,
|
|
|
|
|
(alloctype == CD_ASSIGN) ? mesh_src->mloop :
|
|
|
|
|
MEM_dupallocN(mesh_src->mloop),
|
|
|
|
|
tmp.totloop);
|
|
|
|
|
CustomData_add_layer(&tmp.pdata,
|
|
|
|
|
CD_MPOLY,
|
|
|
|
|
CD_ASSIGN,
|
|
|
|
|
(alloctype == CD_ASSIGN) ? mesh_src->mpoly :
|
|
|
|
|
MEM_dupallocN(mesh_src->mpoly),
|
|
|
|
|
tmp.totpoly);
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
/* object had got displacement layer, should copy this layer to save sculpted data */
|
2021-07-05 12:47:46 +10:00
|
|
|
/* NOTE(nazgul): maybe some other layers should be copied? */
|
2018-06-01 17:05:21 +02:00
|
|
|
if (CustomData_has_layer(&mesh_dst->ldata, CD_MDISPS)) {
|
|
|
|
|
if (totloop == mesh_dst->totloop) {
|
2021-09-16 15:44:43 -05:00
|
|
|
MDisps *mdisps = (MDisps *)CustomData_get_layer(&mesh_dst->ldata, CD_MDISPS);
|
2018-06-01 17:05:21 +02:00
|
|
|
CustomData_add_layer(&tmp.ldata, CD_MDISPS, alloctype, mdisps, totloop);
|
2021-04-20 15:10:43 +10:00
|
|
|
if (alloctype == CD_ASSIGN) {
|
2021-09-16 15:44:43 -05:00
|
|
|
/* Assign nullptr to prevent double-free. */
|
|
|
|
|
CustomData_set_layer(&mesh_dst->ldata, CD_MDISPS, nullptr);
|
2021-04-20 15:10:43 +10:00
|
|
|
}
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
/* yes, must be before _and_ after tessellate */
|
|
|
|
|
BKE_mesh_update_customdata_pointers(&tmp, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
CustomData_free(&mesh_dst->vdata, mesh_dst->totvert);
|
|
|
|
|
CustomData_free(&mesh_dst->edata, mesh_dst->totedge);
|
|
|
|
|
CustomData_free(&mesh_dst->fdata, mesh_dst->totface);
|
|
|
|
|
CustomData_free(&mesh_dst->ldata, mesh_dst->totloop);
|
|
|
|
|
CustomData_free(&mesh_dst->pdata, mesh_dst->totpoly);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
/* ok, this should now use new CD shapekey data,
|
|
|
|
|
* which should be fed through the modifier
|
|
|
|
|
* stack */
|
|
|
|
|
if (tmp.totvert != mesh_dst->totvert && !did_shapekeys && mesh_dst->key) {
|
2019-02-01 12:44:19 +11:00
|
|
|
CLOG_ERROR(&LOG, "YEEK! this should be recoded! Shape key loss!: ID '%s'", tmp.id.name);
|
2018-06-01 17:05:21 +02:00
|
|
|
if (tmp.key && !(tmp.id.tag & LIB_TAG_NO_MAIN)) {
|
|
|
|
|
id_us_min(&tmp.key->id);
|
|
|
|
|
}
|
2021-09-16 15:44:43 -05:00
|
|
|
tmp.key = nullptr;
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
/* Clear selection history */
|
|
|
|
|
MEM_SAFE_FREE(tmp.mselect);
|
|
|
|
|
tmp.totselect = 0;
|
2019-09-23 15:31:11 +02:00
|
|
|
tmp.texflag &= ~ME_AUTOSPACE_EVALUATED;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-05 16:10:30 +11:00
|
|
|
/* Clear any run-time data.
|
2021-06-22 10:42:32 -07:00
|
|
|
* Even though this mesh won't typically have run-time data, the Python API can for e.g.
|
2020-11-05 16:10:30 +11:00
|
|
|
* create loop-triangle cache here, which is confusing when left in the mesh, see: T81136. */
|
|
|
|
|
BKE_mesh_runtime_clear_geometry(&tmp);
|
|
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
/* skip the listbase */
|
2019-03-12 16:59:04 +11:00
|
|
|
MEMCPY_STRUCT_AFTER(mesh_dst, &tmp, id.prev);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-08-05 21:10:54 -05:00
|
|
|
BLI_freelistN(&mesh_dst->vertex_group_names);
|
2021-08-05 18:27:07 -05:00
|
|
|
BKE_defgroup_copy_list(&mesh_dst->vertex_group_names, &mesh_src->vertex_group_names);
|
|
|
|
|
mesh_dst->vertex_group_active_index = mesh_src->vertex_group_active_index;
|
|
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
if (take_ownership) {
|
|
|
|
|
if (alloctype == CD_ASSIGN) {
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
CustomData_free_typemask(&mesh_src->vdata, mesh_src->totvert, ~mask->vmask);
|
|
|
|
|
CustomData_free_typemask(&mesh_src->edata, mesh_src->totedge, ~mask->emask);
|
|
|
|
|
CustomData_free_typemask(&mesh_src->ldata, mesh_src->totloop, ~mask->lmask);
|
|
|
|
|
CustomData_free_typemask(&mesh_src->pdata, mesh_src->totpoly, ~mask->pmask);
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
2021-09-16 15:44:43 -05:00
|
|
|
BKE_id_free(nullptr, mesh_src);
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
Refactor: Move normals out of MVert, lazy calculation
As described in T91186, this commit moves mesh vertex normals into a
contiguous array of float vectors in a custom data layer, how face
normals are currently stored.
The main interface is documented in `BKE_mesh.h`. Vertex and face
normals are now calculated on-demand and cached, retrieved with an
"ensure" function. Since the logical state of a mesh is now "has
normals when necessary", they can be retrieved from a `const` mesh.
The goal is to use on-demand calculation for all derived data, but
leave room for eager calculation for performance purposes (modifier
evaluation is threaded, but viewport data generation is not).
**Benefits**
This moves us closer to a SoA approach rather than the current AoS
paradigm. Accessing a contiguous `float3` is much more efficient than
retrieving data from a larger struct. The memory requirements for
accessing only normals or vertex locations are smaller, and at the
cost of more memory usage for just normals, they now don't have to
be converted between float and short, which also simplifies code
In the future, the remaining items can be removed from `MVert`,
leaving only `float3`, which has similar benefits (see T93602).
Removing the combination of derived and original data makes it
conceptually simpler to only calculate normals when necessary.
This is especially important now that we have more opportunities
for temporary meshes in geometry nodes.
**Performance**
In addition to the theoretical future performance improvements by
making `MVert == float3`, I've done some basic performance testing
on this patch directly. The data is fairly rough, but it gives an idea
about where things stand generally.
- Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms),
showing that accessing just `MVert` is now more efficient.
- Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight
change that at least shows there is no regression.
- Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small
but observable speedup.
- Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms),
shows that using normals in geometry nodes is faster.
- Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms),
shows that calculating normals is slightly faster now.
- File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB),
Normals are not saved in files, which can help with large meshes.
As for memory usage, it may be slightly more in some cases, but
I didn't observe any difference in the production files I tested.
**Tests**
Some modifiers and cycles test results need to be updated with this
commit, for two reasons:
- The subdivision surface modifier is not responsible for calculating
normals anymore. In master, the modifier creates different normals
than the result of the `Mesh` normal calculation, so this is a bug
fix.
- There are small differences in the results of some modifiers that
use normals because they are not converted to and from `short`
anymore.
**Future improvements**
- Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier
already retrieves normals if they are needed anyway.
- Copy normals as part of a better CoW system for attributes.
- Make more areas use lazy instead of eager normal calculation.
- Remove `BKE_mesh_normals_tag_dirty` in more places since that is
now the default state of a new mesh.
- Possibly apply a similar change to derived face corner normals.
Differential Revision: https://developer.blender.org/D12770
2022-01-13 14:37:58 -06:00
|
|
|
|
|
|
|
|
BKE_mesh_assert_normals_dirty_or_calculated(mesh_dst);
|
2018-06-01 17:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
2018-06-06 10:30:24 +02:00
|
|
|
void BKE_mesh_nomain_to_meshkey(Mesh *mesh_src, Mesh *mesh_dst, KeyBlock *kb)
|
2018-06-01 17:05:21 +02:00
|
|
|
{
|
2020-03-13 17:16:38 +01:00
|
|
|
BLI_assert(mesh_src->id.tag & LIB_TAG_NO_MAIN);
|
|
|
|
|
|
2018-06-01 17:05:21 +02:00
|
|
|
int a, totvert = mesh_src->totvert;
|
|
|
|
|
float *fp;
|
|
|
|
|
MVert *mvert;
|
|
|
|
|
|
|
|
|
|
if (totvert == 0 || mesh_dst->totvert == 0 || mesh_dst->totvert != totvert) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (kb->data) {
|
2018-06-01 17:05:21 +02:00
|
|
|
MEM_freeN(kb->data);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-01 17:05:21 +02:00
|
|
|
kb->data = MEM_malloc_arrayN(mesh_dst->key->elemsize, mesh_dst->totvert, "kb->data");
|
|
|
|
|
kb->totelem = totvert;
|
|
|
|
|
|
2021-09-16 15:44:43 -05:00
|
|
|
fp = (float *)kb->data;
|
2018-06-01 17:05:21 +02:00
|
|
|
mvert = mesh_src->mvert;
|
|
|
|
|
|
|
|
|
|
for (a = 0; a < kb->totelem; a++, fp += 3, mvert++) {
|
|
|
|
|
copy_v3_v3(fp, mvert->co);
|
|
|
|
|
}
|
|
|
|
|
}
|