Pc-Trace

<< 2024年10月 >>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31






Pc-Trace
PC-Trace

< next 最新の記事 prev >

「iTween」を使ってみた

「Unity」の進展がないまま歳が開けてしまった。

単純な目的でもいざ実行しようとなると、個人的には意外とハードルが高い。
Freeの「Assets」や、標準で添付されている「Assets」の中から使えそうなものを拾いだして活用した方が早そうなのでいくつかピックアップし、試してみた。

今年もkotarou 〜3D〜様の「船屋」モデルから。
風になびく樹木や、おだやかに波打つ海面の表現までは実現出来たが、空を飛ぶ飛行船や、飛行機などが止まったままでは周囲との調和が取れておらず、前から目をつけていたフリーの「iTween」を使って”飛行機”と”飛行船”も動かしてみる事にした。

iTweenの適用前に簡単なパスを作成し、Cubeを動かしてリハーサル。


座標、回転軸の設定など、試行錯誤の末何とか動かすことが出来た。


正しい使い方なのかは疑わしいが、設定については後日。


「Unity」 習うより慣れろ?

SketchUpと勝手の違う「Unity」に悪戦苦闘。

物一つまともに動かせない現状に、公式サイトのマニュアルを丁寧に読みこんで体裁を取らず慣れる事にした。
マニュアルに習って、実際にスクリプトを書いて慣れる両取り作戦。

これほど簡単なスクリプトでもエラー続出でヘトヘトになってしまう。

■先ずはボタンを配置し動かすことから。(移動のみのスクリプト添付)


■移動をボタン操作で行い、理解するための C# 練習スクリプト。添付ファイルの練習スクリプトと違い、回転を含む。

● Unity 5.2.3f1 (32-bit)

using UnityEngine;
using System.Collections;

// Button test pc-trace 2015/12/23

public class GUIBtn01 : MonoBehaviour {

public float DownLimitt = 0f;
public float Mspeed = 0.01f;
private float Movspeed = 0.02f;


void Update () {

Vector3 v = this.transform.position;
//------------回転-----------
if (Input.GetKey(KeyCode.UpArrow)){
this.transform.Rotate (1,0, 0);
}

if (Input.GetKey(KeyCode.DownArrow)){
this.transform.Rotate (-1,0, 0);
}

if (Input.GetKey(KeyCode.LeftArrow)){
this.transform.Rotate (0,-1, 0);
}

if (Input.GetKey(KeyCode.RightArrow)){
this.transform.Rotate (0,1, 0);
}
// 回転リセット
if (Input.GetKey(KeyCode.Keypad5)){
//全角度をリセット
transform.rotation = Quaternion.Euler(0, 0, 0) ;
}

// 上昇、下降 ---------------------
if (Input.GetKey(KeyCode.PageUp) ){
v.y += Mspeed;
}
if (Input.GetKey(KeyCode.PageDown) && transform.position.y >DownLimitt){
v.y -= Mspeed ;
}

this.transform.position = v;
}

// --------ボタンを使った前後左右の移動-------------

void OnGUI () {
// Make a background box
GUI.Box(new Rect(10,10,100,210), "移動");



// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed

if(GUI.RepeatButton(new Rect(20,40,80,20), "← 左")) {
transform.position -= new Vector3(Movspeed, 0f, 0f);
}

if(GUI.RepeatButton(new Rect(20,70,80,20), "→ 右")) {
transform.position += new Vector3(Movspeed, 0f, 0f);
}


if(GUI.RepeatButton(new Rect(20,100,80,20), "↑ 前進")) {
transform.position += new Vector3(0f, 0f,Movspeed);
}

if(GUI.RepeatButton(new Rect(20,130,80,20), "↓ 後退")) {
transform.position -= new Vector3(0f, 0f,Movspeed);
}
//-----------回転リセット--------------------------

if(GUI.RepeatButton(new Rect(20,160,80,20), "回転リセット")) {
transform.rotation = Quaternion.Euler(0, 0, 0) ;
}
//  終了
if(GUI.Button(new Rect(20,190,80,20), "END")) {
Application.Quit();
}

}
}
//----------------end------------------

■とにかくカメラでモデルを見渡したいスクリプト。
もう、ソースの汚さが満開である。
Unity 5.2.3f1 (32-bit) キーボードとマウス兼用。
※スクリプト使用による一切のサポートと、保証はありません。

using UnityEngine;
using System.Collections;

public class MoveRotate2 : MonoBehaviour
{


public float cameraSensitivity = 90;
public float climbSpeed = 4;
public float normalMoveSpeed = 10;
public float slowMoveFactor = 0.25f;
public float fastMoveFactor = 3;

private float rotationX = 0.0f;
private float rotationY = 0.0f;

void Start ()
{
// Cursor.lockState = CursorLockMode.Confined;
Cursor.lockState = CursorLockMode.Confined;
Cursor.visible = false; //OSカーソル非表示
}

void Update ()
{
rotationX += Input.GetAxis("Mouse X") * cameraSensitivity * Time.deltaTime;
rotationY += Input.GetAxis("Mouse Y") * cameraSensitivity * Time.deltaTime;
rotationX += Input.GetAxis ("Horizontal") * cameraSensitivity * Time.deltaTime;
rotationY += Input.GetAxis ("Vertical") * cameraSensitivity * Time.deltaTime;

rotationY = Mathf.Clamp (rotationY, -90, 90);

transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);

if (Input.GetKey (KeyCode.LeftShift) || Input.GetKey (KeyCode.RightShift))
{
//transform.position += transform.forward * (normalMoveSpeed * fastMoveFactor) * Input.GetAxis("Vertical") * Time.deltaTime;
// transform.position += transform.right * (normalMoveSpeed * fastMoveFactor) * Input.GetAxis("Horizontal") * Time.deltaTime;

if (Input.GetKey (KeyCode.Keypad2)) {
transform.position -= transform.forward * (normalMoveSpeed * fastMoveFactor) * Time.deltaTime;
}
if (Input.GetKey (KeyCode.Keypad8)) {
transform.position += transform.forward * (normalMoveSpeed * fastMoveFactor) * Time.deltaTime;
}


if (Input.GetKey (KeyCode.Keypad4)) {
transform.position -= transform.right * (normalMoveSpeed * fastMoveFactor) * Time.deltaTime;
}
if (Input.GetKey (KeyCode.Keypad6)) {
transform.position += transform.right * (normalMoveSpeed * fastMoveFactor) * Time.deltaTime;
}


}
else if (Input.GetKey (KeyCode.LeftControl) || Input.GetKey (KeyCode.RightControl))
{
//transform.position += transform.forward * (normalMoveSpeed * slowMoveFactor) * Input.GetAxis("Vertical") * Time.deltaTime;
//transform.position += transform.right * (normalMoveSpeed * slowMoveFactor) * Input.GetAxis("Horizontal") * Time.deltaTime;

if (Input.GetKey (KeyCode.Keypad2)) {
transform.position -= transform.forward * (normalMoveSpeed * slowMoveFactor) * Time.deltaTime;
}
if (Input.GetKey (KeyCode.Keypad8)) {
transform.position += transform.forward * (normalMoveSpeed * slowMoveFactor) * Time.deltaTime;
}


if (Input.GetKey (KeyCode.Keypad4)) {
transform.position -= transform.right * (normalMoveSpeed * slowMoveFactor) * Time.deltaTime;
}
if (Input.GetKey (KeyCode.Keypad6)) {
transform.position += transform.right * (normalMoveSpeed * slowMoveFactor) * Time.deltaTime;
}

}
else
{
// transform.position += transform.forward * normalMoveSpeed * Input.GetAxis("Vertical") * Time.deltaTime;
// transform.position += transform.right * normalMoveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime;

if (Input.GetKey (KeyCode.Keypad2)) {
transform.position -= transform.forward * normalMoveSpeed * Time.deltaTime;
}
if (Input.GetKey (KeyCode.Keypad8)) {
transform.position += transform.forward * normalMoveSpeed * Time.deltaTime;
}

if (Input.GetKey (KeyCode.Keypad4)) {
transform.position -= transform.right * normalMoveSpeed * Time.deltaTime;
}
if (Input.GetKey (KeyCode.Keypad6)) {
transform.position += transform.right * normalMoveSpeed * Time.deltaTime;
}

}

//--------------------------------------------------------------
if (Input.GetMouseButton(0)) {
transform.position += transform.forward * normalMoveSpeed * Time.deltaTime;
}

if (Input.GetMouseButton(1)) {
transform.position -= transform.forward * normalMoveSpeed * Time.deltaTime;
}

if (Input.GetKey (KeyCode.Keypad8)) {
transform.position += transform.forward * normalMoveSpeed * Time.deltaTime;
}

if (Input.GetKey (KeyCode.Keypad2)) {
transform.position -= transform.forward * normalMoveSpeed * Time.deltaTime;
}


if (Input.GetKey (KeyCode.Keypad4)) {
transform.position -= transform.right * normalMoveSpeed * Time.deltaTime;
}
if (Input.GetKey (KeyCode.Keypad6)) {
transform.position += transform.right * normalMoveSpeed * Time.deltaTime;
}

//--------------------------------------------------------------
if (Input.GetKey (KeyCode.PageUp)) {transform.position += transform.up * climbSpeed * Time.deltaTime;}
if (Input.GetKey (KeyCode.PageDown)) {transform.position -= transform.up * climbSpeed * Time.deltaTime;}
if (Input.GetKey(KeyCode.Escape)) {
Application.Quit();
}


}
}
添付ファイル 添付ファイル


「Unity」 スクリプトに少し挑戦

今度も、kotarou 〜3D〜様の「船屋」モデルお借りし、マウスで移動できるよう「C#」の練習がてらにスクリプトを組んでみた(当然、中身は初心者レベルなので、迷惑を考え非公開)

操作はメチャクチャだが、モデルを動かせると楽しさも倍増する。




「Unity」 練習中

いまだに投げ出さず「Unity」と格闘中。
それほど奥が深く、魅力が多い。

まだ、ほぼ全てが分かってないが、少しづつ前進できる事は分かった。



■水のマテリアルをカップに貼り付け中

添付ファイル 添付ファイル


「Unity」 フリー素材から、猫を拝借

フリーのアセット(猫)にkotarou 〜3D〜様の「船屋」モデルの屋上のテーブルでくつろいでもらった。(勝手にシチュエーション)

しぐさがかわいい。



「Unity」 Treeの設定、備忘録

備忘録その2
しつこくkotarou 〜3D〜様の「船屋」を使わせて頂き船屋の背景に風になびく樹木の設定。
(斬新で、明るく開放的なモデルが個人的にはかなりのお気にい入り。)



初心者でも、フリーのソフトだけでここまで出来る時代になった。



※添付ファイルは"mp4"動画
添付ファイル 添付ファイル


「Unity」 Waterの設定、備忘録

Waterの設定、個人的な備忘録。


※添付ファイルは、作業実寸大の"mp4"動画
添付ファイル 添付ファイル


「Unity」練習1

「Unity」の練習1

毎回利用させて頂いているkotarou 〜3D〜様の「船屋」モデルより。

至る所にで目にする、動く海面を自分でも作りたくて、「Unity」による初の練習作品。




「Unity」

フリーで公開されたUnityをインストールしてみたもののサッパリ??

PS4/PS3/PS Vita向けの「Unity Pro for PlayStation」がすべてのソフトウェアタイトル開発者に無償提供へ
http://www.scei.co.jp/corporate/release/140917.html
http://www.4gamer.net/games/210/G021014/20140917082/

ゲームだけでなく、医療、建築、・・様々な分野で。


使えるスキルがあれば使ってみたい。 画面は「SONY」版のUnity。


散々弄ったあげく、お手上げ状態となり徒労に終わらなければ良いが・・・。


GSU8 + sketchPhysics + Kerkythea キャタピラ・アニメーション

キャタピラのアニメーションをKerkytheaでレンダリングしてみた。
前進と後退の切り替えが極端なため、どちらに回転しているのかよく分からない。(12フレーム/秒)

SketchyPhysicsで動くアニメーションとして書き出せたのはジョイントを設定したオブジェクトだけ。





3D Warehouseから借りたSketchyPhysicsモデルに「Kerkythea」でレンダリングしてみた例。
「animation」のテストとして利用させて頂いたものだが、動作パターン(動く場合と動かない場合)を把握するため、暫くはこの作業が続きそうだ。




GSU8 + SketchPhysics + Kerkythea アニメーション

GSU8 の SketchPhysics Pluginで記録したデータを アニメーション(xml)ファイルとして「Kerkythea」にエクスポート。

その後「Kerkythea」でマテリアルの編集を行い、再度「.kst」のスクリプトファイルを利用して連続自動レンダリングを実行し、作成した磁石音符のアニメ。



アニメーションのテストにつき、フレームレートを1/3にカット。

添付ファイル 添付ファイル


「Kerkythea」海面レンダリング 設定動画

前記事のkotarou 〜3D〜様のGSUモデルをお借りした「Kerkythea」によるレンダリング画像。
海面の設定方法を、動画で備忘録にした。


正しい設定方法が分からないので、プロシージャ・マテリアルを利用した一つの例。
添付ファイル 添付ファイル


「Kerkythea」海面レンダリング その2

再度、kotarou 〜3D〜様のモデルをお借りし、BumpMappingに「Windy Texture」のマテリアルを適用し、海面の効果をテストしてみた。

複雑な設定は記憶に留めておけないため簡単な設定だけでも、それなりの効果が表現出来る事を確認できた。
前回の海面効果より少しましな気がする。




Kerkythea の、「Perlin Noise Texture」+「windy Texture」

以前、kotarou 〜3D〜様に借りした「funaya」のモデルの海面のみにテクスチャを設定し、水面のレンダリング効果を試してみた。

前回と同じ、「Perlin Noise Texture」に、不規則な表現を加えるため、「Windy Texture」を混ぜてテスト。

手探りの手法なので、それなりの結果となった。
先はまだまだ遠い。




その後・・・
KOKAのつぶやき様が「POV-Ray」で制作されているような超がつくほどリアルな海面表現には遠く及ばないが、良い目標ができた。

KOKAのつぶやき様が、「POV-Ray」により制作された海面画像



Kerkythea の、「Perlin Noise Texture」で水の質感

「Kerkythea」でブロックの質感に利用した「Perlin Noise Texture」を使い、水の質感にチャレンジ。

技術的な不満は多いが、短時間でそれなりの効果が得られたと言うことで良しとする事に。

「Kerkythea」水のマテリアル・レンダリング画像


作成の過程


マテリアル・エディッタに設定した個人的な水の設定項目

【Reflectance】
Diffuse: 30%
Reflection: 35%〜50%

【Transmittance】
Refraction: 80%
Index of Refraction: 1.100

【Bump Mapping】
Texture: Perlin Noise Texture
Strength: 0.500〜0.200


※添付ファイルは、作業と同サイズの"mp4"動画
添付ファイル 添付ファイル


< next prev >