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

TranslationTexture.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/Texture/TranslationTexture.h"
00027 #include "Graphics/Scene/Scene.h"
00028 #include "Graphics/Texture/TextureManager.h"
00029 #include "Graphics/Picture/PictureManager.h"
00030 #include "Core/InputOutput/FilePath.h"
00031 
00032 namespace LampForMaya{
00033 
00034 //------------------------------------------------------------------------------
00035 // コンストラクタ
00036 TranslationTexture::TranslationTexture(
00037     const MObject& initializeObject, const String& initializeName) :
00038     object_(initializeObject), name_(initializeName){
00039 }
00040 //------------------------------------------------------------------------------
00041 // 分析
00042 bool TranslationTexture::analyze(){
00043     // ピクチャパスの取得
00044     picturePath_ = MayaAttributeUtility::getString(object_, "fileTextureName");
00045     if(picturePath_.equals("")){
00046         MayaErrorOut(String("TranslationTexture::analyze() "
00047             "ピクチャファイル名が設定されていません。 ") + name_);
00048         return false;
00049     }
00050     // ピクチャ名の取得
00051     FilePath filePath(picturePath_);
00052     pictureName_ = filePath.getName();
00053     // .tgaのみ許可する
00054     if(filePath.getExtension() != "tga"){
00055         MayaErrorOut(String("TranslationTexture::analyze() "
00056             "Targa(.tga)以外のピクチャフォーマットは未対応です ") +
00057             name_ + " " + picturePath_);
00058         return false;
00059     }
00060     // ミラーUVフラグの取得
00061     mirrorU_ = MayaAttributeUtility::getBool(object_, "mirrorU");
00062     mirrorV_ = MayaAttributeUtility::getBool(object_, "mirrorV");
00063     // ラップUVフラグの取得
00064     wrapU_ = MayaAttributeUtility::getBool(object_, "wrapU");
00065     wrapV_ = MayaAttributeUtility::getBool(object_, "wrapV");
00066     // リピートUVの取得
00067     repeatUV_.u = MayaAttributeUtility::getFloat(object_, "repeatU");
00068     repeatUV_.v = MayaAttributeUtility::getFloat(object_, "repeatV");
00069     // オフセットUVの取得
00070     offsetUV_.u = MayaAttributeUtility::getFloat(object_, "offsetU");
00071     offsetUV_.v = MayaAttributeUtility::getFloat(object_, "offsetV");
00072     return true;
00073 }
00074 //------------------------------------------------------------------------------
00075 // デストラクタ
00076 TranslationTexture::~TranslationTexture(){
00077 }
00078 //------------------------------------------------------------------------------
00079 // Lampへの変換
00080 bool TranslationTexture::convertToLamp(Scene* scene){
00081     TextureManager* textureManager = scene->getTextureManager();
00082     SurfaceTexture* texture = textureManager->createSurfaceTexture(name_);
00083     if(mirrorU_){
00084         texture->setAddressModeU(Texture::addressModeMirror);
00085     }else if(wrapU_){
00086         texture->setAddressModeU(Texture::addressModeWrap);
00087     }else{
00088         texture->setAddressModeU(Texture::addressModeClamp);
00089     }
00090     if(mirrorV_){
00091         texture->setAddressModeV(Texture::addressModeMirror);
00092     }else if(wrapV_){
00093         texture->setAddressModeV(Texture::addressModeWrap);
00094     }else{
00095         texture->setAddressModeV(Texture::addressModeClamp);
00096     }
00097     texture->setRepeatUV(repeatUV_);
00098     texture->setOffsetUV(offsetUV_);
00099     // ピクチャとのリンク
00100     PictureManager* pictureManager = scene->getPictureManager();
00101     Picture* picture = pictureManager->search(pictureName_);
00102     if(picture == NULL){
00103         MayaErrorOut(String("TranslationTexture::convertToLamp() "
00104             "ピクチャが見つかりません ") + pictureName_);
00105         return false;
00106     }
00107     texture->addPicture(picture);
00108     return true;
00109 }
00110 //------------------------------------------------------------------------------
00111 } // End of namespace LampForMaya
00112 //------------------------------------------------------------------------------

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