Browse Source

Use M_MAX_UNSIGNED instead of number of bones in Skeleton::GetBoneIndex. Add bindings.

Eugene Kozlov 8 years ago
parent
commit
91f56236b7

+ 3 - 0
Source/Urho3D/AngelScript/GraphicsAPI.cpp

@@ -145,6 +145,7 @@ static void RegisterSkeleton(asIScriptEngine* engine)
     engine->RegisterObjectBehaviour("Bone", asBEHAVE_ADDREF, "void f()", asFUNCTION(FakeAddRef), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectBehaviour("Bone", asBEHAVE_RELEASE, "void f()", asFUNCTION(FakeReleaseRef), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectProperty("Bone", "const String name", offsetof(Bone, name_));
+    engine->RegisterObjectProperty("Bone", "const uint parentIndex", offsetof(Bone, parentIndex_));
     engine->RegisterObjectProperty("Bone", "Vector3 initialPosition", offsetof(Bone, initialPosition_));
     engine->RegisterObjectProperty("Bone", "Quaternion initialRotation", offsetof(Bone, initialRotation_));
     engine->RegisterObjectProperty("Bone", "Vector3 initialScale", offsetof(Bone, initialScale_));
@@ -159,6 +160,8 @@ static void RegisterSkeleton(asIScriptEngine* engine)
     engine->RegisterObjectBehaviour("Skeleton", asBEHAVE_RELEASE, "void f()", asFUNCTION(FakeReleaseRef), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Skeleton", "void Reset()", asMETHOD(Skeleton, Reset), asCALL_THISCALL);
     engine->RegisterObjectMethod("Skeleton", "Bone@+ GetBone(const String&in) const", asMETHODPR(Skeleton, GetBone, (const String&), Bone*), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Skeleton", "uint GetBoneIndex(const String&in) const", asMETHODPR(Skeleton, GetBoneIndex, (const String&) const, unsigned), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Skeleton", "Bone@+ GetBoneParent(Bone@+) const", asMETHODPR(Skeleton, GetBoneParent, (const Bone*), Bone*), asCALL_THISCALL);
     engine->RegisterObjectMethod("Skeleton", "Bone@+ get_rootBone() const", asMETHOD(Skeleton, GetRootBone), asCALL_THISCALL);
     engine->RegisterObjectMethod("Skeleton", "uint get_numBones() const", asMETHOD(Skeleton, GetNumBones), asCALL_THISCALL);
     engine->RegisterObjectMethod("Skeleton", "Bone@+ get_bones(uint)", asMETHODPR(Skeleton, GetBone, (unsigned), Bone*), asCALL_THISCALL);

+ 7 - 2
Source/Urho3D/Graphics/Skeleton.cpp

@@ -161,17 +161,22 @@ unsigned Skeleton::GetBoneIndex(const StringHash& boneNameHash) const
             return i;
     }
 
-    return numBones;
+    return M_MAX_UNSIGNED;
 }
 
 unsigned Skeleton::GetBoneIndex(const Bone* bone) const
 {
     if (bones_.Empty() || bone < &bones_.Front() || bone > &bones_.Back())
-        return bones_.Size();
+        return M_MAX_UNSIGNED;
 
     return static_cast<unsigned>(bone - &bones_.Front());
 }
 
+unsigned Skeleton::GetBoneIndex(const String& boneName) const
+{
+    return GetBoneIndex(StringHash(boneName));
+}
+
 Bone* Skeleton::GetBoneParent(const Bone* bone)
 {
     if (GetBoneIndex(bone) == bone->parentIndex_)

+ 4 - 2
Source/Urho3D/Graphics/Skeleton.h

@@ -110,9 +110,11 @@ public:
 
     /// Return root bone.
     Bone* GetRootBone();
-    /// Return index of the bone by name hash. Return number of bones if not found.
+    /// Return index of the bone by name. Return M_MAX_UNSIGNED if not found.
+    unsigned GetBoneIndex(const String& boneName) const;
+    /// Return index of the bone by name hash. Return M_MAX_UNSIGNED if not found.
     unsigned GetBoneIndex(const StringHash& boneNameHash) const;
-    /// Return index of the bone by the bone pointer.
+    /// Return index of the bone by the bone pointer. Return M_MAX_UNSIGNED if not found.
     unsigned GetBoneIndex(const Bone* bone) const;
     /// Return parent of the given bone. Return null for root bones.
     Bone* GetBoneParent(const Bone* bone);

+ 5 - 2
Source/Urho3D/LuaScript/pkgs/Graphics/Skeleton.pkg

@@ -4,7 +4,7 @@ struct Bone
 {
     Bone();
     ~Bone();
-    
+
     String name_ @ name;
     StringHash nameHash_ @ nameHash;
     unsigned parentIndex_ @ parentIndex;
@@ -25,7 +25,10 @@ class Skeleton
     Bone* GetRootBone();
     Bone* GetBone(const String name);
     Bone* GetBone(unsigned index);
-    
+    unsigned GetBoneIndex(const String boneName) const;
+    unsigned GetBoneIndex(const Bone* bone) const;
+    Bone* GetBoneParent(const Bone* bone);
+
     tolua_readonly tolua_property__get_set unsigned numBones;
     tolua_readonly tolua_property__get_set Bone* rootBone;
 };