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

# TranslationTextureManager.cpp

Go to the documentation of this file.

    00001 //------------------------------------------------------------------------------
    00002 // Lamp : Open source game middleware
    00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
    00004 //
    00005 // This library is free software; you can redistribute it and/or
    00006 // modify it under the terms of the GNU Lesser General Public
    00007 // License as published by the Free Software Foundation; either
    00008 // version 2.1 of the License, or (at your option) any later version.
    00009 //
    00010 // This library is distributed in the hope that it will be useful,
    00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013 // Lesser General Public License for more details.
    00014 //
    00015 // You should have received a copy of the GNU Lesser General Public
    00016 // License along with this library; if not, write to the Free Software
    00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00018 //------------------------------------------------------------------------------
    00019
    00020 /** @file
    00021  * 変換テクスチャマネージャ実装
    00022  * @author Junpee
    00023  */
    00024
    00025 #include "System/stdafx.h"
    00026 #include "Translator/Texture/TranslationTextureManager.h"
    00027
    00028 namespace LampForMaya{
    00029
    00030 //------------------------------------------------------------------------------
    00031 // コンストラクタ
    00032 TranslationTextureManager::TranslationTextureManager() :
    00033     database_(256, 0.75f), array_(256){
    00034 }
    00035 //------------------------------------------------------------------------------
    00036 // デストラクタ
    00037 TranslationTextureManager::~TranslationTextureManager(){
    00038     Assert(database_.getCount() == 0);
    00039     Assert(array_.getCount() == 0);
    00040     if(getCount() != 0){ clear(); }
    00041 }
    00042 //------------------------------------------------------------------------------
    00043 // テクスチャの収集
    00044 bool TranslationTextureManager::collectTextures(){
    00045     MStatus result;
    00046     MItDependencyNodes dependencyNodeIterator(MFn::kFileTexture, &result);
    00047     MayaStatusCheck(result);
    00048     for( ; !dependencyNodeIterator.isDone(); dependencyNodeIterator.next()){
    00049         MObject textureObject = dependencyNodeIterator.item(&result);
    00050         MayaStatusCheck(result);
    00051         if(!analysisTexture(textureObject)){ return false; }
    00052     }
    00053     return true;
    00054 }
    00055 //------------------------------------------------------------------------------
    00056 // テクスチャの解析
    00057 bool TranslationTextureManager::analysisTexture(const MObject& textureObject){
    00058     MStatus result;
    00059     MFnDependencyNode textureNode(textureObject, &result);
    00060     MayaStatusCheck(result);
    00061     String textureName = textureNode.name(&result).asChar();
    00062     MayaStatusCheck(result);
    00063     // 名前の重複が無いかチェック
    00064     TranslationTexture* exist = database_.get(textureName);
    00065     if(exist != NULL){
    00066         MayaErrorOut(String("TranslationTextureManager::analysisTexture() "
    00067             "名前が重複しています ") + textureName);
    00068         return false;
    00069     }
    00070     TranslationTexture* texture =
    00071         new TranslationTexture(textureObject, textureName);
    00072     if(!texture->analyze()){
    00073         delete texture;
    00074         return false;
    00075     }
    00076     database_.put(textureName, texture);
    00077     array_.add(texture);
    00078     return true;
    00079 }
    00080 //------------------------------------------------------------------------------
    00081 // Lampへの変換
    00082 bool TranslationTextureManager::convertToLamp(Scene* scene) const{
    00083     for(int i = 0; i < getCount(); i++){
    00084         if(!get(i)->convertToLamp(scene)){ return false; }
    00085     }
    00086     return true;
    00087 }
    00088 //------------------------------------------------------------------------------
    00089 // クリア
    00090 int TranslationTextureManager::clear(){
    00091     int result = getCount();
    00092     // 要素の削除
    00093     for(int i = 0; i < result; i++){ delete array_.get(i); }
    00094     array_.clear();
    00095     database_.clear();
    00096     return result;
    00097 }
    00098 //------------------------------------------------------------------------------
    00099 } // End of namespace LampForMaya
    00100 //------------------------------------------------------------------------------