日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

3ds Max导出OBJ的mtl贴图路径不正确

發布時間:2023/12/20 编程问答 70 豆豆
生活随笔 收集整理的這篇文章主要介紹了 3ds Max导出OBJ的mtl贴图路径不正确 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 3DSMax導出的材質mtl文件漫反射貼圖路徑不正確

之前流程是寫了一個3DSMAX插件把游戲的場景直接導出為自己定義的格式的文件,包含了頂點數據,三角形數據,貼圖數據等。現在把插件從3DMAX上分離出來,先通過3DMAX導出OBJ,然后再把OBJ導出為自定義的格式。

3DSMax導出的材質mtl文件漫反射貼圖路徑不正確

一開始以為是一個Standardmaterial對應漫反射的Map名字一樣但是貼圖路徑不一樣導致了OBJ導出出錯。寫了一個把同一個Map但是對應不同的貼圖路徑的Map自動重命名的MaxScript腳本,導出發現結果是一樣的。
一個Multimaterial下的Standardmaterial和一個Standardmaterial名字一樣,但是這二個Standardmaterial的diffusemap的文件路徑不一樣。從而導致了OBJ導出出錯。

自動轉換的代碼如下:

--My Dictionary struct 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 key1append values value1true)else(print ("key has already been added! -->" + key1)false)),fn Clear = (keys = #()values = #()true),fn Remove key = (index = findItem keys keyif index != 0 then(deleteItem keys indexdeleteItem values indextrue)else(print ("cann't find the key! -->" + key)false)),fn GetItem key = (index = findItem keys keyif 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 keyif 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:true texturePathToMapNameDict = dict() mapCount = 1000fn processStandardMaterial mat = (if (mat.diffusemap != undefined) then(diffmap = mat.diffusemapmapname = diffmap.nameif (diffmap.fileName != undefined) then(filepath = diffmap.fileName as stringif (texturePathToMapNameDict.ContainsKey filepath) then(dm = texturePathToMapNameDict.getItem filepath--print ("change " + mat.diffusemap.name + " to " + (texturePathToMapNameDict.getItem filepath).name)mat.diffusemap = copy dmupdateMTLInMedit mat.diffusemap)else(newMapName = "Map_#" + (mapCount as string)mapCount = mapCount + 1newDiffuse = mat.diffusemapnewDiffuse.name = newMapName--newDiffuse.reload()mat.diffusemap = copy newDiffusetexturePathToMapNameDict.add filepath newDiffuse ))) )fn processMultimaterial mat = (materialList = mat.materialListfor mm in materialList do(if classof mm == Standardmaterial then(processStandardMaterial mm)else if classof mm == Multimaterial then(processMultimaterial mm)) ) --meditMaterials --SceneMaterials for 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.nameif ((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 + 1standardMaterialDic.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.materialListfor 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名字一樣但是里面數據不一樣的情況。代碼邊學邊寫-_-。主要參考:

  • API參考:http://docs.autodesk.com/3DSMAX/16/ENU/MAXScript-Help/
  • 語法參考:<<3ds MAXScript 腳本語言>>
  • 總結

    以上是生活随笔為你收集整理的3ds Max导出OBJ的mtl贴图路径不正确的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。