2009.01.06
category
comments

Papervision3Dでアニメーションつきdaeファイルを読み込む

daeファイルを読み込んでアニメーションをループさせるとこまでは出来たけど。これだと全フレームのアニメーションになってしまう。10から20フレーム目までとかを任意で動かしたいのに、下記のように自前で無理やり動かすと激重で固まってしまうし。FLVのseek()みたいな感じで弄れたら分かりやすいのにね。DAEクラスにはplay()とstop()しかないのかー。もうちょっと調べてみよう・・・。

override protected function onRenderTick(e:Event = null):void
{
	if(_channels)
	{
		for each(var channel:AbstractChannel3D in _channels)
		{
			channel.updateToFrame(_currentFrame);
		}
		_currentFrame++;
		_currentFrame = _currentFrame < _numFrames ? _currentFrame:0;
	}
}

左右の矢印キーで回転します。

2008.12.18
category
comments

Papervision3Dで3D空間にラインを描画する

Papervision3Dをちゃんと勉強しようかな。今までPlaneとかCubeとか基本的なクラスしか使ったことなかったし。

Vertex3Dとは3D空間における3次元頂点のこと。引数はx、y、zの各座標。ラインを描画するには、開始頂点と終了頂点を線でつなぐ、つまりlineToと一緒でz座標が増えただけ。描画の前にLines3DインスタンスをシーンにaddChildしておくこと。Lines3DはLine3Dを描画する入れ物。複数形なので最初にコード見たとき紛らわしい。

package
{
	import org.papervision3d.core.geom.Lines3D;
	import org.papervision3d.core.geom.renderables.Line3D;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	import org.papervision3d.materials.special.LineMaterial;
	import org.papervision3d.view.BasicView;

	import flash.events.Event;

	public class Main extends BasicView
	{
		private var lines3D:Lines3D;

		//------------------------------
		//    コンストラクタ
		//------------------------------
		public function Main()
		{
			var line:Line3D;
			var startV:Vertex3D;
			var endV:Vertex3D;
			var lm:LineMaterial = new LineMaterial(0xFF66CC);

			//-----[ラインを入れるラッパークラス]
			lines3D = new Lines3D();
			scene.addChild(lines3D);

			//-----[ラインの各頂点位置]
			var vertexAry:Array = [
				{ x:0, y:0, z:0 },
				{ x:50, y:50, z:0 },
				{ x:50, y:100, z:100 },
				{ x:0, y:150, z:100 },
				{ x:0, y:200, z:0 },
				{ x:200, y:250, z:0 },
				{ x:200, y:300, z:400 },
				{ x:0, y:350, z:400 },
				{ x:0, y:400, z:0 },
				{ x:400, y:450, z:0 },
				{ x:400, y:500, z:800 },
				{ x:0, y:550, z:800 },
			]

			//-----[ラインの生成]
			for (var i:uint = 1; i < vertexAry.length; i++)
			{
				startV = new Vertex3D(vertexAry[i - 1].x, vertexAry[i - 1].y, vertexAry[i - 1].z);
				endV = new Vertex3D(vertexAry[i].x, vertexAry[i].y, vertexAry[i].z);
				line = new Line3D(lines3D, lm, 2, startV, endV);
				lines3D.addLine(line);
			}

			//-----[カメラの設定]
			camera.y = 300;
			camera.target.y = 300;

			//-----[レンダリング開始]
			startRendering();
		}

		//------------------------------
		//    レンダリング
		//------------------------------
		protected override function onRenderTick(e:Event = null):void
		{
			lines3D.yaw((mouseX - (stage.stageWidth / 2)) / (stage.width / 2) * 5);
			super.onRenderTick(e);
		}
	}
}
2008.12.18
category
comments

Papervision3Dで動的にマテリアルを張り替える方法

動的にマテリアルの中身を変えたい時はreplaceMaterialByName()を使う。第2引数で張り替えたい個所を指定する。CubeやPlaneの各面を全部変えたい時は”all”にする。

var do3d:DisplayObject3D;
do3d.replaceMaterialByName(new ColorMaterial(0xFF66CC, 0.5), "front");
page 1 / 11