Sfoglia il codice sorgente

Add Skeleton::GetBoneIndex and GetBoneParent helper functions. Add ValueAnimation::GetKeyFrames.

Eugene Kozlov 8 anni fa
parent
commit
2c5624f5ca

+ 31 - 8
Source/Urho3D/Graphics/Skeleton.cpp

@@ -152,6 +152,34 @@ Bone* Skeleton::GetRootBone()
     return GetBone(rootBoneIndex_);
 }
 
+unsigned Skeleton::GetBoneIndex(const StringHash& boneNameHash) const
+{
+    const unsigned numBones = bones_.Size();
+    for (unsigned i = 0; i < numBones; ++i)
+    {
+        if (bones_[i].nameHash_ == boneNameHash)
+            return i;
+    }
+
+    return numBones;
+}
+
+unsigned Skeleton::GetBoneIndex(const Bone* bone) const
+{
+    if (bones_.Empty() || bone < &bones_.Front() || bone > &bones_.Back())
+        return bones_.Size();
+
+    return static_cast<unsigned>(bone - &bones_.Front());
+}
+
+Bone* Skeleton::GetBoneParent(const Bone* bone)
+{
+    if (GetBoneIndex(bone) == bone->parentIndex_)
+        return nullptr;
+    else
+        return GetBone(bone->parentIndex_);
+}
+
 Bone* Skeleton::GetBone(unsigned index)
 {
     return index < bones_.Size() ? &bones_[index] : nullptr;
@@ -167,15 +195,10 @@ Bone* Skeleton::GetBone(const char* name)
     return GetBone(StringHash(name));
 }
 
-Bone* Skeleton::GetBone(StringHash nameHash)
+Bone* Skeleton::GetBone(const StringHash& boneNameHash)
 {
-    for (Vector<Bone>::Iterator i = bones_.Begin(); i != bones_.End(); ++i)
-    {
-        if (i->nameHash_ == nameHash)
-            return &(*i);
-    }
-
-    return nullptr;
+    const unsigned index = GetBoneIndex(boneNameHash);
+    return index < bones_.Size() ? &bones_[index] : nullptr;
 }
 
 }

+ 7 - 1
Source/Urho3D/Graphics/Skeleton.h

@@ -110,6 +110,12 @@ public:
 
     /// Return root bone.
     Bone* GetRootBone();
+    /// Return index of the bone by name hash. Return number of bones if not found.
+    unsigned GetBoneIndex(const StringHash& boneNameHash) const;
+    /// Return index of the bone by the bone pointer.
+    unsigned GetBoneIndex(const Bone* bone) const;
+    /// Return parent of the given bone. Return null for root bones.
+    Bone* GetBoneParent(const Bone* bone);
     /// Return bone by index.
     Bone* GetBone(unsigned index);
     /// Return bone by name.
@@ -117,7 +123,7 @@ public:
     /// Return bone by name.
     Bone* GetBone(const char* boneName);
     /// Return bone by name hash.
-    Bone* GetBone(StringHash boneNameHash);
+    Bone* GetBone(const StringHash& boneNameHash);
 
     /// Reset all animating bones to initial positions without marking the nodes dirty. Requires the node dirtying to be performed later.
     void ResetSilent();

+ 3 - 0
Source/Urho3D/Scene/ValueAnimation.h

@@ -126,6 +126,9 @@ public:
     /// Return animation value.
     Variant GetAnimationValue(float scaledTime) const;
 
+    /// Return all key frames.
+    const Vector<VAnimKeyFrame>& GetKeyFrames() const { return keyFrames_; }
+
     /// Has event frames.
     bool HasEventFrames() const { return !eventFrames_.Empty(); }