BL_DeformableGameObject.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /** \file gameengine/Converter/BL_DeformableGameObject.cpp
  28. * \ingroup bgeconv
  29. */
  30. #include "BL_DeformableGameObject.h"
  31. #include "BL_ShapeDeformer.h"
  32. #include "BL_ShapeActionActuator.h"
  33. #include "RAS_MaterialBucket.h"
  34. BL_DeformableGameObject::~BL_DeformableGameObject()
  35. {
  36. if (m_pDeformer)
  37. delete m_pDeformer; // __NLA : Temporary until we decide where to put this
  38. }
  39. void BL_DeformableGameObject::ProcessReplica()
  40. {
  41. KX_GameObject::ProcessReplica();
  42. if (m_pDeformer)
  43. m_pDeformer= (BL_MeshDeformer*)m_pDeformer->GetReplica();
  44. }
  45. CValue* BL_DeformableGameObject::GetReplica()
  46. {
  47. BL_DeformableGameObject* replica = new BL_DeformableGameObject(*this);//m_float,GetName());
  48. replica->ProcessReplica();
  49. return replica;
  50. }
  51. bool BL_DeformableGameObject::SetActiveAction(BL_ShapeActionActuator *act, short priority, double curtime)
  52. {
  53. if (curtime != m_lastframe) {
  54. m_activePriority = 9999;
  55. m_lastframe= curtime;
  56. m_activeAct = NULL;
  57. }
  58. if (priority<=m_activePriority)
  59. {
  60. if (m_activeAct && (m_activeAct!=act))
  61. m_activeAct->SetBlendTime(0.0f); /* Reset the blend timer */
  62. m_activeAct = act;
  63. m_activePriority = priority;
  64. m_lastframe = curtime;
  65. return true;
  66. }
  67. else {
  68. act->SetBlendTime(0.0f);
  69. return false;
  70. }
  71. }
  72. bool BL_DeformableGameObject::GetShape(vector<float> &shape)
  73. {
  74. shape.clear();
  75. BL_ShapeDeformer* shape_deformer = dynamic_cast<BL_ShapeDeformer*>(m_pDeformer);
  76. if (shape_deformer)
  77. {
  78. // this check is normally superfluous: a shape deformer can only be created if the mesh
  79. // has relative keys
  80. Key* key = shape_deformer->GetKey();
  81. if (key && key->type==KEY_RELATIVE)
  82. {
  83. KeyBlock *kb;
  84. for (kb = (KeyBlock *)key->block.first; kb; kb = (KeyBlock *)kb->next)
  85. {
  86. shape.push_back(kb->curval);
  87. }
  88. }
  89. }
  90. return !shape.empty();
  91. }
  92. void BL_DeformableGameObject::SetDeformer(class RAS_Deformer* deformer)
  93. {
  94. m_pDeformer = deformer;
  95. SG_QList::iterator<RAS_MeshSlot> mit(m_meshSlots);
  96. for (mit.begin(); !mit.end(); ++mit)
  97. {
  98. (*mit)->SetDeformer(deformer);
  99. }
  100. }