Fixed crash with ipo'ed collision object

This commit is contained in:
Daniel Genrich
2007-10-02 09:47:08 +00:00
parent b91cb25986
commit a5db16f913
4 changed files with 37 additions and 25 deletions

View File

@@ -86,12 +86,12 @@ struct DerivedMesh;
typedef enum
{
CSIMSETT_FLAG_RESET = (1 << 1), // The CM object requires a reinitializaiton.
CSIMSETT_FLAG_COLLOBJ = (1 << 2), // object is only collision object, no cloth simulation is done
CSIMSETT_FLAG_GOAL = (1 << 3), // we have goals enabled
CSIMSETT_FLAG_CCACHE_FREE_ALL = (1 << 4), // delete all from cache
CSIMSETT_FLAG_CCACHE_FREE_PART = (1 << 5), // delete some part of cache
CSIMSETT_FLAG_TEARING_ENABLED = (1 << 6), // true if tearing is enabled
CSIMSETT_FLAG_CCACHE_PROTECT = (1 << 7), // true if tearing is enabled
CSIMSETT_FLAG_COLLOBJ = (1 << 2), // object is only collision object, no cloth simulation is done
CSIMSETT_FLAG_GOAL = (1 << 3), // we have goals enabled
CSIMSETT_FLAG_CCACHE_FREE_ALL = (1 << 4), // delete all from cache
CSIMSETT_FLAG_CCACHE_FREE_PART = (1 << 5), // delete some part of cache
CSIMSETT_FLAG_TEARING_ENABLED = (1 << 6), // true if tearing is enabled
CSIMSETT_FLAG_CCACHE_PROTECT = (1 << 7), // true if tearing is enabled
} CSIMSETT_FLAGS;
/* Spring types as defined in the paper.*/
@@ -106,7 +106,7 @@ typedef enum
typedef enum
{
CSPRING_FLAG_DEACTIVATE = (1 << 1),
CSPRING_FLAG_NEEDED = (1 << 2), // springs has values to be applied
CSPRING_FLAG_NEEDED = (1 << 2), // springs has values to be applied
} CSPRINGS_FLAGS;
// needed for buttons_object.c

View File

@@ -656,6 +656,7 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
// only be active during a specific period:
// that's "first frame" and "last frame" on GUI
if (!(clmd->sim_parms.flags & CSIMSETT_FLAG_COLLOBJ))
{
if(current_time < clmd->sim_parms.firstframe)
@@ -699,7 +700,11 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
if ((clmd->clothObject == NULL) || (numverts != clmd->clothObject->numverts) )
{
if(!collobj_from_object (ob, clmd, dm, vertexCos, framenr))
{
clmd->sim_parms.flags |= CSIMSETT_FLAG_COLLOBJ;
cloth_free_modifier(clmd);
return;
}
if(clmd->clothObject == NULL)
return;
@@ -712,7 +717,7 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
clmd->sim_parms.sim_time = current_time;
verts = cloth->verts;
for (i = 0; i < clmd->clothObject->numverts; i++, verts++)
{
// Save the previous position.
@@ -753,24 +758,24 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
{
verts = cloth->verts;
/* Force any pinned verts to their constrained location. */
// Force any pinned verts to their constrained location.
for (i = 0; i < clmd->clothObject->numverts; i++, verts++)
{
/* Save the previous position. */
// Save the previous position.
VECCOPY (verts->xold, verts->xconst);
VECCOPY (verts->txold, verts->x);
/* Get the current position. */
// Get the current position.
VECCOPY (verts->xconst, vertexCos[i]);
Mat4MulVecfl(ob->obmat, verts->xconst);
}
tstart();
/* Call the solver. */
// Call the solver.
if (solvers [clmd->sim_parms.solver_type].solver)
solvers [clmd->sim_parms.solver_type].solver (ob, framenr, clmd, effectors);
tend();
printf("Cloth simulation time: %f\n", (float)tval());
@@ -801,6 +806,7 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
}
}
}
}
/* frees all */
@@ -815,7 +821,7 @@ void cloth_free_modifier (ClothModifierData *clmd)
if(!(clmd->sim_parms.flags & CSIMSETT_FLAG_CCACHE_PROTECT))
{
// free our frame cache
// free our frame cache, TODO: but get to first position before
clmd->sim_parms.flags |= CSIMSETT_FLAG_CCACHE_FREE_ALL;
cloth_cache_free(clmd, 0);
@@ -848,10 +854,10 @@ void cloth_free_modifier (ClothModifierData *clmd)
// 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;
}
@@ -965,8 +971,8 @@ static int collobj_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh
clmd->clothObject = MEM_callocN (sizeof(Cloth), "cloth");
if (clmd->clothObject)
{
clmd->clothObject->old_solver_type = -1;
clmd->clothObject->old_collision_type = -1;
clmd->clothObject->old_solver_type = 255;
clmd->clothObject->old_collision_type = 255;
}
else if (clmd->clothObject == NULL)
{
@@ -986,8 +992,12 @@ static int collobj_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh
if (clmd->clothObject != NULL)
{
mvert = CDDM_get_verts(dm);
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++)
{
@@ -1004,7 +1014,7 @@ static int collobj_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh
clmd->clothObject->tree = bvh_build(clmd,clmd->coll_parms.epsilon);
}
return 1;
default: return 0; // TODO - we do not support changing meshes
}
@@ -1175,8 +1185,8 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
clmd->clothObject = MEM_callocN (sizeof(Cloth), "cloth");
if (clmd->clothObject)
{
clmd->clothObject->old_solver_type = -1;
clmd->clothObject->old_collision_type = -1;
clmd->clothObject->old_solver_type = 255;
clmd->clothObject->old_collision_type = 255;
}
else if (clmd->clothObject == NULL)
{
@@ -1242,7 +1252,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
clmd->clothObject->tree = bvh_build(clmd, clmd->coll_parms.epsilon);
cloth_cache_set_frame(clmd, 1);
// cloth_cache_set_frame(clmd, 1);
}
return 1;
@@ -1265,7 +1275,7 @@ static void cloth_from_mesh (Object *ob, ClothModifierData *clmd, DerivedMesh *d
{
unsigned int numverts = dm->getNumVerts(dm);
unsigned int numfaces = dm->getNumFaces(dm);
MFace *mface = CDDM_get_faces(dm);
MFace *mface = dm->getFaceArray(dm);
unsigned int i = 0;
/* Allocate our vertices.

View File

@@ -572,6 +572,7 @@ BVH *bvh_build (ClothModifierData *clmd, float epsilon)
bvh->flags = 0;
bvh->leaf_tree = NULL;
bvh->leaf_root = NULL;
bvh->tree = NULL;
bvh->epsilon = epsilon;
bvh->numfaces = cloth->numfaces;
@@ -581,7 +582,7 @@ BVH *bvh_build (ClothModifierData *clmd, float epsilon)
bvh->verts = cloth->verts;
tree = (Tree *)MEM_callocN(sizeof(Tree), "Tree");
// TODO: check succesfull alloc
BLI_linklist_prepend(&bvh->tree, tree);
BLI_linklist_append(&bvh->tree, tree);
nlink = bvh->tree;

View File

@@ -1067,6 +1067,7 @@ void do_global_buttons(unsigned short event)
else if(nr==ID_LA) idtest= (ID *)add_ipo("LaIpo", nr);
else if(nr==ID_CA) idtest= (ID *)add_ipo("CaIpo", nr);
else if(nr==ID_SO) idtest= (ID *)add_ipo("SndIpo", nr);
else if(nr==ID_FLUIDSIM) idtest= (ID *)add_ipo("FluidsimIpo", nr);
else error("Warn bugtracker!");
}
idtest->us--;