Fixed 2 crashers when activating collision object; Also put some additional openMP code in (doesn't hurt since #pragma gets ignored if no openMP available)
This commit is contained in:
@@ -444,6 +444,43 @@ int cloth_cache_search_frame(ClothModifierData *clmd, float time)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int cloth_cache_last_frame(ClothModifierData *clmd)
|
||||
{
|
||||
Frame *frame = NULL;
|
||||
LinkNode *search = NULL;
|
||||
int temptime = 0;
|
||||
|
||||
Cloth *cloth = NULL;
|
||||
|
||||
if(!clmd)
|
||||
return 0;
|
||||
|
||||
cloth = clmd->clothObject;
|
||||
|
||||
if(!cloth)
|
||||
return 0;
|
||||
|
||||
if(clmd->sim_parms.cache)
|
||||
{
|
||||
search = clmd->sim_parms.cache;
|
||||
|
||||
// check if frame exists
|
||||
while(search)
|
||||
{
|
||||
frame = search->link;
|
||||
|
||||
if(frame->time > temptime)
|
||||
{
|
||||
temptime = frame->time;
|
||||
}
|
||||
|
||||
search = search->next;
|
||||
}
|
||||
}
|
||||
|
||||
return temptime;
|
||||
}
|
||||
|
||||
void cloth_cache_get_frame(ClothModifierData *clmd, float time)
|
||||
{
|
||||
Frame *frame = NULL;
|
||||
@@ -622,8 +659,23 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
|
||||
float deltaTime = current_time - clmd->sim_parms.sim_time;
|
||||
|
||||
// only be active during a specific period
|
||||
if((current_time < clmd->sim_parms.firstframe)||(current_time > clmd->sim_parms.lastframe))
|
||||
if(current_time < clmd->sim_parms.firstframe)
|
||||
return;
|
||||
else if(current_time > clmd->sim_parms.lastframe)
|
||||
{
|
||||
int frametime = cloth_cache_last_frame(clmd);
|
||||
if(cloth_cache_search_frame(clmd, frametime))
|
||||
{
|
||||
cloth_cache_get_frame(clmd, frametime);
|
||||
cloth_to_object (ob, clmd, vertexCos, numverts);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if(ABS(deltaTime) >= 2.0f ) // no timewarps allowed
|
||||
{
|
||||
if(!cloth_cache_search_frame(clmd, framenr))
|
||||
return;
|
||||
}
|
||||
|
||||
// unused in the moment
|
||||
clmd->sim_parms.dt = 1.0f / clmd->sim_parms.stepsPerFrame;
|
||||
@@ -668,7 +720,7 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
|
||||
VECCOPY (verts->txold, verts->x);
|
||||
|
||||
// Get the current position.
|
||||
VECCOPY (verts->x, mvert[i].co);
|
||||
VECCOPY (verts->x, vertexCos[i]);
|
||||
Mat4MulVecfl(ob->obmat, verts->x);
|
||||
|
||||
// Compute the vertices velocity.
|
||||
@@ -902,6 +954,23 @@ static int collobj_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh
|
||||
unsigned int i;
|
||||
MVert *mvert = NULL;
|
||||
ClothVertex *verts = NULL;
|
||||
|
||||
/* 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 = -1;
|
||||
clmd->clothObject->old_collision_type = -1;
|
||||
}
|
||||
else if (clmd->clothObject == NULL)
|
||||
{
|
||||
modifier_setError (&(clmd->modifier), "Out of memory on allocating clmd->clothObject.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (ob->type)
|
||||
{
|
||||
|
||||
@@ -403,7 +403,7 @@ double implicit_tri_check_coherence (ClothModifierData *clmd, ClothModifierData
|
||||
VECCOPY(b[0], cloth2->verts[face2->v1].txold);
|
||||
VECCOPY(b[1], cloth2->verts[face2->v2].txold);
|
||||
VECCOPY(b[2], cloth2->verts[face2->v3].txold);
|
||||
|
||||
#pragma omp critical
|
||||
distance = plNearestPoints(a,b,pa,pb,normal);
|
||||
|
||||
quadA = quadB = 0;
|
||||
@@ -450,7 +450,7 @@ double implicit_tri_check_coherence (ClothModifierData *clmd, ClothModifierData
|
||||
VECCOPY(b[0], cloth2->verts[indexD].txold);
|
||||
VECCOPY(b[1], cloth2->verts[indexE].txold);
|
||||
VECCOPY(b[2], cloth2->verts[indexF].txold);
|
||||
|
||||
#pragma omp critical
|
||||
tempdistance = plNearestPoints(a,b,tpa,tpb,tnormal);
|
||||
|
||||
if(tempdistance < distance)
|
||||
@@ -483,7 +483,7 @@ void bvh_collision_response(ClothModifierData *clmd, ClothModifierData *coll_clm
|
||||
LinkNode **linknode;
|
||||
double distance = 0;
|
||||
float epsilon = clmd->coll_parms.epsilon;
|
||||
|
||||
|
||||
collpair = (CollPair *)MEM_callocN(sizeof(CollPair), "cloth coll pair");
|
||||
linknode = clmd->coll_parms.temp;
|
||||
|
||||
@@ -505,7 +505,6 @@ void bvh_collision_response(ClothModifierData *clmd, ClothModifierData *coll_clm
|
||||
// printf("normal x: %f, y: %f, z: %f\n", collpair->normal[0], collpair->normal[1], collpair->normal[2]);
|
||||
|
||||
collpair->distance = distance;
|
||||
|
||||
BLI_linklist_append(&linknode[tree1->tri_index], collpair);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -89,7 +89,7 @@ double itval()
|
||||
// intrinsics need better compile flag checking
|
||||
// #include <xmmintrin.h>
|
||||
// #include <pmmintrin.h>
|
||||
#include <pthread.h>
|
||||
// #include <pthread.h>
|
||||
|
||||
static struct timeval _itstart, _itend;
|
||||
static struct timezone itz;
|
||||
@@ -247,14 +247,9 @@ DO_INLINE void submul_lfvectorS(float (*to)[3], float (*fLongVector)[3], float s
|
||||
DO_INLINE float dot_lfvector(float (*fLongVectorA)[3], float (*fLongVectorB)[3], unsigned int verts)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
|
||||
#ifndef _WIN32
|
||||
float temp __attribute__ ((aligned (16) ) )= 0.0f; // __declspec(align(16))
|
||||
#else
|
||||
float temp = 0.0f;
|
||||
#endif
|
||||
|
||||
#pragma omp parallel for reduction(+: temp) schedule(guided, 1)
|
||||
float temp = 0.0;
|
||||
// schedule(guided, 2)
|
||||
#pragma omp parallel for reduction(+: temp)
|
||||
for(i = 0; i < verts; i++)
|
||||
{
|
||||
temp += INPR(fLongVectorA[i], fLongVectorB[i]);
|
||||
@@ -264,7 +259,6 @@ DO_INLINE float dot_lfvector(float (*fLongVectorA)[3], float (*fLongVectorB)[3],
|
||||
/* A = B + C --> for big vector */
|
||||
DO_INLINE void add_lfvector_lfvector(float (*to)[3], float (*fLongVectorA)[3], float (*fLongVectorB)[3], unsigned int verts)
|
||||
{
|
||||
|
||||
unsigned int i = 0;
|
||||
|
||||
for(i = 0; i < verts; i++)
|
||||
@@ -576,7 +570,7 @@ DO_INLINE void mul_bfmatrix_S(fmatrix3x3 *matrix, float scalar)
|
||||
/* STATUS: verified */
|
||||
DO_INLINE void mul_bfmatrix_lfvector( float (*to)[3], fmatrix3x3 *from, float (*fLongVector)[3])
|
||||
{
|
||||
unsigned int i = 0,j=0;
|
||||
int i = 0,j=0;
|
||||
zero_lfvector(to, from[0].vcount);
|
||||
/* process diagonal elements */
|
||||
for(i = 0; i < from[0].vcount; i++)
|
||||
@@ -585,12 +579,21 @@ DO_INLINE void mul_bfmatrix_lfvector( float (*to)[3], fmatrix3x3 *from, float (*
|
||||
}
|
||||
|
||||
/* process off-diagonal entries (every off-diagonal entry needs to be symmetric) */
|
||||
for(j = from[0].vcount; j < from[0].vcount+from[0].scount; j++)
|
||||
#pragma parallel for shared(to,from, fLongVector) private(i)
|
||||
for(i = from[0].vcount; i < from[0].vcount+from[0].scount; i++)
|
||||
{
|
||||
muladd_fmatrix_fvector(to[from[j].c], from[j].m, fLongVector[from[j].r]);
|
||||
muladd_fmatrix_fvector(to[from[j].r], from[j].m, fLongVector[from[j].c]);
|
||||
}
|
||||
|
||||
// muladd_fmatrix_fvector(to[from[i].c], from[i].m, fLongVector[from[i].r]);
|
||||
|
||||
to[from[i].c][0] += INPR(from[i].m[0],fLongVector[from[i].r]);
|
||||
to[from[i].c][1] += INPR(from[i].m[1],fLongVector[from[i].r]);
|
||||
to[from[i].c][2] += INPR(from[i].m[2],fLongVector[from[i].r]);
|
||||
|
||||
// muladd_fmatrix_fvector(to[from[i].r], from[i].m, fLongVector[from[i].c]);
|
||||
|
||||
to[from[i].r][0] += INPR(from[i].m[0],fLongVector[from[i].c]);
|
||||
to[from[i].r][1] += INPR(from[i].m[1],fLongVector[from[i].c]);
|
||||
to[from[i].r][2] += INPR(from[i].m[2],fLongVector[from[i].c]);
|
||||
}
|
||||
}
|
||||
/* SPARSE SYMMETRIC add big matrix with big matrix: A = B + C*/
|
||||
DO_INLINE void add_bfmatrix_bfmatrix( fmatrix3x3 *to, fmatrix3x3 *from, fmatrix3x3 *matrix)
|
||||
@@ -1195,12 +1198,13 @@ DO_INLINE void calc_spring_force(ClothModifierData *clmd, ClothSpring *s, lfVect
|
||||
|
||||
dfdx_spring_type1(dfdx, dir,length,L,k);
|
||||
|
||||
dfdv_damp(dfdv, dir,clmd->sim_parms.Cdis);
|
||||
dfdv_damp(dfdv, dir,clmd->sim_parms.Cdis);
|
||||
|
||||
sub_fmatrix_fmatrix(dFdV[s->ij].m, dFdV[s->ij].m, dfdv);
|
||||
sub_fmatrix_fmatrix(dFdV[s->kl].m, dFdV[s->kl].m, dfdv);
|
||||
|
||||
add_fmatrix_fmatrix(dFdV[s->matrix_index].m, dFdV[s->matrix_index].m, dfdv);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else // calculate force of bending springs
|
||||
@@ -1424,7 +1428,7 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase
|
||||
}
|
||||
|
||||
// call collision function
|
||||
// result = cloth_bvh_objcollision(clmd, step + dt, bvh_collision_response, dt);
|
||||
result = cloth_bvh_objcollision(clmd, step + dt, bvh_collision_response, dt);
|
||||
|
||||
// copy corrected positions back to simulation
|
||||
for(i = 0; i < numverts; i++)
|
||||
|
||||
@@ -728,7 +728,7 @@ DO_INLINE int bvh_overlap(float *bv1, float *bv2)
|
||||
*/
|
||||
int bvh_traverse(ClothModifierData * clmd, ClothModifierData * coll_clmd, Tree * tree1, Tree * tree2, float step, CM_COLLISION_RESPONSE collision_response)
|
||||
{
|
||||
int i = 0, ret=0;
|
||||
int i = 0, j = 0, ret=0;
|
||||
|
||||
/*
|
||||
// Shouldn't be possible
|
||||
@@ -737,8 +737,7 @@ int bvh_traverse(ClothModifierData * clmd, ClothModifierData * coll_clmd, Tree *
|
||||
printf("Error: no tree there\n");
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
*/
|
||||
if (bvh_overlap(tree1->bv, tree2->bv))
|
||||
{
|
||||
// Check if this node in the first tree is a leaf
|
||||
@@ -751,7 +750,7 @@ int bvh_traverse(ClothModifierData * clmd, ClothModifierData * coll_clmd, Tree *
|
||||
|
||||
if(collision_response)
|
||||
collision_response (clmd, coll_clmd, tree1, tree2);
|
||||
return 1;
|
||||
ret = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -767,14 +766,15 @@ int bvh_traverse(ClothModifierData * clmd, ClothModifierData * coll_clmd, Tree *
|
||||
else
|
||||
{
|
||||
// Process the quad tree.
|
||||
for (i = 0; i < 4; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
{
|
||||
// Only traverse nodes that exist.
|
||||
if (tree1->nodes [i] && bvh_traverse (clmd, coll_clmd, tree1->nodes[i], tree2, step, collision_response))
|
||||
if (tree1->nodes [j] && bvh_traverse (clmd, coll_clmd, tree1->nodes[j], tree2, step, collision_response))
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -3231,8 +3231,8 @@ static void object_panel_cloth_II(Object *ob)
|
||||
|
||||
uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
|
||||
|
||||
uiDefButI(block, NUM, B_CLOTH_RENEW, "First Frame:", 10,160,150,20, &clmd->sim_parms.firstframe, 0, MAXFRAME, 1, 0, "Frame on which the simulation starts");
|
||||
uiDefButI(block, NUM, B_CLOTH_RENEW, "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, "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");
|
||||
|
||||
if(clmd->sim_parms.cache)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user