BGE LibLoad: Allow the user to disable loading text datablocks if they want to attemp...
[blender.git] / source / gameengine / Converter / BL_DeformableGameObject.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file gameengine/Converter/BL_DeformableGameObject.cpp
29  *  \ingroup bgeconv
30  */
31
32
33 #include "BL_DeformableGameObject.h"
34 #include "BL_ShapeDeformer.h"
35 #include "BL_ShapeActionActuator.h"
36 #include "RAS_MaterialBucket.h"
37
38
39 BL_DeformableGameObject::~BL_DeformableGameObject()
40 {
41         if (m_pDeformer)
42                 delete m_pDeformer;             //      __NLA : Temporary until we decide where to put this
43 }
44
45 void BL_DeformableGameObject::ProcessReplica()
46 {
47         KX_GameObject::ProcessReplica();
48
49         if (m_pDeformer)
50                 m_pDeformer= (BL_MeshDeformer*)m_pDeformer->GetReplica();
51 }
52
53 CValue*         BL_DeformableGameObject::GetReplica()
54 {
55
56         BL_DeformableGameObject* replica = new BL_DeformableGameObject(*this);//m_float,GetName());
57         replica->ProcessReplica();
58         return replica;
59 }
60
61 bool BL_DeformableGameObject::SetActiveAction(BL_ShapeActionActuator *act, short priority, double curtime)
62 {
63         if (curtime != m_lastframe) {
64                 m_activePriority = 9999;
65                 m_lastframe= curtime;
66                 m_activeAct = NULL;
67         }
68
69         if (priority<=m_activePriority)
70         {
71                 if (m_activeAct && (m_activeAct!=act))
72                         m_activeAct->SetBlendTime(0.0f);        /* Reset the blend timer */
73                 m_activeAct = act;
74                 m_activePriority = priority;
75                 m_lastframe = curtime;
76         
77                 return true;
78         }
79         else {
80                 act->SetBlendTime(0.0f);
81                 return false;
82         }
83 }
84
85 bool BL_DeformableGameObject::GetShape(vector<float> &shape)
86 {
87         shape.clear();
88         BL_ShapeDeformer* shape_deformer = dynamic_cast<BL_ShapeDeformer*>(m_pDeformer);
89         if (shape_deformer)
90         {
91                 // this check is normally superfluous: a shape deformer can only be created if the mesh
92                 // has relative keys
93                 Key* key = shape_deformer->GetKey();
94                 if (key && key->type==KEY_RELATIVE) 
95                 {
96                         KeyBlock *kb;
97                         for (kb = (KeyBlock*)key->block.first; kb; kb = (KeyBlock*)kb->next)
98                         {
99                                 shape.push_back(kb->curval);
100                         }
101                 }
102         }
103         return !shape.empty();
104 }
105
106 void BL_DeformableGameObject::SetDeformer(class RAS_Deformer* deformer)
107 {
108         m_pDeformer = deformer;
109
110         SG_QList::iterator<RAS_MeshSlot> mit(m_meshSlots);
111         for (mit.begin(); !mit.end(); ++mit)
112         {
113                 (*mit)->SetDeformer(deformer);
114         }
115 }
116