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

# TranslationMaterialManager.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/Material/TranslationMaterialManager.h"
    00027 #include "Translator/Material/TranslationBasicMaterial.h"
    00028 #include "Material/Basic/LampBasicMaterial.h"
    00029
    00030 namespace LampForMaya{
    00031
    00032 //------------------------------------------------------------------------------
    00033 // コンストラクタ
    00034 TranslationMaterialManager::TranslationMaterialManager() :
    00035     database_(256, 0.75f), array_(256){
    00036 }
    00037 //------------------------------------------------------------------------------
    00038 // デストラクタ
    00039 TranslationMaterialManager::~TranslationMaterialManager(){
    00040     Assert(database_.getCount() == 0);
    00041     Assert(array_.getCount() == 0);
    00042     if(getCount() != 0){ clear(); }
    00043 }
    00044 //------------------------------------------------------------------------------
    00045 // マテリアルの収集
    00046 bool TranslationMaterialManager::collectMaterials(){
    00047     MStatus result;
    00048     // ハードウェアマテリアルノードのイテレータはバグっているっぽい
    00049 //  MItDependencyNodes dependencyNodeIterator(MFn::kHwMaterialNode, &result);
    00050     MItDependencyNodes dependencyNodeIterator(MFn::kInvalid, &result);
    00051     MayaStatusCheck(result);
    00052     for( ; !dependencyNodeIterator.isDone(); dependencyNodeIterator.next()){
    00053         MObject materialObject = dependencyNodeIterator.item(&result);
    00054         MayaStatusCheck(result);
    00055         if(!analysisMaterial(materialObject)){ return false; }
    00056     }
    00057     return true;
    00058 }
    00059 //------------------------------------------------------------------------------
    00060 // マテリアルの解析
    00061 bool TranslationMaterialManager::analysisMaterial(const MObject& materialObject){
    00062     MStatus result;
    00063     MFnDependencyNode materialNode(materialObject, &result);
    00064     MayaStatusCheck(result);
    00065     // TypeIDチェック
    00066     MTypeId typeID = materialNode.typeId(&result);
    00067     MayaStatusCheck(result);
    00068     // マテリアルのふるいわけ
    00069     if(typeID != LampBasicMaterial::id){
    00070         return true;
    00071     }
    00072     // 名前の重複が無いかチェック
    00073     String materialName = materialNode.name(&result).asChar();
    00074     MayaStatusCheck(result);
    00075     TranslationMaterial* exist = database_.get(materialName);
    00076     if(exist != NULL){
    00077         MayaErrorOut(String("TranslationMaterialManager::analysisMaterial() "
    00078             "名前が重複しています ") + materialName);
    00079         return false;
    00080     }
    00081     // マテリアル構築
    00082     TranslationMaterial* material = NULL;
    00083     if(typeID == LampBasicMaterial::id){
    00084         material = new TranslationBasicMaterial(materialObject, materialName);
    00085     }
    00086     if(!material->analyze()){
    00087         delete material;
    00088         return false;
    00089     }
    00090     database_.put(materialName, material);
    00091     array_.add(material);
    00092     return true;
    00093 }
    00094 //------------------------------------------------------------------------------
    00095 // Lampへの変換
    00096 bool TranslationMaterialManager::convertToLamp(Scene* scene) const{
    00097     for(int i = 0; i < getCount(); i++){
    00098         if(!get(i)->convertToLamp(scene)){ return false; }
    00099     }
    00100     return true;
    00101 }
    00102 //------------------------------------------------------------------------------
    00103 // クリア
    00104 int TranslationMaterialManager::clear(){
    00105     int result = getCount();
    00106     // 要素の削除
    00107     for(int i = 0; i < result; i++){ delete array_.get(i); }
    00108     array_.clear();
    00109     database_.clear();
    00110     return result;
    00111 }
    00112 //------------------------------------------------------------------------------
    00113 } // End of namespace LampForMaya
    00114 //------------------------------------------------------------------------------