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_wave.c')
-rw-r--r--source/blender/modifiers/intern/MOD_wave.c145
1 files changed, 80 insertions, 65 deletions
diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c
index 38123c5e3bb..cc3035d3d9b 100644
--- a/source/blender/modifiers/intern/MOD_wave.c
+++ b/source/blender/modifiers/intern/MOD_wave.c
@@ -35,28 +35,31 @@
#include "BLI_math.h"
+#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
-#include "DNA_scene_types.h"
#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
#include "BLI_utildefines.h"
#include "BKE_deform.h"
-#include "BKE_DerivedMesh.h"
+#include "BKE_editmesh.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
+#include "BKE_mesh.h"
#include "BKE_scene.h"
#include "BKE_texture.h"
-#include "depsgraph_private.h"
-
#include "MEM_guardedalloc.h"
#include "RE_shader_ext.h"
#include "MOD_modifiertypes.h"
#include "MOD_util.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
static void initData(ModifierData *md)
{
WaveModifierData *wmd = (WaveModifierData *) md; // whadya know, moved here from Iraq
@@ -111,25 +114,6 @@ static void foreachTexLink(
walk(userData, ob, md, "texture");
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- WaveModifierData *wmd = (WaveModifierData *) md;
-
- if (wmd->objectcenter) {
- DagNode *curNode = dag_get_node(ctx->forest, wmd->objectcenter);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_OB_DATA,
- "Wave Modifier");
- }
-
- if (wmd->map_object) {
- DagNode *curNode = dag_get_node(ctx->forest, wmd->map_object);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_OB_DATA,
- "Wave Modifer");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
WaveModifierData *wmd = (WaveModifierData *)md;
@@ -139,6 +123,12 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
if (wmd->map_object != NULL) {
DEG_add_object_relation(ctx->node, wmd->map_object, DEG_OB_COMP_TRANSFORM, "Wave Modifier");
}
+ if (wmd->objectcenter != NULL || wmd->map_object != NULL) {
+ DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Wave Modifier");
+ }
+ if (wmd->texture != NULL) {
+ DEG_add_generic_id_relation(ctx->node, &wmd->texture->id, "Wave Modifier");
+ }
}
static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
@@ -158,16 +148,24 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
return dataMask;
}
+static bool dependsOnNormals(ModifierData *md)
+{
+ WaveModifierData *wmd = (WaveModifierData *)md;
+
+ return (wmd->flag & MOD_WAVE_NORM) != 0;
+}
+
static void waveModifier_do(
WaveModifierData *md,
- Scene *scene, Object *ob, DerivedMesh *dm,
+ const ModifierEvalContext *ctx,
+ Object *ob, Mesh *mesh,
float (*vertexCos)[3], int numVerts)
{
WaveModifierData *wmd = (WaveModifierData *) md;
MVert *mvert = NULL;
MDeformVert *dvert;
int defgrp_index;
- float ctime = BKE_scene_frame_get(scene);
+ float ctime = DEG_get_ctime(ctx->depsgraph);
float minfac = (float)(1.0 / exp(wmd->width * wmd->narrow * wmd->width * wmd->narrow));
float lifefac = wmd->height;
float (*tex_co)[3] = NULL;
@@ -175,23 +173,26 @@ static void waveModifier_do(
const float falloff = wmd->falloff;
float falloff_fac = 1.0f; /* when falloff == 0.0f this stays at 1.0f */
- if ((wmd->flag & MOD_WAVE_NORM) && (ob->type == OB_MESH))
- mvert = dm->getVertArray(dm);
+ if ((wmd->flag & MOD_WAVE_NORM) && (mesh != NULL)) {
+ mvert = mesh->mvert;
+ }
- if (wmd->objectcenter) {
+ if (wmd->objectcenter != NULL) {
float mat[4][4];
/* get the control object's location in local coordinates */
invert_m4_m4(ob->imat, ob->obmat);
- mul_m4_m4m4(mat, ob->imat, wmd->objectcenter->obmat);
+ mul_m4_m4m4(mat, ob->imat, DEG_get_evaluated_object(ctx->depsgraph, wmd->objectcenter)->obmat);
wmd->startx = mat[3][0];
wmd->starty = mat[3][1];
}
/* get the index of the deform group */
- modifier_get_vgroup(ob, dm, wmd->defgrp_name, &dvert, &defgrp_index);
+ MOD_get_vgroup(ob, mesh, wmd->defgrp_name, &dvert, &defgrp_index);
- if (wmd->damp == 0) wmd->damp = 10.0f;
+ if (wmd->damp == 0.0f) {
+ wmd->damp = 10.0f;
+ }
if (wmd->lifetime != 0.0f) {
float x = ctime - wmd->timeoffs;
@@ -204,17 +205,17 @@ static void waveModifier_do(
}
}
- if (wmd->texture) {
- tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co),
- "waveModifier_do tex_co");
- get_texture_coords((MappingInfoModifierData *)wmd, ob, dm, vertexCos, tex_co, numVerts);
+ Tex *tex_target = (Tex *)DEG_get_evaluated_id(ctx->depsgraph, &wmd->texture->id);
+ if (mesh != NULL && tex_target != NULL) {
+ tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co), "waveModifier_do tex_co");
+ MOD_get_texture_coords((MappingInfoModifierData *)wmd, ctx, ob, mesh, vertexCos, tex_co);
- modifier_init_texture(wmd->modifier.scene, wmd->texture);
+ MOD_init_texture((MappingInfoModifierData *)wmd, ctx);
}
if (lifefac != 0.0f) {
/* avoid divide by zero checks within the loop */
- float falloff_inv = falloff ? 1.0f / falloff : 1.0f;
+ float falloff_inv = falloff != 0.0f ? 1.0f / falloff : 1.0f;
int i;
for (i = 0; i < numVerts; i++) {
@@ -279,10 +280,11 @@ static void waveModifier_do(
amplit = (float)(1.0f / expf(amplit * amplit) - minfac);
/*apply texture*/
- if (wmd->texture) {
+ if (tex_target) {
+ Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
TexResult texres;
texres.nor = NULL;
- BKE_texture_get_value(wmd->modifier.scene, wmd->texture, tex_co[i], &texres, false);
+ BKE_texture_get_value(scene, tex_target, tex_co[i], &texres, false);
amplit *= texres.tin;
}
@@ -309,46 +311,52 @@ static void waveModifier_do(
}
}
- if (wmd->texture) MEM_freeN(tex_co);
+ MEM_SAFE_FREE(tex_co);
}
static void deformVerts(
- ModifierData *md, Object *ob,
- DerivedMesh *derivedData,
+ ModifierData *md, const ModifierEvalContext *ctx,
+ Mesh *mesh,
float (*vertexCos)[3],
- int numVerts,
- ModifierApplyFlag UNUSED(flag))
+ int numVerts)
{
- DerivedMesh *dm = derivedData;
WaveModifierData *wmd = (WaveModifierData *)md;
+ Mesh *mesh_src = NULL;
- if (wmd->flag & MOD_WAVE_NORM)
- dm = get_cddm(ob, NULL, dm, vertexCos, false);
- else if (wmd->texture || wmd->defgrp_name[0])
- dm = get_dm(ob, NULL, dm, NULL, false, false);
+ if (wmd->flag & MOD_WAVE_NORM) {
+ mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, vertexCos, numVerts, true, false);
+ }
+ else if (wmd->texture != NULL || wmd->defgrp_name[0] != '\0') {
+ mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false);
+ }
- waveModifier_do(wmd, md->scene, ob, dm, vertexCos, numVerts);
+ waveModifier_do(wmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
- if (dm != derivedData)
- dm->release(dm);
+ if (!ELEM(mesh_src, NULL, mesh)) {
+ BKE_id_free(NULL, mesh_src);
+ }
}
static void deformVertsEM(
- ModifierData *md, Object *ob, struct BMEditMesh *editData,
- DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
+ ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *editData,
+ Mesh *mesh, float (*vertexCos)[3], int numVerts)
{
- DerivedMesh *dm = derivedData;
WaveModifierData *wmd = (WaveModifierData *)md;
+ Mesh *mesh_src = NULL;
- if (wmd->flag & MOD_WAVE_NORM)
- dm = get_cddm(ob, editData, dm, vertexCos, false);
- else if (wmd->texture || wmd->defgrp_name[0])
- dm = get_dm(ob, editData, dm, NULL, false, false);
+ if (wmd->flag & MOD_WAVE_NORM) {
+ mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, vertexCos, numVerts, true, false);
+ }
+ else if (wmd->texture != NULL || wmd->defgrp_name[0] != '\0') {
+ mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, numVerts, false, false);
+ }
- waveModifier_do(wmd, md->scene, ob, dm, vertexCos, numVerts);
+ waveModifier_do(wmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
- if (dm != derivedData)
- dm->release(dm);
+ if (!ELEM(mesh_src, NULL, mesh)) {
+ BKE_id_free(NULL, mesh_src);
+ }
}
@@ -360,21 +368,28 @@ ModifierTypeInfo modifierType_Wave = {
/* flags */ eModifierTypeFlag_AcceptsCVs |
eModifierTypeFlag_AcceptsLattice |
eModifierTypeFlag_SupportsEditmode,
+
/* copyData */ modifier_copyData_generic,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+
/* deformVerts */ deformVerts,
/* deformMatrices */ NULL,
/* deformVertsEM */ deformVertsEM,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
- /* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
- /* dependsOnNormals */ NULL,
+ /* dependsOnNormals */ dependsOnNormals,
/* foreachObjectLink */ foreachObjectLink,
/* foreachIDLink */ foreachIDLink,
/* foreachTexLink */ foreachTexLink,