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

TranslationInstance.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/Instance/TranslationInstance.h"
00027 #include "Translator/Instance/TranslationInstanceManager.h"
00028 #include "Graphics/SceneNode/SceneNodeManager.h"
00029 #include "Animation/System/AnimationManager.h"
00030 #include "Animation/System/AnimationSet.h"
00031 #include "Animation/System/ObjectAnimation.h"
00032 
00033 namespace LampForMaya{
00034 
00035 //------------------------------------------------------------------------------
00036 // コンストラクタ
00037 TranslationInstance::TranslationInstance(
00038     const MDagPath& initializePath, const String& initializeName) :
00039     dagPath_(initializePath), name_(initializeName){
00040     MStatus result;
00041     // オブジェクトの取得
00042     object_ = dagPath_.node(&result);
00043     MayaStatusCheck(result);
00044 }
00045 //------------------------------------------------------------------------------
00046 // デストラクタ
00047 TranslationInstance::~TranslationInstance(){
00048 }
00049 //------------------------------------------------------------------------------
00050 // インスタンスの分析
00051 bool TranslationInstance::analyzeInstance(){
00052     MStatus result;
00053     MFnDagNode dagNode(dagPath_, &result);
00054     MayaStatusCheck(result);
00055     // 親の名前取得
00056     u_int instanceNumber = dagPath_.instanceNumber(&result);
00057     MayaStatusCheck(result);
00058     MObject parent = dagNode.parent(instanceNumber, &result);
00059     MayaStatusCheck(result);
00060     parentSceneNodeName_ = MayaNodeUtility::getName(parent);
00061     // 表示フラグ
00062     visibility_ = MayaAttributeUtility::getBool(object_, "visibility");
00063     return true;
00064 }
00065 //------------------------------------------------------------------------------
00066 // シーンノードアニメーションの変換
00067 bool TranslationInstance::convertSceneNodeAnimation(
00068     AnimationManager* animationManager, AnimationSet* animationSet,
00069     SceneNode* sourceSceneNode, SceneNode* destinationSceneNode){
00070     Animation* source = animationManager->search(sourceSceneNode->getName());
00071     if((source != NULL) && (source->isObjectAnimation())){
00072         ObjectAnimation* destination = source->copy()->castObjectAnimation();
00073         Assert(destination != NULL);
00074         destination->setTargetName(destinationSceneNode->getName());
00075         animationSet->addAnimation(destination);
00076     }
00077     // 子のシーンノードをたどる
00078     int sceneNodeCount = sourceSceneNode->getSceneNodeCount();
00079     for(int i = 0; i < sceneNodeCount; i++){
00080         convertSceneNodeAnimation(animationManager, animationSet,
00081             sourceSceneNode->getSceneNode(i),
00082             destinationSceneNode->getSceneNode(i));
00083     }
00084     // 子のモデルをたどる
00085     int sceneLeafCount = sourceSceneNode->getSceneLeafCount();
00086     for(int i = 0; i < sceneLeafCount; i++){
00087         convertSceneLeafAnimation(animationManager, animationSet,
00088             sourceSceneNode->getSceneLeaf(i),
00089             destinationSceneNode->getSceneLeaf(i));
00090     }
00091     return true;
00092 }
00093 //------------------------------------------------------------------------------
00094 // シーンリーフアニメーションの変換
00095 bool TranslationInstance::convertSceneLeafAnimation(
00096     AnimationManager* animationManager, AnimationSet* animationSet,
00097     SceneLeaf* sourceSceneLeaf, SceneLeaf* destinationSceneLeaf){
00098     Animation* source = animationManager->search(sourceSceneLeaf->getName());
00099     if(source == NULL){ return true; }
00100     if(!source->isObjectAnimation()){ return true; }
00101     ObjectAnimation* destination = source->copy()->castObjectAnimation();
00102     Assert(destination != NULL);
00103     destination->setTargetName(destinationSceneLeaf->getName());
00104     animationSet->addAnimation(destination);
00105     return true;
00106 }
00107 //------------------------------------------------------------------------------
00108 } // End of namespace LampForMaya
00109 //------------------------------------------------------------------------------

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