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

TextAnimationLoader.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/TextAnimationLoader.h"
00027 #include "Core/InputOutput/FilePath.h"
00028 #include "Core/InputOutput/TextFileReader.h"
00029 #include "Core/InputOutput/StreamTokenizer.h"
00030 #include "Animation/VectorInterpolator/VectorConstantInterpolator.h"
00031 #include "Animation/VectorInterpolator/VectorArrayInterpolator.h"
00032 #include "Animation/VectorInterpolator/VectorLinearInterpolator.h"
00033 #include "Animation/RotationInterpolator/RotationConstantInterpolator.h"
00034 #include "Animation/RotationInterpolator/EulerArrayInterpolator.h"
00035 #include "Animation/RotationInterpolator/QuaternionArrayInterpolator.h"
00036 #include "Animation/RotationInterpolator/QuaternionLinearInterpolator.h"
00037 
00038 #include "Animation/System/AnimationManager.h"
00039 #include "Animation/System/AnimationSet.h"
00040 #include "Animation/Camera/CameraAnimation.h"
00041 #include "Animation/SceneNode/SceneNodeAnimation.h"
00042 #include "Animation/Model/CharacterModelAnimation.h"
00043 
00044 namespace Lamp{
00045 
00046 //------------------------------------------------------------------------------
00047 // コンストラクタ
00048 TextAnimationLoader::TextAnimationLoader(){
00049 }
00050 //------------------------------------------------------------------------------
00051 // デストラクタ
00052 TextAnimationLoader::~TextAnimationLoader(){
00053 }
00054 //------------------------------------------------------------------------------
00055 // ロード
00056 void TextAnimationLoader::load(
00057     const String& filePath, AnimationManager* manager){
00058     FilePath path(filePath);
00059     Assert(path.existFile());
00060     TextFileReader* textFileReader = new TextFileReader(filePath);
00061     load(textFileReader, manager);
00062     delete textFileReader;
00063 }
00064 //------------------------------------------------------------------------------
00065 // ロード
00066 void TextAnimationLoader::load(
00067     TextReader* textReader, AnimationManager* manager){
00068     tokenizer_ = new StreamTokenizer(textReader);
00069     manager_ = manager;
00070 
00071     // ヘッダの読み込み
00072     readHeader();
00073 
00074     while(true){
00075         // トークン読み終わり
00076         if(!tokenizer_->nextToken()){ break; }
00077         String chunkName = tokenizer_->getToken();
00078         if(chunkName == "AnimationSet"){
00079             readAnimationSetList();
00080         }else if(chunkName == "CameraAnimation"){
00081             // カメラアニメーション
00082             openChunk();
00083             while(true){
00084                 String token = readToken("readCameraAnimation()");
00085                 if(token == "}"){ break; }
00086                 readCameraAnimation(token);
00087             }
00088         }else if(chunkName == "CameraAnimationData"){
00089             // カメラアニメーションデータ
00090             openChunk();
00091             while(true){
00092                 String token = readToken("readCameraAnimationData()");
00093                 if(token == "}"){ break; }
00094                 readCameraAnimationData(token);
00095             }
00096         }else if(chunkName == "SceneNodeAnimation"){
00097             // シーンノードアニメーション
00098             openChunk();
00099             while(true){
00100                 String token = readToken("readSceneNodeAnimation()");
00101                 if(token == "}"){ break; }
00102                 readSceneNodeAnimation(token);
00103             }
00104         }else if(chunkName == "SceneNodeAnimationData"){
00105             // シーンノードアニメーションデータ
00106             openChunk();
00107             while(true){
00108                 String token = readToken("readSceneNodeAnimationData()");
00109                 if(token == "}"){ break; }
00110                 readSceneNodeAnimationData(token);
00111             }
00112         }else if(chunkName == "CharacterModelAnimation"){
00113             // キャラクタモデルアニメーション
00114             openChunk();
00115             while(true){
00116                 String token = readToken("readCharacterModelAnimation()");
00117                 if(token == "}"){ break; }
00118                 readCharacterModelAnimation(token);
00119             }
00120         }else if(chunkName == "CharacterModelAnimationData"){
00121             // キャラクタモデルアニメーションデータ
00122             openChunk();
00123             while(true){
00124                 String token = readToken("readCharacterModelAnimationData()");
00125                 if(token == "}"){ break; }
00126                 readCharacterModelAnimationData(token);
00127             }
00128         }else if(chunkName == "AnimationSetLink"){
00129             readAnimationSetLinkList();
00130         }else if(chunkName == "CameraLink"){
00131             readCameraLinkList();
00132         }else if(chunkName == "SceneNodeLink"){
00133             readSceneNodeLinkList();
00134         }else if(chunkName == "CharacterModelLink"){
00135             readCharacterModelLinkList();
00136         }else{
00137             ErrorOut("TextAnimationLoader::load() "
00138                 "invalid chunk %s (line %d)",
00139                 chunkName.getBytes(), tokenizer_->getLineNumber());
00140         }
00141     }
00142     delete tokenizer_;
00143 }
00144 //------------------------------------------------------------------------------
00145 // ヘッダの読み込み
00146 void TextAnimationLoader::readHeader(){
00147     skipWord("Header");
00148     openChunk();
00149     skipWord("type");
00150     skipWord("LampTextAnimationFormat");
00151     skipWord("version");
00152     skipWord("0_9_0");
00153     closeChunk();
00154 }
00155 //------------------------------------------------------------------------------
00156 // アニメーションセット
00157 //------------------------------------------------------------------------------
00158 // アニメーションセットリストの読み込み
00159 void TextAnimationLoader::readAnimationSetList(){
00160     openChunk();
00161     while(true){
00162         String token = readToken("readAnimationSetList()");
00163         if(token == "}"){ break; }
00164         readAnimationSet(token);
00165     }
00166 }
00167 //------------------------------------------------------------------------------
00168 // アニメーションセットの読み込み
00169 void TextAnimationLoader::readAnimationSet(const String& name){
00170     AnimationSet* animation = manager_->createAnimationSet(name);
00171     openChunk();
00172     // 有効、無効フラグ
00173     skipWord("enabled");
00174     animation->setEnabled(readBool());
00175     closeChunk();
00176 }
00177 //------------------------------------------------------------------------------
00178 // カメラ
00179 //------------------------------------------------------------------------------
00180 // カメラアニメーションの読み込み
00181 void TextAnimationLoader::readCameraAnimation(const String& name){
00182     CameraAnimation* animation = manager_->createCamera(name);
00183     openChunk();
00184     // ターゲット名
00185     skipWord("targetName");
00186     animation->setTargetName(readToken("readCameraAnimation()"));
00187     // 有効、無効フラグ
00188     skipWord("enabled");
00189     animation->setEnabled(readBool());
00190     closeChunk();
00191 }
00192 //------------------------------------------------------------------------------
00193 // カメラアニメーションデータの読み込み
00194 void TextAnimationLoader::readCameraAnimationData(const String& name){
00195     CameraAnimationData* data = manager_->createCameraData(name);
00196     openChunk();
00197     skipWord("sequenceCount");
00198     int sequenceCount = readInt();
00199     data->setSequenceCount(sequenceCount);
00200     for(int i = 0; i < sequenceCount; i++){
00201         skipWord("sequence");
00202         int sequenceNumber = readInt();
00203         Assert(i == sequenceNumber);
00204         openChunk();
00205         // 回転
00206         skipWord("rotation");
00207         data->setRotation(i, readRotationInterpolator());
00208         // 移動
00209         skipWord("translation");
00210         data->setTranslation(i, readVectorInterpolator());
00211         // ループ
00212         skipWord("looped");
00213         data->setLooped(i, readBool());
00214         closeChunk();
00215     }
00216     closeChunk();
00217 }
00218 //------------------------------------------------------------------------------
00219 // シーンノード
00220 //------------------------------------------------------------------------------
00221 // シーンノードアニメーションの読み込み
00222 void TextAnimationLoader::readSceneNodeAnimation(const String& name){
00223     SceneNodeAnimation* animation = manager_->createSceneNode(name);
00224     openChunk();
00225     skipWord("targetName");
00226     animation->setTargetName(readToken("readSceneNodeAnimation()"));
00227     // 有効、無効フラグ
00228     skipWord("enabled");
00229     animation->setEnabled(readBool());
00230     closeChunk();
00231 }
00232 //------------------------------------------------------------------------------
00233 // シーンノードアニメーションデータの読み込み
00234 void TextAnimationLoader::readSceneNodeAnimationData(const String& name){
00235     SceneNodeAnimationData* data = manager_->createSceneNodeData(name);
00236     openChunk();
00237     skipWord("sequenceCount");
00238     int sequenceCount = readInt();
00239     data->setSequenceCount(sequenceCount);
00240     for(int i = 0; i < sequenceCount; i++){
00241         skipWord("sequence");
00242         int sequenceNumber = readInt();
00243         Assert(i == sequenceNumber);
00244         openChunk();
00245         // スケール
00246         skipWord("scale");
00247         data->setScale(i, readVectorInterpolator());
00248         // 回転
00249         skipWord("rotation");
00250         data->setRotation(i, readRotationInterpolator());
00251         // 移動
00252         skipWord("translation");
00253         data->setTranslation(i, readVectorInterpolator());
00254         // ループ
00255         skipWord("looped");
00256         data->setLooped(i, readBool());
00257         closeChunk();
00258     }
00259     closeChunk();
00260 }
00261 //------------------------------------------------------------------------------
00262 // キャラクタモデル
00263 //------------------------------------------------------------------------------
00264 // キャラクタモデルアニメーションの読み込み
00265 void TextAnimationLoader::readCharacterModelAnimation(const String& name){
00266     CharacterModelAnimation* animation =
00267         manager_->createCharacterModel(name);
00268     openChunk();
00269     skipWord("targetName");
00270     animation->setTargetName(readToken("readCharacterModelAnimation()"));
00271     skipWord("boneCount");
00272     int boneCount = readInt();
00273     animation->setBoneCount(boneCount);
00274     openChunk();
00275     for(int i = 0; i < boneCount; i++){
00276         animation->setBoneName(i, readToken("readCharacterModelAnimation()"));
00277     }
00278     closeChunk();
00279     // 有効、無効フラグ
00280     skipWord("enabled");
00281     animation->setEnabled(readBool());
00282     closeChunk();
00283 }
00284 //------------------------------------------------------------------------------
00285 // キャラクタモデルアニメーションデータの読み込み
00286 void TextAnimationLoader::readCharacterModelAnimationData(const String& name){
00287     CharacterModelAnimationData* data =
00288         manager_->createCharacterModelData(name);
00289     openChunk();
00290     skipWord("boneCount");
00291     int boneCount = readInt();
00292     data->setBoneCount(boneCount);
00293     skipWord("sequenceCount");
00294     int sequenceCount = readInt();
00295     data->setSequenceCount(sequenceCount);
00296     for(int i = 0; i < sequenceCount; i++){
00297         skipWord("sequence");
00298         int sequenceNumber = readInt();
00299         Assert(i == sequenceNumber);
00300         openChunk();
00301         for(int j = 0; j < boneCount; j++){
00302             skipWord("bone");
00303             int boneNumber = readInt();
00304             Assert(j == boneNumber);
00305             openChunk();
00306             // スケール
00307             skipWord("scale");
00308             data->setScale(i, j, readVectorInterpolator());
00309             // 回転
00310             skipWord("rotation");
00311             data->setRotation(i, j, readRotationInterpolator());
00312             // 移動
00313             skipWord("translation");
00314             data->setTranslation(i, j, readVectorInterpolator());
00315             closeChunk();
00316         }
00317         // ループ
00318         skipWord("looped");
00319         data->setLooped(i, readBool());
00320         closeChunk();
00321     }
00322     closeChunk();
00323 }
00324 //------------------------------------------------------------------------------
00325 // アニメーションセットリンク
00326 //------------------------------------------------------------------------------
00327 // アニメーションセットリンクリストの読み込み
00328 void TextAnimationLoader::readAnimationSetLinkList(){
00329     openChunk();
00330     while(true){
00331         String token = readToken("readAnimationSetLinkList()");
00332         if(token == "}"){ break; }
00333         readAnimationSetLink(token);
00334     }
00335 }
00336 //------------------------------------------------------------------------------
00337 // アニメーションセットリンクの読み込み
00338 void TextAnimationLoader::readAnimationSetLink(const String& name){
00339     AnimationSet* animationSet = NULL;
00340     Animation* animation = manager_->search(name);
00341     if(animation != NULL){ animationSet = animation->castAnimationSet(); }
00342     if(animationSet == NULL){
00343         ErrorOut("TextAnimationLoader::readAnimationSetLink() "
00344             "not found AnimationSet %s (line %d)",
00345             name.getBytes(), tokenizer_->getLineNumber());
00346     }
00347     openChunk();
00348     while(true){
00349         String token = readToken("readAnimationSetLink()");
00350         if(token == "}"){ break; }
00351         // アニメーションとのリンク
00352         Animation* child = manager_->search(token);
00353         if(child == NULL){
00354             ErrorOut("TextAnimationLoader::readAnimationSetLink() "
00355                 "not found animation %s (line %d)",
00356                 token.getBytes(), tokenizer_->getLineNumber());
00357         }
00358         animationSet->addAnimation(child);
00359     }
00360 }
00361 //------------------------------------------------------------------------------
00362 // カメラアニメーションリンク
00363 //------------------------------------------------------------------------------
00364 // カメラアニメーションリンクリスト読み込み
00365 void TextAnimationLoader::readCameraLinkList(){
00366     CameraAnimation* camera;
00367     CameraAnimationData* cameraData;
00368     openChunk();
00369     while(true){
00370         String token = readToken("readCameraLinkList()");
00371         if(token == "}"){ break; }
00372         Animation* animation = manager_->search(token);
00373         if(animation == NULL){
00374             ErrorOut("TextAnimationLoader::readCameraLinkList() "
00375                 "not found CameraAnimation %s (line %d)",
00376                 token.getBytes(), tokenizer_->getLineNumber());
00377         }
00378         camera = animation->castCameraAnimation();
00379         if(camera == NULL){
00380             ErrorOut("TextAnimationLoader::readCameraLinkList() "
00381                 "not found CameraAnimation %s (line %d)",
00382                 token.getBytes(), tokenizer_->getLineNumber());
00383         }
00384         String target = readToken("readCameraLinkList()");
00385         AnimationData* data = manager_->searchData(target);
00386         if(data == NULL){
00387             ErrorOut("TextAnimationLoader::readCameraLinkList() "
00388                 "not found CameraAnimationData %s (line %d)",
00389                 token.getBytes(), tokenizer_->getLineNumber());
00390         }
00391         cameraData = data->castCameraAnimationData();
00392         if(cameraData == NULL){
00393             ErrorOut("TextAnimationLoader::readCameraLinkList() "
00394                 "not found CameraAnimationData %s (line %d)",
00395                 token.getBytes(), tokenizer_->getLineNumber());
00396         }
00397         camera->setCameraAnimationData(cameraData);
00398     }
00399 }
00400 //------------------------------------------------------------------------------
00401 // シーンノードアニメーションリンク
00402 //------------------------------------------------------------------------------
00403 // シーンノードアニメーションリンクリスト読み込み
00404 void TextAnimationLoader::readSceneNodeLinkList(){
00405     SceneNodeAnimation* sceneNode;
00406     SceneNodeAnimationData* sceneNodeData;
00407     openChunk();
00408     while(true){
00409         String token = readToken("readSceneNodeLinkList()");
00410         if(token == "}"){ break; }
00411         Animation* animation = manager_->search(token);
00412         if(animation == NULL){
00413             ErrorOut("TextAnimationLoader::readSceneNodeLinkList() "
00414                 "not found SceneNodeAnimation %s (line %d)",
00415                 token.getBytes(), tokenizer_->getLineNumber());
00416         }
00417         sceneNode = animation->castSceneNodeAnimation();
00418         if(sceneNode == NULL){
00419             ErrorOut("TextAnimationLoader::readSceneNodeLinkList() "
00420                 "not found SceneNodeAnimation %s (line %d)",
00421                 token.getBytes(), tokenizer_->getLineNumber());
00422         }
00423         String target = readToken("readSceneNodeLinkList()");
00424         AnimationData* data = manager_->searchData(target);
00425         if(data == NULL){
00426             ErrorOut("TextAnimationLoader::readSceneNodeLinkList() "
00427                 "not found SceneNodeAnimationData %s (line %d)",
00428                 token.getBytes(), tokenizer_->getLineNumber());
00429         }
00430         sceneNodeData = data->castSceneNodeAnimationData();
00431         if(sceneNodeData == NULL){
00432             ErrorOut("TextAnimationLoader::readSceneNodeLinkList() "
00433                 "not found SceneNodeAnimationData %s (line %d)",
00434                 token.getBytes(), tokenizer_->getLineNumber());
00435         }
00436         sceneNode->setSceneNodeAnimationData(sceneNodeData);
00437     }
00438 }
00439 //------------------------------------------------------------------------------
00440 // キャラクタモデルアニメーションリンク
00441 //------------------------------------------------------------------------------
00442 // キャラクタモデルアニメーションリンクリスト読み込み
00443 void TextAnimationLoader::readCharacterModelLinkList(){
00444     CharacterModelAnimation* characterModel;
00445     CharacterModelAnimationData* characterModelData;
00446     openChunk();
00447     while(true){
00448         String token = readToken("readCharacterModelLinkList()");
00449         if(token == "}"){ break; }
00450         Animation* animation = manager_->search(token);
00451         if(animation == NULL){
00452             ErrorOut("TextAnimationLoader::readCharacterModelLinkList() "
00453                 "not found CharacterModelAnimation %s (line %d)",
00454                 token.getBytes(), tokenizer_->getLineNumber());
00455         }
00456         characterModel = animation->castCharacterModelAnimation();
00457         if(characterModel == NULL){
00458             ErrorOut("TextAnimationLoader::readCharacterModelLinkList() "
00459                 "not found CharacterModelAnimation %s (line %d)",
00460                 token.getBytes(), tokenizer_->getLineNumber());
00461         }
00462         String target = readToken("readCharacterModelLinkList()");
00463         AnimationData* data = manager_->searchData(target);
00464         if(data == NULL){
00465             ErrorOut("TextAnimationLoader::readCharacterModelLinkList() "
00466                 "not found CharacterModelAnimationData %s (line %d)",
00467                 token.getBytes(), tokenizer_->getLineNumber());
00468         }
00469         characterModelData = data->castCharacterModelAnimationData();
00470         if(characterModelData == NULL){
00471             ErrorOut("TextAnimationLoader::readCharacterModelLinkList() "
00472                 "not found CharacterModelAnimationData %s (line %d)",
00473                 token.getBytes(), tokenizer_->getLineNumber());
00474         }
00475         characterModel->setCharacterModelAnimationData(characterModelData);
00476     }
00477 }
00478 //------------------------------------------------------------------------------
00479 // 値の読み込み
00480 //------------------------------------------------------------------------------
00481 // bool値の読み込み
00482 bool TextAnimationLoader::readBool(){
00483     String token = readToken("readBool()");
00484     if(token == "true"){ return true; }
00485     else if(token == "false"){ return false; }
00486     ErrorOut("TextAnimationLoader::readBool() invalid token %s (line %d)",
00487         token.getBytes(), tokenizer_->getLineNumber());
00488     return false;
00489 }
00490 //------------------------------------------------------------------------------
00491 // int値の読み込み
00492 int TextAnimationLoader::readInt(){
00493     String token = readToken("readInt()");
00494     int value = 0;
00495     bool result = token.parseInt(&value);
00496     if(!result){
00497         ErrorOut("TextAnimationLoader::readInt() invalid token %s (line %d)",
00498             token.getBytes(), tokenizer_->getLineNumber());
00499     }
00500     return value;
00501 }
00502 //------------------------------------------------------------------------------
00503 // float値の読み込み
00504 float TextAnimationLoader::readFloat(){
00505     String token = readToken("readFloat()");
00506     float value = 0.f;
00507     bool result = token.parseFloat(&value);
00508     if(!result){
00509         ErrorOut("TextAnimationLoader::readFloat() invalid token %s (line %d)",
00510             token.getBytes(), tokenizer_->getLineNumber());
00511     }
00512     return value;
00513 }
00514 //------------------------------------------------------------------------------
00515 // Vector3値の読み込み
00516 Vector3 TextAnimationLoader::readVector3(){
00517     Vector3 result;
00518     openChunk();
00519     result.x = readFloat();
00520     result.y = readFloat();
00521     result.z = readFloat();
00522     closeChunk();
00523     return result;
00524 }
00525 //------------------------------------------------------------------------------
00526 // Quaternion値の読み込み
00527 Quaternion TextAnimationLoader::readQuaternion(){
00528     Quaternion result;
00529     openChunk();
00530     result.x = readFloat();
00531     result.y = readFloat();
00532     result.z = readFloat();
00533     result.w = readFloat();
00534     closeChunk();
00535     return result;
00536 }
00537 //------------------------------------------------------------------------------
00538 // ベクトル補間の読み込み
00539 //------------------------------------------------------------------------------
00540 // ベクトル補間の読み込み
00541 VectorInterpolator* TextAnimationLoader::readVectorInterpolator(){
00542     String token = readToken("readVectorInterpolator()");
00543     // NULLチェック
00544     if(token.equals("NULL")){
00545         return NULL;
00546     }else if(token.equals("{")){
00547         // タイプチェック
00548         skipWord("type");
00549         String type = readToken("readVectorInterpolator()");
00550         if(type.equals("Constant")){
00551             return readVectorConstantInterpolator();
00552         }else if(type.equals("Array")){
00553             return readVectorArrayInterpolator();
00554         }else if(type.equals("Linear")){
00555             return readVectorLinearInterpolator();
00556         }else{
00557             ErrorOut("TextAnimationLoader::readVectorInterpolator() "
00558                 "Unknown interpolator type %s (line %d)",
00559                 token.getBytes(), tokenizer_->getLineNumber());
00560         }
00561     }else{
00562         ErrorOut("TextAnimationLoader::readVectorInterpolator() "
00563             "invalid token %s (line %d)",
00564             token.getBytes(), tokenizer_->getLineNumber());
00565     }
00566     return NULL;
00567 }
00568 //------------------------------------------------------------------------------
00569 // ベクトル定数補間の読み込み
00570 VectorInterpolator* TextAnimationLoader::readVectorConstantInterpolator(){
00571     VectorConstantInterpolator* interpolator = new VectorConstantInterpolator();
00572     skipWord("length");
00573     interpolator->setLength(readFloat());
00574     skipWord("value");
00575     interpolator->setValue(readVector3());
00576     closeChunk();
00577     return interpolator;
00578 }
00579 //------------------------------------------------------------------------------
00580 // ベクトル配列補間の読み込み
00581 VectorInterpolator* TextAnimationLoader::readVectorArrayInterpolator(){
00582     VectorArrayInterpolator* interpolator = new VectorArrayInterpolator();
00583     skipWord("value");
00584     int size = readInt();
00585     interpolator->setSize(size);
00586     openChunk();
00587     for(int i = 0; i < size; i++){ interpolator->setValue(i, readVector3()); }
00588     closeChunk();
00589     closeChunk();
00590     return interpolator;
00591 }
00592 //------------------------------------------------------------------------------
00593 // ベクトル線形補間の読み込み
00594 VectorInterpolator* TextAnimationLoader::readVectorLinearInterpolator(){
00595     VectorLinearInterpolator* interpolator = new VectorLinearInterpolator();
00596     skipWord("value");
00597     int keyCount = readInt();
00598     interpolator->setKeyCount(keyCount);
00599     openChunk();
00600     for(int i = 0; i < keyCount; i++){
00601         float time = readFloat();
00602         interpolator->setKey(i, time, readVector3());
00603     }
00604     closeChunk();
00605     closeChunk();
00606     return interpolator;
00607 }
00608 //------------------------------------------------------------------------------
00609 // 回転補間の読み込み
00610 //------------------------------------------------------------------------------
00611 // 回転補間の読み込み
00612 RotationInterpolator* TextAnimationLoader::readRotationInterpolator(){
00613     String token = readToken("readRotationInterpolator()");
00614     // NULLチェック
00615     if(token.equals("NULL")){
00616         return NULL;
00617     }else if(token.equals("{")){
00618         // タイプチェック
00619         skipWord("type");
00620         String type = readToken("readRotationInterpolator()");
00621         if(type.equals("Constant")){
00622             return readRotationConstantInterpolator();
00623         }else if(type.equals("EulerArray")){
00624             return readEulerArrayInterpolator();
00625         }else if(type.equals("QuaternionArray")){
00626             return readQuaternionArrayInterpolator();
00627         }else if(type.equals("QuaternionLinear")){
00628             return readQuaternionLinearInterpolator();
00629         }else{
00630             ErrorOut("TextAnimationLoader::readRotationInterpolator() "
00631                 "Unknown interpolator type %s (line %d)",
00632                 token.getBytes(), tokenizer_->getLineNumber());
00633         }
00634     }else{
00635         ErrorOut("TextAnimationLoader::readRotationInterpolator() "
00636             "invalid token %s (line %d)",
00637             token.getBytes(), tokenizer_->getLineNumber());
00638     }
00639     return NULL;
00640 }
00641 //------------------------------------------------------------------------------
00642 // 回転定数補間の読み込み
00643 RotationInterpolator* TextAnimationLoader::readRotationConstantInterpolator(){
00644     RotationConstantInterpolator* interpolator =
00645         new RotationConstantInterpolator();
00646     skipWord("length");
00647     interpolator->setLength(readFloat());
00648     String valueType = readToken("readRotationConstantInterpolator()");
00649     if(valueType.equals("quaternionValue")){
00650         interpolator->setQuaternion(readQuaternion());
00651     }else if(valueType.equals("eulerValue")){
00652         interpolator->setEuler(readVector3());
00653     }else{
00654         ErrorOut("TextAnimationLoader::readRotationConstantInterpolator() "
00655             "Unknown value type %s (line %d)",
00656             valueType.getBytes(), tokenizer_->getLineNumber());
00657     }
00658     closeChunk();
00659     return interpolator;
00660 }
00661 //------------------------------------------------------------------------------
00662 // オイラー回転配列補間の読み込み
00663 RotationInterpolator* TextAnimationLoader::readEulerArrayInterpolator(){
00664     EulerArrayInterpolator* interpolator =
00665         new EulerArrayInterpolator();
00666     skipWord("value");
00667     int size = readInt();
00668     interpolator->setSize(size);
00669     openChunk();
00670     for(int i = 0; i < size; i++){ interpolator->setValue(i, readVector3()); }
00671     closeChunk();
00672     closeChunk();
00673     return interpolator;
00674 }
00675 //------------------------------------------------------------------------------
00676 // 四元数回転配列補間の読み込み
00677 RotationInterpolator* TextAnimationLoader::readQuaternionArrayInterpolator(){
00678     QuaternionArrayInterpolator* interpolator =
00679         new QuaternionArrayInterpolator();
00680     skipWord("value");
00681     int size = readInt();
00682     interpolator->setSize(size);
00683     openChunk();
00684     for(int i = 0; i < size; i++){
00685         interpolator->setValue(i, readQuaternion());
00686     }
00687     closeChunk();
00688     closeChunk();
00689     return interpolator;
00690 }
00691 //------------------------------------------------------------------------------
00692 // 四元数回転線形補間の読み込み
00693 RotationInterpolator* TextAnimationLoader::readQuaternionLinearInterpolator(){
00694     QuaternionLinearInterpolator* interpolator =
00695         new QuaternionLinearInterpolator();
00696     skipWord("value");
00697     int keyCount = readInt();
00698     interpolator->setKeyCount(keyCount);
00699     openChunk();
00700     for(int i = 0; i < keyCount; i++){
00701         float time = readFloat();
00702         interpolator->setKey(i, time, readQuaternion());
00703     }
00704     closeChunk();
00705     closeChunk();
00706     return interpolator;
00707 }
00708 //------------------------------------------------------------------------------
00709 // ユーティリティ
00710 //------------------------------------------------------------------------------
00711 // トークンの読み込み
00712 String TextAnimationLoader::readToken(const String& caller){
00713     bool hasNext = tokenizer_->nextToken();
00714     if(!hasNext){
00715         ErrorOut("TextAnimationLoader::%s nothing token (line %d)",
00716             caller.getBytes(), tokenizer_->getLineNumber());
00717     }
00718     return tokenizer_->getToken();
00719 }
00720 //------------------------------------------------------------------------------
00721 // 指定ワードの読み飛ばし
00722 void TextAnimationLoader::skipWord(const String& word){
00723     String token = readToken("skipWord()");
00724     if(token != word){
00725         ErrorOut("TextAnimationLoader::skipWord(%s) "
00726             "invalid token %s (line %d)",
00727             word.getBytes(), token.getBytes(), tokenizer_->getLineNumber());
00728     }
00729 }
00730 //------------------------------------------------------------------------------
00731 } // End of namespace Lamp
00732 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:37 2005 for Lamp by doxygen 1.3.2