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

# TextAnimationSaver.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 "LampBasic.h"
    00026 #include "Animation/InputOutput/TextAnimationSaver.h"
    00027 #include "Core/InputOutput/TextFileWriter.h"
    00028
    00029 #include "Animation/VectorInterpolator/VectorConstantInterpolator.h"
    00030 #include "Animation/VectorInterpolator/VectorArrayInterpolator.h"
    00031 #include "Animation/VectorInterpolator/VectorLinearInterpolator.h"
    00032 #include "Animation/RotationInterpolator/RotationConstantInterpolator.h"
    00033 #include "Animation/RotationInterpolator/EulerArrayInterpolator.h"
    00034 #include "Animation/RotationInterpolator/QuaternionArrayInterpolator.h"
    00035 #include "Animation/RotationInterpolator/QuaternionLinearInterpolator.h"
    00036
    00037 #include "Animation/System/AnimationManager.h"
    00038 #include "Animation/System/AnimationSet.h"
    00039 #include "Animation/Camera/CameraAnimation.h"
    00040 #include "Animation/SceneNode/SceneNodeAnimation.h"
    00041 #include "Animation/Model/CharacterModelAnimation.h"
    00042
    00043 namespace Lamp{
    00044
    00045 //------------------------------------------------------------------------------
    00046 // コンストラクタ
    00047 TextAnimationSaver::TextAnimationSaver(){
    00048 }
    00049 //------------------------------------------------------------------------------
    00050 // デストラクタ
    00051 TextAnimationSaver::~TextAnimationSaver(){
    00052 }
    00053 //------------------------------------------------------------------------------
    00054 // セーブ
    00055 void TextAnimationSaver::save(
    00056     const String& filePath, AnimationManager* manager){
    00057     TextFileWriter* textFileWriter = new TextFileWriter(filePath);
    00058     save(textFileWriter, manager);
    00059     delete textFileWriter;
    00060 }
    00061 //------------------------------------------------------------------------------
    00062 // セーブ
    00063 void TextAnimationSaver::save(
    00064     TextWriter* textWriter, AnimationManager* manager){
    00065     writer_ = textWriter;
    00066     manager_ = manager;
    00067     // ヘッダの書き出し
    00068     writeHeader();
    00069     // オブジェクトのカウント
    00070     if(countObjects() == 0){ return; }
    00071     // アニメーションリストの書き出し
    00072     writeAnimationList();
    00073     // リンクの書き出し
    00074     writeLink();
    00075     writeLineComment();
    00076 }
    00077 //------------------------------------------------------------------------------
    00078 // ヘッダの書き出し
    00079 void TextAnimationSaver::writeHeader(){
    00080     writeBlockComment("Header");
    00081     writer_->writeText("Header {\n");
    00082     writer_->writeText("\ttype LampTextAnimationFormat\n");
    00083     writer_->writeText("\tversion 0_9_0\n");
    00084     writer_->writeText("}\n\n");
    00085 }
    00086 //------------------------------------------------------------------------------
    00087 // オブジェクトのカウント
    00088 int TextAnimationSaver::countObjects(){
    00089     // アニメーションカウントクリア
    00090     animationCount_ = manager_->getCount();
    00091     animationSetCount_ = 0;
    00092     cameraCount_ = 0;
    00093     sceneNodeCount_ = 0;
    00094     characterModelCount_ = 0;
    00095     // 各アニメーションのカウント
    00096     for(int i = 0; i < animationCount_; i++){
    00097         Animation* animation = manager_->get(i);
    00098         if(animation->isAnimationSet()){
    00099             animationSetCount_++;
    00100         }else if(animation->isCameraAnimation()){
    00101             cameraCount_++;
    00102         }else if(animation->isSceneNodeAnimation()){
    00103             sceneNodeCount_++;
    00104         }else if(animation->isCharacterModelAnimation()){
    00105             characterModelCount_++;
    00106         }else{
    00107             ErrorOut("TextAnimationSaver::countObjects() "
    00108                 "Unsupported animation type");
    00109         }
    00110     }
    00111     // アニメーションデータカウントクリア
    00112     animationDataCount_ = manager_->getDataCount();
    00113     cameraDataCount_ = 0;
    00114     sceneNodeDataCount_ = 0;
    00115     characterModelDataCount_ = 0;
    00116     // 各アニメーションデータのカウント
    00117     for(int i = 0; i < animationDataCount_; i++){
    00118         AnimationData* data = manager_->getData(i);
    00119         if(data->isCameraAnimationData()){
    00120             cameraDataCount_++;
    00121         }else if(data->isSceneNodeAnimationData()){
    00122             sceneNodeDataCount_++;
    00123         }else if(data->isCharacterModelAnimationData()){
    00124             characterModelDataCount_++;
    00125         }else{
    00126             ErrorOut("TextAnimationSaver::countObjects() "
    00127                 "Unsupported animation data type");
    00128         }
    00129     }
    00130     return (animationCount_ + animationDataCount_);
    00131 }
    00132 //------------------------------------------------------------------------------
    00133 // アニメーションリストの書き出し
    00134 void TextAnimationSaver::writeAnimationList(){
    00135     // アニメーションセットの書き出し
    00136     if(animationSetCount_ != 0){
    00137         writeBlockComment("AnimationSet");
    00138         writer_->writeText("AnimationSet {\n");
    00139         for(int i = 0; i < animationCount_; i++){
    00140             Animation* animation = manager_->get(i);
    00141             if(animation->isAnimationSet()){
    00142                 writeAnimationSet(animation->castAnimationSet());
    00143             }
    00144         }
    00145         writer_->writeText("}\n\n");
    00146     }
    00147     // カメラアニメーションの書き出し
    00148     if(cameraCount_ != 0){
    00149         writeBlockComment("CameraAnimation");
    00150         writer_->writeText("CameraAnimation {\n");
    00151         for(int i = 0; i < animationCount_; i++){
    00152             Animation* animation = manager_->get(i);
    00153             if(animation->isCameraAnimation()){
    00154                 writeCameraAnimation(animation->castCameraAnimation());
    00155             }
    00156         }
    00157         writer_->writeText("}\n\n");
    00158     }
    00159     // カメラアニメーションデータの書き出し
    00160     if(cameraDataCount_ != 0){
    00161         writeBlockComment("CameraAnimationData");
    00162         writer_->writeText("CameraAnimationData {\n");
    00163         for(int i = 0; i < animationDataCount_; i++){
    00164             AnimationData* data = manager_->getData(i);
    00165             if(data->isCameraAnimationData()){
    00166                 writeCameraAnimationData(
    00167                     data->castCameraAnimationData());
    00168             }
    00169         }
    00170         writer_->writeText("}\n\n");
    00171     }
    00172     // シーンノードアニメーションの書き出し
    00173     if(sceneNodeCount_ != 0){
    00174         writeBlockComment("SceneNodeAnimation");
    00175         writer_->writeText("SceneNodeAnimation {\n");
    00176         for(int i = 0; i < animationCount_; i++){
    00177             Animation* animation = manager_->get(i);
    00178             if(animation->isSceneNodeAnimation()){
    00179                 writeSceneNodeAnimation(animation->castSceneNodeAnimation());
    00180             }
    00181         }
    00182         writer_->writeText("}\n\n");
    00183     }
    00184     // シーンノードアニメーションデータの書き出し
    00185     if(sceneNodeDataCount_ != 0){
    00186         writeBlockComment("SceneNodeAnimationData");
    00187         writer_->writeText("SceneNodeAnimationData {\n");
    00188         for(int i = 0; i < animationDataCount_; i++){
    00189             AnimationData* data = manager_->getData(i);
    00190             if(data->isSceneNodeAnimationData()){
    00191                 writeSceneNodeAnimationData(
    00192                     data->castSceneNodeAnimationData());
    00193             }
    00194         }
    00195         writer_->writeText("}\n\n");
    00196     }
    00197     // キャラクタモデルアニメーションの書き出し
    00198     if(characterModelCount_ != 0){
    00199         writeBlockComment("CharacterModelAnimation");
    00200         writer_->writeText("CharacterModelAnimation {\n");
    00201         for(int i = 0; i < animationCount_; i++){
    00202             Animation* animation = manager_->get(i);
    00203             if(animation->isCharacterModelAnimation()){
    00204                 writeCharacterModelAnimation(
    00205                     animation->castCharacterModelAnimation());
    00206             }
    00207         }
    00208         writer_->writeText("}\n\n");
    00209     }
    00210     // キャラクタモデルアニメーションデータの書き出し
    00211     if(characterModelDataCount_ != 0){
    00212         writeBlockComment("CharacterModelAnimationData");
    00213         writer_->writeText("CharacterModelAnimationData {\n");
    00214         for(int i = 0; i < animationDataCount_; i++){
    00215             AnimationData* data = manager_->getData(i);
    00216             if(data->isCharacterModelAnimationData()){
    00217                 writeCharacterModelAnimationData(
    00218                     data->castCharacterModelAnimationData());
    00219             }
    00220         }
    00221         writer_->writeText("}\n\n");
    00222     }
    00223 }
    00224 //------------------------------------------------------------------------------
    00225 // リンクの書き出し
    00226 void TextAnimationSaver::writeLink(){
    00227     writeBlockComment("Link");
    00228     // アニメーションセットリンク
    00229     if(animationSetCount_ != 0){
    00230         writer_->writeText("AnimationSetLink {\n");
    00231         for(int i = 0; i < animationCount_; i++){
    00232             Animation* animation = manager_->get(i);
    00233             if(animation->isAnimationSet()){
    00234                 writeAnimationSetLink(animation->castAnimationSet());
    00235             }
    00236         }
    00237         writer_->writeText("}\n\n");
    00238     }
    00239     // カメラリンク
    00240     if(cameraCount_ != 0){
    00241         writer_->writeText("CameraLink {\n");
    00242         for(int i = 0; i < animationCount_; i++){
    00243             Animation* animation = manager_->get(i);
    00244             if(animation->isCameraAnimation()){
    00245                 writeCameraAnimationLink(
    00246                     animation->castCameraAnimation());
    00247             }
    00248         }
    00249         writer_->writeText("}\n\n");
    00250     }
    00251     // シーンノードリンク
    00252     if(sceneNodeCount_ != 0){
    00253         writer_->writeText("SceneNodeLink {\n");
    00254         for(int i = 0; i < animationCount_; i++){
    00255             Animation* animation = manager_->get(i);
    00256             if(animation->isSceneNodeAnimation()){
    00257                 writeSceneNodeAnimationLink(
    00258                     animation->castSceneNodeAnimation());
    00259             }
    00260         }
    00261         writer_->writeText("}\n\n");
    00262     }
    00263     // キャラクタモデルリンク
    00264     if(characterModelCount_ != 0){
    00265         writer_->writeText("CharacterModelLink {\n");
    00266         for(int i = 0; i < animationCount_; i++){
    00267             Animation* animation = manager_->get(i);
    00268             if(animation->isCharacterModelAnimation()){
    00269                 writeCharacterModelAnimationLink(
    00270                     animation->castCharacterModelAnimation());
    00271             }
    00272         }
    00273         writer_->writeText("}\n\n");
    00274     }
    00275 }
    00276 //------------------------------------------------------------------------------
    00277 // アニメーションセット
    00278 //------------------------------------------------------------------------------
    00279 // アニメーションセットの書き出し
    00280 void TextAnimationSaver::writeAnimationSet(AnimationSet* animation){
    00281     writer_->writeText("\t");
    00282     writer_->writeText(animation->getName());
    00283     writer_->writeText(" {\n");
    00284     // 有効、無効
    00285     writer_->writeText("\t\tenabled ");
    00286     writeBool(animation->isEnabled());
    00287     writer_->writeText("\n");
    00288     writer_->writeText("\t}\n\n");
    00289 }
    00290 //------------------------------------------------------------------------------
    00291 // カメラ
    00292 //------------------------------------------------------------------------------
    00293 // カメラアニメーションの書き出し
    00294 void TextAnimationSaver::writeCameraAnimation(CameraAnimation* animation){
    00295     writer_->writeText("\t");
    00296     writer_->writeText(animation->getName());
    00297     writer_->writeText(" {\n");
    00298     // ターゲット名
    00299     writer_->writeText("\t\ttargetName ");
    00300     writer_->writeText(animation->getTargetName());
    00301     writer_->writeText("\n");
    00302     // 有効、無効
    00303     writer_->writeText("\t\tenabled ");
    00304     writeBool(animation->isEnabled());
    00305     writer_->writeText("\n");
    00306     writer_->writeText("\t}\n\n");
    00307 }
    00308 //------------------------------------------------------------------------------
    00309 // カメラアニメーションデータの書き出し
    00310 void TextAnimationSaver::writeCameraAnimationData(
    00311     CameraAnimationData* data){
    00312     writer_->writeText("\t");
    00313     writer_->writeText(data->getName());
    00314     writer_->writeText(" {\n");
    00315     // シーケンス数
    00316     int sequenceCount = data->getSequenceCount();
    00317     writer_->writeFormat("\t\tsequenceCount %d\n", sequenceCount);
    00318     // アニメーションデータの書き出し
    00319     String tabDepth = "\t\t\t";
    00320     for(int i = 0; i < sequenceCount; i++){
    00321         writer_->writeFormat("\t\tsequence %d {\n", i);
    00322         // 回転
    00323         writeRotationInterpolator(
    00324             data->getRotation(i), "rotation", tabDepth);
    00325         // 移動
    00326         writeVectorInterpolator(
    00327             data->getTranslation(i), "translation", tabDepth);
    00328         // ループフラグ
    00329         writer_->writeText("\t\t\tlooped ");
    00330         writeBool(data->isLooped(i));
    00331         writer_->writeText("\n\t\t}\n");
    00332     }
    00333     writer_->writeText("\t}\n\n");
    00334 }
    00335 //------------------------------------------------------------------------------
    00336 // シーンノード
    00337 //------------------------------------------------------------------------------
    00338 // シーンノードアニメーションの書き出し
    00339 void TextAnimationSaver::writeSceneNodeAnimation(SceneNodeAnimation* animation){
    00340     writer_->writeText("\t");
    00341     writer_->writeText(animation->getName());
    00342     writer_->writeText(" {\n");
    00343     // ターゲット名
    00344     writer_->writeText("\t\ttargetName ");
    00345     writer_->writeText(animation->getTargetName());
    00346     writer_->writeText("\n");
    00347     // 有効、無効
    00348     writer_->writeText("\t\tenabled ");
    00349     writeBool(animation->isEnabled());
    00350     writer_->writeText("\n");
    00351     writer_->writeText("\t}\n\n");
    00352 }
    00353 //------------------------------------------------------------------------------
    00354 // シーンノードアニメーションデータの書き出し
    00355 void TextAnimationSaver::writeSceneNodeAnimationData(
    00356     SceneNodeAnimationData* data){
    00357     writer_->writeText("\t");
    00358     writer_->writeText(data->getName());
    00359     writer_->writeText(" {\n");
    00360     // シーケンス数
    00361     int sequenceCount = data->getSequenceCount();
    00362     writer_->writeFormat("\t\tsequenceCount %d\n", sequenceCount);
    00363     // アニメーションデータの書き出し
    00364     String tabDepth = "\t\t\t";
    00365     for(int i = 0; i < sequenceCount; i++){
    00366         writer_->writeFormat("\t\tsequence %d {\n", i);
    00367         // スケール
    00368         writeVectorInterpolator(
    00369             data->getScale(i), "scale", tabDepth);
    00370         // 回転
    00371         writeRotationInterpolator(
    00372             data->getRotation(i), "rotation", tabDepth);
    00373         // 移動
    00374         writeVectorInterpolator(
    00375             data->getTranslation(i), "translation", tabDepth);
    00376         // ループフラグ
    00377         writer_->writeText("\t\t\tlooped ");
    00378         writeBool(data->isLooped(i));
    00379         writer_->writeText("\n\t\t}\n");
    00380     }
    00381     writer_->writeText("\t}\n\n");
    00382 }
    00383 //------------------------------------------------------------------------------
    00384 // モデル
    00385 //------------------------------------------------------------------------------
    00386 // キャラクタモデルアニメーションの書き出し
    00387 void TextAnimationSaver::writeCharacterModelAnimation(
    00388     CharacterModelAnimation* animation){
    00389     writer_->writeText("\t");
    00390     writer_->writeText(animation->getName());
    00391     writer_->writeText(" {\n");
    00392     // ターゲット名
    00393     writer_->writeText("\t\ttargetName ");
    00394     writer_->writeText(animation->getTargetName());
    00395     writer_->writeText("\n");
    00396     // ボーン数
    00397     int boneCount = animation->getBoneCount();
    00398     writer_->writeFormat("\t\tboneCount %d {\n", boneCount);
    00399     for(int i = 0; i < boneCount; i++){
    00400         writer_->writeText("\t\t\t");
    00401         writer_->writeText(animation->getBoneName(i));
    00402         writer_->writeText("\n");
    00403     }
    00404     writer_->writeText("\t\t}\n");
    00405     // 有効、無効
    00406     writer_->writeText("\t\tenabled ");
    00407     writeBool(animation->isEnabled());
    00408     writer_->writeText("\n");
    00409     writer_->writeText("\t}\n\n");
    00410 }
    00411 //------------------------------------------------------------------------------
    00412 // キャラクタモデルアニメーションデータの書き出し
    00413 void TextAnimationSaver::writeCharacterModelAnimationData(
    00414     CharacterModelAnimationData* data){
    00415     writer_->writeText("\t");
    00416     writer_->writeText(data->getName());
    00417     writer_->writeText(" {\n");
    00418     // ボーン数
    00419     int boneCount = data->getBoneCount();
    00420     writer_->writeFormat("\t\tboneCount %d\n", boneCount);
    00421     // シーケンス数
    00422     int sequenceCount = data->getSequenceCount();
    00423     writer_->writeFormat("\t\tsequenceCount %d\n", sequenceCount);
    00424     // アニメーションデータの書き出し
    00425     String tabDepth = "\t\t\t\t";
    00426     for(int i = 0; i < sequenceCount; i++){
    00427         writer_->writeFormat("\t\tsequence %d {\n", i);
    00428         for(int j = 0; j < boneCount; j++){
    00429             writer_->writeFormat("\t\t\tbone %d {\n", j);
    00430             // スケール
    00431             writeVectorInterpolator(
    00432                 data->getScale(i, j), "scale", tabDepth);
    00433             // 回転
    00434             writeRotationInterpolator(
    00435                 data->getRotation(i, j), "rotation", tabDepth);
    00436             // 移動
    00437             writeVectorInterpolator(
    00438                 data->getTranslation(i, j), "translation", tabDepth);
    00439             writer_->writeText("\t\t\t}\n");
    00440         }
    00441         // ループフラグ
    00442         writer_->writeText("\t\t\tlooped ");
    00443         writeBool(data->isLooped(i));
    00444         writer_->writeText("\n\t\t}\n");
    00445     }
    00446     writer_->writeText("\t}\n\n");
    00447 }
    00448 //------------------------------------------------------------------------------
    00449 // リンク
    00450 //------------------------------------------------------------------------------
    00451 // アニメーションセットリンクの書き出し
    00452 void TextAnimationSaver::writeAnimationSetLink(AnimationSet* animation){
    00453     int childCount = animation->getAnimationCount();
    00454     if(childCount == 0){ return; }
    00455     writer_->writeText("\t");
    00456     writer_->writeText(animation->getName());
    00457     writer_->writeText(" {\n");
    00458     for(int i = 0; i < childCount; i++){
    00459         Animation* child = animation->getAnimation(i);
    00460         writer_->writeText("\t\t");
    00461         writer_->writeText(child->getName());
    00462         writer_->writeText("\n");
    00463     }
    00464     writer_->writeText("\t}\n\n");
    00465 }
    00466 //------------------------------------------------------------------------------
    00467 // カメラアニメーションリンクの書き出し
    00468 void TextAnimationSaver::writeCameraAnimationLink(
    00469     CameraAnimation* animation){
    00470     writer_->writeText("\t");
    00471     writer_->writeText(animation->getName());
    00472     writer_->writeText(" ");
    00473     writer_->writeText(animation->getAnimationData()->getName());
    00474     writer_->writeText("\n");
    00475 }
    00476 //------------------------------------------------------------------------------
    00477 // シーンノードアニメーションリンクの書き出し
    00478 void TextAnimationSaver::writeSceneNodeAnimationLink(
    00479     SceneNodeAnimation* animation){
    00480     writer_->writeText("\t");
    00481     writer_->writeText(animation->getName());
    00482     writer_->writeText(" ");
    00483     writer_->writeText(animation->getAnimationData()->getName());
    00484     writer_->writeText("\n");
    00485 }
    00486 //------------------------------------------------------------------------------
    00487 // キャラクタモデルアニメーションリンクの書き出し
    00488 void TextAnimationSaver::writeCharacterModelAnimationLink(
    00489     CharacterModelAnimation* animation){
    00490     writer_->writeText("\t");
    00491     writer_->writeText(animation->getName());
    00492     writer_->writeText(" ");
    00493     writer_->writeText(animation->getAnimationData()->getName());
    00494     writer_->writeText("\n");
    00495 }
    00496 //------------------------------------------------------------------------------
    00497 // ベクトル補間
    00498 //------------------------------------------------------------------------------
    00499 // ベクトル補間の書き出し
    00500 void TextAnimationSaver::writeVectorInterpolator(
    00501     VectorInterpolator* interpolator,
    00502     const String& name, const String& tabDepth){
    00503     // NULL対応
    00504     if(interpolator == NULL){
    00505         writer_->writeText(tabDepth);
    00506         writer_->writeText(name);
    00507         writer_->writeText(" NULL\n");
    00508         return;
    00509     }
    00510     // 各補間の書き出し
    00511     if(interpolator->isVectorConstantInterpolator()){
    00512         writeVectorConstantInterpolator(
    00513             interpolator->castVectorConstantInterpolator(), name, tabDepth);
    00514     }else if(interpolator->isVectorArrayInterpolator()){
    00515         writeVectorArrayInterpolator(
    00516             interpolator->castVectorArrayInterpolator(), name, tabDepth);
    00517     }else if(interpolator->isVectorLinearInterpolator()){
    00518         writeVectorLinearInterpolator(
    00519             interpolator->castVectorLinearInterpolator(), name, tabDepth);
    00520     }else{
    00521         ErrorOut("TextAnimationSaver::writeVectorInterpolator() "
    00522             "Unsupported interpolater");
    00523     }
    00524 }
    00525 //------------------------------------------------------------------------------
    00526 // ベクトル定数補間の書き出し
    00527 void TextAnimationSaver::writeVectorConstantInterpolator(
    00528     VectorConstantInterpolator* interpolator,
    00529     const String& name, const String& tabDepth){
    00530     // 名前
    00531     writer_->writeText(tabDepth);
    00532     writer_->writeText(name);
    00533     writer_->writeText(" {\n");
    00534     // タイプ
    00535     writer_->writeText(tabDepth);
    00536     writer_->writeText("\ttype Constant\n");
    00537     // 長さ
    00538     writer_->writeText(tabDepth);
    00539     writer_->writeFormat("\tlength %.8f\n", interpolator->getLength());
    00540     // 値
    00541     writer_->writeText(tabDepth);
    00542     Vector3 value = interpolator->getValue();
    00543     writer_->writeFormat("\tvalue { %.8f %.8f %.8f }\n",
    00544         value.x, value.y, value.z);
    00545     writer_->writeText(tabDepth);
    00546     writer_->writeText("}\n");
    00547 }
    00548 //------------------------------------------------------------------------------
    00549 // ベクトル配列補間の書き出し
    00550 void TextAnimationSaver::writeVectorArrayInterpolator(
    00551     VectorArrayInterpolator* interpolator,
    00552     const String& name, const String& tabDepth){
    00553     // 名前
    00554     writer_->writeText(tabDepth);
    00555     writer_->writeText(name);
    00556     writer_->writeText(" {\n");
    00557     // タイプ
    00558     writer_->writeText(tabDepth);
    00559     writer_->writeText("\ttype Array\n");
    00560     // 値
    00561     writer_->writeText(tabDepth);
    00562     int size = interpolator->getSize();
    00563     writer_->writeFormat("\tvalue %d {\n", size);
    00564     String valueTab = tabDepth + "\t\t";
    00565     for(int i = 0; i < size; i++){
    00566         writer_->writeText(valueTab);
    00567         const Vector3& value = interpolator->getValue(i);
    00568         writer_->writeFormat("{ %.8f %.8f %.8f }\n",
    00569             value.x, value.y, value.z);
    00570     }
    00571     writer_->writeText(tabDepth);
    00572     writer_->writeText("\t}\n");
    00573     writer_->writeText(tabDepth);
    00574     writer_->writeText("}\n");
    00575 }
    00576 //------------------------------------------------------------------------------
    00577 // ベクトル線形補間の書き出し
    00578 void TextAnimationSaver::writeVectorLinearInterpolator(
    00579     VectorLinearInterpolator* interpolator,
    00580     const String& name, const String& tabDepth){
    00581     // 名前
    00582     writer_->writeText(tabDepth);
    00583     writer_->writeText(name);
    00584     writer_->writeText(" {\n");
    00585     // タイプ
    00586     writer_->writeText(tabDepth);
    00587     writer_->writeText("\ttype Linear\n");
    00588     // 値
    00589     writer_->writeText(tabDepth);
    00590     int keyCount = interpolator->getKeyCount();
    00591     writer_->writeFormat("\tvalue %d {\n", keyCount);
    00592     String valueTab = tabDepth + "\t\t";
    00593     for(int i = 0; i < keyCount; i++){
    00594         writer_->writeText(valueTab);
    00595         float time = interpolator->getTime(i);
    00596         const Vector3& value = interpolator->getValue(i);
    00597         writer_->writeFormat("%.8f { %.8f %.8f %.8f }\n",
    00598             time, value.x, value.y, value.z);
    00599     }
    00600     writer_->writeText(tabDepth);
    00601     writer_->writeText("\t}\n");
    00602     writer_->writeText(tabDepth);
    00603     writer_->writeText("}\n");
    00604 }
    00605 //------------------------------------------------------------------------------
    00606 // 回転補間
    00607 //------------------------------------------------------------------------------
    00608 // 回転補間の書き出し
    00609 void TextAnimationSaver::writeRotationInterpolator(
    00610     RotationInterpolator* interpolator,
    00611     const String& name, const String& tabDepth){
    00612     // NULL対応
    00613     if(interpolator == NULL){
    00614         writer_->writeText(tabDepth);
    00615         writer_->writeText(name);
    00616         writer_->writeText(" NULL\n");
    00617         return;
    00618     }
    00619     // 各補間の書き出し
    00620     if(interpolator->isRotationConstantInterpolator()){
    00621         writeRotationConstantInterpolator(
    00622             interpolator->castRotationConstantInterpolator(), name, tabDepth);
    00623     }else if(interpolator->isEulerArrayInterpolator()){
    00624         writeEulerArrayInterpolator(
    00625             interpolator->castEulerArrayInterpolator(), name, tabDepth);
    00626     }else if(interpolator->isQuaternionArrayInterpolator()){
    00627         writeQuaternionArrayInterpolator(
    00628             interpolator->castQuaternionArrayInterpolator(), name, tabDepth);
    00629     }else if(interpolator->isQuaternionLinearInterpolator()){
    00630         writeQuaternionLinearInterpolator(
    00631             interpolator->castQuaternionLinearInterpolator(), name, tabDepth);
    00632     }else{
    00633         ErrorOut("TextAnimationSaver::writeRotationInterpolator() "
    00634             "Unsupported interpolater");
    00635     }
    00636 }
    00637 //------------------------------------------------------------------------------
    00638 // 回転定数補間の書き出し
    00639 void TextAnimationSaver::writeRotationConstantInterpolator(
    00640     RotationConstantInterpolator* interpolator,
    00641     const String& name, const String& tabDepth){
    00642     // 名前
    00643     writer_->writeText(tabDepth);
    00644     writer_->writeText(name);
    00645     writer_->writeText(" {\n");
    00646     // タイプ
    00647     writer_->writeText(tabDepth);
    00648     writer_->writeText("\ttype Constant\n");
    00649     // 長さ
    00650     writer_->writeText(tabDepth);
    00651     writer_->writeFormat("\tlength %.8f\n", interpolator->getLength());
    00652     // 値
    00653     writer_->writeText(tabDepth);
    00654     Quaternion value = interpolator->getQuaternion();
    00655     writer_->writeFormat("\tquaternionValue { %.8f %.8f %.8f %.8f }\n",
    00656         value.x, value.y, value.z, value.w);
    00657     writer_->writeText(tabDepth);
    00658     writer_->writeText("}\n");
    00659 }
    00660 //------------------------------------------------------------------------------
    00661 // オイラー回転配列補間の書き出し
    00662 void TextAnimationSaver::writeEulerArrayInterpolator(
    00663     EulerArrayInterpolator* interpolator,
    00664     const String& name, const String& tabDepth){
    00665     // 名前
    00666     writer_->writeText(tabDepth);
    00667     writer_->writeText(name);
    00668     writer_->writeText(" {\n");
    00669     // タイプ
    00670     writer_->writeText(tabDepth);
    00671     writer_->writeText("\ttype EulerArray\n");
    00672     // 値
    00673     writer_->writeText(tabDepth);
    00674     int size = interpolator->getSize();
    00675     writer_->writeFormat("\tvalue %d {\n", size);
    00676     String valueTab = tabDepth + "\t\t";
    00677     for(int i = 0; i < size; i++){
    00678         writer_->writeText(valueTab);
    00679         const Vector3& value = interpolator->getValue(i);
    00680         writer_->writeFormat("{ %.8f %.8f %.8f }\n",
    00681             value.x, value.y, value.z);
    00682     }
    00683     writer_->writeText(tabDepth);
    00684     writer_->writeText("\t}\n");
    00685     writer_->writeText(tabDepth);
    00686     writer_->writeText("}\n");
    00687 }
    00688 //------------------------------------------------------------------------------
    00689 // 四元数回転配列補間の書き出し
    00690 void TextAnimationSaver::writeQuaternionArrayInterpolator(
    00691     QuaternionArrayInterpolator* interpolator,
    00692     const String& name, const String& tabDepth){
    00693     // 名前
    00694     writer_->writeText(tabDepth);
    00695     writer_->writeText(name);
    00696     writer_->writeText(" {\n");
    00697     // タイプ
    00698     writer_->writeText(tabDepth);
    00699     writer_->writeText("\ttype QuaternionArray\n");
    00700     // 値
    00701     writer_->writeText(tabDepth);
    00702     int size = interpolator->getSize();
    00703     writer_->writeFormat("\tvalue %d {\n", size);
    00704     String valueTab = tabDepth + "\t\t";
    00705     for(int i = 0; i < size; i++){
    00706         writer_->writeText(valueTab);
    00707         const Quaternion& value = interpolator->getValue(i);
    00708         writer_->writeFormat("{ %.8f %.8f %.8f %.8f }\n",
    00709             value.x, value.y, value.z, value.w);
    00710     }
    00711     writer_->writeText(tabDepth);
    00712     writer_->writeText("\t}\n");
    00713     writer_->writeText(tabDepth);
    00714     writer_->writeText("}\n");
    00715 }
    00716 //------------------------------------------------------------------------------
    00717 // 四元数回転線形補間の書き出し
    00718 void TextAnimationSaver::writeQuaternionLinearInterpolator(
    00719     QuaternionLinearInterpolator* interpolator,
    00720     const String& name, const String& tabDepth){
    00721     // 名前
    00722     writer_->writeText(tabDepth);
    00723     writer_->writeText(name);
    00724     writer_->writeText(" {\n");
    00725     // タイプ
    00726     writer_->writeText(tabDepth);
    00727     writer_->writeText("\ttype QuaternionLinear\n");
    00728     // 値
    00729     writer_->writeText(tabDepth);
    00730     int keyCount = interpolator->getKeyCount();
    00731     writer_->writeFormat("\tvalue %d {\n", keyCount);
    00732     String valueTab = tabDepth + "\t\t";
    00733     for(int i = 0; i < keyCount; i++){
    00734         writer_->writeText(valueTab);
    00735         float time = interpolator->getTime(i);
    00736         const Quaternion& value = interpolator->getValue(i);
    00737         writer_->writeFormat("%.8f { %.8f %.8f %.8f %.8f }\n",
    00738             time, value.x, value.y, value.z, value.w);
    00739     }
    00740     writer_->writeText(tabDepth);
    00741     writer_->writeText("\t}\n");
    00742     writer_->writeText(tabDepth);
    00743     writer_->writeText("}\n");
    00744 }
    00745 //------------------------------------------------------------------------------
    00746 // ユーティリティ
    00747 //------------------------------------------------------------------------------
    00748 // boolの書き出し
    00749 void TextAnimationSaver::writeBool(bool flag){
    00750     if(flag){
    00751         writer_->writeText("true");
    00752     }else{
    00753         writer_->writeText("false");
    00754     }
    00755 }
    00756 //------------------------------------------------------------------------------
    00757 // 線コメントの書き出し
    00758 void TextAnimationSaver::writeLineComment(){
    00759     writer_->writeText("//----------------------------"
    00760         "--------------------------------------------------\n");
    00761 }
    00762 //------------------------------------------------------------------------------
    00763 // ブロックコメントの書き出し
    00764 void TextAnimationSaver::writeBlockComment(const String& blockName){
    00765     writeLineComment();
    00766     writer_->writeText("// ");
    00767     writer_->writeText(blockName);
    00768     writer_->writeText(" Block\n");
    00769     writeLineComment();
    00770 }
    00771 //------------------------------------------------------------------------------
    00772 } // End of namespace Lamp
    00773 //------------------------------------------------------------------------------