Modifier stack: Port Warp to new Mesh-based system.

This commit is contained in:
Bastien Montagne 2018-05-08 18:41:43 +02:00
parent 8f7e4b314b
commit f7727b5366
1 changed files with 29 additions and 34 deletions

View File

@ -29,14 +29,17 @@
#include "MEM_guardedalloc.h"
#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_editmesh.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_deform.h"
#include "BKE_texture.h"
@ -146,7 +149,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
}
static void warpModifier_do(WarpModifierData *wmd, Object *ob,
DerivedMesh *dm, float (*vertexCos)[3], int numVerts)
Mesh *mesh, float (*vertexCos)[3], int numVerts)
{
float obinv[4][4];
float mat_from[4][4];
@ -169,7 +172,7 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob,
if (!(wmd->object_from && wmd->object_to))
return;
modifier_get_vgroup(ob, dm, wmd->defgrp_name, &dvert, &defgrp_index);
modifier_get_vgroup_mesh(ob, mesh, wmd->defgrp_name, &dvert, &defgrp_index);
if (dvert == NULL) {
defgrp_index = -1;
}
@ -207,7 +210,7 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob,
if (wmd->texture) {
tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co), "warpModifier_do tex_co");
get_texture_coords((MappingInfoModifierData *)wmd, ob, dm, vertexCos, tex_co, numVerts);
get_texture_coords_mesh((MappingInfoModifierData *)wmd, ob, mesh, vertexCos, tex_co);
modifier_init_texture(wmd->modifier.scene, wmd->texture);
}
@ -295,48 +298,40 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob,
}
}
if (tex_co)
if (tex_co) {
MEM_freeN(tex_co);
}
}
static int warp_needs_dm(WarpModifierData *wmd)
{
return wmd->texture || wmd->defgrp_name[0];
}
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)
{
DerivedMesh *dm = NULL;
int use_dm = warp_needs_dm((WarpModifierData *)md);
Mesh *mesh_src = mesh;
if (use_dm) {
dm = get_cddm(ctx->object, NULL, derivedData, vertexCos, false);
if (mesh_src == NULL) {
mesh_src = ctx->object->data;
}
warpModifier_do((WarpModifierData *)md, ctx->object, dm, vertexCos, numVerts);
BLI_assert(mesh_src->totvert == numVerts);
if (use_dm) {
if (dm != derivedData) dm->release(dm);
}
warpModifier_do((WarpModifierData *)md, ctx->object, mesh_src, vertexCos, numVerts);
}
static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *em,
DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
Mesh *mesh, float (*vertexCos)[3], int numVerts)
{
DerivedMesh *dm = derivedData;
int use_dm = warp_needs_dm((WarpModifierData *)md);
Mesh *mesh_src = mesh;
if (use_dm) {
if (!derivedData)
dm = CDDM_from_editbmesh(em, false, false);
if (mesh_src == NULL) {
mesh_src = BKE_bmesh_to_mesh_nomain(em->bm, &(struct BMeshToMeshParams){0});
}
deformVerts(md, ctx, dm, vertexCos, numVerts);
BLI_assert(mesh_src->totvert == numVerts);
if (use_dm) {
if (!derivedData) dm->release(dm);
warpModifier_do((WarpModifierData *)md, ctx->object, mesh_src, vertexCos, numVerts);
if (!mesh) {
BKE_id_free(NULL, mesh_src);
}
}
@ -351,16 +346,16 @@ ModifierTypeInfo modifierType_Warp = {
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
/* deformVerts_DM */ deformVerts,
/* deformVerts_DM */ NULL,
/* deformMatrices_DM */ NULL,
/* deformVertsEM_DM */ deformVertsEM,
/* deformVertsEM_DM */ NULL,
/* deformMatricesEM_DM*/NULL,
/* applyModifier_DM */ NULL,
/* applyModifierEM_DM */NULL,
/* deformVerts */ NULL,
/* deformVerts */ deformVerts,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformVertsEM */ deformVertsEM,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,