4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
31 #pragma warning (disable : 4786)
34 #include "MEM_guardedalloc.h"
35 #include "BL_ShapeDeformer.h"
37 #include "STR_HashedString.h"
38 #include "RAS_IPolygonMaterial.h"
39 #include "BL_SkinMeshObject.h"
41 //#include "BL_ArmatureController.h"
42 #include "DNA_armature_types.h"
43 #include "DNA_action_types.h"
44 #include "DNA_key_types.h"
45 #include "DNA_mesh_types.h"
46 #include "DNA_meshdata_types.h"
47 #include "DNA_ipo_types.h"
48 #include "DNA_curve_types.h"
49 #include "BKE_armature.h"
50 #include "BKE_action.h"
53 #include "MT_Point3.h"
56 #include "BKE_lattice.h"
58 #include "BKE_utildefines.h"
60 #include "BLI_blenlib.h"
61 #include "BLI_arithb.h"
63 #define __NLA_DEFNORMALS
64 //#undef __NLA_DEFNORMALS
67 BL_ShapeDeformer::~BL_ShapeDeformer()
71 RAS_Deformer *BL_ShapeDeformer::GetReplica()
73 BL_ShapeDeformer *result;
75 result = new BL_ShapeDeformer(*this);
76 result->ProcessReplica();
80 void BL_ShapeDeformer::ProcessReplica()
82 BL_SkinDeformer::ProcessReplica();
83 m_lastShapeUpdate = -1;
86 bool BL_ShapeDeformer::LoadShapeDrivers(Object* arma)
90 m_shapeDrivers.clear();
91 // check if this mesh has armature driven shape keys
92 if (m_bmesh->key && m_bmesh->key->ipo) {
93 for(icu= (IpoCurve*)m_bmesh->key->ipo->curve.first; icu; icu= (IpoCurve*)icu->next) {
95 (icu->flag & IPO_MUTE) == 0 &&
96 icu->driver->type == IPO_DRIVER_TYPE_NORMAL &&
97 icu->driver->ob == arma &&
98 icu->driver->blocktype == ID_AR) {
99 // this shape key ipo curve has a driver on the parent armature
100 // record this curve in the shape deformer so that the corresponding
101 m_shapeDrivers.push_back(icu);
105 return !m_shapeDrivers.empty();
108 bool BL_ShapeDeformer::ExecuteShapeDrivers(void)
110 if (!m_shapeDrivers.empty() && PoseUpdated()) {
111 vector<IpoCurve*>::iterator it;
115 // the shape drivers use the bone matrix as input. Must
116 // update the matrix now
117 m_armobj->ApplyPose();
119 for (it=m_shapeDrivers.begin(); it!=m_shapeDrivers.end(); it++) {
120 // no need to set a specific time: this curve has a driver
121 // XXX IpoCurve *icu = *it;
122 //calc_icu(icu, 1.0f);
123 //poin = get_ipo_poin((ID*)m_bmesh->key, icu, &type);
125 // write_ipo_poin(poin, type, icu->curval);
129 m_armobj->RestorePose();
136 bool BL_ShapeDeformer::Update(void)
138 bool bShapeUpdate = false;
139 bool bSkinUpdate = false;
141 ExecuteShapeDrivers();
143 /* See if the object shape has changed */
144 if (m_lastShapeUpdate != m_gameobj->GetLastFrame()) {
145 /* the key coefficient have been set already, we just need to blend the keys */
146 Object* blendobj = m_gameobj->GetBlendObject();
148 // make sure the vertex weight cache is in line with this object
149 m_pMeshObject->CheckWeightCache(blendobj);
151 /* we will blend the key directly in mvert array: it is used by armature as the start position */
152 /* m_bmesh->key can be NULL in case of Modifier deformer */
154 do_rel_key(0, m_bmesh->totvert, m_bmesh->totvert, (char *)m_bmesh->mvert->co, m_bmesh->key, 0);
158 // Don't release the weight array as in Blender, it will most likely be reusable on next frame
159 // The weight array are ultimately deleted when the skin mesh is destroyed
161 /* Update the current frame */
162 m_lastShapeUpdate=m_gameobj->GetLastFrame();
164 // As we have changed, the mesh, the skin deformer must update as well.
165 // This will force the update
166 BL_SkinDeformer::ForceUpdate();
169 // check for armature deform
170 bSkinUpdate = BL_SkinDeformer::Update();
172 // non dynamic deformer = Modifer without armature and shape keys, no need to create storage
173 if (!bSkinUpdate && bShapeUpdate && m_bDynamic) {
174 // this means that there is no armature, we still need to copy the vertex to m_transverts
175 // and update the normal (was not done after shape key calculation)
177 /* store verts locally */
180 for (int v =0; v<m_bmesh->totvert; v++)
181 VECCOPY(m_transverts[v], m_bmesh->mvert[v].co);
183 #ifdef __NLA_DEFNORMALS