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

# BinaryAnimationSaver.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/BinaryAnimationSaver.h"
    00027 #include "Core/InputOutput/BinaryFileWriter.h"
    00028 #include "Animation/VectorInterpolator/VectorConstantInterpolator.h"
    00029 #include "Animation/VectorInterpolator/VectorArrayInterpolator.h"
    00030 #include "Animation/VectorInterpolator/VectorLinearInterpolator.h"
    00031 #include "Animation/RotationInterpolator/RotationConstantInterpolator.h"
    00032 #include "Animation/RotationInterpolator/EulerArrayInterpolator.h"
    00033 #include "Animation/RotationInterpolator/QuaternionArrayInterpolator.h"
    00034 #include "Animation/RotationInterpolator/QuaternionLinearInterpolator.h"
    00035
    00036 #include "Animation/System/AnimationManager.h"
    00037 #include "Animation/System/AnimationSet.h"
    00038 #include "Animation/Camera/CameraAnimation.h"
    00039 #include "Animation/SceneNode/SceneNodeAnimation.h"
    00040 #include "Animation/Model/CharacterModelAnimation.h"
    00041
    00042 namespace Lamp{
    00043
    00044 //------------------------------------------------------------------------------
    00045 // コンストラクタ
    00046 BinaryAnimationSaver::BinaryAnimationSaver(){
    00047 }
    00048 //------------------------------------------------------------------------------
    00049 // デストラクタ
    00050 BinaryAnimationSaver::~BinaryAnimationSaver(){
    00051 }
    00052 //------------------------------------------------------------------------------
    00053 // セーブ
    00054 //------------------------------------------------------------------------------
    00055 // セーブ
    00056 void BinaryAnimationSaver::save(
    00057     const String& filePath, AnimationManager* manager){
    00058     BinaryFileWriter* binaryFileWriter = new BinaryFileWriter(filePath);
    00059     save(binaryFileWriter, manager);
    00060     delete binaryFileWriter;
    00061 }
    00062 //------------------------------------------------------------------------------
    00063 // セーブ
    00064 void BinaryAnimationSaver::save(
    00065     BinaryWriter* binaryWriter, AnimationManager* manager){
    00066     Assert((binaryWriter != NULL) && (manager != NULL))
    00067     writer_ = binaryWriter;
    00068     manager_ = manager;
    00069
    00070     // ヘッダの書き出し
    00071     writeHeader();
    00072     // オブジェクトのカウント
    00073     if(countObjects() == 0){ return; }
    00074
    00075     // アニメーションリストの書き出し
    00076     writeAnimationList();
    00077     // リンクの書き出し
    00078     writeLink();
    00079 }
    00080 //------------------------------------------------------------------------------
    00081 // ヘッダの書き出し
    00082 void BinaryAnimationSaver::writeHeader(){
    00083     writeString("LampBinaryAnimation");
    00084     u_int version = 0x00000900;
    00085     writer_->writeUInt(version);
    00086     // アライメント
    00087     align();
    00088 }
    00089 //------------------------------------------------------------------------------
    00090 // オブジェクトのカウント
    00091 int BinaryAnimationSaver::countObjects(){
    00092     // アニメーションカウントクリア
    00093     clearObjectCount();
    00094     // 各アニメーションのカウント
    00095     animationCount_ = manager_->getCount();
    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("BinaryAnimationSaver::countObjects() "
    00108                 "Unsupported animation type");
    00109         }
    00110     }
    00111     // 各アニメーションデータのカウント
    00112     animationDataCount_ = manager_->getDataCount();
    00113     for(int i = 0; i < animationDataCount_; i++){
    00114         AnimationData* data = manager_->getData(i);
    00115         if(data->isCameraAnimationData()){
    00116             cameraDataCount_++;
    00117         }else if(data->isSceneNodeAnimationData()){
    00118             sceneNodeDataCount_++;
    00119         }else if(data->isCharacterModelAnimationData()){
    00120             characterModelDataCount_++;
    00121         }else{
    00122             ErrorOut("BinaryAnimationSaver::countObjects() "
    00123                 "Unsupported animation data type");
    00124         }
    00125     }
    00126     return (animationCount_ + animationDataCount_);
    00127 }
    00128 //------------------------------------------------------------------------------
    00129 // アニメーションリスト
    00130 //------------------------------------------------------------------------------
    00131 // アニメーションリストの書き出し
    00132 void BinaryAnimationSaver::writeAnimationList(){
    00133     // アニメーションセットの書き出し
    00134     if(animationSetCount_ != 0){
    00135         int startAddress = startBlock("AnimationSet");
    00136         for(int i = 0; i < animationCount_; i++){
    00137             Animation* animation = manager_->get(i);
    00138             if(animation->isAnimationSet()){
    00139                 writeAnimationSet(animation->castAnimationSet());
    00140             }
    00141         }
    00142         endBlock(startAddress, animationSetCount_);
    00143     }
    00144     // カメラアニメーションの書き出し
    00145     if(cameraCount_ != 0){
    00146         int startAddress = startBlock("Camera");
    00147         for(int i = 0; i < animationCount_; i++){
    00148             Animation* animation = manager_->get(i);
    00149             if(animation->isCameraAnimation()){
    00150                 writeCameraAnimation(animation->castCameraAnimation());
    00151             }
    00152         }
    00153         endBlock(startAddress, cameraCount_);
    00154     }
    00155     // カメラアニメーションデータの書き出し
    00156     if(cameraDataCount_ != 0){
    00157         int startAddress = startBlock("CameraData");
    00158         for(int i = 0; i < animationDataCount_; i++){
    00159             AnimationData* data = manager_->getData(i);
    00160             if(data->isCameraAnimationData()){
    00161                 writeCameraAnimationData(
    00162                     data->castCameraAnimationData());
    00163             }
    00164         }
    00165         endBlock(startAddress, cameraDataCount_);
    00166     }
    00167     // シーンノードアニメーションの書き出し
    00168     if(sceneNodeCount_ != 0){
    00169         int startAddress = startBlock("SceneNode");
    00170         for(int i = 0; i < animationCount_; i++){
    00171             Animation* animation = manager_->get(i);
    00172             if(animation->isSceneNodeAnimation()){
    00173                 writeSceneNodeAnimation(animation->castSceneNodeAnimation());
    00174             }
    00175         }
    00176         endBlock(startAddress, sceneNodeCount_);
    00177     }
    00178     // シーンノードアニメーションデータの書き出し
    00179     if(sceneNodeDataCount_ != 0){
    00180         int startAddress = startBlock("SceneNodeData");
    00181         for(int i = 0; i < animationDataCount_; i++){
    00182             AnimationData* data = manager_->getData(i);
    00183             if(data->isSceneNodeAnimationData()){
    00184                 writeSceneNodeAnimationData(
    00185                     data->castSceneNodeAnimationData());
    00186             }
    00187         }
    00188         endBlock(startAddress, sceneNodeDataCount_);
    00189     }
    00190     // キャラクタモデルアニメーションの書き出し
    00191     if(characterModelCount_ != 0){
    00192         int startAddress = startBlock("CharacterModel");
    00193         for(int i = 0; i < animationCount_; i++){
    00194             Animation* animation = manager_->get(i);
    00195             if(animation->isCharacterModelAnimation()){
    00196                 writeCharacterModelAnimation(
    00197                     animation->castCharacterModelAnimation());
    00198             }
    00199         }
    00200         endBlock(startAddress, characterModelCount_);
    00201     }
    00202     // キャラクタモデルアニメーションデータの書き出し
    00203     if(characterModelDataCount_ != 0){
    00204         int startAddress = startBlock("CharacterModelData");
    00205         for(int i = 0; i < animationDataCount_; i++){
    00206             AnimationData* data = manager_->getData(i);
    00207             if(data->isCharacterModelAnimationData()){
    00208                 writeCharacterModelAnimationData(
    00209                     data->castCharacterModelAnimationData());
    00210             }
    00211         }
    00212         endBlock(startAddress, characterModelDataCount_);
    00213     }
    00214 }
    00215 //------------------------------------------------------------------------------
    00216 // アニメーションセット
    00217 //------------------------------------------------------------------------------
    00218 // アニメーションセットの書き出し
    00219 void BinaryAnimationSaver::writeAnimationSet(AnimationSet* animation){
    00220     // 名前
    00221     writeString(animation->getName());
    00222     // 有効、無効
    00223     writer_->writeBool(animation->isEnabled());
    00224     // アライメント
    00225     align();
    00226 }
    00227 //------------------------------------------------------------------------------
    00228 // カメラ
    00229 //------------------------------------------------------------------------------
    00230 // カメラアニメーションの書き出し
    00231 void BinaryAnimationSaver::writeCameraAnimation(CameraAnimation* animation){
    00232     // 名前
    00233     writeString(animation->getName());
    00234     // 有効、無効
    00235     writer_->writeBool(animation->isEnabled());
    00236     // ターゲット名
    00237     writeString(animation->getTargetName());
    00238     // アライメント
    00239     align();
    00240 }
    00241 //------------------------------------------------------------------------------
    00242 // カメラアニメーションデータの書き出し
    00243 void BinaryAnimationSaver::writeCameraAnimationData(
    00244     CameraAnimationData* data){
    00245     // 名前
    00246     writeString(data->getName());
    00247     // シーケンス数
    00248     int sequenceCount = data->getSequenceCount();
    00249     writer_->writeInt(sequenceCount);
    00250     // アニメーションデータ
    00251     for(int i = 0; i < sequenceCount; i++){
    00252         // 回転
    00253         writeRotationInterpolator(data->getRotation(i));
    00254         // 移動
    00255         writeVectorInterpolator(data->getTranslation(i));
    00256     }
    00257     // ループフラグ
    00258     for(int i = 0; i < sequenceCount; i++){
    00259         writer_->writeBool(data->isLooped(i));
    00260     }
    00261     // アライメント
    00262     align();
    00263 }
    00264 //------------------------------------------------------------------------------
    00265 // シーンノード
    00266 //------------------------------------------------------------------------------
    00267 // シーンノードアニメーションの書き出し
    00268 void BinaryAnimationSaver::writeSceneNodeAnimation(
    00269     SceneNodeAnimation* animation){
    00270     // 名前
    00271     writeString(animation->getName());
    00272     // 有効、無効
    00273     writer_->writeBool(animation->isEnabled());
    00274     // ターゲット名
    00275     writeString(animation->getTargetName());
    00276     // アライメント
    00277     align();
    00278 }
    00279 //------------------------------------------------------------------------------
    00280 // シーンノードアニメーションデータの書き出し
    00281 void BinaryAnimationSaver::writeSceneNodeAnimationData(
    00282     SceneNodeAnimationData* data){
    00283     // 名前
    00284     writeString(data->getName());
    00285     // シーケンス数
    00286     int sequenceCount = data->getSequenceCount();
    00287     writer_->writeInt(sequenceCount);
    00288     // アニメーションデータ
    00289     for(int i = 0; i < sequenceCount; i++){
    00290         // スケール
    00291         writeVectorInterpolator(data->getScale(i));
    00292         // 回転
    00293         writeRotationInterpolator(data->getRotation(i));
    00294         // 移動
    00295         writeVectorInterpolator(data->getTranslation(i));
    00296     }
    00297     // ループフラグ
    00298     for(int i = 0; i < sequenceCount; i++){
    00299         writer_->writeBool(data->isLooped(i));
    00300     }
    00301     // アライメント
    00302     align();
    00303 }
    00304 //------------------------------------------------------------------------------
    00305 // キャラクタモデル
    00306 //------------------------------------------------------------------------------
    00307 // キャラクタモデルアニメーションの書き出し
    00308 void BinaryAnimationSaver::writeCharacterModelAnimation(
    00309     CharacterModelAnimation* animation){
    00310     // 名前
    00311     writeString(animation->getName());
    00312     // 有効、無効
    00313     writer_->writeBool(animation->isEnabled());
    00314     // ターゲット名
    00315     writeString(animation->getTargetName());
    00316     // ボーン数
    00317     int boneCount = animation->getBoneCount();
    00318     writer_->writeInt(boneCount);
    00319     // ボーン名
    00320     for(int i = 0; i < boneCount; i++){
    00321         writeString(animation->getBoneName(i));
    00322     }
    00323     // アライメント
    00324     align();
    00325 }
    00326 //------------------------------------------------------------------------------
    00327 // キャラクタモデルアニメーションデータの書き出し
    00328 void BinaryAnimationSaver::writeCharacterModelAnimationData(
    00329     CharacterModelAnimationData* data){
    00330     // 名前
    00331     writeString(data->getName());
    00332     // シーケンス数
    00333     int sequenceCount = data->getSequenceCount();
    00334     writer_->writeInt(sequenceCount);
    00335     // ボーン数
    00336     int boneCount = data->getBoneCount();
    00337     writer_->writeInt(boneCount);
    00338     // アニメーションデータ
    00339     for(int i = 0; i < sequenceCount; i++){
    00340         for(int j = 0; j < boneCount; j++){
    00341             // スケール
    00342             writeVectorInterpolator(data->getScale(i, j));
    00343             // 回転
    00344             writeRotationInterpolator(data->getRotation(i, j));
    00345             // 移動
    00346             writeVectorInterpolator(data->getTranslation(i, j));
    00347         }
    00348     }
    00349     // ループフラグ
    00350     for(int i = 0; i < sequenceCount; i++){
    00351         writer_->writeBool(data->isLooped(i));
    00352     }
    00353     // アライメント
    00354     align();
    00355 }
    00356 //------------------------------------------------------------------------------
    00357 // リンク
    00358 //------------------------------------------------------------------------------
    00359 // リンクの書き出し
    00360 void BinaryAnimationSaver::writeLink(){
    00361     // アニメーションセットリンク
    00362     if(animationSetCount_ != 0){
    00363         int startAddress = startBlock("AnimationSetLink");
    00364         for(int i = 0; i < animationCount_; i++){
    00365             Animation* animation = manager_->get(i);
    00366             if(animation->isAnimationSet()){
    00367                 writeAnimationSetLink(animation->castAnimationSet());
    00368             }
    00369         }
    00370         endBlock(startAddress, animationSetCount_);
    00371     }
    00372     // カメラリンク
    00373     if(cameraCount_ != 0){
    00374         int startAddress = startBlock("CameraLink");
    00375         for(int i = 0; i < animationCount_; i++){
    00376             Animation* animation = manager_->get(i);
    00377             if(animation->isCameraAnimation()){
    00378                 writeCameraAnimationLink(
    00379                     animation->castCameraAnimation());
    00380             }
    00381         }
    00382         endBlock(startAddress, cameraCount_);
    00383     }
    00384     // シーンノードリンク
    00385     if(sceneNodeCount_ != 0){
    00386         int startAddress = startBlock("SceneNodeLink");
    00387         for(int i = 0; i < animationCount_; i++){
    00388             Animation* animation = manager_->get(i);
    00389             if(animation->isSceneNodeAnimation()){
    00390                 writeSceneNodeAnimationLink(
    00391                     animation->castSceneNodeAnimation());
    00392             }
    00393         }
    00394         endBlock(startAddress, sceneNodeCount_);
    00395     }
    00396     // キャラクタモデルリンク
    00397     if(characterModelCount_ != 0){
    00398         int startAddress = startBlock("CharacterModelLink");
    00399         for(int i = 0; i < animationCount_; i++){
    00400             Animation* animation = manager_->get(i);
    00401             if(animation->isCharacterModelAnimation()){
    00402                 writeCharacterModelAnimationLink(
    00403                     animation->castCharacterModelAnimation());
    00404             }
    00405         }
    00406         endBlock(startAddress, characterModelCount_);
    00407     }
    00408 }
    00409 //------------------------------------------------------------------------------
    00410 // アニメーションセットリンクの書き出し
    00411 void BinaryAnimationSaver::writeAnimationSetLink(AnimationSet* animation){
    00412     // 名前
    00413     writeString(animation->getName());
    00414     // 子供
    00415     int childCount = animation->getAnimationCount();
    00416     writer_->writeInt(childCount);
    00417     for(int i = 0; i < childCount; i++){
    00418         writeString(animation->getAnimation(i)->getName());
    00419     }
    00420     // アライメント
    00421     align();
    00422 }
    00423 //------------------------------------------------------------------------------
    00424 // カメラアニメーションリンクの書き出し
    00425 void BinaryAnimationSaver::writeCameraAnimationLink(
    00426     CameraAnimation* animation){
    00427     // 名前
    00428     writeString(animation->getName());
    00429     // データの名前
    00430     writeString(animation->getAnimationData()->getName());
    00431     // アライメント
    00432     align();
    00433 }
    00434 //------------------------------------------------------------------------------
    00435 // シーンノードアニメーションリンクの書き出し
    00436 void BinaryAnimationSaver::writeSceneNodeAnimationLink(
    00437     SceneNodeAnimation* animation){
    00438     // 名前
    00439     writeString(animation->getName());
    00440     // データの名前
    00441     writeString(animation->getAnimationData()->getName());
    00442     // アライメント
    00443     align();
    00444 }
    00445 //------------------------------------------------------------------------------
    00446 // キャラクタモデルアニメーションリンクの書き出し
    00447 void BinaryAnimationSaver::writeCharacterModelAnimationLink(
    00448     CharacterModelAnimation* animation){
    00449     // 名前
    00450     writeString(animation->getName());
    00451     // データの名前
    00452     writeString(animation->getAnimationData()->getName());
    00453     // アライメント
    00454     align();
    00455 }
    00456 //------------------------------------------------------------------------------
    00457 // 値の書き出し
    00458 //------------------------------------------------------------------------------
    00459 // 文字列の書き出し
    00460 void BinaryAnimationSaver::writeString(const String& string){
    00461     int writeSize = string.getSize() + 1;
    00462     writer_->writeInt(writeSize);
    00463     writer_->writeBytes(string.getBytes(), writeSize);
    00464     align();
    00465 }
    00466 //------------------------------------------------------------------------------
    00467 // 三次元ベクトルの書き出し
    00468 void BinaryAnimationSaver::writeVector3(const Vector3& vector){
    00469     writer_->writeBytes(vector.array, sizeof(Vector3));
    00470 }
    00471 //------------------------------------------------------------------------------
    00472 // 四元数の書き出し
    00473 void BinaryAnimationSaver::writeQuaternion(const Quaternion& quaternion){
    00474     writer_->writeBytes(quaternion.array, sizeof(Quaternion));
    00475 }
    00476 //------------------------------------------------------------------------------
    00477 // ベクトル補間
    00478 //------------------------------------------------------------------------------
    00479 // ベクトル補間の書き出し
    00480 void BinaryAnimationSaver::writeVectorInterpolator(
    00481     VectorInterpolator* interpolator){
    00482     // NULL対応
    00483     if(interpolator == NULL){
    00484         // NULL対応
    00485         writer_->writeInt(0);
    00486     }else if(interpolator->isVectorConstantInterpolator()){
    00487         writer_->writeInt(1);
    00488         writeVectorConstantInterpolator(
    00489             interpolator->castVectorConstantInterpolator());
    00490     }else if(interpolator->isVectorArrayInterpolator()){
    00491         writer_->writeInt(2);
    00492         writeVectorArrayInterpolator(
    00493             interpolator->castVectorArrayInterpolator());
    00494     }else if(interpolator->isVectorLinearInterpolator()){
    00495         writer_->writeInt(3);
    00496         writeVectorLinearInterpolator(
    00497             interpolator->castVectorLinearInterpolator());
    00498     }else{
    00499         ErrorOut("BinaryAnimationSaver::writeVectorInterpolator() "
    00500             "Unsupported interpolater");
    00501     }
    00502 }
    00503 //------------------------------------------------------------------------------
    00504 // ベクトル定数補間の書き出し
    00505 void BinaryAnimationSaver::writeVectorConstantInterpolator(
    00506     VectorConstantInterpolator* interpolator){
    00507     // 長さ
    00508     writer_->writeFloat(interpolator->getLength());
    00509     // 値
    00510     writeVector3(interpolator->getValue());
    00511 }
    00512 //------------------------------------------------------------------------------
    00513 // ベクトル配列補間の書き出し
    00514 void BinaryAnimationSaver::writeVectorArrayInterpolator(
    00515     VectorArrayInterpolator* interpolator){
    00516     // 値
    00517     int size = interpolator->getSize();
    00518     writer_->writeInt(size);
    00519     for(int i = 0; i < size; i++){ writeVector3(interpolator->getValue(i)); }
    00520 }
    00521 //------------------------------------------------------------------------------
    00522 // ベクトル線形補間の書き出し
    00523 void BinaryAnimationSaver::writeVectorLinearInterpolator(
    00524     VectorLinearInterpolator* interpolator){
    00525     // 値
    00526     int keyCount = interpolator->getKeyCount();
    00527     writer_->writeInt(keyCount);
    00528     for(int i = 0; i < keyCount; i++){
    00529         writer_->writeFloat(interpolator->getTime(i));
    00530         writeVector3(interpolator->getValue(i));
    00531     }
    00532 }
    00533 //------------------------------------------------------------------------------
    00534 // 回転補間
    00535 //------------------------------------------------------------------------------
    00536 // 回転補間の書き出し
    00537 void BinaryAnimationSaver::writeRotationInterpolator(
    00538     RotationInterpolator* interpolator){
    00539     if(interpolator == NULL){
    00540         // NULL対応
    00541         writer_->writeInt(0);
    00542     }else if(interpolator->isRotationConstantInterpolator()){
    00543         writer_->writeInt(1);
    00544         writeRotationConstantInterpolator(
    00545             interpolator->castRotationConstantInterpolator());
    00546     }else if(interpolator->isEulerArrayInterpolator()){
    00547         writer_->writeInt(2);
    00548         writeEulerArrayInterpolator(
    00549             interpolator->castEulerArrayInterpolator());
    00550     }else if(interpolator->isQuaternionArrayInterpolator()){
    00551         writer_->writeInt(3);
    00552         writeQuaternionArrayInterpolator(
    00553             interpolator->castQuaternionArrayInterpolator());
    00554     }else if(interpolator->isQuaternionLinearInterpolator()){
    00555         writer_->writeInt(4);
    00556         writeQuaternionLinearInterpolator(
    00557             interpolator->castQuaternionLinearInterpolator());
    00558     }else{
    00559         ErrorOut("BinaryAnimationSaver::writeRotationInterpolator() "
    00560             "Unsupported interpolater");
    00561     }
    00562 }
    00563 //------------------------------------------------------------------------------
    00564 // 回転定数補間の書き出し
    00565 void BinaryAnimationSaver::writeRotationConstantInterpolator(
    00566     RotationConstantInterpolator* interpolator){
    00567     // 長さ
    00568     writer_->writeFloat(interpolator->getLength());
    00569     // 値
    00570     writeQuaternion(interpolator->getQuaternion());
    00571 }
    00572 //------------------------------------------------------------------------------
    00573 // オイラー回転配列補間の書き出し
    00574 void BinaryAnimationSaver::writeEulerArrayInterpolator(
    00575     EulerArrayInterpolator* interpolator){
    00576     // 値
    00577     int size = interpolator->getSize();
    00578     writer_->writeInt(size);
    00579     for(int i = 0; i < size; i++){ writeVector3(interpolator->getValue(i)); }
    00580 }
    00581 //------------------------------------------------------------------------------
    00582 // 四元数回転配列補間の書き出し
    00583 void BinaryAnimationSaver::writeQuaternionArrayInterpolator(
    00584     QuaternionArrayInterpolator* interpolator){
    00585     // 値
    00586     int size = interpolator->getSize();
    00587     writer_->writeInt(size);
    00588     for(int i = 0; i < size; i++){ writeQuaternion(interpolator->getValue(i)); }
    00589 }
    00590 //------------------------------------------------------------------------------
    00591 // 四元数回転線形補間の書き出し
    00592 void BinaryAnimationSaver::writeQuaternionLinearInterpolator(
    00593     QuaternionLinearInterpolator* interpolator){
    00594     // 値
    00595     int keyCount = interpolator->getKeyCount();
    00596     writer_->writeInt(keyCount);
    00597     for(int i = 0; i < keyCount; i++){
    00598         writer_->writeFloat(interpolator->getTime(i));
    00599         writeQuaternion(interpolator->getValue(i));
    00600     }
    00601 }
    00602 //------------------------------------------------------------------------------
    00603 // ユーティリティ
    00604 //------------------------------------------------------------------------------
    00605 // アライメントを取る
    00606 void BinaryAnimationSaver::align(){
    00607     // 変更した場合はendBlock()に修正が必要
    00608     writer_->align(16);
    00609 }
    00610 //------------------------------------------------------------------------------
    00611 // ブロックの開始
    00612 int BinaryAnimationSaver::startBlock(const String& blockName){
    00613     writeString(blockName);
    00614     // ブロックサイズの予約
    00615     int blockAddress = writer_->getPosition();
    00616     writer_->writeInt(0);
    00617     // オブジェクト数の予約
    00618     writer_->writeInt(0);
    00619     align();
    00620     return blockAddress;
    00621 }
    00622 //------------------------------------------------------------------------------
    00623 // ブロックの終了
    00624 void BinaryAnimationSaver::endBlock(int blockStartAddress, int objectCount){
    00625     align();
    00626     int blockEndPosition = writer_->getPosition();
    00627     // ブロックヘッダ内容をブロックサイズから引く、アライメント依存
    00628     int blockSize = blockEndPosition - blockStartAddress - (sizeof(int) * 4);
    00629     writer_->setPosition(blockStartAddress);
    00630     // ブロックサイズ書き込み
    00631     writer_->writeInt(blockSize);
    00632     // オブジェクト数書き込み
    00633     writer_->writeInt(objectCount);
    00634     // カーソルを戻す
    00635     writer_->setPosition(blockEndPosition);
    00636 }
    00637 //------------------------------------------------------------------------------
    00638 } // End of namespace Lamp
    00639 //------------------------------------------------------------------------------