diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2018-05-18 18:32:22 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2018-05-22 18:11:30 +0300 |
commit | f5d911f8b0deb28d04737451adf355da80c792c3 (patch) | |
tree | 3f3c3acfce7ebea109aa7c139cbb45770637bbd2 /source/blender/modifiers | |
parent | e89fa4c85b8e249465158215ade49e3726a0e7a0 (diff) |
Modifiers: ported Cloth DerivedMesh → Mesh
The modifier is still quite slow; this could be due to caches being written
to a CoW datablock instead of the original one. More investigation is
needed.
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r-- | source/blender/modifiers/intern/MOD_cloth.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c index 268b0b22050..33d608aa868 100644 --- a/source/blender/modifiers/intern/MOD_cloth.c +++ b/source/blender/modifiers/intern/MOD_cloth.c @@ -36,6 +36,7 @@ #include "DNA_cloth_types.h" #include "DNA_key_types.h" +#include "DNA_mesh_types.h" #include "DNA_scene_types.h" #include "DNA_object_types.h" @@ -44,11 +45,12 @@ #include "BLI_utildefines.h" #include "BKE_cloth.h" -#include "BKE_cdderivedmesh.h" #include "BKE_effect.h" #include "BKE_global.h" #include "BKE_key.h" +#include "BKE_library.h" #include "BKE_library_query.h" +#include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_pointcache.h" @@ -71,10 +73,10 @@ static void initData(ModifierData *md) static void deformVerts( ModifierData *md, const ModifierEvalContext *ctx, - DerivedMesh *derivedData, float (*vertexCos)[3], + Mesh *mesh, float (*vertexCos)[3], int numVerts) { - DerivedMesh *dm; + Mesh *mesh_src; ClothModifierData *clmd = (ClothModifierData *) md; /* check for alloc failing */ @@ -85,9 +87,20 @@ static void deformVerts( return; } - dm = get_dm(ctx->object, NULL, derivedData, NULL, false, false); - if (dm == derivedData) - dm = CDDM_copy(dm); + if (mesh == NULL) { + mesh_src = get_mesh(ctx->object, NULL, NULL, NULL, false, false); + } + else { + /* Not possible to use get_mesh() in this case as we'll modify its vertices + * and get_mesh() would return 'mesh' directly. */ + BKE_id_copy_ex( + NULL, (ID *)mesh, (ID **)&mesh_src, + LIB_ID_CREATE_NO_MAIN | + LIB_ID_CREATE_NO_USER_REFCOUNT | + LIB_ID_CREATE_NO_DEG_TAG | + LIB_ID_COPY_NO_PREVIEW, + false); + } /* TODO(sergey): For now it actually duplicates logic from DerivedMesh.c * and needs some more generic solution. But starting experimenting with @@ -95,25 +108,24 @@ static void deformVerts( * * Also hopefully new cloth system will arrive soon.. */ - if (derivedData == NULL && clmd->sim_parms->shapekey_rest) { + if (mesh == NULL && clmd->sim_parms->shapekey_rest) { KeyBlock *kb = BKE_keyblock_from_key(BKE_key_from_object(ctx->object), clmd->sim_parms->shapekey_rest); if (kb && kb->data != NULL) { float (*layerorco)[3]; - if (!(layerorco = DM_get_vert_data_layer(dm, CD_CLOTH_ORCO))) { - DM_add_vert_layer(dm, CD_CLOTH_ORCO, CD_CALLOC, NULL); - layerorco = DM_get_vert_data_layer(dm, CD_CLOTH_ORCO); + if (!(layerorco = CustomData_get_layer(&mesh_src->vdata, CD_CLOTH_ORCO))) { + layerorco = CustomData_add_layer(&mesh_src->vdata, CD_CLOTH_ORCO, CD_CALLOC, NULL, mesh_src->totvert); } memcpy(layerorco, kb->data, sizeof(float) * 3 * numVerts); } } - CDDM_apply_vert_coords(dm, vertexCos); + BKE_mesh_apply_vert_coords(mesh_src, vertexCos); - clothModifier_do(clmd, ctx->depsgraph, md->scene, ctx->object, dm, vertexCos); + clothModifier_do(clmd, ctx->depsgraph, md->scene, ctx->object, mesh_src, vertexCos); - dm->release(dm); + BKE_id_free(NULL, mesh_src); } static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx) @@ -229,14 +241,14 @@ ModifierTypeInfo modifierType_Cloth = { /* copyData */ copyData, - /* deformVerts_DM */ deformVerts, + /* deformVerts_DM */ NULL, /* deformMatrices_DM */ NULL, /* deformVertsEM_DM */ NULL, /* deformMatricesEM_DM*/NULL, /* applyModifier_DM */ NULL, /* applyModifierEM_DM */NULL, - /* deformVerts */ NULL, + /* deformVerts */ deformVerts, /* deformMatrices */ NULL, /* deformVertsEM */ NULL, /* deformMatricesEM */ NULL, |