2011年10月2日日曜日

scriptのすすめ6 ~アニメーション animate onとat time~

突然ですが、自分の勉強も兼ねて英語で書くことにしました。
多分間違いだらけの英語ですが、英語で全部書いてから日本語訳するという書き方です。
下に日本語の解説があります。

こうやって、自分のキャパを徐々に超えていってしまう気が。。。
挫けて日本語だけになったら、笑って下さいw

This time I'd like to introduce how to animate in maxscript.
Basically there are 2 ways to create animation in maxscript.

First one is that "animate on"and "at time".
Second one is "addNewKey"

I suppose first one is easier than second one.I should explain it.
I will show you an example.

t = teapot()
animate on
(
    at time 10 t.pos=[0,0,100]
    at time 20 t.pos=[100,0,10]
)

you can see the teapot is moving.
"animate on" is kind of like an "Auto key button" as usually function.
"at time" is for specifying frame when the subsequent script is executed.
That's a basic way.

Let's combine it with previous lessons which are "random function","for loop "and "material functions".

t = box()
m = standardmaterial()
m.selfillumination =100
t.material = m
animate on
(
    for i = 1 to 100 do
    (
        at time i
        (
            rr = random 0 255
            rg= random 0 255
            rb= random 0 255
            t.material.diffuse= color rr rg rb
        )
    )
)

Copy this and press "Ctrl+E"!!!

you can see above the random changing of the color in every frame from 0f to 100f.

I expand the functions of this script.
this is the result.


These boxes are changing color and position every 3 frames.
however,I made a mistake. Position animation is not necessary.
It could be possible to make by particles.

I will show you this script code next time.
The essential is to create boxes in 10 by 10 square without crossing-over.
Until then see you next time!!
----------------------------------------------------------------------------------
今回はアニメーションについてです。
maxscript でアニメーションを付けるには2通りの方法があります。
1つの方法は animate onとat timeを使う方法と
2つ目はaddnewkeyを使う方法です。

1つ目の方法の方が簡単なので、そちらを説明しようと思います。

t = teapot()
animate on
(
    at time 10   t.pos=[0,0,100]
    at time 20   t.pos=[100,0,10]
)

ティーポットがアニメーションしていると思います。
animate onはオートキー(Autokeyボタン、オン)の様なもので、
at timeは 時間を指定するもで、そのフレームでその後のスクリプトが実行されます。
これが基本的な使い方です。

では、前回までのrandom関数やforループ、マテリアル操作する方法とを組み合わせて見ましょう。

t = box()
m = standardmaterial()
m.selfillumination =100
t.material = m
animate on
(
    for i = 1 to 100 do
    (
        at time i
        (
            rr = random 0 255
            rg= random 0 255
            rb= random 0 255
            t.material.diffuse= color rr rg rb
        )
    )
)

0から100フレームで、1フレーム毎にカラーがランダムに変わっていると思います。

このスクリプトを拡張したものが上のVimeoのムービーです。
3フレーム毎にカラーとポジションがアニメーションしています。
ですが、ポジションアニメーションは必要なかったですね。
これならパーティクルで出来そうです。

次回はこのコードを解説しようと思います。
縦横、10×10の範囲にランダムかつ重ならないように並べるところがポイントです。
ではではまた。

2 件のコメント :

uiti さんのコメント...

試しに書いてみました
コメントにコードを直に書いて済みません。

box_list = #()

for x = 1 to 10 do
(
for y = 1 to 10 do
(
hoge = box pos:[x, y, 0] height:1 width:1 length:1 wirecolor:blue
m = standardmaterial()
m.selfillumination =100
hoge.material = m

append box_list hoge
)
)

animate on
(
for i = 1 to 100 by 3 do
(
at time i
(
for i in box_list do
(
rb = random 0 255
i.material.diffuse = color 00 00 rb
)
)
)
)

Sugimura さんのコメント...

uitiさん
コメントありがとうございます。
すっかり気付かず、すみません。
stepアニメーションに出来れば完璧でしたね~