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

TranslationSceneNodeManager.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/SceneNode/TranslationSceneNodeManager.h"
00027 
00028 namespace LampForMaya{
00029 
00030 //------------------------------------------------------------------------------
00031 // コンストラクタ
00032 TranslationSceneNodeManager::TranslationSceneNodeManager() :
00033     database_(256, 0.75f), array_(256){
00034 }
00035 //------------------------------------------------------------------------------
00036 // デストラクタ
00037 TranslationSceneNodeManager::~TranslationSceneNodeManager(){
00038     Assert(database_.getCount() == 0);
00039     Assert(array_.getCount() == 0);
00040     if(getCount() != 0){ clear(); }
00041 }
00042 //------------------------------------------------------------------------------
00043 // シーンノードの収集
00044 bool TranslationSceneNodeManager::collectSceneNodes(){
00045     MStatus result;
00046     MItDag dagIterator(MItDag::kBreadthFirst, MFn::kInvalid, &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         // 有効なDagノードかチェック
00055         if(!checkValidDagNode(dagPath)){ continue; }
00056         // インスタンス化されていればキャンセル
00057         u_int instanceNumber = dagPath.instanceNumber(&result);
00058         MayaStatusCheck(result);
00059         if(instanceNumber > 0){ continue; }
00060         // トランスフォームファンクションを持っていなければキャンセル
00061         // これでworldオブジェクトをはじける
00062         if(!dagPath.hasFn(MFn::kTransform)){ continue; }
00063         // 名前の取得
00064         MString dagName = dagNode.name(&result);
00065         MayaStatusCheck(result);
00066         // グラウンドプレーンならキャンセル
00067         if(dagName == "groundPlane_transform"){ continue; }
00068         // シーンノードの解析
00069         if(!analysisSceneNode(dagPath)){ return false; }
00070     }
00071     return true;
00072 }
00073 //------------------------------------------------------------------------------
00074 // 有効Dagノードチェック
00075 bool TranslationSceneNodeManager::checkValidDagNode(const MDagPath& dagPath){
00076     // DAGノードのフィルタリング
00077     // もっとスマートにしたい
00078     MStatus result;
00079     MFnDagNode dagNode(dagPath, &result);
00080     MayaStatusCheck(result);
00081     // 中間オブジェクトならキャンセル
00082     if(dagNode.isIntermediateObject()){ return false; }
00083     // カメラならキャンセル
00084     if(dagPath.hasFn(MFn::kCamera)){ return false; }
00085     // ロケータならキャンセル
00086     if(dagPath.hasFn(MFn::kLocator)){ return false; }
00087     // ルックアットならキャンセル
00088     if(dagPath.hasFn(MFn::kLookAt)){ return false; }
00089     // ジョイントならキャンセル
00090     if(dagPath.hasFn(MFn::kJoint)){ return false; }
00091     // IKエフェクタならキャンセル
00092     if(dagPath.hasFn(MFn::kIkEffector)){ return false; }
00093     // IKハンドルならキャンセル
00094     if(dagPath.hasFn(MFn::kIkHandle)){ return false; }
00095     // NURBSファンクションを持っていればキャンセル
00096     if(dagPath.hasFn(MFn::kNurbsSurface)){ return false; }
00097     // NURBSカーブファンクションを持っていればキャンセル
00098     if(dagPath.hasFn(MFn::kNurbsCurve)){ return false; }
00099     // Subdivファンクションを持っていればキャンセル
00100     if(dagPath.hasFn(MFn::kSubdiv)){ return false; }
00101     // Particleファンクションを持っていればキャンセル
00102     if(dagPath.hasFn(MFn::kParticle)){ return false; }
00103     // ラティスならキャンセル
00104     if(dagPath.hasFn(MFn::kLattice)){ return false; }
00105     // フルイドならキャンセル
00106     if(dagPath.hasFn(MFn::kFluid)){ return false; }
00107     // フィールドならキャンセル
00108     if(dagPath.hasFn(MFn::kField)){ return false; }
00109     return true;
00110 }
00111 //------------------------------------------------------------------------------
00112 // シーンノードの解析
00113 bool TranslationSceneNodeManager::analysisSceneNode(MDagPath dagPath){
00114     MStatus result;
00115     MFnDagNode dagNode(dagPath, &result);
00116     MayaStatusCheck(result);
00117     // 名前の重複が無いかチェック
00118     String sceneNodeName = dagNode.name(&result).asChar();
00119     MayaStatusCheck(result);
00120     TranslationSceneNode* exist = database_.get(sceneNodeName);
00121     if(exist != NULL){
00122         MayaErrorOut(String("TranslationSceneNodeManager::analysisSceneNode() "
00123             "名前が重複しています ") + sceneNodeName);
00124         return false;
00125     }
00126     TranslationSceneNode* sceneNode =
00127         new TranslationSceneNode(dagPath, sceneNodeName);
00128     if(!sceneNode->analyze()){
00129         delete sceneNode;
00130         return false;
00131     }
00132     database_.put(sceneNodeName, sceneNode);
00133     array_.add(sceneNode);
00134     return true;
00135 }
00136 //------------------------------------------------------------------------------
00137 // ピボットのコンパイル
00138 bool TranslationSceneNodeManager::compilePivot(
00139     TranslationModelManager* modelManager){
00140     // ピボットのコンパイル
00141     for(int i = 0; i < getCount(); i++){
00142         if(!get(i)->compilePivot(this, modelManager)){ return false; }
00143     }
00144     return true;
00145 }
00146 //------------------------------------------------------------------------------
00147 // アニメーションの収集
00148 bool TranslationSceneNodeManager::collectAnimations(){
00149     for(int i = 0; i < getCount(); i++){
00150         if(!get(i)->analyzeAnimation()){ return false; }
00151     }
00152     return true;
00153 }
00154 //------------------------------------------------------------------------------
00155 // Lampへの変換
00156 bool TranslationSceneNodeManager::convertToLamp(Scene* scene) const{
00157     // シーンノードのコンバート
00158     for(int i = 0; i < getCount(); i++){
00159         if(!get(i)->convertToLamp(scene)){ return false; }
00160     }
00161     // リンクの接続
00162     for(int i = 0; i < getCount(); i++){
00163         if(!get(i)->linkConnect(scene)){ return false; }
00164     }
00165     return true;
00166 }
00167 //------------------------------------------------------------------------------
00168 // アニメーションの変換
00169 bool TranslationSceneNodeManager::convertAnimation(
00170     AnimationManager* animationManager, AnimationSet* animationSet){
00171     for(int i = 0; i < getCount(); i++){
00172         if(!get(i)->convertAnimation(animationManager, animationSet)){
00173             return false;
00174         }
00175     }
00176     return true;
00177 }
00178 //------------------------------------------------------------------------------
00179 // クリア
00180 int TranslationSceneNodeManager::clear(){
00181     int result = getCount();
00182     // 要素の削除
00183     for(int i = 0; i < result; i++){ delete array_.get(i); }
00184     array_.clear();
00185     database_.clear();
00186     return result;
00187 }
00188 //------------------------------------------------------------------------------
00189 } // End of namespace LampForMaya
00190 //------------------------------------------------------------------------------

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