思路:在3dsmax中先记录每一个材质球对应的材质名与其所使用的贴图名,写出文件,然后uniyt中读取这个材质名与贴图名,在unity中批量将材质球恢复贴图。

3dsmax导出材质名与贴图名部分

struct HMtl(mtlDiffuse,mtlReflection,mtlRefraction,mtlBump,mtlOpacity)
--将list里的内容写入in_test
fn formatList2 list in_text= (file = CreatEFile in_textif list.count !=0 then(for listInner in list do(if listInner.count != 0 then(format "usemat %\n" (listInner[1]) to:fileformat "\tdifmap:%\n" (listInner[2]) to:file))--for i结束)--if 结束   )
--------------------------------------------------------------------------------------------------------------------------通道过滤 --通道迭代找出贴图路径 --MapChannel 通道名--MapList 接受贴图路径的数组fn Get_MapChannel MapChannel =(--MapList = #() --清空数组--如果这个通道不为空则进行下面的判断if classof MapChannel != UndefinedClass do(filepath =case classof MapChannel of (--1 Bitmaptexture: if MapChannel.filename!=undefined then MapChannel.filename  --2falloff: Get_MapChannel MapChannel.map1--3Color_Correction: Get_MapChannel MapChannel.map--4Mask: Get_MapChannel MapChannel.map  Mix: Get_MapChannel MapChannel.mask --20190423添加 CompositeTexturemap: Get_MapChannel MapChannel.mapList[1]  --20190424 合成材质通道VRayNormalMap:Get_MapChannel MapChannel.normal_map --20192424VrayNormalMapVRayHDRI: if MapChannel.HDRIMapName!=undefined and MapChannel.HDRIMapName!= "" then MapChannel.HDRIMapName       --20190605对hdr贴图的处理)))
--------------------------------------------------------------------------------------------------------------------------获取Mtl的贴图
fn Get_Map Mtl =(  if ((superclassof Mtl)!=material) then return MtlmatClass= classof Mtl    --获取选择物体的材质类型   VR:VRayMtl; 标准:Standardmaterial;  多维子材质:Multimaterial ;混全材质:Blendcase matClass of(--0CoronaMtl:(                   ---漫反射通道mtlDiffuse =if Mtl.texmapDiffuse!=undefined then Get_MapChannel Mtl.texmapDiffuse --print mtlDiffuseMap.count---凹凸通道          mtlBump = if Mtl.texmapBump!=undefined then Get_MapChannel Mtl.texmapBump     --print mtlBump.count---反射通道mtlReflection = if Mtl.texmapReflect!=undefined then  Get_MapChannel Mtl.texmapReflect --print mtlReflectionMap.count---折射通道mtlRefraction = if Mtl.texmapRefract!=undefined then Get_MapChannel Mtl.texmapRefract --print mtlRefractionMap.count---镂空通道mtlOpacity = if Mtl.texmapOpacity!=undefined then Get_MapChannel Mtl.texmapOpacity --print mtlOpacity.count)--1VrayMtl:(                   ---漫反射通道mtlDiffuse =if Mtl.texmap_diffuse!=undefined then Get_MapChannel Mtl.texmap_diffuse --print mtlDiffuseMap.count---凹凸通道            mtlBump = if Mtl.texmap_bump!=undefined then Get_MapChannel Mtl.texmap_bump   --print mtlBump.count---反射通道mtlReflection = if Mtl.texmap_reflection!=undefined then  Get_MapChannel Mtl.texmap_reflection --print mtlReflectionMap.count---折射通道mtlRefraction = if Mtl.texmap_refraction!=undefined then Get_MapChannel Mtl.texmap_refraction --print mtlRefractionMap.count---镂空通道mtlOpacity = if Mtl.texmap_opacity!=undefined then Get_MapChannel Mtl.texmap_opacity --print mtlOpacity.count)-------------------------------------------------    Standardmaterial:(--print "Standardmaterial:"---漫反射通道mtlDiffuse =if Mtl.diffuseMap!=undefined then Get_MapChannel Mtl.diffuseMap --print mtlDiffuseMap.count---凹凸通道         mtlBump = if Mtl.bumpMap!=undefined then Get_MapChannel Mtl.bumpMap--print mtlBump.count---反射通道mtlReflection = if Mtl.reflectionMap!=undefined then  Get_MapChannel Mtl.reflectionMap--print mtlReflectionMap.count---折射通道mtlRefraction = if Mtl.refractionMap!=undefined then Get_MapChannel Mtl.refractionMap--print mtlRefractionMap.count---镂空通道mtlOpacity = if Mtl.opacityMap!=undefined then Get_MapChannel Mtl.opacityMap)-------------------------------------------------CoronaLightMtl:(--print "CoronaLightMtl:"mtlDiffuse =if Mtl.texmap!=undefined then Get_MapChannel Mtl.texmap )VRayLightMtl:(--print --"VRayLightMtl:"mtlDiffuse =if Mtl.texmap!=undefined then Get_MapChannel Mtl.texmap )-------------------------------------------------   Multimaterial:(messagebox "这是一个多维子材质,请处理后再给材质!")-------------------------------------------------  Blend:(messagebox "这是一个混合材质Blend,请处理后再给材质!")--VRayMtlWrapper:Get_Map Mtl.baseMtl--VRayBlendMtl:Get_Map Mtl.baseMtl--VRay2SidedMtl:Get_Map Mtl.frontMtl                default: return undefined               )--print "原始材质的贴图有:"--print("mtlDiffuse:"+mtlDiffuse as string )--print("mtlReflection:"+mtlReflection as string)--print("mtlRefraction:"+mtlRefraction as string)--print("mtlBump:"+mtlBump as string)--print("mtlOpacity:"+mtlOpacity as string)HMtl2 = HMtl mtlDiffuse:mtlDiffuse mtlReflection:mtlReflection mtlRefraction:mtlRefraction mtlBump:mtlBump mtlOpacity:mtlOpacity        )fn getMatAndDifMap = (mats = scenematerials  matAndMapList = #()        --mat and diffusemapfor mat in mats do(     matmaps = Get_Map mat          diffuseMapName = matmaps.mtlDiffuseif diffuseMapName != undefined then (diffuseMapName2 = (filenameFromPath diffuseMapName)append matAndMapList #(mat.name,diffuseMapName2)--print(mat.name)--print (diffuseMapName2)--print("----------------")))matAndMapList    )

调用说明:

f = "E:\a.p"
matmaplist = getMatAndDifMap ()    --返回的是一个二维数组
formatList2  matmaplist f       --写出到文件f中

Unity 代码部分

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
using System.Text.RegularExpressions;
//存储材质相关信息的结构体
public struct MatMap{public string MatName;public string DiffuseMap;public MatMap( string matname, string diffusemap  ){this.MatName = matname;this.DiffuseMap = diffusemap;}public string matname{get{return this.MatName;}set{this.MatName = value;}}public string diffusemap{get{return this.DiffuseMap;}set{this.DiffuseMap = value;}}
}
public class HyqMenumTools : MonoBehaviour
{//MARSK 材质贴图对应关系数据库public static string MatTextureFilePath = "Assets/Hyq/Models/a.p";public static string modelName = "";//材质球所在的资源文件夹路径public static string matDirPath = "Assets/Hyq/Models/NavTest1/Materials";// MARSK _w 单一的快捷键 w// MARSK #w shift + w// MARSK %w CTRL + w// MARSK &W alt + w[MenuItem("HYQTOOLS/MenumTools/Test _n")]public static void Test(){Debug.Log("单一的快捷键 ::>>> n");        List<MatMap> matMaps =  GetMatMaps(MatTextureFilePath);foreach(MatMap m in matMaps){SetMatMap(m.matname,m.diffusemap);}Debug.Log(matMaps.Count);}//shift + i 导入材质贴图[MenuItem("HYQTOOLS/MenumTools/Test2# #i")]public static void Test2(){        Debug.Log("#i ::>>>>> shift + i");}//ctrl + i[MenuItem("HYQTOOLS/MenumTools/Test#% #%i")]public static void Test3(){Debug.Log("%i ::>>>>> ctrl+shift+ i");}//alt + i[MenuItem("HYQTOOLS/MenumTools/Test3& &i")]public static void Test4(){string fullPath = "Assets/Hyq/Models/NavTest1/Materials";//获取指定路径下面的所有资源文件if (Directory.Exists(fullPath)){DirectoryInfo direction = new DirectoryInfo(fullPath);FileInfo[] files = direction.GetFiles("*",SearchOption.AllDirectories);Debug.Log(files.Length);for(int i=0;i<files.Length;i++){if (files[i].Name.EndsWith(".meta")){continue;}Debug.Log( "Name:" + files[i].Name );//Debug.Log( "FullName:" + files[i].FullName );//Debug.Log( "DirectoryName:" + files[i].DirectoryName );}}}public static List<MatMap> GetMatMaps(string path){List<MatMap> matMaps = new List<MatMap>(); string lines =  File.ReadAllText(path);string[] linesList = lines.Split('\n');int len = linesList.Length;for(int i = 0;i < len-1;i+=2){string matName = linesList[i].Replace("usemat ",modelName).Trim();string diffuseMapName = linesList[i+1].TrimStart().Replace("difmap:","").Trim();matMaps.Add(new MatMap(matName,diffuseMapName));}   return matMaps;}public static void SetMatMap(string matName,string mapName){string matpath = matDirPath + "/" + matName +".mat";Material mat = AssetDatabase.LoadAssetAtPath<Material>(matpath);Texture map = AssetDatabase.LoadAssetAtPath<Texture>("Assets/Hyq/Models/NavTest1/textures/"+mapName);if (mat != null && map != null){mat.SetTexture("_BaseColorMap",map);}AssetDatabase.Refresh();  }
}

使用说明:脚本保存在Editor文件夹中,快捷键n执行命令.

UnityHDR渲染管线中使用3dsmax导入的模型丢失贴图恢复相关推荐

  1. unity导入的模型的贴图十分暗看不清

    unity导入的模型的贴图十分暗看不清 我将模型从3dmax导入unity,在3dmax中模型贴图看得十分清楚 但将模型导入unity之后,模型贴图特别暗,看不清楚. 最后我发现我的材质的反射颜色(A ...

  2. ArcGIS Pro2.7 导入obj模型后贴图丢失问题

    .mtl文件已经修改贴图为相对路径,import模型后仍然丢失贴图. 可能是模型中文导致的.测试,mtl,obj及obj内的mtl都修改为英文后,可以正常导入贴图. 建议:在3dsMax中建模的时候模 ...

  3. 3dmax材质丢失插件_常见3DMAX插件导出模型丢失贴图问题

    在使用超图3DMAX插件导出模型时,时常出现全部或局部区域出现贴图丢失的情况,本文收集了几种常见的贴图丢失问题,并且提供解决方案. 1. 模型中所有贴图不在一个文件夹下,或贴图文件夹中存在子文件夹(图 ...

  4. maya拆完uv,画好贴图后导入,模型上贴图显示混乱

    问题描述:拆好了UV,并且在棋盘格状态下也是对的,但是贴图之后就会混乱是为什么? 本文参考出自于知乎大佬的回答点击这里查看 Maya有个默认的uv集,叫map1,之后你每重新展一次uv和保存之后,就会 ...

  5. max模型怎么导入ue4_3dsMax模型转UE4

    转自:http://blog.csdn.net/qq_24835213/article/details/68063344 一.模型设置: 1.将Vary材质转成标准材质 2.将模型减面 3.加一套UV ...

  6. EF架构~将数据库注释添加导入到模型实体类中

    回到目录 相关文章系列 第八回 EF架构~将数据库注释添加导入到模型实体类中 第二十一回  EF架构~为EF DbContext生成的实体添加注释(T4模板应用) 第二十二回  EF架构~为EF Db ...

  7. Three.js中导入GLTF模型变黑无法看到模型

    一个下午都在Three.js官网导入GLTF模型,但是很不幸,根据官网DEMO中一直待有texture纹理,不能单独载入模型,后经一番查找,发现其实早已经单独讲模型载入到网页中,但是模型与背景色均为黑 ...

  8. 详解Unity中的导入3D模型

    前言 三维模型可以表示任何现实世界中存在的物体,自然也可以表示任何游戏世界中存在的物体,比如地面,山川河流,花草树木,建筑,人物,都需要使用三维模型来表示.一般我们使用一些建模软件来建出游戏中需要的模 ...

  9. Zemax | Zemax中导入CAD模型

    在处理非序列模式时常常需要导入一些复杂的模型结构,使用Zemax软件自身的画图功能显得有些相形见绌了,可以在CAD中先画好模型再导入进去. 一.将CAD模型导出为IGES/STEP等格式,将文件放出到 ...

最新文章

  1. 安装您的Sbo Add-on插件
  2. IT兄弟连 JavaWeb教程 JSON和JSON字符串
  3. Raising Modulo Numbers
  4. Qt程式异常崩溃处理技巧(Win)
  5. php 将颜色透明度,css中如何使颜色透明度
  6. 索尼发布Xperia 8手机:采用骁龙630处理器
  7. Android 下拉刷新用法
  8. speex回声消除源码解读
  9. 编程算法 - 赛马问题
  10. 商品信息mysql设计_电商-商品信息 - 数据库设计 - 数据库表结构 - 果创云
  11. 人像美颜美妆算法入门必备
  12. 关于python中的复数的虚部可以j或i_Python 中的复数问题
  13. 微信小程序:音乐播放器(附源码)
  14. java file数组 初始化_Java之处理数组
  15. python3出现TypeError: can only concatenate str (not bytes) to str的错误,大一刚上手python的学习,望大神解决。感激不尽
  16. c语言修改pdf文件内容,PDF如何编辑,PDF文件怎么修改文字
  17. Redis Key(键) 命令使用
  18. Java项目:毕业论文管理系统(java+SSM+JSP+Tomcat+mysql)
  19. 嵌入式之uboot源码分析-启动第二阶段学习笔记(下篇)
  20. python能做_Python能做什么?超乎你的想象

热门文章

  1. 表格属性cellspacing、cellpadding
  2. Leetcode 宝石与石头 C++
  3. Keil5修改背景黑色仿VS
  4. php梗相亲梗,真实、有梗、接地气,看完这档相亲节目你没笑算我输!
  5. Linux:磁盘配额
  6. 27 | 尽早暴露问题: 为什么被指责的总是你?
  7. android listview使用glide异步加载图片错位,闪烁问题
  8. 资源管理:caching模式
  9. 周鸿祎的绝招—“寄生战略”
  10. 如何使用Bootstrap制作网页主界面、增加界面