Blender V2.61 - r43446

BL_DeformableGameObject.cpp

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) 2001-2002 by NaN Holding BV.
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 
00033 #include "BL_DeformableGameObject.h"
00034 #include "BL_ShapeDeformer.h"
00035 #include "BL_ShapeActionActuator.h"
00036 #include "RAS_MaterialBucket.h"
00037 
00038 
00039 BL_DeformableGameObject::~BL_DeformableGameObject()
00040 {
00041     if (m_pDeformer)
00042         delete m_pDeformer;     //  __NLA : Temporary until we decide where to put this
00043 }
00044 
00045 void BL_DeformableGameObject::ProcessReplica()
00046 {
00047     KX_GameObject::ProcessReplica();
00048 
00049     if (m_pDeformer)
00050         m_pDeformer= (BL_MeshDeformer*)m_pDeformer->GetReplica();
00051 }
00052 
00053 CValue*     BL_DeformableGameObject::GetReplica()
00054 {
00055 
00056     BL_DeformableGameObject* replica = new BL_DeformableGameObject(*this);//m_float,GetName());
00057     replica->ProcessReplica();
00058     return replica;
00059 }
00060 
00061 bool BL_DeformableGameObject::SetActiveAction(BL_ShapeActionActuator *act, short priority, double curtime)
00062 {
00063     if (curtime != m_lastframe){
00064         m_activePriority = 9999;
00065         m_lastframe= curtime;
00066         m_activeAct = NULL;
00067     }
00068 
00069     if (priority<=m_activePriority)
00070     {
00071         if (m_activeAct && (m_activeAct!=act))
00072             m_activeAct->SetBlendTime(0.0f);    /* Reset the blend timer */
00073         m_activeAct = act;
00074         m_activePriority = priority;
00075         m_lastframe = curtime;
00076     
00077         return true;
00078     }
00079     else{
00080         act->SetBlendTime(0.0f);
00081         return false;
00082     }
00083 }
00084 
00085 bool BL_DeformableGameObject::GetShape(vector<float> &shape)
00086 {
00087     shape.clear();
00088     BL_ShapeDeformer* shape_deformer = dynamic_cast<BL_ShapeDeformer*>(m_pDeformer);
00089     if (shape_deformer)
00090     {
00091         // this check is normally superfluous: a shape deformer can only be created if the mesh
00092         // has relative keys
00093         Key* key = shape_deformer->GetKey();
00094         if (key && key->type==KEY_RELATIVE) 
00095         {
00096             KeyBlock *kb;
00097             for (kb = (KeyBlock*)key->block.first; kb; kb = (KeyBlock*)kb->next)
00098             {
00099                 shape.push_back(kb->curval);
00100             }
00101         }
00102     }
00103     return !shape.empty();
00104 }
00105 
00106 void BL_DeformableGameObject::SetDeformer(class RAS_Deformer* deformer)
00107 {
00108     m_pDeformer = deformer;
00109 
00110     SG_QList::iterator<RAS_MeshSlot> mit(m_meshSlots);
00111     for(mit.begin(); !mit.end(); ++mit)
00112     {
00113         (*mit)->SetDeformer(deformer);
00114     }
00115 }
00116