1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Houdiniで簡単なPythonのツールをつくる

Last updated at Posted at 2019-09-02

はじめに

Houdiniを勉強するにあたり、自分の得意分野であるリギングから進めようと考え、チュートリアルを始めました。リンク

チュートリアルを進める上で気になったのが、ノードとノードの位置合わせ方法です。

1. 指定位置にあるノードの子として位置を合わせたいノードを接続
2. 位置を合わせたいノードの移動値を0にする
3. 【keep Position When Parenting】 にチェックを入れる
4. 接続を切断する

ノードを位置合わせするたびに、上記の手順を繰り返しています。
こんなのやってられないので、ツールを作ってみました。

位置合わせツール

指定位置にあるノードと位置を合わせたいノードを選択し、下記のコードを実行すると、位置合わせができます。

Nodes = hou.selectedNodes()

if len(Nodes) >= 2:
    Target_Node = Nodes[0]
    Source_Nodes = Nodes[1:]
    
    xform = Target_Node.worldTransform()
    
    posx = xform.at(3,0)
    posy = xform.at(3,1)
    posz = xform.at(3,2)
    
    for Source_Node in Source_Nodes:
        Source_xform = Source_Node.worldTransform()        
        Source_xform.setAt(3,0,posx)
        Source_xform.setAt(3,1,posy)
        Source_xform.setAt(3,2,posz)
        
        Source_Node.setWorldTransform(Source_xform)
else:
    print("ノードが選択されていません。:")

コード解説

Nodes = hou.selectedNodes()

選択されたノードを取得しています。

    xform = Target_Node.worldTransform()
    posx = xform.at(3,0)
    posy = xform.at(3,1)
    posz = xform.at(3,2)

ノードのワールドのトランスフォームを取得します。座標行列から移動値を抜き出します。

    for Source_Node in Source_Nodes:
        Source_xform = Source_Node.worldTransform()        
        Source_xform.setAt(3,0,posx)
        Source_xform.setAt(3,1,posy)
        Source_xform.setAt(3,2,posz)

位置合わせしたいノードのワールド座標を取得し、上記で抜き出した移動値を位置行列にセットします。

    Source_Node.setWorldTransform(Source_xform)

最後に、位置合わせしたいノードのワールド座標を更新します。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?