2013年2月27日水曜日

[python]開放されているポートを調べる

以前RealFlowを使用したとき、レンダーノードに
接続できなかったため、ポートチェックのために
pythonを使用しました。
from socket import *
import sys
if len(sys.argv[1:]) == 2:
    ip = sys.argv[1]
    sport = int(sys.argv[2])
    eport = sport + 1
elif len(sys.argv[1:]) == 3:
    ip = sys.argv[1]
    sport = int(sys.argv[2])
    eport = int(sys.argv[3]) + 1
else:
    exit()
for port in range(sport, eport):
    try:
        s = socket(AF_INET, SOCK_STREAM,0)
        s.settimeout(1)
        s.connect((ip,port))
        print str(port) + ':OK'
        s.close()
    except error, msg:
        print str(port) + ':' + str(msg)
RealFlowのレンダーノードは2223から2226を使用するので
python portCheck.py 2223 2226
で使用します。

2013年2月21日木曜日

[Unity3D]HingeJointを使った揺れモノ設定

キャラクタのヘアを揺らすための設定を
Hinge jointで考えてみました。











Hinge jointはグローバル座標でないとただしく動作しないので、
シーンに直接作成しています。
Sphereを作成してジョイントの代わりにPysicsコンポーネントを追加します。
Sphere1は物理の影響を受けさせたくないのでisKinematicをオンに
しておきます。

  • Sphere1にRigidBodyコンポーネントを追加
  • Sphere2,3,4にHinge jointを追加
  • Hinge joint>Connected Bodyに親のジョイントを設定
















次にCube1にHinge jointの親(Sphere1)にコンストレインさせるため
コンストレイン用のスクリプトを作成します。
using UnityEngine;
using System.Collections;

public class Constraint : MonoBehaviour {
	public Transform tr;
	private Quaternion rot;

	// Update is called once per frame
	void Update () {
		this.transform.position= tr.position;
		this.transform.rotation= Quaternion.Euler(	tr.eulerAngles.x,
													tr.eulerAngles.y,
													tr.eulerAngles.z );
	}
}
Sphere1にコンストレイントのコンポーネントを追加してターゲットに
Transform(Cube1)を設定します。

シーンを再生してCube1,Cube2を動かすと確認できます。

2013年2月15日金曜日

2013年2月12日火曜日

Unity 3Dのカメラを作成(win,mac)

Unity3Dのカメラスクリプトを作成しました。
マウスのみ対応で、pan,zoom,orbitが可能です。
https://gist.github.com/hiko9lock/4760161

使い方

  1. maimCameraにスクリプトをアタッチ
  2. targetに注視点用のgameObjectを設定
  • middleボタンでパン
  • LeftButtonでローテート
  • alt+RightButtonでズーム
transform.LookAtを使用しているため注視点用の
gameObjectを設定してください。

Unity3Dのassetのカメラスクリプトを拡張しようとしましたが
思ったとおりに制御できなかったので球座標系で位置を
計算しています。

2013年2月10日日曜日

Githubアカウント作成

Githubのアカウント作成しました。
URL https://github.com/hiko9lock

プログラマーではないのですがGithubにお世話になることが多々あるので 継続してチェックしているプロジェクトなど確認しやすくなりそうです。

 今はテストで作成したリポジトリしかありませんが、過去に作成したツールなども まとめていきたいと思います。

2013年2月7日木曜日

unity iOSプロファイラー

iOSではUnityのプロファイラーが使えないのでxCodeで有効にして
xCodeのOutPutWindowにプロファイル情報を表示させる必要があります。

 #define ENABLE_INTERNAL_PROFILER 1
結果はこちら。
iPhone Unity internal profiler stats:
cpu-player>    min:  3.3   max:  4.0   avg:  3.5
cpu-ogles-drv> min:  3.2   max:  4.0   avg:  3.7
cpu-present>   min:  0.9   max:  4.1   avg:  1.4
frametime>     min: 29.8   max: 36.6   avg: 33.4
draw-call #>   min:  11    max:  11    avg:  11     | batched:     0
tris #>        min: 13510  max: 13510  avg: 13510   | batched:     0
verts #>       min: 13368  max: 13368  avg: 13368   | batched:     0
player-detail> physx:  0.4 animation:  0.1 culling  0.0 skinning:  1.1 batching:  0.0 render:  1.5 fixed-update-count: 1 .. 2
mono-scripts>  update:  0.2   fixedUpdate:  0.0 coroutines:  0.0 
mono-memory>   used heap: 253952 allocated heap: 262144  max number of collections: 0 collection total duration:  0.0
詳細はこちら。
内蔵プロファイラでのパフォーマンス測定