2012年1月27日金曜日

First nuke python

nukeのpython初めて書いてみました。
ヘルプが大分使いづらいので、googleで検索した方が答えに近いです。
pythonの良いところは日本でも3DCG以外の人もユーザーが多く、すぐに調べ物が見つかります。


選択したReadノードの連番の桁数を調べるスクリプト。

import os.path
fp = nuke.selectedNode()['file'].getValue()
root, ext = os.path.splitext(fp)
print ext
print root
print len(ext)
fileName = root[1: (len(root)-4)]
print fileName
Keta =int( root[(len(root)-3) : len(root)-1])
print Keta
----------------------------------------------------------------------------------

nukkeファイルのあるディレクトリを開くスクリプト。

import os

nukeFile = nuke.root().name()
nukeDir = os.path.dirname(nukeFile)
print nukeDir
unc_path = nukeDir.replace( "/", "\\" )
en = 'explorer'+' '+unc_path
print en

os.system(en)

2012年1月14日土曜日

scriptのすすめ10 ~変数と配列~ maxscript tips

This time I will explain about variable and array.
Probably this post is boaring but they are very necessary to understand every script language and to construct complicate script.
I've never explain them because I'd like to write this tips for artists and I'd like to make scripts easy to introduce.
Actuarlly we already use varialbe before now.

For instance, "b=box(), rc = random 0 255 ,myP = point(),m= standardmaterial() and i= 1"

b,rc,myP,m,i are variable.
I make the analogy of other thing,it`s like a case which is set in one object.
you can put anything (e.g. box(),point(),number...)into cases and you can access the content of a case by using the variable.

On the ohter hand,I think array is like an extended version of variable.I will introduce two exsamples.

myArray =#(a,5,9,"text",100)
a = #($Teapot001,box(),9,standardmaterial())


Array is like a locker with number label,you can also anything into lockers and you can access the each contents by using array`s name and label number.
For instance,the way to access 2nd value of myArray is myArray[2] which return 5 and a[1] is $Teapot01.
Position value (e.g. [2,4,3]) called point3 one of kinds of array.
Besides "selection" is one of kinds of array.Both contents can be access by label number as well.

So let`s make a align tool.
First I'll prepare several objects are orderd randamly.
As I showed before,I use for loop and random function.
------------------------------------------------------------------------------------------------------------------------------------------------
for i = 1 to 20 do
(
    rx = random -50 100
    ry = random -50 100
    t = teapot radius:10
    t.pos = [rx,ry,0]
)

------------------------------------------------------------------------------------------------------------------------------------------------

So, let`s line up selected objects on their avelage positon of Y axis.
------------------------------------------------------------------------------------------------------------------------------------------------
total=0 --prepare a variable to keep to add Y position value of all objects.
for o in selection do
(
    total= total+o.pos[2] --As I explain before, first "total" is result of "total+o.pos[2]"
)
--o.pos[2] means Y position value of each seleted object.
--First resut of this for-loop becomes 0+o.pos[2] ,2nd result becames "1st result+o.pos[2]", So, one after another "o.pos[2]" is added in "total" variable.

avelage = total/selection.count --you can get array's number of elements by using ".count".
--divide total value by number of selected objects.

for o in selection do
(
    o.pos.y= avelage -- assign the avelage value to Y position of selected objects.
)

------------------------------------------------------------------------------------------------------------------------------------------------

I wrote this script with comments after "--" is comment which is not evaluate so you can just paste this script on maxscript editor.

Finally, you have to need a bit mathmatic knowledge,
let's try to line up selected objects on a circle.
We use trigonometric function.

------------------------------------------------------------------------------------------------------------------------------------------------
oc = selection.count
i = 0
for o in selection do
(
    i = i+1
    o.pos.x=sin(i*360/oc)*60
    o.pos.y=cos(i*360/oc)*60
)

------------------------------------------------------------------------------------------------------------------------------------------------

Next time I will revise this script for modeling.
so see you then! next time!

------------------------------------------------------------------------------------------------------------------------------------------------
今回は、変数と配列について説明しようと思います。
おそらく、ひどく退屈な記事になりそうですが、変数と配列はどのスクリプト言語にとっても必要な要素で複雑なスクリプトを書くには通らねばならぬ道となります。
今まで説明してこなかったのは、デザイナー・アーティスト向けのTipsとして導入しやすくしたい気持ちがあったのです。

変数は実はもう今までに散々使っていて、例えば

"b=box(), rc = random 0 255 ,myP = point(),m= standardmaterial(),i= 1"

のb,rc,myP,m,i などは全て変数です。
変数を他のもので例えるならば、1つ物を入れる事の出来るケースの様なものです。ケースには何でも入れることが出来、boxでもpointでも数でも入れる事が出来ます。そして中に入れたものにはその変数を使ってアクセスできます。

一方、配列は変数の拡張版の様なものです。まずは、2つの例をお見せします。

myArray =#(a,5,9,"text",100)
a = #($Teapot001,box(),9,standardmaterial())


配列はラベルナンバー付きのロッカーの様なもので、同様にどんな物でも入れられ、中身には配列の名前とナンバーを使ってアクセスできます。

例えば、myArrayの2番目の値にアクセスするにはmyArray[2] と書き、5の値が返ってきます。
a[1]は$Teapot01です。(シーンにTeapot01という名前のオブジェクトが無いとエラーになります。)
ポジションの値(例、[2,4,3])なども、配列の一種でpoint3など呼ばれています。
さらに、selectionも配列の一つです。共にラベルナンバーを使って中身にアクセスできます。

では、整列ツールを作ってみましょう。
最初に、いくつかのオブジェクトをランダムに並べてみましょう。
以前紹介した様に、for ループとrandomメソッドを使います。
------------------------------------------------------------------------------------------------------------------------------------------------
for i = 1 to 20 do
(
    rx = random -50 100
    ry = random -50 100
    t = teapot radius:10
    t.pos = [rx,ry,0]
)

------------------------------------------------------------------------------------------------------------------------------------------------

では、選択したオブジェクト達のY軸の平均値に一列に整列させてみましょう。
------------------------------------------------------------------------------------------------------------------------------------------------
total=0 --最初にそれぞれのYポジションの値を足し算していく為の変数totalを用意します。
for o in selection do
(
    total= total+o.pos[2] --以前説明した様に、最初のtotalはtotal+o.pos[2]の結果です。
)
--o.pos[2]は選択オブジェクト1つ1つのYポジションの値です。
--なので、このforループの1回目の結果は"0(ゼロ)+o.pos[2]" で、2回目の結果は"01回目の結果+o.pos[2]"となり、次々にそれぞれのYポジションの値がtotalという変数に足されていきます。
avelage = total/selection.count -- ".count"を使って、配列に幾つオブジェクトが入っているか値を得ることが出来ます。
--totalの数を選択オブジェクトの数で割ることで、平均値が求めれれます。

for o in selection do
(
    o.pos.y= avelage --平均値をYポジションに割り当てます。
)

------------------------------------------------------------------------------------------------------------------------------------------------

コメント付きでスクリプトを書きました。 "--" より後ろは評価されませんので、そのままスクリプトエディタに貼り付けてもO.Kです。

最後に、少し数学の知識が必要ですが選択オブジェクトを円形に並べてみようと思います。三角関数を使います。

------------------------------------------------------------------------------------------------------------------------------------------------
oc = selection.count
i = 0
for o in selection do
(
    i = i+1
    o.pos.x=sin(i*360/oc)*60
    o.pos.y=cos(i*360/oc)*60
)

------------------------------------------------------------------------------------------------------------------------------------------------

次回はこれを拡張してモデリングに応用してみようと思います。
それでは、また!!


2012年1月9日月曜日

2012年心に刻む格言

失敗したからって、それがどうしたというのだ。

Houdini POPs Breaking System (with 2nd and 3rd fracturing)

http://vimeo.com/34260583

HoudiniのPopsで2次破壊3次破壊をコントロールするシステムを作ってみました。
DOPsに自動で衝突時に破片を作ってくれるノードもあるのですが、重い、プラス衝突時のみの
機能なので、条件を設定する事が出来ません。
破片の形状をボロノイ拡張した仕組みにしたので、Houdiniならではのディールを持てる
仕組みに出来たと思います。

2012年1月3日火曜日

謹賀新年

明けましておめでとうございます。
さて、あっという間に1年が経っちゃいました。

色々振り返ると、去年は色々身の回りの環境が変わった年で、
意識はなかったけれど、少し守りに入ってしまったような気もします。
悪い癖で、何か行動する前に考え過ぎてしまって行動が鈍るとこもあります。
今年は積極的に、まずは行動出来たらと思います。

そういえば、昨年知った大前研一さんの名言があります。

人間が変わる方法は3つしかない。
1番目は時間配分を変える。
2番目は住む場所を変える。
3番目はつきあう人を変える。

この3つの要素でしか人間は変わらない。
最も無意味なのは『決意を新たにする』ことだ。


3つの方法は、なるほど便利だなと思い、上手く利用出来たらとも思いますが、
決意も継続は力なりで意識して行動すれば、自分を変える事も可能だと思います。

最近深く心に刻んでいる事があって、
どのジャンルでも一流の人は人並み外れた努力しているという事、
そして自分を信じている事。

この業界に10年以上いて、天才と思った人は3人いましたが、皆どこかで努力していて、
そして迷いが無い人達でした。

自分もその方々に近づけるよう、今年も自分を信じてやっていこうと思います。

本年もよろしくお願いします!