Houdini低模解算转成高模关键帧动画并拆分碎块UV

2019-04-13 12:11发布

    bakeFragDetailsUV.otl可以实现将刚体解算的低模运动状态转换成高模关键帧动画,碎块UV进行表面和内部的分离,以便导入maya使用,基于软件版本Houdini FX 15.0.244.16。 节点连接注意节点的参数设置,相同节点设置可能有所不同: 低模进行刚体解算,高模匹配动画关键帧包括位移旋转。 对碎块进行UV拆分,将outsideinsideUV进行分开。 图一连接节点并设置好参数之后,选择bakeFragDetailsUV1节点设置好需要bake的起始帧和结束帧之后,点击Bake Frag Details UV按钮,/obj路径生成group即为动画UV的高模 PythonModule代码 from time import * #Bake RBDs simulation to "group" subnetwork #Packed RBDs simulation and get attributes as Trans,Orient,Pivot etc #Transfer the Orient attribute to rotation def bakeFragDetailsUV(): tstart = time() hou_node = hou.pwd() hou_geo = hou_node.geometry() points = hou_geo.points() points_num = len(points) # print points_num point_loc = hou.node('/obj') group_node = point_loc.createNode('subnet','group') rbd_node = hou_node.node('..') group_node.setPosition(rbd_node.position()) group_node.move([0,-1]) group_node.setSelected(True) rbd_node.setSelected(False) # create copy piece,set the pivot for point in points: frags_node = group_node.createNode('geo','due'+str(point.number())) a_node = hou.node('/obj/group/due'+str(point.number())) b_node = a_node.children() b_node[0].destroy() c_node = a_node.createNode('object_merge','piece'+str(point.number())) obj_path = c_node.parm('objpath1') obj_path.set('/obj/'+rbd_node.name()+'/pack2') group_piece = c_node.parm('group1') group_piece.set('@name=piece'+str(point.number())) unpack_node = a_node.createNode('unpack','unpack'+str(point.number())) unpack_node.setPosition(c_node.position()) unpack_node.move([0,-1]) unpack_node.setNextInput(c_node) unpack_node.setDisplayFlag(True) unpack_node.setRenderFlag(True) pivot_origin = point.attribValue('pivot') # print pivot_origin a_node.setParms({'px':pivot_origin[0], 'py':pivot_origin[1], 'pz':pivot_origin[2]}) # print a_node.evalParmTuple('p') # setKeyframe tx,ty,tz,rx,ry,rz # for x in range(int(hou.expandString('$FSTART')), int(hou.expandString('$FEND'))+1, 1): for x in range(int(hou_node.evalParm('f1')), int(hou_node.evalParm('f2'))+1, 1): hou.setFrame(x) print str(x) + ' frame' + ',please wait...' for point in points: pos1 = point.position() # print "(%d) -> x=%f, y=%f, z=%f" % (point.number(), pos1[0], pos1[1], pos1[2]) pos2 = point.attribValue('pivot') # print "(%d) -> x=%f, y=%f, z=%f" % (point.number(), pos2[0], pos2[1], pos2[2]) pos3 = [0,0,0] if(x != 1): pos3[0] = pos1[0]-pos2[0] pos3[1] = pos1[1]-pos2[1] pos3[2] = pos1[2]-pos2[2] # print "(%d) -> x=%f, y=%f, z=%f" % (point.number(), pos3[0], pos3[1], pos3[2]) orient_num = point.attribValue('orient') # print "(%d) -> x=%f, y=%f, z=%f, n=%f" % (point.number(), orient_num[0], orient_num[1], orient_num[2], orient_num[3]) frags_selet_node = hou.node('/obj/group/due'+str(point.number())) orient_qua = hou.Quaternion(orient_num).normalized() # print type(orient_qua) matrix3 = orient_qua.extractRotationMatrix3() # print matrix3 rot = matrix3.extractRotates() # print rot point_tx = frags_selet_node.parm('tx') point_keyframe = hou.Keyframe() point_keyframe.setValue(pos3[0]) point_tx.setKeyframe(point_keyframe) point_ty = frags_selet_node.parm('ty') point_keyframe = hou.Keyframe() point_keyframe.setValue(pos3[1]) point_ty.setKeyframe(point_keyframe) point_tz = frags_selet_node.parm('tz') point_keyframe = hou.Keyframe() point_keyframe.setValue(pos3[2]) point_tz.setKeyframe(point_keyframe) point_rx = frags_selet_node.parm('rx') point_keyframe = hou.Keyframe() point_keyframe.setValue(rot[0]) point_rx.setKeyframe(point_keyframe) point_ry = frags_selet_node.parm('ry') point_keyframe = hou.Keyframe() point_keyframe.setValue(rot[1]) point_ry.setKeyframe(point_keyframe) point_rz = frags_selet_node.parm('rz') point_keyframe = hou.Keyframe() point_keyframe.setValue(rot[2]) point_rz.setKeyframe(point_keyframe) print 'Done' tend = time() t = tend - tstart print 'time use ' + str(int(t)) +" s" 详情见附件:http://download.csdn.net/detail/baichuanxiaoove/9293197