[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12058] branches/cloth/blender/source/ blender: 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)
Daniel Genrich
daniel.genrich at gmx.net
Mon Sep 17 12:41:20 CEST 2007
Revision: 12058
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12058
Author: genscher
Date: 2007-09-17 12:41:20 +0200 (Mon, 17 Sep 2007)
Log Message:
-----------
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)
Modified Paths:
--------------
branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
branches/cloth/blender/source/blender/blenkernel/intern/collision.c
branches/cloth/blender/source/blender/blenkernel/intern/implicit.c
branches/cloth/blender/source/blender/blenkernel/intern/kdop.c
branches/cloth/blender/source/blender/src/buttons_object.c
Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2007-09-17 10:26:09 UTC (rev 12057)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2007-09-17 10:41:20 UTC (rev 12058)
@@ -444,6 +444,43 @@
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 @@
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 @@
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,7 +954,24 @@
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)
{
case OB_MESH:
Modified: branches/cloth/blender/source/blender/blenkernel/intern/collision.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/collision.c 2007-09-17 10:26:09 UTC (rev 12057)
+++ branches/cloth/blender/source/blender/blenkernel/intern/collision.c 2007-09-17 10:41:20 UTC (rev 12058)
@@ -403,7 +403,7 @@
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 @@
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 @@
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 @@
// 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
Modified: branches/cloth/blender/source/blender/blenkernel/intern/implicit.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/implicit.c 2007-09-17 10:26:09 UTC (rev 12057)
+++ branches/cloth/blender/source/blender/blenkernel/intern/implicit.c 2007-09-17 10:41:20 UTC (rev 12058)
@@ -89,7 +89,7 @@
// 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 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 @@
/* 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 @@
/* 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 @@
}
/* 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 @@
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 @@
}
// 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++)
Modified: branches/cloth/blender/source/blender/blenkernel/intern/kdop.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/kdop.c 2007-09-17 10:26:09 UTC (rev 12057)
+++ branches/cloth/blender/source/blender/blenkernel/intern/kdop.c 2007-09-17 10:41:20 UTC (rev 12058)
@@ -728,7 +728,7 @@
*/
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 @@
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 @@
if(collision_response)
collision_response (clmd, coll_clmd, tree1, tree2);
- return 1;
+ ret = 1;
}
else
{
@@ -767,14 +766,15 @@
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;
}
Modified: branches/cloth/blender/source/blender/src/buttons_object.c
===================================================================
--- branches/cloth/blender/source/blender/src/buttons_object.c 2007-09-17 10:26:09 UTC (rev 12057)
+++ branches/cloth/blender/source/blender/src/buttons_object.c 2007-09-17 10:41:20 UTC (rev 12058)
@@ -3231,8 +3231,8 @@
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)
{
More information about the Bf-blender-cvs
mailing list