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,需要设置一下项目设置和插件;
在这里插入图片描述
在这里插入图片描述
然后导入窗口的旋转设置一下;
在这里插入图片描述
这里可以设置一下基础属性;
在这里插入图片描述
这里可以开启物理模拟;
在这里插入图片描述可以创建绑定;这样就可以替换默认的头发了,也可以通道添加组件添加到骨骼模型上;
在这里插入图片描述
打开角色蓝图,就可以替换之前的模型资产和材质了;
在这里插入图片描述
材质球设置:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
这里可以通过绘画贴图来实现不同颜色的发色;

在这里插入图片描述

在这里插入图片描述

  • 10
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值