[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28917] branches/hairsim: commit of working copy; note, will not compile, it uses an auto-differentiation library, but the one I tried is very slow, I need to plug in another one that' s faster and allows reusing the derivatives.
Joseph Eagar
joeedh at gmail.com
Sat May 22 13:55:17 CEST 2010
Revision: 28917
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28917
Author: joeedh
Date: 2010-05-22 13:55:17 +0200 (Sat, 22 May 2010)
Log Message:
-----------
commit of working copy; note, will not compile, it uses an auto-differentiation library, but the one I tried is very slow, I need to plug in another one that's faster and allows reusing the derivatives.
Modified Paths:
--------------
branches/hairsim/CMake/macros.cmake
branches/hairsim/CMakeLists.txt
branches/hairsim/source/blender/blenkernel/BKE_cloth.h
branches/hairsim/source/blender/blenkernel/CMakeLists.txt
branches/hairsim/source/blender/blenkernel/intern/cloth.c
branches/hairsim/source/blender/blenkernel/intern/collision.c
branches/hairsim/source/blender/blenkernel/intern/implicit.c
branches/hairsim/source/blender/blenlib/intern/math_vector_inline.c
branches/hairsim/source/blender/editors/interface/interface_widgets.c
branches/hairsim/source/blender/makesdna/DNA_modifier_types.h
branches/hairsim/source/blender/modifiers/intern/MOD_collision.c
Modified: branches/hairsim/CMake/macros.cmake
===================================================================
--- branches/hairsim/CMake/macros.cmake 2010-05-22 07:32:55 UTC (rev 28916)
+++ branches/hairsim/CMake/macros.cmake 2010-05-22 11:55:17 UTC (rev 28917)
@@ -45,6 +45,8 @@
LINK_DIRECTORIES(${JPEG_LIBPATH} ${PNG_LIBPATH} ${ZLIB_LIBPATH} ${FREETYPE_LIBPATH} ${LIBSAMPLERATE_LIBPATH})
+ LINK_DIRECTORIES(${CPPAD_LIBPATH})
+
IF(WITH_PYTHON)
LINK_DIRECTORIES(${PYTHON_LIBPATH})
ENDIF(WITH_PYTHON)
@@ -91,7 +93,7 @@
target)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS} ")
- TARGET_LINK_LIBRARIES(${target} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${JPEG_LIBRARY} ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} ${LLIBS})
+ TARGET_LINK_LIBRARIES(${target} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${JPEG_LIBRARY} ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} ${LLIBS} speed )
# since we are using the local libs for python when compiling msvc projects, we need to add _d when compiling debug versions
IF(WITH_PYTHON)
Modified: branches/hairsim/CMakeLists.txt
===================================================================
--- branches/hairsim/CMakeLists.txt 2010-05-22 07:32:55 UTC (rev 28916)
+++ branches/hairsim/CMakeLists.txt 2010-05-22 11:55:17 UTC (rev 28917)
@@ -172,7 +172,10 @@
# SET(PYTHON_BINARY ${PYTHON_EXECUTABLE} CACHE STRING "")
SET(PYTHON_LINKFLAGS "-Xlinker -export-dynamic")
-
+
+ SET(CPPAD_INCLUDE "/home/guest/include")
+ SET(CPPAD_LIBPATH "/home/guest/lib")
+
IF(WITH_SDL)
FIND_PACKAGE(SDL)
# UNSET(SDLMAIN_LIBRARY CACHE)
Modified: branches/hairsim/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- branches/hairsim/source/blender/blenkernel/BKE_cloth.h 2010-05-22 07:32:55 UTC (rev 28916)
+++ branches/hairsim/source/blender/blenkernel/BKE_cloth.h 2010-05-22 11:55:17 UTC (rev 28917)
@@ -173,6 +173,8 @@
/* these are for hair position-based multigrid solver */
struct ClothVertex *parents[2];
cdouble_t parentw[2];
+ cdouble_t txstart[3];
+ cdouble_t goal_velocity[3]; /*used to dampen forces from goal velocity*/
}
ClothVertex;
Modified: branches/hairsim/source/blender/blenkernel/CMakeLists.txt
===================================================================
--- branches/hairsim/source/blender/blenkernel/CMakeLists.txt 2010-05-22 07:32:55 UTC (rev 28916)
+++ branches/hairsim/source/blender/blenkernel/CMakeLists.txt 2010-05-22 11:55:17 UTC (rev 28917)
@@ -24,7 +24,7 @@
#
# ***** END GPL LICENSE BLOCK *****
-FILE(GLOB SRC intern/*.c)
+FILE(GLOB SRC intern/*.c intern/*.cpp)
SET(INC
. ../../../intern/guardedalloc ../../../intern/memutil ../editors/include ../blenlib ../makesdna ../modifiers
@@ -35,7 +35,7 @@
../../../intern/bsp/extern ../blenfont
../../../intern/audaspace/intern
../../../source/blender/windowmanager # XXX - BAD LEVEL CALL WM_api.h
- ${ZLIB_INC}
+ ${ZLIB_INC} ${CCPAD_INCLUDE}
)
Modified: branches/hairsim/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/hairsim/source/blender/blenkernel/intern/cloth.c 2010-05-22 07:32:55 UTC (rev 28916)
+++ branches/hairsim/source/blender/blenkernel/intern/cloth.c 2010-05-22 11:55:17 UTC (rev 28917)
@@ -249,11 +249,11 @@
v = cloth->verts;
for (i=0; i<cloth->numverts; i++, v++) {
- if (!BLI_ghash_haskey(gh, v) && !((v->flags&CLOTH_VERT_FLAG_PINNED) || v->goal == 1.0)) {
+ if (!BLI_ghash_haskey(gh, v)) {
float co[2][3];
if (!bvhspringtree)
- bvhspringtree = BLI_bvhtree_new(cloth->numverts, MAX2(epsilon, 0.01), 4, 26);
+ bvhspringtree = BLI_bvhtree_new(cloth->numverts*2, MAX2(epsilon, 0.01), 4, 26);
VECCOPY(co[0], v->txold);
VECCOPY(co[1], v->tx);
Modified: branches/hairsim/source/blender/blenkernel/intern/collision.c
===================================================================
--- branches/hairsim/source/blender/blenkernel/intern/collision.c 2010-05-22 07:32:55 UTC (rev 28916)
+++ branches/hairsim/source/blender/blenkernel/intern/collision.c 2010-05-22 11:55:17 UTC (rev 28917)
@@ -77,8 +77,6 @@
cdouble_t k, realk; /*stiffness of constraint, and current solver iteration stiffness*/
cdouble_t w, result;
cdouble_t grad[CMAXVERTS][3];
- cdouble_t dist[CMAXVERTS];
- cdouble_t no[3];
int type;
} Constraint;
@@ -89,8 +87,8 @@
ClothTri *colltri;
cdouble_t mat[4][4];
int flip;
- cdouble_t mindis;
- double friction;
+ cdouble_t mindis, no[3];
+ cdouble_t friction;
} PointConstraint;
@@ -105,14 +103,12 @@
static void springcon_eval(void *vself) {
SpringConstraint *scon = vself;
ClothVertex *v1 = scon->head.verts[0], *v2 = scon->head.verts[1];
- cdouble_t cent[3], vec[3], dis;
+ cdouble_t vec[3], dis;
- VECADD(cent, v1->tx, v2->tx);
- VECMULS(cent, 0.5);
- VECSUB(vec, v1->tx, cent);
+ VECSUB(vec, v1->tx, v2->tx);
dis = len_v3_d(vec);
- if (fabs(dis-scon->restlen) < DBL_EPSILON) {
+ if (fabs(dis-scon->restlen) <= DBL_EPSILON) {
scon->head.result = 0.0;
return;
}
@@ -122,15 +118,20 @@
return;
}
- scon->head.result = (scon->restlen - dis);
+ scon->head.result = (dis - scon->restlen);
- normalize_v3_d(vec);
+ mul_v3_d(vec, (1.0/dis));
- VECCOPY(scon->head.grad[0], vec);
- VECMULS(scon->head.grad[0], scon->head.result);
+ /*the idea is when you multiply grad with
+ result, you get a vector straight to
+ the position that satisfies the constraint.
+ in this particular case, normalized vec
+ works*/
+ copy_v3_v3_d(scon->head.grad[0], vec);
+ mul_v3_d(scon->head.grad[0], 1.0);
- VECCOPY(scon->head.grad[1], vec);
- VECMULS(scon->head.grad[1], -scon->head.result);
+ copy_v3_v3_d(scon->head.grad[1], vec);
+ mul_v3_d(scon->head.grad[1], -1.0);
}
SpringConstraint *make_spring_constraint(ClothVertex *v1, ClothVertex *v2, double restlen,
@@ -148,11 +149,15 @@
scon->head.type = CON_SPRING;
scon->head.eval = springcon_eval;
- scon->restlen = restlen*0.5; //(restlen*0.5)*(restlen*0.5); /*we pre-square this*/
+ scon->restlen = restlen;
return scon;
}
+void solve_bending_gradient(double ip1[3], double ip2[3], double ip3[3], double grad1[3],
+ double grad2[3], double grad3[3], double restangle);
+
+
static void eval_point_constraint(void *vcon) {
PointConstraint *con = vcon;
ClothVertex *v = con->head.verts[0];
@@ -182,8 +187,9 @@
add_v3_v3_d(v3, off);
/*we don't restrict to the triangle's bounds here, the whole plane is fine*/
+#if 1
if (isect_ray_tri_plane_v3_d(co2, no, v1, v2, v3, &lambda, uv)) {
- double lambda2;
+ double cdouble_t, g1[3], g2[3], g3[3], lambda2;
VECSUB(vel, v->txold, co2);
normalize_v3_d(vel);
@@ -195,29 +201,29 @@
VECADD2(no, vel);
lambda += (lambda2 - lambda)*con->friction;
- uv[0] += (uv2[0] - uv[0])*con->friction;
- uv[1] += (uv2[1] - uv[1])*con->friction;
}
+#endif
+ //cdouble_t g1[3], g2[3], g3[3];
- CLAMP(uv[0], 0.0, 1.0);
- CLAMP(uv[1], 0.0, 1.0);
+ sub_v3_v3v3_d(co2, v->tx, v1);
+ normalize_v3_d(co2);
+ normalize_v3_d(no);
- con->head.result = lambda;
+ lambda = dot_v3v3_d(co2, no);
- VECCOPY(con->head.grad[0], no);
- mul_v3_d(con->head.grad[0], lambda);
+ if (lambda >= 0.0) {
+ con->head.result = 0.0;
+ return;
+ }
- //uv[2] = 1.0 - uv[1] - uv[0];
- uv[0] = uv[1] = uv[2] = 0.0; //0.5;
- VECCOPY(con->head.grad[v1i], no);
- mul_v3_d(con->head.grad[v1i], -lambda*uv[0]);
+ add_v3_v3v3_d(co2, v1, no);
+ solve_bending_gradient(v->tx, v1, co2, g1, g2, g3, M_PI/2);
- VECCOPY(con->head.grad[v2i], no);
- mul_v3_d(con->head.grad[v2i], -lambda*uv[1]);
+ VECCOPY(con->head.grad[0], g1);
+ mul_v3_d(con->head.grad[0], 0.1);
- VECCOPY(con->head.grad[v3i], no);
- mul_v3_d(con->head.grad[v3i], -lambda*uv[2]);
-
+ con->head.result = fabs(saacos_d(lambda));
+ //}
return;
}
@@ -235,9 +241,6 @@
memset(con, 0, sizeof(*con));
con->head.verts[0] = point;
- con->head.verts[1] = colltri->verts[0];
- con->head.verts[2] = colltri->verts[1];
- con->head.verts[3] = colltri->verts[2];
con->v1 = colltri->verts[0];
con->v2 = colltri->verts[1];
@@ -248,8 +251,8 @@
VECCOPY(ov2, v2->txold);
VECCOPY(ov3, v3->txold);
- normal_tri_v3_d(con->head.no, ov1, ov2, ov3);
- VECCOPY(no, con->head.no);
+ normal_tri_v3_d(con->no, ov1, ov2, ov3);
+ VECCOPY(no, con->no);
con->head.type = CON_POINT;
con->head.k = 1.0;
@@ -264,7 +267,7 @@
VECSUB(off, oco, v1->txold);
normalize_v3_d(off);
if (dot_v3v3_d(off, no) < -DBL_EPSILON) {
- con->flip = 1;
+ //con->flip = 1;
}
return con;
@@ -289,22 +292,24 @@
static void eval_goal_constraint(void *vself)
{
GoalConstraint *self = vself;
- ClothVertex *v1 = self->v1, *v2 = self->head.verts[0];
- cdouble_t quat[4], vec1[3], vec2[3], vec5[3], nor[3], dot, l2;
+ ClothVertex *v1 = self->v1, *v2 = self->head.verts[0], *v3;
+ cdouble_t vec1[3], vec2[3], dot, l2;
+ cdouble_t g1[3], g2[3], g3[3];
+ if (!self->parent)
+ return;
+
+ v3 = self->head.verts[2];
+
/*calculate reference frame*/
sub_v3_v3v3_d(vec1, v2->txconst, v1->txconst);
sub_v3_v3v3_d(vec2, v2->tx, v1->tx);
- /*interpolate vec1->vec2 with k*/
- //sub_v3_v3v3_d(vec5, vec2, vec1);
- //mul_v3_d(vec5, pow(1.0 - self->head.k, 40));
- //add_v3_v3_d(vec1, vec5);
-
l2 = len_v3_d(vec2);
normalize_v3_d(vec1);
normalize_v3_d(vec2);
+#if 1
/*if we have a parent, rotate constrained goal vector
by parent frame*/
if (self->parent) {
@@ -316,11 +321,6 @@
sub_v3_v3v3_d(vec3, self->parent->head.verts[0]->txconst, self->parent->v1->txconst);
sub_v3_v3v3_d(vec4, self->parent->head.verts[0]->tx, self->parent->v1->tx);
- /*interpolate vec3->vec4 with k*/
- //sub_v3_v3v3_d(vec5, vec4, vec3);
- //mul_v3_d(vec5, 1.0 - self->head.k);
- //add_v3_v3_d(vec3, vec5);
-
normalize_v3_d(vec3);
normalize_v3_d(vec4);
@@ -335,7 +335,7 @@
cross_v3_v3v3_d(self->parent->nor, vec3, vec4);
normalize_v3_d(self->parent->nor);
- t = acos(t)*self->head.realk;
+ t = saacos_d(t)*0.5;
axis_angle_to_quat_d(self->parent->quat, self->parent->nor, t);
if (self->parent->parent) {
@@ -352,194 +352,148 @@
}
mul_qt_v3_d(self->parent->quat, vec1);
- self->parent->t = self->parent->coangular ? acos(t) : t;
} else {
unit_qt_d(self->quat);
}
+#endif
dot = dot_v3v3_d(vec1, vec2);
/*see if we are colinear, if so set frame to use a world axis as a tangent and
return*/
- if (dot <= -1.0 + DBL_EPSILON) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list