StrataCafe-Forums/その3 スクリプトでユーザーインターフェース要素を作成

Last-modified: 2008-09-15 (月) 17:08:04

例となるSSはリンク先を参照してください。

http://www.stratacafe.com/forum/topic.asp?ARCHIVE=true&TOPIC_ID=5518

While I am certain than many of you enterprising scripters are eager to start (or have already started) creating your own great new scripts for animations and visual effects in the latest version of Strata 3D, here is a simple example (taken from the Beta team) of creating a real UI "dialog box" with a script. This shows just how deep the scripting controls in Strata CX 5 can really go.
一方、I、あなたのうちの多数より確かである、進取的な脚本家は、層3Dの最新のバージョン中でアニメーションおよび視覚効果用の自分の大きな新しいスクリプトを作成し始めることを(あるいは既に始められて持っている)熱望します、ここに、スクリプトで実際のUI「ダイアログ・ボックス」を作成することの単純な例(ベータ・チームから得られた)があります。これは、層CX 5の中のスクリプトを書くコントロールがどれくらい深く実際に行くことができるかちょうど示します。

Something we take for granted in most applications is that while we may be able to move palettes around and assign new keyboard shortcuts to things, we are pretty much stuck with the buttons, checkboxes, dialogs, and tools provided. What is now available in Strata CX 5 (similar to the scripting in other high-end 3D applications) is the ability to *create* our own dialogs and user-interface elements, and have them displayed and function just like any other UI element in Strata!
私たちがほとんどの適用で当然と考えるものが、パレットを動かすことができるかもしれないし、事態に新しいキーボード近道を帰することができるかもしれない一方、ボタン、チェックボックス、対話および提供されるツールで私たちがほとんど突き刺されるということです。CX 5(他の高?zの3Dアプリケーションの点でスクリプトを書くことに似ている)が、能力である層において今利用可能なことは、自分の対話およびユーザ・インターフェース要素を*create*します、またそれらを表示する、またちょうど層での他のUI要素のような機能!

The real power of this is when these UI elements are "tied to" a set of instructions to make things happen in your Strata 3D scene. One example of where this could be useful is if you want to randomize the position of a bunch of objects, but only along certain axes. You might write a general "randomize position" script for all axes, and use these UI creation methods to create a dialog that pops-up when you run your script! This could then use checkboxes for each axis. So, rather than editing the script each time to "only randomize on X and Y," then "only randomize on Z", you run the script and a dialog pops-up where you can check off which axis you want for the randomization right then. Perhaps even get fancy and add an "amount of randomizing" to create subtle effects...
この実際の力は、「これらのUI要素いつ結ばれるかです」事態を作る1セットの指示があなたの層3D場面の中で起こります。これがどこで有用になりえるかの1つの例は、あなたがオブジェクトの房の、だがある軸に沿ったのみ位置を無作為化したいかどうかです。書いてもよい、1つの、一般的「位置を無作為化する」すべての軸のためのスクリプト、またあなたがスクリプトを実行する場合にポップするアップ対話を作成するこれらのUI生成方法を使用する!その後、これはチェックボックスを各軸に使用することができました。そのように、その後「XとYを上に単に無作為化する」ために毎時間スクリプトを編集するのではなく「Zを上に単に無作為化してください。」あなたはスクリプトを実行します。また、あなたがチェックすることができるところで、その軸からそのとき無作為化のためにちょうど望む対話はポップするアップ。恐らくさらに装飾的になって、微妙な結果を作成するために「無作為化する量」を加えてください...

Well, that's all great, but where is an example?
さて、それはすべて大きい。しかし、例はどこですか。

Okay - I'm not much of a scripter or coder, so the following example (modified from something the engineers provided) has no functions attached to it - and therefore took much less time to write and debug - but will create and show a totally new dialog in Strata 3D CX 5.
承認-私はたいした脚本家かコーダーではありません、したがって、次の例(何かから提供されるエンジニアを修正する)はそれに機能を付けません-またしたがって、書きデバッグする非常により少ない時間をとった-しかし層3D CX 5の中の全く新しい対話を作成し示すだろう。

This is what we want to present to the world when our script is run:
これは私たちのスクリプトが実行される場合、私たちが世界へ提示したいものです:

So, let's get started!
したがって、始めましょう!

  • In your shiny new "Scripting" menu in Strata 3D CX 5, select the "Show Console" to open the Lua Scripting console. This is like a sandbox where you can play with scripts and get immediate feedback while Strata is running. It isn't really the place to put final scripts, since it doesn't save them when you close your file or quit Strata 3D, but you can test things out very easily here and even see the results in your current scene! (Although you don't need a scene open for this example to work...)
  • 層3D CX 5の中のあなたの光る新しい「スクリプトを書く」メニューでは、Luaをス?Nリプトにするコンソールを開くために「ショー・コンソール」を選択してください。あなたがスクリプトで遊ぶことができ、層が走っている間に、即時のフィードバックを得ることができるところで、これは砂場に似ています。あなたがファイルを閉じるか、層3Dを中止する場合、それがそれらを保存しないので、最終スクリプトを置くことは実際にその場所ではありません。しかし、非常に容易に事態をここで実地に試みて、現在の場面に結果を見出すことができます!(例(この)が働くのに開いた場面を必要としませんが...)

The Scripting Console will open and show you the Welcome Message and some brief instructions on how to use the Console, but it is essentially a giant text-entry box. The text you enter will be Lua script, and the text returned will be the "results" of your action.
スクリプトを書くコンソールはあなたにウェルカムメッセージ、およびコンソールを使用する方法についてのいくつかの簡潔な指示を開けて示すでしょう。しかし、それは本質的に巨大なテキスト・エントリー箱です。入力するテキストはLuaスクリプトになるでしょう。また、返されたテキストはあなたのアクションの「結果」になるでしょう。

  • Copy the text below and Paste it into the Scripting Console (typically below the other text, where the blinking prompt is):
  • テキストを下にコピーして、スクリプトを書くコンソール(典型的に、別のテキスト以下に、明滅が促す場所はそうです)へそれを貼り付けてください:

print(s3d.ui.Dialog)
d = s3d.ui.Dialog("Custom UI dialog")
d:SetLabel(s3d.ui.Dialog.kOkay, "OK")
d:SetLabel(s3d.ui.Dialog.kCancel, "Cancel")
d:AddStaticText("This dialog has no atttached functions.")
d:AddStaticText("But it is Custom User-Interface goodness!")
d:BeginCluster("Controls")
d:AddNumberText(100)
d:AddColumn()
d:AddStaticText("% Understood")
d:AddCheckbox("Look - a checkbox!")
d:EndCluster()
d:Present()

  • or --
  • d:Present( function (id) print("Control hit", id) return id end )

印刷(s3d.ui.Dialog)d、s3d.ui.Dialog(「カスタムUI対話」)d:SetLabel(s3d.ui.Dialog.kOkay、「よろしい」)d:SetLabel(s3d.ui.Dialog.kCancel、「取り消してください」)d:AddStaticText(「この対話はatttachedされた機能を持っていません。。」)d:AddStaticText(「しかし、それはカスタム・ユーザ・インターフェース長所です」!)d:BeginCluster(「コントロール」) d:AddNumberText(100)d:AddColumn()d:AddStaticText(「理解された%」)d:AddCheckbox(「外観 - チェックボックス!」 - )d:EndCluster()d:現在の()-- あるいは---- d:現在(関数(id)印刷(「打たれたコントロール」(id))リターンid終了)

  • Now that this little Beta-team inspired script chunk is entered in the Console, we can "Evaluate" either some, or all of it, to see its effects and determine if it is good code. Select all of the script you just pasted (like selecting text in any text-editor), then press the "Evaluate" button in the lower left corner.
  • この小さなベータ・チームすばらしいスクリプト塊が今コンソールに入力されるので、私たちはその結果を見るためにそのうちのいくらかあるいはすべてのいずれかを「評価することができ」、それがよいコードかどうか判断することができます。ちょうど貼った(任意のテキストエディター中のテキストの選択のように)スクリプトをすべて選択して、次に、より低い左隅の「評価する」ボタンを押してください。

Hey, hey! What do you think of that magic? You have just created a user-interface element (a dialog box) in Strata 3D CX 5 that wasn't there before! Obviously, the more talented and dedicated individuals among us will attach actual *scripted functions* to those buttons and checkboxes and entry boxes, but this opens up the world of custom tools and "widgets" within Strata 3D. (You can press Cancel or OK to close the dialog.)
ヘイ、ヘイ!どうそのマジックについて考えますか。たった今なかった層3D CX 5にそこにユーザ・インターフェース要素(ダイアログ・ボックス)を以前に作成したことがあります!明らかに、私たちの間のより才能があり専心的な個人は、それらのボタンへの実際の*の台本通りの関数*およびチェックボックス、ならびにエントリー箱を付けるでしょう。しかし、これは、層3Dの内の外注金型および「小型装置」の世界を開きます。(押すことができます、取り消す、あるいは対話を閉じるのによろしい)

After the script is evaluated, the Console will show some output text which indicates what the Lua scripting evaluator did with your script. This can be helpful if you know what you are looking for, and it usually will indicate an error if the script could not be successfully executed. In this case, the script (as shown above) should return no error and show a dialog box like the previous image.
スクリプトが評価された後、コンソールは検討者をスクリプトにするLuaがあなたのスクリプトで何を行ったか示すある出力テキストを示すでしょう。何を捜しているかあなたが知っていれば、これは有用になりえます。また、成功裡にスクリプトを実行することができなかったならば、それは通常エラーを示すでしょう。この場合、スクリプト(上に示されたように)はエラーを返さず、前のイメージのようなダイアログ・ボックスを示すべきです。

Now the fun part - editing this little script to make the dialog "your own." By editing the lines of text in the script, you can change the dialog to say other things, or have other elements in it. Simply edit the text of the script (now highlighted in bold in the Console) to whatever you want, *select it all again* and press the Evaluate button again to see the changes! (If you want to save this script for later, simply copy it to a text file and save it on your drive somewhere. Again, this is because the Console is a sandbox for temporary experiments.)
今の楽しい部分 - 対話を「あなたのもの」にするためにこの小さなスクリプトを編集すること。スクリプト中のテキストの行の編集によって、他のことを言うかあるいはそれに他の要素を持つために対話を変更することができます。単に望むものすべてにスクリプト(今中へ強調された、コンソールにおいて大胆)のテキストを編集する、*、再びそれをすべて選択する*、また変更を見るために再びEvaluateボタンを押す!(後のためにこのスクリプトを保存したい場合は、単にテキストファイルにそれをコピーして、駆動上にそれをどこかに保存してください。再び、これはコンソールは一時的実験用の砂場であるからです。)
____________________________
____________________________

A few explanations of what you just entered and "evaluated" (although I am not a scripting guru or Lua expert by any means). Someone else can come along and correct me - please! You will probably notice some trends in how each line of the script is written, though - this is how Lua works as a scripting language. By working within this powerful language (and asking questions here) you can create more complicated scripts than this one.
少数の説明、何の、あなた、ちょうど入力された「そして評価された。」(であるが、I、決してスクリプトを書くグルかLuaエキスパートでない)誰か他の人はやって来て、私を修正することができます。喜ばせます!しかしながら、恐らくスクリプトのラインがそれぞれどのように書かれているかにおけるいくつかの傾向に気づくでしょう。このようにして、Luaはスクリプト言語として働きます。この強力な言語(また、ここで質問をして)内に働くことによって、これより複雑なスクリプトを作成することができます。

Okay... again, these are oversimplified explanations because I am not a techie-scripter-guru.
よろしい...再び、私が技術者脚本家グルではないので、これらは簡素化され過ぎた説明です。

print(s3d.ui.Dialog)
tells Strata you want to make a UI dialog, and everything that follows (up to the presentation of the dialog) are the elements of that dialog.
印刷(s3d.ui.Dialog)は、あなたがUI対話をしたいと層に伝えます、そして続く(対話のプレゼンテーションまで)ものすべて、その対話の要素です。

d = s3d.ui.Dialog("Custom UI dialog")
establishes the "Constructor" to build a dialog called (in the quotes) Custom UI dialog. Change the text in quotes to give the dialog your own name which will appear at the top of the dialog window! (In fact, wherever you see text in quotes, you can change this value to say whatever you want in the dialog.)
d=s3d.ui.Dialog(「カスタムUI対話」)は、カスタムUI対話と呼ばれる(引用の中で)対話を構築するために「建設者」を確立します。対話ウィンドウの一番上に現われる自分の名前を対話に与えるために引用中のテキストを変更してください!(実際(引用にテキストを見出すところならどこでも、)、対話で望むものすべてを言うためにこの値を変更することができます。)

d:SetLabel(s3d.ui.Dialog.kOkay, "OK")
this sets the label (or visible name) for a "constant" button which is the "Okay" or accept button. It is important to have these OK and Cancel buttons so the dialog (and its functions, if there were any) can be accepted and closed - this is why they are already defined as constants! UI conventions dictate that they will be at the lower, right corner of your dialog by default.
d:これがセットするSetLabel(s3d.ui.Dialog.kOkay、「よろしい」)「OKの」「一定の」ボタンのためのラベル(あるいは可視の名前)あるいはボタンを受理します。これらをOKにしておくことは重要です、そしてCancelボタン、したがって、対話(およびもしあったならばその機能)は受理し閉じることができます-これは、なぜそれらが既に定数として定義されているかです!UI協定は、それらがデフォルトによるあなたの対話のより低い正しい角にあるだろうと命令します。

d:AddStaticText("This dialog has no atttached functions.")
this adds, naturally, some static text. Each line like this in the script is a new line of text, and the dialog will resize to contain this text and the other elements included. (As always, feel free to change the text!)
d:これが加えるAddStaticText(「この対話はatttachedされた機能を持っていません。。」)、当然ある静止のテキスト。このようなラインはそれぞれスクリプトの中にテキストの新しいラインです。また、対話は含まれたこのテキストおよび他の要素を含むためにサイズ変更するでしょう。(常にように、自由にテキストを変更してください!)

d:BeginCluster("Controls")
this says that we want to create a "subsection" of our dialog specifically for (alas, non-functioning) controls. You will note that everything between this line and the line: "d:EndCluster()" are the elements inside this Cluster.
私たちが対話の「サブセクション」を特に作成したいとそのために(悲しいかな、機能せずに)これが言うd:BeginCluster(「コントロール」)はコントロールします。次のことを注目するでしょう、このラインとラインの間のすべて:「d:EndCluster()」はこのクラスタの内部の要素です。

d:AddNumberText(100)
Hey look! We just added a numeric entry box - not only that, we provided a preset default value of 100! Depending on how you write your script and what new lines you add into this dialog, you can tie this numeric amount to a control in your script, possibly using a variable that will be defined by this entry that can be used later in another scripted function.
d:AddNumberText(100)、ヘイ、見る!私たちは数値のエントリー箱をちょうど加えました-ない、単にそれ、私たちは、100のプリセットされたデフォルト値を提供しました!あなたがどのようにスクリプトを書くか、また、あなたがこの対話へどこの新しいラインを加えるかによって、後で別の台本通りの機能の中で使用することができるこのエントリーによって定義される変数を恐らく使用して、スクリプト中のコントロールにこの数値の量を結び付けることができます。

d:AddColumn()
Okay, I'm getting a little fancy here, but this starts a new vertical column (inside our cluster, no less) for other elements. The nice thing is that this allows for horizontal and vertical positioning of elements in the dialog. There are many other controls to lay out your UI's, but this is a basic way to separate things. In this case, the new column (everything after this line) contains the static text "label" for our numeric entry box. Not pretty, but feel free to enter the % of the script you understood...
d:AddColumn()承認、私はここで少し想像を得ています、しかし、これは他の要素のために新しい垂直のカラム(まさしく私たちのクラスタの内部の)を始めます。よいことは、これが対話での要素の水平・垂直のポジショニングを考慮に入れるということです。あなたのUIをレイアウトする他の多くのコントロールがあります。しかし、これは事態を分離する基礎的な方法です。この場合、新しいカラム(このラインの後のすべて)は私たちの数値のエントリー箱用に静止のテキスト「ラベル」を含んでいます。きれいでない、しかし理解したスクリプトの%に自由に入ること...

d:AddCheckbox("Look - a checkbox!")
Now we've added a simple on/off checkbox, and given it a name (in quotes) that can be easily changed to something less self-referential. Like the numeric entry box, this can be "tied" to a scripted control that has an on/off state, such as the X, Y, or Z axis in our vague randomization idea.
d:AddCheckbox(「外観」-チェックボックス!-)今、私たちは単純なオン/オフ・チェックボックスを加えて、それほど自己参考でないものに容易に変更することができる名前(引用中の)をそれに与えました。数値のエントリー箱のように、これは、私たちの曖昧な無作為化考えの中のX、YあるいはZ軸のようなオン/オフ状態を持っている台本通りのコントロールに「結び付けることができます。」

Finally, we end the Cluster (which needs to be told where the internal elements of the Cluster stop being defined), then we tell Strata (through the script) to "Present" the dialog so we see immediate results of our test. The dialog is then the targeted window in Strata for your mouse to "hit" - try clicking on another Strata UI element or palette and you will find that the only target for mouse clicks and keyboard presses is this dialog! Powerful stuff, and all with only a few lines of code...
最後に、私たちはクラスタ(クラスタの内部要素が定義されることをやめるところでそれは伝えられる必要がある)を終了します。次に、私たちは、私たちがテストの即時の結果を見るように、対話を「示す」ように層(スクリプトを通って)に命じます。対話はそのときあなたのマウスが「打つ」べき層でのターゲットとされたウィンドウです―別の層UI要素あるいはパレットをクリックしてみる、また、マウスのただ一つの目標がクリックすることを知るでしょう、そしてキーボード圧迫、この対話である!強力な材料、およびコードのほんの数ラインを備えたすべて...

So feel free to edit this script (don't worry, you won't "break" your new copy of Strata 3D CX 5 if you do something wrong!) and select all of the text and evaluate it again to see your own, customized version of this experiment. I'm sure you can imagine all kinds of things you would like to see handled in a dialog, and this is just an example of the potential to make the dialog itself. The real work is actually writing the script *behind* the dialog to do all of the fancy modeling, rendering, and animation functions that a dialog could control.
したがってこのスクリプト(心配しない、間違ったものをすれば層3D CX 5の新しいコピーを「壊さないだろう」)を自由に編集しテキストをすべて選択することあなたのものを見るために再びそれを評価する、この実験のバージョンをカスタマイズしました。私は、あなたが対話で扱われて見て欲しい、すべての種類のものを想像することができると確信します。また、これは単に対話を自体する可能性の例です。実際の仕事は実際にスクリプト*behind*を書いています、対話がコントロールすることができる想像モデリング、演出およびアニメーション機能をすべて行う対話。
______________________
______________________

I hope this gets some excitement going, but if you are really new to scripting and have big ideas, there is a lot of learning ahead. If you know some simple scripting (like Java) you can use what you already know. You can find more information on Lua and how it is written and used at www.lua.org , and post your questions about Lua in Strata 3D here to get us all started.
Iはこれがある興奮を行かせることを望みます。しかし、あなたがスクリプトを書くことに実際に不慣れで、大きな考えを持っていれば、多くの学習が前方にあります。いくらか知っている場合、単純、あなたをスクリプトにすること(Javaのように)は、あなたが既に知っているものを使用するかもしれません。Lua、およびそれがwww.lua.orgでどのように書かれており、使用されるかについてのより多くの情報を見つけて、私たちにをすべて始めさせるためにここで層3Dの中のLuaに関する質問を記入することができます。

Keep in mind that Scripting in Strata is totally new to pretty much all of us - from the newbies in these forums to the programmers who just put this into CX 5. We can all help each other to understand the scripting and improve Strata itself by exchanging ideas, scripts, and questions and answers. The documentation on the Lua scripting in Strata is also pretty sparse (!) at this time because getting it implemented in 5.0 was the important task, and thoroughly documenting it all and making it approachable is the next step. But just like writing that cool new widget you'd like to see in Strata, if you sit back and wait for others to provide all the answers it will take a lot more time before your idea sees the light of day. Help the Strata team to improve everyone's understanding of scripting in Strata (in this forum, right here) and we will all advance and get these exciting new functions into the Strata community!
層でスクリプトを書くことが全く新しいと心に留めておく、に、かなり、私たちのすべて-これらのフォーラムの新米からCX 5にこれをちょうど入れたプログラマまで私たちはすべて、スクリプトを書くことを理解し、かつ考え、スクリプトおよび質問の交換および答えにより層をそれ自体改善するために互いに支援することができます。5.0にそれをインプリメントすることが重要なタスクだったので、層でスクリプトを書くLuaについてのドキュメンテーションはこの時期にさらに、かなり希薄な(!)です。また、徹底的にそれをすべて文書化しそれを接近可能にすることは次のステップです。しかし、ちょうど、その涼しい新しい小型装置を書くことのように、層であなたは見たいこと、くつろぎ、他のものが答えをすべて示すのを待つ場合、あなたの考えの前の非常により多くの時間はかかるだろう、日の目を見ます。層(ちょうどここにこのフォーラム中の)でスクリプトを書く皆の理解を改善するチームおよび私たちがすべて、進めて、層コミュニティーへこれらの刺激的な新しい機能を取って来てやる層を支援してください!

_m