Cleanup: Use const when retrieving custom data layers

Knowing when layers are retrieved for write access will be essential
when adding proper copy-on-write support. This commit makes that
clearer by adding `const` where the retrieved data is not modified.

Ref T95842
This commit is contained in:
2022-05-13 18:31:29 +02:00
parent fa7224d8ed
commit cf69652618
50 changed files with 188 additions and 200 deletions

View File

@@ -228,35 +228,38 @@ void BKE_defvert_normalize_lock_map(struct MDeformVert *dvert,
/* Utilities to 'extract' a given vgroup into a simple float array,
* for verts, but also edges/polys/loops. */
void BKE_defvert_extract_vgroup_to_vertweights(
struct MDeformVert *dvert, int defgroup, int num_verts, float *r_weights, bool invert_vgroup);
void BKE_defvert_extract_vgroup_to_vertweights(const struct MDeformVert *dvert,
int defgroup,
int num_verts,
bool invert_vgroup,
float *r_weights);
/**
* The following three make basic interpolation,
* using temp vert_weights array to avoid looking up same weight several times.
*/
void BKE_defvert_extract_vgroup_to_edgeweights(struct MDeformVert *dvert,
void BKE_defvert_extract_vgroup_to_edgeweights(const struct MDeformVert *dvert,
int defgroup,
int num_verts,
struct MEdge *edges,
int num_edges,
float *r_weights,
bool invert_vgroup);
void BKE_defvert_extract_vgroup_to_loopweights(struct MDeformVert *dvert,
bool invert_vgroup,
float *r_weights);
void BKE_defvert_extract_vgroup_to_loopweights(const struct MDeformVert *dvert,
int defgroup,
int num_verts,
struct MLoop *loops,
int num_loops,
float *r_weights,
bool invert_vgroup);
void BKE_defvert_extract_vgroup_to_polyweights(struct MDeformVert *dvert,
bool invert_vgroup,
float *r_weights);
void BKE_defvert_extract_vgroup_to_polyweights(const struct MDeformVert *dvert,
int defgroup,
int num_verts,
struct MLoop *loops,
int num_loops,
struct MPoly *polys,
int num_polys,
float *r_weights,
bool invert_vgroup);
bool invert_vgroup,
float *r_weights);
void BKE_defvert_weight_to_rgb(float r_rgb[3], float weight);

View File

@@ -583,7 +583,7 @@ void psys_interpolate_face(struct Mesh *mesh,
const float (*vert_normals)[3],
struct MFace *mface,
struct MTFace *tface,
float (*orcodata)[3],
const float (*orcodata)[3],
float w[4],
float vec[3],
float nor[3],

View File

@@ -73,7 +73,7 @@ typedef struct ShrinkwrapTreeData {
BVHTreeFromMesh treeData;
const float (*pnors)[3];
float (*clnors)[3];
const float (*clnors)[3];
ShrinkwrapBoundaryData *boundary;
} ShrinkwrapTreeData;

View File

@@ -715,7 +715,7 @@ static bool cloth_from_object(
int i = 0;
MVert *mvert = NULL;
ClothVertex *verts = NULL;
float(*shapekey_rest)[3] = NULL;
const float(*shapekey_rest)[3] = NULL;
const float tnull[3] = {0, 0, 0};
/* If we have a clothObject, free it. */

View File

@@ -477,7 +477,7 @@ static void data_transfer_layersmapping_add_item_cd(ListBase *r_map,
const int mix_mode,
const float mix_factor,
const float *mix_weights,
void *data_src,
const void *data_src,
void *data_dst,
cd_datatransfer_interp interp,
void *interp_data)
@@ -532,7 +532,8 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(ListBase *r_map
cd_datatransfer_interp interp,
void *interp_data)
{
void *data_src, *data_dst = NULL;
const void *data_src;
void *data_dst = NULL;
int idx_src = num_layers_src;
int idx_dst, tot_dst = CustomData_number_of_layers(cd_dst, cddata_type);
bool *data_dst_to_delete = NULL;
@@ -695,7 +696,8 @@ static bool data_transfer_layersmapping_cdlayers(ListBase *r_map,
void *interp_data)
{
int idx_src, idx_dst;
void *data_src, *data_dst = NULL;
const void *data_src;
void *data_dst = NULL;
if (CustomData_layertype_is_singleton(cddata_type)) {
if (!(data_src = CustomData_get_layer(cd_src, cddata_type))) {
@@ -1369,7 +1371,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
/* Assumed always true if not using an evaluated mesh as destination. */
bool dirty_nors_dst = true;
MDeformVert *mdef = NULL;
const MDeformVert *mdef = NULL;
int vg_idx = -1;
float *weights[DATAMAX] = {NULL};
@@ -1509,7 +1511,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
if (mdef && vg_idx != -1 && !weights[VDATA]) {
weights[VDATA] = MEM_mallocN(sizeof(*(weights[VDATA])) * (size_t)num_verts_dst, __func__);
BKE_defvert_extract_vgroup_to_vertweights(
mdef, vg_idx, num_verts_dst, weights[VDATA], invert_vgroup);
mdef, vg_idx, num_verts_dst, invert_vgroup, weights[VDATA]);
}
if (data_transfer_layersmapping_generate(&lay_map,
@@ -1588,7 +1590,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
if (mdef && vg_idx != -1 && !weights[EDATA]) {
weights[EDATA] = MEM_mallocN(sizeof(*weights[EDATA]) * (size_t)num_edges_dst, __func__);
BKE_defvert_extract_vgroup_to_edgeweights(
mdef, vg_idx, num_verts_dst, edges_dst, num_edges_dst, weights[EDATA], invert_vgroup);
mdef, vg_idx, num_verts_dst, edges_dst, num_edges_dst, invert_vgroup, weights[EDATA]);
}
if (data_transfer_layersmapping_generate(&lay_map,
@@ -1683,7 +1685,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
if (mdef && vg_idx != -1 && !weights[LDATA]) {
weights[LDATA] = MEM_mallocN(sizeof(*weights[LDATA]) * (size_t)num_loops_dst, __func__);
BKE_defvert_extract_vgroup_to_loopweights(
mdef, vg_idx, num_verts_dst, loops_dst, num_loops_dst, weights[LDATA], invert_vgroup);
mdef, vg_idx, num_verts_dst, loops_dst, num_loops_dst, invert_vgroup, weights[LDATA]);
}
if (data_transfer_layersmapping_generate(&lay_map,
@@ -1769,8 +1771,8 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
num_loops_dst,
polys_dst,
num_polys_dst,
weights[PDATA],
invert_vgroup);
invert_vgroup,
weights[PDATA]);
}
if (data_transfer_layersmapping_generate(&lay_map,

View File

@@ -147,9 +147,9 @@ void BKE_defvert_copy_index(MDeformVert *dvert_dst,
const MDeformVert *dvert_src,
const int defgroup_src)
{
MDeformWeight *dw_src, *dw_dst;
MDeformWeight *dw_dst;
dw_src = BKE_defvert_find_index(dvert_src, defgroup_src);
const MDeformWeight *dw_src = BKE_defvert_find_index(dvert_src, defgroup_src);
if (dw_src) {
/* Source is valid, ensure destination is created. */
@@ -1008,11 +1008,11 @@ void BKE_defvert_array_free(MDeformVert *dvert, int totvert)
MEM_freeN(dvert);
}
void BKE_defvert_extract_vgroup_to_vertweights(MDeformVert *dvert,
void BKE_defvert_extract_vgroup_to_vertweights(const MDeformVert *dvert,
const int defgroup,
const int num_verts,
float *r_weights,
const bool invert_vgroup)
const bool invert_vgroup,
float *r_weights)
{
if (dvert && defgroup != -1) {
int i = num_verts;
@@ -1027,20 +1027,20 @@ void BKE_defvert_extract_vgroup_to_vertweights(MDeformVert *dvert,
}
}
void BKE_defvert_extract_vgroup_to_edgeweights(MDeformVert *dvert,
void BKE_defvert_extract_vgroup_to_edgeweights(const MDeformVert *dvert,
const int defgroup,
const int num_verts,
MEdge *edges,
const int num_edges,
float *r_weights,
const bool invert_vgroup)
const bool invert_vgroup,
float *r_weights)
{
if (dvert && defgroup != -1) {
int i = num_edges;
float *tmp_weights = MEM_mallocN(sizeof(*tmp_weights) * (size_t)num_verts, __func__);
BKE_defvert_extract_vgroup_to_vertweights(
dvert, defgroup, num_verts, tmp_weights, invert_vgroup);
dvert, defgroup, num_verts, invert_vgroup, tmp_weights);
while (i--) {
MEdge *me = &edges[i];
@@ -1055,20 +1055,20 @@ void BKE_defvert_extract_vgroup_to_edgeweights(MDeformVert *dvert,
}
}
void BKE_defvert_extract_vgroup_to_loopweights(MDeformVert *dvert,
void BKE_defvert_extract_vgroup_to_loopweights(const MDeformVert *dvert,
const int defgroup,
const int num_verts,
MLoop *loops,
const int num_loops,
float *r_weights,
const bool invert_vgroup)
const bool invert_vgroup,
float *r_weights)
{
if (dvert && defgroup != -1) {
int i = num_loops;
float *tmp_weights = MEM_mallocN(sizeof(*tmp_weights) * (size_t)num_verts, __func__);
BKE_defvert_extract_vgroup_to_vertweights(
dvert, defgroup, num_verts, tmp_weights, invert_vgroup);
dvert, defgroup, num_verts, invert_vgroup, tmp_weights);
while (i--) {
MLoop *ml = &loops[i];
@@ -1083,22 +1083,22 @@ void BKE_defvert_extract_vgroup_to_loopweights(MDeformVert *dvert,
}
}
void BKE_defvert_extract_vgroup_to_polyweights(MDeformVert *dvert,
void BKE_defvert_extract_vgroup_to_polyweights(const MDeformVert *dvert,
const int defgroup,
const int num_verts,
MLoop *loops,
const int UNUSED(num_loops),
MPoly *polys,
const int num_polys,
float *r_weights,
const bool invert_vgroup)
const bool invert_vgroup,
float *r_weights)
{
if (dvert && defgroup != -1) {
int i = num_polys;
float *tmp_weights = MEM_mallocN(sizeof(*tmp_weights) * (size_t)num_verts, __func__);
BKE_defvert_extract_vgroup_to_vertweights(
dvert, defgroup, num_verts, tmp_weights, invert_vgroup);
dvert, defgroup, num_verts, invert_vgroup, tmp_weights);
while (i--) {
MPoly *mp = &polys[i];
@@ -1193,7 +1193,7 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(ListBase *r_map,
const bool use_delete,
Object *ob_src,
Object *ob_dst,
MDeformVert *data_src,
const MDeformVert *data_src,
MDeformVert *data_dst,
CustomData *UNUSED(cd_src),
CustomData *cd_dst,
@@ -1348,7 +1348,6 @@ bool data_transfer_layersmapping_vgroups(ListBase *r_map,
const int tolayers)
{
int idx_src, idx_dst;
MDeformVert *data_src, *data_dst = NULL;
const size_t elem_size = sizeof(*((MDeformVert *)NULL));
@@ -1370,9 +1369,9 @@ bool data_transfer_layersmapping_vgroups(ListBase *r_map,
return true;
}
data_src = CustomData_get_layer(cd_src, CD_MDEFORMVERT);
const MDeformVert *data_src = CustomData_get_layer(cd_src, CD_MDEFORMVERT);
data_dst = CustomData_get_layer(cd_dst, CD_MDEFORMVERT);
MDeformVert *data_dst = CustomData_get_layer(cd_dst, CD_MDEFORMVERT);
if (data_dst && use_dupref_dst && r_map) {
/* If dest is a derivedmesh, we do not want to overwrite cdlayers of org mesh! */
data_dst = CustomData_duplicate_referenced_layer(cd_dst, CD_MDEFORMVERT, num_elem_dst);

View File

@@ -1824,7 +1824,7 @@ static void sample_mesh(FluidFlowSettings *ffs,
const float *vert_vel,
bool has_velocity,
int defgrp_index,
MDeformVert *dvert,
const MDeformVert *dvert,
float x,
float y,
float z)
@@ -2008,7 +2008,7 @@ typedef struct EmitFromDMData {
const MLoop *mloop;
const MLoopTri *mlooptri;
const MLoopUV *mloopuv;
MDeformVert *dvert;
const MDeformVert *dvert;
int defgrp_index;
BVHTreeFromMesh *tree;
@@ -2079,7 +2079,7 @@ static void emit_from_mesh(
const MLoopTri *mlooptri = NULL;
const MLoop *mloop = NULL;
const MLoopUV *mloopuv = NULL;
MDeformVert *dvert = NULL;
const MDeformVert *dvert = NULL;
BVHTreeFromMesh tree_data = {NULL};
int numverts, i;

View File

@@ -290,7 +290,7 @@ void BKE_mesh_remesh_reproject_paint_mask(Mesh *target, Mesh *source)
&target->vdata, CD_PAINT_MASK, CD_CALLOC, nullptr, target->totvert);
}
float *source_mask;
const float *source_mask;
if (CustomData_has_layer(&source->vdata, CD_PAINT_MASK)) {
source_mask = (float *)CustomData_get_layer(&source->vdata, CD_PAINT_MASK);
}

View File

@@ -155,7 +155,7 @@ void BKE_mesh_calc_loop_tangent_single(Mesh *mesh,
float (*r_looptangents)[4],
ReportList *reports)
{
MLoopUV *loopuvs;
const MLoopUV *loopuvs;
float(*loopnors)[3];
/* Check we have valid texture coordinates first! */
@@ -205,10 +205,10 @@ typedef struct {
const float (*precomputedFaceNormals)[3];
const float (*precomputedLoopNormals)[3];
const MLoopTri *looptri;
MLoopUV *mloopuv; /* texture coordinates */
const MPoly *mpoly; /* indices */
const MLoop *mloop; /* indices */
const MVert *mvert; /* vertex coordinates */
const MLoopUV *mloopuv; /* texture coordinates */
const MPoly *mpoly; /* indices */
const MLoop *mloop; /* indices */
const MVert *mvert; /* vertex coordinates */
const float (*vert_normals)[3];
const float (*orco)[3];
float (*tangent)[4]; /* destination */

View File

@@ -69,7 +69,7 @@ static void mesh_loops_to_tessdata(CustomData *fdata,
for (i = 0; i < numUV; i++) {
MTFace *texface = CustomData_get_layer_n(fdata, CD_MTFACE, i);
MLoopUV *mloopuv = CustomData_get_layer_n(ldata, CD_MLOOPUV, i);
const MLoopUV *mloopuv = CustomData_get_layer_n(ldata, CD_MLOOPUV, i);
for (findex = 0, pidx = polyindices, lidx = loopindices; findex < num_faces;
pidx++, lidx++, findex++, texface++) {
@@ -81,7 +81,7 @@ static void mesh_loops_to_tessdata(CustomData *fdata,
for (i = 0; i < numCol; i++) {
MCol(*mcol)[4] = CustomData_get_layer_n(fdata, CD_MCOL, i);
MLoopCol *mloopcol = CustomData_get_layer_n(ldata, CD_PROP_BYTE_COLOR, i);
const MLoopCol *mloopcol = CustomData_get_layer_n(ldata, CD_PROP_BYTE_COLOR, i);
for (findex = 0, lidx = loopindices; findex < num_faces; lidx++, findex++, mcol++) {
for (j = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; j--;) {
@@ -92,7 +92,7 @@ static void mesh_loops_to_tessdata(CustomData *fdata,
if (hasPCol) {
MCol(*mcol)[4] = CustomData_get_layer(fdata, CD_PREVIEW_MCOL);
MLoopCol *mloopcol = CustomData_get_layer(ldata, CD_PREVIEW_MLOOPCOL);
const MLoopCol *mloopcol = CustomData_get_layer(ldata, CD_PREVIEW_MLOOPCOL);
for (findex = 0, lidx = loopindices; findex < num_faces; lidx++, findex++, mcol++) {
for (j = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; j--;) {
@@ -103,7 +103,7 @@ static void mesh_loops_to_tessdata(CustomData *fdata,
if (hasOrigSpace) {
OrigSpaceFace *of = CustomData_get_layer(fdata, CD_ORIGSPACE);
OrigSpaceLoop *lof = CustomData_get_layer(ldata, CD_ORIGSPACE_MLOOP);
const OrigSpaceLoop *lof = CustomData_get_layer(ldata, CD_ORIGSPACE_MLOOP);
for (findex = 0, lidx = loopindices; findex < num_faces; lidx++, findex++, of++) {
for (j = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; j--;) {
@@ -114,7 +114,7 @@ static void mesh_loops_to_tessdata(CustomData *fdata,
if (hasLoopNormal) {
short(*fnors)[4][3] = CustomData_get_layer(fdata, CD_TESSLOOPNORMAL);
float(*lnors)[3] = CustomData_get_layer(ldata, CD_NORMAL);
const float(*lnors)[3] = CustomData_get_layer(ldata, CD_NORMAL);
for (findex = 0, lidx = loopindices; findex < num_faces; lidx++, findex++, fnors++) {
for (j = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; j--;) {
@@ -126,7 +126,7 @@ static void mesh_loops_to_tessdata(CustomData *fdata,
if (hasLoopTangent) {
/* Need to do for all UV maps at some point. */
float(*ftangents)[4] = CustomData_get_layer(fdata, CD_TANGENT);
float(*ltangents)[4] = CustomData_get_layer(ldata, CD_TANGENT);
const float(*ltangents)[4] = CustomData_get_layer(ldata, CD_TANGENT);
for (findex = 0, pidx = polyindices, lidx = loopindices; findex < num_faces;
pidx++, lidx++, findex++) {
@@ -154,8 +154,8 @@ int BKE_mesh_tessface_calc_ex(CustomData *fdata,
const int looptri_num = poly_to_tri_count(totpoly, totloop);
MPoly *mp, *mpoly;
MLoop *ml, *mloop;
const MPoly *mp, *mpoly;
const MLoop *ml, *mloop;
MFace *mface, *mf;
MemArena *arena = NULL;
int *mface_to_poly_map;

View File

@@ -1021,7 +1021,7 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm, Scene *scene)
CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
Object *ob;
Mesh *me;
MDisps *mdisps;
const MDisps *mdisps;
MultiresModifierData *mmd;
ob = ccgdm->multires.ob;

View File

@@ -2051,7 +2051,7 @@ void BKE_sculpt_face_sets_ensure_from_base_mesh_visibility(Mesh *mesh)
void BKE_sculpt_sync_face_sets_visibility_to_base_mesh(Mesh *mesh)
{
int *face_sets = CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS);
const int *face_sets = CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS);
if (!face_sets) {
return;
}
@@ -2066,7 +2066,7 @@ void BKE_sculpt_sync_face_sets_visibility_to_base_mesh(Mesh *mesh)
void BKE_sculpt_sync_face_sets_visibility_to_grids(Mesh *mesh, SubdivCCG *subdiv_ccg)
{
int *face_sets = CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS);
const int *face_sets = CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS);
if (!face_sets) {
return;
}

View File

@@ -1667,7 +1667,7 @@ void psys_interpolate_face(Mesh *mesh,
const float (*vert_normals)[3],
MFace *mface,
MTFace *tface,
float (*orcodata)[3],
const float (*orcodata)[3],
float w[4],
float vec[3],
float nor[3],
@@ -1680,7 +1680,7 @@ void psys_interpolate_face(Mesh *mesh,
float *uv1, *uv2, *uv3, *uv4;
float n1[3], n2[3], n3[3], n4[3];
float tuv[4][2];
float *o1, *o2, *o3, *o4;
const float *o1, *o2, *o3, *o4;
v1 = mvert[mface->v1].co;
v2 = mvert[mface->v2].co;
@@ -1903,9 +1903,10 @@ int psys_particle_dm_face_lookup(Mesh *mesh_final,
struct LinkNode **poly_nodes)
{
MFace *mtessface_final;
OrigSpaceFace *osface_final;
const OrigSpaceFace *osface_final;
int pindex_orig;
float uv[2], (*faceuv)[2];
float uv[2];
const float(*faceuv)[2];
const int *index_mf_to_mpoly_deformed = NULL;
const int *index_mf_to_mpoly = NULL;
@@ -2048,11 +2049,7 @@ static int psys_map_index_on_dm(Mesh *mesh,
}
else { /* FROM_FACE/FROM_VOLUME */
/* find a face on the derived mesh that uses this face */
MFace *mface;
OrigSpaceFace *osface;
int i;
i = index_dmcache;
int i = index_dmcache;
if (i == DMCACHE_NOTFOUND || i >= mesh->totface) {
return 0;
@@ -2062,8 +2059,8 @@ static int psys_map_index_on_dm(Mesh *mesh,
/* modify the original weights to become
* weights for the derived mesh face */
osface = CustomData_get_layer(&mesh->fdata, CD_ORIGSPACE);
mface = &mesh->mface[i];
OrigSpaceFace *osface = CustomData_get_layer(&mesh->fdata, CD_ORIGSPACE);
const MFace *mface = &mesh->mface[i];
if (osface == NULL) {
mapfw[0] = mapfw[1] = mapfw[2] = mapfw[3] = 0.0f;
@@ -2090,7 +2087,7 @@ void psys_particle_on_dm(Mesh *mesh_final,
float orco[3])
{
float tmpnor[3], mapfw[4];
float(*orcodata)[3];
const float(*orcodata)[3];
int mapindex;
if (!psys_map_index_on_dm(
@@ -3843,7 +3840,7 @@ static void psys_face_mat(Object *ob, Mesh *mesh, ParticleData *pa, float mat[4]
float v[3][3];
MFace *mface;
OrigSpaceFace *osface;
float(*orcodata)[3];
const float(*orcodata)[3];
int i = (ELEM(pa->num_dmcache, DMCACHE_ISCHILD, DMCACHE_NOTFOUND)) ? pa->num : pa->num_dmcache;
if (i == -1 || i >= mesh->totface) {
@@ -4159,7 +4156,7 @@ static int get_particle_uv(Mesh *mesh,
bool from_vert)
{
MFace *mf;
MTFace *tf;
const MTFace *tf;
int i;
tf = CustomData_get_layer_named(&mesh->fdata, CD_MTFACE, name);

View File

@@ -808,7 +808,7 @@ static void exec_distribute_child(TaskPool *__restrict UNUSED(pool), void *taskd
static int distribute_compare_orig_index(const void *p1, const void *p2, void *user_data)
{
int *orig_index = (int *)user_data;
const int *orig_index = (const int *)user_data;
int index1 = orig_index[*(const int *)p1];
int index2 = orig_index[*(const int *)p2];
@@ -989,7 +989,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
if (from == PART_FROM_VERT) {
MVert *mv = mesh->mvert;
float(*orcodata)[3] = CustomData_get_layer(&mesh->vdata, CD_ORCO);
const float(*orcodata)[3] = CustomData_get_layer(&mesh->vdata, CD_ORCO);
int totvert = mesh->totvert;
tree = BLI_kdtree_3d_new(totvert);
@@ -1037,7 +1037,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
if ((part->flag & PART_EDISTR || children) && from != PART_FROM_VERT) {
MVert *v1, *v2, *v3, *v4;
float totarea = 0.0f, co1[3], co2[3], co3[3], co4[3];
float(*orcodata)[3];
const float(*orcodata)[3];
orcodata = CustomData_get_layer(&mesh->vdata, CD_ORCO);
@@ -1219,7 +1219,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
/* For hair, sort by origindex (allows optimization's in rendering), */
/* however with virtual parents the children need to be in random order. */
if (part->type == PART_HAIR && !(part->childtype == PART_CHILD_FACES && part->parents != 0.0f)) {
int *orig_index = NULL;
const int *orig_index = NULL;
if (from == PART_FROM_VERT) {
if (mesh->totvert) {
@@ -1233,8 +1233,11 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
}
if (orig_index) {
BLI_qsort_r(
particle_element, totpart, sizeof(int), distribute_compare_orig_index, orig_index);
BLI_qsort_r(particle_element,
totpart,
sizeof(int),
distribute_compare_orig_index,
(void *)orig_index);
}
}

View File

@@ -321,8 +321,9 @@ void psys_calc_dmcache(Object *ob, Mesh *mesh_final, Mesh *mesh_original, Partic
if (!mesh_final->runtime.deformed_only) {
/* Will use later to speed up subsurf/evaluated mesh. */
LinkNode *node, *nodedmelem, **nodearray;
int totdmelem, totelem, i, *origindex, *origindex_poly = NULL;
int totdmelem, totelem, i;
const int *origindex;
const int *origindex_poly = NULL;
if (psys->part->from == PART_FROM_VERT) {
totdmelem = mesh_final->totvert;

View File

@@ -108,7 +108,7 @@ struct EncodePixelsUserData {
ImageUser *image_user;
PBVH *pbvh;
Vector<PBVHNode *> *nodes;
MLoopUV *ldata_uv;
const MLoopUV *ldata_uv;
};
static void do_encode_pixels(void *__restrict userdata,
@@ -283,7 +283,8 @@ static void update_pixels(PBVH *pbvh, Mesh *mesh, Image *image, ImageUser *image
return;
}
MLoopUV *ldata_uv = static_cast<MLoopUV *>(CustomData_get_layer(&mesh->ldata, CD_MLOOPUV));
const MLoopUV *ldata_uv = static_cast<const MLoopUV *>(
CustomData_get_layer(&mesh->ldata, CD_MLOOPUV));
if (ldata_uv == nullptr) {
return;
}

View File

@@ -155,8 +155,7 @@ static void mask_init_functions(SubdivCCGMaskEvaluator *mask_evaluator)
bool BKE_subdiv_ccg_mask_init_from_paint(SubdivCCGMaskEvaluator *mask_evaluator,
const struct Mesh *mesh)
{
GridPaintMask *grid_paint_mask = CustomData_get_layer(&mesh->ldata, CD_GRID_PAINT_MASK);
if (grid_paint_mask == NULL) {
if (CustomData_get_layer(&mesh->ldata, CD_GRID_PAINT_MASK)) {
return false;
}
/* Allocate all required memory. */

View File

@@ -1670,7 +1670,6 @@ static void set_ccgdm_all_geometry(CCGDerivedMesh *ccgdm,
int index;
int i;
int vertNum = 0, edgeNum = 0, faceNum = 0;
int *vertOrigIndex, *polyOrigIndex, *base_polyOrigIndex, *edgeOrigIndex;
short *edgeFlags = ccgdm->edgeFlags;
DMFlagMat *faceFlags = ccgdm->faceFlags;
int *polyidx = NULL;
@@ -1687,7 +1686,6 @@ static void set_ccgdm_all_geometry(CCGDerivedMesh *ccgdm,
int gridInternalEdges;
WeightTable wtable = {NULL};
MEdge *medge = NULL;
MPoly *mpoly = NULL;
bool has_edge_cd;
edgeSize = ccgSubSurf_getEdgeSize(ss);
@@ -1700,13 +1698,13 @@ static void set_ccgdm_all_geometry(CCGDerivedMesh *ccgdm,
medge = dm->getEdgeArray(dm);
mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY);
base_polyOrigIndex = CustomData_get_layer(&dm->polyData, CD_ORIGINDEX);
const MPoly *mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY);
const int *base_polyOrigIndex = CustomData_get_layer(&dm->polyData, CD_ORIGINDEX);
vertOrigIndex = DM_get_vert_data_layer(&ccgdm->dm, CD_ORIGINDEX);
edgeOrigIndex = DM_get_edge_data_layer(&ccgdm->dm, CD_ORIGINDEX);
int *vertOrigIndex = DM_get_vert_data_layer(&ccgdm->dm, CD_ORIGINDEX);
int *edgeOrigIndex = DM_get_edge_data_layer(&ccgdm->dm, CD_ORIGINDEX);
polyOrigIndex = DM_get_poly_data_layer(&ccgdm->dm, CD_ORIGINDEX);
int *polyOrigIndex = DM_get_poly_data_layer(&ccgdm->dm, CD_ORIGINDEX);
has_edge_cd = ((ccgdm->dm.edgeData.totlayer - (edgeOrigIndex ? 1 : 0)) != 0);

View File

@@ -4892,7 +4892,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
/* Default Face Set Color. */
for (Mesh *me = bmain->meshes.first; me != NULL; me = me->id.next) {
if (me->totpoly > 0) {
int *face_sets = CustomData_get_layer(&me->pdata, CD_SCULPT_FACE_SETS);
const int *face_sets = CustomData_get_layer(&me->pdata, CD_SCULPT_FACE_SETS);
if (face_sets) {
me->face_sets_color_default = abs(face_sets[0]);
}

View File

@@ -745,8 +745,8 @@ struct DRWCacheBuildingContext {
/* Origindex layers from the mesh to directly look up during traversal the origindex from the
* base mesh for edit data so that we do not have to handle yet another GPU buffer and do this in
* the shaders. */
int *v_origindex;
int *e_origindex;
const int *v_origindex;
const int *e_origindex;
};
static bool draw_subdiv_topology_info_cb(const SubdivForeachContext *foreach_context,

View File

@@ -67,7 +67,7 @@ typedef struct MeshRenderData {
const float (*bm_poly_normals)[3];
const float (*bm_poly_centers)[3];
int *v_origindex, *e_origindex, *p_origindex;
const int *v_origindex, *e_origindex, *p_origindex;
int edge_crease_ofs;
int vert_crease_ofs;
int bweight_ofs;

View File

@@ -26,7 +26,7 @@ struct UVStretchAngle {
struct MeshExtract_StretchAngle_Data {
UVStretchAngle *vbo_data;
MLoopUV *luv;
const MLoopUV *luv;
float auv[2][2], last_auv[2];
float av[2][3], last_av[3];
int cd_ofs;
@@ -98,7 +98,7 @@ static void extract_edituv_stretch_angle_init(const MeshRenderData *mr,
}
else {
BLI_assert(ELEM(mr->extract_type, MR_EXTRACT_MAPPED, MR_EXTRACT_MESH));
data->luv = (MLoopUV *)CustomData_get_layer(&mr->me->ldata, CD_MLOOPUV);
data->luv = (const MLoopUV *)CustomData_get_layer(&mr->me->ldata, CD_MLOOPUV);
}
}

View File

@@ -17,7 +17,7 @@ namespace blender::draw {
struct MeshExtract_FdotUV_Data {
float (*vbo_data)[2];
MLoopUV *uv_data;
const MLoopUV *uv_data;
int cd_ofs;
};
@@ -49,7 +49,7 @@ static void extract_fdots_uv_init(const MeshRenderData *mr,
data->cd_ofs = CustomData_get_offset(&mr->bm->ldata, CD_MLOOPUV);
}
else {
data->uv_data = (MLoopUV *)CustomData_get_layer(&mr->me->ldata, CD_MLOOPUV);
data->uv_data = (const MLoopUV *)CustomData_get_layer(&mr->me->ldata, CD_MLOOPUV);
}
}

View File

@@ -17,7 +17,7 @@ namespace blender::draw {
struct MeshExtract_Orco_Data {
float (*vbo_data)[4];
float (*orco)[3];
const float (*orco)[3];
};
static void extract_orco_init(const MeshRenderData *mr,
@@ -42,7 +42,7 @@ static void extract_orco_init(const MeshRenderData *mr,
MeshExtract_Orco_Data *data = static_cast<MeshExtract_Orco_Data *>(tls_data);
data->vbo_data = (float(*)[4])GPU_vertbuf_get_data(vbo);
data->orco = static_cast<float(*)[3]>(CustomData_get_layer(cd_vdata, CD_ORCO));
data->orco = static_cast<const float(*)[3]>(CustomData_get_layer(cd_vdata, CD_ORCO));
/* Make sure `orco` layer was requested only if needed! */
BLI_assert(data->orco);
}
@@ -105,7 +105,7 @@ static void extract_orco_init_subdiv(const DRWSubdivCache *subdiv_cache,
float(*coarse_vbo_data)[4] = static_cast<float(*)[4]>(GPU_vertbuf_get_data(coarse_vbo));
CustomData *cd_vdata = &mr->me->vdata;
float(*orco)[3] = static_cast<float(*)[3]>(CustomData_get_layer(cd_vdata, CD_ORCO));
const float(*orco)[3] = static_cast<const float(*)[3]>(CustomData_get_layer(cd_vdata, CD_ORCO));
if (mr->extract_type == MR_EXTRACT_MESH) {
const MLoop *mloop = mr->mloop;

View File

@@ -220,7 +220,7 @@ static void extract_pos_nor_init_subdiv(const DRWSubdivCache *subdiv_cache,
if (subdiv_cache->use_custom_loop_normals) {
Mesh *coarse_mesh = subdiv_cache->mesh;
float(*lnors)[3] = static_cast<float(*)[3]>(
const float(*lnors)[3] = static_cast<float(*)[3]>(
CustomData_get_layer(&coarse_mesh->ldata, CD_NORMAL));
BLI_assert(lnors != nullptr);

View File

@@ -42,8 +42,8 @@ static void extract_sculpt_data_init(const MeshRenderData *mr,
CustomData *cd_vdata = (mr->extract_type == MR_EXTRACT_BMESH) ? &mr->bm->vdata : &mr->me->vdata;
CustomData *cd_pdata = (mr->extract_type == MR_EXTRACT_BMESH) ? &mr->bm->pdata : &mr->me->pdata;
float *cd_mask = (float *)CustomData_get_layer(cd_vdata, CD_PAINT_MASK);
int *cd_face_set = (int *)CustomData_get_layer(cd_pdata, CD_SCULPT_FACE_SETS);
const float *cd_mask = (const float *)CustomData_get_layer(cd_vdata, CD_PAINT_MASK);
const int *cd_face_set = (const int *)CustomData_get_layer(cd_pdata, CD_SCULPT_FACE_SETS);
GPU_vertbuf_init_with_format(vbo, format);
GPU_vertbuf_data_alloc(vbo, mr->loop_len);
@@ -54,7 +54,7 @@ static void extract_sculpt_data_init(const MeshRenderData *mr,
};
gpuSculptData *vbo_data = (gpuSculptData *)GPU_vertbuf_get_data(vbo);
MLoop *loops = (MLoop *)CustomData_get_layer(cd_ldata, CD_MLOOP);
const MLoop *loops = (const MLoop *)CustomData_get_layer(cd_ldata, CD_MLOOP);
if (mr->extract_type == MR_EXTRACT_BMESH) {
int cd_mask_ofs = CustomData_get_offset(cd_vdata, CD_PAINT_MASK);
@@ -126,7 +126,7 @@ static void extract_sculpt_data_init_subdiv(const DRWSubdivCache *subdiv_cache,
/* First, interpolate mask if available. */
GPUVertBuf *mask_vbo = nullptr;
GPUVertBuf *subdiv_mask_vbo = nullptr;
float *cd_mask = (float *)CustomData_get_layer(cd_vdata, CD_PAINT_MASK);
const float *cd_mask = (const float *)CustomData_get_layer(cd_vdata, CD_PAINT_MASK);
if (cd_mask) {
GPUVertFormat mask_format = {0};
@@ -167,7 +167,7 @@ static void extract_sculpt_data_init_subdiv(const DRWSubdivCache *subdiv_cache,
};
gpuFaceSet *face_sets = (gpuFaceSet *)GPU_vertbuf_get_data(face_set_vbo);
int *cd_face_set = (int *)CustomData_get_layer(cd_pdata, CD_SCULPT_FACE_SETS);
const int *cd_face_set = (const int *)CustomData_get_layer(cd_pdata, CD_SCULPT_FACE_SETS);
GPUVertFormat *format = get_sculpt_data_format();
GPU_vertbuf_init_build_on_device(vbo, format, subdiv_cache->num_subdiv_loops);

View File

@@ -291,7 +291,8 @@ static void extract_tan_init_subdiv(const DRWSubdivCache *subdiv_cache,
for (int i = 0; i < tan_len; i++) {
float(*tan_data)[4] = (float(*)[4])GPU_vertbuf_get_data(coarse_vbo);
const char *name = tangent_names[i];
float(*layer_data)[4] = (float(*)[4])CustomData_get_layer_named(&loop_data, CD_TANGENT, name);
const float(*layer_data)[4] = (float(*)[4])CustomData_get_layer_named(
&loop_data, CD_TANGENT, name);
for (int ml_index = 0; ml_index < mr->loop_len; ml_index++) {
copy_v3_v3(*tan_data, layer_data[ml_index]);
(*tan_data)[3] = (layer_data[ml_index][3] > 0.0f) ? 1.0f : -1.0f;
@@ -306,7 +307,7 @@ static void extract_tan_init_subdiv(const DRWSubdivCache *subdiv_cache,
}
if (use_orco_tan) {
float(*tan_data)[4] = (float(*)[4])GPU_vertbuf_get_data(coarse_vbo);
float(*layer_data)[4] = (float(*)[4])CustomData_get_layer_n(&loop_data, CD_TANGENT, 0);
const float(*layer_data)[4] = (float(*)[4])CustomData_get_layer_n(&loop_data, CD_TANGENT, 0);
for (int ml_index = 0; ml_index < mr->loop_len; ml_index++) {
copy_v3_v3(*tan_data, layer_data[ml_index]);
(*tan_data)[3] = (layer_data[ml_index][3] > 0.0f) ? 1.0f : -1.0f;

View File

@@ -195,7 +195,7 @@ static void try_convert_single_object(Object &curves_ob,
/* Prepare utility data structure to map hair roots to mfaces. */
const Span<int> mface_to_poly_map{
static_cast<int *>(CustomData_get_layer(&surface_me.fdata, CD_ORIGINDEX)),
static_cast<const int *>(CustomData_get_layer(&surface_me.fdata, CD_ORIGINDEX)),
surface_me.totface};
Array<Vector<int>> poly_to_mface_map(surface_me.totpoly);
for (const int mface_i : mface_to_poly_map.index_range()) {

View File

@@ -549,9 +549,9 @@ int ED_mesh_sculpt_color_add(
}
if (CustomData_has_layer(&me->vdata, CD_PROP_COLOR) && do_init) {
MPropCol *color_data = CustomData_get_layer(&me->vdata, CD_PROP_COLOR);
const MPropCol *color_data = CustomData_get_layer(&me->vdata, CD_PROP_COLOR);
CustomData_add_layer_named(
&me->vdata, CD_PROP_COLOR, CD_DUPLICATE, color_data, me->totvert, name);
&me->vdata, CD_PROP_COLOR, CD_DUPLICATE, (MPropCol *)color_data, me->totvert, name);
}
else {
CustomData_add_layer_named(&me->vdata, CD_PROP_COLOR, CD_DEFAULT, NULL, me->totvert, name);

View File

@@ -1273,7 +1273,6 @@ bool ED_mesh_pick_face_vert(
MLoop *me_eval_mloop;
MVert *me_eval_mvert;
uint me_eval_mpoly_len;
const int *index_mp_to_orig;
me_eval_mpoly = me_eval->mpoly;
me_eval_mloop = me_eval->mloop;
@@ -1281,7 +1280,7 @@ bool ED_mesh_pick_face_vert(
me_eval_mpoly_len = me_eval->totpoly;
index_mp_to_orig = CustomData_get_layer(&me_eval->pdata, CD_ORIGINDEX);
const int *index_mp_to_orig = CustomData_get_layer(&me_eval->pdata, CD_ORIGINDEX);
/* tag all verts using this face */
if (index_mp_to_orig) {
@@ -1313,8 +1312,7 @@ bool ED_mesh_pick_face_vert(
/* map 'dm -> me' r_index if possible */
if (v_idx_best != ORIGINDEX_NONE) {
const int *index_mv_to_orig;
index_mv_to_orig = CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX);
const int *index_mv_to_orig = CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX);
if (index_mv_to_orig) {
v_idx_best = index_mv_to_orig[v_idx_best];
}

View File

@@ -446,9 +446,9 @@ static bool bake_object_check(ViewLayer *view_layer,
}
if (target == R_BAKE_TARGET_VERTEX_COLORS) {
MPropCol *mcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR);
const MPropCol *mcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR);
const bool mcol_valid = (mcol != NULL);
MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_PROP_BYTE_COLOR);
const MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_PROP_BYTE_COLOR);
if (mloopcol == NULL && !mcol_valid) {
BKE_reportf(reports,
RPT_ERROR,
@@ -943,9 +943,9 @@ static bool bake_targets_init_vertex_colors(BakeTargets *targets, Object *ob, Re
}
Mesh *me = ob->data;
MPropCol *mcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR);
const MPropCol *mcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR);
const bool mcol_valid = (mcol != NULL);
MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_PROP_BYTE_COLOR);
const MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_PROP_BYTE_COLOR);
if (mloopcol == NULL && !mcol_valid) {
BKE_report(reports, RPT_ERROR, "No vertex colors layer found to bake to");
return false;

View File

@@ -60,7 +60,7 @@
int ED_sculpt_face_sets_find_next_available_id(struct Mesh *mesh)
{
int *face_sets = CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS);
const int *face_sets = CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS);
if (!face_sets) {
return SCULPT_FACE_SET_NONE;
}

View File

@@ -639,14 +639,14 @@ static int vertex_to_loop_colors_exec(bContext *C, wmOperator *UNUSED(op))
}
MPropCol *vertcols = CustomData_get_layer_n(&mesh->vdata, CD_PROP_COLOR, MPropCol_layer_n);
MLoop *loops = CustomData_get_layer(&mesh->ldata, CD_MLOOP);
MPoly *polys = CustomData_get_layer(&mesh->pdata, CD_MPOLY);
const MLoop *loops = CustomData_get_layer(&mesh->ldata, CD_MLOOP);
const MPoly *polys = CustomData_get_layer(&mesh->pdata, CD_MPOLY);
for (int i = 0; i < mesh->totpoly; i++) {
MPoly *c_poly = &polys[i];
const MPoly *c_poly = &polys[i];
for (int j = 0; j < c_poly->totloop; j++) {
int loop_index = c_poly->loopstart + j;
MLoop *c_loop = &loops[c_poly->loopstart + j];
const MLoop *c_loop = &loops[c_poly->loopstart + j];
float srgb_color[4];
linearrgb_to_srgb_v4(srgb_color, vertcols[c_loop->v].color);
loopcols[loop_index].r = (char)(srgb_color[0] * 255);
@@ -719,14 +719,14 @@ static int loop_to_vertex_colors_exec(bContext *C, wmOperator *UNUSED(op))
}
MPropCol *vertcols = CustomData_get_layer_n(&mesh->vdata, CD_PROP_COLOR, MPropCol_layer_n);
MLoop *loops = CustomData_get_layer(&mesh->ldata, CD_MLOOP);
MPoly *polys = CustomData_get_layer(&mesh->pdata, CD_MPOLY);
const MLoop *loops = CustomData_get_layer(&mesh->ldata, CD_MLOOP);
const MPoly *polys = CustomData_get_layer(&mesh->pdata, CD_MPOLY);
for (int i = 0; i < mesh->totpoly; i++) {
MPoly *c_poly = &polys[i];
const MPoly *c_poly = &polys[i];
for (int j = 0; j < c_poly->totloop; j++) {
int loop_index = c_poly->loopstart + j;
MLoop *c_loop = &loops[c_poly->loopstart + j];
const MLoop *c_loop = &loops[c_poly->loopstart + j];
vertcols[c_loop->v].color[0] = (loopcols[loop_index].r / 255.0f);
vertcols[c_loop->v].color[1] = (loopcols[loop_index].g / 255.0f);
vertcols[c_loop->v].color[2] = (loopcols[loop_index].b / 255.0f);

View File

@@ -1265,7 +1265,7 @@ static SculptUndoNode *sculpt_undo_face_sets_push(Object *ob, SculptUndoType typ
unode->face_sets = MEM_callocN(me->totpoly * sizeof(int), "sculpt face sets");
int *face_sets = CustomData_get_layer(&me->pdata, CD_SCULPT_FACE_SETS);
const int *face_sets = CustomData_get_layer(&me->pdata, CD_SCULPT_FACE_SETS);
for (int i = 0; i < me->totpoly; i++) {
unode->face_sets[i] = face_sets[i];
}

View File

@@ -256,7 +256,7 @@ IndexMask GeometryDataSource::apply_selection_filter(Vector<int64_t> &indices) c
BMesh *bm = mesh_orig->edit_mesh->bm;
BM_mesh_elem_table_ensure(bm, BM_VERT);
int *orig_indices = (int *)CustomData_get_layer(&mesh_eval->vdata, CD_ORIGINDEX);
const int *orig_indices = (int *)CustomData_get_layer(&mesh_eval->vdata, CD_ORIGINDEX);
if (orig_indices != nullptr) {
/* Use CD_ORIGINDEX layer if it exists. */
VArray<bool> selection = mesh_component->attribute_try_adapt_domain<bool>(

View File

@@ -370,7 +370,7 @@ int BlenderFileLoader::testDegenerateTriangle(float v1[3], float v2[3], float v3
return 0;
}
static bool testEdgeMark(Mesh *me, FreestyleEdge *fed, const MLoopTri *lt, int i)
static bool testEdgeMark(Mesh *me, const FreestyleEdge *fed, const MLoopTri *lt, int i)
{
MLoop *mloop = &me->mloop[lt->tri[i]];
MLoop *mloop_next = &me->mloop[lt->tri[(i + 1) % 3]];
@@ -395,7 +395,7 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id)
// Compute loop normals
BKE_mesh_calc_normals_split(me);
float(*lnors)[3] = nullptr;
const float(*lnors)[3] = nullptr;
if (CustomData_has_layer(&me->ldata, CD_NORMAL)) {
lnors = (float(*)[3])CustomData_get_layer(&me->ldata, CD_NORMAL);
@@ -405,8 +405,8 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id)
MVert *mvert = me->mvert;
MLoop *mloop = me->mloop;
MPoly *mpoly = me->mpoly;
FreestyleEdge *fed = (FreestyleEdge *)CustomData_get_layer(&me->edata, CD_FREESTYLE_EDGE);
FreestyleFace *ffa = (FreestyleFace *)CustomData_get_layer(&me->pdata, CD_FREESTYLE_FACE);
const FreestyleEdge *fed = (FreestyleEdge *)CustomData_get_layer(&me->edata, CD_FREESTYLE_EDGE);
const FreestyleFace *ffa = (FreestyleFace *)CustomData_get_layer(&me->pdata, CD_FREESTYLE_FACE);
// Compute view matrix
Object *ob_camera_eval = DEG_get_evaluated_object(_depsgraph, RE_GetCamera(_re));

View File

@@ -619,7 +619,7 @@ void GeometryExporter::create_normals(std::vector<Normal> &normals,
MVert *verts = me->mvert;
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(me);
MLoop *mloops = me->mloop;
float(*lnors)[3] = nullptr;
const float(*lnors)[3] = nullptr;
bool use_custom_normals = false;
BKE_mesh_calc_normals_split(me);

View File

@@ -560,7 +560,7 @@ static void rna_MeshVertex_undeformed_co_get(PointerRNA *ptr, float values[3])
{
Mesh *me = rna_mesh(ptr);
MVert *mvert = (MVert *)ptr->data;
float(*orco)[3] = CustomData_get_layer(&me->vdata, CD_ORCO);
const float(*orco)[3] = CustomData_get_layer(&me->vdata, CD_ORCO);
if (orco) {
/* orco is normalized to 0..1, we do inverse to match mvert->co */

View File

@@ -310,13 +310,11 @@ static void displaceModifier_do(DisplaceModifierData *dmd,
CustomData *ldata = &mesh->ldata;
if (CustomData_has_layer(ldata, CD_CUSTOMLOOPNORMAL)) {
float(*clnors)[3] = NULL;
if (!CustomData_has_layer(ldata, CD_NORMAL)) {
BKE_mesh_calc_normals_split(mesh);
}
clnors = CustomData_get_layer(ldata, CD_NORMAL);
float(*clnors)[3] = CustomData_get_layer(ldata, CD_NORMAL);
vert_clnors = MEM_malloc_arrayN(verts_num, sizeof(*vert_clnors), __func__);
BKE_mesh_normals_loop_to_vertex(
verts_num, mesh->mloop, mesh->totloop, (const float(*)[3])clnors, vert_clnors);

View File

@@ -124,7 +124,7 @@ static void createFacepa(ExplodeModifierData *emd, ParticleSystemModifierData *p
/* set protected verts */
if (emd->vgroup) {
MDeformVert *dvert = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
const MDeformVert *dvert = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
if (dvert) {
const int defgrp_index = emd->vgroup - 1;
for (i = 0; i < totvert; i++, dvert++) {

View File

@@ -91,7 +91,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
}
/* A vertex will be in the mask if a selected bone influences it more than a certain threshold. */
static void compute_vertex_mask__armature_mode(MDeformVert *dvert,
static void compute_vertex_mask__armature_mode(const MDeformVert *dvert,
Mesh *mesh,
Object *armature_ob,
float threshold,
@@ -125,7 +125,7 @@ static void compute_vertex_mask__armature_mode(MDeformVert *dvert,
}
/* A vertex will be in the mask if the vertex group influences it more than a certain threshold. */
static void compute_vertex_mask__vertex_group_mode(MDeformVert *dvert,
static void compute_vertex_mask__vertex_group_mode(const MDeformVert *dvert,
int defgrp_index,
float threshold,
MutableSpan<bool> r_vertex_mask)
@@ -347,7 +347,7 @@ static void copy_masked_vertices_to_new_mesh(const Mesh &src_mesh,
}
static float get_interp_factor_from_vgroup(
MDeformVert *dvert, int defgrp_index, float threshold, uint v1, uint v2)
const MDeformVert *dvert, int defgrp_index, float threshold, uint v1, uint v2)
{
/* NOTE: this calculation is done twice for every vertex,
* instead of storing it the first time and then reusing it. */
@@ -360,7 +360,7 @@ static void add_interp_verts_copy_edges_to_new_mesh(const Mesh &src_mesh,
Mesh &dst_mesh,
Span<bool> vertex_mask,
Span<int> vertex_map,
MDeformVert *dvert,
const MDeformVert *dvert,
int defgrp_index,
float threshold,
uint edges_masked_num,
@@ -478,7 +478,7 @@ static void add_interpolated_polys_to_new_mesh(const Mesh &src_mesh,
Span<bool> vertex_mask,
Span<int> vertex_map,
Span<int> edge_map,
MDeformVert *dvert,
const MDeformVert *dvert,
int defgrp_index,
float threshold,
Span<int> masked_poly_indices,
@@ -619,7 +619,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx)
(mmd->flag & MOD_MASK_SMOOTH);
/* Return empty or input mesh when there are no vertex groups. */
MDeformVert *dvert = (MDeformVert *)CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
const MDeformVert *dvert = (const MDeformVert *)CustomData_get_layer(&mesh->vdata,
CD_MDEFORMVERT);
if (dvert == nullptr) {
return invert_mask ? mesh : BKE_mesh_new_nomain_from_template(mesh, 0, 0, 0, 0, 0);
}

View File

@@ -136,7 +136,7 @@ static void mix_normals(const float mix_factor,
if (dvert) {
facs = MEM_malloc_arrayN((size_t)loops_num, sizeof(*facs), __func__);
BKE_defvert_extract_vgroup_to_loopweights(
dvert, defgrp_index, verts_num, mloop, loops_num, facs, use_invert_vgroup);
dvert, defgrp_index, verts_num, mloop, loops_num, use_invert_vgroup, facs);
}
for (i = loops_num, no_new = nos_new, no_old = nos_old, wfac = facs; i--;
@@ -532,14 +532,13 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
MDeformVert *dvert;
float(*loopnors)[3] = NULL;
short(*clnors)[2] = NULL;
CustomData *ldata = &result->ldata;
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(result);
const float(*poly_normals)[3] = BKE_mesh_poly_normals_ensure(result);
clnors = CustomData_get_layer(ldata, CD_CUSTOMLOOPNORMAL);
short(*clnors)[2] = CustomData_get_layer(ldata, CD_CUSTOMLOOPNORMAL);
if (use_current_clnors) {
clnors = CustomData_duplicate_referenced_layer(ldata, CD_CUSTOMLOOPNORMAL, loops_num);
loopnors = MEM_malloc_arrayN((size_t)loops_num, sizeof(*loopnors), __func__);

View File

@@ -182,7 +182,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
ScrewModifierData *ltmd = (ScrewModifierData *)md;
const bool use_render_params = (ctx->flag & MOD_APPLY_RENDER) != 0;
int *origindex;
int mpoly_index = 0;
uint step;
uint i, j;
@@ -397,7 +396,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
CustomData_add_layer(&result->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, (int)maxPolys);
}
origindex = CustomData_get_layer(&result->pdata, CD_ORIGINDEX);
int *origindex = CustomData_get_layer(&result->pdata, CD_ORIGINDEX);
CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, (int)totvert);

View File

@@ -881,34 +881,29 @@ static int calc_edge_subdivisions(const MVert *mvert,
/* Take a Mesh and subdivide its edges to keep skin nodes
* reasonably close. */
static Mesh *subdivide_base(Mesh *orig)
static Mesh *subdivide_base(const Mesh *orig)
{
Mesh *result;
MVertSkin *orignode, *outnode;
MVert *origvert, *outvert;
MEdge *origedge, *outedge, *e;
MDeformVert *origdvert, *outdvert;
int orig_vert_num, orig_edge_num;
int subd_num, *degree, *edge_subd;
const MEdge *e;
int subd_num;
int i, j, k, u, v;
float radrat;
orignode = CustomData_get_layer(&orig->vdata, CD_MVERT_SKIN);
origvert = orig->mvert;
origedge = orig->medge;
origdvert = orig->dvert;
orig_vert_num = orig->totvert;
orig_edge_num = orig->totedge;
const MVertSkin *orignode = CustomData_get_layer(&orig->vdata, CD_MVERT_SKIN);
const MVert *origvert = orig->mvert;
const MEdge *origedge = orig->medge;
const MDeformVert *origdvert = orig->dvert;
int orig_vert_num = orig->totvert;
int orig_edge_num = orig->totedge;
/* Get degree of all vertices */
degree = MEM_calloc_arrayN(orig_vert_num, sizeof(int), "degree");
int *degree = MEM_calloc_arrayN(orig_vert_num, sizeof(int), "degree");
for (i = 0; i < orig_edge_num; i++) {
degree[origedge[i].v1]++;
degree[origedge[i].v2]++;
}
/* Per edge, store how many subdivisions are needed */
edge_subd = MEM_calloc_arrayN((uint)orig_edge_num, sizeof(int), "edge_subd");
int *edge_subd = MEM_calloc_arrayN((uint)orig_edge_num, sizeof(int), "edge_subd");
for (i = 0, subd_num = 0; i < orig_edge_num; i++) {
edge_subd[i] += calc_edge_subdivisions(origvert, orignode, &origedge[i], degree);
BLI_assert(edge_subd[i] >= 0);
@@ -918,13 +913,13 @@ static Mesh *subdivide_base(Mesh *orig)
MEM_freeN(degree);
/* Allocate output mesh */
result = BKE_mesh_new_nomain_from_template(
Mesh *result = BKE_mesh_new_nomain_from_template(
orig, orig_vert_num + subd_num, orig_edge_num + subd_num, 0, 0, 0);
outvert = result->mvert;
outedge = result->medge;
outnode = CustomData_get_layer(&result->vdata, CD_MVERT_SKIN);
outdvert = result->dvert;
MVert *outvert = result->mvert;
MEdge *outedge = result->medge;
MVertSkin *outnode = CustomData_get_layer(&result->vdata, CD_MVERT_SKIN);
MDeformVert *outdvert = result->dvert;
/* Copy original vertex data */
CustomData_copy_data(&orig->vdata, &result->vdata, 0, 0, orig_vert_num);

View File

@@ -100,10 +100,9 @@ void MOD_get_texture_coords(MappingInfoModifierData *dmd,
BLI_bitmap *done = BLI_BITMAP_NEW(verts_num, __func__);
const int polys_num = mesh->totpoly;
char uvname[MAX_CUSTOMDATA_LAYER_NAME];
MLoopUV *mloop_uv;
CustomData_validate_layer_name(&mesh->ldata, CD_MLOOPUV, dmd->uvlayer_name, uvname);
mloop_uv = CustomData_get_layer_named(&mesh->ldata, CD_MLOOPUV, uvname);
const MLoopUV *mloop_uv = CustomData_get_layer_named(&mesh->ldata, CD_MLOOPUV, uvname);
/* verts are given the UV from the first face that uses them */
for (i = 0, mp = mpoly; i < polys_num; i++, mp++) {

View File

@@ -82,7 +82,7 @@ typedef struct WeightedNormalData {
MPoly *mpoly;
const float (*polynors)[3];
int *poly_strength;
const int *poly_strength;
MDeformVert *dvert;
const int defgrp_index;
@@ -195,7 +195,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
MPoly *mpoly = wn_data->mpoly;
const float(*polynors)[3] = wn_data->polynors;
int *poly_strength = wn_data->poly_strength;
const int *poly_strength = wn_data->poly_strength;
MDeformVert *dvert = wn_data->dvert;
@@ -603,15 +603,13 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
const float split_angle = mesh->smoothresh;
short(*clnors)[2];
CustomData *ldata = &result->ldata;
clnors = CustomData_get_layer(ldata, CD_CUSTOMLOOPNORMAL);
short(*clnors)[2] = CustomData_get_layer(&result->ldata, CD_CUSTOMLOOPNORMAL);
/* Keep info whether we had clnors,
* it helps when generating clnor spaces and default normals. */
const bool has_clnors = clnors != NULL;
if (!clnors) {
clnors = CustomData_add_layer(ldata, CD_CUSTOMLOOPNORMAL, CD_CALLOC, NULL, loops_num);
clnors = CustomData_add_layer(&result->ldata, CD_CUSTOMLOOPNORMAL, CD_CALLOC, NULL, loops_num);
}
MDeformVert *dvert;

View File

@@ -206,8 +206,6 @@ void weightvg_do_mask(const ModifierEvalContext *ctx,
MEM_freeN(tex_co);
}
else if ((ref_didx = BKE_id_defgroup_name_index(&mesh->id, defgrp_name)) != -1) {
MDeformVert *dvert = NULL;
/* Check whether we want to set vgroup weights from a constant weight factor or a vertex
* group.
*/
@@ -215,7 +213,7 @@ void weightvg_do_mask(const ModifierEvalContext *ctx,
/* Proceed only if vgroup is valid, else use constant factor. */
/* Get actual dverts (ie vertex group data). */
dvert = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
const MDeformVert *dvert = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
/* Proceed only if vgroup is valid, else assume factor = O. */
if (dvert == NULL) {
return;

View File

@@ -96,7 +96,7 @@ typedef struct TriTessFace {
const MVert *mverts[3];
const float *vert_normals[3];
const TSpace *tspace[3];
float *loop_normal[3];
const float *loop_normal[3];
float normal[3]; /* for flat faces */
bool is_smooth;
} TriTessFace;
@@ -451,9 +451,6 @@ static bool cast_ray_highpoly(BVHTreeFromMesh *treeData,
static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval)
{
int i;
MVert *mvert;
TSpace *tspace = NULL;
float(*loop_normals)[3] = NULL;
const int tottri = poly_to_tri_count(me->totpoly, me->totloop);
MLoopTri *looptri;
@@ -463,7 +460,7 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval
unsigned int mpoly_prev = UINT_MAX;
float no[3];
mvert = CustomData_get_layer(&me->vdata, CD_MVERT);
const MVert *mvert = CustomData_get_layer(&me->vdata, CD_MVERT);
looptri = MEM_mallocN(sizeof(*looptri) * tottri, __func__);
triangles = MEM_callocN(sizeof(TriTessFace) * tottri, __func__);
@@ -480,6 +477,8 @@ static TriTessFace *mesh_calc_tri_tessface(Mesh *me, bool tangent, Mesh *me_eval
BKE_mesh_recalc_looptri(me->mloop, me->mpoly, me->mvert, me->totloop, me->totpoly, looptri);
}
const TSpace *tspace = NULL;
const float(*loop_normals)[3] = NULL;
if (tangent) {
BKE_mesh_ensure_normals_for_display(me_eval);
BKE_mesh_calc_normals_split(me_eval);

View File

@@ -492,11 +492,11 @@ static void generate_margin(ImBuf *ibuf,
MPoly *mpoly;
MLoop *mloop;
MLoopUV const *mloopuv;
const MLoopUV *mloopuv;
int totpoly, totloop, totedge;
int tottri;
MLoopTri const *looptri;
const MLoopTri *looptri;
MLoopTri *looptri_mem = nullptr;
if (me) {

View File

@@ -323,13 +323,12 @@ static void pointdensity_cache_vertex_weight(PointDensity *pd,
float *data_color)
{
const int totvert = mesh->totvert;
const MDeformVert *mdef, *dv;
int mdef_index;
int i;
BLI_assert(data_color);
mdef = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
const MDeformVert *mdef = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
if (!mdef) {
return;
}
@@ -341,6 +340,7 @@ static void pointdensity_cache_vertex_weight(PointDensity *pd,
return;
}
const MDeformVert *dv;
for (i = 0, dv = mdef; i < totvert; i++, dv++, data_color += 3) {
MDeformWeight *dw;
int j;