doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / gameengine / Converter / BL_DeformableGameObject.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
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.
10  *
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.
15  *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include "BL_DeformableGameObject.h"
31 #include "BL_ShapeDeformer.h"
32 #include "BL_ShapeActionActuator.h"
33 #include "RAS_MaterialBucket.h"
34
35
36 BL_DeformableGameObject::~BL_DeformableGameObject()
37 {
38         if (m_pDeformer)
39                 delete m_pDeformer;             //      __NLA : Temporary until we decide where to put this
40 }
41
42 void BL_DeformableGameObject::ProcessReplica()
43 {
44         KX_GameObject::ProcessReplica();
45
46         if (m_pDeformer)
47                 m_pDeformer= (BL_MeshDeformer*)m_pDeformer->GetReplica();
48 }
49
50 CValue*         BL_DeformableGameObject::GetReplica()
51 {
52
53         BL_DeformableGameObject* replica = new BL_DeformableGameObject(*this);//m_float,GetName());
54         replica->ProcessReplica();
55         return replica;
56 }
57
58 bool BL_DeformableGameObject::SetActiveAction(BL_ShapeActionActuator *act, short priority, double curtime)
59 {
60         if (curtime != m_lastframe){
61                 m_activePriority = 9999;
62                 m_lastframe= curtime;
63                 m_activeAct = NULL;
64         }
65
66         if (priority<=m_activePriority)
67         {
68                 if (m_activeAct && (m_activeAct!=act))
69                         m_activeAct->SetBlendTime(0.0f);        /* Reset the blend timer */
70                 m_activeAct = act;
71                 m_activePriority = priority;
72                 m_lastframe = curtime;
73         
74                 return true;
75         }
76         else{
77                 act->SetBlendTime(0.0f);
78                 return false;
79         }
80 }
81
82 bool BL_DeformableGameObject::GetShape(vector<float> &shape)
83 {
84         shape.clear();
85         if (m_pDeformer)
86         {
87                 Mesh* mesh = ((BL_MeshDeformer*)m_pDeformer)->GetMesh();
88                 // this check is normally superfluous: a shape deformer can only be created if the mesh
89                 // has relative keys
90                 if (mesh && mesh->key && mesh->key->type==KEY_RELATIVE) 
91                 {
92                         KeyBlock *kb;
93                         for (kb = (KeyBlock*)mesh->key->block.first; kb; kb = (KeyBlock*)kb->next)
94                         {
95                                 shape.push_back(kb->curval);
96                         }
97                 }
98         }
99         return !shape.empty();
100 }
101
102 void BL_DeformableGameObject::SetDeformer(class RAS_Deformer* deformer)
103 {
104         m_pDeformer = deformer;
105
106         SG_QList::iterator<RAS_MeshSlot> mit(m_meshSlots);
107         for(mit.begin(); !mit.end(); ++mit)
108         {
109                 (*mit)->SetDeformer(deformer);
110         }
111 }
112