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