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

# TranslationBasicMaterial.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/Material/TranslationBasicMaterial.h"
    00027 #include "Material/Utility/LampMaterialUtility.h"
    00028 #include "Graphics/Scene/Scene.h"
    00029 #include "Graphics/Material/MaterialManager.h"
    00030 #include "Graphics/Texture/TextureManager.h"
    00031
    00032 namespace LampForMaya{
    00033
    00034 //------------------------------------------------------------------------------
    00035 // コンストラクタ
    00036 TranslationBasicMaterial::TranslationBasicMaterial(
    00037     const MObject& initializeObject, const String& initializeName) :
    00038     TranslationMaterial(initializeObject, initializeName){
    00039 }
    00040 //------------------------------------------------------------------------------
    00041 // デストラクタ
    00042 TranslationBasicMaterial::~TranslationBasicMaterial(){
    00043 }
    00044 //------------------------------------------------------------------------------
    00045 // 分析
    00046 bool TranslationBasicMaterial::analyze(){
    00047     // マテリアルの分析
    00048     if(!analyzeMaterial()){ return false; }
    00049     // ベーステクスチャ名
    00050     baseTextureName_ = LampMaterialUtility::getTextureName(object_, "color");
    00051     // ベースUVインデックス
    00052     baseUVIndex_ = MayaAttributeUtility::getInt(object_, "baseUVIndex");
    00053     // 光沢テクスチャ名
    00054     glossTextureName_ =
    00055         LampMaterialUtility::getTextureName(object_, "glossTexture");
    00056     // 光沢UVインデックス
    00057     glossUVIndex_ = MayaAttributeUtility::getInt(object_, "glossUVIndex");
    00058     // ライトテクスチャ名
    00059     lightTextureName_ =
    00060         LampMaterialUtility::getTextureName(object_, "lightTexture");
    00061     // ライトUVインデックス
    00062     lightUVIndex_ = MayaAttributeUtility::getInt(object_, "lightUVIndex");
    00063     // 汚れテクスチャ名
    00064     stainTextureName_ =
    00065         LampMaterialUtility::getTextureName(object_, "stainTexture");
    00066     // 汚れUVインデックス
    00067     stainUVIndex_ = MayaAttributeUtility::getInt(object_, "stainUVIndex");
    00068
    00069     // ディフューズカラー
    00070     diffuseColor_ = MayaAttributeUtility::getColor3f(object_, "diffuseColor");
    00071     // スペキュラカラー
    00072     specularColor_ = MayaAttributeUtility::getColor3f(object_, "specularColor");
    00073     // スペキュラパワー
    00074     specularPower_ = MayaAttributeUtility::getFloat(object_, "specularPower");
    00075     // アンビエントカラー
    00076     ambientColor_ = MayaAttributeUtility::getColor3f(object_, "ambientColor");
    00077     // エミッシブカラー
    00078     emissiveColor_ = MayaAttributeUtility::getColor3f(object_, "emissiveColor");
    00079     return true;
    00080 }
    00081 //------------------------------------------------------------------------------
    00082 // Lampへの変換
    00083 bool TranslationBasicMaterial::convertToLamp(Scene* scene){
    00084     MaterialManager* materialManager = scene->getMaterialManager();
    00085     BasicMaterial* material = materialManager->createBasicMaterial(name_);
    00086     TextureManager* textureManager = scene->getTextureManager();
    00087     // マテリアルの変換
    00088     if(!convertMaterial(material)){ return false; }
    00089     // ベーステクスチャ名
    00090     if(!baseTextureName_.isEmpty()){
    00091         Texture* baseTexture = textureManager->search(baseTextureName_);
    00092         if(baseTexture == NULL){
    00093             MayaErrorOut("TranslationBasicMaterial::convertToLamp() "
    00094                 "ベーステクスチャが見つかりません " + baseTextureName_);
    00095             return false;
    00096         }
    00097         material->setBaseTexture(baseTexture);
    00098     }
    00099     // ベースUVインデックス
    00100     material->setBaseUVIndex(baseUVIndex_);
    00101     // 光沢テクスチャ名
    00102     if(!glossTextureName_.isEmpty()){
    00103         Texture* glossTexture = textureManager->search(glossTextureName_);
    00104         if(glossTexture == NULL){
    00105             MayaErrorOut("TranslationBasicMaterial::convertToLamp() "
    00106                 "光沢テクスチャが見つかりません " + glossTextureName_);
    00107             return false;
    00108         }
    00109         material->setGlossTexture(glossTexture);
    00110     }
    00111     // 光沢UVインデックス
    00112     material->setGlossUVIndex(glossUVIndex_);
    00113     // ライトテクスチャ名
    00114     if(!lightTextureName_.isEmpty()){
    00115         Texture* lightTexture = textureManager->search(lightTextureName_);
    00116         if(lightTexture == NULL){
    00117             MayaErrorOut("TranslationBasicMaterial::convertToLamp() "
    00118                 "ライトテクスチャが見つかりません " + lightTextureName_);
    00119             return false;
    00120         }
    00121         material->setLightTexture(lightTexture);
    00122     }
    00123     // ライトUVインデックス
    00124     material->setLightUVIndex(lightUVIndex_);
    00125     // 汚れテクスチャ名
    00126     if(!stainTextureName_.isEmpty()){
    00127         Texture* stainTexture = textureManager->search(stainTextureName_);
    00128         if(stainTexture == NULL){
    00129             MayaErrorOut("TranslationBasicMaterial::convertToLamp() "
    00130                 "汚れテクスチャが見つかりません " + stainTextureName_);
    00131             return false;
    00132         }
    00133         material->setStainTexture(stainTexture);
    00134     }
    00135     // 汚れUVインデックス
    00136     material->setStainUVIndex(stainUVIndex_);
    00137
    00138     // ディフューズカラー
    00139     material->setDiffuseColor(diffuseColor_);
    00140     // スペキュラカラー
    00141     material->setSpecularColor(specularColor_);
    00142     // スペキュラパワー
    00143     material->setSpecularPower(specularPower_);
    00144     // アンビエントカラー
    00145     material->setAmbientColor(ambientColor_);
    00146     // エミッシブカラー
    00147     material->setEmissiveColor(emissiveColor_);
    00148     return true;
    00149 }
    00150 //------------------------------------------------------------------------------
    00151 } // End of namespace LampForMaya
    00152 //------------------------------------------------------------------------------