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