Blender V2.61 - r43446

BKE_shrinkwrap.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 #ifndef BKE_SHRINKWRAP_H
00028 #define BKE_SHRINKWRAP_H
00029 
00034 /* mesh util */
00035 
00036 //TODO: move this somewhere else
00037 #include "BKE_customdata.h"
00038 struct DerivedMesh;
00039 struct Object;
00040 struct DerivedMesh *object_get_derived_final(struct Object *ob);
00041 
00042 
00043 /* SpaceTransform stuff */
00044 /*
00045  * TODO: move this somewhere else
00046  *
00047  * this structs encapsulates all needed data to convert between 2 coordinate spaces
00048  * (where conversion can be represented by a matrix multiplication)
00049  *
00050  * This is used to reduce the number of arguments to pass to functions that need to perform
00051  * this kind of operation and make it easier for the coder, as he/she doenst needs to recode
00052  * the matrix calculation.
00053  *
00054  * A SpaceTransform is initialized using:
00055  *   space_transform_setup( &data,  ob1, ob2 )
00056  *
00057  * After that the following calls can be used:
00058  *   space_transform_apply (&data, co); //converts a coordinate in ob1 coords space to the corresponding ob2 coords
00059  *   space_transform_invert(&data, co); //converts a coordinate in ob2 coords space to the corresponding ob1 coords
00060  *
00061  *  //Same Concept as space_transform_apply and space_transform_invert, but no is normalized after conversion
00062  *   space_transform_apply_normal (&data, &no);
00063  *   space_transform_invert_normal(&data, &no);
00064  *
00065  */
00066 struct Object;
00067 
00068 typedef struct SpaceTransform
00069 {
00070     float local2target[4][4];
00071     float target2local[4][4];
00072 
00073 } SpaceTransform;
00074 
00075 void space_transform_from_matrixs(struct SpaceTransform *data, float local[4][4], float target[4][4]);
00076 void space_transform_apply(const struct SpaceTransform *data, float *co);
00077 void space_transform_invert(const struct SpaceTransform *data, float *co);
00078 
00079 #define space_transform_setup(data, local, target) space_transform_from_matrixs(data, (local)->obmat, (target)->obmat)
00080 
00081 /* Shrinkwrap stuff */
00082 #include "BKE_bvhutils.h"
00083 
00084 /*
00085  * Shrinkwrap is composed by a set of functions and options that define the type of shrink.
00086  *
00087  * 3 modes are available:
00088  *    - Nearest vertex
00089  *    - Nearest surface
00090  *    - Normal projection
00091  *
00092  * ShrinkwrapCalcData encapsulates all needed data for shrinkwrap functions.
00093  * (So that you dont have to pass an enormous amount of arguments to functions)
00094  */
00095 
00096 struct Object;
00097 struct Scene;
00098 struct DerivedMesh;
00099 struct MVert;
00100 struct MDeformVert;
00101 struct ShrinkwrapModifierData;
00102 struct MDeformVert;
00103 struct BVHTree;
00104 
00105 
00106 typedef struct ShrinkwrapCalcData
00107 {
00108     ShrinkwrapModifierData *smd;    //shrinkwrap modifier data
00109 
00110     struct Object *ob;              //object we are applying shrinkwrap to
00111 
00112     struct MVert *vert;                 //Array of verts being projected (to fetch normals or other data)
00113     float (*vertexCos)[3];          //vertexs being shrinkwraped
00114     int numVerts;
00115 
00116     struct MDeformVert* dvert;          //Pointer to mdeform array
00117     int vgroup;                     //Vertex group num
00118 
00119     struct DerivedMesh *target;     //mesh we are shrinking to  
00120     SpaceTransform local2target;    //transform to move between local and target space
00121 
00122     float keepDist;                 //Distance to keep above target surface (units are in local space)
00123 
00124 } ShrinkwrapCalcData;
00125 
00126 void shrinkwrapModifier_deform(struct ShrinkwrapModifierData *smd, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3], int numVerts);
00127 
00128 /*
00129  * This function casts a ray in the given BVHTree.. but it takes into consideration the space_transform, that is:
00130  *
00131  * if transf was configured with "space_transform_setup( &transf,  ob1, ob2 )"
00132  * then the input (vert, dir, BVHTreeRayHit) must be defined in ob1 coordinates space
00133  * and the BVHTree must be built in ob2 coordinate space.
00134  *
00135  * Thus it provides an easy way to cast the same ray across several trees (where each tree was built on its own coords space)
00136  */
00137 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);
00138 
00139 /*
00140  * NULL initializers to local data
00141  */
00142 #define NULL_ShrinkwrapCalcData {NULL, }
00143 #define NULL_BVHTreeFromMesh    {NULL, }
00144 #define NULL_BVHTreeRayHit      {NULL, }
00145 #define NULL_BVHTreeNearest     {0, }
00146 
00147 
00148 #endif
00149