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

LampMaterialUtility.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  * Lampマテリアルユーティリティ実装
00022  * @author Junpee
00023  */
00024 
00025 #include "System/stdafx.h"
00026 #include "Material/Utility/LampMaterialUtility.h"
00027 
00028 namespace LampForMaya{
00029 
00030 //------------------------------------------------------------------------------
00031 // テクスチャ
00032 //------------------------------------------------------------------------------
00033 // テクスチャの取得
00034 MObject LampMaterialUtility::getTexture(
00035     const MObject& node, const String& attributeName){
00036     MStatus result;
00037     MPlug texturePlug = MayaAttributeUtility::getPlug(node, attributeName);
00038     MItDependencyGraph textureIterator(
00039         texturePlug, MFn::kFileTexture,
00040         MItDependencyGraph::kUpstream,
00041         MItDependencyGraph::kBreadthFirst,
00042         MItDependencyGraph::kNodeLevel);
00043     MObject texture = textureIterator.thisNode();
00044     if(texture.hasFn(MFn::kFileTexture)){
00045         return texture;
00046     }
00047     return MObject();
00048 }
00049 //------------------------------------------------------------------------------
00050 // テクスチャ名の取得
00051 String LampMaterialUtility::getTextureName(
00052     const MObject& node, const String& attributeName){
00053     MObject texture = getTexture(node, attributeName);
00054     if(texture.isNull()){ return String(""); }
00055     String textureName = MayaNodeUtility::getName(texture);
00056     return textureName;
00057 }
00058 //------------------------------------------------------------------------------
00059 // アトリビュート初期化
00060 //------------------------------------------------------------------------------
00061 // ベーステクスチャアトリビュートの追加
00062 void LampMaterialUtility::addBaseTextureAttribute(){
00063     MStatus result;
00064     MFnNumericAttribute attribute;
00065     // ベーステクスチャ
00066     MObject baseTexture = attribute.createColor(
00067         "color", "c", &result);
00068     MayaStatusCheck(result);
00069     MayaStatusCheck(attribute.setDefault(1.f, 1.f, 1.f));
00070     MayaStatusCheck(MPxNode::addAttribute(baseTexture));
00071     MayaStatusCheck(MPxNode::attributeAffects(
00072         baseTexture, MPxHwShaderNode::outColor));
00073     // ベースUVインデックス
00074     MObject baseUVIndex = attribute.create(
00075         "baseUVIndex", "bui", MFnNumericData::kInt, 0, &result);
00076     MayaStatusCheck(result);
00077     MayaStatusCheck(attribute.setConnectable(false));
00078     MayaStatusCheck(attribute.setMax(7));
00079     MayaStatusCheck(attribute.setMin(0));
00080     MayaStatusCheck(MPxNode::addAttribute(baseUVIndex));
00081     MayaStatusCheck(MPxNode::attributeAffects(
00082         baseUVIndex, MPxHwShaderNode::outColor));
00083 }
00084 //------------------------------------------------------------------------------
00085 // 光沢テクスチャアトリビュートの追加
00086 void LampMaterialUtility::addGlossTextureAttribute(){
00087     MStatus result;
00088     MFnNumericAttribute attribute;
00089     // 光沢テクスチャ
00090     MObject glossTexture = attribute.createColor(
00091         "glossTexture", "glt", &result);
00092     MayaStatusCheck(result);
00093     MayaStatusCheck(attribute.setDefault(1.f, 1.f, 1.f));
00094     MayaStatusCheck(MPxNode::addAttribute(glossTexture));
00095     MayaStatusCheck(MPxNode::attributeAffects(
00096         glossTexture, MPxHwShaderNode::outColor));
00097     // 光沢UVインデックス
00098     MObject glossUVIndex = attribute.create(
00099         "glossUVIndex", "gui", MFnNumericData::kInt, 0, &result);
00100     MayaStatusCheck(result);
00101     MayaStatusCheck(attribute.setConnectable(false));
00102     MayaStatusCheck(attribute.setMax(7));
00103     MayaStatusCheck(attribute.setMin(0));
00104     MayaStatusCheck(MPxNode::addAttribute(glossUVIndex));
00105     MayaStatusCheck(MPxNode::attributeAffects(
00106         glossUVIndex, MPxHwShaderNode::outColor));
00107 }
00108 //------------------------------------------------------------------------------
00109 // ライトテクスチャアトリビュートの追加
00110 void LampMaterialUtility::addLightTextureAttribute(){
00111     MStatus result;
00112     MFnNumericAttribute attribute;
00113     // ライトテクスチャ
00114     MObject lightTexture = attribute.createColor(
00115         "lightTexture", "lgt", &result);
00116     MayaStatusCheck(result);
00117     MayaStatusCheck(attribute.setDefault(1.f, 1.f, 1.f));
00118     MayaStatusCheck(MPxNode::addAttribute(lightTexture));
00119     MayaStatusCheck(MPxNode::attributeAffects(
00120         lightTexture, MPxHwShaderNode::outColor));
00121     // ライトUVインデックス
00122     MObject lightUVIndex = attribute.create(
00123         "lightUVIndex", "lui", MFnNumericData::kInt, 0, &result);
00124     MayaStatusCheck(result);
00125     MayaStatusCheck(attribute.setConnectable(false));
00126     MayaStatusCheck(attribute.setMax(7));
00127     MayaStatusCheck(attribute.setMin(0));
00128     MayaStatusCheck(MPxNode::addAttribute(lightUVIndex));
00129     MayaStatusCheck(MPxNode::attributeAffects(
00130         lightUVIndex, MPxHwShaderNode::outColor));
00131 }
00132 //------------------------------------------------------------------------------
00133 // 汚れテクスチャアトリビュートの追加
00134 void LampMaterialUtility::addStainTextureAttribute(){
00135     MStatus result;
00136     MFnNumericAttribute attribute;
00137     // 汚れテクスチャ
00138     MObject stainTexture = attribute.createColor(
00139         "stainTexture", "stt", &result);
00140     MayaStatusCheck(result);
00141     MayaStatusCheck(attribute.setDefault(1.f, 1.f, 1.f));
00142     MayaStatusCheck(MPxNode::addAttribute(stainTexture));
00143     MayaStatusCheck(MPxNode::attributeAffects(
00144         stainTexture, MPxHwShaderNode::outColor));
00145     // 汚れUVインデックス
00146     MObject stainUVIndex = attribute.create(
00147         "stainUVIndex", "sui", MFnNumericData::kInt, 0, &result);
00148     MayaStatusCheck(result);
00149     MayaStatusCheck(attribute.setConnectable(false));
00150     MayaStatusCheck(attribute.setMax(7));
00151     MayaStatusCheck(attribute.setMin(0));
00152     MayaStatusCheck(MPxNode::addAttribute(stainUVIndex));
00153     MayaStatusCheck(MPxNode::attributeAffects(
00154         stainUVIndex, MPxHwShaderNode::outColor));
00155 }
00156 //------------------------------------------------------------------------------
00157 // ディフューズアトリビュートの追加
00158 void LampMaterialUtility::addDiffuseAttribute(){
00159     MStatus result;
00160     MFnNumericAttribute attribute;
00161     // ディフューズカラー
00162     MObject diffuseColor = attribute.createColor(
00163         "diffuseColor", "dc", &result);
00164     MayaStatusCheck(result);
00165     MayaStatusCheck(attribute.setDefault(1.f, 1.f, 1.f));
00166     MayaStatusCheck(attribute.setConnectable(false));
00167     MayaStatusCheck(MPxNode::addAttribute(diffuseColor));
00168     MayaStatusCheck(MPxNode::attributeAffects(
00169         diffuseColor, MPxHwShaderNode::outColor));
00170 }
00171 //------------------------------------------------------------------------------
00172 // スペキュラアトリビュートの追加
00173 void LampMaterialUtility::addSpecularAttribute(){
00174     MStatus result;
00175     MFnNumericAttribute attribute;
00176     // スペキュラカラー
00177     MObject specularColor = attribute.createColor(
00178         "specularColor", "sc", &result);
00179     MayaStatusCheck(result);
00180     MayaStatusCheck(attribute.setDefault(0.f, 0.f, 0.f));
00181     MayaStatusCheck(attribute.setConnectable(false));
00182     MayaStatusCheck(MPxNode::addAttribute(specularColor));
00183     MayaStatusCheck(MPxNode::attributeAffects(
00184         specularColor, MPxHwShaderNode::outColor));
00185     // スペキュラパワー
00186     MObject specularPower = attribute.create(
00187         "specularPower", "sp", MFnNumericData::kFloat, 8.f, &result);
00188     MayaStatusCheck(result);
00189     MayaStatusCheck(attribute.setConnectable(false));
00190     MayaStatusCheck(attribute.setMax(128.f));
00191     MayaStatusCheck(attribute.setMin(0.f));
00192     MayaStatusCheck(MPxNode::addAttribute(specularPower));
00193     MayaStatusCheck(MPxNode::attributeAffects(
00194         specularPower, MPxHwShaderNode::outColor));
00195 }
00196 //------------------------------------------------------------------------------
00197 // アンビエントアトリビュートの追加
00198 void LampMaterialUtility::addAmbientAttribute(){
00199     MStatus result;
00200     // アンビエントカラー
00201     MFnNumericAttribute attribute;
00202     MObject ambientColor = attribute.createColor(
00203         "ambientColor", "ac", &result);
00204     MayaStatusCheck(result);
00205     MayaStatusCheck(attribute.setDefault(1.f, 1.f, 1.f));
00206     MayaStatusCheck(attribute.setConnectable(false));
00207     MayaStatusCheck(MPxNode::addAttribute(ambientColor));
00208     MayaStatusCheck(MPxNode::attributeAffects(
00209         ambientColor, MPxHwShaderNode::outColor));
00210 }
00211 //------------------------------------------------------------------------------
00212 // エミッシブアトリビュートの追加
00213 void LampMaterialUtility::addEmissiveAttribute(){
00214     MStatus result;
00215     // エミッシブカラー
00216     MFnNumericAttribute attribute;
00217     MObject emissiveColor = attribute.createColor(
00218         "emissiveColor", "ec", &result);
00219     MayaStatusCheck(result);
00220     MayaStatusCheck(attribute.setDefault(0.f, 0.f, 0.f));
00221     MayaStatusCheck(attribute.setConnectable(false));
00222     MayaStatusCheck(MPxNode::addAttribute(emissiveColor));
00223     MayaStatusCheck(MPxNode::attributeAffects(
00224         emissiveColor, MPxHwShaderNode::outColor));
00225 }
00226 //------------------------------------------------------------------------------
00227 } // End of namespace LampForMaya
00228 //------------------------------------------------------------------------------

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