|
Blender
V2.59
|
00001 /* 00002 * $Id: BL_ShapeDeformer.cpp 36523 2011-05-06 20:18:42Z blendix $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00035 #if defined(WIN32) && !defined(FREE_WINDOWS) 00036 #pragma warning (disable : 4786) 00037 #endif //WIN32 00038 00039 #include "MEM_guardedalloc.h" 00040 #include "BL_ShapeDeformer.h" 00041 #include "CTR_Map.h" 00042 #include "STR_HashedString.h" 00043 #include "RAS_IPolygonMaterial.h" 00044 #include "RAS_MeshObject.h" 00045 00046 //#include "BL_ArmatureController.h" 00047 #include "DNA_armature_types.h" 00048 #include "DNA_action_types.h" 00049 #include "DNA_key_types.h" 00050 #include "DNA_mesh_types.h" 00051 #include "DNA_meshdata_types.h" 00052 #include "DNA_ipo_types.h" 00053 #include "DNA_curve_types.h" 00054 #include "BKE_armature.h" 00055 #include "BKE_action.h" 00056 #include "BKE_key.h" 00057 #include "BKE_ipo.h" 00058 #include "MT_Point3.h" 00059 00060 extern "C"{ 00061 #include "BKE_lattice.h" 00062 } 00063 00064 00065 #include "BLI_blenlib.h" 00066 #include "BLI_math.h" 00067 00068 #define __NLA_DEFNORMALS 00069 //#undef __NLA_DEFNORMALS 00070 00071 00072 BL_ShapeDeformer::~BL_ShapeDeformer() 00073 { 00074 }; 00075 00076 RAS_Deformer *BL_ShapeDeformer::GetReplica() 00077 { 00078 BL_ShapeDeformer *result; 00079 00080 result = new BL_ShapeDeformer(*this); 00081 result->ProcessReplica(); 00082 return result; 00083 } 00084 00085 void BL_ShapeDeformer::ProcessReplica() 00086 { 00087 BL_SkinDeformer::ProcessReplica(); 00088 m_lastShapeUpdate = -1; 00089 } 00090 00091 bool BL_ShapeDeformer::LoadShapeDrivers(Object* arma) 00092 { 00093 IpoCurve *icu; 00094 00095 m_shapeDrivers.clear(); 00096 // check if this mesh has armature driven shape keys 00097 if (m_bmesh->key && m_bmesh->key->ipo) { 00098 for(icu= (IpoCurve*)m_bmesh->key->ipo->curve.first; icu; icu= (IpoCurve*)icu->next) { 00099 if(icu->driver && 00100 (icu->flag & IPO_MUTE) == 0 && 00101 icu->driver->type == IPO_DRIVER_TYPE_NORMAL && 00102 icu->driver->ob == arma && 00103 icu->driver->blocktype == ID_AR) { 00104 // this shape key ipo curve has a driver on the parent armature 00105 // record this curve in the shape deformer so that the corresponding 00106 m_shapeDrivers.push_back(icu); 00107 } 00108 } 00109 } 00110 return !m_shapeDrivers.empty(); 00111 } 00112 00113 bool BL_ShapeDeformer::ExecuteShapeDrivers(void) 00114 { 00115 if (!m_shapeDrivers.empty() && PoseUpdated()) { 00116 vector<IpoCurve*>::iterator it; 00117 // void *poin; 00118 // int type; 00119 00120 // the shape drivers use the bone matrix as input. Must 00121 // update the matrix now 00122 m_armobj->ApplyPose(); 00123 00124 for (it=m_shapeDrivers.begin(); it!=m_shapeDrivers.end(); it++) { 00125 // no need to set a specific time: this curve has a driver 00126 // XXX IpoCurve *icu = *it; 00127 //calc_icu(icu, 1.0f); 00128 //poin = get_ipo_poin((ID*)m_bmesh->key, icu, &type); 00129 //if (poin) 00130 // write_ipo_poin(poin, type, icu->curval); 00131 } 00132 00133 ForceUpdate(); 00134 m_armobj->RestorePose(); 00135 m_bDynamic = true; 00136 return true; 00137 } 00138 return false; 00139 } 00140 00141 bool BL_ShapeDeformer::Update(void) 00142 { 00143 bool bShapeUpdate = false; 00144 bool bSkinUpdate = false; 00145 00146 ExecuteShapeDrivers(); 00147 00148 /* See if the object shape has changed */ 00149 if (m_lastShapeUpdate != m_gameobj->GetLastFrame()) { 00150 /* the key coefficient have been set already, we just need to blend the keys */ 00151 Object* blendobj = m_gameobj->GetBlendObject(); 00152 00153 // make sure the vertex weight cache is in line with this object 00154 m_pMeshObject->CheckWeightCache(blendobj); 00155 00156 /* we will blend the key directly in m_transverts array: it is used by armature as the start position */ 00157 /* m_bmesh->key can be NULL in case of Modifier deformer */ 00158 if (m_bmesh->key) { 00159 /* store verts locally */ 00160 VerifyStorage(); 00161 00162 do_rel_key(0, m_bmesh->totvert, m_bmesh->totvert, (char *)(float *)m_transverts, m_bmesh->key, NULL, 0); /* last arg is ignored */ 00163 m_bDynamic = true; 00164 } 00165 00166 // Don't release the weight array as in Blender, it will most likely be reusable on next frame 00167 // The weight array are ultimately deleted when the skin mesh is destroyed 00168 00169 /* Update the current frame */ 00170 m_lastShapeUpdate=m_gameobj->GetLastFrame(); 00171 00172 // As we have changed, the mesh, the skin deformer must update as well. 00173 // This will force the update 00174 BL_SkinDeformer::ForceUpdate(); 00175 bShapeUpdate = true; 00176 } 00177 // check for armature deform 00178 bSkinUpdate = BL_SkinDeformer::UpdateInternal(bShapeUpdate && m_bDynamic); 00179 00180 // non dynamic deformer = Modifer without armature and shape keys, no need to create storage 00181 if (!bSkinUpdate && bShapeUpdate && m_bDynamic) { 00182 // this means that there is no armature, we still need to 00183 // update the normal (was not done after shape key calculation) 00184 00185 #ifdef __NLA_DEFNORMALS 00186 if (m_recalcNormal) 00187 RecalcNormals(); 00188 #endif 00189 bSkinUpdate = true; 00190 } 00191 return bSkinUpdate; 00192 }