Houdini KineFX 笔记

// space switch 功能

otl下载

让左边输入端(source_skeleton)的某个骨骼,跟随右输入端(parent_skeleton)的某个骨骼。

                     

 spaceswith_wrangle 代码 

#include <kinefx.h>
#include <kinefx_posedifference.h>

// Get joint data
string joint_name = chs("../joint") ;
string split[] = split(joint_name, "=");
if(len(split) > 1)
    joint_name = split[1] ;

int joint_id = findattribval(0, "point", "name", joint_name);
matrix joint_move_M  = pointtransform(0, joint_id) ;
matrix joint_stash_M = pointtransform(1, joint_id) ;


// Get space swtich
int chosen_space = chi("../spaceswitch") ;

// Transformation compoments used for blend
int components = chi("../components") ;

// Prep variables
string parent_parm ;
string parent_name ;
int parent_id ;

if(chosen_space >= 0 && chosen_space < chi("../config"))
{
    int i = chosen_space + 1 ;

    // Get parent data
    parent_parm = sprintf("../parent%d", i);
    parent_name = chs(parent_parm) ;
    split = split(parent_name, "=") ;
    if(len(split) > 1)
        parent_name = split[1] ;

    parent_id = findattribval(2, "point", "name", parent_name);
    matrix parent_stash_M = pointtransform(2, parent_id) ;
    matrix parent_move_M  = pointtransform(3, parent_id) ;

    // Get diference matrix
    matrix diff_M = joint_stash_M * invert(parent_stash_M) ;
    
    // Finall matrix
    matrix end_M =  diff_M * parent_move_M ;

    // Blend with input 0
    matrix blend_M = blendtransforms(joint_move_M, end_M, 1.0, components) ;
    setpointtransform(0, joint_id, blend_M,1);

}
View Code

 // space switch 功能

 apex script

2026-05-07_223159

 

#create spt node
spt_node = graph.addOrUpdateNode('SPT', 'skel::SetPointTransforms')
geo_freezed = graph.addOrUpdateNode('geo_freeze_SPT', 'Value<Geometry>')
geo_freezed.parm.promote('Base.skel')
geo_freezed.value.connect(spt_node.geo_in)
spt_node.geo_out.promote("Base.skel")
spt_node.geo_out.promote('Base.skel')

#------------------------------------------
#create boneDeform node
boneDeform_node = graph.addNode(name='boneDeform', callback='sop::bonedeform')
boneDeform_node.geo_out.promote('Base.shp')
boneDeform_node.geoinput1_in.promote('Base.skel')
boneDeform_node.geoinput0_in.promote('Base.shp')
spt_node.geo_out.connect(boneDeform_node.geoinput2_in)

#------------------------------------------



for pt in geo.points():
    name : String = geo.pointAttribValue(pt,"name")
    restlocal : Matrix4 = geo.getPointLocalTransform(name)

    trObj_node = graph.addOrUpdateNode(name, 'TransformObject', parms={"restlocal": restlocal})

    trObj_node.t_in.promote(f'{name}_t')
    trObj_node.r_in.promote(f'{name}_r')
    trObj_node.s_in.promote(f'{name}_s')
    
    #get point parents
    parent_point : Int #this is for autocomplete reasons
    parent_point = geo.getParent(pt)
    
    #if joint has a parent, make connections to parent node
    if parent_point != -1:
        parent_name : String = geo.pointAttribValue(parent_point,"name")
        parent_node = graph.findNode(parent_name)
        parent_node.xform_out.connect(trObj_node.parent_in)
        parent_node.localxform_out.connect(trObj_node.parentlocal_in)
    
   
    #connect xform to spt node
    graph.findAndConnectInput(srcnode = trObj_node, 
                              srcname = 'xform', 
                              dstnode = spt_node, 
                              dstname = 'transforms', 
                              dstalias = name)
                              

graph.layout()
View Code

  // Offset  rig

在Rig Attribute Wrangle里面,对skeleton位移

image

// Get user-defined offset (a vector parameter called "offset")
vector arm_offset = chv("offset");

// Convert the 3x3 transform attribute into a full 4x4 matrix
// (this stores orientation/scale, now expanded to a 4x4 to also allow translation)
matrix xform_matrix = set(3@transform);
 
// Create an identity 4x4 matrix (does nothing yet)
matrix trans_matrix = ident();

// Build a translation matrix from the point position (@P)
translate(trans_matrix, @P);

// Multiply orientation matrix with the translation matrix
// -> now xform_matrix has both orientation and position
xform_matrix *= trans_matrix;

// Apply a "pre-translation" (shift before other transforms) by the offset vector
// This effectively moves the point in local space
pretranslate(xform_matrix, arm_offset);

// Reset point position to origin (0,0,0)
// so we can apply only our new transformed version
@P = set(0, 0, 0);

// Finally, multiply the origin (0,0,0) by the matrix to get the transformed position
@P *= xform_matrix;

  // 群集添加shape的技巧

2

int bone = agentrigfind(1,0,"mixamorig:RightHand");
matrix trn = agentworldtransform(1,0,bone);
matrix sel = getpackedtransform(0,@ptnum);
matrix mult = sel * invert(trn);
setpackedtransform(0,@ptnum,mult);

 

posted @ 2024-11-30 23:56  鹏_VFX  阅读(126)  评论(0)    收藏  举报