关闭

Houdini otl bake fracture animation Python程序

标签: Houdiniotlbakefractureanimation
572人阅读 评论(0) 收藏 举报
分类:


*详情见附件:http://download.csdn.net/detail/baichuanxiaoove/9283755

Usage:

- Install bakeRBD.otl

通过这个工具可以将每个Voronoi Fracture碎块bake成关键帧动画形成每个单独的带动画帧的Geometry物体,可以导出FBX格式文件。

注意Voronoi FracturePack参数设置破碎的碎块必须进行Pack之后再进行动力学解算。具体动力学节点连接请参看bakeRBD.hip场景测试文件。计算动力学时间bake碎块10000,时间5min左右

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 bakeRBD():
    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()+'/pack1')
        group_piece = c_node.parm('group1')
        group_piece.set('@name=piece'+str(point.number()))

        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"

 

0
0

猜你在找
【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐(算法+实战)--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:9740次
    • 积分:245
    • 等级:
    • 排名:千里之外
    • 原创:15篇
    • 转载:0篇
    • 译文:0篇
    • 评论:2条
    文章分类
    文章存档
    最新评论