Changeset View
Changeset View
Standalone View
Standalone View
source/blender/modifiers/intern/MOD_correctivesmooth.c
| Show All 39 Lines | |||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "MOD_modifiertypes.h" | #include "MOD_modifiertypes.h" | ||||
| #include "MOD_util.h" | #include "MOD_util.h" | ||||
| #include "BLI_strict_flags.h" | #include "BLI_strict_flags.h" | ||||
| #include "DEG_depsgraph_query.h" | |||||
| // #define DEBUG_TIME | // #define DEBUG_TIME | ||||
| #include "PIL_time.h" | #include "PIL_time.h" | ||||
| #ifdef DEBUG_TIME | #ifdef DEBUG_TIME | ||||
| # include "PIL_time_utildefines.h" | # include "PIL_time_utildefines.h" | ||||
| #endif | #endif | ||||
| /* minor optimization, calculate this inline */ | /* minor optimization, calculate this inline */ | ||||
| ▲ Show 20 Lines • Show All 497 Lines • ▼ Show 20 Lines | #endif | ||||
| } | } | ||||
| MEM_freeN(tangent_spaces); | MEM_freeN(tangent_spaces); | ||||
| MEM_freeN(smooth_vertex_coords); | MEM_freeN(smooth_vertex_coords); | ||||
| } | } | ||||
| static void correctivesmooth_modifier_do( | static void correctivesmooth_modifier_do( | ||||
| ModifierData *md, Object *ob, Mesh *mesh, | ModifierData *md, Depsgraph *depsgraph, Object *ob, Mesh *mesh, | ||||
| float (*vertexCos)[3], unsigned int numVerts, | float (*vertexCos)[3], unsigned int numVerts, | ||||
| struct BMEditMesh *em) | struct BMEditMesh *em) | ||||
| { | { | ||||
| CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md; | CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md; | ||||
| const bool force_delta_cache_update = | const bool force_delta_cache_update = | ||||
| /* XXX, take care! if mesh data its self changes we need to forcefully recalculate deltas */ | /* XXX, take care! if mesh data its self changes we need to forcefully recalculate deltas */ | ||||
| ((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_ORCO) && | ((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_ORCO) && | ||||
| (((ID *)ob->data)->recalc & ID_RECALC_ALL)); | (((ID *)ob->data)->recalc & ID_RECALC_ALL)); | ||||
| bool use_only_smooth = (csmd->flag & MOD_CORRECTIVESMOOTH_ONLY_SMOOTH) != 0; | bool use_only_smooth = (csmd->flag & MOD_CORRECTIVESMOOTH_ONLY_SMOOTH) != 0; | ||||
| MDeformVert *dvert = NULL; | MDeformVert *dvert = NULL; | ||||
| int defgrp_index; | int defgrp_index; | ||||
| MOD_get_vgroup(ob, mesh, csmd->defgrp_name, &dvert, &defgrp_index); | MOD_get_vgroup(ob, mesh, csmd->defgrp_name, &dvert, &defgrp_index); | ||||
| /* if rest bind_coords not are defined, set them (only run during bind) */ | /* if rest bind_coords not are defined, set them (only run during bind) */ | ||||
| if ((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) && | if ((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) && | ||||
| /* signal to recalculate, whoever sets MUST also free bind coords */ | /* signal to recalculate, whoever sets MUST also free bind coords */ | ||||
| (csmd->bind_coords_num == (unsigned int)-1)) | (csmd->bind_coords_num == (unsigned int)-1)) | ||||
| { | { | ||||
| BLI_assert(csmd->bind_coords == NULL); | BLI_assert(csmd->bind_coords == NULL); | ||||
| csmd->bind_coords = MEM_dupallocN(vertexCos); | csmd->bind_coords = MEM_dupallocN(vertexCos); | ||||
| csmd->bind_coords_num = numVerts; | csmd->bind_coords_num = numVerts; | ||||
| BLI_assert(csmd->bind_coords != NULL); | BLI_assert(csmd->bind_coords != NULL); | ||||
brecht: Move these lines 4 lines inside `if (DEG_is_active(depsgraph))` too? | |||||
sergeyAuthorUnsubmitted Done Inline ActionsProbably, just to be consistent with other modifiers. sergey: Probably, just to be consistent with other modifiers. | |||||
| /* Copy bound data to the original modifier. */ | |||||
| if (DEG_is_active(depsgraph)) { | |||||
| CorrectiveSmoothModifierData *csmd_orig = | |||||
| (CorrectiveSmoothModifierData *)modifier_get_original(&csmd->modifier); | |||||
| csmd_orig->bind_coords = MEM_dupallocN(csmd->bind_coords); | |||||
| csmd_orig->bind_coords_num = csmd->bind_coords_num; | |||||
| } | |||||
| else { | |||||
| modifier_setError(md, "Attempt to bind from inactive dependency graph"); | |||||
| } | |||||
| } | } | ||||
| if (UNLIKELY(use_only_smooth)) { | if (UNLIKELY(use_only_smooth)) { | ||||
| smooth_verts(csmd, mesh, dvert, defgrp_index, vertexCos, numVerts); | smooth_verts(csmd, mesh, dvert, defgrp_index, vertexCos, numVerts); | ||||
| return; | return; | ||||
| } | } | ||||
| if ((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) && (csmd->bind_coords == NULL)) { | if ((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) && (csmd->bind_coords == NULL)) { | ||||
| ▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | |||||
| static void deformVerts( | static void deformVerts( | ||||
| ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, | ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, | ||||
| float (*vertexCos)[3], int numVerts) | float (*vertexCos)[3], int numVerts) | ||||
| { | { | ||||
| Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false); | Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false); | ||||
| correctivesmooth_modifier_do(md, ctx->object, mesh_src, vertexCos, (unsigned int)numVerts, NULL); | correctivesmooth_modifier_do(md, ctx->depsgraph, ctx->object, mesh_src, vertexCos, (unsigned int)numVerts, NULL); | ||||
| if (mesh_src != mesh) { | if (mesh_src != mesh) { | ||||
| BKE_id_free(NULL, mesh_src); | 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, | ||||
| Mesh *mesh, float (*vertexCos)[3], int numVerts) | Mesh *mesh, float (*vertexCos)[3], int numVerts) | ||||
| { | { | ||||
| Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, numVerts, false, false); | Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, numVerts, false, false); | ||||
| correctivesmooth_modifier_do(md, ctx->object, mesh_src, vertexCos, (unsigned int)numVerts, editData); | correctivesmooth_modifier_do(md, ctx->depsgraph, ctx->object, mesh_src, vertexCos, (unsigned int)numVerts, editData); | ||||
| if (mesh_src != mesh) { | if (mesh_src != mesh) { | ||||
| BKE_id_free(NULL, mesh_src); | BKE_id_free(NULL, mesh_src); | ||||
| } | } | ||||
| } | } | ||||
| ModifierTypeInfo modifierType_CorrectiveSmooth = { | ModifierTypeInfo modifierType_CorrectiveSmooth = { | ||||
| Show All 27 Lines | |||||
Move these lines 4 lines inside if (DEG_is_active(depsgraph)) too?