[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13381] branches/cloth/blender/source/ blender: New: Editable cache.
Daniel Genrich
daniel.genrich at gmx.net
Thu Jan 24 11:43:14 CET 2008
Revision: 13381
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13381
Author: genscher
Date: 2008-01-24 11:43:12 +0100 (Thu, 24 Jan 2008)
Log Message:
-----------
New: Editable cache. Fixed: Don't clear cache on e.g. lamp moving. Changed: Switched to another modifier type to be more flexible (allows tearing later)
Modified Paths:
--------------
branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
branches/cloth/blender/source/blender/blenkernel/intern/implicit.c
branches/cloth/blender/source/blender/blenkernel/intern/modifier.c
branches/cloth/blender/source/blender/src/buttons_object.c
branches/cloth/blender/source/blender/src/editmesh.c
branches/cloth/blender/source/blender/src/transform_conversions.c
branches/cloth/blender/source/blender/src/vpaint.c
Modified: branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h 2008-01-24 07:25:02 UTC (rev 13380)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h 2008-01-24 10:43:12 UTC (rev 13381)
@@ -160,16 +160,6 @@
#define CLOTH_VERT_FLAG_PINNED 1
#define CLOTH_VERT_FLAG_COLLISION 2
-
-// needed for buttons_object.c
-void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr);
-
-// needed for cloth.c
-void implicit_set_positions ( ClothModifierData *clmd );
-
-// from cloth.c, needed for modifier.c
-void clothModifier_do ( ClothModifierData *clmd, Object *ob, DerivedMesh *dm, float ( *vertexCos ) [3], int numverts );
-
typedef void ( *CM_COLLISION_RESPONSE ) ( ClothModifierData *clmd, CollisionModifierData *collmd, CollisionTree *tree1, CollisionTree *tree2 );
@@ -193,6 +183,7 @@
int implicit_init ( Object *ob, ClothModifierData *clmd );
int implicit_free ( ClothModifierData *clmd );
int implicit_solver ( Object *ob, float frame, ClothModifierData *clmd, ListBase *effectors );
+void implicit_set_positions ( ClothModifierData *clmd );
////////////////////////////////////////////////
@@ -204,13 +195,16 @@
void cloth_free_modifier_extern (ClothModifierData *clmd);
void cloth_free_modifier (Object *ob, ClothModifierData *clmd);
void cloth_init (ClothModifierData *clmd);
-void cloth_deform_verts (struct Object *ob, float framenr, float ( *vertexCos ) [3], int numVerts, void *derivedData, ClothModifierData *clmd);
+DerivedMesh *clothModifier_do(ClothModifierData *clmd,Object *ob, DerivedMesh *dm, int useRenderParams, int isFinalCalc);
void cloth_update_normals (ClothVertex *verts, int nVerts, MFace *face, int totface);
// needed for collision.c
void bvh_update_from_cloth(ClothModifierData *clmd, int moving);
+// needed for editmesh.c
+void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr);
+
////////////////////////////////////////////////
Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2008-01-24 07:25:02 UTC (rev 13380)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2008-01-24 10:43:12 UTC (rev 13381)
@@ -121,9 +121,9 @@
/* ********** cloth engine ******* */
/* Prototypes for internal functions.
*/
-static void cloth_to_object ( Object *ob, ClothModifierData *clmd, float ( *vertexCos ) [3], unsigned int numverts );
+static void cloth_to_object (Object *ob, ClothModifierData *clmd, DerivedMesh *dm);
static void cloth_from_mesh ( Object *ob, ClothModifierData *clmd, DerivedMesh *dm );
-static int cloth_from_object ( Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float ( *vertexCos ) [3], unsigned int numverts, float framenr );
+static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float framenr);
int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm );
static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm, short vgroup );
@@ -545,7 +545,7 @@
cloth_read_cache(ob, clmd, framenr);
}
}
-static void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr)
+void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr)
{
FILE *fp = NULL;
int stack_index = -1;
@@ -579,26 +579,46 @@
-/**
-* cloth_deform_verts - simulates one step, framenr is in frames.
-*
-**/
-void clothModifier_do ( ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
- float ( *vertexCos ) [3], int numverts )
+/************************************************
+ * clothModifier_do - main simulation function
+************************************************/
+DerivedMesh *clothModifier_do(ClothModifierData *clmd,Object *ob, DerivedMesh *dm, int useRenderParams, int isFinalCalc)
+
{
unsigned int i;
Cloth *cloth = clmd->clothObject;
unsigned int framenr = ( float ) G.scene->r.cfra;
float current_time = bsystem_time ( ob, ( float ) G.scene->r.cfra, 0.0 );
- ListBase *effectors = NULL;
+ ListBase *effectors = NULL;
ClothVertex *verts = NULL;
float deltaTime = current_time - clmd->sim_parms->sim_time;
+ unsigned int numverts = -1;
+ unsigned int numedges = -1;
+ unsigned int numfaces = -1;
+ MVert *mvert = NULL;
+ MEdge *medge = NULL;
+ MFace *mface = NULL;
+ DerivedMesh *result = NULL;
+ result = CDDM_copy(dm);
+
+ if(!result)
+ {
+ return dm;
+ }
+
+ numverts = result->getNumVerts(result);
+ numedges = result->getNumEdges(result);
+ numfaces = result->getNumFaces(result);
+ mvert = CDDM_get_verts(result);
+ medge = CDDM_get_edges(result);
+ mface = CDDM_get_faces(result);
+
// only be active during a specific period:
// that's "first frame" and "last frame" on GUI
if ( current_time < clmd->sim_parms->firstframe )
{
- return;
+ return result;
}
else if ( current_time > clmd->sim_parms->lastframe )
{
@@ -609,10 +629,10 @@
if(cloth_read_cache(ob, clmd, framenr))
{
// Copy the result back to the object.
- cloth_to_object ( ob, clmd, vertexCos, numverts );
+ cloth_to_object (ob, clmd, result);
}
}
- return;
+ return result;
}
// printf("ct: %f, st: %f, r.cfra: %f, dt: %f\n", current_time, clmd->sim_parms->sim_time, ( float ) G.scene->r.cfra, deltaTime);
@@ -639,11 +659,11 @@
{
cloth_clear_cache(ob, clmd, 0);
- if ( !cloth_from_object ( ob, clmd, dm, vertexCos, numverts, framenr ) )
- return;
+ if ( !cloth_from_object ( ob, clmd, result, framenr ) )
+ return result;
if ( clmd->clothObject == NULL )
- return;
+ return result;
cloth = clmd->clothObject;
}
@@ -665,7 +685,7 @@
VECCOPY ( verts->txold, verts->x );
// Get the current position.
- VECCOPY ( verts->xconst, vertexCos[i] );
+ VECCOPY ( verts->xconst, mvert[i].co );
Mat4MulVecfl ( ob->obmat, verts->xconst );
}
@@ -679,14 +699,10 @@
// printf ( "Cloth simulation time: %f\n", ( float ) tval() );
cloth_write_cache(ob, clmd, framenr);
-
}
// Copy the result back to the object.
- cloth_to_object ( ob, clmd, vertexCos, numverts );
-
- // bvh_free(clmd->clothObject->tree);
- // clmd->clothObject->tree = bvh_build(clmd, clmd->coll_parms->epsilon);
+ cloth_to_object (ob, clmd, result);
}
}
@@ -696,7 +712,7 @@
{
if(cloth_read_cache(ob, clmd, framenr))
{
- cloth_to_object ( ob, clmd, vertexCos, numverts );
+ cloth_to_object (ob, clmd, result);
}
}
else
@@ -704,6 +720,8 @@
cloth_clear_cache(ob, clmd, 0);
}
}
+
+ return result;
}
@@ -783,59 +801,55 @@
return;
cloth = clmd->clothObject;
+
+ if ( cloth )
+ {
+ // If our solver provides a free function, call it
+ if ( cloth->old_solver_type < 255 && solvers [cloth->old_solver_type].free )
+ {
+ solvers [cloth->old_solver_type].free ( clmd );
+ }
- if ( ! ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT ) )
- {
- if ( cloth )
- {
- // If our solver provides a free function, call it
- if ( cloth->old_solver_type < 255 && solvers [cloth->old_solver_type].free )
- {
- solvers [cloth->old_solver_type].free ( clmd );
- }
+ // Free the verts.
+ if ( cloth->verts != NULL )
+ MEM_freeN ( cloth->verts );
- // Free the verts.
- if ( cloth->verts != NULL )
- MEM_freeN ( cloth->verts );
+ cloth->verts = NULL;
+ cloth->numverts = 0;
- cloth->verts = NULL;
- cloth->numverts = 0;
-
- // Free the springs.
- if ( cloth->springs != NULL )
+ // Free the springs.
+ if ( cloth->springs != NULL )
+ {
+ LinkNode *search = cloth->springs;
+ while(search)
{
- LinkNode *search = cloth->springs;
- while(search)
- {
- ClothSpring *spring = search->link;
-
- MEM_freeN ( spring );
- search = search->next;
- }
- BLI_linklist_free(cloth->springs, NULL);
-
- cloth->springs = NULL;
+ ClothSpring *spring = search->link;
+
+ MEM_freeN ( spring );
+ search = search->next;
}
-
+ BLI_linklist_free(cloth->springs, NULL);
+
cloth->springs = NULL;
- cloth->numsprings = 0;
+ }
- // free BVH collision tree
- if ( cloth->tree )
- bvh_free ( ( BVH * ) cloth->tree );
+ cloth->springs = NULL;
+ cloth->numsprings = 0;
- // we save our faces for collision objects
- if ( cloth->mfaces )
- MEM_freeN ( cloth->mfaces );
- /*
- if(clmd->clothObject->facemarks)
- MEM_freeN(clmd->clothObject->facemarks);
- */
- MEM_freeN ( cloth );
- clmd->clothObject = NULL;
- }
+ // free BVH collision tree
+ if ( cloth->tree )
+ bvh_free ( ( BVH * ) cloth->tree );
+
+ // we save our faces for collision objects
+ if ( cloth->mfaces )
+ MEM_freeN ( cloth->mfaces );
+ /*
+ if(clmd->clothObject->facemarks)
+ MEM_freeN(clmd->clothObject->facemarks);
+ */
+ MEM_freeN ( cloth );
+ clmd->clothObject = NULL;
}
- clmd->sim_parms->flags &= ~CLOTH_SIMSETTINGS_FLAG_RESET;
}
/******************************************************************************
@@ -847,24 +861,25 @@
/**
* cloth_to_object - copies the deformed vertices to the object.
*
-* This function is a modified version of the softbody.c:softbody_to_object() function.
**/
-static void cloth_to_object ( Object *ob, ClothModifierData *clmd, float ( *vertexCos ) [3], unsigned int numverts )
+static void cloth_to_object (Object *ob, ClothModifierData *clmd, DerivedMesh *dm)
{
- ClothVertex *verts = NULL;
unsigned int i = 0;
+ MVert *mvert = NULL;
+ unsigned int numverts;
+ Cloth *cloth = clmd->clothObject;
- if ( clmd->clothObject )
- {
- verts = clmd->clothObject->verts;
-
+ if (clmd->clothObject) {
/* inverse matrix is not uptodate... */
- Mat4Invert ( ob->imat, ob->obmat );
+ Mat4Invert (ob->imat, ob->obmat);
- for ( i = 0; i < numverts; i++, verts++ )
+ mvert = CDDM_get_verts(dm);
+ numverts = dm->getNumVerts(dm);
+
+ for (i = 0; i < numverts; i++)
{
- VECCOPY ( vertexCos[i], verts->x );
- Mat4MulVecfl ( ob->imat, vertexCos[i] ); /* cloth is in global coords */
+ VECCOPY (mvert[i].co, cloth->verts[i].x);
+ Mat4MulVecfl (ob->imat, mvert[i].co); /* cloth is in global coords */
}
}
}
@@ -948,20 +963,18 @@
return VecLenf ( p1,p2 );
}
-// only meshes supported at the moment
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list