diff options
author | Andre Susano Pinto <andresusanopinto@gmail.com> | 2008-09-23 02:48:44 +0400 |
---|---|---|
committer | Andre Susano Pinto <andresusanopinto@gmail.com> | 2008-09-23 02:48:44 +0400 |
commit | 2911df487ede413fb6b83b2de199f50657cc5cfe (patch) | |
tree | b97b48c050999f1e1060d22c48ff9cb4e4c9c1bf /source/blender | |
parent | 656ee61718d85f9366115756ba28e4b53f36d6b2 (diff) |
Fixed shrinkwrap constraint handling of matrixs.
Also since contraint uses BVHCache its now usable and fast.
Being possible to shrinkwrap constraint several objects to another
and only have one BVHTree being build.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 49 |
1 files changed, 20 insertions, 29 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index db173126375..6e94fc255ac 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -3263,9 +3263,6 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr { bShrinkwrapConstraint *scon = (bShrinkwrapConstraint *) con->data; - if (ct) - Mat4CpyMat4(ct->matrix, cob->startmat); - if( VALID_CONS_TARGET(ct) && (ct->tar->type == OB_MESH) ) { int fail = FALSE; @@ -3274,13 +3271,10 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr float dist; SpaceTransform transform; - DerivedMesh *target = CDDM_copy( object_get_derived_final(ct->tar, CD_MASK_BAREMESH) ); + DerivedMesh *target = object_get_derived_final(ct->tar, CD_MASK_BAREMESH); BVHTreeRayHit hit; BVHTreeNearest nearest; - //TODO - //Its stupid to create a bvhtree.. if we are only going to project one vertex - //But lets do it this way.. (so that in future maybe bvhtree gets a cache system and then the tree would already be build) BVHTreeFromMesh treeData; memset( &treeData, 0, sizeof(treeData) ); @@ -3290,42 +3284,32 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr hit.index = -1; hit.dist = 100000.0f; //TODO should use FLT_MAX.. but normal projection doenst yet supports it + Mat4One(ct->matrix); + if(target != NULL) { - - space_transform_from_matrixs(&transform, cob->startmat, ct->tar->obmat); + space_transform_from_matrixs(&transform, cob->matrix, ct->tar->obmat); switch(scon->shrinkType) { case MOD_SHRINKWRAP_NEAREST_SURFACE: - bvhtree_from_mesh_faces(&treeData, target, 0.0, 2, 6); - if(treeData.tree == NULL) - { - fail = TRUE; - break; - } - - space_transform_apply(&transform, co); + case MOD_SHRINKWRAP_NEAREST_VERTEX: - BLI_bvhtree_find_nearest(treeData.tree, co, &nearest, treeData.nearest_callback, &treeData); - - dist = VecLenf(co, nearest.co); - VecLerpf(co, co, nearest.co, (dist - scon->dist)/dist); //linear interpolation - space_transform_invert(&transform, co); - break; + if(scon->shrinkType == MOD_SHRINKWRAP_NEAREST_VERTEX) + bvhtree_from_mesh_verts(&treeData, target, 0.0, 2, 6); + else + bvhtree_from_mesh_faces(&treeData, target, 0.0, 2, 6); - case MOD_SHRINKWRAP_NEAREST_VERTEX: - bvhtree_from_mesh_verts(&treeData, target, 0.0, 2, 6); if(treeData.tree == NULL) { fail = TRUE; break; } - space_transform_apply_normal(&transform, no); + space_transform_apply(&transform, co); BLI_bvhtree_find_nearest(treeData.tree, co, &nearest, treeData.nearest_callback, &treeData); - + dist = VecLenf(co, nearest.co); VecLerpf(co, co, nearest.co, (dist - scon->dist)/dist); //linear interpolation space_transform_invert(&transform, co); @@ -3365,8 +3349,15 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr target->release(target); - if(fail == FALSE) - VECADD(ct->matrix[3], ct->matrix[3], co); + if(fail == TRUE) + { + //Don't move the point + co[0] = co[1] = co[2] = 0.0f; + } + + //co is in local object coordinates, change it to global and update target position + VecMat4MulVecfl(co, cob->matrix, co); + VECCOPY(ct->matrix[3], co); } } } |