Browse Source

AssetImpoter can import a subset animation frames.

Terence 9 years ago
parent
commit
d73be95692
1 changed files with 29 additions and 7 deletions
  1. 29 7
      Source/Tools/AssetImporter/AssetImporter.cpp

+ 29 - 7
Source/Tools/AssetImporter/AssetImporter.cpp

@@ -124,6 +124,9 @@ HashSet<aiAnimation*> allAnimations_;
 PODVector<aiAnimation*> sceneAnimations_;
 
 float defaultTicksPerSecond_ = 4800.0f;
+// for subset animation import usage.
+float importStartTime_ = 0.0f;
+float importEndTime_ = 0.0f;
 
 int main(int argc, char** argv);
 void Run(const Vector<String>& arguments);
@@ -245,7 +248,9 @@ void Run(const Vector<String>& arguments)
             "-ct         Check and do not overwrite if texture exists\n"
             "-ctn        Check and do not overwrite if texture has newer timestamp\n"
             "-am         Export all meshes even if identical (scene mode only)\n"
-            "-bp         Move bones to bind pose before saving model\n"
+			"-bp         Move bones to bind pose before saving model\n"
+			"-split <start> <end> (animation model only)\n"
+			"            Split animation, will only import from start frame to end frame \n"
         );
     }
 
@@ -391,6 +396,15 @@ void Run(const Vector<String>& arguments)
                 checkUniqueModel_ = false;
             else if (argument == "bp")
                 moveToBindPose_ = true;
+			else if (argument == "split")
+			{
+				String value2 = i + 2 < arguments.Size() ? arguments[i + 2] : String::EMPTY;
+				if (value.Length() && value2.Length() && (value[0] != '-') && (value2[0] != '-'))
+				{
+					importStartTime_	= ::atof(value.CString());
+					importEndTime_		= ::atof(value2.CString());
+				}
+			}
         }
     }
 
@@ -1112,6 +1126,9 @@ void BuildAndSaveAnimations(OutModel* model)
         String animName = FromAIString(anim->mName);
         String animOutName;
 
+		if (importEndTime_ == 0.0f) // if -split is disable, set the end time to duration.
+			importEndTime_ = duration;
+
         if (animName.Empty())
             animName = "Anim" + String(i + 1);
         if (model)
@@ -1138,7 +1155,9 @@ void BuildAndSaveAnimations(OutModel* model)
             if (channel->mScalingKeys > 0)
                 startTime = Min(startTime, (float)channel->mScalingKeys[0].mTime);
         }
-        duration -= startTime;
+		if (startTime > importStartTime_)
+			importStartTime_ = startTime;
+		duration =importEndTime_ - importStartTime_;
 
         SharedPtr<Animation> outAnim(new Animation(context_));
         outAnim->SetAnimationName(animName);
@@ -1254,11 +1273,11 @@ void BuildAndSaveAnimations(OutModel* model)
 
                 // Get time for the keyframe. Adjust with animation's start time
                 if (track->channelMask_ & CHANNEL_POSITION && k < channel->mNumPositionKeys)
-                    kf.time_ = ((float)channel->mPositionKeys[k].mTime - startTime) * tickConversion;
+                    kf.time_ = ((float)channel->mPositionKeys[k].mTime - startTime);
                 else if (track->channelMask_ & CHANNEL_ROTATION && k < channel->mNumRotationKeys)
-                    kf.time_ = ((float)channel->mRotationKeys[k].mTime - startTime) * tickConversion;
+                    kf.time_ = ((float)channel->mRotationKeys[k].mTime - startTime);
                 else if (track->channelMask_ & CHANNEL_SCALE && k < channel->mNumScalingKeys)
-                    kf.time_ = ((float)channel->mScalingKeys[k].mTime - startTime) * tickConversion;
+                    kf.time_ = ((float)channel->mScalingKeys[k].mTime - startTime);
 
                 // Make sure time stays positive
                 kf.time_ = Max(kf.time_, 0.0f);
@@ -1294,8 +1313,11 @@ void BuildAndSaveAnimations(OutModel* model)
                     kf.rotation_ = ToQuaternion(rot);
                 if (track->channelMask_ & CHANNEL_SCALE)
                     kf.scale_ = ToVector3(scale);
-
-                track->keyFrames_.Push(kf);
+				if (kf.time_ >= importStartTime_ && kf.time_ <= importEndTime_)
+				{
+					kf.time_ = (kf.time_ - importStartTime_) * tickConversion;
+					track->keyFrames_.Push(kf);
+				}
             }
         }