diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-01-26 23:20:33 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-01-26 23:20:33 +0400 |
commit | de4eeb96946943289ac898525f09fc9c7afd4157 (patch) | |
tree | 5887eac0f56db6ce226a25ae34eaaa1169c7ee3a /source/blender/blenkernel/intern/cloth.c | |
parent | ce90b472afbe4f90af60e19a0a6cc6704d3a3549 (diff) | |
parent | 4514a4455be89bc0a789d78355321abe6cfd5112 (diff) |
svn merge ^/trunk/blender -r43693:43733
Diffstat (limited to 'source/blender/blenkernel/intern/cloth.c')
-rw-r--r-- | source/blender/blenkernel/intern/cloth.c | 52 |
1 files changed, 19 insertions, 33 deletions
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 44df3edb3e5..ca0898a7085 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -91,7 +91,7 @@ static CM_SOLVER_DEF solvers [] = /* ********** cloth engine ******* */ /* Prototypes for internal functions. */ -static void cloth_to_object (Object *ob, ClothModifierData *clmd, DerivedMesh *dm); +static void cloth_to_object (Object *ob, ClothModifierData *clmd, float (*vertexCos)[3]); static void cloth_from_mesh ( ClothModifierData *clmd, DerivedMesh *dm ); static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float framenr, int first); static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ); @@ -430,9 +430,8 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul /************************************************ * clothModifier_do - main simulation function ************************************************/ -DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, DerivedMesh *dm) +void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, DerivedMesh *dm, float (*vertexCos)[3]) { - DerivedMesh *result; PointCache *cache; PTCacheID pid; float timescale; @@ -442,20 +441,14 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, clmd->scene= scene; /* nice to pass on later :) */ framenr= (int)scene->r.cfra; cache= clmd->point_cache; - result = CDDM_copy(dm, 0); BKE_ptcache_id_from_cloth(&pid, ob, clmd); BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, ×cale); clmd->sim_parms->timescale= timescale; - if(!result) { - BKE_ptcache_invalidate(cache); - return dm; - } - if(clmd->sim_parms->reset || (framenr == (startframe - clmd->sim_parms->preroll) && clmd->sim_parms->preroll != 0) - || (clmd->clothObject && result->getNumVerts(result) != clmd->clothObject->numverts)) + || (clmd->clothObject && dm->getNumVerts(dm) != clmd->clothObject->numverts)) { clmd->sim_parms->reset = 0; cache->flag |= PTCACHE_OUTDATED; @@ -463,7 +456,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, BKE_ptcache_validate(cache, 0); cache->last_exact= 0; cache->flag &= ~PTCACHE_REDO_NEEDED; - return result; + return; } // unused in the moment, calculated separately in implicit.c @@ -475,20 +468,20 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, /* do simulation */ if(!do_init_cloth(ob, clmd, dm, framenr)) - return result; + return; do_step_cloth(ob, clmd, dm, framenr); - cloth_to_object(ob, clmd, result); + cloth_to_object(ob, clmd, vertexCos); clmd->clothObject->last_frame= framenr; - return result; + return; } /* simulation is only active during a specific period */ if(framenr < startframe) { BKE_ptcache_invalidate(cache); - return result; + return; } else if(framenr > endframe) { framenr= endframe; @@ -496,7 +489,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, /* initialize simulation data if it didn't exist already */ if(!do_init_cloth(ob, clmd, dm, framenr)) - return result; + return; if((framenr == startframe) && (clmd->sim_parms->preroll == 0)) { BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED); @@ -504,7 +497,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, BKE_ptcache_validate(cache, framenr); cache->flag &= ~PTCACHE_REDO_NEEDED; clmd->clothObject->last_frame= framenr; - return result; + return; } /* try to read from cache */ @@ -512,7 +505,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, if(cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) { implicit_set_positions(clmd); - cloth_to_object (ob, clmd, result); + cloth_to_object (ob, clmd, vertexCos); BKE_ptcache_validate(cache, framenr); @@ -521,7 +514,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, clmd->clothObject->last_frame= framenr; - return result; + return; } else if(cache_result==PTCACHE_READ_OLD) { implicit_set_positions(clmd); @@ -529,11 +522,11 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, else if( /*ob->id.lib ||*/ (cache->flag & PTCACHE_BAKED)) { /* 2.4x disabled lib, but this can be used in some cases, testing further - campbell */ /* if baked and nothing in cache, do nothing */ BKE_ptcache_invalidate(cache); - return result; + return; } if(framenr!=clmd->clothObject->last_frame+1) - return result; + return; /* if on second frame, write cache for first frame */ if(cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0)) @@ -550,10 +543,8 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, else BKE_ptcache_write(&pid, framenr); - cloth_to_object (ob, clmd, result); + cloth_to_object (ob, clmd, vertexCos); clmd->clothObject->last_frame= framenr; - - return result; } /* frees all */ @@ -708,24 +699,19 @@ void cloth_free_modifier_extern ( ClothModifierData *clmd ) * cloth_to_object - copies the deformed vertices to the object. * **/ -static void cloth_to_object (Object *ob, ClothModifierData *clmd, DerivedMesh *dm) +static void cloth_to_object (Object *ob, ClothModifierData *clmd, float (*vertexCos)[3]) { unsigned int i = 0; - MVert *mvert = NULL; - unsigned int numverts; Cloth *cloth = clmd->clothObject; if (clmd->clothObject) { /* inverse matrix is not uptodate... */ invert_m4_m4(ob->imat, ob->obmat); - mvert = CDDM_get_verts(dm); - numverts = dm->getNumVerts(dm); - - for (i = 0; i < numverts; i++) + for (i = 0; i < cloth->numverts; i++) { - copy_v3_v3 (mvert[i].co, cloth->verts[i].x); - mul_m4_v3(ob->imat, mvert[i].co); /* cloth is in global coords */ + copy_v3_v3 (vertexCos[i], cloth->verts[i].x); + mul_m4_v3(ob->imat, vertexCos[i]); /* cloth is in global coords */ } } } |