Browse Source

In AssetImporter, set default tickrate 4800 for animations that do not define a tickrate. This can also be configured from the command line.
Prevent bones with no skinned geometry (ie. dummies) affecting the animated model's bounding box.

Lasse Öörni 14 years ago
parent
commit
4311f615ac
2 changed files with 22 additions and 2 deletions
  1. 11 1
      Engine/Graphics/AnimatedModel.cpp
  2. 11 1
      Tools/AssetImporter/AssetImporter.cpp

+ 11 - 1
Engine/Graphics/AnimatedModel.cpp

@@ -607,10 +607,20 @@ void AnimatedModel::SetSkeleton(const Skeleton& skeleton, bool createBones)
         
         
         skeleton_.Define(skeleton);
         skeleton_.Define(skeleton);
         
         
+        // Remove collision information from dummy bones that do not affect skinning, to prevent them from being merged
+        // to the bounding box
+        Vector<Bone>& bones = skeleton_.GetModifiableBones();
+        for (Vector<Bone>::Iterator i = bones.Begin(); i != bones.End(); ++i)
+        {
+            if (i->collisionMask_ & BONECOLLISION_BOX && i->boundingBox_.Size().Length() < M_EPSILON)
+                i->collisionMask_ &= ~BONECOLLISION_BOX;
+            if (i->collisionMask_ & BONECOLLISION_SPHERE && i->radius_ < M_EPSILON)
+                i->collisionMask_ &= ~BONECOLLISION_SPHERE;
+        }
+        
         // Create scene nodes for the bones
         // Create scene nodes for the bones
         if (createBones)
         if (createBones)
         {
         {
-            Vector<Bone>& bones = skeleton_.GetModifiableBones();
             for (Vector<Bone>::Iterator i = bones.Begin(); i != bones.End(); ++i)
             for (Vector<Bone>::Iterator i = bones.Begin(); i != bones.End(); ++i)
             {
             {
                 // Create bones as local, as they are never to be directly synchronized over the network
                 // Create bones as local, as they are never to be directly synchronized over the network

+ 11 - 1
Tools/AssetImporter/AssetImporter.cpp

@@ -109,6 +109,7 @@ bool localIDs_ = false;
 bool saveBinary_ = false;
 bool saveBinary_ = false;
 bool createZone_ = true;
 bool createZone_ = true;
 bool noAnimations_ = false;
 bool noAnimations_ = false;
+float defaultTicksPerSecond_ = 4800.0f;
 
 
 int main(int argc, char** argv);
 int main(int argc, char** argv);
 void Run(const Vector<String>& arguments);
 void Run(const Vector<String>& arguments);
@@ -196,6 +197,7 @@ void Run(const Vector<String>& arguments)
             "-nz   Do not create a zone and a directional light (scene mode only)\n"
             "-nz   Do not create a zone and a directional light (scene mode only)\n"
             "-pX   Set path X for scene resources. Default is output file path\n"
             "-pX   Set path X for scene resources. Default is output file path\n"
             "-rX   Use scene node X as root node\n"
             "-rX   Use scene node X as root node\n"
+            "-fX   Animation tick frequency to use if unspecified. Default 4800\n"
             "-t    Generate tangents to model(s)\n"
             "-t    Generate tangents to model(s)\n"
         );
         );
     }
     }
@@ -257,6 +259,10 @@ void Run(const Vector<String>& arguments)
                 flags |= aiProcess_CalcTangentSpace;
                 flags |= aiProcess_CalcTangentSpace;
                 break;
                 break;
                 
                 
+            case 'f':
+                defaultTicksPerSecond_ = ToFloat(parameter);
+                break;
+                
             case 'n':
             case 'n':
                 if (!parameter.Empty())
                 if (!parameter.Empty())
                 {
                 {
@@ -883,7 +889,11 @@ void BuildAndSaveAnimations(OutModel& model)
         String animOutName = GetPath(model.outName_) + GetFileName(model.outName_) + "_" + SanitateAssetName(animName) + ".ani";
         String animOutName = GetPath(model.outName_) + GetFileName(model.outName_) + "_" + SanitateAssetName(animName) + ".ani";
         
         
         SharedPtr<Animation> outAnim(new Animation(context_));
         SharedPtr<Animation> outAnim(new Animation(context_));
-        float tickConversion = 1.0f / (float)anim->mTicksPerSecond;
+        float ticksPerSecond = (float)anim->mTicksPerSecond;
+        // If ticks per second not specified, it's probably a .X file. In this case use the default tick rate
+        if (ticksPerSecond < M_EPSILON)
+            ticksPerSecond = defaultTicksPerSecond_;
+        float tickConversion = 1.0f / ticksPerSecond;
         outAnim->SetAnimationName(animName);
         outAnim->SetAnimationName(animName);
         outAnim->SetLength((float)anim->mDuration * tickConversion);
         outAnim->SetLength((float)anim->mDuration * tickConversion);