2017-05-24 203 views
0

我在学校有一项任务,要在maya中创建一个自定义.obj和.mtl导出器,但文档很难理解和使用。如何在maya中创建.obj和.mtl导出器

发现了一个看起来像这样的博文,代码有效,但我想知道更多关于它的实际功能以及将来如何处理这类问题的提示。

import pymel.core as pm 

def material(): 
    file2 = open("C:/Users/MyName/Desktop/test.mtl", "wb") 
    textureName="" 
    object = pm.ls(sl=1)[0].split(':')[0] 

    selection = pm.ls(sl=1) 
    for each in selection: 
     object=pm.PyNode(each) 
     shadingGroups = object.shadingGroups() 
     print("SG "+str(shadingGroups)) 

     for shadingGroup in shadingGroups: 
      material=shadingGroup.listConnections(source=True, destination=False, type=nt.Lambert)[0] 
      print("Mat "+str(material)) 
      texture = material.color.listConnections(type=nt.File)[0] 
      textureName=texture.fileTextureName.get() 
      print("Texture "+str(textureName)) 

      materialColor = material.getColor() # for Kd 
      materialAmbient = material.getAmbientColor() # for Ka 
      materialSpecular = material.getSpecularColor() # for Ks 
      refractiveIndex = material.getRefractiveIndex() # for Ni 

      file2.write("newmtl " + "test" + "\r\n") 
      file2.write("Ka " + str(materialAmbient[0]) + " " 
        + str(materialAmbient[1]) + " " 
        + str(materialAmbient[2]) + "\r\n") 
      file2.write("Kd " + str(materialColor[0]) + " " 
        + str(materialColor[1]) + " " 
        + str(materialColor[2]) + "\r\n") 
      file2.write("Ks " + str(materialSpecular[0]) + " " + str(materialSpecular[1]) + " " + str(materialSpecular[2]) + "\r\n") 
      file2.write("d 1.0\r\n") 
      file2.write("Illum 2\r\n") 
      file2.write("map_Kd " + textureName + "\r\n") # for map_Kd 

    file2.close() 

回答

1

由于它的功课我最好给一些文件,而不是代码正确吗? ;)..以下是来自maya的自定义文件翻译器的documentation。而示例翻译可以找到here,更深一些example

+0

欣赏它:) – Hamaro

相关问题