Murayama blog.

AIの民主化。

Cubeで遊んでみた。


久しぶりにActionScriptを触ってみたので記念にアップ。



プログラムはしょぼしょぼやけど、3Dで動くのを作るのはやっぱり面白い。

package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.Event;
	
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.view.BasicView;
	
	public class CubeSample extends BasicView
	{
		[Embed(source="/assets/IMG_0150.JPG")]
		private var ok:Class;
		[Embed(source="/assets/IMG_0053.JPG")]
		private var boy:Class;
		[Embed(source="/assets/IMG_0055.JPG")]
		private var bird:Class;
		[Embed(source="/assets/IMG_0077.JPG")]
		private var cafe:Class;
		private var cube:Cube;
		
		public function CubeSample()
		{
			var materialsList:MaterialsList = new MaterialsList();
			var array:Array = [bird, boy, ok, cafe];
			var array2:Array = ["front", "back", "top", "bottom"];
			for(var i:Number = 0; i < array.length; i++){
				var bitmap:Bitmap = new array[i]() as Bitmap;
				var bitmapData:BitmapData = new BitmapData(210, 280);
				bitmapData.draw(bitmap);
				var material:BitmapMaterial = new BitmapMaterial(bitmapData, true);
				materialsList.addMaterial(material, array2[i]);	
			}
			
			materialsList.addMaterial(new ColorMaterial(0xffffff), "right");
			materialsList.addMaterial(new ColorMaterial(0xffffff), "left");
 			cube = new Cube(materialsList, 210, 280, 280, 4, 4, 4);
			scene.addChild(cube);
			startRendering();
		}
		
		override protected function onRenderTick(event:Event=null):void
		{
			cube.rotationX += 1.5;
			super.onRenderTick(event);
		}
	}
}