Home Coding, Scripting, Shaders

Need help using the Simple_Hair_UV script for creating hair uvs

polycounter lvl 9
Offline / Send Message
mickeal_alex polycounter lvl 9

Im using the Simple_Hair_UV script found in the Xgen UE documentation however when i imported my IGS alembic file that i exported, it has 3 different description and multiple splinegrp .
How do i add multiple groups and curves in the script?
Tried using " ; " and " , " in between each group and it doesn’t work.

https://docs.unrealengine.com/4.26/en-US/WorkingWithContent/Hair/XgenGuidelines/

Here is the part i am having trouble with, it's using Python.

curve_top_group= 'Herc_Flyaways|Herc_Hair_SplineGrp0 , Herc_HairBlend|Herc_Hair_SplineGrp0 , Herc_Hair|Herc_Hair_SplineGrp0'

It keeps giving me error, here is how the outliner looks like

 Wip385jpg 


Herer is the default script:

  1. from maya import OpenMaya
  2. import os
  3.  
  4. def create_root_uv_attribute(curves_group, mesh_node, uv_set='map1'):
  5. '''
  6. Create "groom_root_uv" attribute on group of curves.
  7. '''
  8.  
  9. # check curves group
  10. if not cmds.objExists(curves_group):
  11. raise RuntimeError('Group not found: "{}"'.format(curves_group))
  12.  
  13. # get curves in group
  14. curve_shapes = cmds.listRelatives(curves_group, shapes=True, noIntermediate=True)
  15. curve_shapes = cmds.ls(curve_shapes, type='nurbsCurve')
  16. if not curve_shapes:
  17. raise RuntimeError('Invalid curves group. No nurbs-curves found in group.')
  18. else:
  19. print "found curves"
  20. print curve_shapes
  21.  
  22. # get curve roots
  23. points = list()
  24. for curve_shape in curve_shapes:
  25. point = cmds.pointPosition('{}.cv[0]'.format(curve_shape), world=True)
  26. points.append(point)
  27.  
  28. # get uvs
  29. values = list()
  30. uvs = find_closest_uv_point(points, mesh_node, uv_set=uv_set)
  31. for u, v in uvs:
  32. values.append([u, v, 0])
  33. #print (str(u) + " , " + str(v) )
  34.  
  35. # create attribute
  36. name = 'groom_root_uv'
  37. cmds.addAttr(curves_group, ln=name, dt='vectorArray')
  38. cmds.addAttr(curves_group, ln='{}_AbcGeomScope'.format(name), dt='string')
  39. cmds.addAttr(curves_group, ln='{}_AbcType'.format(name), dt='string')
  40.  
  41. cmds.setAttr('{}.{}'.format(curves_group, name), len(values), *values, type='vectorArray')
  42. cmds.setAttr('{}.{}_AbcGeomScope'.format(curves_group, name), 'uni', type='string')
  43. cmds.setAttr('{}.{}_AbcType'.format(curves_group, name), 'vector2', type='string')
  44.  
  45. return uvs
  46.  
  47. def find_closest_uv_point(points, mesh_node, uv_set='map1'):
  48. '''
  49. Find mesh UV-coordinates at given points.
  50. '''
  51.  
  52. # check mesh
  53. if not cmds.objExists(mesh_node):
  54. raise RuntimeError('Node not found: "{}"'.format(mesh_node))
  55.  
  56. # check uv_set
  57. uv_sets = cmds.polyUVSet(mesh_node, q=True, allUVSets=True)
  58. if uv_set not in uv_sets:
  59. raise RuntimeError('Invalid uv_set provided: "{}"'.format(uv_set))
  60.  
  61. # get mesh as dag-path
  62. selection_list = OpenMaya.MSelectionList()
  63. selection_list.add(mesh_node)
  64.  
  65. mesh_dagpath = OpenMaya.MDagPath()
  66. selection_list.getDagPath(0, mesh_dagpath)
  67. mesh_dagpath.extendToShape()
  68.  
  69. # get mesh function set
  70. fn_mesh = OpenMaya.MFnMesh(mesh_dagpath)
  71.  
  72. uvs = list()
  73. for i in range(len(points)):
  74.  
  75. script_util = OpenMaya.MScriptUtil()
  76. script_util.createFromDouble(0.0, 0.0)
  77. uv_point = script_util.asFloat2Ptr()
  78.  
  79. point = OpenMaya.MPoint(*points[i])
  80. fn_mesh.getUVAtPoint(point, uv_point, OpenMaya.MSpace.kWorld, uv_set)
  81.  
  82. u = OpenMaya.MScriptUtil.getFloat2ArrayItem(uv_point, 0, 0)
  83. v = OpenMaya.MScriptUtil.getFloat2ArrayItem(uv_point, 0, 1)
  84.  
  85. uvs.append((u, v))
  86.  
  87. return uvs
  88.  
  89. def abc_export(filepath, node=None, start_frame=1, end_frame=1, data_format='otawa', uv_write=True):
  90.  
  91. job_command = '-frameRange {} {} '.format(start_frame, end_frame)
  92. job_command += '-dataFormat {} '.format(data_format)
  93.  
  94. job_command += '-attr groom_root_uv '
  95.  
  96. if uv_write:
  97. job_command += '-uvWrite '
  98.  
  99. job_command += '-root {} '.format(node)
  100.  
  101. job_command += '-file {} '.format(filepath)
  102.  
  103. cmds.AbcExport(verbose=True, j=job_command)
  104.  
  105. def main():
  106.  
  107. export_directory = 'D:/Dev/Ref'
  108. hair_file = os.path.join(export_directory, 'hair_export.abc')
  109. curve_top_group= 'description1|SplineGrp0'
  110. uv_mesh='pPlane1'
  111.  
  112. create_root_uv_attribute( curve_top_group , uv_mesh)
  113. abc_export(hair_file, curve_top_group)
  114.  
  115. main()

Replies

Sign In or Register to comment.