Murayama blog.

AIの民主化。

続 Papervision3Dが気になる Cube編

似たようなプログラム。

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	import org.papervision3d.cameras.Camera3D;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.MovieMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.view.Viewport3D;
	
	public class Sample2 extends Sprite
	{
		public function Sample2()
		{
			
			var viewport3D:Viewport3D = new Viewport3D(0, 0, true, true);
			addChild(viewport3D);
			viewport3D.buttonMode = true;
			
			var rendrer:BasicRenderEngine = new BasicRenderEngine();
			var scene:Scene3D = new Scene3D();
			
			var camera:Camera3D = new Camera3D();
			camera.zoom = 11;
			camera.focus = 100;
		
			var cc1:ColorMaterial = new ColorMaterial(0xFFFFFF);
			cc1.interactive = true;
			cc1.smooth = true;
			var cc2:ColorMaterial = new ColorMaterial(0xFFFF00);
			cc2.interactive = true;
			cc2.smooth = true;
			var cc3:ColorMaterial = new ColorMaterial(0xFF00FF);
			cc3.interactive = true;
			cc3.smooth = true;
			var cc4:ColorMaterial = new ColorMaterial(0x00FFFF);
			cc4.interactive = true;
			cc4.smooth = true;
			var cc5:ColorMaterial = new ColorMaterial(0x00FF00);
			cc5.interactive = true;
			cc5.smooth = true;
			var cc6:ColorMaterial = new ColorMaterial(0x000000);
			cc6.interactive = true;
			cc6.smooth = true;
			
			var cube:Cube = new Cube(new MaterialsList(
										{
											front:cc1,
											left:cc2,
											right:cc3,
											top:cc4,
											bottom:cc5,
											back:cc6
										}), 100, 100, 100, 10, 10, 10);
			scene.addChild(cube);
						
			this.addEventListener(Event.ENTER_FRAME, loop);
			function loop(e:Event):void
			{
				var xDist:Number = mouseX - stage.stageWidth * 0.5
				var yDist:Number = mouseY - stage.stageHeight * 0.5
			
				cube.rotationY += xDist * 0.05;
				cube.rotationX += yDist * 0.05;
				
				rendrer.renderScene(scene, camera, viewport3D);
			}
		}
	}
}

実行結果


サイコロっぽいのができました。
#あと、ライブラリのVersionを1.5から2.0のものに変えました。


[参考にさせて頂いたサイト]
404 Not Found


つづく。