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

TranslationModelManager.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/Model/TranslationModelManager.h"
00027 #include "Translator/Model/TranslationCharacterModel.h"
00028 
00029 namespace LampForMaya{
00030 
00031 //------------------------------------------------------------------------------
00032 // コンストラクタ
00033 TranslationModelManager::TranslationModelManager() :
00034     database_(256, 0.75f), array_(256){
00035 }
00036 //------------------------------------------------------------------------------
00037 // デストラクタ
00038 TranslationModelManager::~TranslationModelManager(){
00039     Assert(database_.getCount() == 0);
00040     Assert(array_.getCount() == 0);
00041     if(getCount() != 0){ clear(); }
00042 }
00043 //------------------------------------------------------------------------------
00044 // モデルの収集
00045 bool TranslationModelManager::collectModels(
00046     TranslationMeshManager* meshManager){
00047     meshManager_ = meshManager;
00048     MStatus result;
00049     // 幅優先DAGイテレータ
00050     MItDag dagIterator(MItDag::kBreadthFirst, MFn::kInvalid, &result);
00051     MayaStatusCheck(result);
00052     MDagPath dagPath;
00053     for( ; !dagIterator.isDone(); dagIterator.next()){
00054         result = dagIterator.getPath(dagPath);
00055         MayaStatusCheck(result);
00056         // モデル解析
00057         if(!analysisModel(dagPath)){ return false; }
00058     }
00059     return true;
00060 }
00061 //------------------------------------------------------------------------------
00062 // モデルの解析
00063 bool TranslationModelManager::analysisModel(MDagPath dagPath){
00064     MStatus result;
00065     MFnDagNode dagNode(dagPath, &result);
00066     MayaStatusCheck(result);
00067     // 中間オブジェクトならキャンセル
00068     if(dagNode.isIntermediateObject()){ return true; }
00069     // メッシュファンクションを持っていなければキャンセル
00070     if(!dagPath.hasFn(MFn::kMesh)){ return true; }
00071     // トランスフォームファンクションを持っていればキャンセル
00072     if(dagPath.hasFn(MFn::kTransform)){ return true; }
00073     // オブジェクトの取得
00074     MObject modelObject = dagPath.node(&result);
00075     MayaStatusCheck(result);
00076     // 名前の重複が無いかチェック
00077     String modelName = dagNode.name(&result).asChar();
00078     MayaStatusCheck(result);
00079     TranslationModel* exist = database_.get(modelName);
00080     if(exist != NULL){
00081         // オブジェクトが同じならインスタンスなので読み飛ばし、そうでなければエラー
00082         if(exist->getObject() != modelObject){
00083             MayaErrorOut(String("TranslationModelManager::analysisModel() "
00084                 "名前が重複しています ") + modelName);
00085             return false;
00086         }
00087         return true;
00088     }
00089 
00090     // キャラクタメッシュの判別
00091     MPlug inMeshPlug = MayaNodeUtility::getPlug(modelObject, "inMesh");
00092     // 失敗する場合があるのでresultはチェックしない
00093     MItDependencyGraph characterIterator(inMeshPlug,
00094         MFn::kSkinClusterFilter, MItDependencyGraph::kUpstream,
00095         MItDependencyGraph::kBreadthFirst,
00096         MItDependencyGraph::kNodeLevel, &result);
00097     MObject inMesh = characterIterator.thisNode(&result);
00098     TranslationModel* model = NULL;
00099     if((!inMesh.isNull()) && inMesh.hasFn(MFn::kSkinClusterFilter)){
00100         // スキンクラスタならキャラクタモデル
00101         model = new TranslationCharacterModel(modelObject, modelName, inMesh);
00102     }else{
00103         // そうでなければスタンダードモデル
00104         model = new TranslationStandardModel(modelObject, modelName);
00105     }
00106 
00107     // モデルのアナライズ
00108     if(!model->analyze(meshManager_)){
00109         delete model;
00110         return false;
00111     }
00112     // データベースに追加
00113     database_.put(modelName, model);
00114     array_.add(model);
00115     return true;
00116 }
00117 //------------------------------------------------------------------------------
00118 // アニメーションの収集
00119 bool TranslationModelManager::collectAnimations(){
00120     for(int i = 0; i < getCount(); i++){
00121         if(!get(i)->analyzeAnimation()){ return false; }
00122     }
00123     return true;
00124 }
00125 //------------------------------------------------------------------------------
00126 // Lampへの変換
00127 bool TranslationModelManager::convertToLamp(Scene* scene) const{
00128     for(int i = 0; i < getCount(); i++){
00129         if(!get(i)->convertToLamp(scene)){ return false; }
00130     }
00131     return true;
00132 }
00133 //------------------------------------------------------------------------------
00134 // アニメーションの変換
00135 bool TranslationModelManager::convertAnimation(
00136     AnimationManager* animationManager, AnimationSet* animationSet){
00137     for(int i = 0; i < getCount(); i++){
00138         if(!get(i)->convertAnimation(animationManager, animationSet)){
00139             return false;
00140         }
00141     }
00142     return true;
00143 }
00144 //------------------------------------------------------------------------------
00145 // クリア
00146 int TranslationModelManager::clear(){
00147     int result = getCount();
00148     // 要素の削除
00149     for(int i = 0; i < result; i++){ delete array_.get(i); }
00150     array_.clear();
00151     database_.clear();
00152     return result;
00153 }
00154 //------------------------------------------------------------------------------
00155 } // End of namespace LampForMaya
00156 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:56 2005 for LampForMaya by doxygen 1.3.2