LoginSignup
6
8

More than 5 years have passed since last update.

Wrangle x Python本やってみたメモ [1]

Last updated at Posted at 2016-04-13

これはなに?

COMITIA115(2016/01/31 於:東京ビッグサイト)にて頒布された
Houdini実践ハンドブックWrangle×Python(サークル『魔法の蒸留水』)
http://majou.jp/archives/667/

の、Pythonの例文に取り組んでみたときのメモです。

p.10 「3 Wrangle x Python の実践」 3.1 Pointの移動

準備

新規シーン → geometryノード作成
geo1.png

中に入ったら(元からあるfile1は削除して)
gridを作成
pythonを作成
つなぎます
gridWithPy.png

setPosition()

p.10にある例文を
Pythonノード内のPython Code欄に書いていきます
code01.png

最初の2行はPythonノードを作成した時点で書き込まれているので、
そのあとの4行だけ。
(※この最初の2行については p.6 に記述アリ)

for point in geo.points():
    pos = point.position()
    pos += hou.Vector3(0,2,0)
    point.setPosition(pos)

geo.points()のpointsをpointにタイポしていて「あっれー」ってなったのはここだけのヒミツ

結果
result01.png
Y方向に 2 移動したぞおおおおおおおおお


以下のように書き換えて遊んだりもします

書き換え1
for point in geo.points():
    point.setPosition( point.position()+hou.Vector3(0,2,0) )
書き換え2
x = 0
y = 2
z = 0
pos = hou.Vector3(x,y,z)

for point in geo.points():
    point.setPosition( point.position()+pos )

hmath.buildTranslate

p.10 二つ目の例文

for point in geo.points():
    pos = point.position()
    mtx = hou.hmath.buildTranslate((0,2,0))
    pos = pos * mtx
    point.setPosition(pos)

result02.png

pos = pos * mtx は代入演算子にしても可。pos *= mtx

まとめ

とりあえずp.10のPythonの例文だけ。

Wrangle x Python本、とらのあなで注文可能な模様
https://www.toranoana.jp/mailorder/article/04/0030/38/99/040030389986.html
僅少らしいです <[2]を書くタイミングで確認したら売り切れてました!

備考

サジェスト

hou.hmath.bあたりとか、打ってる途中で入力補完が出ます

suggest.png

関数の説明

関数の引数を入力し始めると、関数の説明が出ます。

guide.png

printやhelp

Python Code内にprinthelp()を入れると
「Houdini Console」という別ウィンドウに表示されます。
console.png

行数が多すぎると流れちゃうので注意です。
例えば上図はhelp(hou.hmath)したときの例ですが、冒頭部分は流れちゃって読めませんでした。(さすがにhelpはPython Shellで〜)

参考

Vector3
http://sidefx.jp/doc/hom/hou/Vector3.html

Matrix4
http://sidefx.jp/doc/hom/hou/Matrix4.html

setPosition
http://sidefx.jp/doc/hom/hou/Point.html#setPosition

hmath
http://sidefx.jp/doc/hom/hou/hmath.html

公開されている日本語ドキュメントも意外と日本語化されてなかったりするのでおとなしく本家に行くのが早いことが多いです。


ちなみにHoudiniのPython環境については
こちらでもすこし触れています

Maya, Houdini, blender, Nuke でのPythonインタープリタ
http://qiita.com/it_ks/items/ae1d0ae01d831c2fc9ae#houdini

6
8
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
6
8