|
I need to export Maya scene into own application. And I’ve got problems with materials. I’ve found over the Web a working example that I’ve used for the base:
mesh.getConnectedSetsAndMembers(instanceNumber, sets, components, True)
file.write("<MeshMaterials>")
for i in range(sets.length()):
material = Material()
set = sets[i]
component = components[i]
fnSet = maya.OpenMaya.MFnSet(set)
dependencyNode = maya.OpenMaya.MFnDependencyNode(set)
surfaceShaderAttribute = dependencyNode.attribute("surfaceShader");
surfaceShaderPlug = maya.OpenMaya.MPlug(set, surfaceShaderAttribute)
sourcePlugArray = maya.OpenMaya.MPlugArray()
surfaceShaderPlug.connectedTo(sourcePlugArray, True, False)
if sourcePlugArray.length() == 0:
continue
sourceNode = sourcePlugArray[0].node()
materialDepNode = maya.OpenMaya.MFnDependencyNode(sourceNode)
material.Name = materialDepNode.name()
if (sourceNode.hasFn(maya.OpenMaya.MFn.kLambert)):
lambertShader = maya.OpenMaya.MFnLambertShader(sourceNode)
presaveLambertShaderDiffuseColor(material, lambertShader)
But there are also common material attrbiutes that I need to export also, but I don’t know how to access them. If I write
if (sourceNode.hasFn(maya.OpenMaya.MFn.kMaterial)):
baseMaterial = maya.OpenMaya.MMaterial(sourceNode)
print baseMaterial.color
I never see the output, i. e. the node never can be used to create MMaterial. And I don’t know how to access it some other way.
Tell me please how can I export common material attrbiutes.
|