Skeleton.h 3.6 KB

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