colladaAppSequence.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "ts/collada/colladaExtensions.h"
  24. #include "ts/collada/colladaAppSequence.h"
  25. ColladaAppSequence::ColladaAppSequence(const domAnimation_clip* clip)
  26. : pClip(clip), clipExt(new ColladaExtension_animation_clip(clip))
  27. {
  28. seqStart = pClip->getStart();
  29. seqEnd = pClip->getEnd();
  30. }
  31. ColladaAppSequence::~ColladaAppSequence()
  32. {
  33. delete clipExt;
  34. }
  35. const char* ColladaAppSequence::getName() const
  36. {
  37. return _GetNameOrId(pClip);
  38. }
  39. S32 ColladaAppSequence::getNumTriggers()
  40. {
  41. return clipExt->triggers.size();
  42. }
  43. void ColladaAppSequence::getTrigger(S32 index, TSShape::Trigger& trigger)
  44. {
  45. trigger.pos = clipExt->triggers[index].time;
  46. trigger.state = clipExt->triggers[index].state;
  47. }
  48. U32 ColladaAppSequence::getFlags() const
  49. {
  50. U32 flags = 0;
  51. if (clipExt->cyclic) flags |= TSShape::Cyclic;
  52. if (clipExt->blend) flags |= TSShape::Blend;
  53. return flags;
  54. }
  55. F32 ColladaAppSequence::getPriority()
  56. {
  57. return clipExt->priority;
  58. }
  59. F32 ColladaAppSequence::getBlendRefTime()
  60. {
  61. return clipExt->blendReferenceTime;
  62. }
  63. void ColladaAppSequence::setActive(bool active)
  64. {
  65. for (S32 iAnim = 0; iAnim < getClip()->getInstance_animation_array().getCount(); iAnim++) {
  66. domAnimation* anim = daeSafeCast<domAnimation>(getClip()->getInstance_animation_array()[iAnim]->getUrl().getElement());
  67. if (anim)
  68. setAnimationActive(anim, active);
  69. }
  70. }
  71. void ColladaAppSequence::setAnimationActive(const domAnimation* anim, bool active)
  72. {
  73. // Enabled/disable data channels for this animation
  74. for (S32 iChannel = 0; iChannel < anim->getChannel_array().getCount(); iChannel++) {
  75. domChannel* channel = anim->getChannel_array()[iChannel];
  76. AnimData* animData = reinterpret_cast<AnimData*>(channel->getUserData());
  77. if (animData)
  78. animData->enabled = active;
  79. }
  80. // Recurse into child animations
  81. for (S32 iAnim = 0; iAnim < anim->getAnimation_array().getCount(); iAnim++)
  82. setAnimationActive(anim->getAnimation_array()[iAnim], active);
  83. }