00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00052 baseUVIndex_ = MayaAttributeUtility::getInt(object_, "baseUVIndex");
00053
00054 glossTextureName_ =
00055 LampMaterialUtility::getTextureName(object_, "glossTexture");
00056
00057 glossUVIndex_ = MayaAttributeUtility::getInt(object_, "glossUVIndex");
00058
00059 lightTextureName_ =
00060 LampMaterialUtility::getTextureName(object_, "lightTexture");
00061
00062 lightUVIndex_ = MayaAttributeUtility::getInt(object_, "lightUVIndex");
00063
00064 stainTextureName_ =
00065 LampMaterialUtility::getTextureName(object_, "stainTexture");
00066
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
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
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
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
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
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 }
00152