Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/DerivedMesh.cc')
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.cc239
1 files changed, 82 insertions, 157 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc
index a29d8726f21..11ef2b08df4 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -35,6 +35,7 @@
#include "BKE_colorband.h"
#include "BKE_deform.h"
#include "BKE_editmesh.h"
+#include "BKE_editmesh_cache.h"
#include "BKE_geometry_set.hh"
#include "BKE_geometry_set_instances.hh"
#include "BKE_key.h"
@@ -68,6 +69,8 @@
using blender::float3;
using blender::IndexRange;
+using blender::Span;
+using blender::VArray;
/* very slow! enable for testing only! */
//#define USE_MODIFIER_VALIDATE
@@ -95,7 +98,7 @@ static MVert *dm_getVertArray(DerivedMesh *dm)
if (!mvert) {
mvert = (MVert *)CustomData_add_layer(
- &dm->vertData, CD_MVERT, CD_CALLOC, nullptr, dm->getNumVerts(dm));
+ &dm->vertData, CD_MVERT, CD_SET_DEFAULT, nullptr, dm->getNumVerts(dm));
CustomData_set_layer_flag(&dm->vertData, CD_MVERT, CD_FLAG_TEMPORARY);
dm->copyVertArray(dm, mvert);
}
@@ -109,7 +112,7 @@ static MEdge *dm_getEdgeArray(DerivedMesh *dm)
if (!medge) {
medge = (MEdge *)CustomData_add_layer(
- &dm->edgeData, CD_MEDGE, CD_CALLOC, nullptr, dm->getNumEdges(dm));
+ &dm->edgeData, CD_MEDGE, CD_SET_DEFAULT, nullptr, dm->getNumEdges(dm));
CustomData_set_layer_flag(&dm->edgeData, CD_MEDGE, CD_FLAG_TEMPORARY);
dm->copyEdgeArray(dm, medge);
}
@@ -123,7 +126,7 @@ static MLoop *dm_getLoopArray(DerivedMesh *dm)
if (!mloop) {
mloop = (MLoop *)CustomData_add_layer(
- &dm->loopData, CD_MLOOP, CD_CALLOC, nullptr, dm->getNumLoops(dm));
+ &dm->loopData, CD_MLOOP, CD_SET_DEFAULT, nullptr, dm->getNumLoops(dm));
CustomData_set_layer_flag(&dm->loopData, CD_MLOOP, CD_FLAG_TEMPORARY);
dm->copyLoopArray(dm, mloop);
}
@@ -137,7 +140,7 @@ static MPoly *dm_getPolyArray(DerivedMesh *dm)
if (!mpoly) {
mpoly = (MPoly *)CustomData_add_layer(
- &dm->polyData, CD_MPOLY, CD_CALLOC, nullptr, dm->getNumPolys(dm));
+ &dm->polyData, CD_MPOLY, CD_SET_DEFAULT, nullptr, dm->getNumPolys(dm));
CustomData_set_layer_flag(&dm->polyData, CD_MPOLY, CD_FLAG_TEMPORARY);
dm->copyPolyArray(dm, mpoly);
}
@@ -145,54 +148,6 @@ static MPoly *dm_getPolyArray(DerivedMesh *dm)
return mpoly;
}
-static MVert *dm_dupVertArray(DerivedMesh *dm)
-{
- MVert *tmp = (MVert *)MEM_malloc_arrayN(
- dm->getNumVerts(dm), sizeof(*tmp), "dm_dupVertArray tmp");
-
- if (tmp) {
- dm->copyVertArray(dm, tmp);
- }
-
- return tmp;
-}
-
-static MEdge *dm_dupEdgeArray(DerivedMesh *dm)
-{
- MEdge *tmp = (MEdge *)MEM_malloc_arrayN(
- dm->getNumEdges(dm), sizeof(*tmp), "dm_dupEdgeArray tmp");
-
- if (tmp) {
- dm->copyEdgeArray(dm, tmp);
- }
-
- return tmp;
-}
-
-static MLoop *dm_dupLoopArray(DerivedMesh *dm)
-{
- MLoop *tmp = (MLoop *)MEM_malloc_arrayN(
- dm->getNumLoops(dm), sizeof(*tmp), "dm_dupLoopArray tmp");
-
- if (tmp) {
- dm->copyLoopArray(dm, tmp);
- }
-
- return tmp;
-}
-
-static MPoly *dm_dupPolyArray(DerivedMesh *dm)
-{
- MPoly *tmp = (MPoly *)MEM_malloc_arrayN(
- dm->getNumPolys(dm), sizeof(*tmp), "dm_dupPolyArray tmp");
-
- if (tmp) {
- dm->copyPolyArray(dm, tmp);
- }
-
- return tmp;
-}
-
static int dm_getNumLoopTri(DerivedMesh *dm)
{
const int numlooptris = poly_to_tri_count(dm->getNumPolys(dm), dm->getNumLoops(dm));
@@ -231,14 +186,10 @@ void DM_init_funcs(DerivedMesh *dm)
dm->getEdgeArray = dm_getEdgeArray;
dm->getLoopArray = dm_getLoopArray;
dm->getPolyArray = dm_getPolyArray;
- dm->dupVertArray = dm_dupVertArray;
- dm->dupEdgeArray = dm_dupEdgeArray;
- dm->dupLoopArray = dm_dupLoopArray;
- dm->dupPolyArray = dm_dupPolyArray;
dm->getLoopTriArray = dm_getLoopTriArray;
- /* subtypes handle getting actual data */
+ /* Sub-types handle getting actual data. */
dm->getNumLoopTri = dm_getNumLoopTri;
dm->getVertDataArray = DM_get_vert_data_layer;
@@ -284,13 +235,11 @@ void DM_from_template(DerivedMesh *dm,
int numPolys)
{
const CustomData_MeshMasks *mask = &CD_MASK_DERIVEDMESH;
- CustomData_copy(&source->vertData, &dm->vertData, mask->vmask, CD_CALLOC, numVerts);
- CustomData_copy(&source->edgeData, &dm->edgeData, mask->emask, CD_CALLOC, numEdges);
- CustomData_copy(&source->faceData, &dm->faceData, mask->fmask, CD_CALLOC, numTessFaces);
- CustomData_copy(&source->loopData, &dm->loopData, mask->lmask, CD_CALLOC, numLoops);
- CustomData_copy(&source->polyData, &dm->polyData, mask->pmask, CD_CALLOC, numPolys);
-
- dm->cd_flag = source->cd_flag;
+ CustomData_copy(&source->vertData, &dm->vertData, mask->vmask, CD_SET_DEFAULT, numVerts);
+ CustomData_copy(&source->edgeData, &dm->edgeData, mask->emask, CD_SET_DEFAULT, numEdges);
+ CustomData_copy(&source->faceData, &dm->faceData, mask->fmask, CD_SET_DEFAULT, numTessFaces);
+ CustomData_copy(&source->loopData, &dm->loopData, mask->lmask, CD_SET_DEFAULT, numLoops);
+ CustomData_copy(&source->polyData, &dm->polyData, mask->pmask, CD_SET_DEFAULT, numPolys);
dm->type = type;
dm->numVertData = numVerts;
@@ -329,40 +278,10 @@ bool DM_release(DerivedMesh *dm)
return false;
}
-void DM_DupPolys(DerivedMesh *source, DerivedMesh *target)
-{
- CustomData_free(&target->loopData, source->numLoopData);
- CustomData_free(&target->polyData, source->numPolyData);
-
- CustomData_copy(&source->loopData,
- &target->loopData,
- CD_MASK_DERIVEDMESH.lmask,
- CD_DUPLICATE,
- source->numLoopData);
- CustomData_copy(&source->polyData,
- &target->polyData,
- CD_MASK_DERIVEDMESH.pmask,
- CD_DUPLICATE,
- source->numPolyData);
-
- target->numLoopData = source->numLoopData;
- target->numPolyData = source->numPolyData;
-
- if (!CustomData_has_layer(&target->polyData, CD_MPOLY)) {
- MPoly *mpoly;
- MLoop *mloop;
-
- mloop = source->dupLoopArray(source);
- mpoly = source->dupPolyArray(source);
- CustomData_add_layer(&target->loopData, CD_MLOOP, CD_ASSIGN, mloop, source->numLoopData);
- CustomData_add_layer(&target->polyData, CD_MPOLY, CD_ASSIGN, mpoly, source->numPolyData);
- }
-}
-
void DM_ensure_looptri_data(DerivedMesh *dm)
{
- const unsigned int totpoly = dm->numPolyData;
- const unsigned int totloop = dm->numLoopData;
+ const uint totpoly = dm->numPolyData;
+ const uint totloop = dm->numLoopData;
const int looptris_num = poly_to_tri_count(totpoly, totloop);
BLI_assert(dm->looptris.array_wip == nullptr);
@@ -584,8 +503,7 @@ static void add_orco_mesh(Object *ob, BMEditMesh *em, Mesh *mesh, Mesh *mesh_orc
}
if (!(layerorco = (float(*)[3])CustomData_get_layer(&mesh->vdata, layer))) {
- CustomData_add_layer(&mesh->vdata, layer, CD_CALLOC, nullptr, mesh->totvert);
- BKE_mesh_update_customdata_pointers(mesh, false);
+ CustomData_add_layer(&mesh->vdata, layer, CD_SET_DEFAULT, nullptr, mesh->totvert);
layerorco = (float(*)[3])CustomData_get_layer(&mesh->vdata, layer);
}
@@ -620,7 +538,7 @@ static void mesh_calc_modifier_final_normals(const Mesh *mesh_input,
(final_datamask->lmask & CD_MASK_NORMAL) != 0);
/* Needed as `final_datamask` is not preserved outside modifier stack evaluation. */
- SubsurfRuntimeData *subsurf_runtime_data = mesh_final->runtime.subsurf_runtime_data;
+ SubsurfRuntimeData *subsurf_runtime_data = mesh_final->runtime->subsurf_runtime_data;
if (subsurf_runtime_data) {
subsurf_runtime_data->calc_loop_normals = calc_loop_normals;
}
@@ -668,11 +586,12 @@ static void mesh_calc_finalize(const Mesh *mesh_input, Mesh *mesh_eval)
void BKE_mesh_wrapper_deferred_finalize_mdata(Mesh *me_eval,
const CustomData_MeshMasks *cd_mask_finalize)
{
- if (me_eval->runtime.wrapper_type_finalize & (1 << ME_WRAPPER_TYPE_BMESH)) {
+ if (me_eval->runtime->wrapper_type_finalize & (1 << ME_WRAPPER_TYPE_BMESH)) {
editbmesh_calc_modifier_final_normals(me_eval, cd_mask_finalize);
- me_eval->runtime.wrapper_type_finalize &= ~(1 << ME_WRAPPER_TYPE_BMESH);
+ me_eval->runtime->wrapper_type_finalize = eMeshWrapperType(
+ me_eval->runtime->wrapper_type_finalize & ~(1 << ME_WRAPPER_TYPE_BMESH));
}
- BLI_assert(me_eval->runtime.wrapper_type_finalize == 0);
+ BLI_assert(me_eval->runtime->wrapper_type_finalize == 0);
}
/**
@@ -741,6 +660,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
Mesh **r_final,
GeometrySet **r_geometry_set)
{
+ using namespace blender::bke;
/* Input and final mesh. Final mesh is only created the moment the first
* constructive modifier is executed, or a deform modifier needs normals
* or certain data layers. */
@@ -811,7 +731,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
* subdividing them is expensive. */
CustomData_MeshMasks final_datamask = *dataMask;
CDMaskLink *datamasks = BKE_modifier_calc_data_masks(
- scene, ob, md, &final_datamask, required_mode, previewmd, &previewmask);
+ scene, md, &final_datamask, required_mode, previewmd, &previewmask);
CDMaskLink *md_datamask = datamasks;
/* XXX Always copying POLYINDEX, else tessellated data are no more valid! */
CustomData_MeshMasks append_mask = CD_MASK_BAREMESH_ORIGINDEX;
@@ -824,18 +744,13 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
mesh_final = BKE_mesh_copy_for_eval(mesh_input, true);
ASSERT_IS_VALID_MESH(mesh_final);
}
- float3 *rest_positions = static_cast<float3 *>(CustomData_add_layer_named(&mesh_final->vdata,
- CD_PROP_FLOAT3,
- CD_DEFAULT,
- nullptr,
- mesh_final->totvert,
- "rest_position"));
- blender::threading::parallel_for(
- IndexRange(mesh_final->totvert), 1024, [&](const IndexRange range) {
- for (const int i : range) {
- rest_positions[i] = mesh_final->mvert[i].co;
- }
- });
+ MutableAttributeAccessor attributes = mesh_final->attributes_for_write();
+ SpanAttributeWriter<float3> rest_positions =
+ attributes.lookup_or_add_for_write_only_span<float3>("rest_position", ATTR_DOMAIN_POINT);
+ if (rest_positions) {
+ attributes.lookup<float3>("position").materialize(rest_positions.span);
+ rest_positions.finish();
+ }
}
/* Apply all leading deform modifiers. */
@@ -937,7 +852,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
/* Add orco mesh as layer if needed by this modifier. */
if (mesh_final && mesh_orco && mti->requiredDataMask) {
CustomData_MeshMasks mask = {0};
- mti->requiredDataMask(ob, md, &mask);
+ mti->requiredDataMask(md, &mask);
if (mask.vmask & CD_MASK_ORCO) {
add_orco_mesh(ob, nullptr, mesh_final, mesh_orco, CD_ORCO);
}
@@ -1007,11 +922,11 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
((nextmask.vmask | nextmask.emask | nextmask.pmask) & CD_MASK_ORIGINDEX)) {
/* calc */
CustomData_add_layer(
- &mesh_final->vdata, CD_ORIGINDEX, CD_CALLOC, nullptr, mesh_final->totvert);
+ &mesh_final->vdata, CD_ORIGINDEX, CD_CONSTRUCT, nullptr, mesh_final->totvert);
CustomData_add_layer(
- &mesh_final->edata, CD_ORIGINDEX, CD_CALLOC, nullptr, mesh_final->totedge);
+ &mesh_final->edata, CD_ORIGINDEX, CD_CONSTRUCT, nullptr, mesh_final->totedge);
CustomData_add_layer(
- &mesh_final->pdata, CD_ORIGINDEX, CD_CALLOC, nullptr, mesh_final->totpoly);
+ &mesh_final->pdata, CD_ORIGINDEX, CD_CONSTRUCT, nullptr, mesh_final->totpoly);
/* Not worth parallelizing this,
* gives less than 0.1% overall speedup in best of best cases... */
@@ -1047,8 +962,11 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
/* add an origspace layer if needed */
if ((md_datamask->mask.lmask) & CD_MASK_ORIGSPACE_MLOOP) {
if (!CustomData_has_layer(&mesh_final->ldata, CD_ORIGSPACE_MLOOP)) {
- CustomData_add_layer(
- &mesh_final->ldata, CD_ORIGSPACE_MLOOP, CD_CALLOC, nullptr, mesh_final->totloop);
+ CustomData_add_layer(&mesh_final->ldata,
+ CD_ORIGSPACE_MLOOP,
+ CD_SET_DEFAULT,
+ nullptr,
+ mesh_final->totloop);
mesh_init_origspace(mesh_final);
}
}
@@ -1085,7 +1003,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
temp_cddata_masks.pmask = CD_MASK_ORIGINDEX;
if (mti->requiredDataMask != nullptr) {
- mti->requiredDataMask(ob, md, &temp_cddata_masks);
+ mti->requiredDataMask(md, &temp_cddata_masks);
}
CustomData_MeshMasks_update(&temp_cddata_masks, &nextmask);
mesh_set_only_copy(mesh_orco, &temp_cddata_masks);
@@ -1136,7 +1054,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
append_mask.lmask |= CD_MASK_PREVIEW_MLOOPCOL;
}
- mesh_final->runtime.deformed_only = false;
+ mesh_final->runtime->deformed_only = false;
}
isPrevDeform = (mti->type == eModifierTypeType_OnlyDeform);
@@ -1203,10 +1121,9 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
mesh_calc_finalize(mesh_input, mesh_final);
}
else {
- Mesh_Runtime *runtime = &mesh_input->runtime;
+ blender::bke::MeshRuntime *runtime = mesh_input->runtime;
if (runtime->mesh_eval == nullptr) {
- BLI_assert(runtime->eval_mutex != nullptr);
- BLI_mutex_lock((ThreadMutex *)runtime->eval_mutex);
+ std::lock_guard lock{mesh_input->runtime->eval_mutex};
if (runtime->mesh_eval == nullptr) {
/* Not yet finalized by any instance, do it now
* Isolate since computing normals is multithreaded and we are holding a lock. */
@@ -1222,7 +1139,6 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
/* Already finalized by another instance, reuse. */
mesh_final = runtime->mesh_eval;
}
- BLI_mutex_unlock((ThreadMutex *)runtime->eval_mutex);
}
else if (!mesh_has_modifier_final_normals(mesh_input, &final_datamask, runtime->mesh_eval)) {
/* Modifier stack was (re-)evaluated with a request for additional normals
@@ -1291,7 +1207,7 @@ static void editbmesh_calc_modifier_final_normals(Mesh *mesh_final,
const bool calc_loop_normals = ((mesh_final->flag & ME_AUTOSMOOTH) != 0 ||
(final_datamask->lmask & CD_MASK_NORMAL) != 0);
- SubsurfRuntimeData *subsurf_runtime_data = mesh_final->runtime.subsurf_runtime_data;
+ SubsurfRuntimeData *subsurf_runtime_data = mesh_final->runtime->subsurf_runtime_data;
if (subsurf_runtime_data) {
subsurf_runtime_data->calc_loop_normals = calc_loop_normals;
}
@@ -1318,9 +1234,10 @@ static void editbmesh_calc_modifier_final_normals(Mesh *mesh_final,
static void editbmesh_calc_modifier_final_normals_or_defer(
Mesh *mesh_final, const CustomData_MeshMasks *final_datamask)
{
- if (mesh_final->runtime.wrapper_type != ME_WRAPPER_TYPE_MDATA) {
+ if (mesh_final->runtime->wrapper_type != ME_WRAPPER_TYPE_MDATA) {
/* Generated at draw time. */
- mesh_final->runtime.wrapper_type_finalize = (1 << mesh_final->runtime.wrapper_type);
+ mesh_final->runtime->wrapper_type_finalize = eMeshWrapperType(
+ 1 << mesh_final->runtime->wrapper_type);
return;
}
@@ -1380,7 +1297,7 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
* subdividing them is expensive. */
CustomData_MeshMasks final_datamask = *dataMask;
CDMaskLink *datamasks = BKE_modifier_calc_data_masks(
- scene, ob, md, &final_datamask, required_mode, nullptr, nullptr);
+ scene, md, &final_datamask, required_mode, nullptr, nullptr);
CDMaskLink *md_datamask = datamasks;
CustomData_MeshMasks append_mask = CD_MASK_BAREMESH;
@@ -1410,7 +1327,7 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
/* Add an orco mesh as layer if needed by this modifier. */
if (mesh_final && mesh_orco && mti->requiredDataMask) {
CustomData_MeshMasks mask = {0};
- mti->requiredDataMask(ob, md, &mask);
+ mti->requiredDataMask(md, &mask);
if (mask.vmask & CD_MASK_ORCO) {
add_orco_mesh(ob, em_input, mesh_final, mesh_orco, CD_ORCO);
}
@@ -1510,8 +1427,11 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
if (mask.lmask & CD_MASK_ORIGSPACE_MLOOP) {
if (!CustomData_has_layer(&mesh_final->ldata, CD_ORIGSPACE_MLOOP)) {
- CustomData_add_layer(
- &mesh_final->ldata, CD_ORIGSPACE_MLOOP, CD_CALLOC, nullptr, mesh_final->totloop);
+ CustomData_add_layer(&mesh_final->ldata,
+ CD_ORIGSPACE_MLOOP,
+ CD_SET_DEFAULT,
+ nullptr,
+ mesh_final->totloop);
mesh_init_origspace(mesh_final);
}
}
@@ -1531,7 +1451,7 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
deformed_verts = nullptr;
}
}
- mesh_final->runtime.deformed_only = false;
+ mesh_final->runtime->deformed_only = false;
}
if (r_cage && i == cageIndex) {
@@ -1550,7 +1470,8 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
if (!BKE_mesh_runtime_ensure_edit_data(me_orig)) {
BKE_mesh_runtime_reset_edit_data(me_orig);
}
- me_orig->runtime.edit_data->vertexCos = (const float(*)[3])MEM_dupallocN(deformed_verts);
+ me_orig->runtime->edit_data->vertexCos = (const float(*)[3])MEM_dupallocN(
+ deformed_verts);
}
mesh_cage = BKE_mesh_wrapper_from_editmesh_with_coords(
em_input,
@@ -1570,11 +1491,9 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
* then we need to build one. */
if (mesh_final) {
if (deformed_verts) {
- Mesh *mesh_tmp = BKE_mesh_copy_for_eval(mesh_final, false);
- if (mesh_final != mesh_cage) {
- BKE_id_free(nullptr, mesh_final);
+ if (mesh_final == mesh_cage) {
+ mesh_final = BKE_mesh_copy_for_eval(mesh_final, false);
}
- mesh_final = mesh_tmp;
BKE_mesh_vert_coords_apply(mesh_final, deformed_verts);
}
}
@@ -1595,7 +1514,7 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
/* Add orco coordinates to final and deformed mesh if requested. */
if (final_datamask.vmask & CD_MASK_ORCO) {
- /* FIXME(Campbell): avoid the need to convert to mesh data just to add an orco layer. */
+ /* FIXME(@campbellbarton): avoid the need to convert to mesh data just to add an orco layer. */
BKE_mesh_wrapper_ensure_mdata(mesh_final);
add_orco_mesh(ob, em_input, mesh_final, mesh_orco, CD_ORCO);
@@ -1666,7 +1585,7 @@ static void mesh_build_data(struct Depsgraph *depsgraph,
* object's runtime: this could cause access freed data on depsgraph destruction (mesh who owns
* the final result might be freed prior to object). */
Mesh *mesh = (Mesh *)ob->data;
- const bool is_mesh_eval_owned = (mesh_eval != mesh->runtime.mesh_eval);
+ const bool is_mesh_eval_owned = (mesh_eval != mesh->runtime->mesh_eval);
BKE_object_eval_assign_data(ob, &mesh_eval->id, is_mesh_eval_owned);
/* Add the final mesh as a non-owning component to the geometry set. */
@@ -1726,7 +1645,7 @@ static void editbmesh_build_data(struct Depsgraph *depsgraph,
}
}
- const bool is_mesh_eval_owned = (me_final != mesh->runtime.mesh_eval);
+ const bool is_mesh_eval_owned = (me_final != mesh->runtime->mesh_eval);
BKE_object_eval_assign_data(obedit, &me_final->id, is_mesh_eval_owned);
obedit->runtime.editmesh_eval_cage = me_cage;
@@ -1743,6 +1662,7 @@ static void object_get_datamask(const Depsgraph *depsgraph,
CustomData_MeshMasks *r_mask,
bool *r_need_mapping)
{
+ Scene *scene = DEG_get_evaluated_scene(depsgraph);
ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
DEG_get_customdata_mask_for_object(depsgraph, ob, r_mask);
@@ -1757,8 +1677,11 @@ static void object_get_datamask(const Depsgraph *depsgraph,
return;
}
- Object *actob = view_layer->basact ? DEG_get_original_object(view_layer->basact->object) :
- nullptr;
+ BKE_view_layer_synced_ensure(scene, view_layer);
+ Object *actob = BKE_view_layer_active_object_get(view_layer);
+ if (actob) {
+ actob = DEG_get_original_object(actob);
+ }
if (DEG_get_original_object(ob) == actob) {
bool editing = BKE_paint_select_face_test(actob);
@@ -1801,7 +1724,7 @@ void makeDerivedMesh(struct Depsgraph *depsgraph,
BKE_object_free_derived_caches(ob);
if (DEG_is_active(depsgraph)) {
- BKE_sculpt_update_object_before_eval(scene, ob);
+ BKE_sculpt_update_object_before_eval(ob);
}
/* NOTE: Access the `edit_mesh` after freeing the derived caches, so that `ob->data` is restored
@@ -1978,7 +1901,7 @@ struct MappedUserData {
static void make_vertexcos__mapFunc(void *userData,
int index,
const float co[3],
- const float UNUSED(no[3]))
+ const float /*no*/[3])
{
MappedUserData *mappedData = (MappedUserData *)userData;
@@ -1993,7 +1916,7 @@ static void make_vertexcos__mapFunc(void *userData,
void mesh_get_mapped_verts_coords(Mesh *me_eval, float (*r_cos)[3], const int totcos)
{
- if (me_eval->runtime.deformed_only == false) {
+ if (me_eval->runtime->deformed_only == false) {
MappedUserData userData;
memset(r_cos, 0, sizeof(*r_cos) * totcos);
userData.vertexcos = r_cos;
@@ -2002,9 +1925,9 @@ void mesh_get_mapped_verts_coords(Mesh *me_eval, float (*r_cos)[3], const int to
MEM_freeN(userData.vertex_visit);
}
else {
- MVert *mv = me_eval->mvert;
- for (int i = 0; i < totcos; i++, mv++) {
- copy_v3_v3(r_cos[i], mv->co);
+ const Span<MVert> verts = me_eval->verts();
+ for (int i = 0; i < totcos; i++) {
+ copy_v3_v3(r_cos[i], verts[i].co);
}
}
}
@@ -2017,9 +1940,11 @@ static void mesh_init_origspace(Mesh *mesh)
CD_ORIGSPACE_MLOOP);
const int numpoly = mesh->totpoly;
// const int numloop = mesh->totloop;
- MVert *mv = mesh->mvert;
- MLoop *ml = mesh->mloop;
- MPoly *mp = mesh->mpoly;
+ const Span<MVert> verts = mesh->verts();
+ const Span<MPoly> polys = mesh->polys();
+ const Span<MLoop> loops = mesh->loops();
+
+ const MPoly *mp = polys.data();
int i, j, k;
blender::Vector<blender::float2, 64> vcos_2d;
@@ -2033,19 +1958,19 @@ static void mesh_init_origspace(Mesh *mesh)
}
}
else {
- MLoop *l = &ml[mp->loopstart];
+ const MLoop *l = &loops[mp->loopstart];
float p_nor[3], co[3];
float mat[3][3];
float min[2] = {FLT_MAX, FLT_MAX}, max[2] = {-FLT_MAX, -FLT_MAX};
float translate[2], scale[2];
- BKE_mesh_calc_poly_normal(mp, l, mv, p_nor);
+ BKE_mesh_calc_poly_normal(mp, l, verts.data(), p_nor);
axis_dominant_v3_to_m3(mat, p_nor);
vcos_2d.resize(mp->totloop);
for (j = 0; j < mp->totloop; j++, l++) {
- mul_v3_m3v3(co, mat, mv[l->v].co);
+ mul_v3_m3v3(co, mat, verts[l->v].co);
copy_v2_v2(vcos_2d[j], co);
for (k = 0; k < 2; k++) {