Maya之传递模型和贴图的关系
白羽 2018-06-13 来源 :网络 阅读 2969 评论 0

摘要:本文将带带你了解Maya之传递模型和贴图的关系,希望本文对大家学Maya有所帮助。




这里只有四个模型 两个材质球,项目中有上千个模型和三十个材质球,都一样的。

 

 

 Maya之传递模型和贴图的关系Maya之传递模型和贴图的关系

 

 

 


本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标常用软件之Maya频道!

思路

1..在maya中把模型abc导出,再用ReadGeo导入nuke

2.把模型和相对应的贴图关系写成一个字典,再用json存出来。

[python] view plain copy
1. import maya.cmds as mc  
2. import json  
3. def nukeTexterLink(link_file):  
4.     meshes=mc.ls(sl=1)  
5.     modelist=[]  
6.   
7.     for mode in meshes:  
8.         attr={}  
9.         aShape=mc.listRelatives(mode,s=1)  
10.         fShape=mc.listRelatives(mode,s=1,f=1)  
11.         attr['a_shape']=aShape  
12.         attr['f_shape']=fShape  
13.         a_sg=mc.listConnections('%s|%s'%(mode,aShape[0]))  
14.         aShape=mc.listRelatives(mode,s=1)  
15.         a_shaders=mc.listConnections(a_sg)  
16.           
17.         for a_shader in a_shaders:  
18.             nt=mc.nodeType(a_shader)  
19.             se='lambert'  
20.             if nt==se:  
21.                 a_textures=mc.listConnections(a_shader)  
22.                 for a_texture in a_textures:  
23.                     nt2=mc.nodeType(a_texture)  
24.                     se2='file'  
25.                     if nt2==se2:  
26.                         textureFile=mc.getAttr('%s.fileTextureName'%a_texture)  
27.         attr['a_textureFile']=textureFile  
28.         modelist.append(attr)  
29.   
30.     f = open(link_file, 'w')  
31.     f.write(json.dumps(modelist, indent = 4))  
32.     f.close()  
33.       
34.       
link_file 文件内容
[plain] view plain copy
1. [  
2.     {  
3.         "a_shape": [  
4.             "pSphereShape1"  
5.         ],   
6.         "a_textureFile": "C:/Users/Public/Pictures/Sample Pictures/Koala.jpg",   
7.         "f_shape": [  
8.             "|pSphere1|pSphereShape1"  
9.         ]  
10.     },   
11.     {  
12.         "a_shape": [  
13.             "pSphereShape2"  
14.         ],   
15.         "a_textureFile": "C:/Users/Public/Pictures/Sample Pictures/Desert.jpg",   
16.         "f_shape": [  
17.             "|pSphere2|pSphereShape2"  
18.         ]  
19.     },   
20.     {  
21.         "a_shape": [  
22.             "pPlaneShape1"  
23.         ],   
24.         "a_textureFile": "C:/Users/Public/Pictures/Sample Pictures/Koala.jpg",   
25.         "f_shape": [  
26.             "|pPlane1|pPlaneShape1"  
27.         ]  
28.     },   
29.     {  
30.         "a_shape": [  
31.             "pPlaneShape2"  
32.         ],   
33.         "a_textureFile": "C:/Users/Public/Pictures/Sample Pictures/Desert.jpg",   
34.         "f_shape": [  
35.             "|pPlane2|pPlaneShape2"  
36.         ]  
37.     }  
38. ]  
 
 
 
 
3.在nuke中导入刚才存的文件link_file 利用 ApplyMaterial节点恢复模型和贴图的关系。
[python] view plain copy
1. import nuke  
[python] view plain copy
1. import json  
[python] view plain copy
1. def maya2nuke():  
2.   
3.     sl = nuke.Panel('Maya to nuke')  
4.     sl.addSingleLineInput('texturelink', '')  
5.     ret = sl.show()  
6.   
7.     link_file=sl.value('texturelink')  
8.     with open(link_file,'r') as data:  
9.         shapes=json.load(data)  
10.   
11.     ReadG=nuke.selectedNode()  
12.     appTmp=ReadG  
13.     textureFile=[]  
14.     textureReadNodes=[]  
15.   
16.     for shapetmp in shapes:  
17.         if shapetmp['a_textureFile'] not in textureFile:  
18.             textureReadNode={}  
19.             textureReadNode['Name']=shapetmp['a_textureFile'].split('/')[-1]  
20.               
21.             textureRead= nuke.nodes.Read()  
22.               
23.             textureRead['name'].setValue(textureReadNode['Name'])  
24.             textureRead['file'].setValue(shapetmp['a_textureFile'])  
25.             textureReadNode['node']=textureRead  
26.             textureFile.append( shapetmp['a_textureFile'])  
27.             textureReadNodes.append(textureReadNode)  
28.   
29.   
30.   
31.     for shapetmp2 in shapes:  
32.   
33.         textureReadNodeName=shapetmp2['a_textureFile'].split('/')[-1]  
34.         for shape in shapetmp2['f_shape']:  
35.   
36.             rootshape1=shape.split('|')[-1]  
37.             rootshape2=shape.split('|')[-2]  
38.             rootshape='/root/%s/%s'%(rootshape2,rootshape1)          
39.             for textureReadNode in textureReadNodes :  
40.                 if textureReadNode['Name']==textureReadNodeName:  
41.                     appM=nuke.nodes.ApplyMaterial(inputs =[appTmp,textureReadNode['node']])  
42.                     appTmp=appM  
43.                     appM['filter_type'].setValue('1')  
44.                     appM['filter_name'].setValue(rootshape)  
45.                     appM['name'].setValue(rootshape2)  
46.   
47. maya2nuke()

 


本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标常用软件之Maya频道!


本文由 @白羽 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程