[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13361] branches/cloth/blender/source/ blender: (hopefully) fixed huge problem with cache/cloth reset.
Daniel Genrich
daniel.genrich at gmx.net
Wed Jan 23 00:17:12 CET 2008
Revision: 13361
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13361
Author: genscher
Date: 2008-01-23 00:17:10 +0100 (Wed, 23 Jan 2008)
Log Message:
-----------
(hopefully) fixed huge problem with cache/cloth reset.
Modified Paths:
--------------
branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
branches/cloth/blender/source/blender/blenkernel/BKE_modifier.h
branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
branches/cloth/blender/source/blender/blenkernel/intern/modifier.c
branches/cloth/blender/source/blender/include/butspace.h
branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h
branches/cloth/blender/source/blender/src/buttons_object.c
branches/cloth/blender/source/blender/src/editmesh.c
branches/cloth/blender/source/blender/src/editobject.c
branches/cloth/blender/source/blender/src/transform_conversions.c
branches/cloth/blender/source/blender/src/transform_generics.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-22 22:01:49 UTC (rev 13360)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h 2008-01-22 23:17:10 UTC (rev 13361)
@@ -198,11 +198,15 @@
/////////////////////////////////////////////////
// cloth.c
////////////////////////////////////////////////
-void cloth_free_modifier ( 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 );
-void cloth_update_normals ( ClothVertex *verts, int nVerts, MFace *face, int totface );
+// needed for modifier.c
+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);
+
+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);
Modified: branches/cloth/blender/source/blender/blenkernel/BKE_modifier.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_modifier.h 2008-01-22 22:01:49 UTC (rev 13360)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_modifier.h 2008-01-22 23:17:10 UTC (rev 13361)
@@ -287,7 +287,7 @@
int *lastPossibleCageIndex_r);
int modifiers_isSoftbodyEnabled(struct Object *ob);
-ClothModifierData * modifiers_isClothEnabled(Object *ob);
+int modifiers_isClothEnabled(struct Object *ob);
int modifiers_isParticleEnabled(struct Object *ob);
struct Object *modifiers_isDeformedByArmature(struct Object *ob);
Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2008-01-22 22:01:49 UTC (rev 13360)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2008-01-22 23:17:10 UTC (rev 13361)
@@ -124,7 +124,6 @@
static void cloth_to_object ( Object *ob, ClothModifierData *clmd, float ( *vertexCos ) [3], unsigned int numverts );
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 collobj_from_object ( Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float ( *vertexCos ) [3], unsigned int numverts );
int cloth_build_springs ( Cloth *cloth, DerivedMesh *dm );
static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm, short vgroup );
@@ -165,7 +164,7 @@
clmd->coll_parms->friction = 10.0;
clmd->coll_parms->loop_count = 1;
clmd->coll_parms->epsilon = 0.01f;
- clmd->coll_parms->flags = 0;
+ clmd->coll_parms->flags = CLOTH_COLLISIONSETTINGS_FLAG_ENABLED;
/* These defaults are copied from softbody.c's
* softbody_calc_forces() function.
@@ -572,24 +571,13 @@
float ( *vertexCos ) [3], int numverts )
{
unsigned int i;
- unsigned int numedges = -1;
- unsigned int numfaces = -1;
- MVert *mvert = NULL;
- MEdge *medge = NULL;
- MFace *mface = NULL;
- DerivedMesh *result = NULL, *result2 = NULL;
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;
- ClothVertex *newframe= NULL, *verts;
- Frame *frame = NULL;
- LinkNode *search = NULL;
+ ClothVertex *verts = NULL;
float deltaTime = current_time - clmd->sim_parms->sim_time;
- clmd->sim_parms->ob = ob;
-
-
// only be active during a specific period:
// that's "first frame" and "last frame" on GUI
/*
@@ -640,58 +628,11 @@
clmd->sim_parms->sim_time = current_time;
- // check if cloth object was some collision object before and needs freeing now
- if ( ! ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_COLLOBJ ) && ( clmd->clothObject != NULL ) && ( clmd->clothObject->old_solver_type == 255 ) )
- {
- // temporary set CSIMSETT_FLAG_COLLOBJ flag for proper freeing
- clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_COLLOBJ;
- cloth_free_modifier ( clmd );
- clmd->sim_parms->flags &= ~CLOTH_SIMSETTINGS_FLAG_COLLOBJ;
+ if(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_RESET)
+ {
+ cloth_free_modifier (ob, clmd);
}
- // This is for collisions objects: check special case CSIMSETT_FLAG_COLLOBJ
- if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_COLLOBJ )
- {
- // save next position + time
- if ( ( clmd->clothObject == NULL ) || ( numverts != clmd->clothObject->numverts ) )
- {
- if ( !collobj_from_object ( ob, clmd, dm, vertexCos, framenr ) )
- {
- clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_COLLOBJ;
- cloth_free_modifier ( clmd );
- return;
- }
-
- if ( clmd->clothObject == NULL )
- return;
-
- cloth = clmd->clothObject;
- }
-
- // Save old position
- clmd->sim_parms->sim_time_old = clmd->sim_parms->sim_time;
- clmd->sim_parms->sim_time = current_time;
-
- verts = cloth->verts;
-
- for ( i = 0; i < clmd->clothObject->numverts; i++, verts++ )
- {
- // Save the previous position.
- VECCOPY ( verts->xold, verts->x );
- VECCOPY ( verts->txold, verts->x );
-
- // Get the current position.
- VECCOPY ( verts->x, vertexCos[i] );
- Mat4MulVecfl ( ob->obmat, verts->x );
-
- // Compute the vertices "velocity".
- // (no dt correction here because of float error)
- VECSUB ( verts->v, verts->x, verts->xold );
- }
-
- return;
- }
-
if ( deltaTime == 1.0f )
{
if ( ( clmd->clothObject == NULL ) || ( numverts != clmd->clothObject->numverts ) )
@@ -769,10 +710,9 @@
}
/* frees all */
-void cloth_free_modifier ( ClothModifierData *clmd )
+void cloth_free_modifier ( Object *ob, ClothModifierData *clmd )
{
Cloth *cloth = NULL;
- Object *ob = clmd->sim_parms->ob;
if ( !clmd )
return;
@@ -784,8 +724,7 @@
if ( cloth )
{
// free our frame cache, TODO: but get to first position before
- if(ob)
- cloth_clear_cache ( ob, clmd, 0 );
+ cloth_clear_cache ( ob, clmd, 0 );
// If our solver provides a free function, call it
if ( cloth->old_solver_type < 255 && solvers [cloth->old_solver_type].free )
@@ -834,9 +773,73 @@
clmd->clothObject = NULL;
}
}
+ clmd->sim_parms->flags &= ~CLOTH_SIMSETTINGS_FLAG_RESET;
}
+/* frees all */
+void cloth_free_modifier_extern ( ClothModifierData *clmd )
+{
+ Cloth *cloth = NULL;
+
+ if ( !clmd )
+ return;
+ cloth = clmd->clothObject;
+
+ 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 );
+
+ cloth->verts = NULL;
+ cloth->numverts = 0;
+
+ // Free the springs.
+ if ( cloth->springs != NULL )
+ {
+ 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;
+ }
+
+ cloth->springs = NULL;
+ cloth->numsprings = 0;
+
+ // 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;
+}
+
/******************************************************************************
*
* Internal functions.
@@ -933,72 +936,6 @@
}
}
-// only meshes supported at the moment
-/* collision objects */
-static int collobj_from_object ( Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float ( *vertexCos ) [3], unsigned int numverts )
-{
- unsigned int i;
- MVert *mvert = NULL;
- ClothVertex *verts = NULL;
- float tnull[3] = {0,0,0};
-
- /* If we have a clothObject, free it. */
- if ( clmd->clothObject != NULL )
- cloth_free_modifier ( clmd );
-
- /* Allocate a new cloth object. */
- clmd->clothObject = MEM_callocN ( sizeof ( Cloth ), "cloth" );
- if ( clmd->clothObject )
- {
- clmd->clothObject->old_solver_type = 255;
- // clmd->clothObject->old_collision_type = 255;
- }
- else if ( clmd->clothObject == NULL )
- {
- modifier_setError ( & ( clmd->modifier ), "Out of memory on allocating clmd->clothObject." );
- return 0;
- }
-
- switch ( ob->type )
- {
- case OB_MESH:
-
- // mesh input objects need DerivedMesh
- if ( !dm )
- return 0;
-
- cloth_from_mesh ( ob, clmd, dm );
-
- if ( clmd->clothObject != NULL )
- {
- if ( !dm ) return 0;
- if ( !dm->getNumVerts ( dm ) || !dm->getNumFaces ( dm ) ) return 0;
-
- mvert = dm->getVertArray ( dm );
- verts = clmd->clothObject->verts;
- numverts = clmd->clothObject->numverts = dm->getNumVerts ( dm );
-
- for ( i = 0; i < numverts; i++, verts++ )
- {
- VECCOPY ( verts->x, mvert[i].co );
- Mat4MulVecfl ( ob->obmat, verts->x );
- verts->flags = 0;
- VECCOPY ( verts->xold, verts->x );
- VECCOPY ( verts->txold, verts->x );
- VECCOPY ( verts->tx, verts->x );
- VecMulf ( verts->v, 0.0f );
- verts->impulse_count = 0;
- VECCOPY ( verts->impulse, tnull );
- }
- clmd->clothObject->tree = bvh_build_from_cloth ( clmd,clmd->coll_parms->epsilon );
-
- }
-
- return 1;
- default: return 0; // TODO - we do not support changing meshes
- }
-}
-
/*
helper function to get proper spring length
when object is rescaled
@@ -1024,7 +961,7 @@
/* If we have a clothObject, free it. */
if ( clmd->clothObject != NULL )
- cloth_free_modifier ( clmd );
+ cloth_free_modifier ( ob, clmd );
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list