Cubic Pixel

Molehill ファーストインプレッション | ClockMaker Blog」を参考に、埋め込み画像の画素を立方体に置き換えて表示してみました。Away3Dのバージョンは4.0 Betaを使用しています。

Get Adobe Flash Player
package
{
	import flash.display.*;
	import flash.events.Event;
	import away3d.containers.ObjectContainer3D;
	import away3d.containers.View3D;
	import away3d.debug.AwayStats;
	import away3d.entities.Mesh;
	import away3d.lights.DirectionalLight;
	import away3d.materials.ColorMaterial;
	import away3d.materials.lightpickers.StaticLightPicker;
	import away3d.primitives.CubeGeometry;

	[SWF(width = "400", height = "300", frameRate = "60")]
	public class CubicPixel extends Sprite
	{
		[Embed(source = "CubicPixel.png")]
		private var ImgCls:Class;
		private var view:View3D;
		private var container:ObjectContainer3D;
		private var cubes:Vector.<Mesh> = new Vector.<Mesh>();

		public function CubicPixel()
		{
			if (stage) addedToStageHanlder();
			else addEventListener(Event.ADDED_TO_STAGE, addedToStageHanlder);
		}

		private function addedToStageHanlder(event:Event = null):void
		{
			view = new View3D();
			view.antiAlias = 4;
			view.camera.z = -1000;
			addChild(view);

			var light:DirectionalLight = new DirectionalLight(0, -1, 1);
			light.specular = 0.25;
			view.scene.addChild(light);

			var lightPicker:StaticLightPicker = new StaticLightPicker([light]);

			container = new ObjectContainer3D();
			view.scene.addChild(container);

			var img:BitmapData = new ImgCls().bitmapData;
			var cubeGeometry:CubeGeometry = new CubeGeometry(30, 30, 30);
			for (var j:int = 0; j < img.height; j++) {
				for (var i:int = 0; i < img.width; i++) {
					var material:ColorMaterial = new ColorMaterial(img.getPixel(i, j));
					material.lightPicker = lightPicker;
					var cube:Mesh = new Mesh(cubeGeometry, material);
					cube.x = 50 * (i - img.width / 2) + 25;
					cube.y = 50 * (img.height / 2 - j) - 25;
					cubes.push(cube);
					container.addChild(cube);
				}
			}

			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			addChild(new AwayStats(view));

			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}

		private function enterFrameHandler(event:Event):void
		{
			for each (var cube:Mesh in cubes) {
				cube.rotationX += 1;
				cube.rotationY += 1;
			}
			container.rotationX += 0.25;
			container.rotationY += 0.25;
			view.render();
		}
	}
}
[トップページに戻る]