Skeleton.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  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 deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // 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 FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Math/BoundingBox.h"
  24. #include "../Scene/Node.h"
  25. namespace Atomic
  26. {
  27. static const unsigned BONECOLLISION_NONE = 0x0;
  28. static const unsigned BONECOLLISION_SPHERE = 0x1;
  29. static const unsigned BONECOLLISION_BOX = 0x2;
  30. class Deserializer;
  31. class ResourceCache;
  32. class Serializer;
  33. /// %Bone in a skeleton.
  34. struct Bone
  35. {
  36. /// Construct with defaults.
  37. Bone() :
  38. parentIndex_(0),
  39. initialPosition_(Vector3::ZERO),
  40. initialRotation_(Quaternion::IDENTITY),
  41. initialScale_(Vector3::ONE),
  42. animated_(true),
  43. collisionMask_(0),
  44. radius_(0.0f)
  45. {
  46. }
  47. /// Bone name.
  48. String name_;
  49. /// Bone name hash.
  50. StringHash nameHash_;
  51. /// Parent bone index.
  52. unsigned parentIndex_;
  53. /// Reset position.
  54. Vector3 initialPosition_;
  55. /// Reset rotation.
  56. Quaternion initialRotation_;
  57. /// Reset scale.
  58. Vector3 initialScale_;
  59. /// Offset matrix.
  60. Matrix3x4 offsetMatrix_;
  61. /// Animation enable flag.
  62. bool animated_;
  63. /// Supported collision types.
  64. unsigned char collisionMask_;
  65. /// Radius.
  66. float radius_;
  67. /// Local-space bounding box.
  68. BoundingBox boundingBox_;
  69. /// Scene node.
  70. WeakPtr<Node> node_;
  71. };
  72. /// Hierarchical collection of bones.
  73. class ATOMIC_API Skeleton
  74. {
  75. public:
  76. /// Construct an empty skeleton.
  77. Skeleton();
  78. /// Destruct.
  79. ~Skeleton();
  80. /// Read from a stream. Return true if successful.
  81. bool Load(Deserializer& source);
  82. /// Write to a stream. Return true if successful.
  83. bool Save(Serializer& dest) const;
  84. /// Define from another skeleton.
  85. void Define(const Skeleton& src);
  86. /// Set root bone's index.
  87. void SetRootBoneIndex(unsigned index);
  88. /// Clear bones.
  89. void ClearBones();
  90. /// Reset all animating bones to initial positions.
  91. void Reset();
  92. /// Return all bones.
  93. const Vector<Bone>& GetBones() const { return bones_; }
  94. /// Return modifiable bones.
  95. Vector<Bone>& GetModifiableBones() { return bones_; }
  96. /// Return number of bones.
  97. unsigned GetNumBones() const { return bones_.Size(); }
  98. /// Return root bone.
  99. Bone* GetRootBone();
  100. /// Return bone by index.
  101. Bone* GetBone(unsigned index);
  102. /// Return bone by name.
  103. Bone* GetBone(const String& boneName);
  104. /// Return bone by name.
  105. Bone* GetBone(const char* boneName);
  106. /// Return bone by name hash.
  107. Bone* GetBone(StringHash boneNameHash);
  108. /// Reset all animating bones to initial positions without marking the nodes dirty. Requires the node dirtying to be performed later.
  109. void ResetSilent();
  110. private:
  111. /// Bones.
  112. Vector<Bone> bones_;
  113. /// Root bone index.
  114. unsigned rootBoneIndex_;
  115. };
  116. }