Maya-UE xgen-UE 毛发导入UE流程整理

首先声明:maya建议用2022版本及一下,因为要用到Python 2 ,Maya2023以后默认是Python3不再支持Python2;

第一步:Xgen做好的毛发转成交互式Groom

第二步:导出刚生成的交互式Groom缓存,需要设置一下当前帧,和写入宽度;到这里其实就可以直接导入到UE了,为了后面能做多颜色毛发和渐变毛发可以继续看,如果不需要,到这一步就可以直接打开UE导入了,按照后面的流程导入UE就可以了!

第三步:导入刚刚导出的缓存文件,导入后会根据毛发数量自动分组;

第四步:利用官方文档的Python脚本分别重新导出这三个分好组的缓存文件,这一步的目的是为了让缓存文件拥有UV,方便进去UE后根据需求继续调整(举例做渐变毛发和多颜色毛发);可以直接复制,有几个代码需要修改,看说明;

复制代码
from maya import cmds
from maya import OpenMaya
import os


def create_root_uv_attribute(curves_group, mesh_node, uv_set='map1'):
    '''
    Create "groom_root_uv" attribute on group of curves.
    '''

    # check curves group
    if not cmds.objExists(curves_group):
        raise RuntimeError('Group not found: "{}"'.format(curves_group))

    # get curves in group
    curve_shapes = cmds.listRelatives(curves_group, shapes=True, noIntermediate=True)
    curve_shapes = cmds.ls(curve_shapes, type='nurbsCurve')
    if not curve_shapes:
        raise RuntimeError('Invalid curves group. No nurbs-curves found in group.')
    else:
        print "found curves"
        print curve_shapes

    # get curve roots
    points = list()
    for curve_shape in curve_shapes:
        point = cmds.pointPosition('{}.cv[0]'.format(curve_shape), world=True)
        points.append(point)

    # get uvs
    values = list()
    uvs = find_closest_uv_point(points, mesh_node, uv_set=uv_set)
    for u, v in uvs:
        values.append([u, v, 0])
        #print (str(u) + " , " + str(v)  )

    # create attribute
    name = 'groom_root_uv'
    cmds.addAttr(curves_group, ln=name, dt='vectorArray')
    cmds.addAttr(curves_group, ln='{}_AbcGeomScope'.format(name), dt='string')
    cmds.addAttr(curves_group, ln='{}_AbcType'.format(name), dt='string')

    cmds.setAttr('{}.{}'.format(curves_group, name), len(values), *values, type='vectorArray')
    cmds.setAttr('{}.{}_AbcGeomScope'.format(curves_group, name), 'uni', type='string')
    cmds.setAttr('{}.{}_AbcType'.format(curves_group, name), 'vector2', type='string')

    return uvs

def find_closest_uv_point(points, mesh_node, uv_set='map1'):
    '''
    Find mesh UV-coordinates at given points.
    '''

    # check mesh
    if not cmds.objExists(mesh_node):
        raise RuntimeError('Node not found: "{}"'.format(mesh_node))

    # check uv_set
    uv_sets = cmds.polyUVSet(mesh_node, q=True, allUVSets=True)
    if uv_set not in uv_sets:
        raise RuntimeError('Invalid uv_set provided: "{}"'.format(uv_set))

    # get mesh as dag-path
    selection_list = OpenMaya.MSelectionList()
    selection_list.add(mesh_node)

    mesh_dagpath = OpenMaya.MDagPath()
    selection_list.getDagPath(0, mesh_dagpath)
    mesh_dagpath.extendToShape()

    # get mesh function set
    fn_mesh = OpenMaya.MFnMesh(mesh_dagpath)

    uvs = list()
    for i in range(len(points)):

        script_util = OpenMaya.MScriptUtil()
        script_util.createFromDouble(0.0, 0.0)
        uv_point = script_util.asFloat2Ptr()

        point = OpenMaya.MPoint(*points[i])
        fn_mesh.getUVAtPoint(point, uv_point, OpenMaya.MSpace.kWorld, uv_set)

        u = OpenMaya.MScriptUtil.getFloat2ArrayItem(uv_point, 0, 0)
        v = OpenMaya.MScriptUtil.getFloat2ArrayItem(uv_point, 0, 1)

        uvs.append((u, v))

    return uvs

def abc_export(filepath, node=None, start_frame=1, end_frame=1, data_format='otawa', uv_write=True):
    
    job_command = '-frameRange {} {} '.format(start_frame, end_frame)
    job_command += '-dataFormat {} '.format(data_format)
    
    job_command += '-attr groom_root_uv '

    if uv_write:
        job_command += '-uvWrite '
    
    job_command += '-root {} '.format(node)   
    
    job_command += '-file {} '.format(filepath) 
    
    cmds.AbcExport(verbose=True, j=job_command)
    
    


def main():
    
    export_directory = 'D:/Dev/Ref'
    hair_file = os.path.join(export_directory, 'hair_export.abc')
    curve_top_group= 'description1|SplineGrp0'
    uv_mesh='pPlane1'
    
    create_root_uv_attribute( curve_top_group , uv_mesh)
    abc_export(hair_file, curve_top_group)
    
main()

第五步:由于是分别导出的3个文件,因为三个分别导入UE有些麻烦也没必要,需要重新整合一下;重新开一个新的maya文件,把3个缓存文件重新导入到新的maya里面,再次整体导出一个缓存文件;这里需要添加一个groom_root_UV(说明 :groom_root_uv属性为每根头发指定它所附加到的基础网格uv。该属性是可选的,如果未指定,将使用球形贴图在引擎中自动生成一个根UV)

第六步:导入UE,需要设置一下项目设置和插件;

然后导入窗口的旋转设置一下;

这里可以设置一下基础属性;

这里可以开启物理模拟;
可以创建绑定;这样就可以替换默认的头发了,也可以通道添加组件添加到骨骼模型上;

打开角色蓝图,就可以替换之前的模型资产和材质了;

材质球设置:



这里可以通过绘画贴图来实现不同颜色的发色;

相关推荐
Microvision维视智造2 天前
焊缝好不好,用数据说了算 | 激光焊接 3D 视觉检测方案
人工智能·计算机视觉·3d·机器人·视觉检测·机器视觉
硅谷秋水4 天前
面向精确到达任务的机器人-对齐3D高斯溅射方法——基于腕部-相机VLA策略
数码相机·机器学习·计算机视觉·3d·机器人
feasibility.8 天前
英伟达把物理AI的3D模型“应用商店”开放了:2575个SimReady仿真资产,总计约472GB,可让agent装配机器人训练场景
人工智能·3d·机器人·仿真·建模·具身智能·英伟达
mengzhi啊10 天前
UE5角色模型替换核心:设置领导者姿势组件
ue5
Solange__10 天前
Blender 3D模型优化:普通复制、共享网格、实例、合并怎么选?
人工智能·3d·ai·自然语言处理·编辑器·blender·材质
Martina_032111 天前
AI生成的3D白模单帧没问题,镜头一移动就被挡?用6步检查遮挡与构图
图像处理·人工智能·数学建模·3d·ai·自然语言处理·游戏策划
mengzhi啊14 天前
UE5 沙漠添加植物,然后在湖泊游泳。关键词:湖泊使用蓝图的重叠事件,湖泊的碰撞偏移。所有的物体都可以使用蓝图来使用它
ue5
时间的情敌14 天前
Cesium 建筑单体化、3DTiles 分类、楼层显隐、分户高亮(BIM + 倾斜孪生高频)
前端·3d·cesium
加搜科技观察15 天前
哪个品牌 3D 相机好用?工业 3D 相机品牌选型评估指南
数码相机·3d