3ds Max导出OBJ的mtl贴图路径不正确
来源:互联网 发布:linux cern 知乎 编辑:程序博客网 时间:2024/05/29 13:23
之前流程是写了一个3DSMAX插件把游戏的场景直接导出为自己定义的格式的文件,包含了顶点数据,三角形数据,贴图数据等。现在把插件从3DMAX上分离出来,先通过3DMAX导出OBJ,然后再把OBJ导出为自定义的格式。
3DSMax导出的材质mtl文件漫反射贴图路径不正确
一开始以为是一个Standardmaterial对应漫反射的Map名字一样但是贴图路径不一样导致了OBJ导出出错。写了一个把同一个Map但是对应不同的贴图路径的Map自动重命名的MaxScript脚本,导出发现结果是一样的。
一个Multimaterial下的Standardmaterial和一个Standardmaterial名字一样,但是这二个Standardmaterial的diffusemap的文件路径不一样。从而导致了OBJ导出出错。
自动转换的代码如下:
--My Dictionarystruct dict( public keys = #(), public values = #(), --methods: fn Count = ( if keys.count == values.count then ( keys.count as integer ) else ( print "Error: keys.count != values.count" 0 ) ), fn Add key1 value1 = ( if findItem keys key1 == 0 then ( append keys key1 append values value1 true ) else ( print ("key has already been added! -->" + key1) false ) ), fn Clear = ( keys = #() values = #() true ), fn Remove key = ( index = findItem keys key if index != 0 then ( deleteItem keys index deleteItem values index true ) else ( print ("cann't find the key! -->" + key) false ) ), fn GetItem key = ( index = findItem keys key if index != 0 then ( if keys.count == values.count then ( values[index] ) else ( print "Error: keys.count != values.count" undefined ) ) else ( print ("cann't find the key! -->" + key) undefined ) ), fn ContainsKey key = ( index = findItem keys key if index != 0 then ( true ) else ( false ) )) struct mtlData( public mapName = "", public relalMap)openLog "D:\Users\Administrator\Desktop\3DMAX_OBJ\my_log.txt" mode:"a" outputOnly:truetexturePathToMapNameDict = dict()mapCount = 1000fn processStandardMaterial mat = ( if (mat.diffusemap != undefined) then ( diffmap = mat.diffusemap mapname = diffmap.name if (diffmap.fileName != undefined) then ( filepath = diffmap.fileName as string if (texturePathToMapNameDict.ContainsKey filepath) then ( dm = texturePathToMapNameDict.getItem filepath --print ("change " + mat.diffusemap.name + " to " + (texturePathToMapNameDict.getItem filepath).name) mat.diffusemap = copy dm updateMTLInMedit mat.diffusemap ) else ( newMapName = "Map_#" + (mapCount as string) mapCount = mapCount + 1 newDiffuse = mat.diffusemap newDiffuse.name = newMapName --newDiffuse.reload() mat.diffusemap = copy newDiffuse texturePathToMapNameDict.add filepath newDiffuse ) ) ))fn processMultimaterial mat = ( materialList = mat.materialList for mm in materialList do ( if classof mm == Standardmaterial then ( processStandardMaterial mm ) else if classof mm == Multimaterial then ( processMultimaterial mm ) ))--meditMaterials--SceneMaterialsfor mat in SceneMaterials do( if classof mat == Standardmaterial then ( processStandardMaterial mat ) else if classof mat == Multimaterial then ( processMultimaterial mat ))standardMaterialDic = dict()matNameCount = 1fn processRenameStandardMaterial mat =( --print ("process std" + mat.name) if (standardMaterialDic.ContainsKey mat.name) then ( diffusemap = standardMaterialDic.getItem mat.name if ((diffusemap == undefined and mat.diffusemap == undefined) or (diffusemap != undefined and mat.diffusemap != undefined and diffusemap.name == mat.diffusemap.name)) then ( --print ("same" + diffusemap.name) ) else ( print ("change " + mat.name + " to " + (mat.name + "_" + matNameCount as string)) mat.name = (mat.name + "_" + matNameCount as string) matNameCount = matNameCount + 1 standardMaterialDic.add mat.name mat.diffusemap ) ) else ( --print ("change " + mat.name) standardMaterialDic.add mat.name mat.diffusemap ))fn processRenameMultimaterial mat = ( --print ("process mul" + mat.name) materialList = mat.materialList for mm in materialList do ( if classof mm == Standardmaterial then ( processRenameStandardMaterial mm ) else if classof mm == Multimaterial then ( processRenameMultimaterial mm ) ))for mat in SceneMaterials do( if classof mat == Standardmaterial then ( processRenameStandardMaterial mat ) else if classof mat == Multimaterial then ( processRenameMultimaterial mat ))print ("转换完成!!!")closeLog()
dict字典代码来自博客
代码很简单,就是先把map同名但是贴图路径不一致名字自动修改map名字,然后Standardmaterial名字一样但是map名字不一致自动修Standardmaterial名字,不考虑Multimaterial名字一样但是里面数据不一样的情况。代码边学边写-_-。主要参考:
1. API参考:http://docs.autodesk.com/3DSMAX/16/ENU/MAXScript-Help/
2. 语法参考:<<3ds MAXScript 脚本语言>>
阅读全文
0 0
- 3ds Max导出OBJ的mtl贴图路径不正确
- 3ds max的纹理导出
- 3Ds MAX 光照贴图uv
- 3ds Max材质贴图批量重命名
- 3ds max法线贴图制作流程
- three for 3ds max 导出three obj 模型文件,插件安装方法
- [转]3ds max sdk导出插件编写的心得
- 3ds max sdk导出插件编写的心得
- 3ds max 中平滑组顶点法线的导出
- unity自带LightMapping和3Ds Max烘焙贴图的小对比
- unity自带LightMapping和3Ds Max烘焙贴图的小对比
- unity自带LightMapping和3Ds Max烘焙贴图的小对比
- Autodesk 3ds Max 新手入门必看(如何贴图)
- 3ds max 导出插件开发后记
- 3ds max 导出插件开发后记
- Android OpenGLES2.0(十六)——3D模型贴图及光照处理(obj+mtl)
- 3DXI重写过的3Ds Max 导出插件代码放出
- 通过编写3ds max插件导出模型数据的一个demo
- 第二周 Linux基础命令入门(二)
- LeetCode<Day2> Distribute Candies
- the general framework of RL_DQN
- java小细节不然很容易报错或者出逻辑问题得不到自己想要的。
- ARM的商业模式和ARM各种版本号区分
- 3ds Max导出OBJ的mtl贴图路径不正确
- 根据id分表
- SVN 使用简介及个人总结
- 131. Palindrome Partitioning
- C++之inline函数
- 如何远程操控另一台计算机
- A14_反射
- android inflate源码解析
- 53. Maximum Subarray