From 3889483b1fa23911e58cff4d7d195d16e83760b0 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 15 May 2014 14:18:35 +0200 Subject: Fix T40053: Cloth simulation, rest shape key does not function It was a regression since 5d49eff. Not really sure about proper solution here, so used a bit workaround-ish way for now. Hopefully new cloth will be landed after this GSoC anyway. --- source/blender/modifiers/intern/MOD_cloth.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'source/blender/modifiers') diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c index 6bda8210f81..1561fd1a981 100644 --- a/source/blender/modifiers/intern/MOD_cloth.c +++ b/source/blender/modifiers/intern/MOD_cloth.c @@ -32,8 +32,10 @@ * \ingroup modifiers */ +#include #include "DNA_cloth_types.h" +#include "DNA_key_types.h" #include "DNA_scene_types.h" #include "DNA_object_types.h" @@ -45,6 +47,7 @@ #include "BKE_cloth.h" #include "BKE_cdderivedmesh.h" #include "BKE_global.h" +#include "BKE_key.h" #include "BKE_modifier.h" #include "BKE_pointcache.h" @@ -68,7 +71,7 @@ static void initData(ModifierData *md) } static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], - int UNUSED(numVerts), ModifierApplyFlag UNUSED(flag)) + int numVerts, ModifierApplyFlag UNUSED(flag)) { DerivedMesh *dm; ClothModifierData *clmd = (ClothModifierData *) md; @@ -85,6 +88,26 @@ static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, if (dm == derivedData) dm = CDDM_copy(dm); + /* TODO(sergey): For now it actually duplicates logic from DerivedMesh.c + * and needs some more generic solution. But starting experimenting with + * this so close to the release is not that nice.. + * + * Also hopefully new cloth system will arrive soon.. + */ + if (derivedData == NULL && clmd->sim_parms->shapekey_rest) { + KeyBlock *kb = BKE_keyblock_from_key(BKE_key_from_object(ob), + clmd->sim_parms->shapekey_rest); + if (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); + } + + memcpy(layerorco, kb->data, sizeof(float) * 3 * numVerts); + } + } + CDDM_apply_vert_coords(dm, vertexCos); DM_ensure_tessface(dm); /* BMESH - UNTIL MODIFIER IS UPDATED FOR MPoly */ -- cgit v1.2.3