In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

setUVsToFace

WASDで移動します
package {
	import alternativ5.engine3d.controllers.*;
	import alternativ5.engine3d.core.*;
	import alternativ5.engine3d.display.*;
	import alternativ5.types.*;
	import alternativ5.utils.*;
	import alternativ5.engine3d.materials.*;
	import flash.system.LoaderContext;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	
	import flash.display.Loader;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	import flash.geom.Point;
	
	/*
	 * WASDで移動します
	 *
	 */

	[SWF(backgroundColor="#000000", frameRate="120")]
	public class Main extends Sprite {
	    
		private var scene:Scene3D;
		private var view:View;
		private var camera:Camera3D;
		private var cameraController:CameraController;
		
		private var geo:Mesh;
		private var geo2:Mesh;
		
		private var image:BitmapData;
		private var loader:Loader;
		

		public function Main() {
			this.addEventListener(Event.ADDED, init);
		}
		
		public function init(e:Event):void {
			this.removeEventListener(Event.ADDED, init);
			loader = new Loader();
			loader.load(new URLRequest("http://assets.wonderfl.net/images/related_images/f/f4/f417/f4175bbac5bf6b5cd64ec3b251fbbc6b4797f6d1m"), new LoaderContext(true));
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaded);
		}
		
		private function loaded(e:Event):void{
			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,loaded);
			image = new BitmapData(loader.content.width, loader.content.height,true);
			image.draw(loader);

			hoge();
		}
			
	    public function hoge():void{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			scene = new Scene3D();
			scene.root = new Object3D();
			
			geo = scene.root.addChild(createMesh1()) as Mesh;
			geo2 = scene.root.addChild(createMesh2()) as Mesh;
			
			geo2.x = 300;
			
			camera = new Camera3D();
			camera.x = 130;
			camera.y = -90;
			camera.z = 130;
			scene.root.addChild(camera);
			
			view = new View();
			addChild(view);
			view.camera = camera;
			
			cameraController = new CameraController(stage);
			cameraController.camera = camera;
			cameraController.lookAt(geo.coords);
			cameraController.setDefaultBindings();
			cameraController.checkCollisions = true;
			cameraController.collisionRadius = 20;
			cameraController.speed = 200;
			cameraController.controlsEnabled = true;
			
			FPS.init(stage);
			
			stage.addEventListener(Event.RESIZE, onResize);
			stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
			onResize(null);
		}

		private function onResize(e:Event):void {
			view.width = stage.stageWidth;
			view.height = stage.stageHeight;
		}
		
		private function onEnterFrame(e:Event):void {
			cameraController.processInput();
			scene.calculate();
		}
		
		private function createMesh1():Mesh {
			var mesh:Mesh = new Mesh();
			
			mesh.createVertex(-100, -100, 0, "v1");
			mesh.createVertex(100, -100, 0, "v2");
			mesh.createVertex(100, 100, 0, "v3");
			mesh.createVertex(-100, 100, 0, "v4");
			mesh.createFace(["v1", "v2", "v3", "v4"], "geoFace");
			mesh.setUVsToFace(new Point(0,0), new Point(1,0), new Point(1,1), "geoFace");
			mesh.createSurface(["geoFace"], "geo");
			mesh.setMaterialToSurface(new TextureMaterial(new Texture(image)), "geo");

			mesh.createVertex(-100, -100, 100, "v21");
			mesh.createVertex(100, -100, 100, "v22");
			mesh.createVertex(100, 100, 100, "v23");
			mesh.createVertex(-100, 100, 100, "v24");
			mesh.createFace(["v21", "v22", "v23", "v24"], "geoFace2");
			mesh.setUVsToFace(new Point(0,0), new Point(0,1), new Point(1,1), "geoFace2");
			mesh.createSurface(["geoFace2"], "geo2");
			mesh.setMaterialToSurface(new TextureMaterial(new Texture(image)), "geo2");
			
			mesh.createVertex(-100, -100, 200, "v31");
			mesh.createVertex(100, -100, 200, "v32");
			mesh.createVertex(100, 100, 200, "v33");
			mesh.createVertex(-100, 100, 200, "v34");
			mesh.createFace(["v31", "v32", "v33", "v34"], "geoFace3");
			mesh.setUVsToFace(new Point(0,0), new Point(0,1), new Point(0,1), "geoFace3");
			mesh.createSurface(["geoFace3"], "geo3");
			mesh.setMaterialToSurface(new TextureMaterial(new Texture(image)), "geo3");	
			
			return mesh;
		}
		
		private function createMesh2():Mesh {
			var mesh:Mesh = new Mesh();
			
			for (var i:uint = 0; i < 5; i++){
				mesh.createVertex(-100, -100, 100 * i, "sv1" + i);
				mesh.createVertex(100, -100, 100 * i, "sv2" + i);
				mesh.createVertex(100, 100, 100 * i, "sv3" + i);
				mesh.createVertex(-100, 100, 100 * i, "sv4" + i);
				mesh.createFace(["sv1" + i, "sv2" + i, "sv3" + i, "sv4" + i], "geoFaceS" + i);
				mesh.setUVsToFace(new Point(0,0), new Point(1 * i,0), new Point(1 * i,1 * i), "geoFaceS" + i);
				mesh.createSurface(["geoFaceS" + i], "geoS" + i);
				mesh.setMaterialToSurface(new TextureMaterial(new Texture(image)), "geoS" + i);
			}
			
			return mesh;
		}
	}
}