Cleanup: Use C++ types for modifier type deform callbacks

This commit is contained in:
Hans Goudey
2023-11-14 10:54:57 +01:00
parent 805e6b7525
commit 8f5ff2c5dd
34 changed files with 292 additions and 279 deletions

View File

@@ -6,10 +6,12 @@
/** \file
* \ingroup bke
*/
#include "BLI_compiler_attrs.h"
#include "BLI_math_matrix_types.hh"
#include "DNA_modifier_types.h" /* needed for all enum typdefs */
#include "BKE_customdata.h"
#include "BLI_compiler_attrs.h"
#include "DNA_modifier_types.h" /* needed for all enum typdefs */
namespace blender::bke {
struct GeometrySet;
@@ -188,8 +190,7 @@ struct ModifierTypeInfo {
void (*deform_verts)(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int numVerts);
blender::MutableSpan<blender::float3> positions);
/**
* Like deform_matrices_EM but called from object mode (for supporting modifiers in sculpt mode).
@@ -197,9 +198,8 @@ struct ModifierTypeInfo {
void (*deform_matrices)(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
float (*defMats)[3][3],
int numVerts);
blender::MutableSpan<blender::float3> positions,
blender::MutableSpan<blender::float3x3> matrices);
/**
* Like deform_verts but called during edit-mode if supported. The \a mesh argument might be a
* wrapper around edit BMesh data.
@@ -208,17 +208,15 @@ struct ModifierTypeInfo {
const ModifierEvalContext *ctx,
BMEditMesh *em,
Mesh *mesh,
float (*vertexCos)[3],
int numVerts);
blender::MutableSpan<blender::float3> positions);
/* Set deform matrix per vertex for crazy-space correction */
void (*deform_matrices_EM)(ModifierData *md,
const ModifierEvalContext *ctx,
BMEditMesh *em,
Mesh *mesh,
float (*vertexCos)[3],
float (*defMats)[3][3],
int numVerts);
blender::MutableSpan<blender::float3> positions,
blender::MutableSpan<blender::float3x3> matrices);
/********************* Non-deform modifier functions *********************/
@@ -557,15 +555,13 @@ Mesh *BKE_modifier_modify_mesh(ModifierData *md, const ModifierEvalContext *ctx,
void BKE_modifier_deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *me,
float (*vertexCos)[3],
int numVerts);
blender::MutableSpan<blender::float3> positions);
void BKE_modifier_deform_vertsEM(ModifierData *md,
const ModifierEvalContext *ctx,
BMEditMesh *em,
Mesh *me,
float (*vertexCos)[3],
int numVerts);
blender::MutableSpan<blender::float3> positions);
/**
* Get evaluated mesh for other evaluated object, which is used as an operand for the modifier,

View File

@@ -658,12 +658,7 @@ static void mesh_calc_modifiers(Depsgraph *depsgraph,
}
}
BKE_modifier_deform_verts(
md,
&mectx,
mesh_final,
reinterpret_cast<float(*)[3]>(mesh_final->vert_positions_for_write().data()),
mesh_final->totvert);
BKE_modifier_deform_verts(md, &mectx, mesh_final, mesh_final->vert_positions_for_write());
}
else {
break;
@@ -748,12 +743,7 @@ static void mesh_calc_modifiers(Depsgraph *depsgraph,
mesh_final = BKE_mesh_copy_for_eval(mesh_input);
ASSERT_IS_VALID_MESH(mesh_final);
}
BKE_modifier_deform_verts(
md,
&mectx,
mesh_final,
reinterpret_cast<float(*)[3]>(mesh_final->vert_positions_for_write().data()),
mesh_final->totvert);
BKE_modifier_deform_verts(md, &mectx, mesh_final, mesh_final->vert_positions_for_write());
}
else {
bool check_for_needs_mapping = false;
@@ -1179,24 +1169,17 @@ static void editbmesh_calc_modifiers(Depsgraph *depsgraph,
if (mti->type == ModifierTypeType::OnlyDeform) {
if (mti->deform_verts_EM) {
BKE_modifier_deform_vertsEM(
md,
&mectx,
em_input,
mesh_final,
reinterpret_cast<float(*)[3]>(
mesh_wrapper_vert_coords_ensure_for_write(mesh_final).data()),
BKE_mesh_wrapper_vert_len(mesh_final));
BKE_modifier_deform_vertsEM(md,
&mectx,
em_input,
mesh_final,
mesh_wrapper_vert_coords_ensure_for_write(mesh_final));
BKE_mesh_wrapper_tag_positions_changed(mesh_final);
}
else {
BKE_mesh_wrapper_ensure_mdata(mesh_final);
BKE_modifier_deform_verts(
md,
&mectx,
mesh_final,
reinterpret_cast<float(*)[3]>(mesh_final->vert_positions_for_write().data()),
mesh_final->totvert);
BKE_modifier_deform_verts(md, &mectx, mesh_final, mesh_final->vert_positions_for_write());
BKE_mesh_tag_positions_changed(mesh_final);
}
}

View File

@@ -289,7 +289,12 @@ int BKE_crazyspace_get_first_deform_matrices_editbmesh(Depsgraph *depsgraph,
unit_m3(defmats[a]);
}
}
mti->deform_matrices_EM(md, &mectx, em, me, deformedVerts, defmats, verts_num);
mti->deform_matrices_EM(md,
&mectx,
em,
me,
{reinterpret_cast<blender::float3 *>(deformedVerts), verts_num},
{reinterpret_cast<blender::float3x3 *>(defmats), verts_num});
}
else {
break;
@@ -402,7 +407,12 @@ int BKE_sculpt_get_first_deform_matrices(Depsgraph *depsgraph,
}
if (mti->deform_matrices) {
mti->deform_matrices(md, &mectx, me_eval, deformedVerts, defmats, me_eval->totvert);
mti->deform_matrices(
md,
&mectx,
me_eval,
{reinterpret_cast<blender::float3 *>(deformedVerts), me_eval->totvert},
{reinterpret_cast<blender::float3x3 *>(defmats), me_eval->totvert});
}
else {
/* More complex handling will continue in BKE_crazyspace_build_sculpt.
@@ -482,7 +492,11 @@ void BKE_crazyspace_build_sculpt(Depsgraph *depsgraph,
mesh_eval = BKE_mesh_copy_for_eval(mesh);
}
mti->deform_verts(md, &mectx, mesh_eval, deformedVerts, mesh_eval->totvert);
mti->deform_verts(
md,
&mectx,
mesh_eval,
{reinterpret_cast<blender::float3 *>(deformedVerts), mesh_eval->totvert});
deformed = 1;
}
}

View File

@@ -619,7 +619,8 @@ void BKE_curve_calc_modifiers_pre(Depsgraph *depsgraph,
deformedVerts = BKE_curve_nurbs_vert_coords_alloc(source_nurb, &numVerts);
}
mti->deform_verts(md, &mectx, nullptr, deformedVerts, numVerts);
mti->deform_verts(
md, &mectx, nullptr, {reinterpret_cast<blender::float3 *>(deformedVerts), numVerts});
if (md == pretessellatePoint) {
break;
@@ -741,11 +742,7 @@ static blender::bke::GeometrySet curve_calc_modifiers_post(Depsgraph *depsgraph,
Mesh *mesh = geometry_set.get_mesh_for_write();
if (mti->type == ModifierTypeType::OnlyDeform) {
mti->deform_verts(md,
&mectx_deform,
mesh,
reinterpret_cast<float(*)[3]>(mesh->vert_positions_for_write().data()),
mesh->totvert);
mti->deform_verts(md, &mectx_deform, mesh, mesh->vert_positions_for_write());
BKE_mesh_tag_positions_changed(mesh);
}
else {

View File

@@ -545,7 +545,8 @@ void BKE_lattice_modifiers_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
vert_coords = BKE_lattice_vert_coords_alloc(effective_lattice, &numVerts);
}
mti->deform_verts(md, &mectx, nullptr, vert_coords, numVerts);
mti->deform_verts(
md, &mectx, nullptr, {reinterpret_cast<blender::float3 *>(vert_coords), numVerts});
}
if (vert_coords == nullptr) {

View File

@@ -1006,14 +1006,13 @@ Mesh *BKE_modifier_modify_mesh(ModifierData *md, const ModifierEvalContext *ctx,
void BKE_modifier_deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *me,
float (*vertexCos)[3],
int numVerts)
blender::MutableSpan<blender::float3> positions)
{
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
if (me && mti->depends_on_normals && mti->depends_on_normals(md)) {
modwrap_dependsOnNormals(me);
}
mti->deform_verts(md, ctx, me, vertexCos, numVerts);
mti->deform_verts(md, ctx, me, positions);
if (me) {
BKE_mesh_tag_positions_changed(me);
}
@@ -1023,14 +1022,13 @@ void BKE_modifier_deform_vertsEM(ModifierData *md,
const ModifierEvalContext *ctx,
BMEditMesh *em,
Mesh *me,
float (*vertexCos)[3],
int numVerts)
blender::MutableSpan<blender::float3> positions)
{
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
if (me && mti->depends_on_normals && mti->depends_on_normals(md)) {
modwrap_dependsOnNormals(me);
}
mti->deform_verts_EM(md, ctx, em, me, vertexCos, numVerts);
mti->deform_verts_EM(md, ctx, em, me, positions);
}
/* end modifier callback wrappers */

View File

@@ -288,7 +288,10 @@ float (*BKE_multires_create_deformed_base_mesh_vert_coords(
}
BKE_modifier_deform_verts(
md, &mesh_eval_context, base_mesh, deformed_verts, num_deformed_verts);
md,
&mesh_eval_context,
base_mesh,
{reinterpret_cast<blender::float3 *>(deformed_verts), num_deformed_verts});
}
if (r_num_deformed_verts != nullptr) {

View File

@@ -107,7 +107,10 @@ bool multiresModifier_reshapeFromDeformModifier(Depsgraph *depsgraph,
modifier_ctx.flag = MOD_APPLY_USECACHE | MOD_APPLY_IGNORE_SIMPLIFY;
BKE_modifier_deform_verts(
deform_md, &modifier_ctx, multires_mesh, deformed_verts, multires_mesh->totvert);
deform_md,
&modifier_ctx,
multires_mesh,
{reinterpret_cast<blender::float3 *>(deformed_verts), num_deformed_verts});
BKE_id_free(nullptr, multires_mesh);
/* Reshaping */

View File

@@ -780,9 +780,7 @@ static Mesh *create_applied_mesh_for_modifier(Depsgraph *depsgraph,
Mesh *mesh_temp = reinterpret_cast<Mesh *>(
BKE_id_copy_ex(nullptr, &me->id, nullptr, LIB_ID_COPY_LOCALIZE));
const int numVerts = mesh_temp->totvert;
float(*deformedVerts)[3] = reinterpret_cast<float(*)[3]>(
mesh_temp->vert_positions_for_write().data());
MutableSpan<float3> deformedVerts = mesh_temp->vert_positions_for_write();
if (use_virtual_modifiers) {
VirtualModifierData virtual_modifier_data;
@@ -801,14 +799,14 @@ static Mesh *create_applied_mesh_for_modifier(Depsgraph *depsgraph,
continue;
}
mti_virt->deform_verts(md_eval_virt, &mectx, mesh_temp, deformedVerts, numVerts);
mti_virt->deform_verts(md_eval_virt, &mectx, mesh_temp, deformedVerts);
}
}
Mesh *result = nullptr;
if (mti->type == ModifierTypeType::OnlyDeform) {
result = mesh_temp;
mti->deform_verts(md_eval, &mectx, result, deformedVerts, numVerts);
mti->deform_verts(md_eval, &mectx, result, deformedVerts);
BKE_mesh_tag_positions_changed(result);
if (build_shapekey_layers) {
@@ -1022,7 +1020,8 @@ static bool modifier_apply_obdata(
int verts_num;
float(*vertexCos)[3] = BKE_curve_nurbs_vert_coords_alloc(&curve_eval->nurb, &verts_num);
mti->deform_verts(md_eval, &mectx, nullptr, vertexCos, verts_num);
mti->deform_verts(
md_eval, &mectx, nullptr, {reinterpret_cast<float3 *>(vertexCos), verts_num});
BKE_curve_nurbs_vert_coords_apply(&curve->nurb, vertexCos, false);
MEM_freeN(vertexCos);
@@ -1041,7 +1040,8 @@ static bool modifier_apply_obdata(
int verts_num;
float(*vertexCos)[3] = BKE_lattice_vert_coords_alloc(lattice, &verts_num);
mti->deform_verts(md_eval, &mectx, nullptr, vertexCos, verts_num);
mti->deform_verts(
md_eval, &mectx, nullptr, {reinterpret_cast<float3 *>(vertexCos), verts_num});
BKE_lattice_vert_coords_apply(lattice, vertexCos);
MEM_freeN(vertexCos);

View File

@@ -126,18 +126,18 @@ static void update_depsgraph(ModifierData *md, const ModifierUpdateDepsgraphCont
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
ArmatureModifierData *amd = (ArmatureModifierData *)md;
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
/* if next modifier needs original vertices */
MOD_previous_vcos_store(md, reinterpret_cast<float(*)[3]>(positions.data()));
BKE_armature_deform_coords_with_mesh(amd->object,
ctx->object,
vertexCos,
reinterpret_cast<float(*)[3]>(positions.data()),
nullptr,
verts_num,
positions.size(),
amd->deformflag,
amd->vert_coords_prev,
amd->defgrp_name,
@@ -151,23 +151,23 @@ static void deform_verts_EM(ModifierData *md,
const ModifierEvalContext *ctx,
BMEditMesh *em,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
if (mesh->runtime->wrapper_type == ME_WRAPPER_TYPE_MDATA) {
deform_verts(md, ctx, mesh, vertexCos, verts_num);
deform_verts(md, ctx, mesh, positions);
return;
}
ArmatureModifierData *amd = (ArmatureModifierData *)md;
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
/* if next modifier needs original vertices */
MOD_previous_vcos_store(md, reinterpret_cast<float(*)[3]>(positions.data()));
BKE_armature_deform_coords_with_editmesh(amd->object,
ctx->object,
vertexCos,
reinterpret_cast<float(*)[3]>(positions.data()),
nullptr,
verts_num,
positions.size(),
amd->deformflag,
amd->vert_coords_prev,
amd->defgrp_name,
@@ -181,17 +181,16 @@ static void deform_matrices_EM(ModifierData *md,
const ModifierEvalContext *ctx,
BMEditMesh *em,
Mesh * /*mesh*/,
float (*vertexCos)[3],
float (*defMats)[3][3],
int verts_num)
blender::MutableSpan<blender::float3> positions,
blender::MutableSpan<blender::float3x3> matrices)
{
ArmatureModifierData *amd = (ArmatureModifierData *)md;
BKE_armature_deform_coords_with_editmesh(amd->object,
ctx->object,
vertexCos,
defMats,
verts_num,
reinterpret_cast<float(*)[3]>(positions.data()),
reinterpret_cast<float(*)[3][3]>(matrices.data()),
positions.size(),
amd->deformflag,
nullptr,
amd->defgrp_name,
@@ -201,16 +200,15 @@ static void deform_matrices_EM(ModifierData *md,
static void deform_matrices(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
float (*defMats)[3][3],
int verts_num)
blender::MutableSpan<blender::float3> positions,
blender::MutableSpan<blender::float3x3> matrices)
{
ArmatureModifierData *amd = (ArmatureModifierData *)md;
BKE_armature_deform_coords_with_mesh(amd->object,
ctx->object,
vertexCos,
defMats,
verts_num,
reinterpret_cast<float(*)[3]>(positions.data()),
reinterpret_cast<float(*)[3][3]>(matrices.data()),
positions.size(),
amd->deformflag,
nullptr,
amd->defgrp_name,

View File

@@ -93,8 +93,7 @@ static void sphere_do(CastModifierData *cmd,
const ModifierEvalContext * /*ctx*/,
Object *ob,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
const MDeformVert *dvert = nullptr;
const bool invert_vgroup = (cmd->flag & MOD_CAST_INVERT_VGROUP) != 0;
@@ -157,20 +156,20 @@ static void sphere_do(CastModifierData *cmd,
}
if (len <= 0) {
for (i = 0; i < verts_num; i++) {
len += len_v3v3(center, vertexCos[i]);
for (i = 0; i < positions.size(); i++) {
len += len_v3v3(center, positions[i]);
}
len /= verts_num;
len /= positions.size();
if (len == 0.0f) {
len = 10.0f;
}
}
for (i = 0; i < verts_num; i++) {
for (i = 0; i < positions.size(); i++) {
float tmp_co[3];
copy_v3_v3(tmp_co, vertexCos[i]);
copy_v3_v3(tmp_co, positions[i]);
if (ctrl_ob) {
if (flag & MOD_CAST_USE_OB_TRANSFORM) {
mul_m4_v3(mat, tmp_co);
@@ -226,7 +225,7 @@ static void sphere_do(CastModifierData *cmd,
}
}
copy_v3_v3(vertexCos[i], tmp_co);
copy_v3_v3(positions[i], tmp_co);
}
}
@@ -234,8 +233,7 @@ static void cuboid_do(CastModifierData *cmd,
const ModifierEvalContext * /*ctx*/,
Object *ob,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
const MDeformVert *dvert = nullptr;
int defgrp_index;
@@ -310,14 +308,14 @@ static void cuboid_do(CastModifierData *cmd,
/* let the center of the ctrl_ob be part of the bound box: */
minmax_v3v3_v3(min, max, center);
for (i = 0; i < verts_num; i++) {
sub_v3_v3v3(vec, vertexCos[i], center);
for (i = 0; i < positions.size(); i++) {
sub_v3_v3v3(vec, positions[i], center);
minmax_v3v3_v3(min, max, vec);
}
}
else {
for (i = 0; i < verts_num; i++) {
minmax_v3v3_v3(min, max, vertexCos[i]);
for (i = 0; i < positions.size(); i++) {
minmax_v3v3_v3(min, max, positions[i]);
}
}
@@ -345,12 +343,12 @@ static void cuboid_do(CastModifierData *cmd,
bb[4][2] = bb[5][2] = bb[6][2] = bb[7][2] = max[2];
/* ready to apply the effect, one vertex at a time */
for (i = 0; i < verts_num; i++) {
for (i = 0; i < positions.size(); i++) {
int octant, coord;
float d[3], dmax, apex[3], fbb;
float tmp_co[3];
copy_v3_v3(tmp_co, vertexCos[i]);
copy_v3_v3(tmp_co, positions[i]);
if (ctrl_ob) {
if (flag & MOD_CAST_USE_OB_TRANSFORM) {
mul_m4_v3(mat, tmp_co);
@@ -451,23 +449,22 @@ static void cuboid_do(CastModifierData *cmd,
}
}
copy_v3_v3(vertexCos[i], tmp_co);
copy_v3_v3(positions[i], tmp_co);
}
}
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
CastModifierData *cmd = (CastModifierData *)md;
if (cmd->type == MOD_CAST_TYPE_CUBOID) {
cuboid_do(cmd, ctx, ctx->object, mesh, vertexCos, verts_num);
cuboid_do(cmd, ctx, ctx->object, mesh, positions);
}
else { /* MOD_CAST_TYPE_SPHERE or MOD_CAST_TYPE_CYLINDER */
sphere_do(cmd, ctx, ctx->object, mesh, vertexCos, verts_num);
sphere_do(cmd, ctx, ctx->object, mesh, positions);
}
}

View File

@@ -78,8 +78,7 @@ static void init_data(ModifierData *md)
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
ClothModifierData *clmd = (ClothModifierData *)md;
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
@@ -111,13 +110,18 @@ static void deform_verts(ModifierData *md,
CustomData_add_layer(&mesh->vert_data, CD_CLOTH_ORCO, CD_SET_DEFAULT, mesh->totvert));
}
memcpy(layerorco, kb->data, sizeof(float[3]) * verts_num);
memcpy(layerorco, kb->data, sizeof(float[3]) * positions.size());
}
}
BKE_mesh_vert_coords_apply(mesh, vertexCos);
BKE_mesh_vert_coords_apply(mesh, reinterpret_cast<float(*)[3]>(positions.data()));
clothModifier_do(clmd, ctx->depsgraph, scene, ctx->object, mesh, vertexCos);
clothModifier_do(clmd,
ctx->depsgraph,
scene,
ctx->object,
mesh,
reinterpret_cast<float(*)[3]>(positions.data()));
}
static void update_depsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)

View File

@@ -90,8 +90,7 @@ static bool depends_on_time(Scene * /*scene*/, ModifierData * /*md*/)
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int /*verts_num*/)
blender::MutableSpan<blender::float3> positions)
{
CollisionModifierData *collmd = (CollisionModifierData *)md;
Object *ob = ctx->object;
@@ -110,7 +109,7 @@ static void deform_verts(ModifierData *md,
float current_time = 0;
int mvert_num = 0;
BKE_mesh_vert_coords_apply(mesh, vertexCos);
BKE_mesh_vert_coords_apply(mesh, reinterpret_cast<const float(*)[3]>(positions.data()));
current_time = DEG_get_ctime(ctx->depsgraph);

View File

@@ -749,15 +749,9 @@ error:
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
correctivesmooth_modifier_do(md,
ctx->depsgraph,
ctx->object,
mesh,
{reinterpret_cast<blender::float3 *>(vertexCos), verts_num},
nullptr);
correctivesmooth_modifier_do(md, ctx->depsgraph, ctx->object, mesh, positions, nullptr);
}
static void panel_draw(const bContext * /*C*/, Panel *panel)

View File

@@ -102,8 +102,7 @@ static void update_depsgraph(ModifierData *md, const ModifierUpdateDepsgraphCont
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
CurveModifierData *cmd = (CurveModifierData *)md;
@@ -116,8 +115,8 @@ static void deform_verts(ModifierData *md,
BKE_curve_deform_coords(cmd->object,
ctx->object,
vertexCos,
verts_num,
reinterpret_cast<float(*)[3]>(positions.data()),
positions.size(),
dvert,
defgrp_index,
cmd->flag,
@@ -128,11 +127,10 @@ static void deform_verts_EM(ModifierData *md,
const ModifierEvalContext *ctx,
BMEditMesh *em,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
if (mesh->runtime->wrapper_type == ME_WRAPPER_TYPE_MDATA) {
deform_verts(md, ctx, mesh, vertexCos, verts_num);
deform_verts(md, ctx, mesh, positions);
return;
}
@@ -150,8 +148,8 @@ static void deform_verts_EM(ModifierData *md,
if (use_dverts) {
BKE_curve_deform_coords_with_editmesh(cmd->object,
ctx->object,
vertexCos,
verts_num,
reinterpret_cast<float(*)[3]>(positions.data()),
positions.size(),
defgrp_index,
cmd->flag,
cmd->defaxis - 1,
@@ -160,8 +158,8 @@ static void deform_verts_EM(ModifierData *md,
else {
BKE_curve_deform_coords(cmd->object,
ctx->object,
vertexCos,
verts_num,
reinterpret_cast<float(*)[3]>(positions.data()),
positions.size(),
nullptr,
defgrp_index,
cmd->flag,

View File

@@ -156,7 +156,7 @@ struct DisplaceUserdata {
bool use_global_direction;
Tex *tex_target;
float (*tex_co)[3];
float (*vertexCos)[3];
blender::MutableSpan<blender::float3> positions;
float local_mat[4][4];
blender::Span<blender::float3> vert_normals;
float (*vert_clnors)[3];
@@ -175,7 +175,7 @@ static void displaceModifier_do_task(void *__restrict userdata,
int direction = data->direction;
bool use_global_direction = data->use_global_direction;
float(*tex_co)[3] = data->tex_co;
float(*vertexCos)[3] = data->vertexCos;
blender::MutableSpan<blender::float3> positions = data->positions;
float(*vert_clnors)[3] = data->vert_clnors;
/* When no texture is used, we fallback to white. */
@@ -212,32 +212,32 @@ static void displaceModifier_do_task(void *__restrict userdata,
switch (direction) {
case MOD_DISP_DIR_X:
if (use_global_direction) {
vertexCos[iter][0] += delta * data->local_mat[0][0];
vertexCos[iter][1] += delta * data->local_mat[1][0];
vertexCos[iter][2] += delta * data->local_mat[2][0];
positions[iter][0] += delta * data->local_mat[0][0];
positions[iter][1] += delta * data->local_mat[1][0];
positions[iter][2] += delta * data->local_mat[2][0];
}
else {
vertexCos[iter][0] += delta;
positions[iter][0] += delta;
}
break;
case MOD_DISP_DIR_Y:
if (use_global_direction) {
vertexCos[iter][0] += delta * data->local_mat[0][1];
vertexCos[iter][1] += delta * data->local_mat[1][1];
vertexCos[iter][2] += delta * data->local_mat[2][1];
positions[iter][0] += delta * data->local_mat[0][1];
positions[iter][1] += delta * data->local_mat[1][1];
positions[iter][2] += delta * data->local_mat[2][1];
}
else {
vertexCos[iter][1] += delta;
positions[iter][1] += delta;
}
break;
case MOD_DISP_DIR_Z:
if (use_global_direction) {
vertexCos[iter][0] += delta * data->local_mat[0][2];
vertexCos[iter][1] += delta * data->local_mat[1][2];
vertexCos[iter][2] += delta * data->local_mat[2][2];
positions[iter][0] += delta * data->local_mat[0][2];
positions[iter][1] += delta * data->local_mat[1][2];
positions[iter][2] += delta * data->local_mat[2][2];
}
else {
vertexCos[iter][2] += delta;
positions[iter][2] += delta;
}
break;
case MOD_DISP_DIR_RGB_XYZ:
@@ -248,13 +248,13 @@ static void displaceModifier_do_task(void *__restrict userdata,
mul_transposed_mat3_m4_v3(data->local_mat, local_vec);
}
mul_v3_fl(local_vec, strength);
add_v3_v3(vertexCos[iter], local_vec);
add_v3_v3(positions[iter], local_vec);
break;
case MOD_DISP_DIR_NOR:
madd_v3_v3fl(vertexCos[iter], data->vert_normals[iter], delta);
madd_v3_v3fl(positions[iter], data->vert_normals[iter], delta);
break;
case MOD_DISP_DIR_CLNOR:
madd_v3_v3fl(vertexCos[iter], vert_clnors[iter], delta);
madd_v3_v3fl(positions[iter], vert_clnors[iter], delta);
break;
}
}
@@ -262,8 +262,7 @@ static void displaceModifier_do_task(void *__restrict userdata,
static void displaceModifier_do(DisplaceModifierData *dmd,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
const int verts_num)
blender::MutableSpan<blender::float3> positions)
{
Object *ob = ctx->object;
const MDeformVert *dvert;
@@ -291,9 +290,14 @@ static void displaceModifier_do(DisplaceModifierData *dmd,
Tex *tex_target = dmd->texture;
if (tex_target != nullptr) {
tex_co = static_cast<float(*)[3]>(
MEM_calloc_arrayN(size_t(verts_num), sizeof(*tex_co), "displaceModifier_do tex_co"));
MOD_get_texture_coords((MappingInfoModifierData *)dmd, ctx, ob, mesh, vertexCos, tex_co);
tex_co = static_cast<float(*)[3]>(MEM_calloc_arrayN(
size_t(positions.size()), sizeof(*tex_co), "displaceModifier_do tex_co"));
MOD_get_texture_coords((MappingInfoModifierData *)dmd,
ctx,
ob,
mesh,
reinterpret_cast<float(*)[3]>(positions.data()),
tex_co);
MOD_init_texture((MappingInfoModifierData *)dmd, ctx);
}
@@ -304,9 +308,9 @@ static void displaceModifier_do(DisplaceModifierData *dmd,
if (direction == MOD_DISP_DIR_CLNOR) {
if (CustomData_has_layer(&mesh->loop_data, CD_CUSTOMLOOPNORMAL)) {
vert_clnors = static_cast<float(*)[3]>(
MEM_malloc_arrayN(verts_num, sizeof(*vert_clnors), __func__));
MEM_malloc_arrayN(positions.size(), sizeof(*vert_clnors), __func__));
BKE_mesh_normals_loop_to_vertex(
verts_num,
positions.size(),
mesh->corner_verts().data(),
mesh->totloop,
reinterpret_cast<const float(*)[3]>(mesh->corner_normals().data()),
@@ -332,7 +336,7 @@ static void displaceModifier_do(DisplaceModifierData *dmd,
data.use_global_direction = use_global_direction;
data.tex_target = tex_target;
data.tex_co = tex_co;
data.vertexCos = vertexCos;
data.positions = positions;
copy_m4_m4(data.local_mat, local_mat);
if (direction == MOD_DISP_DIR_NOR) {
data.vert_normals = mesh->vert_normals();
@@ -344,8 +348,8 @@ static void displaceModifier_do(DisplaceModifierData *dmd,
}
TaskParallelSettings settings;
BLI_parallel_range_settings_defaults(&settings);
settings.use_threading = (verts_num > 512);
BLI_task_parallel_range(0, verts_num, &data, displaceModifier_do_task, &settings);
settings.use_threading = (positions.size() > 512);
BLI_task_parallel_range(0, positions.size(), &data, displaceModifier_do_task, &settings);
if (data.pool != nullptr) {
BKE_image_pool_free(data.pool);
@@ -363,10 +367,9 @@ static void displaceModifier_do(DisplaceModifierData *dmd,
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
displaceModifier_do((DisplaceModifierData *)md, ctx, mesh, vertexCos, verts_num);
displaceModifier_do((DisplaceModifierData *)md, ctx, mesh, positions);
}
static void panel_draw(const bContext *C, Panel *panel)

View File

@@ -124,7 +124,7 @@ static void update_depsgraph(ModifierData *md, const ModifierUpdateDepsgraphCont
}
struct HookData_cb {
float (*vertexCos)[3];
blender::MutableSpan<blender::float3> positions;
/**
* When anything other than -1, use deform groups.
@@ -232,7 +232,7 @@ static float hook_falloff(const HookData_cb *hd, const float len_sq)
static void hook_co_apply(HookData_cb *hd, int j, const MDeformVert *dv)
{
float *co = hd->vertexCos[j];
float *co = hd->positions[j];
float fac;
if (hd->use_falloff) {
@@ -272,8 +272,7 @@ static void deformVerts_do(HookModifierData *hmd,
Object *ob,
Mesh *mesh,
BMEditMesh *em,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
Object *ob_target = hmd->object;
bPoseChannel *pchan = BKE_pose_channel_find_name(ob_target->pose, hmd->subtarget);
@@ -293,7 +292,7 @@ static void deformVerts_do(HookModifierData *hmd,
}
/* Generic data needed for applying per-vertex calculations (initialize all members) */
hd.vertexCos = vertexCos;
hd.positions = positions;
MOD_get_vgroup(ob, mesh, hmd->name, &dvert, &hd.defgrp_index);
int cd_dvert_offset = -1;
@@ -365,13 +364,13 @@ static void deformVerts_do(HookModifierData *hmd,
if (mesh && (origindex_ar = static_cast<const int *>(
CustomData_get_layer(&mesh->vert_data, CD_ORIGINDEX))))
{
int verts_orig_num = verts_num;
int verts_orig_num = positions.size();
if (ob->type == OB_MESH) {
const Mesh *me_orig = static_cast<const Mesh *>(ob->data);
verts_orig_num = me_orig->totvert;
}
BLI_bitmap *indexar_used = hook_index_array_to_bitmap(hmd, verts_orig_num);
for (i = 0; i < verts_num; i++) {
for (i = 0; i < positions.size(); i++) {
int i_orig = origindex_ar[i];
BLI_assert(i_orig < verts_orig_num);
if (BLI_BITMAP_TEST(indexar_used, i_orig)) {
@@ -382,8 +381,8 @@ static void deformVerts_do(HookModifierData *hmd,
}
else { /* missing mesh or ORIGINDEX */
if ((em != nullptr) && (hd.defgrp_index != -1)) {
BLI_assert(em->bm->totvert == verts_num);
BLI_bitmap *indexar_used = hook_index_array_to_bitmap(hmd, verts_num);
BLI_assert(em->bm->totvert == positions.size());
BLI_bitmap *indexar_used = hook_index_array_to_bitmap(hmd, positions.size());
BMIter iter;
BMVert *v;
BM_ITER_MESH_INDEX (v, &iter, em->bm, BM_VERTS_OF_MESH, i) {
@@ -398,7 +397,7 @@ static void deformVerts_do(HookModifierData *hmd,
else {
for (i = 0, index_pt = hmd->indexar; i < hmd->indexar_num; i++, index_pt++) {
const int j = *index_pt;
if (j < verts_num) {
if (j < positions.size()) {
hook_co_apply(&hd, j, dvert ? &dvert[j] : nullptr);
}
}
@@ -407,7 +406,7 @@ static void deformVerts_do(HookModifierData *hmd,
}
else if (hd.defgrp_index != -1) { /* vertex group hook */
if (em != nullptr) {
BLI_assert(em->bm->totvert == verts_num);
BLI_assert(em->bm->totvert == positions.size());
BMIter iter;
BMVert *v;
BM_ITER_MESH_INDEX (v, &iter, em->bm, BM_VERTS_OF_MESH, i) {
@@ -418,7 +417,7 @@ static void deformVerts_do(HookModifierData *hmd,
}
else {
BLI_assert(dvert != nullptr);
for (i = 0; i < verts_num; i++) {
for (i = 0; i < positions.size(); i++) {
hook_co_apply(&hd, i, &dvert[i]);
}
}
@@ -428,19 +427,17 @@ static void deformVerts_do(HookModifierData *hmd,
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
HookModifierData *hmd = (HookModifierData *)md;
deformVerts_do(hmd, ctx, ctx->object, mesh, nullptr, vertexCos, verts_num);
deformVerts_do(hmd, ctx, ctx->object, mesh, nullptr, positions);
}
static void deform_verts_EM(ModifierData *md,
const ModifierEvalContext *ctx,
BMEditMesh *em,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
HookModifierData *hmd = (HookModifierData *)md;
@@ -449,8 +446,7 @@ static void deform_verts_EM(ModifierData *md,
ctx->object,
mesh,
mesh->runtime->wrapper_type == ME_WRAPPER_TYPE_BMESH ? em : nullptr,
vertexCos,
verts_num);
positions);
}
static void panel_draw(const bContext * /*C*/, Panel *panel)

View File

@@ -747,11 +747,13 @@ static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
LaplacianDeformModifier_do(
(LaplacianDeformModifierData *)md, ctx->object, mesh, vertexCos, verts_num);
LaplacianDeformModifier_do((LaplacianDeformModifierData *)md,
ctx->object,
mesh,
reinterpret_cast<float(*)[3]>(positions.data()),
positions.size());
}
static void free_data(ModifierData *md)

View File

@@ -504,15 +504,17 @@ static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
if (verts_num == 0) {
if (positions.is_empty()) {
return;
}
laplaciansmoothModifier_do(
(LaplacianSmoothModifierData *)md, ctx->object, mesh, vertexCos, verts_num);
laplaciansmoothModifier_do((LaplacianSmoothModifierData *)md,
ctx->object,
mesh,
reinterpret_cast<float(*)[3]>(positions.data()),
positions.size());
}
static void panel_draw(const bContext * /*C*/, Panel *panel)

View File

@@ -96,35 +96,47 @@ static void update_depsgraph(ModifierData *md, const ModifierUpdateDepsgraphCont
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
LatticeModifierData *lmd = (LatticeModifierData *)md;
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
/* if next modifier needs original vertices */
MOD_previous_vcos_store(md, reinterpret_cast<const float(*)[3]>(positions.data()));
BKE_lattice_deform_coords_with_mesh(
lmd->object, ctx->object, vertexCos, verts_num, lmd->flag, lmd->name, lmd->strength, mesh);
BKE_lattice_deform_coords_with_mesh(lmd->object,
ctx->object,
reinterpret_cast<float(*)[3]>(positions.data()),
positions.size(),
lmd->flag,
lmd->name,
lmd->strength,
mesh);
}
static void deform_verts_EM(ModifierData *md,
const ModifierEvalContext *ctx,
BMEditMesh *em,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
if (mesh->runtime->wrapper_type == ME_WRAPPER_TYPE_MDATA) {
deform_verts(md, ctx, mesh, vertexCos, verts_num);
deform_verts(md, ctx, mesh, positions);
return;
}
LatticeModifierData *lmd = (LatticeModifierData *)md;
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
/* if next modifier needs original vertices */
MOD_previous_vcos_store(md, reinterpret_cast<const float(*)[3]>(positions.data()));
BKE_lattice_deform_coords_with_editmesh(
lmd->object, ctx->object, vertexCos, verts_num, lmd->flag, lmd->name, lmd->strength, em);
BKE_lattice_deform_coords_with_editmesh(lmd->object,
ctx->object,
reinterpret_cast<float(*)[3]>(positions.data()),
positions.size(),
lmd->flag,
lmd->name,
lmd->strength,
em);
}
static void panel_draw(const bContext * /*C*/, Panel *panel)

View File

@@ -278,13 +278,17 @@ static void meshcache_do(MeshCacheModifierData *mcmd,
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md;
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
meshcache_do(mcmd, scene, ctx->object, mesh, vertexCos, verts_num);
meshcache_do(mcmd,
scene,
ctx->object,
mesh,
reinterpret_cast<float(*)[3]>(positions.data()),
positions.size());
}
static void panel_draw(const bContext * /*C*/, Panel *panel)

View File

@@ -439,11 +439,12 @@ finally:
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
meshdeformModifier_do(md, ctx, mesh, vertexCos, verts_num);
/* if next modifier needs original vertices */
MOD_previous_vcos_store(md, reinterpret_cast<float(*)[3]>(positions.data()));
meshdeformModifier_do(
md, ctx, mesh, reinterpret_cast<float(*)[3]>(positions.data()), positions.size());
}
#define MESHDEFORM_MIN_INFLUENCE 0.00001f

View File

@@ -274,9 +274,8 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh
static void deform_matrices(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertex_cos)[3],
float (*deform_matrices)[3][3],
int verts_num)
blender::MutableSpan<blender::float3> positions,
blender::MutableSpan<blender::float3x3> /*matrices*/)
{
#if !defined(WITH_OPENSUBDIV)
@@ -284,9 +283,6 @@ static void deform_matrices(ModifierData *md,
return;
#endif
/* Subsurf does not require extra space mapping, keep matrices as is. */
(void)deform_matrices;
MultiresModifierData *mmd = (MultiresModifierData *)md;
SubdivSettings subdiv_settings;
@@ -308,7 +304,8 @@ static void deform_matrices(ModifierData *md,
return;
}
BKE_subdiv_displacement_attach_from_multires(subdiv, mesh, mmd);
BKE_subdiv_deform_coarse_vertices(subdiv, mesh, vertex_cos, verts_num);
BKE_subdiv_deform_coarse_vertices(
subdiv, mesh, reinterpret_cast<float(*)[3]>(positions.data()), positions.size());
if (subdiv != runtime_data->subdiv) {
BKE_subdiv_free(subdiv);
}

View File

@@ -99,8 +99,7 @@ static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int /*verts_num*/)
blender::MutableSpan<blender::float3> positions)
{
ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md;
ParticleSystem *psys = nullptr;
@@ -148,7 +147,7 @@ static void deform_verts(ModifierData *md,
/* make new mesh */
psmd->mesh_final = BKE_mesh_copy_for_eval(mesh);
BKE_mesh_vert_coords_apply(psmd->mesh_final, vertexCos);
BKE_mesh_vert_coords_apply(psmd->mesh_final, reinterpret_cast<float(*)[3]>(positions.data()));
BKE_mesh_tessface_ensure(psmd->mesh_final);

View File

@@ -28,8 +28,7 @@
static void deform_verts(ModifierData * /*md*/,
const ModifierEvalContext *ctx,
Mesh * /*mesh*/,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
Key *key = BKE_key_from_object(ctx->object);
@@ -37,8 +36,8 @@ static void deform_verts(ModifierData * /*md*/,
int deformedVerts_tot;
BKE_key_evaluate_object_ex(ctx->object,
&deformedVerts_tot,
(float *)vertexCos,
sizeof(*vertexCos) * verts_num,
reinterpret_cast<float *>(positions.data()),
sizeof(blender::float3) * positions.size(),
nullptr);
}
}
@@ -46,16 +45,13 @@ static void deform_verts(ModifierData * /*md*/,
static void deform_matrices(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
float (*defMats)[3][3],
int verts_num)
blender::MutableSpan<blender::float3> positions,
blender::MutableSpan<blender::float3x3> matrices)
{
Key *key = BKE_key_from_object(ctx->object);
KeyBlock *kb = BKE_keyblock_from_object(ctx->object);
(void)vertexCos; /* unused */
if (kb && kb->totelem == verts_num && kb != key->refkey) {
if (kb && kb->totelem == positions.size() && kb != key->refkey) {
float scale[3][3];
int a;
@@ -66,25 +62,24 @@ static void deform_matrices(ModifierData *md,
scale_m3_fl(scale, kb->curval);
}
for (a = 0; a < verts_num; a++) {
copy_m3_m3(defMats[a], scale);
for (a = 0; a < positions.size(); a++) {
copy_m3_m3(matrices[a].ptr(), scale);
}
}
deform_verts(md, ctx, mesh, vertexCos, verts_num);
deform_verts(md, ctx, mesh, positions);
}
static void deform_verts_EM(ModifierData *md,
const ModifierEvalContext *ctx,
BMEditMesh * /*em*/,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
Key *key = BKE_key_from_object(ctx->object);
if (key && key->type == KEY_RELATIVE) {
deform_verts(md, ctx, mesh, vertexCos, verts_num);
deform_verts(md, ctx, mesh, positions);
}
}
@@ -92,21 +87,18 @@ static void deform_matrices_EM(ModifierData * /*md*/,
const ModifierEvalContext *ctx,
BMEditMesh * /*em*/,
Mesh * /*mesh*/,
float (*vertexCos)[3],
float (*defMats)[3][3],
int verts_num)
blender::MutableSpan<blender::float3> /*positions*/,
blender::MutableSpan<blender::float3x3> matrices)
{
Key *key = BKE_key_from_object(ctx->object);
KeyBlock *kb = BKE_keyblock_from_object(ctx->object);
(void)vertexCos; /* unused */
if (kb && kb->totelem == verts_num && kb != key->refkey) {
if (kb && kb->totelem == matrices.size() && kb != key->refkey) {
float scale[3][3];
scale_m3_fl(scale, kb->curval);
for (int a = 0; a < verts_num; a++) {
copy_m3_m3(defMats[a], scale);
for (int a = 0; a < matrices.size(); a++) {
copy_m3_m3(matrices[a].ptr(), scale);
}
}
}

View File

@@ -88,8 +88,7 @@ static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
ShrinkwrapModifierData *swmd = (ShrinkwrapModifierData *)md;
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
@@ -98,8 +97,15 @@ static void deform_verts(ModifierData *md,
int defgrp_index = -1;
MOD_get_vgroup(ctx->object, mesh, swmd->vgroup_name, &dvert, &defgrp_index);
shrinkwrapModifier_deform(
swmd, ctx, scene, ctx->object, mesh, dvert, defgrp_index, vertexCos, verts_num);
shrinkwrapModifier_deform(swmd,
ctx,
scene,
ctx->object,
mesh,
dvert,
defgrp_index,
reinterpret_cast<float(*)[3]>(positions.data()),
positions.size());
}
static void update_depsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)

View File

@@ -445,11 +445,15 @@ static void update_depsgraph(ModifierData *md, const ModifierUpdateDepsgraphCont
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
SimpleDeformModifierData *sdmd = (SimpleDeformModifierData *)md;
SimpleDeformModifier_do(sdmd, ctx, ctx->object, mesh, vertexCos, verts_num);
SimpleDeformModifier_do(sdmd,
ctx,
ctx->object,
mesh,
reinterpret_cast<float(*)[3]>(positions.data()),
positions.size());
}
static void panel_draw(const bContext * /*C*/, Panel *panel)

View File

@@ -178,11 +178,11 @@ static void smoothModifier_do(
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
SmoothModifierData *smd = (SmoothModifierData *)md;
smoothModifier_do(smd, ctx->object, mesh, vertexCos, verts_num);
smoothModifier_do(
smd, ctx->object, mesh, reinterpret_cast<float(*)[3]>(positions.data()), positions.size());
}
static void panel_draw(const bContext * /*C*/, Panel *panel)

View File

@@ -40,12 +40,15 @@
static void deform_verts(ModifierData * /*md*/,
const ModifierEvalContext *ctx,
Mesh * /*mesh*/,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
sbObjectStep(
ctx->depsgraph, scene, ctx->object, DEG_get_ctime(ctx->depsgraph), vertexCos, verts_num);
sbObjectStep(ctx->depsgraph,
scene,
ctx->object,
DEG_get_ctime(ctx->depsgraph),
reinterpret_cast<float(*)[3]>(positions.data()),
positions.size());
}
static bool depends_on_time(Scene * /*scene*/, ModifierData * /*md*/)

View File

@@ -286,9 +286,8 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh
static void deform_matrices(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertex_cos)[3],
float (*deform_matrices)[3][3],
int verts_num)
blender::MutableSpan<blender::float3> positions,
blender::MutableSpan<blender::float3x3> /*matrices*/)
{
#if !defined(WITH_OPENSUBDIV)
BKE_modifier_set_error(ctx->object, md, "Disabled, built without OpenSubdiv");
@@ -296,7 +295,6 @@ static void deform_matrices(ModifierData *md,
#endif
/* Subsurf does not require extra space mapping, keep matrices as is. */
(void)deform_matrices;
SubsurfModifierData *smd = (SubsurfModifierData *)md;
if (!BKE_subsurf_modifier_runtime_init(smd, (ctx->flag & MOD_APPLY_RENDER) != 0)) {
@@ -308,7 +306,8 @@ static void deform_matrices(ModifierData *md,
/* Happens on bad topology, but also on empty input mesh. */
return;
}
BKE_subdiv_deform_coarse_vertices(subdiv, mesh, vertex_cos, verts_num);
BKE_subdiv_deform_coarse_vertices(
subdiv, mesh, reinterpret_cast<float(*)[3]>(positions.data()), positions.size());
if (!ELEM(subdiv, runtime_data->subdiv_cpu, runtime_data->subdiv_gpu)) {
BKE_subdiv_free(subdiv);
}

View File

@@ -89,8 +89,7 @@ static bool depends_on_time(Scene * /*scene*/, ModifierData * /*md*/)
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int /*verts_num*/)
blender::MutableSpan<blender::float3> positions)
{
SurfaceModifierData *surmd = (SurfaceModifierData *)md;
const int cfra = int(DEG_get_ctime(ctx->depsgraph));
@@ -119,7 +118,8 @@ static void deform_verts(ModifierData *md,
uint mesh_verts_num = 0, i = 0;
int init = 0;
BKE_mesh_vert_coords_apply(surmd->runtime.mesh, vertexCos);
BKE_mesh_vert_coords_apply(surmd->runtime.mesh,
reinterpret_cast<const float(*)[3]>(positions.data()));
mesh_verts_num = surmd->runtime.mesh->totvert;

View File

@@ -1571,10 +1571,14 @@ static void surfacedeformModifier_do(ModifierData *md,
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
surfacedeformModifier_do(md, ctx, vertexCos, verts_num, ctx->object, mesh);
surfacedeformModifier_do(md,
ctx,
reinterpret_cast<float(*)[3]>(positions.data()),
positions.size(),
ctx->object,
mesh);
}
static bool is_disabled(const Scene * /*scene*/, ModifierData *md, bool /*use_render_params*/)

View File

@@ -338,11 +338,11 @@ static void warpModifier_do(WarpModifierData *wmd,
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
WarpModifierData *wmd = (WarpModifierData *)md;
warpModifier_do(wmd, ctx, mesh, vertexCos, verts_num);
warpModifier_do(
wmd, ctx, mesh, reinterpret_cast<float(*)[3]>(positions.data()), positions.size());
}
static void panel_draw(const bContext * /*C*/, Panel *panel)

View File

@@ -291,11 +291,15 @@ static void waveModifier_do(WaveModifierData *md,
static void deform_verts(ModifierData *md,
const ModifierEvalContext *ctx,
Mesh *mesh,
float (*vertexCos)[3],
int verts_num)
blender::MutableSpan<blender::float3> positions)
{
WaveModifierData *wmd = (WaveModifierData *)md;
waveModifier_do(wmd, ctx, ctx->object, mesh, vertexCos, verts_num);
waveModifier_do(wmd,
ctx,
ctx->object,
mesh,
reinterpret_cast<float(*)[3]>(positions.data()),
positions.size());
}
static void panel_draw(const bContext * /*C*/, Panel *panel)