[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12476] branches/cloth/blender/source/ blender: Implemented simple selfcollisions with use of OpenMP ( WITH_BF_OPENMP = 'true' - for NEW compilers like gcc 4.2.0 and MSVC prof)
Daniel Genrich
daniel.genrich at gmx.net
Sun Nov 4 22:02:37 CET 2007
Revision: 12476
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12476
Author: genscher
Date: 2007-11-04 22:02:37 +0100 (Sun, 04 Nov 2007)
Log Message:
-----------
Implemented simple selfcollisions with use of OpenMP (WITH_BF_OPENMP = 'true' - for NEW compilers like gcc 4.2.0 and MSVC prof)
Modified Paths:
--------------
branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h
branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
branches/cloth/blender/source/blender/blenkernel/intern/implicit.c
branches/cloth/blender/source/blender/blenkernel/intern/kdop.c
branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h
branches/cloth/blender/source/blender/src/buttons_object.c
Modified: branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h 2007-11-04 20:56:21 UTC (rev 12475)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_cloth.h 2007-11-04 21:02:37 UTC (rev 12476)
@@ -149,6 +149,7 @@
// only one available in the moment
typedef enum {
CM_IMPLICIT = 0,
+ CM_VERLET = 1,
} CM_SOLVER_ID;
Modified: branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h 2007-11-04 20:56:21 UTC (rev 12475)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_collisions.h 2007-11-04 21:02:37 UTC (rev 12476)
@@ -88,6 +88,8 @@
// forward declarations
/////////////////////////////////////////////////
+// NOTICE: mvert-routines for building + update the BVH are the most native ones
+
// builds bounding volume hierarchy
BVH *bvh_build_from_mvert (MFace *mfaces, unsigned int numfaces, MVert *x, unsigned int numverts, float epsilon);
BVH *bvh_build_from_float3 (MFace *mfaces, unsigned int numfaces, float (*x)[3], unsigned int numverts, float epsilon);
Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2007-11-04 20:56:21 UTC (rev 12475)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2007-11-04 21:02:37 UTC (rev 12476)
@@ -111,11 +111,11 @@
/* Our available solvers. */
// 255 is the magic reserved number, so NEVER try to put 255 solvers in here!
// 254 = MAX!
-static CM_SOLVER_DEF solvers [] =
- {
- { "Implicit", CM_IMPLICIT, implicit_init, implicit_solver, implicit_free },
- // { "Implicit C++", CM_IMPLICITCPP, implicitcpp_init, implicitcpp_solver, implicitcpp_free },
- };
+static CM_SOLVER_DEF solvers [] =
+{
+ { "Implicit", CM_IMPLICIT, implicit_init, implicit_solver, implicit_free },
+ // { "Implicit", CM_VERLET, verlet_init, verlet_solver, verlet_free },
+};
/* ********** cloth engine ******* */
/* Prototypes for internal functions.
@@ -158,7 +158,8 @@
clmd->coll_parms.self_friction = 5.0;
clmd->coll_parms.friction = 10.0;
clmd->coll_parms.loop_count = 1;
- clmd->coll_parms.epsilon = 0.01f;
+ clmd->coll_parms.epsilon = 0.01;
+ clmd->coll_parms.selfepsilon = 0.1;
/* These defaults are copied from softbody.c's
* softbody_calc_forces() function.
@@ -167,11 +168,11 @@
clmd->sim_parms.eff_wind_scale = 250.0;
// also from softbodies
- clmd->sim_parms.maxgoal = 1.0f;
- clmd->sim_parms.mingoal = 0.0f;
- clmd->sim_parms.defgoal = 0.7f;
- clmd->sim_parms.goalspring = 100.0f;
- clmd->sim_parms.goalfrict = 0.0f;
+ clmd->sim_parms.maxgoal = 1.0;
+ clmd->sim_parms.mingoal = 0.0;
+ clmd->sim_parms.defgoal = 0.7;
+ clmd->sim_parms.goalspring = 100.0;
+ clmd->sim_parms.goalfrict = 0.0;
clmd->sim_parms.cache = NULL;
}
@@ -519,6 +520,7 @@
memcpy ( clmd->clothObject->current_xold, frame->current_xold, sizeof ( float ) *frame->numverts * 3);
+ // TODO: temp off
implicit_set_positions ( clmd );
return;
@@ -621,32 +623,37 @@
if ( frame->time >= newtime )
{
+
if ( frame->verts )
{
MEM_freeN ( frame->verts );
}
+
if ( frame->x )
{
MEM_freeN ( frame->x );
}
+
if ( frame->xold )
{
MEM_freeN ( frame->xold );
}
+
if ( frame->v )
{
MEM_freeN ( frame->v );
}
+
if ( frame->current_xold )
{
MEM_freeN ( frame->current_xold );
}
+
MEM_freeN ( frame );
lastsearch->next = search->next;
MEM_freeN ( search );
search = lastsearch->next;
- lastsearch->next = NULL;
}
else
{
@@ -657,6 +664,7 @@
if ( time <= 1.0 )
{
+ BLI_linklist_free(clmd->sim_parms.cache, NULL);
clmd->sim_parms.cache = NULL;
}
@@ -852,7 +860,7 @@
// Free the faces.
if ( cloth->mfaces != NULL )
MEM_freeN ( cloth->mfaces );
-
+
// Free the verts.
if ( cloth->x != NULL )
MEM_freeN ( cloth->x );
@@ -860,7 +868,7 @@
// Free the verts.
if ( cloth->xold != NULL )
MEM_freeN ( cloth->xold );
-
+
// Free the verts.
if ( cloth->v != NULL )
MEM_freeN ( cloth->v );
@@ -876,7 +884,7 @@
// Free the verts.
if ( cloth->current_v != NULL )
MEM_freeN ( cloth->current_v );
-
+
cloth->verts = NULL;
cloth->numverts = -1;
@@ -902,6 +910,13 @@
if(cloth->tree)
bvh_free((BVH *)cloth->tree);
+ // free BVH self collision tree
+ if(cloth->selftree)
+ bvh_free((BVH *)cloth->selftree);
+
+ if(cloth->edgehash)
+ BLI_edgehash_free ( cloth->edgehash, NULL );
+
MEM_freeN (cloth);
clmd->clothObject = NULL;
}
@@ -1019,6 +1034,7 @@
if (clmd->clothObject)
{
clmd->clothObject->old_solver_type = 255;
+ clmd->clothObject->edgehash = NULL;
}
else if (clmd->clothObject == NULL)
{
@@ -1058,12 +1074,12 @@
if ( clmd->sim_parms.flags & CLOTH_SIMSETTINGS_FLAG_GOAL )
clmd->clothObject->verts [i].goal= clmd->sim_parms.defgoal;
else
- clmd->clothObject->verts [i].goal= 0.0f;
+ clmd->clothObject->verts [i].goal= 0.0;
clmd->clothObject->verts [i].flags = 0;
VECCOPY(clmd->clothObject->xold[i], clmd->clothObject->x[i]);
VECCOPY(clmd->clothObject->verts [i].xconst, clmd->clothObject->x[i]);
VECCOPY(clmd->clothObject->current_xold[i], clmd->clothObject->x[i]);
- VecMulf(clmd->clothObject->v[i], 0.0f);
+ VecMulf(clmd->clothObject->v[i], 0.0);
clmd->clothObject->verts [i].impulse_count = 0;
VECCOPY ( clmd->clothObject->verts [i].impulse, tnull );
@@ -1078,7 +1094,9 @@
solvers [clmd->sim_parms.solver_type].init (ob, clmd);
clmd->clothObject->tree = bvh_build_from_float3(CDDM_get_faces(dm), dm->getNumFaces(dm), clmd->clothObject->x, numverts, clmd->coll_parms.epsilon);
-
+
+ clmd->clothObject->selftree = bvh_build_from_float3(NULL, 0, clmd->clothObject->x, numverts, clmd->coll_parms.selfepsilon);
+
// cloth_cache_set_frame(clmd, 1);
}
@@ -1346,9 +1364,9 @@
}
if ( edgelist )
MEM_freeN ( edgelist );
+
+ cloth->edgehash = edgehash;
- BLI_edgehash_free ( edgehash, NULL );
-
return 1;
} /* cloth_build_springs */
Modified: branches/cloth/blender/source/blender/blenkernel/intern/implicit.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/implicit.c 2007-11-04 20:56:21 UTC (rev 12475)
+++ branches/cloth/blender/source/blender/blenkernel/intern/implicit.c 2007-11-04 21:02:37 UTC (rev 12476)
@@ -46,8 +46,9 @@
#include "DNA_lattice_types.h"
#include "DNA_scene_types.h"
#include "DNA_modifier_types.h"
+#include "BLI_arithb.h"
#include "BLI_blenlib.h"
-#include "BLI_arithb.h"
+#include "BLI_edgehash.h"
#include "BLI_threads.h"
#include "BKE_collisions.h"
#include "BKE_curve.h"
@@ -62,7 +63,6 @@
#include "BKE_global.h"
#include "BIF_editdeform.h"
-
#ifdef _WIN32
#include <windows.h>
static LARGE_INTEGER _itstart, _itend;
@@ -581,7 +581,7 @@
/* process off-diagonal entries (every off-diagonal entry needs to be symmetric) */
// TODO: pragma below is wrong, correct it!
-#pragma omp parallel for shared(to,from, fLongVector) private(i)
+// #pragma omp parallel for shared(to,from, fLongVector) private(i)
for(i = from[0].vcount; i < from[0].vcount+from[0].scount; i++)
{
unsigned int row = from[i].r;
@@ -593,7 +593,7 @@
to[column][1] += INPR(from[i].m[1],fLongVector[row]);
to[column][2] += INPR(from[i].m[2],fLongVector[row]);
}
-#pragma omp parallel for shared(to,from, fLongVector) private(i)
+// #pragma omp parallel for shared(to,from, fLongVector) private(i)
for(i = from[0].vcount; i < from[0].vcount+from[0].scount; i++)
{
unsigned int row = from[i].r;
@@ -1505,6 +1505,8 @@
// copy corrected positions back to simulation
if(result)
{
+ printf("result: %d\n", result);
+
memcpy(cloth->current_xold, cloth->current_x, sizeof(lfVector) * numverts);
memcpy(id->Xnew, cloth->current_x, sizeof(lfVector) * numverts);
@@ -1532,6 +1534,7 @@
cloth_calc_force(clmd, id->F, id->X, id->V, id->dFdV, id->dFdX, effectors, step);
simulate_implicit_euler(id->Vnew, id->X, id->V, id->F, id->dFdV, id->dFdX, dt / 2.0f, id->A, id->B, id->dV, id->S, id->z, id->olddV, id->P, id->Pinv);
}
+
}
else
{
@@ -1544,7 +1547,7 @@
// V = Vnew;
cp_lfvector(id->V, id->Vnew, numverts);
-
+
step += dt;
if(effectors) pdEndEffectors(effectors);
@@ -2171,8 +2174,9 @@
Object *ob2 = NULL;
BVH *bvh1 = NULL, *bvh2 = NULL;
LinkNode *collision_list = NULL;
- unsigned int i = 0;
- int collisions = 0;
+ unsigned int i = 0, j = 0;
+ int collisions = 0, count = 0;
+ float (*current_x)[3];
if (!(((Cloth *)clmd->clothObject)->tree))
{
@@ -2186,7 +2190,7 @@
////////////////////////////////////////////////////////////
// static collisions
////////////////////////////////////////////////////////////
-
+ /*
// update cloth bvh
bvh_update_from_float3(bvh1, cloth->current_xold, cloth->numverts, cloth->current_x, 0); // 0 means STATIC, 1 means MOVING (see later in this function)
@@ -2238,6 +2242,80 @@
VECADD(cloth->current_x[i], cloth->current_xold[i], cloth->current_v[i]);
}
//////////////////////////////////////////////
+ */
+ // Test on *simple* selfcollisions
+ collisions = 1;
+ count = 0;
+ current_x = cloth->current_x; // needed for openMP
- return collisions;
+#pragma omp parallel for private(i,j, collisions) shared(current_x)
+ for(count = 0; count < 6; count++)
+ {
+ collisions = 0;
+
+ for(i = 0; i < cloth->numverts; i++)
+ {
+ for(j = i + 1; j < cloth->numverts; j++)
+ {
+ float temp[3];
+ float length = 0;
+ float mindistance = cloth->selftree->epsilon;
+
+ if(clmd->sim_parms.flags & CLOTH_SIMSETTINGS_FLAG_GOAL)
+ {
+ if((cloth->verts [i].goal >= SOFTGOALSNAP)
+ && (cloth->verts [j].goal >= SOFTGOALSNAP))
+ {
+ continue;
+ }
+ }
+
+ // check for adjacent points
+ if(BLI_edgehash_haskey ( cloth->edgehash, i, j ))
+ {
+ continue;
+ }
+
+ VECSUB(temp, current_x[i], current_x[j]);
+
+ length = Normalize(temp);
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list