Skeleton.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. /// Construct with defaults.
  36. Bone() :
  37. parentIndex_(0),
  38. collisionMask_(0),
  39. radius_(0.0f),
  40. initialPosition_(Vector3::ZERO),
  41. initialRotation_(Quaternion::IDENTITY),
  42. initialScale_(Vector3::ONE),
  43. animated_(true)
  44. {
  45. }
  46. /// Bone name.
  47. String name_;
  48. /// Bone name hash.
  49. StringHash nameHash_;
  50. /// Parent bone index.
  51. unsigned parentIndex_;
  52. /// Reset position.
  53. Vector3 initialPosition_;
  54. /// Reset rotation.
  55. Quaternion initialRotation_;
  56. /// Reset scale.
  57. Vector3 initialScale_;
  58. /// Offset matrix.
  59. Matrix3x4 offsetMatrix_;
  60. /// Animation enable flag.
  61. bool animated_;
  62. /// Supported collision types.
  63. unsigned char collisionMask_;
  64. /// Radius.
  65. float radius_;
  66. /// Bounding box.
  67. BoundingBox boundingBox_;
  68. /// Scene node.
  69. WeakPtr<Node> node_;
  70. };
  71. /// Hierarchical collection of bones.
  72. class Skeleton
  73. {
  74. public:
  75. /// Construct an empty skeleton.
  76. Skeleton();
  77. /// Destruct.
  78. ~Skeleton();
  79. /// Read from a stream. Return true if successful.
  80. bool Load(Deserializer& source);
  81. /// Write to a stream. Return true if successful.
  82. bool Save(Serializer& dest);
  83. /// Define from another skeleton.
  84. void Define(const Skeleton& src);
  85. /// Clear bones.
  86. void ClearBones();
  87. /// Reset all animating bones to initial positions.
  88. void Reset();
  89. /// Return all bones.
  90. const Vector<Bone>& GetBones() const { return bones_; }
  91. /// Return modifiable bones.
  92. Vector<Bone>& GetModifiableBones() { return bones_; }
  93. /// Return number of bones.
  94. unsigned GetNumBones() const { return bones_.Size(); }
  95. /// Return root bone.
  96. Bone* GetRootBone();
  97. /// Return bone by index.
  98. Bone* GetBone(unsigned index);
  99. /// Return bone by name.
  100. Bone* GetBone(const String& boneName);
  101. /// Return bone by name hash.
  102. Bone* GetBone(StringHash boneNameHash);
  103. private:
  104. /// Bones.
  105. Vector<Bone> bones_;
  106. /// Root bone index.
  107. unsigned rootBoneIndex_;
  108. };