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

# TranslationLightManager.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/Light/TranslationLightManager.h"
    00027
    00028 namespace LampForMaya{
    00029
    00030 //------------------------------------------------------------------------------
    00031 // コンストラクタ
    00032 TranslationLightManager::TranslationLightManager() :
    00033     database_(256, 0.75f), array_(256){
    00034 }
    00035 //------------------------------------------------------------------------------
    00036 // デストラクタ
    00037 TranslationLightManager::~TranslationLightManager(){
    00038     Assert(database_.getCount() == 0);
    00039     Assert(array_.getCount() == 0);
    00040     if(getCount() != 0){ clear(); }
    00041 }
    00042 //------------------------------------------------------------------------------
    00043 // ライトの収集
    00044 bool TranslationLightManager::collectLights(){
    00045     MStatus result;
    00046     MItDag dagIterator(MItDag::kBreadthFirst, MFn::kLight, &result);
    00047     MayaStatusCheck(result);
    00048     MDagPath dagPath;
    00049     for( ; !dagIterator.isDone(); dagIterator.next()){
    00050         result = dagIterator.getPath(dagPath);
    00051         MayaStatusCheck(result);
    00052         MFnDagNode dagNode(dagPath, &result);
    00053         MayaStatusCheck(result);
    00054         // 名前の取得
    00055         MString dagName = dagNode.name(&result);
    00056         MayaStatusCheck(result);
    00057         // ライトでなければキャンセル
    00058         if(!dagPath.hasFn(MFn::kLight)){ continue; }
    00059         // 中間オブジェクトならキャンセル
    00060         if(dagNode.isIntermediateObject()){ continue; }
    00061         // ライトの解析
    00062         if(!analysisLight(dagPath)){ return false; }
    00063     }
    00064     return true;
    00065 }
    00066 //------------------------------------------------------------------------------
    00067 // ライトの解析
    00068 bool TranslationLightManager::analysisLight(const MDagPath& dagPath){
    00069     MStatus result;
    00070     MFnDagNode lightNode(dagPath, &result);
    00071     MayaStatusCheck(result);
    00072     if( (!dagPath.hasFn(MFn::kAmbientLight)) &&
    00073         (!dagPath.hasFn(MFn::kDirectionalLight)) &&
    00074         (!dagPath.hasFn(MFn::kPointLight)) ){ return true; }
    00075     // オブジェクトの取得
    00076     MObject lightObject = dagPath.node(&result);
    00077     MayaStatusCheck(result);
    00078     // 名前の重複が無いかチェック
    00079     String lightName = lightNode.name(&result).asChar();
    00080     MayaStatusCheck(result);
    00081     TranslationLight* exist = database_.get(lightName);
    00082     if(exist != NULL){
    00083         // オブジェクトが同じならインスタンスなので読み飛ばし、そうでなければエラー
    00084         if(exist->getObject() != lightObject){
    00085             MayaErrorOut(String("TranslationLightManager::analysisModel() "
    00086                 "名前が重複しています ") + lightName);
    00087             return false;
    00088         }
    00089         return true;
    00090     }
    00091     // ライト構築
    00092     TranslationLight* light = NULL;
    00093     if(dagPath.hasFn(MFn::kAmbientLight)){
    00094         light = new TranslationAmbientLight(dagPath, lightName);
    00095     }else if(dagPath.hasFn(MFn::kDirectionalLight)){
    00096         light = new TranslationDirectionalLight(dagPath, lightName);
    00097     }else if(dagPath.hasFn(MFn::kPointLight)){
    00098         light = new TranslationPointLight(dagPath, lightName);
    00099     }
    00100     if(!light->analyze()){
    00101         delete light;
    00102         return false;
    00103     }
    00104     database_.put(lightName, light);
    00105     array_.add(light);
    00106     return true;
    00107 }
    00108 //------------------------------------------------------------------------------
    00109 // Lampへの変換
    00110 bool TranslationLightManager::convertToLamp(Scene* scene) const{
    00111     for(int i = 0; i < getCount(); i++){
    00112         if(!get(i)->convertToLamp(scene)){ return false; }
    00113     }
    00114     return true;
    00115 }
    00116 //------------------------------------------------------------------------------
    00117 // クリア
    00118 int TranslationLightManager::clear(){
    00119     int result = getCount();
    00120     // 要素の削除
    00121     for(int i = 0; i < result; i++){ delete array_.get(i); }
    00122     array_.clear();
    00123     database_.clear();
    00124     return result;
    00125 }
    00126 //------------------------------------------------------------------------------
    00127 } // End of namespace LampForMaya
    00128 //------------------------------------------------------------------------------