Changeset View
Changeset View
Standalone View
Standalone View
source/blender/modifiers/intern/MOD_laplaciansmooth.c
| Show All 23 Lines | |||||
| * | * | ||||
| */ | */ | ||||
| /** \file blender/modifiers/intern/MOD_laplaciansmooth.c | /** \file blender/modifiers/intern/MOD_laplaciansmooth.c | ||||
| * \ingroup modifiers | * \ingroup modifiers | ||||
| */ | */ | ||||
| #include "DNA_mesh_types.h" | |||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BKE_cdderivedmesh.h" | |||||
| #include "BKE_deform.h" | #include "BKE_deform.h" | ||||
| #include "BKE_editmesh.h" | |||||
| #include "BKE_library.h" | |||||
| #include "BKE_mesh.h" | |||||
| #include "BKE_modifier.h" | #include "BKE_modifier.h" | ||||
| #include "MOD_util.h" | #include "MOD_util.h" | ||||
sybren: Keep new includes ordered alphabetically. | |||||
| #include "eigen_capi.h" | #include "eigen_capi.h" | ||||
| #if 0 | #if 0 | ||||
| #define MOD_LAPLACIANSMOOTH_MAX_EDGE_PERCENTAGE 1.8f | #define MOD_LAPLACIANSMOOTH_MAX_EDGE_PERCENTAGE 1.8f | ||||
| #define MOD_LAPLACIANSMOOTH_MIN_EDGE_PERCENTAGE 0.02f | #define MOD_LAPLACIANSMOOTH_MIN_EDGE_PERCENTAGE 0.02f | ||||
| #endif | #endif | ||||
| struct BLaplacianSystem { | struct BLaplacianSystem { | ||||
| ▲ Show 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | static void validate_solution(LaplacianSystem *sys, short flag, float lambda, float lambda_border) | ||||
| } | } | ||||
| if (flag & MOD_LAPLACIANSMOOTH_PRESERVE_VOLUME) { | if (flag & MOD_LAPLACIANSMOOTH_PRESERVE_VOLUME) { | ||||
| vend = compute_volume(sys->vert_centroid, sys->vertexCos, sys->mpoly, sys->numPolys, sys->mloop); | vend = compute_volume(sys->vert_centroid, sys->vertexCos, sys->mpoly, sys->numPolys, sys->mloop); | ||||
| volume_preservation(sys, vini, vend, flag); | volume_preservation(sys, vini, vend, flag); | ||||
| } | } | ||||
| } | } | ||||
| static void laplaciansmoothModifier_do( | static void laplaciansmoothModifier_do( | ||||
| LaplacianSmoothModifierData *smd, Object *ob, DerivedMesh *dm, | LaplacianSmoothModifierData *smd, Object *ob, Mesh *mesh, | ||||
| float (*vertexCos)[3], int numVerts) | float (*vertexCos)[3], int numVerts) | ||||
| { | { | ||||
| LaplacianSystem *sys; | LaplacianSystem *sys; | ||||
| MDeformVert *dvert = NULL; | MDeformVert *dvert = NULL; | ||||
| MDeformVert *dv = NULL; | MDeformVert *dv = NULL; | ||||
| float w, wpaint; | float w, wpaint; | ||||
| int i, iter; | int i, iter; | ||||
| int defgrp_index; | int defgrp_index; | ||||
| sys = init_laplacian_system(dm->getNumEdges(dm), dm->getNumPolys(dm), dm->getNumLoops(dm), numVerts); | sys = init_laplacian_system(mesh->totedge, mesh->totpoly, mesh->totloop, numVerts); | ||||
| if (!sys) { | if (!sys) { | ||||
| return; | return; | ||||
| } | } | ||||
| sys->mpoly = dm->getPolyArray(dm); | sys->mpoly = mesh->mpoly; | ||||
| sys->mloop = dm->getLoopArray(dm); | sys->mloop = mesh->mloop; | ||||
| sys->medges = dm->getEdgeArray(dm); | sys->medges = mesh->medge; | ||||
| sys->vertexCos = vertexCos; | sys->vertexCos = vertexCos; | ||||
| sys->min_area = 0.00001f; | sys->min_area = 0.00001f; | ||||
| modifier_get_vgroup(ob, dm, smd->defgrp_name, &dvert, &defgrp_index); | modifier_get_vgroup_mesh(ob, mesh, smd->defgrp_name, &dvert, &defgrp_index); | ||||
| sys->vert_centroid[0] = 0.0f; | sys->vert_centroid[0] = 0.0f; | ||||
| sys->vert_centroid[1] = 0.0f; | sys->vert_centroid[1] = 0.0f; | ||||
| sys->vert_centroid[2] = 0.0f; | sys->vert_centroid[2] = 0.0f; | ||||
| memset_laplacian_system(sys, 0); | memset_laplacian_system(sys, 0); | ||||
| sys->context = EIG_linear_least_squares_solver_new(numVerts, numVerts, 3); | sys->context = EIG_linear_least_squares_solver_new(numVerts, numVerts, 3); | ||||
| ▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | static CustomDataMask required_data_mask(Object *UNUSED(ob), ModifierData *md) | ||||
| CustomDataMask dataMask = 0; | CustomDataMask dataMask = 0; | ||||
| /* ask for vertexgroups if we need them */ | /* ask for vertexgroups if we need them */ | ||||
| if (smd->defgrp_name[0]) dataMask |= CD_MASK_MDEFORMVERT; | if (smd->defgrp_name[0]) dataMask |= CD_MASK_MDEFORMVERT; | ||||
| return dataMask; | return dataMask; | ||||
| } | } | ||||
| static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx, DerivedMesh *derivedData, | static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, | ||||
| float (*vertexCos)[3], int numVerts) | float (*vertexCos)[3], int numVerts) | ||||
| { | { | ||||
| DerivedMesh *dm; | Mesh *mesh_src; | ||||
Not Done Inline ActionsRename mesh to mesh_src and meshData to mesh, to be consistent with other modifiers. sybren: Rename `mesh` to `mesh_src` and `meshData` to `mesh`, to be consistent with other modifiers. | |||||
| if (numVerts == 0) | if (numVerts == 0) | ||||
| return; | return; | ||||
| dm = get_dm(ctx->object, NULL, derivedData, NULL, false, false); | mesh_src = get_mesh(ctx->object, NULL, mesh, NULL, false, false); | ||||
| laplaciansmoothModifier_do((LaplacianSmoothModifierData *)md, ctx->object, dm, | laplaciansmoothModifier_do((LaplacianSmoothModifierData *)md, ctx->object, mesh_src, | ||||
| vertexCos, numVerts); | vertexCos, numVerts); | ||||
| if (dm != derivedData) | if (mesh_src != mesh) | ||||
| dm->release(dm); | BKE_id_free(NULL, mesh_src); | ||||
| } | } | ||||
| static void deformVertsEM( | static void deformVertsEM( | ||||
| ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *editData, | ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *editData, | ||||
| DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) | Mesh *mesh, float (*vertexCos)[3], int numVerts) | ||||
| { | { | ||||
| DerivedMesh *dm; | Mesh *mesh_src; | ||||
Not Done Inline ActionsRename mesh to mesh_src and meshData to mesh, to be consistent with other modifiers. sybren: Rename `mesh` to `mesh_src` and `meshData` to `mesh`, to be consistent with other modifiers. | |||||
| if (numVerts == 0) | if (numVerts == 0) | ||||
| return; | return; | ||||
| dm = get_dm(ctx->object, editData, derivedData, NULL, false, false); | mesh_src = get_mesh(ctx->object, editData, mesh, NULL, false, false); | ||||
| laplaciansmoothModifier_do((LaplacianSmoothModifierData *)md, ctx->object, dm, | laplaciansmoothModifier_do((LaplacianSmoothModifierData *)md, ctx->object, mesh_src, | ||||
| vertexCos, numVerts); | vertexCos, numVerts); | ||||
| if (dm != derivedData) | if (mesh_src != mesh) | ||||
| dm->release(dm); | BKE_id_free(NULL, mesh_src); | ||||
| } | } | ||||
| ModifierTypeInfo modifierType_LaplacianSmooth = { | ModifierTypeInfo modifierType_LaplacianSmooth = { | ||||
| /* name */ "Laplacian Smooth", | /* name */ "Laplacian Smooth", | ||||
| /* structName */ "LaplacianSmoothModifierData", | /* structName */ "LaplacianSmoothModifierData", | ||||
| /* structSize */ sizeof(LaplacianSmoothModifierData), | /* structSize */ sizeof(LaplacianSmoothModifierData), | ||||
| /* type */ eModifierTypeType_OnlyDeform, | /* type */ eModifierTypeType_OnlyDeform, | ||||
| /* flags */ eModifierTypeFlag_AcceptsMesh | | /* flags */ eModifierTypeFlag_AcceptsMesh | | ||||
| eModifierTypeFlag_SupportsEditmode, | eModifierTypeFlag_SupportsEditmode, | ||||
| /* copyData */ modifier_copyData_generic, | /* copyData */ modifier_copyData_generic, | ||||
| /* deformVerts_DM */ deformVerts, | /* deformVerts_DM */ NULL, | ||||
| /* deformMatrices_DM */ NULL, | /* deformMatrices_DM */ NULL, | ||||
| /* deformVertsEM_DM */ deformVertsEM, | /* deformVertsEM_DM */ NULL, | ||||
| /* deformMatricesEM_DM*/NULL, | /* deformMatricesEM_DM*/NULL, | ||||
| /* applyModifier_DM */ NULL, | /* applyModifier_DM */ NULL, | ||||
| /* applyModifierEM_DM */NULL, | /* applyModifierEM_DM */NULL, | ||||
| /* deformVerts */ NULL, | /* deformVerts */ deformVerts, | ||||
| /* deformMatrices */ NULL, | /* deformMatrices */ NULL, | ||||
| /* deformVertsEM */ NULL, | /* deformVertsEM */ deformVertsEM, | ||||
| /* deformMatricesEM */ NULL, | /* deformMatricesEM */ NULL, | ||||
| /* applyModifier */ NULL, | /* applyModifier */ NULL, | ||||
| /* applyModifierEM */ NULL, | /* applyModifierEM */ NULL, | ||||
| /* initData */ init_data, | /* initData */ init_data, | ||||
| /* requiredDataMask */ required_data_mask, | /* requiredDataMask */ required_data_mask, | ||||
| /* freeData */ NULL, | /* freeData */ NULL, | ||||
| /* isDisabled */ is_disabled, | /* isDisabled */ is_disabled, | ||||
| /* updateDepsgraph */ NULL, | /* updateDepsgraph */ NULL, | ||||
| /* dependsOnTime */ NULL, | /* dependsOnTime */ NULL, | ||||
| /* dependsOnNormals */ NULL, | /* dependsOnNormals */ NULL, | ||||
| /* foreachObjectLink */ NULL, | /* foreachObjectLink */ NULL, | ||||
| /* foreachIDLink */ NULL, | /* foreachIDLink */ NULL, | ||||
| /* foreachTexLink */ NULL, | /* foreachTexLink */ NULL, | ||||
| }; | }; | ||||
Keep new includes ordered alphabetically.