文章目录
- ?? 前言
- ?? 如何将RPM中编辑的Avatar导入到Unity
- ?? 如何提取模型中的Mesh网格、Material材质、及Texture贴图
- ?? 如何提取RPM网页中的图片资源
- ?? 资源配置
?? 前言
在RPM的Avatar Hub中,选择我们想要导入到Unity中的Avatar,通过复制链接。
下载完成后,在文件夹下可以看到下载的.glb模型文件:
?? 如何提取模型中的Mesh网格、Material材质、及Texture贴图
网格和材质的提取可以直接在组件中获取并通过并调用类中的来创建和保存资产:
- asset:第一个参数为要进行保存/创建的资产;
- path:第二个参数为该资产生成的文件夹路径。
而贴图资源可以通过调用类中的方法获取材质球的依赖项文件路径:
根据路径调用方法加载贴图资源:
本篇内容中提取Avatar数字人相关资产的工作流如下:
- fbx导入到Unity后,在导入设置中将类型改为,应用后编辑器会在该fbx文件所在目录下生成相应的材质和贴图资源文件夹:
该方法可以提取Avatar的头部、身体、上衣、裤子及鞋子的相关资产,代码如下:
using UnityEngine;using UnityEditor;namespace Metaverse{ ///
/// 用于提取ReadyPlayerMe的Avatar服装资源 ///
public class RPMAvatarClothingCollecter {[MenuItem("Metaverse/Ready Player Me/Avatar Clothing Collect")]public static void Execute(){ //如果未选中任何物体 if (Selection.activeGameObject == null) return; //弹出窗口 选择资源提取的路径 string collectPath = EditorUtility.OpenFolderPanel("选择路径", Application.dataPath, null); //如果路径为空或无效 返回 if (string.IsNullOrEmpty(collectPath)) return; //AssetDatabase路径 collectPath = collectPath.Replace(Application.dataPath, "Assets"); if (!AssetDatabase.IsValidFolder(collectPath)) return; //头部 Transform head = Selection.activeGameObject.transform.Find("Wolf3D_Head"); if (head != null) Collect(collectPath, head.GetComponentSkinnedMeshRenderer>(), "head"); //身体 Transform body = Selection.activeGameObject.transform.Find("Wolf3D_Body"); if (head != null) Collect(collectPath, body.GetComponentSkinnedMeshRenderer>(), "body"); //上衣 Transform top = Selection.activeGameObject.transform.Find("Wolf3D_Outfit_Top"); if (top != null) Collect(collectPath, top.GetComponentSkinnedMeshRenderer>(), "top"); //裤子 Transform bottom = Selection.activeGameObject.transform.Find("Wolf3D_Outfit_Bottom"); if (bottom != null) Collect(collectPath, bottom.GetComponentSkinnedMeshRenderer>(), "bottom"); //鞋子 Transform footwear = Selection.activeGameObject.transform.Find("Wolf3D_Outfit_Footwear"); if (footwear != null) Collect(collectPath, footwear.GetComponentSkinnedMeshRenderer>(), "footwear"); //刷新 AssetDatabase.Refresh();}public static void Collect(string path, SkinnedMeshRenderer smr, string suffix){ //创建Mesh网格资产 AssetDatabase.CreateAsset(Object.Instantiate(smr.sharedMesh), string.Format("{0}/mesh_{1}.asset", path, suffix)); 来源:CoderZ1010
声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!