WIP commit, many debug outputs, extensive log comes after bug is killed
This commit is contained in:
@@ -62,9 +62,7 @@ struct CollisionTree;
|
||||
#define CLOTH_MAX_THREAD 2
|
||||
|
||||
/**
|
||||
* Pin and unpin frames are the frames on which the vertices stop moving.
|
||||
* They will assume the position they had prior to pinFrame until unpinFrame
|
||||
* is reached.
|
||||
* The definition of a cloth vertex.
|
||||
*/
|
||||
typedef struct ClothVertex
|
||||
{
|
||||
@@ -87,7 +85,6 @@ typedef struct ClothVertex
|
||||
}
|
||||
ClothVertex;
|
||||
|
||||
|
||||
/**
|
||||
* The definition of a spring.
|
||||
*/
|
||||
@@ -106,7 +103,6 @@ typedef struct ClothSpring
|
||||
}
|
||||
ClothSpring;
|
||||
|
||||
|
||||
/* goal defines */
|
||||
#define SOFTGOALSNAP 0.999f
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ SET(INC
|
||||
../python ../render/extern/include ../../../intern/decimation/extern
|
||||
../imbuf ../avi ../../../intern/elbeem/extern ../../../intern/opennl/extern
|
||||
../../../intern/iksolver/extern ../blenloader ../quicktime
|
||||
../../../intern/bmfont
|
||||
../../../intern/bmfont ../../../extern/bullet2/src
|
||||
../nodes
|
||||
${SDL_INC}
|
||||
${ZLIB_INC}
|
||||
|
||||
@@ -125,7 +125,7 @@ static void cloth_to_object (Object *ob, ClothModifierData *clmd, DerivedMesh *
|
||||
static void cloth_from_mesh ( Object *ob, ClothModifierData *clmd, DerivedMesh *dm );
|
||||
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, int mode );
|
||||
static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm );
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
@@ -162,12 +162,12 @@ void cloth_init ( ClothModifierData *clmd )
|
||||
clmd->sim_parms->vgroup_mass = 0;
|
||||
clmd->sim_parms->lastcachedframe = 0;
|
||||
clmd->sim_parms->editedframe = 0;
|
||||
clmd->sim_parms->autoprotect = 10;
|
||||
clmd->sim_parms->autoprotect = 25;
|
||||
|
||||
clmd->coll_parms->self_friction = 5.0;
|
||||
clmd->coll_parms->friction = 10.0;
|
||||
clmd->coll_parms->loop_count = 5;
|
||||
clmd->coll_parms->epsilon = 0.01f;
|
||||
clmd->coll_parms->loop_count = 3;
|
||||
clmd->coll_parms->epsilon = 0.015f;
|
||||
clmd->coll_parms->flags = CLOTH_COLLSETTINGS_FLAG_ENABLED;
|
||||
|
||||
/* These defaults are copied from softbody.c's
|
||||
@@ -182,8 +182,6 @@ void cloth_init ( ClothModifierData *clmd )
|
||||
clmd->sim_parms->defgoal = 0.0f;
|
||||
clmd->sim_parms->goalspring = 100.0f;
|
||||
clmd->sim_parms->goalfrict = 0.0f;
|
||||
|
||||
clmd->sim_parms->cache = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -521,17 +519,38 @@ int cloth_read_cache(Object *ob, ClothModifierData *clmd, float framenr)
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
/*
|
||||
// belongs to another location ?!?
|
||||
if((clmd->sim_parms->solver_type == 0) && (ret!=0))
|
||||
{
|
||||
implicit_set_positions(clmd);
|
||||
}
|
||||
*/
|
||||
|
||||
if(clmd->sim_parms->lastcachedframe < framenr)
|
||||
{
|
||||
printf("cloth_read_cache problem: lnex - f#: %f, lastCF: %d\n", framenr, clmd->sim_parms->lastcachedframe);
|
||||
}
|
||||
}
|
||||
|
||||
if(clmd->sim_parms->solver_type == 0)
|
||||
implicit_set_positions(clmd);
|
||||
|
||||
printf("cloth_read_cache: %f\n", framenr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
|
||||
{
|
||||
int stack_index = -1;
|
||||
printf("cloth_clear_cache: %f\n", framenr);
|
||||
|
||||
/*
|
||||
// belongs to another location ?!?
|
||||
if(framenr>0)
|
||||
{
|
||||
cloth_read_cache(ob, clmd, framenr);
|
||||
}
|
||||
*/
|
||||
|
||||
/* clear cache if specific frame cleaning requested or cache is not protected */
|
||||
if((!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT)) || (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE))
|
||||
@@ -541,13 +560,13 @@ void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
|
||||
BKE_ptcache_id_clear((ID *)ob, PTCACHE_CLEAR_AFTER, framenr, stack_index);
|
||||
}
|
||||
|
||||
if(framenr>0)
|
||||
{
|
||||
cloth_read_cache(ob, clmd, framenr);
|
||||
}
|
||||
/* update last cached frame # */
|
||||
clmd->sim_parms->lastcachedframe = framenr;
|
||||
|
||||
/* delete cache free request */
|
||||
clmd->sim_parms->flags &= ~CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE;
|
||||
|
||||
|
||||
}
|
||||
void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr)
|
||||
{
|
||||
@@ -556,8 +575,11 @@ void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr)
|
||||
unsigned int a;
|
||||
Cloth *cloth = clmd->clothObject;
|
||||
|
||||
printf("cloth_write_cache: %f\n", framenr);
|
||||
|
||||
if(!cloth)
|
||||
{
|
||||
printf("cloth_write_cache: no cloth\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -566,6 +588,7 @@ void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr)
|
||||
fp = BKE_ptcache_id_fopen((ID *)ob, 'w', framenr, stack_index);
|
||||
if(!fp)
|
||||
{
|
||||
printf("cloth_write_cache: no fp\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -578,6 +601,8 @@ void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr)
|
||||
|
||||
clmd->sim_parms->lastcachedframe = MAX2(clmd->sim_parms->lastcachedframe, framenr);
|
||||
|
||||
printf("lcf: %d, framenr: %f\n", clmd->sim_parms->lastcachedframe, framenr);
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
@@ -591,7 +616,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd,Object *ob, DerivedMesh *d
|
||||
{
|
||||
unsigned int i;
|
||||
Cloth *cloth = clmd->clothObject;
|
||||
unsigned int framenr = ( float ) G.scene->r.cfra;
|
||||
float framenr = G.scene->r.cfra;
|
||||
float current_time = bsystem_time ( ob, ( float ) G.scene->r.cfra, 0.0 );
|
||||
ListBase *effectors = NULL;
|
||||
ClothVertex *verts = NULL;
|
||||
@@ -604,6 +629,8 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd,Object *ob, DerivedMesh *d
|
||||
MFace *mface = NULL;
|
||||
DerivedMesh *result = NULL;
|
||||
|
||||
printf("clothModifier_do start\n");
|
||||
|
||||
result = CDDM_copy(dm);
|
||||
|
||||
if(!result)
|
||||
@@ -614,134 +641,182 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd,Object *ob, DerivedMesh *d
|
||||
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 result;
|
||||
}
|
||||
else if ( current_time > clmd->sim_parms->lastframe )
|
||||
{
|
||||
int stack_index = modifiers_indexInObject(ob, (ModifierData *)clmd);
|
||||
|
||||
if(BKE_ptcache_id_exist((ID *)ob, clmd->sim_parms->lastcachedframe, stack_index))
|
||||
{
|
||||
if(cloth_read_cache(ob, clmd, framenr))
|
||||
{
|
||||
// Copy the result back to the object.
|
||||
cloth_to_object (ob, clmd, result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// unused in the moment, calculated seperately in implicit.c
|
||||
clmd->sim_parms->dt = 1.0f / clmd->sim_parms->stepsPerFrame;
|
||||
|
||||
clmd->sim_parms->sim_time = current_time;
|
||||
mvert = dm->getVertArray(result);
|
||||
medge = dm->getEdgeArray(result);
|
||||
mface = dm->getFaceArray(result);
|
||||
|
||||
/* check if cache is active / if file is already saved */
|
||||
/*
|
||||
if ((!G.relbase_valid) && ( deltaTime != 1.0f ))
|
||||
{
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_RESET;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
if(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_RESET)
|
||||
{
|
||||
cloth_free_modifier (ob, clmd);
|
||||
printf("clothModifier_do CLOTH_SIMSETTINGS_FLAG_RESET\n");
|
||||
}
|
||||
|
||||
// sanity check for correctness of GUI values
|
||||
if(clmd->sim_parms->max_struct<clmd->sim_parms->structural)
|
||||
clmd->sim_parms->max_struct=clmd->sim_parms->structural;
|
||||
if(clmd->sim_parms->max_bend<clmd->sim_parms->bending)
|
||||
clmd->sim_parms->max_struct=clmd->sim_parms->bending;
|
||||
if(clmd->sim_parms->max_shear<clmd->sim_parms->shear)
|
||||
clmd->sim_parms->max_shear=clmd->sim_parms->shear;
|
||||
|
||||
if ( deltaTime == 1.0f )
|
||||
// unused in the moment, calculated seperately in implicit.c
|
||||
clmd->sim_parms->dt = 1.0f / clmd->sim_parms->stepsPerFrame;
|
||||
|
||||
if ( ( clmd->clothObject == NULL ) || (clmd->clothObject && (numverts != clmd->clothObject->numverts )) )
|
||||
{
|
||||
if ( ( clmd->clothObject == NULL ) || ( numverts != clmd->clothObject->numverts ) )
|
||||
/* only force free the cache if we have a different number of verts */
|
||||
if(clmd->clothObject && (numverts != clmd->clothObject->numverts ))
|
||||
{
|
||||
cloth_clear_cache(ob, clmd, 0);
|
||||
|
||||
// printf("v1: %d, v2: %d\n", numverts, clmd->clothObject->numverts);
|
||||
|
||||
if ( !cloth_from_object ( ob, clmd, result, framenr ) )
|
||||
return result;
|
||||
|
||||
if ( clmd->clothObject == NULL )
|
||||
return result;
|
||||
|
||||
cloth = clmd->clothObject;
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE;
|
||||
cloth_free_modifier ( ob, clmd );
|
||||
}
|
||||
|
||||
clmd->clothObject->old_solver_type = clmd->sim_parms->solver_type;
|
||||
|
||||
// Insure we have a clmd->clothObject, in case allocation failed.
|
||||
if ( clmd->clothObject != NULL )
|
||||
{
|
||||
if(!cloth_read_cache(ob, clmd, framenr))
|
||||
{
|
||||
verts = cloth->verts;
|
||||
|
||||
// Force any pinned verts to their constrained location.
|
||||
for ( i = 0; i < clmd->clothObject->numverts; i++, verts++ )
|
||||
{
|
||||
// Save the previous position.
|
||||
VECCOPY ( verts->xold, verts->xconst );
|
||||
VECCOPY ( verts->txold, verts->x );
|
||||
|
||||
// Get the current position.
|
||||
VECCOPY ( verts->xconst, mvert[i].co );
|
||||
Mat4MulVecfl ( ob->obmat, verts->xconst );
|
||||
}
|
||||
|
||||
cloth_clear_cache(ob, clmd, 0);
|
||||
|
||||
tstart();
|
||||
|
||||
// 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() );
|
||||
|
||||
cloth_write_cache(ob, clmd, framenr);
|
||||
|
||||
// check for autoprotection
|
||||
if(framenr >= clmd->sim_parms->autoprotect)
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT;
|
||||
}
|
||||
|
||||
// Copy the result back to the object.
|
||||
cloth_to_object (ob, clmd, result);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( clmd->clothObject != NULL )
|
||||
if ( !cloth_from_object ( ob, clmd, result, framenr ) )
|
||||
return result;
|
||||
|
||||
if ( clmd->clothObject == NULL )
|
||||
return result;
|
||||
|
||||
cloth = clmd->clothObject;
|
||||
|
||||
if(!cloth_read_cache(ob, clmd, framenr))
|
||||
{
|
||||
if(cloth_read_cache(ob, clmd, framenr))
|
||||
{
|
||||
cloth_to_object (ob, clmd, result);
|
||||
}
|
||||
/* save first frame in case we have a reseted object
|
||||
and we move one frame forward.
|
||||
In that case we would only start with the SECOND frame
|
||||
if we don't save the current state before
|
||||
TODO PROBLEM: IMHO we can't track external movement from the
|
||||
first frame in this case! */
|
||||
/*
|
||||
if ( deltaTime == 1.0f )
|
||||
cloth_write_cache(ob, clmd, framenr-1.0);
|
||||
*/
|
||||
printf("cloth_from_object NO cloth_read_cache cloth_write_cache\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("cloth_from_object cloth_read_cache\n");
|
||||
|
||||
implicit_set_positions(clmd);
|
||||
}
|
||||
|
||||
clmd->sim_parms->sim_time = current_time;
|
||||
}
|
||||
|
||||
// only be active during a specific period:
|
||||
// that's "first frame" and "last frame" on GUI
|
||||
/*
|
||||
// TODO: enable later again after refactoring
|
||||
if ( current_time < clmd->sim_parms->firstframe )
|
||||
{
|
||||
return result;
|
||||
}
|
||||
else if ( current_time > clmd->sim_parms->lastframe )
|
||||
{
|
||||
int stack_index = modifiers_indexInObject(ob, (ModifierData *)clmd);
|
||||
|
||||
if(BKE_ptcache_id_exist((ID *)ob, clmd->sim_parms->lastcachedframe, stack_index))
|
||||
{
|
||||
if(cloth_read_cache(ob, clmd, framenr))
|
||||
{
|
||||
// Copy the result back to the object.
|
||||
cloth_to_object (ob, clmd, result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
/* nice moving one frame forward */
|
||||
if ( deltaTime == 1.0f )
|
||||
{
|
||||
clmd->sim_parms->sim_time = current_time;
|
||||
|
||||
printf("clothModifier_do deltaTime=1\n");
|
||||
|
||||
if(!cloth_read_cache(ob, clmd, framenr))
|
||||
{
|
||||
verts = cloth->verts;
|
||||
|
||||
// Force any pinned verts to their constrained location.
|
||||
for ( i = 0; i < clmd->clothObject->numverts; i++, verts++ )
|
||||
{
|
||||
// Save the previous position.
|
||||
VECCOPY ( verts->xold, verts->xconst );
|
||||
VECCOPY ( verts->txold, verts->x );
|
||||
|
||||
// Get the current position.
|
||||
VECCOPY ( verts->xconst, mvert[i].co );
|
||||
Mat4MulVecfl ( ob->obmat, verts->xconst );
|
||||
}
|
||||
|
||||
tstart();
|
||||
|
||||
// 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() );
|
||||
|
||||
cloth_write_cache(ob, clmd, framenr);
|
||||
|
||||
// check for autoprotection
|
||||
if(framenr >= clmd->sim_parms->autoprotect)
|
||||
{
|
||||
printf("fr#: %f, auto: %d\n", framenr, clmd->sim_parms->autoprotect);
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT;
|
||||
}
|
||||
|
||||
printf("clothModifier_do deltaTime=1 cachewrite\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("clothModifier_do deltaTime=1 cacheread\n");
|
||||
implicit_set_positions(clmd);
|
||||
}
|
||||
|
||||
// Copy the result back to the object.
|
||||
cloth_to_object (ob, clmd, result);
|
||||
}
|
||||
else if(deltaTime == 0.0f)
|
||||
{
|
||||
printf("clothModifier_do deltaTime!=1 clmd->clothObject != NULL\n");
|
||||
if(cloth_read_cache(ob, clmd, framenr))
|
||||
{
|
||||
cloth_to_object (ob, clmd, result);
|
||||
implicit_set_positions(clmd);
|
||||
}
|
||||
else /* same cache parts are missing */
|
||||
{
|
||||
/*
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_RESET;
|
||||
*/
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE;
|
||||
cloth_clear_cache(ob, clmd, 0);
|
||||
|
||||
if ( !cloth_from_object ( ob, clmd, result, framenr ) )
|
||||
return result;
|
||||
cloth_write_cache(ob, clmd, framenr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("clothModifier_do deltaTime!=1 clmd->clothObject != NULL\n");
|
||||
if(cloth_read_cache(ob, clmd, framenr))
|
||||
{
|
||||
cloth_to_object (ob, clmd, result);
|
||||
implicit_set_positions(clmd);
|
||||
clmd->sim_parms->sim_time = current_time;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* jump to a non-existing frame makes sim reset */
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_RESET;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/* frees all */
|
||||
@@ -754,59 +829,54 @@ void cloth_free_modifier ( Object *ob, ClothModifierData *clmd )
|
||||
|
||||
cloth = clmd->clothObject;
|
||||
|
||||
if ( ! ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT ) )
|
||||
{
|
||||
if ( cloth )
|
||||
|
||||
if ( cloth )
|
||||
{
|
||||
// If our solver provides a free function, call it
|
||||
if ( solvers [clmd->sim_parms->solver_type].free )
|
||||
{
|
||||
// free our frame cache, TODO: but get to first position before
|
||||
cloth_clear_cache ( ob, clmd, 0 );
|
||||
|
||||
// If our solver provides a free function, call it
|
||||
if ( solvers [clmd->sim_parms->solver_type].free )
|
||||
{
|
||||
solvers [clmd->sim_parms->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;
|
||||
solvers [clmd->sim_parms->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;
|
||||
}
|
||||
@@ -816,6 +886,8 @@ void cloth_free_modifier_extern ( ClothModifierData *clmd )
|
||||
{
|
||||
Cloth *cloth = NULL;
|
||||
|
||||
printf("cloth_free_modifier_extern\n");
|
||||
|
||||
if ( !clmd )
|
||||
return;
|
||||
|
||||
@@ -823,6 +895,8 @@ void cloth_free_modifier_extern ( ClothModifierData *clmd )
|
||||
|
||||
if ( cloth )
|
||||
{
|
||||
printf("cloth_free_modifier_extern in\n");
|
||||
|
||||
// If our solver provides a free function, call it
|
||||
if ( solvers [clmd->sim_parms->solver_type].free )
|
||||
{
|
||||
@@ -909,7 +983,7 @@ static void cloth_to_object (Object *ob, ClothModifierData *clmd, DerivedMesh *
|
||||
*
|
||||
**/
|
||||
/* can be optimized to do all groups in one loop */
|
||||
static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm, short vgroup, int mode )
|
||||
static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
|
||||
{
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
@@ -918,66 +992,57 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm, short
|
||||
unsigned int numverts = dm->getNumVerts ( dm );
|
||||
float goalfac = 0;
|
||||
ClothVertex *verts = NULL;
|
||||
// clmd->sim_parms->vgroup_mass
|
||||
|
||||
clothObj = clmd->clothObject;
|
||||
|
||||
if ( !dm )
|
||||
return;
|
||||
|
||||
|
||||
numverts = dm->getNumVerts ( dm );
|
||||
|
||||
/* vgroup is 1 based, decrement so we can match the right group. */
|
||||
--vgroup;
|
||||
|
||||
verts = clothObj->verts;
|
||||
|
||||
for ( i = 0; i < numverts; i++, verts++ )
|
||||
|
||||
if (((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING ) ||
|
||||
(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL )) &&
|
||||
((clmd->sim_parms->vgroup_mass>0) ||
|
||||
(clmd->sim_parms->vgroup_struct>0)||
|
||||
(clmd->sim_parms->vgroup_bend>0)))
|
||||
{
|
||||
// LATER ON, support also mass painting here
|
||||
if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL )||(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING))
|
||||
for ( i = 0; i < numverts; i++, verts++ )
|
||||
{
|
||||
dvert = dm->getVertData ( dm, i, CD_MDEFORMVERT );
|
||||
if ( dvert )
|
||||
{
|
||||
for ( j = 0; j < dvert->totweight; j++ )
|
||||
{
|
||||
if ( dvert->dw[j].def_nr == vgroup )
|
||||
if (( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_mass-1)) && (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL ))
|
||||
{
|
||||
if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL )
|
||||
verts->goal = dvert->dw [j].weight;
|
||||
goalfac= 1.0f;
|
||||
|
||||
/*
|
||||
// Kicking goal factor to simplify things...who uses that anyway?
|
||||
// ABS ( clmd->sim_parms->maxgoal - clmd->sim_parms->mingoal );
|
||||
*/
|
||||
|
||||
verts->goal = ( float ) pow ( verts->goal , 4.0f );
|
||||
if ( verts->goal >=SOFTGOALSNAP )
|
||||
verts->flags |= CLOTH_VERT_FLAG_PINNED;
|
||||
}
|
||||
|
||||
if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING )
|
||||
{
|
||||
if( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_struct-1))
|
||||
{
|
||||
if(mode==0)
|
||||
{
|
||||
verts->goal = dvert->dw [j].weight;
|
||||
goalfac= 1.0f;
|
||||
|
||||
/*
|
||||
// Kicking goal factor to simplify things...who uses that anyway?
|
||||
// ABS ( clmd->sim_parms->maxgoal - clmd->sim_parms->mingoal );
|
||||
*/
|
||||
|
||||
verts->goal = ( float ) pow ( verts->goal , 4.0f );
|
||||
if ( verts->goal >=SOFTGOALSNAP )
|
||||
verts->flags |= CLOTH_VERT_FLAG_PINNED;
|
||||
|
||||
break;
|
||||
}
|
||||
verts->struct_stiff = dvert->dw [j].weight;
|
||||
verts->shear_stiff = dvert->dw [j].weight;
|
||||
}
|
||||
|
||||
if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING )
|
||||
if( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_bend-1))
|
||||
{
|
||||
if(mode==2)
|
||||
{
|
||||
verts->struct_stiff = dvert->dw [j].weight;
|
||||
verts->shear_stiff = dvert->dw [j].weight;
|
||||
break;
|
||||
}
|
||||
else if(mode==1)
|
||||
{
|
||||
verts->bend_stiff = dvert->dw [j].weight;
|
||||
break;
|
||||
}
|
||||
verts->bend_stiff = dvert->dw [j].weight;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1010,6 +1075,8 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
|
||||
if ( clmd->clothObject != NULL )
|
||||
{
|
||||
cloth_free_modifier ( ob, clmd );
|
||||
|
||||
printf("cloth_free_modifier cloth_from_object\n");
|
||||
}
|
||||
|
||||
// Allocate a new cloth object.
|
||||
@@ -1037,14 +1104,21 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
|
||||
clmd->clothObject->springs = NULL;
|
||||
clmd->clothObject->numsprings = -1;
|
||||
|
||||
mvert = CDDM_get_verts ( dm );
|
||||
mvert = dm->getVertArray ( dm );
|
||||
verts = clmd->clothObject->verts;
|
||||
|
||||
// set initial values
|
||||
for ( i = 0; i < dm->getNumVerts(dm); i++, verts++ )
|
||||
{
|
||||
VECCOPY ( verts->x, mvert[i].co );
|
||||
|
||||
if(i<5)
|
||||
printf("i: %d, verts->x[0]: %f\n", i, verts->x[0]);
|
||||
|
||||
Mat4MulVecfl ( ob->obmat, verts->x );
|
||||
|
||||
if(i<5)
|
||||
printf("i: %d, verts->x[0]: %f\n\n", i, verts->x[0]);
|
||||
|
||||
verts->mass = clmd->sim_parms->mass;
|
||||
|
||||
@@ -1063,34 +1137,24 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
|
||||
VECCOPY ( verts->impulse, tnull );
|
||||
}
|
||||
|
||||
// apply / set vertex groups
|
||||
// has to be happen before springs are build!
|
||||
cloth_apply_vgroup (clmd, dm);
|
||||
|
||||
if ( !cloth_build_springs ( clmd, dm ) )
|
||||
{
|
||||
cloth_free_modifier ( ob, clmd );
|
||||
modifier_setError ( & ( clmd->modifier ), "Can't build springs." );
|
||||
printf("cloth_free_modifier cloth_build_springs\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// apply / set vertex groups
|
||||
if ( clmd->sim_parms->vgroup_mass > 0 )
|
||||
cloth_apply_vgroup ( clmd, dm, clmd->sim_parms->vgroup_mass, 0 );
|
||||
|
||||
// apply / set vertex groups
|
||||
if ( clmd->sim_parms->vgroup_bend > 0 )
|
||||
cloth_apply_vgroup ( clmd, dm, clmd->sim_parms->vgroup_bend, 1 );
|
||||
|
||||
// apply / set vertex groups
|
||||
if ( clmd->sim_parms->vgroup_struct > 0 )
|
||||
cloth_apply_vgroup ( clmd, dm, clmd->sim_parms->vgroup_struct, 2 );
|
||||
|
||||
// init our solver
|
||||
if ( solvers [clmd->sim_parms->solver_type].init )
|
||||
solvers [clmd->sim_parms->solver_type].init ( ob, clmd );
|
||||
|
||||
clmd->clothObject->tree = bvh_build_from_cloth ( clmd, clmd->coll_parms->epsilon );
|
||||
|
||||
if(!cloth_read_cache(ob, clmd, framenr))
|
||||
cloth_write_cache(ob, clmd, framenr);
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -1112,6 +1176,7 @@ static void cloth_from_mesh ( Object *ob, ClothModifierData *clmd, DerivedMesh *
|
||||
{
|
||||
cloth_free_modifier ( ob, clmd );
|
||||
modifier_setError ( & ( clmd->modifier ), "Out of memory on allocating clmd->clothObject->verts." );
|
||||
printf("cloth_free_modifier clmd->clothObject->verts\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1122,6 +1187,7 @@ static void cloth_from_mesh ( Object *ob, ClothModifierData *clmd, DerivedMesh *
|
||||
{
|
||||
cloth_free_modifier ( ob, clmd );
|
||||
modifier_setError ( & ( clmd->modifier ), "Out of memory on allocating clmd->clothObject->mfaces." );
|
||||
printf("cloth_free_modifier clmd->clothObject->mfaces\n");
|
||||
return;
|
||||
}
|
||||
for ( i = 0; i < numfaces; i++ )
|
||||
@@ -1214,6 +1280,14 @@ int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm )
|
||||
spring->kl = medge[i].v2;
|
||||
VECSUB ( temp, cloth->verts[spring->kl].x, cloth->verts[spring->ij].x );
|
||||
spring->restlen = sqrt ( INPR ( temp, temp ) );
|
||||
/*
|
||||
if(spring->restlen > 1.0)
|
||||
{
|
||||
printf("i: %d, L: %f\n", i, spring->restlen);
|
||||
printf("%d, x: %f, y: %f, z: %f\n", cloth->verts[spring->ij].x[0], cloth->verts[spring->ij].x[1], spring->ij, cloth->verts[spring->ij].x[2]);
|
||||
printf("%d, x: %f, y: %f, z: %f\n\n",spring->kl, cloth->verts[spring->kl].x[0], cloth->verts[spring->kl].x[1], cloth->verts[spring->kl].x[2]);
|
||||
}
|
||||
*/
|
||||
clmd->coll_parms->avg_spring_len += spring->restlen;
|
||||
spring->type = CLOTH_SPRING_TYPE_STRUCTURAL;
|
||||
spring->flags = 0;
|
||||
|
||||
@@ -991,6 +991,7 @@ int cloth_bvh_objcollision(ClothModifierData * clmd, float step, float dt)
|
||||
ClothVertex *verts = NULL;
|
||||
float tnull[3] = {0,0,0};
|
||||
int ret = 0;
|
||||
ClothModifierData *tclmd;
|
||||
|
||||
if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_COLLOBJ) || !(((Cloth *)clmd->clothObject)->tree))
|
||||
{
|
||||
@@ -1025,6 +1026,10 @@ int cloth_bvh_objcollision(ClothModifierData * clmd, float step, float dt)
|
||||
if (!collmd)
|
||||
continue;
|
||||
|
||||
tclmd = (ClothModifierData *) modifiers_findByType (coll_ob, eModifierType_Cloth);
|
||||
if(tclmd == clmd)
|
||||
continue;
|
||||
|
||||
if (collmd->tree)
|
||||
{
|
||||
BVH *coll_bvh = collmd->tree;
|
||||
@@ -1035,57 +1040,50 @@ int cloth_bvh_objcollision(ClothModifierData * clmd, float step, float dt)
|
||||
}
|
||||
else
|
||||
printf ("cloth_bvh_objcollision: found a collision object with clothObject or collData NULL.\n");
|
||||
}
|
||||
|
||||
// process all collisions (calculate impulses, TODO: also repulses if distance too short)
|
||||
result = 1;
|
||||
for(j = 0; j < 10; j++) // 10 is just a value that ensures convergence
|
||||
{
|
||||
result = 0;
|
||||
|
||||
// handle all collision objects
|
||||
for (base = G.scene->base.first; base; base = base->next)
|
||||
|
||||
// process all collisions (calculate impulses, TODO: also repulses if distance too short)
|
||||
result = 1;
|
||||
for(j = 0; j < 10; j++) // 10 is just a value that ensures convergence
|
||||
{
|
||||
|
||||
coll_ob = base->object;
|
||||
collmd = (CollisionModifierData *) modifiers_findByType (coll_ob, eModifierType_Collision);
|
||||
if (!collmd)
|
||||
continue;
|
||||
|
||||
result += cloth_collision_response_static(clmd, collmd);
|
||||
}
|
||||
|
||||
// apply impulses in parallel
|
||||
ic=0;
|
||||
for(i = 0; i < numverts; i++)
|
||||
{
|
||||
// calculate "velocities" (just xnew = xold + v; no dt in v)
|
||||
if(verts[i].impulse_count)
|
||||
{
|
||||
VECADDMUL(verts[i].tv, verts[i].impulse, 1.0f / verts[i].impulse_count);
|
||||
VECCOPY(verts[i].impulse, tnull);
|
||||
verts[i].impulse_count = 0;
|
||||
result = 0;
|
||||
|
||||
ic++;
|
||||
ret++;
|
||||
if (collmd->tree)
|
||||
result += cloth_collision_response_static(clmd, collmd);
|
||||
|
||||
|
||||
// apply impulses in parallel
|
||||
ic=0;
|
||||
for(i = 0; i < numverts; i++)
|
||||
{
|
||||
// calculate "velocities" (just xnew = xold + v; no dt in v)
|
||||
if(verts[i].impulse_count)
|
||||
{
|
||||
VECADDMUL(verts[i].tv, verts[i].impulse, 1.0f / verts[i].impulse_count);
|
||||
VECCOPY(verts[i].impulse, tnull);
|
||||
verts[i].impulse_count = 0;
|
||||
|
||||
ic++;
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// free collision list
|
||||
if(clmd->coll_parms->collision_list)
|
||||
{
|
||||
LinkNode *search = clmd->coll_parms->collision_list;
|
||||
while(search)
|
||||
{
|
||||
CollPair *coll_pair = search->link;
|
||||
|
||||
MEM_freeN(coll_pair);
|
||||
search = search->next;
|
||||
}
|
||||
BLI_linklist_free(clmd->coll_parms->collision_list,NULL);
|
||||
|
||||
clmd->coll_parms->collision_list = NULL;
|
||||
// free collision list
|
||||
if(clmd->coll_parms->collision_list)
|
||||
{
|
||||
LinkNode *search = clmd->coll_parms->collision_list;
|
||||
while(search)
|
||||
{
|
||||
CollPair *coll_pair = search->link;
|
||||
|
||||
MEM_freeN(coll_pair);
|
||||
search = search->next;
|
||||
}
|
||||
BLI_linklist_free(clmd->coll_parms->collision_list,NULL);
|
||||
|
||||
clmd->coll_parms->collision_list = NULL;
|
||||
}
|
||||
}
|
||||
rounds++;
|
||||
}
|
||||
|
||||
@@ -4956,6 +4956,7 @@ static void clothModifier_initData(ModifierData *md)
|
||||
return;
|
||||
|
||||
cloth_init (clmd);
|
||||
printf("clothModifier_initData\n");
|
||||
}
|
||||
|
||||
static DerivedMesh *clothModifier_applyModifier(ModifierData *md, Object *ob,
|
||||
@@ -5050,6 +5051,8 @@ static void clothModifier_freeData(ModifierData *md)
|
||||
if (clmd)
|
||||
{
|
||||
|
||||
printf("clothModifier_freeData\n");
|
||||
|
||||
cloth_free_modifier_extern (clmd);
|
||||
|
||||
if(clmd->sim_parms)
|
||||
|
||||
@@ -1788,7 +1788,7 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
|
||||
} else if (md->type==eModifierType_Softbody) {
|
||||
height = 31;
|
||||
} else if (md->type==eModifierType_Cloth) {
|
||||
height = 26;
|
||||
height = 31;
|
||||
} else if (md->type==eModifierType_Collision) {
|
||||
height = 19;
|
||||
} else if (md->type==eModifierType_Boolean) {
|
||||
|
||||
@@ -2355,10 +2355,13 @@ void do_object_panels(unsigned short event)
|
||||
/* force freeing because user wants */
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE;
|
||||
|
||||
/*user wants to free all, so free whole cloth, this helps to start sim at later frame */
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_RESET;
|
||||
|
||||
CFRA= 1;
|
||||
update_for_newframe_muted();
|
||||
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
|
||||
cloth_clear_cache(ob, clmd, 1);
|
||||
cloth_clear_cache(ob, clmd, 0);
|
||||
allqueue(REDRAWBUTSOBJECT, 0);
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
}
|
||||
@@ -2372,7 +2375,7 @@ void do_object_panels(unsigned short event)
|
||||
/* force freeing because user wants */
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE;
|
||||
|
||||
cloth_clear_cache(ob, clmd, MAX2(1.0,G.scene->r.cfra));
|
||||
cloth_clear_cache(ob, clmd, MAX2(0.0,G.scene->r.cfra));
|
||||
// MAX2(1.0,G.scene->r.cfra + 1.0)
|
||||
allqueue(REDRAWBUTSOBJECT, 0);
|
||||
}
|
||||
@@ -2383,14 +2386,11 @@ void do_object_panels(unsigned short event)
|
||||
ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
|
||||
if(clmd)
|
||||
{
|
||||
if(clmd->sim_parms->cache)
|
||||
{
|
||||
CFRA= 1;
|
||||
update_for_newframe_muted();
|
||||
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
|
||||
allqueue(REDRAWBUTSOBJECT, 0);
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
}
|
||||
CFRA= 1;
|
||||
update_for_newframe_muted();
|
||||
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
|
||||
allqueue(REDRAWBUTSOBJECT, 0);
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -2401,6 +2401,9 @@ void do_object_panels(unsigned short event)
|
||||
if(clmd)
|
||||
{
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_RESET;
|
||||
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
|
||||
allqueue(REDRAWBUTSOBJECT, 0);
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -5047,7 +5050,9 @@ static void object_cloth__enabletoggle(void *ob_v, void *arg2)
|
||||
md = modifier_new(eModifierType_Cloth);
|
||||
BLI_addhead(&ob->modifiers, md);
|
||||
|
||||
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
|
||||
allqueue(REDRAWBUTSEDIT, 0);
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
}
|
||||
else {
|
||||
Object *ob = ob_v;
|
||||
@@ -5121,7 +5126,7 @@ static void object_panel_cloth(Object *ob)
|
||||
uiBlockBeginAlign(block);
|
||||
|
||||
|
||||
uiDefButBitI(block, TOG, CLOTH_SIMSETTINGS_FLAG_GOAL, REDRAWVIEW3D, "Pinning of cloth", 10,70,150,20, &clmd->sim_parms->flags, 0, 0, 0, 0, "Define forces for vertices to stick to animated position");
|
||||
uiDefButBitI(block, TOG, CLOTH_SIMSETTINGS_FLAG_GOAL, B_CLOTH_RENEW, "Pinning of cloth", 10,70,150,20, &clmd->sim_parms->flags, 0, 0, 0, 0, "Define forces for vertices to stick to animated position");
|
||||
|
||||
if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) && (BLI_countlist (&ob->defbase) > 0))
|
||||
{
|
||||
@@ -5207,7 +5212,7 @@ static void object_panel_cloth_II(Object *ob)
|
||||
if(clmd)
|
||||
{
|
||||
uiDefButI(block, NUM, B_DIFF, "First Frame:", 10,160,150,20, &clmd->sim_parms->firstframe, 0, MAXFRAME, 1, 0, "Frame on which the simulation starts");
|
||||
uiDefButI(block, NUM, B_DIFF, "Last Frame:", 160,160,150,20, &clmd->sim_parms->lastframe, 0, MAXFRAME, 10, 0, "Frame on which the simulation stops");
|
||||
uiDefButI(block, NUM, B_DIFF, "Last Frame:", 160,160,150,20, &clmd->sim_parms->lastframe, 0, MAXFRAME, 1, 0, "Frame on which the simulation stops");
|
||||
|
||||
uiDefBut(block, LABEL, 0, "",10,140,300,20, NULL, 0.0, 0, 0, 0, "");
|
||||
|
||||
@@ -5234,11 +5239,11 @@ static void object_panel_cloth_II(Object *ob)
|
||||
uiDefBut(block, LABEL, 0, " ", 10,80,145,20, NULL, 0.0, 0, 0, 0, "");
|
||||
*/
|
||||
|
||||
uiDefButBitI(block, TOG, CLOTH_COLLSETTINGS_FLAG_ENABLED, REDRAWVIEW3D, "Enable collisions", 10,60,150,20, &clmd->coll_parms->flags, 0, 0, 0, 0, "Enable collisions with this object");
|
||||
uiDefButBitI(block, TOG, CLOTH_COLLSETTINGS_FLAG_ENABLED, B_CLOTH_RENEW, "Enable collisions", 10,60,150,20, &clmd->coll_parms->flags, 0, 0, 0, 0, "Enable collisions with this object");
|
||||
if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED)
|
||||
{
|
||||
uiDefButF(block, NUM, B_CLOTH_RENEW, "Min Distance:", 160,60,150,20, &clmd->coll_parms->epsilon, 0.001f, 1.0, 0.01f, 0, "Minimum distance between collision objects before collision response takes in");
|
||||
uiDefButS(block, NUM, REDRAWBUTSOBJECT, "Collision Quality:", 10,40,300,20, &clmd->coll_parms->loop_count, 1.0, 100.0, 1.0, 0, "How many collision iterations should be done. (higher = better = slower), je be changed for each frame");
|
||||
uiDefButF(block, NUM, REDRAWBUTSOBJECT, "Min Distance:", 160,60,150,20, &clmd->coll_parms->epsilon, 0.001f, 1.0, 0.01f, 0, "Minimum distance between collision objects before collision response takes in, can be changed for each frame");
|
||||
uiDefButS(block, NUM, REDRAWBUTSOBJECT, "Collision Quality:", 10,40,300,20, &clmd->coll_parms->loop_count, 1.0, 100.0, 1.0, 0, "How many collision iterations should be done. (higher = better = slower), can be changed for each frame");
|
||||
}
|
||||
else
|
||||
uiDefBut(block, LABEL, 0, "",160,60,150,20, NULL, 0.0, 0, 0, 0, "");
|
||||
@@ -5268,9 +5273,9 @@ static void object_panel_cloth_III(Object *ob)
|
||||
char clmvg [] = "Vertex Groups%t|None%x0|";
|
||||
char clmvg2 [] = "Vertex Groups%t|None%x0|";
|
||||
|
||||
uiDefButI(block, NUM, B_DIFF, "Autoprotect Cache From:",10,160,300,20, &clmd->sim_parms->autoprotect, 0, MAXFRAME, 1, 0, "Frame on which the simulation gets cache protection enabled automatically (To prevent accidently cleaning it).");
|
||||
uiDefButI(block, NUM, B_DIFF, "Autoprotect Cache From:",10,160,300,20, &clmd->sim_parms->autoprotect, 0.0, MAXFRAME + 1, 1, 0, "Frame on which the simulation gets cache protection enabled automatically (To prevent accidently cleaning it).");
|
||||
|
||||
uiDefButBitI(block, TOG, CLOTH_SIMSETTINGS_FLAG_SCALING, REDRAWVIEW3D, "Enable stiffness scaling",10,130,300,20, &clmd->sim_parms->flags, 0, 0, 0, 0, "If enabled, stiffness can be scaled along a weight painted vertex group.");
|
||||
uiDefButBitI(block, TOG, CLOTH_SIMSETTINGS_FLAG_SCALING, B_CLOTH_RENEW, "Enable stiffness scaling",10,130,300,20, &clmd->sim_parms->flags, 0, 0, 0, 0, "If enabled, stiffness can be scaled along a weight painted vertex group.");
|
||||
|
||||
if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING)&& (BLI_countlist (&ob->defbase) > 0))
|
||||
{
|
||||
|
||||
@@ -857,14 +857,16 @@ void make_editMesh()
|
||||
/* check if we have cache for this frame */
|
||||
int stack_index = modifiers_indexInObject(G.obedit, (ModifierData *)clmd);
|
||||
|
||||
if(BKE_ptcache_id_exist((ID *)G.obedit, (float) G.scene->r.cfra, stack_index))
|
||||
if(BKE_ptcache_id_exist((ID *)G.obedit, G.scene->r.cfra, stack_index))
|
||||
{
|
||||
cloth_enabled = 1;
|
||||
|
||||
clmd->sim_parms->editedframe = (float) G.scene->r.cfra;
|
||||
clmd->sim_parms->editedframe = G.scene->r.cfra;
|
||||
|
||||
/* inverse matrix is not uptodate... */
|
||||
Mat4Invert ( G.obedit->imat, G.obedit->obmat );
|
||||
|
||||
printf("make_editmesh --> cloth_enabled\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1014,6 +1016,8 @@ void load_editMesh(void)
|
||||
ClothModifierData *clmd = NULL;
|
||||
Cloth *cloth = NULL;
|
||||
float temp[3], dt = 0.0;
|
||||
|
||||
printf("loadmesh\n");
|
||||
|
||||
#ifdef WITH_VERSE
|
||||
if(em->vnode) {
|
||||
@@ -1102,6 +1106,7 @@ void load_editMesh(void)
|
||||
Mat4Invert ( G.obedit->imat, G.obedit->obmat );
|
||||
dt = 1.0f / clmd->sim_parms->stepsPerFrame;
|
||||
}
|
||||
printf("loadmesh --> tot: %d, num: %d\n", G.totvert, cloth->numverts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1110,6 +1115,7 @@ void load_editMesh(void)
|
||||
|
||||
if(cloth_enabled)
|
||||
{
|
||||
printf("loadmesh --> cloth_enabled\n");
|
||||
|
||||
VECCOPY(temp, cloth->verts[i].x);
|
||||
VECCOPY(cloth->verts[i].x, eve->co);
|
||||
@@ -1123,6 +1129,7 @@ void load_editMesh(void)
|
||||
*/
|
||||
if(oldverts) {
|
||||
VECCOPY(mvert->co, oldverts[i].co);
|
||||
printf("loadmesh --> cloth_enabled oldverts\n");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -1159,12 +1166,22 @@ void load_editMesh(void)
|
||||
/* burn changes to cache */
|
||||
if(cloth_enabled)
|
||||
{
|
||||
printf("loadmesh --> cloth_enabled cloth_write_cache\n");
|
||||
cloth_write_cache(G.obedit, clmd, clmd->sim_parms->editedframe);
|
||||
|
||||
/* in this case we have to get the data for the requested frame */
|
||||
if(clmd->sim_parms->editedframe != (float) G.scene->r.cfra)
|
||||
if(clmd->sim_parms->editedframe != G.scene->r.cfra)
|
||||
{
|
||||
cloth_read_cache(G.obedit, clmd, (float) G.scene->r.cfra);
|
||||
cloth_read_cache(G.obedit, clmd, G.scene->r.cfra);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(modifiers_isClothEnabled(G.obedit)) {
|
||||
ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(G.obedit, eModifierType_Cloth);
|
||||
printf("loadmesh --> CLOTH_SIMSETTINGS_FLAG_RESET\n");
|
||||
/* only reset cloth when no cache was used */
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_RESET;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1426,18 +1443,7 @@ void load_editMesh(void)
|
||||
if(me->id.us>1) {
|
||||
Base *base;
|
||||
for(base= G.scene->base.first; base; base= base->next) {
|
||||
if(base->object->data==me) {
|
||||
if(modifiers_isClothEnabled(base->object)) {
|
||||
ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(base->object, eModifierType_Cloth);
|
||||
|
||||
/* only reset cloth when no cache was used */
|
||||
if(!cloth_enabled)
|
||||
{
|
||||
clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_RESET;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(base->object->data==me) {
|
||||
base->object->softflag |= OB_SB_REDO;
|
||||
base->object->recalc |= OB_RECALC_DATA;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user