Revision: 16072
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16072
Author:   jaguarandi
Date:     2008-08-12 22:43:10 +0200 (Tue, 12 Aug 2008)

Log Message:
-----------

*Added documentation mainly at shrinkwrap.c

*removed commented code about the dropped shrinkwrap options
*Removed references to "cut plane", "limitMesh".. its now called "auxiliar 
target"

*Added option to shrinkwrap over an selected axis
*"Normal projection" mode is now called "projection" since it can now project 
over "normal, and any combination X, Y, Z"

Modified Paths:
--------------
    branches/soc-2008-jaguarandi/source/blender/blenkernel/BKE_shrinkwrap.h
    branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/constraint.c
    branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/modifier.c
    branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/shrinkwrap.c
    branches/soc-2008-jaguarandi/source/blender/makesdna/DNA_constraint_types.h
    branches/soc-2008-jaguarandi/source/blender/makesdna/DNA_modifier_types.h
    branches/soc-2008-jaguarandi/source/blender/src/buttons_editing.c
    branches/soc-2008-jaguarandi/source/blender/src/buttons_object.c

Modified: 
branches/soc-2008-jaguarandi/source/blender/blenkernel/BKE_shrinkwrap.h
===================================================================
--- branches/soc-2008-jaguarandi/source/blender/blenkernel/BKE_shrinkwrap.h     
2008-08-12 20:28:43 UTC (rev 16071)
+++ branches/soc-2008-jaguarandi/source/blender/blenkernel/BKE_shrinkwrap.h     
2008-08-12 20:43:10 UTC (rev 16072)
@@ -30,27 +30,36 @@
 #define BKE_SHRINKWRAP_H
 
 /* mesh util */
-//TODO move this somewhere else
+//TODO: move this somewhere else
 #include "BKE_customdata.h"
 struct DerivedMesh;
 struct Object;
 struct DerivedMesh *object_get_derived_final(struct Object *ob, CustomDataMask 
dataMask);
 
-/* bitset stuff */
-//TODO: should move this to other generic lib files?
-typedef char* BitSet;
-#define bitset_memsize(size)           (sizeof(char)*((size+7)>>3))
 
-#define bitset_new(size,name)          ((BitSet)MEM_callocN( 
bitset_memsize(size) , name))
-#define bitset_free(set)                       (MEM_freeN((void*)set))
-
-#define bitset_get(set,index)  ((set)[(index)>>3] & (1 << ((index)&0x7)))
-#define bitset_set(set,index)  ((set)[(index)>>3] |= (1 << ((index)&0x7)))
-#define bitset_unset(set,index)        ((set)[(index)>>3] &= ~(1 << 
((index)&0x7)))
-
-
 /* SpaceTransform stuff */
-//TODO: should move to other generic space?
+/*
+ * TODO: move this somewhere else
+ *
+ * this structs encapsulates all needed data to convert between 2 coordinate 
spaces
+ * (where conversion can be represented by a matrix multiplication)
+ *
+ * This is used to reduce the number of arguments to pass to functions that 
need to perform
+ * this kind of operation and make it easier for the coder, as he/she doenst 
needs to recode
+ * the matrix calculation.
+ *
+ * A SpaceTransform is initialized using:
+ *   space_transform_setup( &data,  ob1, ob2 )
+ *
+ * After that the following calls can be used:
+ *   space_transform_apply (&data, co); //converts a coordinate in ob1 coords 
space to the corresponding ob2 coords
+ *   space_transform_invert(&data, co); //converts a coordinate in ob2 coords 
space to the corresponding ob1 coords
+ *
+ *     //Same Concept as space_transform_apply and space_transform_invert, but 
no is normalized after conversion
+ *   space_transform_apply_normal (&data, &no);
+ *   space_transform_invert_normal(&data, &no);
+ *
+ */
 struct Object;
 
 typedef struct SpaceTransform
@@ -66,21 +75,30 @@
 void space_transform_apply (const SpaceTransform *data, float *co);
 void space_transform_invert(const SpaceTransform *data, float *co);
 
-void space_transform_apply_normal (const SpaceTransform *data, float *co);
-void space_transform_invert_normal(const SpaceTransform *data, float *co);
+void space_transform_apply_normal (const SpaceTransform *data, float *no);
+void space_transform_invert_normal(const SpaceTransform *data, float *no);
 
 /* Shrinkwrap stuff */
 #include "BKE_bvhutils.h"
 
+/*
+ * Shrinkwrap is composed by a set of functions and options that define the 
type of shrink.
+ *
+ * 3 modes are available:
+ *    - Nearest vertex
+ *       - Nearest surface
+ *    - Normal projection
+ *
+ * ShrinkwrapCalcData encapsulates all needed data for shrinkwrap functions.
+ * (So that you dont have to pass an enormous ammount of arguments to 
functions)
+ */
+
 struct Object;
 struct DerivedMesh;
 struct ShrinkwrapModifierData;
 struct BVHTree;
 
-/* maybe move to bvh util */
-int normal_projection_project_vertex(char options, const float *vert, const 
float *dir, const SpaceTransform *transf, BVHTree *tree, BVHTreeRayHit *hit, 
BVHTree_RayCastCallback callback, void *userdata);
 
-
 typedef struct ShrinkwrapCalcData
 {
        ShrinkwrapModifierData *smd;    //shrinkwrap modifier data
@@ -95,7 +113,6 @@
        SpaceTransform local2target;    //transform to move bettwem local and 
target space
 
        float keptDist;                                 //Distance to kept from 
target (units are in local space)
-       BitSet moved;                                   //BitSet indicating if 
vertex has moved
 
 } ShrinkwrapCalcData;
 
@@ -103,15 +120,27 @@
 void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *data);
 void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *data);
 
-struct DerivedMesh *shrinkwrapModifier_do(struct ShrinkwrapModifierData *smd, 
struct Object *ob, struct DerivedMesh *dm, int useRenderParams, int 
isFinalCalc);
 void shrinkwrapModifier_deform(struct ShrinkwrapModifierData *smd, struct 
Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3], int numVerts);
 
+/*
+ * This function casts a ray in the given BVHTree.. but it takes into 
consideration the space_transform, that is:
+ *
+ * if transf was configured with "space_transform_setup( &transf,  ob1, ob2 )"
+ * then the input (vert, dir, BVHTreeRayHit) must be defined in ob1 
coordinates space
+ * and the BVHTree must be built in ob2 coordinate space.
+ *
+ * Thus it provides an easy way to cast the same ray across several trees 
(where each tree was built on its own coords space)
+ */
+int normal_projection_project_vertex(char options, const float *vert, const 
float *dir, const SpaceTransform *transf, BVHTree *tree, BVHTreeRayHit *hit, 
BVHTree_RayCastCallback callback, void *userdata);
+
+/*
+ * NULL initializers to local data
+ */
 #define NULL_ShrinkwrapCalcData        {NULL, }
 #define NULL_BVHTreeFromMesh   {NULL, }
 #define NULL_BVHTreeRayHit             {NULL, }
-#define NULL_BVHTreeNearest            {NULL, }
+#define NULL_BVHTreeNearest            {0, }
 
 
 #endif
 
-

Modified: 
branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/constraint.c  
2008-08-12 20:28:43 UTC (rev 16071)
+++ branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/constraint.c  
2008-08-12 20:43:10 UTC (rev 16072)
@@ -3274,6 +3274,7 @@
 
        if( VALID_CONS_TARGET(ct) && (ct->tar->type == OB_MESH) )
        {
+               int fail = FALSE;
                float co[3] = {0.0f, 0.0f, 0.0f};
                float no[3] = {0.0f, 0.0f, 0.0f};
                float dist;
@@ -3295,59 +3296,73 @@
                hit.index = -1;
                hit.dist = 100000.0f;  //TODO should use FLT_MAX.. but normal 
projection doenst yet supports it
 
-               switch(scon->normalAxis)
-               {
-                       case UP_X: no[0] = 1.0f; break;
-                       case UP_Y: no[1] = 1.0f; break;
-                       case UP_Z: no[2] = 1.0f; break;
-               }
-
                if(target != NULL)
                {
 
                        space_transform_from_matrixs(&transform, cob->startmat, 
ct->tar->obmat);
 
-                       //Normal projection applies the transform later
-                       if(scon->shrinkType != MOD_SHRINKWRAP_NORMAL)
-                       {
-                               space_transform_apply(&transform, co);
-                               space_transform_apply_normal(&transform, no);
-                       }
-
                        switch(scon->shrinkType)
                        {
                                case MOD_SHRINKWRAP_NEAREST_SURFACE:
                                        bvhtree_from_mesh_faces(&treeData, 
target, 0.0, 2, 6);
-                                       if(treeData.tree == NULL) return;
+                                       if(treeData.tree == NULL)
+                                       {
+                                               fail = TRUE;
+                                               break;
+                                       }
 
+                                       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);
                                break;
 
                                case MOD_SHRINKWRAP_NEAREST_VERTEX:
                                        bvhtree_from_mesh_verts(&treeData, 
target, 0.0, 2, 6);
-                                       if(treeData.tree == NULL) return;
+                                       if(treeData.tree == NULL)
+                                       {
+                                               fail = TRUE;
+                                               break;
+                                       }
 
+                                       
space_transform_apply_normal(&transform, no);
+
                                        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;
 
-                               case MOD_SHRINKWRAP_NORMAL:
-                                       bvhtree_from_mesh_faces(&treeData, 
target, scon->dist, 4, 6);
-                                       if(treeData.tree == NULL) return;
+                               case MOD_SHRINKWRAP_PROJECT:
+                                       if(scon->projAxis & 
MOD_SHRINKWRAP_PROJECT_OVER_X_AXIS) no[0] = 1.0f;
+                                       if(scon->projAxis & 
MOD_SHRINKWRAP_PROJECT_OVER_Y_AXIS) no[1] = 1.0f;
+                                       if(scon->projAxis & 
MOD_SHRINKWRAP_PROJECT_OVER_Z_AXIS) no[2] = 1.0f;
 
-                                       if(normal_projection_project_vertex(0, 
co, no, &transform, treeData.tree, &hit, treeData.raycast_callback, &treeData) 
== FALSE)
+                                       if(INPR(no,no) < FLT_EPSILON)
                                        {
-                                               
free_bvhtree_from_mesh(&treeData);
+                                               fail = TRUE;
+                                               break;
+                                       }
 
-                                               target->release(target);
+                                       Normalize(no);
 
-                                               return;
+
+                                       bvhtree_from_mesh_faces(&treeData, 
target, scon->dist, 4, 6);
+                                       if(treeData.tree == NULL)
+                                       {
+                                               fail = TRUE;
+                                               break;
                                        }
+
+                                       if(normal_projection_project_vertex(0, 
co, no, &transform, treeData.tree, &hit, treeData.raycast_callback, &treeData) 
== FALSE)
+                                       {
+                                               fail = TRUE;
+                                               break;
+                                       }
                                        VECCOPY(co, hit.co);
                                break;
                        }
@@ -3356,11 +3371,8 @@
 
                        target->release(target);
 
-                       if(scon->shrinkType != MOD_SHRINKWRAP_NORMAL)
-                       {
-                               space_transform_invert(&transform, co);
-                       }
-                       VECADD(ct->matrix[3], ct->matrix[3], co);
+                       if(fail == FALSE)
+                               VECADD(ct->matrix[3], ct->matrix[3], co);
                }
        }
 }

Modified: 
branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/modifier.c
===================================================================
--- branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/modifier.c    
2008-08-12 20:28:43 UTC (rev 16071)
+++ branches/soc-2008-jaguarandi/source/blender/blenkernel/intern/modifier.c    
2008-08-12 20:43:10 UTC (rev 16072)
@@ -7230,11 +7230,11 @@
 {
        ShrinkwrapModifierData *smd = (ShrinkwrapModifierData*) md;
        smd->shrinkType = MOD_SHRINKWRAP_NEAREST_SURFACE;
-       smd->shrinkOpts = MOD_SHRINKWRAP_ALLOW_DEFAULT_NORMAL;
+       smd->shrinkOpts = MOD_SHRINKWRAP_PROJECT_ALLOW_POS_DIR;
        smd->keptDist   = 0.0f;
 
-       smd->target = 0;
-       smd->cutPlane = 0;
+       smd->target             = NULL;
+       smd->auxTarget  = NULL;
 }
 
 static void shrinkwrapModifier_copyData(ModifierData *md, ModifierData *target)
@@ -7242,12 +7242,14 @@
        ShrinkwrapModifierData *smd  = (ShrinkwrapModifierData*)md;
        ShrinkwrapModifierData *tsmd = (ShrinkwrapModifierData*)target;
 
-       tsmd->target = smd->target;
-       tsmd->cutPlane = smd->cutPlane;
+       tsmd->target    = smd->target;
+       tsmd->auxTarget = smd->auxTarget;
+
        strcpy(tsmd->vgroup_name, smd->vgroup_name);
-       tsmd->keptDist = smd->keptDist;
-       tsmd->shrinkType = smd->shrinkType;
-       tsmd->shrinkOpts = smd->shrinkOpts;
+
+       tsmd->keptDist  = smd->keptDist;
+       tsmd->shrinkType= smd->shrinkType;
+       tsmd->shrinkOpts= smd->shrinkOpts;
 }
 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to