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 "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
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
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
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
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 }
00228