Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/modifiers/intern/MOD_warp.c')
-rw-r--r--source/blender/modifiers/intern/MOD_warp.c538
1 files changed, 272 insertions, 266 deletions
diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c
index 30bd391ef84..67b91cfd963 100644
--- a/source/blender/modifiers/intern/MOD_warp.c
+++ b/source/blender/modifiers/intern/MOD_warp.c
@@ -46,332 +46,338 @@
#include "MOD_util.h"
-
static void initData(ModifierData *md)
{
- WarpModifierData *wmd = (WarpModifierData *) md;
-
- wmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
- wmd->texture = NULL;
- wmd->strength = 1.0f;
- wmd->falloff_radius = 1.0f;
- wmd->falloff_type = eWarp_Falloff_Smooth;
- wmd->flag = 0;
+ WarpModifierData *wmd = (WarpModifierData *)md;
+
+ wmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
+ wmd->texture = NULL;
+ wmd->strength = 1.0f;
+ wmd->falloff_radius = 1.0f;
+ wmd->falloff_type = eWarp_Falloff_Smooth;
+ wmd->flag = 0;
}
static void copyData(const ModifierData *md, ModifierData *target, const int flag)
{
- const WarpModifierData *wmd = (const WarpModifierData *) md;
- WarpModifierData *twmd = (WarpModifierData *) target;
+ const WarpModifierData *wmd = (const WarpModifierData *)md;
+ WarpModifierData *twmd = (WarpModifierData *)target;
- modifier_copyData_generic(md, target, flag);
+ modifier_copyData_generic(md, target, flag);
- twmd->curfalloff = curvemapping_copy(wmd->curfalloff);
+ twmd->curfalloff = curvemapping_copy(wmd->curfalloff);
}
-static void requiredDataMask(Object *UNUSED(ob), ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
+static void requiredDataMask(Object *UNUSED(ob),
+ ModifierData *md,
+ CustomData_MeshMasks *r_cddata_masks)
{
- WarpModifierData *wmd = (WarpModifierData *)md;
+ WarpModifierData *wmd = (WarpModifierData *)md;
- /* ask for vertexgroups if we need them */
- if (wmd->defgrp_name[0] != '\0') {
- r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
- }
+ /* ask for vertexgroups if we need them */
+ if (wmd->defgrp_name[0] != '\0') {
+ r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
+ }
- /* ask for UV coordinates if we need them */
- if (wmd->texmapping == MOD_DISP_MAP_UV) {
- r_cddata_masks->fmask |= CD_MASK_MTFACE;
- }
+ /* ask for UV coordinates if we need them */
+ if (wmd->texmapping == MOD_DISP_MAP_UV) {
+ r_cddata_masks->fmask |= CD_MASK_MTFACE;
+ }
}
static bool dependsOnTime(ModifierData *md)
{
- WarpModifierData *wmd = (WarpModifierData *)md;
-
- if (wmd->texture) {
- return BKE_texture_dependsOnTime(wmd->texture);
- }
- else {
- return false;
- }
+ WarpModifierData *wmd = (WarpModifierData *)md;
+
+ if (wmd->texture) {
+ return BKE_texture_dependsOnTime(wmd->texture);
+ }
+ else {
+ return false;
+ }
}
static void freeData(ModifierData *md)
{
- WarpModifierData *wmd = (WarpModifierData *) md;
- curvemapping_free(wmd->curfalloff);
+ WarpModifierData *wmd = (WarpModifierData *)md;
+ curvemapping_free(wmd->curfalloff);
}
-
-static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(userRenderParams))
+static bool isDisabled(const struct Scene *UNUSED(scene),
+ ModifierData *md,
+ bool UNUSED(userRenderParams))
{
- WarpModifierData *wmd = (WarpModifierData *) md;
+ WarpModifierData *wmd = (WarpModifierData *)md;
- return !(wmd->object_from && wmd->object_to);
+ return !(wmd->object_from && wmd->object_to);
}
static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData)
{
- WarpModifierData *wmd = (WarpModifierData *) md;
+ WarpModifierData *wmd = (WarpModifierData *)md;
- walk(userData, ob, &wmd->object_from, IDWALK_CB_NOP);
- walk(userData, ob, &wmd->object_to, IDWALK_CB_NOP);
- walk(userData, ob, &wmd->map_object, IDWALK_CB_NOP);
+ walk(userData, ob, &wmd->object_from, IDWALK_CB_NOP);
+ walk(userData, ob, &wmd->object_to, IDWALK_CB_NOP);
+ walk(userData, ob, &wmd->map_object, IDWALK_CB_NOP);
}
static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
{
- WarpModifierData *wmd = (WarpModifierData *) md;
+ WarpModifierData *wmd = (WarpModifierData *)md;
- walk(userData, ob, (ID **)&wmd->texture, IDWALK_CB_USER);
+ walk(userData, ob, (ID **)&wmd->texture, IDWALK_CB_USER);
- foreachObjectLink(md, ob, (ObjectWalkFunc)walk, userData);
+ foreachObjectLink(md, ob, (ObjectWalkFunc)walk, userData);
}
static void foreachTexLink(ModifierData *md, Object *ob, TexWalkFunc walk, void *userData)
{
- walk(userData, ob, md, "texture");
+ walk(userData, ob, md, "texture");
}
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
- WarpModifierData *wmd = (WarpModifierData *) md;
- if (wmd->object_from != NULL && wmd->object_to != NULL) {
- DEG_add_modifier_to_transform_relation(ctx->node, "Warplace Modifier");
- DEG_add_object_relation(ctx->node, wmd->object_from, DEG_OB_COMP_TRANSFORM, "Warp Modifier from");
- DEG_add_object_relation(ctx->node, wmd->object_to, DEG_OB_COMP_TRANSFORM, "Warp Modifier to");
- }
- if ((wmd->texmapping == MOD_DISP_MAP_OBJECT) && wmd->map_object != NULL) {
- DEG_add_object_relation(ctx->node, wmd->map_object, DEG_OB_COMP_TRANSFORM, "Warp Modifier map");
- }
- if (wmd->texture != NULL) {
- DEG_add_generic_id_relation(ctx->node, &wmd->texture->id, "Warp Modifier");
- }
+ WarpModifierData *wmd = (WarpModifierData *)md;
+ if (wmd->object_from != NULL && wmd->object_to != NULL) {
+ DEG_add_modifier_to_transform_relation(ctx->node, "Warplace Modifier");
+ DEG_add_object_relation(
+ ctx->node, wmd->object_from, DEG_OB_COMP_TRANSFORM, "Warp Modifier from");
+ DEG_add_object_relation(ctx->node, wmd->object_to, DEG_OB_COMP_TRANSFORM, "Warp Modifier to");
+ }
+ if ((wmd->texmapping == MOD_DISP_MAP_OBJECT) && wmd->map_object != NULL) {
+ DEG_add_object_relation(
+ ctx->node, wmd->map_object, DEG_OB_COMP_TRANSFORM, "Warp Modifier map");
+ }
+ if (wmd->texture != NULL) {
+ DEG_add_generic_id_relation(ctx->node, &wmd->texture->id, "Warp Modifier");
+ }
}
-static void warpModifier_do(
- WarpModifierData *wmd, const ModifierEvalContext *ctx,
- Mesh *mesh, float (*vertexCos)[3], int numVerts)
+static void warpModifier_do(WarpModifierData *wmd,
+ const ModifierEvalContext *ctx,
+ Mesh *mesh,
+ float (*vertexCos)[3],
+ int numVerts)
{
- Object *ob = ctx->object;
- float obinv[4][4];
- float mat_from[4][4];
- float mat_from_inv[4][4];
- float mat_to[4][4];
- float mat_unit[4][4];
- float mat_final[4][4];
-
- float tmat[4][4];
-
- const float falloff_radius_sq = SQUARE(wmd->falloff_radius);
- float strength = wmd->strength;
- float fac = 1.0f, weight;
- int i;
- int defgrp_index;
- MDeformVert *dvert, *dv = NULL;
-
- float (*tex_co)[3] = NULL;
-
- if (!(wmd->object_from && wmd->object_to))
- return;
-
- MOD_get_vgroup(ob, mesh, wmd->defgrp_name, &dvert, &defgrp_index);
- if (dvert == NULL) {
- defgrp_index = -1;
- }
-
- if (wmd->curfalloff == NULL) /* should never happen, but bad lib linking could cause it */
- wmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
-
- if (wmd->curfalloff) {
- curvemapping_initialize(wmd->curfalloff);
- }
-
- invert_m4_m4(obinv, ob->obmat);
-
- mul_m4_m4m4(mat_from, obinv, wmd->object_from->obmat);
- mul_m4_m4m4(mat_to, obinv, wmd->object_to->obmat);
-
- invert_m4_m4(tmat, mat_from); // swap?
- mul_m4_m4m4(mat_final, tmat, mat_to);
-
- invert_m4_m4(mat_from_inv, mat_from);
-
- unit_m4(mat_unit);
-
- if (strength < 0.0f) {
- float loc[3];
- strength = -strength;
-
- /* inverted location is not useful, just use the negative */
- copy_v3_v3(loc, mat_final[3]);
- invert_m4(mat_final);
- negate_v3_v3(mat_final[3], loc);
-
- }
- weight = strength;
-
- Tex *tex_target = wmd->texture;
- if (mesh != NULL && tex_target != NULL) {
- tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co), "warpModifier_do tex_co");
- MOD_get_texture_coords((MappingInfoModifierData *)wmd, ctx, ob, mesh, vertexCos, tex_co);
-
- MOD_init_texture((MappingInfoModifierData *)wmd, ctx);
- }
-
- for (i = 0; i < numVerts; i++) {
- float *co = vertexCos[i];
-
- if (wmd->falloff_type == eWarp_Falloff_None ||
- ((fac = len_squared_v3v3(co, mat_from[3])) < falloff_radius_sq &&
- (fac = (wmd->falloff_radius - sqrtf(fac)) / wmd->falloff_radius)))
- {
- /* skip if no vert group found */
- if (defgrp_index != -1) {
- dv = &dvert[i];
- weight = defvert_find_weight(dv, defgrp_index) * strength;
- if (weight <= 0.0f) {
- continue;
- }
- }
-
-
- /* closely match PROP_SMOOTH and similar */
- switch (wmd->falloff_type) {
- case eWarp_Falloff_None:
- fac = 1.0f;
- break;
- case eWarp_Falloff_Curve:
- fac = curvemapping_evaluateF(wmd->curfalloff, 0, fac);
- break;
- case eWarp_Falloff_Sharp:
- fac = fac * fac;
- break;
- case eWarp_Falloff_Smooth:
- fac = 3.0f * fac * fac - 2.0f * fac * fac * fac;
- break;
- case eWarp_Falloff_Root:
- fac = sqrtf(fac);
- break;
- case eWarp_Falloff_Linear:
- /* pass */
- break;
- case eWarp_Falloff_Const:
- fac = 1.0f;
- break;
- case eWarp_Falloff_Sphere:
- fac = sqrtf(2 * fac - fac * fac);
- break;
- case eWarp_Falloff_InvSquare:
- fac = fac * (2.0f - fac);
- break;
- }
-
- fac *= weight;
-
- if (tex_co) {
- struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
- TexResult texres;
- texres.nor = NULL;
- BKE_texture_get_value(scene, tex_target, tex_co[i], &texres, false);
- fac *= texres.tin;
- }
-
- if (fac != 0.0f) {
- /* into the 'from' objects space */
- mul_m4_v3(mat_from_inv, co);
-
- if (fac == 1.0f) {
- mul_m4_v3(mat_final, co);
- }
- else {
- if (wmd->flag & MOD_WARP_VOLUME_PRESERVE) {
- /* interpolate the matrix for nicer locations */
- blend_m4_m4m4(tmat, mat_unit, mat_final, fac);
- mul_m4_v3(tmat, co);
- }
- else {
- float tvec[3];
- mul_v3_m4v3(tvec, mat_final, co);
- interp_v3_v3v3(co, co, tvec, fac);
- }
- }
-
- /* out of the 'from' objects space */
- mul_m4_v3(mat_from, co);
- }
- }
- }
-
- if (tex_co) {
- MEM_freeN(tex_co);
- }
+ Object *ob = ctx->object;
+ float obinv[4][4];
+ float mat_from[4][4];
+ float mat_from_inv[4][4];
+ float mat_to[4][4];
+ float mat_unit[4][4];
+ float mat_final[4][4];
+
+ float tmat[4][4];
+
+ const float falloff_radius_sq = SQUARE(wmd->falloff_radius);
+ float strength = wmd->strength;
+ float fac = 1.0f, weight;
+ int i;
+ int defgrp_index;
+ MDeformVert *dvert, *dv = NULL;
+
+ float(*tex_co)[3] = NULL;
+
+ if (!(wmd->object_from && wmd->object_to))
+ return;
+
+ MOD_get_vgroup(ob, mesh, wmd->defgrp_name, &dvert, &defgrp_index);
+ if (dvert == NULL) {
+ defgrp_index = -1;
+ }
+
+ if (wmd->curfalloff == NULL) /* should never happen, but bad lib linking could cause it */
+ wmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
+
+ if (wmd->curfalloff) {
+ curvemapping_initialize(wmd->curfalloff);
+ }
+
+ invert_m4_m4(obinv, ob->obmat);
+
+ mul_m4_m4m4(mat_from, obinv, wmd->object_from->obmat);
+ mul_m4_m4m4(mat_to, obinv, wmd->object_to->obmat);
+
+ invert_m4_m4(tmat, mat_from); // swap?
+ mul_m4_m4m4(mat_final, tmat, mat_to);
+
+ invert_m4_m4(mat_from_inv, mat_from);
+
+ unit_m4(mat_unit);
+
+ if (strength < 0.0f) {
+ float loc[3];
+ strength = -strength;
+
+ /* inverted location is not useful, just use the negative */
+ copy_v3_v3(loc, mat_final[3]);
+ invert_m4(mat_final);
+ negate_v3_v3(mat_final[3], loc);
+ }
+ weight = strength;
+
+ Tex *tex_target = wmd->texture;
+ if (mesh != NULL && tex_target != NULL) {
+ tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co), "warpModifier_do tex_co");
+ MOD_get_texture_coords((MappingInfoModifierData *)wmd, ctx, ob, mesh, vertexCos, tex_co);
+
+ MOD_init_texture((MappingInfoModifierData *)wmd, ctx);
+ }
+
+ for (i = 0; i < numVerts; i++) {
+ float *co = vertexCos[i];
+
+ if (wmd->falloff_type == eWarp_Falloff_None ||
+ ((fac = len_squared_v3v3(co, mat_from[3])) < falloff_radius_sq &&
+ (fac = (wmd->falloff_radius - sqrtf(fac)) / wmd->falloff_radius))) {
+ /* skip if no vert group found */
+ if (defgrp_index != -1) {
+ dv = &dvert[i];
+ weight = defvert_find_weight(dv, defgrp_index) * strength;
+ if (weight <= 0.0f) {
+ continue;
+ }
+ }
+
+ /* closely match PROP_SMOOTH and similar */
+ switch (wmd->falloff_type) {
+ case eWarp_Falloff_None:
+ fac = 1.0f;
+ break;
+ case eWarp_Falloff_Curve:
+ fac = curvemapping_evaluateF(wmd->curfalloff, 0, fac);
+ break;
+ case eWarp_Falloff_Sharp:
+ fac = fac * fac;
+ break;
+ case eWarp_Falloff_Smooth:
+ fac = 3.0f * fac * fac - 2.0f * fac * fac * fac;
+ break;
+ case eWarp_Falloff_Root:
+ fac = sqrtf(fac);
+ break;
+ case eWarp_Falloff_Linear:
+ /* pass */
+ break;
+ case eWarp_Falloff_Const:
+ fac = 1.0f;
+ break;
+ case eWarp_Falloff_Sphere:
+ fac = sqrtf(2 * fac - fac * fac);
+ break;
+ case eWarp_Falloff_InvSquare:
+ fac = fac * (2.0f - fac);
+ break;
+ }
+
+ fac *= weight;
+
+ if (tex_co) {
+ struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
+ TexResult texres;
+ texres.nor = NULL;
+ BKE_texture_get_value(scene, tex_target, tex_co[i], &texres, false);
+ fac *= texres.tin;
+ }
+
+ if (fac != 0.0f) {
+ /* into the 'from' objects space */
+ mul_m4_v3(mat_from_inv, co);
+
+ if (fac == 1.0f) {
+ mul_m4_v3(mat_final, co);
+ }
+ else {
+ if (wmd->flag & MOD_WARP_VOLUME_PRESERVE) {
+ /* interpolate the matrix for nicer locations */
+ blend_m4_m4m4(tmat, mat_unit, mat_final, fac);
+ mul_m4_v3(tmat, co);
+ }
+ else {
+ float tvec[3];
+ mul_v3_m4v3(tvec, mat_final, co);
+ interp_v3_v3v3(co, co, tvec, fac);
+ }
+ }
+
+ /* out of the 'from' objects space */
+ mul_m4_v3(mat_from, co);
+ }
+ }
+ }
+
+ if (tex_co) {
+ MEM_freeN(tex_co);
+ }
}
-static void deformVerts(
- ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh,
- float (*vertexCos)[3], int numVerts)
+static void deformVerts(ModifierData *md,
+ const ModifierEvalContext *ctx,
+ Mesh *mesh,
+ float (*vertexCos)[3],
+ int numVerts)
{
- WarpModifierData *wmd = (WarpModifierData *)md;
- Mesh *mesh_src = NULL;
+ WarpModifierData *wmd = (WarpModifierData *)md;
+ Mesh *mesh_src = NULL;
- if (wmd->defgrp_name[0] != '\0' || wmd->texture != NULL) {
- /* mesh_src is only needed for vgroups and textures. */
- mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false);
- }
+ if (wmd->defgrp_name[0] != '\0' || wmd->texture != NULL) {
+ /* mesh_src is only needed for vgroups and textures. */
+ mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false);
+ }
- warpModifier_do(wmd, ctx, mesh_src, vertexCos, numVerts);
+ warpModifier_do(wmd, ctx, mesh_src, vertexCos, numVerts);
- if (!ELEM(mesh_src, NULL, mesh)) {
- BKE_id_free(NULL, mesh_src);
- }
+ if (!ELEM(mesh_src, NULL, mesh)) {
+ BKE_id_free(NULL, mesh_src);
+ }
}
-static void deformVertsEM(
- ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *em,
- Mesh *mesh, float (*vertexCos)[3], int numVerts)
+static void deformVertsEM(ModifierData *md,
+ const ModifierEvalContext *ctx,
+ struct BMEditMesh *em,
+ Mesh *mesh,
+ float (*vertexCos)[3],
+ int numVerts)
{
- WarpModifierData *wmd = (WarpModifierData *)md;
- Mesh *mesh_src = NULL;
+ WarpModifierData *wmd = (WarpModifierData *)md;
+ Mesh *mesh_src = NULL;
- if (wmd->defgrp_name[0] != '\0' || wmd->texture != NULL) {
- /* mesh_src is only needed for vgroups and textures. */
- mesh_src = MOD_deform_mesh_eval_get(ctx->object, em, mesh, NULL, numVerts, false, false);
- }
+ if (wmd->defgrp_name[0] != '\0' || wmd->texture != NULL) {
+ /* mesh_src is only needed for vgroups and textures. */
+ mesh_src = MOD_deform_mesh_eval_get(ctx->object, em, mesh, NULL, numVerts, false, false);
+ }
- warpModifier_do(wmd, ctx, mesh_src, vertexCos, numVerts);
+ warpModifier_do(wmd, ctx, mesh_src, vertexCos, numVerts);
- if (!ELEM(mesh_src, NULL, mesh)) {
- BKE_id_free(NULL, mesh_src);
- }
+ if (!ELEM(mesh_src, NULL, mesh)) {
+ BKE_id_free(NULL, mesh_src);
+ }
}
-
ModifierTypeInfo modifierType_Warp = {
- /* name */ "Warp",
- /* structName */ "WarpModifierData",
- /* structSize */ sizeof(WarpModifierData),
- /* type */ eModifierTypeType_OnlyDeform,
- /* flags */ eModifierTypeFlag_AcceptsCVs |
- eModifierTypeFlag_AcceptsLattice |
- eModifierTypeFlag_SupportsEditmode,
- /* copyData */ copyData,
-
- /* deformVerts */ deformVerts,
- /* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
- /* deformMatricesEM */ NULL,
- /* applyModifier */ NULL,
-
- /* initData */ initData,
- /* requiredDataMask */ requiredDataMask,
- /* freeData */ freeData,
- /* isDisabled */ isDisabled,
- /* updateDepsgraph */ updateDepsgraph,
- /* dependsOnTime */ dependsOnTime,
- /* dependsOnNormals */ NULL,
- /* foreachObjectLink */ foreachObjectLink,
- /* foreachIDLink */ foreachIDLink,
- /* foreachTexLink */ foreachTexLink,
- /* freeRuntimeData */ NULL,
+ /* name */ "Warp",
+ /* structName */ "WarpModifierData",
+ /* structSize */ sizeof(WarpModifierData),
+ /* type */ eModifierTypeType_OnlyDeform,
+ /* flags */ eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_AcceptsLattice |
+ eModifierTypeFlag_SupportsEditmode,
+ /* copyData */ copyData,
+
+ /* deformVerts */ deformVerts,
+ /* deformMatrices */ NULL,
+ /* deformVertsEM */ deformVertsEM,
+ /* deformMatricesEM */ NULL,
+ /* applyModifier */ NULL,
+
+ /* initData */ initData,
+ /* requiredDataMask */ requiredDataMask,
+ /* freeData */ freeData,
+ /* isDisabled */ isDisabled,
+ /* updateDepsgraph */ updateDepsgraph,
+ /* dependsOnTime */ dependsOnTime,
+ /* dependsOnNormals */ NULL,
+ /* foreachObjectLink */ foreachObjectLink,
+ /* foreachIDLink */ foreachIDLink,
+ /* foreachTexLink */ foreachTexLink,
+ /* freeRuntimeData */ NULL,
};