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.
This commit is contained in:
Sergey Sharybin 2014-05-15 14:18:35 +02:00
parent 4725941f23
commit 3889483b1f
Notes: blender-bot 2024-03-25 12:30:38 +01:00
Referenced by issue #40223, bevel_factor_mapping_start/end in python loop
Referenced by issue #40053, cloth simulation, rest shape key does not function.
1 changed files with 24 additions and 1 deletions

View File

@ -32,8 +32,10 @@
* \ingroup modifiers
*/
#include <string.h>
#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 */