Cleanup: Move five modifier files to C++
See #103343 Pull Request #105345
This commit is contained in:
@@ -51,7 +51,7 @@ set(SRC
|
||||
intern/MOD_explode.cc
|
||||
intern/MOD_fluid.c
|
||||
intern/MOD_hook.c
|
||||
intern/MOD_laplaciandeform.c
|
||||
intern/MOD_laplaciandeform.cc
|
||||
intern/MOD_laplaciansmooth.cc
|
||||
intern/MOD_lattice.c
|
||||
intern/MOD_mask.cc
|
||||
@@ -75,8 +75,8 @@ set(SRC
|
||||
intern/MOD_shapekey.c
|
||||
intern/MOD_shrinkwrap.c
|
||||
intern/MOD_simpledeform.c
|
||||
intern/MOD_skin.c
|
||||
intern/MOD_smooth.c
|
||||
intern/MOD_skin.cc
|
||||
intern/MOD_smooth.cc
|
||||
intern/MOD_softbody.c
|
||||
intern/MOD_solidify.cc
|
||||
intern/MOD_solidify_extrude.cc
|
||||
|
||||
@@ -55,7 +55,7 @@ enum {
|
||||
LAPDEFORM_SYSTEM_CHANGE_NOT_VALID_GROUP,
|
||||
};
|
||||
|
||||
typedef struct LaplacianSystem {
|
||||
struct LaplacianSystem {
|
||||
bool is_matrix_computed;
|
||||
bool has_solution;
|
||||
int verts_num;
|
||||
@@ -75,12 +75,11 @@ typedef struct LaplacianSystem {
|
||||
LinearSolver *context; /* System for solve general implicit rotations */
|
||||
MeshElemMap *ringf_map; /* Map of faces per vertex */
|
||||
MeshElemMap *ringv_map; /* Map of vertex per vertex */
|
||||
} LaplacianSystem;
|
||||
};
|
||||
|
||||
static LaplacianSystem *newLaplacianSystem(void)
|
||||
{
|
||||
LaplacianSystem *sys;
|
||||
sys = MEM_callocN(sizeof(LaplacianSystem), "DeformCache");
|
||||
LaplacianSystem *sys = MEM_cnew<LaplacianSystem>(__func__);
|
||||
|
||||
sys->is_matrix_computed = false;
|
||||
sys->has_solution = false;
|
||||
@@ -111,12 +110,12 @@ static LaplacianSystem *initLaplacianSystem(int verts_num,
|
||||
sys->anchors_num = anchors_num;
|
||||
sys->repeat = iterations;
|
||||
BLI_strncpy(sys->anchor_grp_name, defgrpName, sizeof(sys->anchor_grp_name));
|
||||
sys->co = MEM_malloc_arrayN(verts_num, sizeof(float[3]), "DeformCoordinates");
|
||||
sys->no = MEM_calloc_arrayN(verts_num, sizeof(float[3]), "DeformNormals");
|
||||
sys->delta = MEM_calloc_arrayN(verts_num, sizeof(float[3]), "DeformDeltas");
|
||||
sys->tris = MEM_malloc_arrayN(tris_num, sizeof(int[3]), "DeformFaces");
|
||||
sys->index_anchors = MEM_malloc_arrayN((anchors_num), sizeof(int), "DeformAnchors");
|
||||
sys->unit_verts = MEM_calloc_arrayN(verts_num, sizeof(int), "DeformUnitVerts");
|
||||
sys->co = static_cast<float(*)[3]>(MEM_malloc_arrayN(verts_num, sizeof(float[3]), __func__));
|
||||
sys->no = static_cast<float(*)[3]>(MEM_calloc_arrayN(verts_num, sizeof(float[3]), __func__));
|
||||
sys->delta = static_cast<float(*)[3]>(MEM_calloc_arrayN(verts_num, sizeof(float[3]), __func__));
|
||||
sys->tris = static_cast<uint(*)[3]>(MEM_malloc_arrayN(tris_num, sizeof(int[3]), __func__));
|
||||
sys->index_anchors = static_cast<int *>(MEM_malloc_arrayN((anchors_num), sizeof(int), __func__));
|
||||
sys->unit_verts = static_cast<int *>(MEM_calloc_arrayN(verts_num, sizeof(int), __func__));
|
||||
return sys;
|
||||
}
|
||||
|
||||
@@ -148,7 +147,7 @@ static void createFaceRingMap(const int mvert_tot,
|
||||
{
|
||||
int i, j, indices_num = 0;
|
||||
int *indices, *index_iter;
|
||||
MeshElemMap *map = MEM_calloc_arrayN(mvert_tot, sizeof(MeshElemMap), "DeformRingMap");
|
||||
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(mvert_tot, __func__);
|
||||
const MLoopTri *mlt;
|
||||
|
||||
for (i = 0, mlt = mlooptri; i < mtri_tot; i++, mlt++) {
|
||||
@@ -159,7 +158,7 @@ static void createFaceRingMap(const int mvert_tot,
|
||||
indices_num++;
|
||||
}
|
||||
}
|
||||
indices = MEM_calloc_arrayN(indices_num, sizeof(int), "DeformRingIndex");
|
||||
indices = MEM_cnew_array<int>(indices_num, __func__);
|
||||
index_iter = indices;
|
||||
for (i = 0; i < mvert_tot; i++) {
|
||||
map[i].indices = index_iter;
|
||||
@@ -183,7 +182,7 @@ static void createVertRingMap(const int mvert_tot,
|
||||
MeshElemMap **r_map,
|
||||
int **r_indices)
|
||||
{
|
||||
MeshElemMap *map = MEM_calloc_arrayN(mvert_tot, sizeof(MeshElemMap), "DeformNeighborsMap");
|
||||
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(mvert_tot, __func__);
|
||||
int i, vid[2], indices_num = 0;
|
||||
int *indices, *index_iter;
|
||||
const MEdge *me;
|
||||
@@ -195,7 +194,7 @@ static void createVertRingMap(const int mvert_tot,
|
||||
map[vid[1]].count++;
|
||||
indices_num += 2;
|
||||
}
|
||||
indices = MEM_calloc_arrayN(indices_num, sizeof(int), "DeformNeighborsIndex");
|
||||
indices = MEM_cnew_array<int>(indices_num, __func__);
|
||||
index_iter = indices;
|
||||
for (i = 0; i < mvert_tot; i++) {
|
||||
map[i].indices = index_iter;
|
||||
@@ -301,7 +300,7 @@ static void initLaplacianMatrix(LaplacianSystem *sys)
|
||||
|
||||
static void computeImplictRotations(LaplacianSystem *sys)
|
||||
{
|
||||
int vid, *vidn = NULL;
|
||||
int vid, *vidn = nullptr;
|
||||
float minj, mjt, qj[3], vj[3];
|
||||
int i, j, ln;
|
||||
|
||||
@@ -512,11 +511,11 @@ static void laplacianDeformPreview(LaplacianSystem *sys, float (*vertexCos)[3])
|
||||
static bool isValidVertexGroup(LaplacianDeformModifierData *lmd, Object *ob, Mesh *mesh)
|
||||
{
|
||||
int defgrp_index;
|
||||
const MDeformVert *dvert = NULL;
|
||||
const MDeformVert *dvert = nullptr;
|
||||
|
||||
MOD_get_vgroup(ob, mesh, lmd->anchor_grp_name, &dvert, &defgrp_index);
|
||||
|
||||
return (dvert != NULL);
|
||||
return (dvert != nullptr);
|
||||
}
|
||||
|
||||
static void initSystem(
|
||||
@@ -526,13 +525,14 @@ static void initSystem(
|
||||
int defgrp_index;
|
||||
int anchors_num;
|
||||
float wpaint;
|
||||
const MDeformVert *dvert = NULL;
|
||||
const MDeformVert *dv = NULL;
|
||||
const MDeformVert *dvert = nullptr;
|
||||
const MDeformVert *dv = nullptr;
|
||||
LaplacianSystem *sys;
|
||||
const bool invert_vgroup = (lmd->flag & MOD_LAPLACIANDEFORM_INVERT_VGROUP) != 0;
|
||||
|
||||
if (isValidVertexGroup(lmd, ob, mesh)) {
|
||||
int *index_anchors = MEM_malloc_arrayN(verts_num, sizeof(int), __func__); /* over-alloc */
|
||||
int *index_anchors = static_cast<int *>(
|
||||
MEM_malloc_arrayN(verts_num, sizeof(int), __func__)); /* over-alloc */
|
||||
const MLoopTri *mlooptri;
|
||||
const MLoop *mloop;
|
||||
|
||||
@@ -541,7 +541,7 @@ static void initSystem(
|
||||
STACK_INIT(index_anchors, verts_num);
|
||||
|
||||
MOD_get_vgroup(ob, mesh, lmd->anchor_grp_name, &dvert, &defgrp_index);
|
||||
BLI_assert(dvert != NULL);
|
||||
BLI_assert(dvert != nullptr);
|
||||
dv = dvert;
|
||||
for (i = 0; i < verts_num; i++) {
|
||||
wpaint = invert_vgroup ? 1.0f - BKE_defvert_find_weight(dv, defgrp_index) :
|
||||
@@ -563,7 +563,7 @@ static void initSystem(
|
||||
memcpy(sys->index_anchors, index_anchors, sizeof(int) * anchors_num);
|
||||
memcpy(sys->co, vertexCos, sizeof(float[3]) * verts_num);
|
||||
MEM_freeN(index_anchors);
|
||||
lmd->vertexco = MEM_malloc_arrayN(verts_num, sizeof(float[3]), "ModDeformCoordinates");
|
||||
lmd->vertexco = static_cast<float *>(MEM_malloc_arrayN(verts_num, sizeof(float[3]), __func__));
|
||||
memcpy(lmd->vertexco, vertexCos, sizeof(float[3]) * verts_num);
|
||||
lmd->verts_num = verts_num;
|
||||
|
||||
@@ -596,8 +596,8 @@ static int isSystemDifferent(LaplacianDeformModifierData *lmd,
|
||||
int defgrp_index;
|
||||
int anchors_num = 0;
|
||||
float wpaint;
|
||||
const MDeformVert *dvert = NULL;
|
||||
const MDeformVert *dv = NULL;
|
||||
const MDeformVert *dvert = nullptr;
|
||||
const MDeformVert *dv = nullptr;
|
||||
LaplacianSystem *sys = (LaplacianSystem *)lmd->cache_system;
|
||||
const bool invert_vgroup = (lmd->flag & MOD_LAPLACIANDEFORM_INVERT_VGROUP) != 0;
|
||||
|
||||
@@ -635,13 +635,13 @@ static void LaplacianDeformModifier_do(
|
||||
{
|
||||
float(*filevertexCos)[3];
|
||||
int sysdif;
|
||||
LaplacianSystem *sys = NULL;
|
||||
filevertexCos = NULL;
|
||||
LaplacianSystem *sys = nullptr;
|
||||
filevertexCos = nullptr;
|
||||
if (!(lmd->flag & MOD_LAPLACIANDEFORM_BIND)) {
|
||||
if (lmd->cache_system) {
|
||||
sys = lmd->cache_system;
|
||||
sys = static_cast<LaplacianSystem *>(lmd->cache_system);
|
||||
deleteLaplacianSystem(sys);
|
||||
lmd->cache_system = NULL;
|
||||
lmd->cache_system = nullptr;
|
||||
}
|
||||
lmd->verts_num = 0;
|
||||
MEM_SAFE_FREE(lmd->vertexco);
|
||||
@@ -649,17 +649,18 @@ static void LaplacianDeformModifier_do(
|
||||
}
|
||||
if (lmd->cache_system) {
|
||||
sysdif = isSystemDifferent(lmd, ob, mesh, verts_num);
|
||||
sys = lmd->cache_system;
|
||||
sys = static_cast<LaplacianSystem *>(lmd->cache_system);
|
||||
if (sysdif) {
|
||||
if (ELEM(sysdif, LAPDEFORM_SYSTEM_ONLY_CHANGE_ANCHORS, LAPDEFORM_SYSTEM_ONLY_CHANGE_GROUP)) {
|
||||
filevertexCos = MEM_malloc_arrayN(verts_num, sizeof(float[3]), "TempModDeformCoordinates");
|
||||
filevertexCos = static_cast<float(*)[3]>(
|
||||
MEM_malloc_arrayN(verts_num, sizeof(float[3]), __func__));
|
||||
memcpy(filevertexCos, lmd->vertexco, sizeof(float[3]) * verts_num);
|
||||
MEM_SAFE_FREE(lmd->vertexco);
|
||||
lmd->verts_num = 0;
|
||||
deleteLaplacianSystem(sys);
|
||||
lmd->cache_system = NULL;
|
||||
lmd->cache_system = nullptr;
|
||||
initSystem(lmd, ob, mesh, filevertexCos, verts_num);
|
||||
sys = lmd->cache_system; /* may have been reallocated */
|
||||
sys = static_cast<LaplacianSystem *>(lmd->cache_system); /* may have been reallocated */
|
||||
MEM_SAFE_FREE(filevertexCos);
|
||||
if (sys) {
|
||||
laplacianDeformPreview(sys, vertexCos);
|
||||
@@ -696,18 +697,19 @@ static void LaplacianDeformModifier_do(
|
||||
lmd->flag &= ~MOD_LAPLACIANDEFORM_BIND;
|
||||
}
|
||||
else if (lmd->verts_num > 0 && lmd->verts_num == verts_num) {
|
||||
filevertexCos = MEM_malloc_arrayN(verts_num, sizeof(float[3]), "TempDeformCoordinates");
|
||||
filevertexCos = static_cast<float(*)[3]>(
|
||||
MEM_malloc_arrayN(verts_num, sizeof(float[3]), "TempDeformCoordinates"));
|
||||
memcpy(filevertexCos, lmd->vertexco, sizeof(float[3]) * verts_num);
|
||||
MEM_SAFE_FREE(lmd->vertexco);
|
||||
lmd->verts_num = 0;
|
||||
initSystem(lmd, ob, mesh, filevertexCos, verts_num);
|
||||
sys = lmd->cache_system;
|
||||
sys = static_cast<LaplacianSystem *>(lmd->cache_system);
|
||||
MEM_SAFE_FREE(filevertexCos);
|
||||
laplacianDeformPreview(sys, vertexCos);
|
||||
}
|
||||
else {
|
||||
initSystem(lmd, ob, mesh, vertexCos, verts_num);
|
||||
sys = lmd->cache_system;
|
||||
sys = static_cast<LaplacianSystem *>(lmd->cache_system);
|
||||
laplacianDeformPreview(sys, vertexCos);
|
||||
}
|
||||
}
|
||||
@@ -732,13 +734,11 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla
|
||||
|
||||
BKE_modifier_copydata_generic(md, target, flag);
|
||||
|
||||
tlmd->vertexco = MEM_dupallocN(lmd->vertexco);
|
||||
tlmd->cache_system = NULL;
|
||||
tlmd->vertexco = static_cast<float *>(MEM_dupallocN(lmd->vertexco));
|
||||
tlmd->cache_system = nullptr;
|
||||
}
|
||||
|
||||
static bool isDisabled(const struct Scene *UNUSED(scene),
|
||||
ModifierData *md,
|
||||
bool UNUSED(useRenderParams))
|
||||
static bool isDisabled(const Scene * /*scene*/, ModifierData *md, bool /*useRenderParams*/)
|
||||
{
|
||||
LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md;
|
||||
if (lmd->anchor_grp_name[0]) {
|
||||
@@ -762,35 +762,36 @@ static void deformVerts(ModifierData *md,
|
||||
float (*vertexCos)[3],
|
||||
int verts_num)
|
||||
{
|
||||
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, verts_num, false);
|
||||
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, nullptr, mesh, nullptr, verts_num, false);
|
||||
|
||||
LaplacianDeformModifier_do(
|
||||
(LaplacianDeformModifierData *)md, ctx->object, mesh_src, vertexCos, verts_num);
|
||||
|
||||
if (!ELEM(mesh_src, NULL, mesh)) {
|
||||
BKE_id_free(NULL, mesh_src);
|
||||
if (!ELEM(mesh_src, nullptr, mesh)) {
|
||||
BKE_id_free(nullptr, mesh_src);
|
||||
}
|
||||
}
|
||||
|
||||
static void deformVertsEM(ModifierData *md,
|
||||
const ModifierEvalContext *ctx,
|
||||
struct BMEditMesh *editData,
|
||||
BMEditMesh *editData,
|
||||
Mesh *mesh,
|
||||
float (*vertexCos)[3],
|
||||
int verts_num)
|
||||
{
|
||||
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, verts_num, false);
|
||||
Mesh *mesh_src = MOD_deform_mesh_eval_get(
|
||||
ctx->object, editData, mesh, nullptr, verts_num, false);
|
||||
|
||||
/* TODO(@ideasman42): use edit-mode data only (remove this line). */
|
||||
if (mesh_src != NULL) {
|
||||
if (mesh_src != nullptr) {
|
||||
BKE_mesh_wrapper_ensure_mdata(mesh_src);
|
||||
}
|
||||
|
||||
LaplacianDeformModifier_do(
|
||||
(LaplacianDeformModifierData *)md, ctx->object, mesh_src, vertexCos, verts_num);
|
||||
|
||||
if (!ELEM(mesh_src, NULL, mesh)) {
|
||||
BKE_id_free(NULL, mesh_src);
|
||||
if (!ELEM(mesh_src, nullptr, mesh)) {
|
||||
BKE_id_free(nullptr, mesh_src);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -805,7 +806,7 @@ static void freeData(ModifierData *md)
|
||||
lmd->verts_num = 0;
|
||||
}
|
||||
|
||||
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
|
||||
static void panel_draw(const bContext * /*C*/, Panel *panel)
|
||||
{
|
||||
uiLayout *row;
|
||||
uiLayout *layout = panel->layout;
|
||||
@@ -818,9 +819,9 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel)
|
||||
|
||||
uiLayoutSetPropSep(layout, true);
|
||||
|
||||
uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE);
|
||||
uiItemR(layout, ptr, "iterations", 0, nullptr, ICON_NONE);
|
||||
|
||||
modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", NULL);
|
||||
modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", nullptr);
|
||||
|
||||
uiItemS(layout);
|
||||
|
||||
@@ -851,13 +852,13 @@ static void blendWrite(BlendWriter *writer, const ID *id_owner, const ModifierDa
|
||||
/* Modifier coming from linked data cannot be bound from an override, so we can remove all
|
||||
* binding data, can save a significant amount of memory. */
|
||||
lmd.verts_num = 0;
|
||||
lmd.vertexco = NULL;
|
||||
lmd.vertexco = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
BLO_write_struct_at_address(writer, LaplacianDeformModifierData, md, &lmd);
|
||||
|
||||
if (lmd.vertexco != NULL) {
|
||||
if (lmd.vertexco != nullptr) {
|
||||
BLO_write_float3_array(writer, lmd.verts_num, lmd.vertexco);
|
||||
}
|
||||
}
|
||||
@@ -867,7 +868,7 @@ static void blendRead(BlendDataReader *reader, ModifierData *md)
|
||||
LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md;
|
||||
|
||||
BLO_read_float3_array(reader, lmd->verts_num, &lmd->vertexco);
|
||||
lmd->cache_system = NULL;
|
||||
lmd->cache_system = nullptr;
|
||||
}
|
||||
|
||||
ModifierTypeInfo modifierType_LaplacianDeform = {
|
||||
@@ -881,22 +882,22 @@ ModifierTypeInfo modifierType_LaplacianDeform = {
|
||||
/*copyData*/ copyData,
|
||||
|
||||
/*deformVerts*/ deformVerts,
|
||||
/*deformMatrices*/ NULL,
|
||||
/*deformMatrices*/ nullptr,
|
||||
/*deformVertsEM*/ deformVertsEM,
|
||||
/*deformMatricesEM*/ NULL,
|
||||
/*modifyMesh*/ NULL,
|
||||
/*modifyGeometrySet*/ NULL,
|
||||
/*deformMatricesEM*/ nullptr,
|
||||
/*modifyMesh*/ nullptr,
|
||||
/*modifyGeometrySet*/ nullptr,
|
||||
|
||||
/*initData*/ initData,
|
||||
/*requiredDataMask*/ requiredDataMask,
|
||||
/*freeData*/ freeData,
|
||||
/*isDisabled*/ isDisabled,
|
||||
/*updateDepsgraph*/ NULL,
|
||||
/*dependsOnTime*/ NULL,
|
||||
/*dependsOnNormals*/ NULL,
|
||||
/*foreachIDLink*/ NULL,
|
||||
/*foreachTexLink*/ NULL,
|
||||
/*freeRuntimeData*/ NULL,
|
||||
/*updateDepsgraph*/ nullptr,
|
||||
/*dependsOnTime*/ nullptr,
|
||||
/*dependsOnNormals*/ nullptr,
|
||||
/*foreachIDLink*/ nullptr,
|
||||
/*foreachTexLink*/ nullptr,
|
||||
/*freeRuntimeData*/ nullptr,
|
||||
/*panelRegister*/ panelRegister,
|
||||
/*blendWrite*/ blendWrite,
|
||||
/*blendRead*/ blendRead,
|
||||
@@ -40,12 +40,12 @@
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "BLI_array.h"
|
||||
#include "BLI_bitmap.h"
|
||||
#include "BLI_heap_simple.h"
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_math_geom.h"
|
||||
#include "BLI_stack.h"
|
||||
#include "BLI_vector.hh"
|
||||
|
||||
#include "BLT_translation.h"
|
||||
|
||||
@@ -117,21 +117,22 @@ static void vert_array_face_normal_update(BMVert **verts, int verts_len)
|
||||
|
||||
/** \} */
|
||||
|
||||
typedef struct {
|
||||
struct EMat {
|
||||
float mat[3][3];
|
||||
/* Vert that edge is pointing away from, no relation to
|
||||
* MEdge.v1 */
|
||||
int origin;
|
||||
} EMat;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
enum SkinNodeFlag {
|
||||
CAP_START = 1,
|
||||
CAP_END = 2,
|
||||
SEAM_FRAME = 4,
|
||||
FLIP_NORMAL = 8,
|
||||
} SkinNodeFlag;
|
||||
};
|
||||
ENUM_OPERATORS(SkinNodeFlag, FLIP_NORMAL);
|
||||
|
||||
typedef struct Frame {
|
||||
struct Frame {
|
||||
/* Index in the vertex array */
|
||||
BMVert *verts[4];
|
||||
/* Location of each corner */
|
||||
@@ -140,7 +141,7 @@ typedef struct Frame {
|
||||
* frame's corner (so they share a vertex index) */
|
||||
struct {
|
||||
/* Merge to target frame/corner (no merge if frame is null) */
|
||||
struct Frame *frame;
|
||||
Frame *frame;
|
||||
int corner;
|
||||
/* checked to avoid chaining.
|
||||
* (merging when we're already been referenced), see #39775 */
|
||||
@@ -151,10 +152,10 @@ typedef struct Frame {
|
||||
bool inside_hull[4];
|
||||
/* Whether any part of the frame (corner or edge) is detached */
|
||||
bool detached;
|
||||
} Frame;
|
||||
};
|
||||
|
||||
#define MAX_SKIN_NODE_FRAMES 2
|
||||
typedef struct {
|
||||
struct SkinNode {
|
||||
Frame frames[MAX_SKIN_NODE_FRAMES];
|
||||
int totframe;
|
||||
|
||||
@@ -162,13 +163,13 @@ typedef struct {
|
||||
|
||||
/* Used for hulling a loop seam */
|
||||
int seam_edges[2];
|
||||
} SkinNode;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct SkinOutput {
|
||||
BMesh *bm;
|
||||
SkinModifierData *smd;
|
||||
int mat_nr;
|
||||
} SkinOutput;
|
||||
};
|
||||
|
||||
static void add_poly(SkinOutput *so, BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4);
|
||||
|
||||
@@ -453,8 +454,7 @@ static Frame **collect_hull_frames(
|
||||
int hull_frames_num, i;
|
||||
|
||||
(*tothullframe) = emap[v].count;
|
||||
hull_frames = MEM_calloc_arrayN(
|
||||
(*tothullframe), sizeof(Frame *), "hull_from_frames.hull_frames");
|
||||
hull_frames = MEM_cnew_array<Frame *>(*tothullframe, __func__);
|
||||
hull_frames_num = 0;
|
||||
for (i = 0; i < emap[v].count; i++) {
|
||||
const MEdge *e = &medge[emap[v].indices[i]];
|
||||
@@ -480,7 +480,7 @@ static void node_frames_init(SkinNode *nf, int totframe)
|
||||
nf->totframe = totframe;
|
||||
memset(nf->frames, 0, sizeof(nf->frames));
|
||||
|
||||
nf->flag = 0;
|
||||
nf->flag = SkinNodeFlag(0);
|
||||
for (i = 0; i < 2; i++) {
|
||||
nf->seam_edges[i] = -1;
|
||||
}
|
||||
@@ -654,10 +654,9 @@ static SkinNode *build_frames(const float (*vert_positions)[3],
|
||||
const MeshElemMap *emap,
|
||||
EMat *emat)
|
||||
{
|
||||
SkinNode *skin_nodes;
|
||||
int v;
|
||||
|
||||
skin_nodes = MEM_calloc_arrayN(verts_num, sizeof(SkinNode), "build_frames.skin_nodes");
|
||||
SkinNode *skin_nodes = MEM_cnew_array<SkinNode>(verts_num, __func__);
|
||||
|
||||
for (v = 0; v < verts_num; v++) {
|
||||
if (emap[v].count <= 1) {
|
||||
@@ -705,11 +704,11 @@ static void calc_edge_mat(float mat[3][3], const float a[3], const float b[3])
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
struct EdgeStackElem {
|
||||
float mat[3][3];
|
||||
int parent_v;
|
||||
int e;
|
||||
} EdgeStackElem;
|
||||
};
|
||||
|
||||
static void build_emats_stack(BLI_Stack *stack,
|
||||
BLI_bitmap *visited_e,
|
||||
@@ -784,7 +783,7 @@ static EMat *build_edge_mats(const MVertSkin *vs,
|
||||
stack = BLI_stack_new(sizeof(stack_elem), "build_edge_mats.stack");
|
||||
|
||||
visited_e = BLI_BITMAP_NEW(edges_num, "build_edge_mats.visited_e");
|
||||
emat = MEM_calloc_arrayN(edges_num, sizeof(EMat), "build_edge_mats.emat");
|
||||
emat = MEM_cnew_array<EMat>(edges_num, __func__);
|
||||
|
||||
/* Edge matrices are built from the root nodes, add all roots with
|
||||
* children to the stack */
|
||||
@@ -862,7 +861,7 @@ static int calc_edge_subdivisions(const float (*vert_positions)[3],
|
||||
const float edge_len = len_v3v3(vert_positions[e->v1], vert_positions[e->v2]);
|
||||
subdivisions_num_fl = (edge_len / avg_radius);
|
||||
if (subdivisions_num_fl < NUM_SUBDIVISIONS_MAX) {
|
||||
subdivisions_num = (int)subdivisions_num_fl;
|
||||
subdivisions_num = int(subdivisions_num_fl);
|
||||
}
|
||||
else {
|
||||
subdivisions_num = NUM_SUBDIVISIONS_MAX;
|
||||
@@ -892,7 +891,8 @@ static Mesh *subdivide_base(const Mesh *orig)
|
||||
int i, j, k, u, v;
|
||||
float radrat;
|
||||
|
||||
const MVertSkin *orignode = CustomData_get_layer(&orig->vdata, CD_MVERT_SKIN);
|
||||
const MVertSkin *orignode = static_cast<const MVertSkin *>(
|
||||
CustomData_get_layer(&orig->vdata, CD_MVERT_SKIN));
|
||||
const float(*orig_vert_positions)[3] = BKE_mesh_vert_positions(orig);
|
||||
const MEdge *origedge = BKE_mesh_edges(orig);
|
||||
const MDeformVert *origdvert = BKE_mesh_deform_verts(orig);
|
||||
@@ -900,14 +900,14 @@ static Mesh *subdivide_base(const Mesh *orig)
|
||||
int orig_edge_num = orig->totedge;
|
||||
|
||||
/* Get degree of all vertices */
|
||||
int *degree = MEM_calloc_arrayN(orig_vert_num, sizeof(int), "degree");
|
||||
int *degree = MEM_cnew_array<int>(orig_vert_num, __func__);
|
||||
for (i = 0; i < orig_edge_num; i++) {
|
||||
degree[origedge[i].v1]++;
|
||||
degree[origedge[i].v2]++;
|
||||
}
|
||||
|
||||
/* Per edge, store how many subdivisions are needed */
|
||||
int *edge_subd = MEM_calloc_arrayN((uint)orig_edge_num, sizeof(int), "edge_subd");
|
||||
int *edge_subd = MEM_cnew_array<int>(orig_edge_num, __func__);
|
||||
for (i = 0, subd_num = 0; i < orig_edge_num; i++) {
|
||||
edge_subd[i] += calc_edge_subdivisions(orig_vert_positions, orignode, &origedge[i], degree);
|
||||
BLI_assert(edge_subd[i] >= 0);
|
||||
@@ -922,9 +922,9 @@ static Mesh *subdivide_base(const Mesh *orig)
|
||||
|
||||
float(*out_vert_positions)[3] = BKE_mesh_vert_positions_for_write(result);
|
||||
MEdge *outedge = BKE_mesh_edges_for_write(result);
|
||||
MVertSkin *outnode = CustomData_get_layer_for_write(
|
||||
&result->vdata, CD_MVERT_SKIN, result->totvert);
|
||||
MDeformVert *outdvert = NULL;
|
||||
MVertSkin *outnode = static_cast<MVertSkin *>(
|
||||
CustomData_get_layer_for_write(&result->vdata, CD_MVERT_SKIN, result->totvert));
|
||||
MDeformVert *outdvert = nullptr;
|
||||
if (origdvert) {
|
||||
outdvert = BKE_mesh_deform_verts_for_write(result);
|
||||
}
|
||||
@@ -934,11 +934,12 @@ static Mesh *subdivide_base(const Mesh *orig)
|
||||
|
||||
/* Subdivide edges */
|
||||
for (i = 0, v = orig_vert_num; i < orig_edge_num; i++) {
|
||||
struct {
|
||||
struct VGroupData {
|
||||
/* Vertex group number */
|
||||
int def_nr;
|
||||
float w1, w2;
|
||||
} *vgroups = NULL, *vg;
|
||||
};
|
||||
VGroupData *vgroups = nullptr, *vg;
|
||||
int vgroups_num = 0;
|
||||
|
||||
e = &origedge[i];
|
||||
@@ -946,11 +947,11 @@ static Mesh *subdivide_base(const Mesh *orig)
|
||||
if (origdvert) {
|
||||
const MDeformVert *dv1 = &origdvert[e->v1];
|
||||
const MDeformVert *dv2 = &origdvert[e->v2];
|
||||
vgroups = MEM_calloc_arrayN(dv1->totweight, sizeof(*vgroups), "vgroup");
|
||||
vgroups = MEM_cnew_array<VGroupData>(dv1->totweight, __func__);
|
||||
|
||||
/* Only want vertex groups used by both vertices */
|
||||
for (j = 0; j < dv1->totweight; j++) {
|
||||
vg = NULL;
|
||||
vg = nullptr;
|
||||
for (k = 0; k < dv2->totweight; k++) {
|
||||
if (dv1->dw[j].def_nr == dv2->dw[k].def_nr) {
|
||||
vg = &vgroups[vgroups_num];
|
||||
@@ -979,7 +980,7 @@ static Mesh *subdivide_base(const Mesh *orig)
|
||||
|
||||
/* Add vertices and edge segments */
|
||||
for (j = 0; j < edge_subd[i]; j++, v++, outedge++) {
|
||||
float r = (j + 1) / (float)(edge_subd[i] + 1);
|
||||
float r = (j + 1) / float(edge_subd[i] + 1);
|
||||
float t = powf(r, radrat);
|
||||
|
||||
/* Interpolate vertex coord */
|
||||
@@ -1034,7 +1035,7 @@ static void add_poly(SkinOutput *so, BMVert *v1, BMVert *v2, BMVert *v3, BMVert
|
||||
BLI_assert(v3 != v4);
|
||||
BLI_assert(v1 && v2 && v3);
|
||||
|
||||
f = BM_face_create_verts(so->bm, verts, v4 ? 4 : 3, NULL, BM_CREATE_NO_DOUBLE, true);
|
||||
f = BM_face_create_verts(so->bm, verts, v4 ? 4 : 3, nullptr, BM_CREATE_NO_DOUBLE, true);
|
||||
BM_face_normal_update(f);
|
||||
if (so->smd->flag & MOD_SKIN_SMOOTH_SHADING) {
|
||||
BM_elem_flag_enable(f, BM_ELEM_SMOOTH);
|
||||
@@ -1105,11 +1106,11 @@ static void output_frames(BMesh *bm, SkinNode *sn, const MDeformVert *input_dver
|
||||
f = &sn->frames[i];
|
||||
for (j = 0; j < 4; j++) {
|
||||
if (!f->merge[j].frame) {
|
||||
BMVert *v = f->verts[j] = BM_vert_create(bm, f->co[j], NULL, BM_CREATE_NOP);
|
||||
BMVert *v = f->verts[j] = BM_vert_create(bm, f->co[j], nullptr, BM_CREATE_NOP);
|
||||
|
||||
if (input_dvert) {
|
||||
MDeformVert *dv;
|
||||
dv = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_MDEFORMVERT);
|
||||
MDeformVert *dv = static_cast<MDeformVert *>(
|
||||
CustomData_bmesh_get(&bm->vdata, v->head.data, CD_MDEFORMVERT));
|
||||
|
||||
BLI_assert(dv->totweight == 0);
|
||||
BKE_defvert_copy(dv, input_dvert);
|
||||
@@ -1136,7 +1137,7 @@ static int isect_ray_poly(const float ray_start[3],
|
||||
BMFace *f,
|
||||
float *r_lambda)
|
||||
{
|
||||
BMVert *v, *v_first = NULL, *v_prev = NULL;
|
||||
BMVert *v, *v_first = nullptr, *v_prev = nullptr;
|
||||
BMIter iter;
|
||||
float best_dist = FLT_MAX;
|
||||
bool hit = false;
|
||||
@@ -1149,7 +1150,8 @@ static int isect_ray_poly(const float ray_start[3],
|
||||
float dist;
|
||||
bool curhit;
|
||||
|
||||
curhit = isect_ray_tri_v3(ray_start, ray_dir, v_first->co, v_prev->co, v->co, &dist, NULL);
|
||||
curhit = isect_ray_tri_v3(
|
||||
ray_start, ray_dir, v_first->co, v_prev->co, v->co, &dist, nullptr);
|
||||
if (curhit && dist < best_dist) {
|
||||
hit = true;
|
||||
best_dist = dist;
|
||||
@@ -1204,13 +1206,13 @@ static BMFace *collapse_face_corners(BMesh *bm, BMFace *f, int n, BMVert **orig_
|
||||
BMO_op_finish(bm, &op);
|
||||
|
||||
/* Find the new face */
|
||||
f = NULL;
|
||||
f = nullptr;
|
||||
BM_ITER_ELEM (vf, &iter, v_safe, BM_FACES_OF_VERT) {
|
||||
bool wrong_face = false;
|
||||
|
||||
for (i = 0; i < orig_len; i++) {
|
||||
if (orig_verts[i] == v_merge) {
|
||||
orig_verts[i] = NULL;
|
||||
orig_verts[i] = nullptr;
|
||||
}
|
||||
else if (orig_verts[i] && !BM_vert_in_face(orig_verts[i], vf)) {
|
||||
wrong_face = true;
|
||||
@@ -1250,7 +1252,7 @@ static BMFace *skin_hole_target_face(BMesh *bm, Frame *frame)
|
||||
|
||||
/* Use a line intersection test and nearest center test against
|
||||
* all faces */
|
||||
isect_target_face = center_target_face = NULL;
|
||||
isect_target_face = center_target_face = nullptr;
|
||||
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
|
||||
float dist, poly_center[3];
|
||||
int hit;
|
||||
@@ -1322,8 +1324,6 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f
|
||||
{
|
||||
BMFace *f;
|
||||
BMVert *verts[4];
|
||||
BMVert **vert_buf = NULL;
|
||||
BLI_array_declare(vert_buf);
|
||||
BMOIter oiter;
|
||||
BMOperator op;
|
||||
int i, best_order[4];
|
||||
@@ -1343,7 +1343,7 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f
|
||||
|
||||
/* Update split face (should only be one new face created
|
||||
* during extrusion) */
|
||||
split_face = NULL;
|
||||
split_face = nullptr;
|
||||
BMO_ITER (f, &oiter, op.slots_out, "faces.out", BM_FACE) {
|
||||
BLI_assert(!split_face);
|
||||
split_face = f;
|
||||
@@ -1351,6 +1351,8 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f
|
||||
|
||||
BMO_op_finish(bm, &op);
|
||||
|
||||
blender::Vector<BMVert *> vert_buf;
|
||||
|
||||
if (split_face->len == 3) {
|
||||
BMEdge *longest_edge;
|
||||
|
||||
@@ -1371,16 +1373,14 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f
|
||||
else if (split_face->len > 4) {
|
||||
/* Maintain a dynamic vert array containing the split_face's
|
||||
* vertices, avoids frequent allocations in #collapse_face_corners(). */
|
||||
if (BLI_array_len(vert_buf) < split_face->len) {
|
||||
BLI_array_grow_items(vert_buf, (split_face->len - BLI_array_len(vert_buf)));
|
||||
}
|
||||
vert_buf.reinitialize(split_face->len);
|
||||
|
||||
/* Get split face's verts */
|
||||
BM_iter_as_array(bm, BM_VERTS_OF_FACE, split_face, (void **)vert_buf, split_face->len);
|
||||
BM_iter_as_array(bm, BM_VERTS_OF_FACE, split_face, (void **)vert_buf.data(), split_face->len);
|
||||
|
||||
/* Earlier edge split operations may have turned some quads
|
||||
* into higher-degree faces */
|
||||
split_face = collapse_face_corners(bm, split_face, 4, vert_buf);
|
||||
split_face = collapse_face_corners(bm, split_face, 4, vert_buf.data());
|
||||
}
|
||||
|
||||
/* `split_face` should now be a quad. */
|
||||
@@ -1389,19 +1389,13 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f
|
||||
/* Account for the highly unlikely case that it's not a quad. */
|
||||
if (split_face->len != 4) {
|
||||
/* Reuse `vert_buf` for updating normals. */
|
||||
BLI_array_clear(vert_buf);
|
||||
BLI_array_grow_items(vert_buf, split_face->len);
|
||||
vert_buf.reinitialize(split_face->len);
|
||||
BM_iter_as_array(bm, BM_FACES_OF_VERT, split_face, (void **)vert_buf.data(), split_face->len);
|
||||
|
||||
BM_iter_as_array(bm, BM_FACES_OF_VERT, split_face, (void **)vert_buf, split_face->len);
|
||||
|
||||
vert_array_face_normal_update(vert_buf, split_face->len);
|
||||
BLI_array_free(vert_buf);
|
||||
vert_array_face_normal_update(vert_buf.data(), split_face->len);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Done with dynamic array. */
|
||||
BLI_array_free(vert_buf);
|
||||
|
||||
/* Get split face's verts */
|
||||
// BM_iter_as_array(bm, BM_VERTS_OF_FACE, split_face, (void **)verts, 4);
|
||||
BM_face_as_array_vert_quad(split_face, verts);
|
||||
@@ -1444,7 +1438,7 @@ static void skin_hole_detach_partially_attached_frame(BMesh *bm, Frame *frame)
|
||||
static void quad_from_tris(BMEdge *e, BMFace *adj[2], BMVert *ndx[4])
|
||||
{
|
||||
BMVert *tri[2][3];
|
||||
BMVert *opp = NULL;
|
||||
BMVert *opp = nullptr;
|
||||
int i, j;
|
||||
|
||||
BLI_assert(adj[0]->len == 3 && adj[1]->len == 3);
|
||||
@@ -1544,7 +1538,7 @@ static void hull_merge_triangles(SkinOutput *so, const SkinModifierData *smd)
|
||||
while (!BLI_heapsimple_is_empty(heap)) {
|
||||
BMFace *adj[2];
|
||||
|
||||
e = BLI_heapsimple_pop_min(heap);
|
||||
e = static_cast<BMEdge *>(BLI_heapsimple_pop_min(heap));
|
||||
|
||||
if (BM_edge_face_pair(e, &adj[0], &adj[1])) {
|
||||
/* If both triangles still free, and if they don't already
|
||||
@@ -1559,7 +1553,7 @@ static void hull_merge_triangles(SkinOutput *so, const SkinModifierData *smd)
|
||||
}
|
||||
}
|
||||
|
||||
BLI_heapsimple_free(heap, NULL);
|
||||
BLI_heapsimple_free(heap, nullptr);
|
||||
|
||||
BM_mesh_delete_hflag_tagged(so->bm, BM_ELEM_TAG, BM_EDGE | BM_FACE);
|
||||
}
|
||||
@@ -1744,7 +1738,9 @@ static void skin_smooth_hulls(BMesh *bm,
|
||||
BM_data_layer_add(bm, &bm->vdata, CD_SHAPEKEY);
|
||||
skey = CustomData_number_of_layers(&bm->vdata, CD_SHAPEKEY) - 1;
|
||||
BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
|
||||
copy_v3_v3(CustomData_bmesh_get_n(&bm->vdata, v->head.data, CD_SHAPEKEY, skey), v->co);
|
||||
copy_v3_v3(
|
||||
static_cast<float *>(CustomData_bmesh_get_n(&bm->vdata, v->head.data, CD_SHAPEKEY, skey)),
|
||||
v->co);
|
||||
}
|
||||
|
||||
/* Smooth vertices, weight unmarked vertices more strongly (helps
|
||||
@@ -1764,12 +1760,14 @@ static void skin_smooth_hulls(BMesh *bm,
|
||||
BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) {
|
||||
BMVert *other = BM_edge_other_vert(e, v);
|
||||
|
||||
add_v3_v3(avg, CustomData_bmesh_get_n(&bm->vdata, other->head.data, CD_SHAPEKEY, skey));
|
||||
add_v3_v3(avg,
|
||||
static_cast<float *>(
|
||||
CustomData_bmesh_get_n(&bm->vdata, other->head.data, CD_SHAPEKEY, skey)));
|
||||
totv++;
|
||||
}
|
||||
|
||||
if (totv > 1) {
|
||||
mul_v3_fl(avg, 1.0f / (float)totv);
|
||||
mul_v3_fl(avg, 1.0f / float(totv));
|
||||
interp_v3_v3v3(v->co, v->co, avg, weight);
|
||||
}
|
||||
}
|
||||
@@ -1813,10 +1811,11 @@ static bool skin_output_branch_hulls(SkinOutput *so,
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef enum eSkinErrorFlag {
|
||||
enum eSkinErrorFlag {
|
||||
SKIN_ERROR_NO_VALID_ROOT = (1 << 0),
|
||||
SKIN_ERROR_HULL = (1 << 1),
|
||||
} eSkinErrorFlag;
|
||||
};
|
||||
ENUM_OPERATORS(eSkinErrorFlag, SKIN_ERROR_HULL);
|
||||
|
||||
static BMesh *build_skin(SkinNode *skin_nodes,
|
||||
int verts_num,
|
||||
@@ -1831,16 +1830,15 @@ static BMesh *build_skin(SkinNode *skin_nodes,
|
||||
int v;
|
||||
|
||||
so.smd = smd;
|
||||
so.bm = BM_mesh_create(&bm_mesh_allocsize_default,
|
||||
&((struct BMeshCreateParams){
|
||||
.use_toolflags = true,
|
||||
}));
|
||||
BMeshCreateParams create_params{};
|
||||
create_params.use_toolflags = true;
|
||||
so.bm = BM_mesh_create(&bm_mesh_allocsize_default, &create_params);
|
||||
so.mat_nr = 0;
|
||||
|
||||
/* BMESH_TODO: bumping up the stack level (see MOD_array.cc) */
|
||||
BM_mesh_elem_toolflags_ensure(so.bm);
|
||||
BMO_push(so.bm, NULL);
|
||||
bmesh_edit_begin(so.bm, 0);
|
||||
BMO_push(so.bm, nullptr);
|
||||
bmesh_edit_begin(so.bm, BMOpTypeFlag(0));
|
||||
|
||||
if (input_dvert) {
|
||||
BM_data_layer_add(so.bm, &so.bm->vdata, CD_MDEFORMVERT);
|
||||
@@ -1853,7 +1851,7 @@ static BMesh *build_skin(SkinNode *skin_nodes,
|
||||
/* Write out all frame vertices to the mesh */
|
||||
for (v = 0; v < verts_num; v++) {
|
||||
if (skin_nodes[v].totframe) {
|
||||
output_frames(so.bm, &skin_nodes[v], input_dvert ? &input_dvert[v] : NULL);
|
||||
output_frames(so.bm, &skin_nodes[v], input_dvert ? &input_dvert[v] : nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1886,7 +1884,7 @@ static BMesh *build_skin(SkinNode *skin_nodes,
|
||||
skin_output_connections(&so, skin_nodes, medge, edges_num);
|
||||
hull_merge_triangles(&so, smd);
|
||||
|
||||
bmesh_edit_end(so.bm, 0);
|
||||
bmesh_edit_end(so.bm, BMOpTypeFlag(0));
|
||||
BMO_pop(so.bm);
|
||||
|
||||
return so.bm;
|
||||
@@ -1894,11 +1892,9 @@ static BMesh *build_skin(SkinNode *skin_nodes,
|
||||
|
||||
static void skin_set_orig_indices(Mesh *mesh)
|
||||
{
|
||||
int *orig, totpoly;
|
||||
|
||||
totpoly = mesh->totpoly;
|
||||
orig = CustomData_add_layer(&mesh->pdata, CD_ORIGINDEX, CD_CONSTRUCT, NULL, totpoly);
|
||||
copy_vn_i(orig, totpoly, ORIGINDEX_NONE);
|
||||
int *orig = static_cast<int *>(
|
||||
CustomData_add_layer(&mesh->pdata, CD_ORIGINDEX, CD_CONSTRUCT, nullptr, mesh->totpoly));
|
||||
copy_vn_i(orig, mesh->totpoly, ORIGINDEX_NONE);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1910,7 +1906,6 @@ static void skin_set_orig_indices(Mesh *mesh)
|
||||
static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_error)
|
||||
{
|
||||
Mesh *result;
|
||||
const MVertSkin *nodes;
|
||||
BMesh *bm;
|
||||
EMat *emat;
|
||||
SkinNode *skin_nodes;
|
||||
@@ -1921,7 +1916,8 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_
|
||||
int verts_num, edges_num;
|
||||
bool has_valid_root = false;
|
||||
|
||||
nodes = CustomData_get_layer(&origmesh->vdata, CD_MVERT_SKIN);
|
||||
const MVertSkin *nodes = static_cast<const MVertSkin *>(
|
||||
CustomData_get_layer(&origmesh->vdata, CD_MVERT_SKIN));
|
||||
|
||||
const float(*vert_positions)[3] = BKE_mesh_vert_positions(origmesh);
|
||||
dvert = BKE_mesh_deform_verts(origmesh);
|
||||
@@ -1935,7 +1931,7 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_
|
||||
nodes, vert_positions, verts_num, medge, emap, edges_num, &has_valid_root);
|
||||
skin_nodes = build_frames(vert_positions, verts_num, nodes, emap, emat);
|
||||
MEM_freeN(emat);
|
||||
emat = NULL;
|
||||
emat = nullptr;
|
||||
|
||||
bm = build_skin(skin_nodes, verts_num, emap, medge, edges_num, dvert, smd, r_error);
|
||||
|
||||
@@ -1948,10 +1944,10 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_
|
||||
}
|
||||
|
||||
if (!bm) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL, origmesh);
|
||||
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, nullptr, origmesh);
|
||||
BM_mesh_free(bm);
|
||||
|
||||
skin_set_orig_indices(result);
|
||||
@@ -1971,7 +1967,7 @@ static Mesh *final_skin(SkinModifierData *smd, Mesh *mesh, eSkinErrorFlag *r_err
|
||||
mesh = subdivide_base(mesh);
|
||||
result = base_skin(mesh, smd, r_error);
|
||||
|
||||
BKE_id_free(NULL, mesh);
|
||||
BKE_id_free(nullptr, mesh);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1991,7 +1987,7 @@ static void initData(ModifierData *md)
|
||||
|
||||
static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
|
||||
{
|
||||
eSkinErrorFlag error = 0;
|
||||
eSkinErrorFlag error = eSkinErrorFlag(0);
|
||||
Mesh *result = final_skin((SkinModifierData *)md, mesh, &error);
|
||||
|
||||
if (error & SKIN_ERROR_NO_VALID_ROOT) {
|
||||
@@ -2007,18 +2003,18 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
||||
}
|
||||
BLI_assert(error == 0);
|
||||
|
||||
if (result == NULL) {
|
||||
if (result == nullptr) {
|
||||
return mesh;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void requiredDataMask(ModifierData *UNUSED(md), CustomData_MeshMasks *r_cddata_masks)
|
||||
static void requiredDataMask(ModifierData * /*md*/, CustomData_MeshMasks *r_cddata_masks)
|
||||
{
|
||||
r_cddata_masks->vmask |= CD_MASK_MVERT_SKIN | CD_MASK_MDEFORMVERT;
|
||||
}
|
||||
|
||||
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
|
||||
static void panel_draw(const bContext * /*C*/, Panel *panel)
|
||||
{
|
||||
uiLayout *row;
|
||||
uiLayout *layout = panel->layout;
|
||||
@@ -2031,25 +2027,25 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel)
|
||||
|
||||
uiLayoutSetPropSep(layout, true);
|
||||
|
||||
uiItemR(layout, ptr, "branch_smoothing", 0, NULL, ICON_NONE);
|
||||
uiItemR(layout, ptr, "branch_smoothing", 0, nullptr, ICON_NONE);
|
||||
|
||||
row = uiLayoutRowWithHeading(layout, true, IFACE_("Symmetry"));
|
||||
uiItemR(row, ptr, "use_x_symmetry", toggles_flag, NULL, ICON_NONE);
|
||||
uiItemR(row, ptr, "use_y_symmetry", toggles_flag, NULL, ICON_NONE);
|
||||
uiItemR(row, ptr, "use_z_symmetry", toggles_flag, NULL, ICON_NONE);
|
||||
uiItemR(row, ptr, "use_x_symmetry", toggles_flag, nullptr, ICON_NONE);
|
||||
uiItemR(row, ptr, "use_y_symmetry", toggles_flag, nullptr, ICON_NONE);
|
||||
uiItemR(row, ptr, "use_z_symmetry", toggles_flag, nullptr, ICON_NONE);
|
||||
|
||||
uiItemR(layout, ptr, "use_smooth_shade", 0, NULL, ICON_NONE);
|
||||
uiItemR(layout, ptr, "use_smooth_shade", 0, nullptr, ICON_NONE);
|
||||
|
||||
row = uiLayoutRow(layout, false);
|
||||
uiItemO(row, IFACE_("Create Armature"), ICON_NONE, "OBJECT_OT_skin_armature_create");
|
||||
uiItemO(row, NULL, ICON_NONE, "MESH_OT_customdata_skin_add");
|
||||
uiItemO(row, nullptr, ICON_NONE, "MESH_OT_customdata_skin_add");
|
||||
|
||||
row = uiLayoutRow(layout, false);
|
||||
uiItemFullO(row,
|
||||
"OBJECT_OT_skin_loose_mark_clear",
|
||||
IFACE_("Mark Loose"),
|
||||
ICON_NONE,
|
||||
NULL,
|
||||
nullptr,
|
||||
WM_OP_EXEC_DEFAULT,
|
||||
0,
|
||||
&op_ptr);
|
||||
@@ -2058,7 +2054,7 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel)
|
||||
"OBJECT_OT_skin_loose_mark_clear",
|
||||
IFACE_("Clear Loose"),
|
||||
ICON_NONE,
|
||||
NULL,
|
||||
nullptr,
|
||||
WM_OP_EXEC_DEFAULT,
|
||||
0,
|
||||
&op_ptr);
|
||||
@@ -2086,24 +2082,24 @@ ModifierTypeInfo modifierType_Skin = {
|
||||
|
||||
/*copyData*/ BKE_modifier_copydata_generic,
|
||||
|
||||
/*deformVerts*/ NULL,
|
||||
/*deformMatrices*/ NULL,
|
||||
/*deformVertsEM*/ NULL,
|
||||
/*deformMatricesEM*/ NULL,
|
||||
/*deformVerts*/ nullptr,
|
||||
/*deformMatrices*/ nullptr,
|
||||
/*deformVertsEM*/ nullptr,
|
||||
/*deformMatricesEM*/ nullptr,
|
||||
/*modifyMesh*/ modifyMesh,
|
||||
/*modifyGeometrySet*/ NULL,
|
||||
/*modifyGeometrySet*/ nullptr,
|
||||
|
||||
/*initData*/ initData,
|
||||
/*requiredDataMask*/ requiredDataMask,
|
||||
/*freeData*/ NULL,
|
||||
/*isDisabled*/ NULL,
|
||||
/*updateDepsgraph*/ NULL,
|
||||
/*dependsOnTime*/ NULL,
|
||||
/*dependsOnNormals*/ NULL,
|
||||
/*foreachIDLink*/ NULL,
|
||||
/*foreachTexLink*/ NULL,
|
||||
/*freeRuntimeData*/ NULL,
|
||||
/*freeData*/ nullptr,
|
||||
/*isDisabled*/ nullptr,
|
||||
/*updateDepsgraph*/ nullptr,
|
||||
/*dependsOnTime*/ nullptr,
|
||||
/*dependsOnNormals*/ nullptr,
|
||||
/*foreachIDLink*/ nullptr,
|
||||
/*foreachTexLink*/ nullptr,
|
||||
/*freeRuntimeData*/ nullptr,
|
||||
/*panelRegister*/ panelRegister,
|
||||
/*blendWrite*/ NULL,
|
||||
/*blendRead*/ NULL,
|
||||
/*blendWrite*/ nullptr,
|
||||
/*blendRead*/ nullptr,
|
||||
};
|
||||
@@ -47,9 +47,7 @@ static void initData(ModifierData *md)
|
||||
MEMCPY_STRUCT_AFTER(smd, DNA_struct_default_get(SmoothModifierData), modifier);
|
||||
}
|
||||
|
||||
static bool isDisabled(const struct Scene *UNUSED(scene),
|
||||
ModifierData *md,
|
||||
bool UNUSED(useRenderParams))
|
||||
static bool isDisabled(const Scene * /*scene*/, ModifierData *md, bool /*useRenderParams*/)
|
||||
{
|
||||
SmoothModifierData *smd = (SmoothModifierData *)md;
|
||||
|
||||
@@ -76,18 +74,18 @@ static void requiredDataMask(ModifierData *md, CustomData_MeshMasks *r_cddata_ma
|
||||
static void smoothModifier_do(
|
||||
SmoothModifierData *smd, Object *ob, Mesh *mesh, float (*vertexCos)[3], int verts_num)
|
||||
{
|
||||
if (mesh == NULL) {
|
||||
if (mesh == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
float(*accumulated_vecs)[3] = MEM_calloc_arrayN(
|
||||
(size_t)verts_num, sizeof(*accumulated_vecs), __func__);
|
||||
float(*accumulated_vecs)[3] = static_cast<float(*)[3]>(
|
||||
MEM_calloc_arrayN((size_t)verts_num, sizeof(*accumulated_vecs), __func__));
|
||||
if (!accumulated_vecs) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint *accumulated_vecs_count = MEM_calloc_arrayN(
|
||||
(size_t)verts_num, sizeof(*accumulated_vecs_count), __func__);
|
||||
uint *accumulated_vecs_count = static_cast<uint *>(
|
||||
MEM_calloc_arrayN((size_t)verts_num, sizeof(*accumulated_vecs_count), __func__));
|
||||
if (!accumulated_vecs_count) {
|
||||
MEM_freeN(accumulated_vecs);
|
||||
return;
|
||||
@@ -130,7 +128,7 @@ static void smoothModifier_do(
|
||||
for (int i = 0; i < verts_num; i++, dv++) {
|
||||
float *vco_orig = vertexCos[i];
|
||||
if (accumulated_vecs_count[i] > 0) {
|
||||
mul_v3_fl(accumulated_vecs[i], 1.0f / (float)accumulated_vecs_count[i]);
|
||||
mul_v3_fl(accumulated_vecs[i], 1.0f / float(accumulated_vecs_count[i]));
|
||||
}
|
||||
float *vco_new = accumulated_vecs[i];
|
||||
|
||||
@@ -157,7 +155,7 @@ static void smoothModifier_do(
|
||||
for (int i = 0; i < verts_num; i++) {
|
||||
float *vco_orig = vertexCos[i];
|
||||
if (accumulated_vecs_count[i] > 0) {
|
||||
mul_v3_fl(accumulated_vecs[i], 1.0f / (float)accumulated_vecs_count[i]);
|
||||
mul_v3_fl(accumulated_vecs[i], 1.0f / float(accumulated_vecs_count[i]));
|
||||
}
|
||||
float *vco_new = accumulated_vecs[i];
|
||||
|
||||
@@ -185,42 +183,42 @@ static void deformVerts(ModifierData *md,
|
||||
int verts_num)
|
||||
{
|
||||
SmoothModifierData *smd = (SmoothModifierData *)md;
|
||||
Mesh *mesh_src = NULL;
|
||||
Mesh *mesh_src = nullptr;
|
||||
|
||||
/* mesh_src is needed for vgroups, and taking edges into account. */
|
||||
mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, verts_num, false);
|
||||
mesh_src = MOD_deform_mesh_eval_get(ctx->object, nullptr, mesh, nullptr, verts_num, false);
|
||||
|
||||
smoothModifier_do(smd, ctx->object, mesh_src, vertexCos, verts_num);
|
||||
|
||||
if (!ELEM(mesh_src, NULL, mesh)) {
|
||||
BKE_id_free(NULL, mesh_src);
|
||||
if (!ELEM(mesh_src, nullptr, mesh)) {
|
||||
BKE_id_free(nullptr, mesh_src);
|
||||
}
|
||||
}
|
||||
|
||||
static void deformVertsEM(ModifierData *md,
|
||||
const ModifierEvalContext *ctx,
|
||||
struct BMEditMesh *editData,
|
||||
BMEditMesh *editData,
|
||||
Mesh *mesh,
|
||||
float (*vertexCos)[3],
|
||||
int verts_num)
|
||||
{
|
||||
SmoothModifierData *smd = (SmoothModifierData *)md;
|
||||
Mesh *mesh_src = NULL;
|
||||
Mesh *mesh_src = nullptr;
|
||||
|
||||
/* mesh_src is needed for vgroups, and taking edges into account. */
|
||||
mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, verts_num, false);
|
||||
mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, nullptr, verts_num, false);
|
||||
|
||||
/* TODO(@ideasman42): use edit-mode data only (remove this line). */
|
||||
BKE_mesh_wrapper_ensure_mdata(mesh_src);
|
||||
|
||||
smoothModifier_do(smd, ctx->object, mesh_src, vertexCos, verts_num);
|
||||
|
||||
if (!ELEM(mesh_src, NULL, mesh)) {
|
||||
BKE_id_free(NULL, mesh_src);
|
||||
if (!ELEM(mesh_src, nullptr, mesh)) {
|
||||
BKE_id_free(nullptr, mesh_src);
|
||||
}
|
||||
}
|
||||
|
||||
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
|
||||
static void panel_draw(const bContext * /*C*/, Panel *panel)
|
||||
{
|
||||
uiLayout *row, *col;
|
||||
uiLayout *layout = panel->layout;
|
||||
@@ -232,15 +230,15 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel)
|
||||
uiLayoutSetPropSep(layout, true);
|
||||
|
||||
row = uiLayoutRowWithHeading(layout, true, IFACE_("Axis"));
|
||||
uiItemR(row, ptr, "use_x", toggles_flag, NULL, ICON_NONE);
|
||||
uiItemR(row, ptr, "use_y", toggles_flag, NULL, ICON_NONE);
|
||||
uiItemR(row, ptr, "use_z", toggles_flag, NULL, ICON_NONE);
|
||||
uiItemR(row, ptr, "use_x", toggles_flag, nullptr, ICON_NONE);
|
||||
uiItemR(row, ptr, "use_y", toggles_flag, nullptr, ICON_NONE);
|
||||
uiItemR(row, ptr, "use_z", toggles_flag, nullptr, ICON_NONE);
|
||||
|
||||
col = uiLayoutColumn(layout, false);
|
||||
uiItemR(col, ptr, "factor", 0, NULL, ICON_NONE);
|
||||
uiItemR(col, ptr, "iterations", 0, NULL, ICON_NONE);
|
||||
uiItemR(col, ptr, "factor", 0, nullptr, ICON_NONE);
|
||||
uiItemR(col, ptr, "iterations", 0, nullptr, ICON_NONE);
|
||||
|
||||
modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", NULL);
|
||||
modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", nullptr);
|
||||
|
||||
modifier_panel_end(layout, ptr);
|
||||
}
|
||||
@@ -263,23 +261,23 @@ ModifierTypeInfo modifierType_Smooth = {
|
||||
/*copyData*/ BKE_modifier_copydata_generic,
|
||||
|
||||
/*deformVerts*/ deformVerts,
|
||||
/*deformMatrices*/ NULL,
|
||||
/*deformMatrices*/ nullptr,
|
||||
/*deformVertsEM*/ deformVertsEM,
|
||||
/*deformMatricesEM*/ NULL,
|
||||
/*modifyMesh*/ NULL,
|
||||
/*modifyGeometrySet*/ NULL,
|
||||
/*deformMatricesEM*/ nullptr,
|
||||
/*modifyMesh*/ nullptr,
|
||||
/*modifyGeometrySet*/ nullptr,
|
||||
|
||||
/*initData*/ initData,
|
||||
/*requiredDataMask*/ requiredDataMask,
|
||||
/*freeData*/ NULL,
|
||||
/*freeData*/ nullptr,
|
||||
/*isDisabled*/ isDisabled,
|
||||
/*updateDepsgraph*/ NULL,
|
||||
/*dependsOnTime*/ NULL,
|
||||
/*dependsOnNormals*/ NULL,
|
||||
/*foreachIDLink*/ NULL,
|
||||
/*foreachTexLink*/ NULL,
|
||||
/*freeRuntimeData*/ NULL,
|
||||
/*updateDepsgraph*/ nullptr,
|
||||
/*dependsOnTime*/ nullptr,
|
||||
/*dependsOnNormals*/ nullptr,
|
||||
/*foreachIDLink*/ nullptr,
|
||||
/*foreachTexLink*/ nullptr,
|
||||
/*freeRuntimeData*/ nullptr,
|
||||
/*panelRegister*/ panelRegister,
|
||||
/*blendWrite*/ NULL,
|
||||
/*blendRead*/ NULL,
|
||||
/*blendWrite*/ nullptr,
|
||||
/*blendRead*/ nullptr,
|
||||
};
|
||||
Reference in New Issue
Block a user