Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

TranslationSequence.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * 変換シーケンス実装
00022  * @author Junpee
00023  */
00024 
00025 #include "System/stdafx.h"
00026 #include "Translator/Animation/TranslationSequence.h"
00027 
00028 namespace LampForMaya{
00029 
00030 //------------------------------------------------------------------------------
00031 // コンストラクタ
00032 TranslationSequence::TranslationSequence() :
00033     hasSequence_(false), sequenceCount_(0),
00034     startTime_(NULL), endTime_(NULL), looped_(NULL){
00035 }
00036 //------------------------------------------------------------------------------
00037 // デストラクタ
00038 TranslationSequence::~TranslationSequence(){
00039     SafeArrayDelete(startTime_);
00040     SafeArrayDelete(endTime_);
00041     SafeArrayDelete(looped_);
00042 }
00043 //------------------------------------------------------------------------------
00044 // 分析
00045 bool TranslationSequence::analyze(const MObject& object){
00046     hasSequence_ = false;
00047     String errorString;
00048     MStatus result;
00049     MFnDependencyNode dependencyNode(object, &result);
00050     MayaStatusCheck(result);
00051     MString name = dependencyNode.name(&result);
00052     MayaStatusCheck(result);
00053     // シーケンスアトリビュートが存在するか
00054     MString sequenceName("LampSequence");
00055     MObject attribute = dependencyNode.attribute(sequenceName, &result);
00056     if(!result){ return hasSequence_; }
00057     // シーケンスアトリビュートがアニメーションしているか
00058     MPlug attributePlug = dependencyNode.findPlug(sequenceName, &result);
00059     MayaStatusCheck(result);
00060     if(!MAnimUtil::isAnimated(attributePlug)){
00061 //      MayaErrorOut(MString("TranslationSequence::analyze() ") + sequenceName +
00062 //          "アトリビュートが有りますが、アニメーションしていません " + name);
00063         return hasSequence_;
00064     }
00065     // アニメーションカーブの取得
00066     MPlugArray plugArray;
00067     if(!attributePlug.connectedTo(plugArray, true, false, &result)){
00068         MayaErrorOut(MString("TranslationSequence::analyze() ") + sequenceName +
00069             "アトリビュートが有りますが、アニメーションしていません " + name);
00070         return hasSequence_;
00071     }
00072     MayaStatusCheck(result);
00073     if(plugArray.length() != 1){
00074         MayaErrorOut(MString("TranslationSequence::analyze() ") + sequenceName +
00075             "アトリビュートが有りますが、複数のプラグが接続されています " + name);
00076         return hasSequence_;
00077     }
00078     MObject curveObject = plugArray[0].node(&result);
00079     MayaStatusCheck(result);
00080     MFnAnimCurve curve(curveObject, &result);
00081     MayaStatusCheck(result);
00082     // アニメーションキーが1つ以上あるか
00083     u_int keyCount = curve.numKeys(&result);
00084     MayaStatusCheck(result);
00085     if(keyCount == 0){
00086         MayaErrorOut(MString("TranslationSequence::analyze() ") + sequenceName +
00087             "アトリビュートが有りますが、キーがありません " + name);
00088         return hasSequence_;
00089     }
00090     // キーの間隔チェック
00091     double preTime = 0.f;
00092     for(u_int i = 0; i < keyCount; i++){
00093         double time = curve.time(i, &result).value();
00094         MayaStatusCheck(result);
00095         if(time - preTime < 2.0){
00096             MayaErrorOut(MString("TranslationSequence::analyze() "
00097                 "シーケンスのアニメーションキーは時間の間隔が2以上必要です ") +
00098                 name);
00099             return hasSequence_;
00100         }
00101         preTime = time;
00102     }
00103     // キーのエラーチェック
00104     for(u_int i = 0; i < keyCount; i++){
00105         // 時間が-のキーが無いかチェック
00106         double time = curve.time(i, &result).value();
00107         MayaStatusCheck(result);
00108         if(time < 0.0){
00109             MayaErrorOut(MString("TranslationSequence::analyze() "
00110                 "シーケンスのアニメーションキーは+の時間を設定してください ") +
00111                 name + " " + time);
00112             return hasSequence_;
00113         }
00114         // 端数が無いかチェック
00115 //      double integer;
00116 //      double fraction = ::modf(time, &integer);
00117 //      if(fraction > (double)Math::epsilon){
00118 //          MayaErrorOut(MString("TranslationSequence::analyze() "
00119 //              "シーケンスのアニメーションキーは整数時間を設定してください ") +
00120 //              name + " " + time);
00121 //          return hasSequence_;
00122 //      }
00123     }
00124     // シーケンスデータ作成
00125     sequenceCount_ = keyCount;
00126     SafeArrayDelete(startTime_);
00127     SafeArrayDelete(endTime_);
00128     SafeArrayDelete(looped_);
00129     startTime_ = new int[sequenceCount_];
00130     endTime_ = new int[sequenceCount_];
00131     looped_ = new bool[sequenceCount_];
00132     MTime time;
00133     double value;
00134     // 1番目シーケンス作成
00135     startTime_[0] = 0;
00136     time = curve.time(0, &result);
00137     MayaStatusCheck(result);
00138     endTime_[0] = (int)time.value();
00139     MayaStatusCheck(curve.evaluate(time, value));
00140     looped_[0] = (value > 0.5);
00141     // 2番目以降のシーケンス作成
00142     for(int i = 1; i < sequenceCount_; i++){
00143         startTime_[i] = (int)curve.time((i - 1), &result).value() + 1;
00144         MayaStatusCheck(result);
00145         time = curve.time(i, &result);
00146         MayaStatusCheck(result);
00147         endTime_[i] = ((int)time.value());
00148         MayaStatusCheck(curve.evaluate(time, value));
00149         looped_[i] = (value > 0.5);
00150     }
00151 /*
00152     for(int i = 0; i < sequenceCount_; i++){
00153         MTime time = curve.time(i, &result);
00154         startTime_[i] = (int)time.value();
00155         MayaStatusCheck(result);
00156         endTime_[i] = ((int)curve.time(i + 1, &result).value()) - 1;
00157         MayaStatusCheck(result);
00158         double value;
00159         result = curve.evaluate(time, value);
00160         looped_[i] = (value > 0.5);
00161     }
00162 */
00163     hasSequence_ = true;
00164     return hasSequence_;
00165 }
00166 //------------------------------------------------------------------------------
00167 } // End of namespace Lamp
00168 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:56 2005 for LampForMaya by doxygen 1.3.2