Skeleton.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "BoundingBox.h"
  25. #include "Node.h"
  26. static const unsigned BONECOLLISION_NONE = 0x0;
  27. static const unsigned BONECOLLISION_SPHERE = 0x1;
  28. static const unsigned BONECOLLISION_BOX = 0x2;
  29. class Deserializer;
  30. class ResourceCache;
  31. class Serializer;
  32. /// Bone in a skeleton
  33. struct Bone
  34. {
  35. Bone() :
  36. parentIndex_(0),
  37. collisionMask_(0),
  38. radius_(0.0f),
  39. initialPosition_(Vector3::ZERO),
  40. initialRotation_(Quaternion::IDENTITY),
  41. initialScale_(Vector3::UNITY),
  42. animated_(true)
  43. {
  44. }
  45. /// Bone name
  46. String name_;
  47. /// Bone name hash
  48. StringHash nameHash_;
  49. /// Parent bone index
  50. unsigned parentIndex_;
  51. /// Reset position
  52. Vector3 initialPosition_;
  53. /// Reset rotation
  54. Quaternion initialRotation_;
  55. /// Reset scale
  56. Vector3 initialScale_;
  57. /// Offset matrix
  58. Matrix3x4 offsetMatrix_;
  59. /// Animation enable flag
  60. bool animated_;
  61. /// Supported collision types
  62. unsigned char collisionMask_;
  63. /// Radius
  64. float radius_;
  65. /// Bounding box
  66. BoundingBox boundingBox_;
  67. /// Scene node
  68. WeakPtr<Node> node_;
  69. };
  70. /// Hierarchical collection of bones
  71. class Skeleton
  72. {
  73. public:
  74. /// Construct an empty skeleton
  75. Skeleton();
  76. /// Destruct
  77. ~Skeleton();
  78. /// Read from a stream. Return true if successful
  79. bool Load(Deserializer& source);
  80. /// Write to a stream. Return true if successful
  81. bool Save(Serializer& dest);
  82. /// Define from another skeleton
  83. void Define(const Skeleton& src);
  84. /// Clear bones
  85. void ClearBones();
  86. /// Reset all animating bones to initial positions
  87. void Reset();
  88. /// Return all bones
  89. const Vector<Bone>& GetBones() const { return bones_; }
  90. /// Return modifiable bones
  91. Vector<Bone>& GetModifiableBones() { return bones_; }
  92. /// Return number of bones
  93. unsigned GetNumBones() const { return bones_.Size(); }
  94. /// Return root bone
  95. Bone* GetRootBone();
  96. /// Return bone by index
  97. Bone* GetBone(unsigned index);
  98. /// Return bone by name
  99. Bone* GetBone(const String& boneName);
  100. /// Return bone by name hash
  101. Bone* GetBone(StringHash boneNameHash);
  102. private:
  103. /// Bones
  104. Vector<Bone> bones_;
  105. /// Root bone index
  106. unsigned rootBoneIndex_;
  107. };