Browse Source

Fixed Billboard & Bone property set access.
Renamed animationEnabled_ in Bone to animated_.

Lasse Öörni 14 years ago
parent
commit
caa4017416

+ 11 - 0
Engine/Engine/APITemplates.h

@@ -39,6 +39,17 @@
 #include <cstring>
 #include <set>
 
+#define ACCESSORS(className, type, variableName, variable) \
+    void className ## Set ## variableName(const type& value, className* ptr) \
+    { \
+        ptr->variable = value; \
+    } \
+    \
+    const type& className ## Get ## variableName(className* ptr) \
+    { \
+        return ptr->variable; \
+    } \
+
 /// Template function for dynamic cast between two script classes
 template <class T, class U> U* RefCast(T* t)
 {

+ 30 - 8
Engine/Engine/GraphicsAPI.cpp

@@ -86,15 +86,28 @@ static Node* BoneGetNode(Bone* ptr)
     return ptr->node_;
 }
 
+// AngelScript complains "Reference is temporary" for non-primitive properties of reference types. Work around with set/get methods
+ACCESSORS(Bone, Vector3, InitialPosition, initialPosition_);
+ACCESSORS(Bone, Quaternion, InitialRotation, initialRotation_);
+ACCESSORS(Bone, Vector3, InitialScale, initialScale_);
+ACCESSORS(Bone, BoundingBox, BoundingBox, boundingBox_);
+
 static void RegisterSkeleton(asIScriptEngine* engine)
 {
     engine->RegisterObjectType("Bone", 0, asOBJ_REF);
     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", "bool animationEnabled", offsetof(Bone, animationEnabled_));
-    engine->RegisterObjectProperty("Bone", "const float radius", offsetof(Bone, radius_));
-    engine->RegisterObjectProperty("Bone", "const BoundingBox boundingBox", offsetof(Bone, boundingBox_));
+    engine->RegisterObjectMethod("Bone", "void set_initialPosition(const Vector3& in)", asFUNCTION(BoneSetInitialPosition), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Bone", "const Vector3& get_initialPosition() const", asFUNCTION(BoneGetInitialPosition), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Bone", "void set_initialRotation(const Quaternion& in)", asFUNCTION(BoneSetInitialRotation), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Bone", "const Quaternion& get_initialRotation() const", asFUNCTION(BoneGetInitialRotation), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Bone", "void set_initialScale(const Vector3& in)", asFUNCTION(BoneSetInitialScale), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Bone", "const Vector3& get_initialScale() const", asFUNCTION(BoneGetInitialScale), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectProperty("Bone", "bool animated", offsetof(Bone, animated_));
+    engine->RegisterObjectProperty("Bone", "float radius", offsetof(Bone, radius_));
+    engine->RegisterObjectMethod("Bone", "void set_boundingBox(const BoundingBox& in)", asFUNCTION(BoneSetBoundingBox), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Bone", "const BoundingBox& get_boundingBox() const", asFUNCTION(BoneGetBoundingBox), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Bone", "Node@+ get_node()", asFUNCTION(BoneGetNode), asCALL_CDECL_OBJLAST);
     
     engine->RegisterObjectType("Skeleton", 0, asOBJ_REF);
@@ -104,7 +117,7 @@ static void RegisterSkeleton(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Skeleton", "Bone@+ GetBone(const String& in) const", asMETHODPR(Skeleton, GetBone, (const std::string&), 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_bone(uint) const", asMETHODPR(Skeleton, GetBone, (unsigned), Bone*), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Skeleton", "Bone@+ get_bones(uint) const", asMETHODPR(Skeleton, GetBone, (unsigned), Bone*), asCALL_THISCALL);
 }
 
 static void ConstructViewport(Viewport* ptr)
@@ -646,15 +659,24 @@ static void RegisterAnimationController(asIScriptEngine* engine)
     engine->RegisterObjectMethod("AnimationController", "float GetFadeTarget(const String& in) const", asMETHOD(AnimationController, GetFadeTarget), asCALL_THISCALL);
 }
 
+ACCESSORS(Billboard, Vector3, Position, position_);
+ACCESSORS(Billboard, Vector2, Size, size_);
+ACCESSORS(Billboard, Rect, Uv, uv_);
+ACCESSORS(Billboard, Color, Color, color_);
+
 static void RegisterBillboardSet(asIScriptEngine* engine)
 {
     engine->RegisterObjectType("Billboard", 0, asOBJ_REF);
     engine->RegisterObjectBehaviour("Billboard", asBEHAVE_ADDREF, "void f()", asFUNCTION(FakeAddRef), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectBehaviour("Billboard", asBEHAVE_RELEASE, "void f()", asFUNCTION(FakeReleaseRef), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectProperty("Billboard", "Vector3 position", offsetof(Billboard, position_));
-    engine->RegisterObjectProperty("Billboard", "Vector2 size", offsetof(Billboard, size_));
-    engine->RegisterObjectProperty("Billboard", "Rect uv", offsetof(Billboard, uv_));
-    engine->RegisterObjectProperty("Billboard", "Color color", offsetof(Billboard, color_));
+    engine->RegisterObjectMethod("Billboard", "void set_position(const Vector3& in)", asFUNCTION(BillboardSetPosition), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Billboard", "const Vector3& get_position() const", asFUNCTION(BillboardGetPosition), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Billboard", "void set_size(const Vector2& in)", asFUNCTION(BillboardSetSize), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Billboard", "const Vector2& get_size() const", asFUNCTION(BillboardGetSize), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Billboard", "void set_uv(const Rect& in)", asFUNCTION(BillboardSetUv), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Billboard", "const Rect& get_uv() const", asFUNCTION(BillboardGetUv), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Billboard", "void set_color(const Color& in)", asFUNCTION(BillboardSetColor), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Billboard", "const Color& get_color() const", asFUNCTION(BillboardGetColor), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectProperty("Billboard", "float rotation", offsetof(Billboard, rotation_));
     engine->RegisterObjectProperty("Billboard", "bool enabled", offsetof(Billboard, enabled_));
     

+ 3 - 3
Engine/Graphics/AnimatedModel.cpp

@@ -86,7 +86,7 @@ void AnimatedModel::RegisterObject(Context* context)
     ATTRIBUTE(AnimatedModel, VAR_RESOURCEREFLIST, "Materials", materials_, ResourceRefList(Material::GetTypeStatic()));
     ATTRIBUTE(AnimatedModel, VAR_FLOAT, "Animation LOD Bias", animationLodBias_, 1.0f);
     ATTRIBUTE(AnimatedModel, VAR_INT, "Raycast/Occlusion LOD Level", softwareLodLevel_, M_MAX_UNSIGNED);
-    ATTRIBUTE(AnimatedModel, VAR_BUFFER, "Bone Animation Enabled", skeleton_, std::vector<unsigned char>());
+    ATTRIBUTE(AnimatedModel, VAR_BUFFER, "Bones Animated", skeleton_, std::vector<unsigned char>());
     ATTRIBUTE(AnimatedModel, VAR_BUFFER, "Animation States", animationStates_, std::vector<unsigned char>());
 }
 
@@ -115,7 +115,7 @@ void AnimatedModel::OnSetAttribute(const AttributeInfo& attr, const Variant& val
             std::vector<Bone>& bones = skeleton_.GetModifiableBones();
             unsigned numBones = buf.ReadVLE();
             for (unsigned i = 0; (i < numBones) && (i < bones.size()); ++i)
-                bones[i].animationEnabled_ = buf.ReadBool();
+                bones[i].animated_ = buf.ReadBool();
         }
         break;
         
@@ -166,7 +166,7 @@ Variant AnimatedModel::OnGetAttribute(const AttributeInfo& attr)
             const std::vector<Bone>& bones = skeleton_.GetBones();
             buf.WriteVLE(bones.size());
             for (std::vector<Bone>::const_iterator i = bones.begin(); i != bones.end(); ++i)
-                buf.WriteBool(i->animationEnabled_);
+                buf.WriteBool(i->animated_);
             return buf.GetBuffer();
         }
         

+ 2 - 2
Engine/Graphics/AnimationState.cpp

@@ -176,7 +176,7 @@ void AnimationState::Apply()
             const AnimationTrack* track = animation_->GetTrack(i->first);
             Bone* bone = i->second;
             Node* boneNode = bone->node_;
-            if ((!boneNode) || (!bone->animationEnabled_) || (!track->keyFrames_.size()))
+            if ((!boneNode) || (!bone->animated_) || (!track->keyFrames_.size()))
                 continue;
             
             unsigned& frame = lastKeyFrame_[i->first];
@@ -239,7 +239,7 @@ void AnimationState::Apply()
             const AnimationTrack* track = animation_->GetTrack(i->first);
             Bone* bone = i->second;
             Node* boneNode = bone->node_;
-            if ((!boneNode) || (!bone->animationEnabled_) || (!track->keyFrames_.size()))
+            if ((!boneNode) || (!bone->animated_) || (!track->keyFrames_.size()))
                 continue;
             
             unsigned& frame = lastKeyFrame_[i->first];

+ 1 - 1
Engine/Graphics/Skeleton.cpp

@@ -121,7 +121,7 @@ void Skeleton::Reset()
 {
     for (std::vector<Bone>::iterator i = bones_.begin(); i != bones_.end(); ++i)
     {
-        if ((i->animationEnabled_) && (i->node_))
+        if ((i->animated_) && (i->node_))
             i->node_->SetTransform(i->initialPosition_, i->initialRotation_, i->initialScale_);
     }
 }

+ 5 - 2
Engine/Graphics/Skeleton.h

@@ -41,7 +41,10 @@ struct Bone
         parentIndex_(0),
         collisionMask_(0),
         radius_(0.0f),
-        animationEnabled_(true)
+        initialPosition_(Vector3::ZERO),
+        initialRotation_(Quaternion::IDENTITY),
+        initialScale_(Vector3::UNITY),
+        animated_(true)
     {
     }
     
@@ -60,7 +63,7 @@ struct Bone
     /// Offset matrix
     Matrix4x3 offsetMatrix_;
     /// Animation enable flag
-    bool animationEnabled_;
+    bool animated_;
     /// Supported collision types
     unsigned char collisionMask_;
     /// Radius