Cleanup: Use mesh helper functions to access vertex group data
This commit is contained in:
@@ -559,15 +559,12 @@ static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[
|
||||
else if (mesh_eval) {
|
||||
const blender::Span<blender::float3> positions = mesh_eval->vert_positions();
|
||||
const blender::Span<blender::float3> vert_normals = mesh_eval->vert_normals();
|
||||
const MDeformVert *dvert = static_cast<const MDeformVert *>(
|
||||
CustomData_get_layer(&mesh_eval->vert_data, CD_MDEFORMVERT));
|
||||
|
||||
const blender::Span<MDeformVert> dverts = mesh_eval->deform_verts();
|
||||
/* check that dvert is a valid pointers (just in case) */
|
||||
if (dvert) {
|
||||
|
||||
if (!dverts.is_empty()) {
|
||||
/* get the average of all verts with that are in the vertex-group */
|
||||
for (const int i : positions.index_range()) {
|
||||
const MDeformVert *dv = &dvert[i];
|
||||
const MDeformVert *dv = &dverts[i];
|
||||
const MDeformWeight *dw = BKE_defvert_find_index(dv, defgroup);
|
||||
|
||||
if (dw && dw->weight > 0.0f) {
|
||||
|
||||
@@ -584,7 +584,7 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(ListBase *r_map
|
||||
/* Create as much data layers as necessary! */
|
||||
for (; idx_dst < idx_src; idx_dst++) {
|
||||
CustomData_add_layer(
|
||||
&cd_dst, eCustomDataType(cddata_type), CD_SET_DEFAULT, num_elem_dst);
|
||||
&cd_dst, eCustomDataType(cddata_type), CD_SET_DEFAULT, num_elem_dst);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -637,7 +637,7 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(ListBase *r_map
|
||||
if (idx_dst == -1) {
|
||||
if (use_create) {
|
||||
CustomData_add_layer_named(
|
||||
&cd_dst, eCustomDataType(cddata_type), CD_SET_DEFAULT, num_elem_dst, name);
|
||||
&cd_dst, eCustomDataType(cddata_type), CD_SET_DEFAULT, num_elem_dst, name);
|
||||
idx_dst = CustomData_get_named_layer(&cd_dst, cddata_type, name);
|
||||
}
|
||||
else {
|
||||
@@ -716,7 +716,7 @@ static bool data_transfer_layersmapping_cdlayers(ListBase *r_map,
|
||||
return true;
|
||||
}
|
||||
data_dst = CustomData_add_layer(
|
||||
&cd_dst, eCustomDataType(cddata_type), CD_SET_DEFAULT, num_elem_dst);
|
||||
&cd_dst, eCustomDataType(cddata_type), CD_SET_DEFAULT, num_elem_dst);
|
||||
}
|
||||
|
||||
if (r_map) {
|
||||
@@ -761,7 +761,7 @@ static bool data_transfer_layersmapping_cdlayers(ListBase *r_map,
|
||||
return true;
|
||||
}
|
||||
data_dst = CustomData_add_layer(
|
||||
&cd_dst, eCustomDataType(cddata_type), CD_SET_DEFAULT, num_elem_dst);
|
||||
&cd_dst, eCustomDataType(cddata_type), CD_SET_DEFAULT, num_elem_dst);
|
||||
}
|
||||
else {
|
||||
data_dst = CustomData_get_layer_n_for_write(&cd_dst, cddata_type, idx_dst, num_elem_dst);
|
||||
@@ -790,7 +790,7 @@ static bool data_transfer_layersmapping_cdlayers(ListBase *r_map,
|
||||
return true;
|
||||
}
|
||||
CustomData_add_layer_named(
|
||||
&cd_dst, eCustomDataType(cddata_type), CD_SET_DEFAULT, num_elem_dst, name);
|
||||
&cd_dst, eCustomDataType(cddata_type), CD_SET_DEFAULT, num_elem_dst, name);
|
||||
idx_dst = CustomData_get_named_layer(&cd_dst, cddata_type, name);
|
||||
}
|
||||
data_dst = CustomData_get_layer_n_for_write(&cd_dst, cddata_type, idx_dst, num_elem_dst);
|
||||
@@ -870,13 +870,13 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
|
||||
SpaceTransform *space_transform)
|
||||
{
|
||||
using namespace blender;
|
||||
|
||||
|
||||
cd_datatransfer_interp interp = nullptr;
|
||||
void *interp_data = nullptr;
|
||||
|
||||
if (elem_type == ME_VERT) {
|
||||
if (!(cddata_type & CD_FAKE)) {
|
||||
if (!data_transfer_layersmapping_cdlayers(r_map,
|
||||
if (!data_transfer_layersmapping_cdlayers(r_map,
|
||||
eCustomDataType(cddata_type),
|
||||
mix_mode,
|
||||
mix_factor,
|
||||
@@ -898,20 +898,20 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
|
||||
}
|
||||
if (cddata_type == CD_FAKE_MDEFORMVERT) {
|
||||
return data_transfer_layersmapping_vgroups(r_map,
|
||||
mix_mode,
|
||||
mix_factor,
|
||||
mix_weights,
|
||||
num_elem_dst,
|
||||
use_create,
|
||||
use_delete,
|
||||
ob_src,
|
||||
ob_dst,
|
||||
me_src->vert_data,
|
||||
mix_mode,
|
||||
mix_factor,
|
||||
mix_weights,
|
||||
num_elem_dst,
|
||||
use_create,
|
||||
use_delete,
|
||||
ob_src,
|
||||
ob_dst,
|
||||
me_src->vert_data,
|
||||
me_dst->vert_data,
|
||||
me_dst != ob_dst->data,
|
||||
fromlayers,
|
||||
tolayers);
|
||||
}
|
||||
me_dst != ob_dst->data,
|
||||
fromlayers,
|
||||
tolayers);
|
||||
}
|
||||
if (cddata_type == CD_FAKE_SHAPEKEY) {
|
||||
/* TODO: leaving shape-keys aside for now, quite specific case,
|
||||
* since we can't access them from mesh vertices :/ */
|
||||
@@ -941,7 +941,7 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
|
||||
}
|
||||
else if (elem_type == ME_EDGE) {
|
||||
if (!(cddata_type & CD_FAKE)) { /* Unused for edges, currently... */
|
||||
if (!data_transfer_layersmapping_cdlayers(r_map,
|
||||
if (!data_transfer_layersmapping_cdlayers(r_map,
|
||||
eCustomDataType(cddata_type),
|
||||
mix_mode,
|
||||
mix_factor,
|
||||
@@ -1071,7 +1071,7 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
|
||||
}
|
||||
|
||||
if (!(cddata_type & CD_FAKE)) {
|
||||
if (!data_transfer_layersmapping_cdlayers(r_map,
|
||||
if (!data_transfer_layersmapping_cdlayers(r_map,
|
||||
eCustomDataType(cddata_type),
|
||||
mix_mode,
|
||||
mix_factor,
|
||||
@@ -1100,7 +1100,7 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
|
||||
}
|
||||
|
||||
if (!(cddata_type & CD_FAKE)) {
|
||||
if (!data_transfer_layersmapping_cdlayers(r_map,
|
||||
if (!data_transfer_layersmapping_cdlayers(r_map,
|
||||
eCustomDataType(cddata_type),
|
||||
mix_mode,
|
||||
mix_factor,
|
||||
@@ -1347,8 +1347,7 @@ bool BKE_object_data_transfer_ex(Depsgraph *depsgraph,
|
||||
}
|
||||
|
||||
if (vgroup_name) {
|
||||
mdef = static_cast<const MDeformVert *>(
|
||||
CustomData_get_layer(&me_dst->vert_data, CD_MDEFORMVERT));
|
||||
mdef = me_dst->deform_verts().data();
|
||||
if (mdef) {
|
||||
vg_idx = BKE_id_defgroup_name_index(&me_dst->id, vgroup_name);
|
||||
}
|
||||
|
||||
@@ -2007,18 +2007,13 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object *
|
||||
/* vertex group paint */
|
||||
else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
|
||||
int defgrp_index = BKE_object_defgroup_name_index(ob, surface->output_name);
|
||||
MDeformVert *dvert = static_cast<MDeformVert *>(CustomData_get_layer_for_write(
|
||||
&result->vert_data, CD_MDEFORMVERT, result->verts_num));
|
||||
float *weight = (float *)sData->type_data;
|
||||
|
||||
/* apply weights into a vertex group, if doesn't exists add a new layer */
|
||||
if (defgrp_index != -1 && !dvert && (surface->output_name[0] != '\0')) {
|
||||
dvert = static_cast<MDeformVert *>(CustomData_add_layer(
|
||||
&result->vert_data, CD_MDEFORMVERT, CD_SET_DEFAULT, sData->total_points));
|
||||
}
|
||||
if (defgrp_index != -1 && dvert) {
|
||||
blender::MutableSpan<MDeformVert> dverts = result->deform_verts_for_write();
|
||||
if (defgrp_index != -1) {
|
||||
for (int i = 0; i < sData->total_points; i++) {
|
||||
MDeformVert *dv = &dvert[i];
|
||||
MDeformVert *dv = &dverts[i];
|
||||
MDeformWeight *def_weight = BKE_defvert_find_index(dv, defgrp_index);
|
||||
|
||||
/* skip if weight value is 0 and no existing weight is found */
|
||||
|
||||
@@ -362,8 +362,7 @@ static void lattice_deform_coords_impl(const Object *ob_lattice,
|
||||
cd_dvert_offset = CustomData_get_offset(&em_target->bm->vdata, CD_MDEFORMVERT);
|
||||
}
|
||||
else if (me_target) {
|
||||
dvert = static_cast<const MDeformVert *>(
|
||||
CustomData_get_layer(&me_target->vert_data, CD_MDEFORMVERT));
|
||||
dvert = me_target->deform_verts().data();
|
||||
}
|
||||
else if (ob_target->type == OB_LATTICE) {
|
||||
dvert = ((Lattice *)ob_target->data)->dvert;
|
||||
|
||||
@@ -445,7 +445,7 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
|
||||
|
||||
/* handle vgroup stuff */
|
||||
if (BKE_object_supports_vertex_groups(ob)) {
|
||||
if ((mmd->flag & MOD_MIR_VGROUP) && CustomData_has_layer(&result->vert_data, CD_MDEFORMVERT)) {
|
||||
if ((mmd->flag & MOD_MIR_VGROUP) && !result->deform_verts().is_empty()) {
|
||||
MDeformVert *dvert = result->deform_verts_for_write().data() + src_verts_num;
|
||||
int flip_map_len = 0;
|
||||
int *flip_map = BKE_object_defgroup_flip_map(ob, false, &flip_map_len);
|
||||
|
||||
@@ -2796,7 +2796,7 @@ static Object *modifier_skin_armature_create(Depsgraph *depsgraph, Main *bmain,
|
||||
const Span<float3> positions_eval = me_eval_deform->vert_positions();
|
||||
|
||||
/* add vertex weights to original mesh */
|
||||
CustomData_add_layer(&mesh->vert_data, CD_MDEFORMVERT, CD_SET_DEFAULT, mesh->verts_num);
|
||||
mesh->deform_verts_for_write();
|
||||
|
||||
Scene *scene = DEG_get_input_scene(depsgraph);
|
||||
ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include "BKE_colortools.hh" /* CurveMapping. */
|
||||
#include "BKE_context.hh"
|
||||
#include "BKE_customdata.hh"
|
||||
#include "BKE_deform.hh"
|
||||
#include "BKE_modifier.hh"
|
||||
#include "BKE_texture.h" /* Texture masking. */
|
||||
@@ -212,8 +211,7 @@ void weightvg_do_mask(const ModifierEvalContext *ctx,
|
||||
|
||||
/* Proceed only if vgroup is valid, else use constant factor. */
|
||||
/* Get actual deform-verts (ie vertex group data). */
|
||||
const MDeformVert *dvert = static_cast<const MDeformVert *>(
|
||||
CustomData_get_layer(&mesh->vert_data, CD_MDEFORMVERT));
|
||||
const MDeformVert *dvert = mesh->deform_verts().data();
|
||||
/* Proceed only if vgroup is valid, else assume factor = O. */
|
||||
if (dvert == nullptr) {
|
||||
return;
|
||||
|
||||
@@ -186,7 +186,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh
|
||||
return mesh;
|
||||
}
|
||||
|
||||
const bool has_mdef = CustomData_has_layer(&mesh->vert_data, CD_MDEFORMVERT);
|
||||
const bool has_mdef = !mesh->deform_verts().is_empty();
|
||||
/* If no vertices were ever added to an object's vgroup, dvert might be nullptr. */
|
||||
if (!has_mdef) {
|
||||
/* If this modifier is not allowed to add vertices, just return. */
|
||||
|
||||
@@ -250,7 +250,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh
|
||||
}
|
||||
}
|
||||
|
||||
const bool has_mdef = CustomData_has_layer(&mesh->vert_data, CD_MDEFORMVERT);
|
||||
const bool has_mdef = !mesh->deform_verts().is_empty();
|
||||
/* If no vertices were ever added to an object's vgroup, dvert might be nullptr. */
|
||||
if (!has_mdef) {
|
||||
/* If not affecting all vertices, just return. */
|
||||
|
||||
@@ -460,7 +460,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh
|
||||
if (defgrp_index == -1) {
|
||||
return mesh;
|
||||
}
|
||||
const bool has_mdef = CustomData_has_layer(&mesh->vert_data, CD_MDEFORMVERT);
|
||||
const bool has_mdef = !mesh->deform_verts().is_empty();
|
||||
/* If no vertices were ever added to an object's vgroup, dvert might be nullptr. */
|
||||
/* As this modifier never add vertices to vgroup, just return. */
|
||||
if (!has_mdef) {
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "DNA_screen_types.h"
|
||||
|
||||
#include "BKE_context.hh"
|
||||
#include "BKE_customdata.hh"
|
||||
#include "BKE_deform.hh"
|
||||
#include "BKE_modifier.hh"
|
||||
#include "BKE_screen.hh"
|
||||
@@ -55,12 +54,7 @@ static Span<MDeformVert> get_vertex_group(const Mesh &mesh, const int defgrp_ind
|
||||
if (defgrp_index == -1) {
|
||||
return {};
|
||||
}
|
||||
const MDeformVert *vertex_group = static_cast<const MDeformVert *>(
|
||||
CustomData_get_layer(&mesh.vert_data, CD_MDEFORMVERT));
|
||||
if (!vertex_group) {
|
||||
return {};
|
||||
}
|
||||
return {vertex_group, mesh.verts_num};
|
||||
return mesh.deform_verts();
|
||||
}
|
||||
|
||||
static IndexMask selected_indices_from_vertex_group(Span<MDeformVert> vertex_group,
|
||||
|
||||
Reference in New Issue
Block a user