setUVsToFace2 - UVマッピング
WASDで移動します
UVマッピングのサンプル
読み込んでいる画像は1つだけです
// forked from break's setUVsToFace
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.*;
import flash.events.*;
import flash.net.*;
import flash.display.*;
import flash.geom.*;
/*
* WASDで移動します
*
* UVマッピングのサンプル
* 読み込んでいる画像は1つだけです
*/
[SWF(backgroundColor="#000000", frameRate="120")]
public class Main extends Sprite {
public function Main() {
this.addEventListener(Event.ADDED, init);
}
public function init(e:Event):void {
this.removeEventListener(Event.ADDED, init);
loader = new Loader();
//読み込んでいる画像は1つだけです
loader.load(new URLRequest("http://assets.wonderfl.net/images/related_images/b/b8/b89e/b89eaa45e7cdaeda208e96077326838c9cf65b64"), new LoaderContext(true));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaded);
}
private function createMesh1():Mesh {
var mesh:Mesh = new Mesh();
/**
* UVs aUV, bUV, cUV
* 画像の左下が原点になります!
*
* 画像の左下を原点(0,0)として画像の右上を(1,1)とします
* (1以上の座標を指定すると、リピートされたように見えます)
*
*
* 参考 : 「uvマッピング」
* http://nishimulabo.edhs.ynu.ac.jp/~povray/3.5jp/povdoc_251.htm
*/
/**
* 1, 2, 3, 4
*/
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");
/**
* 3
*/
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.5,0), new Point(0.5,0.5), "geoFace2");
mesh.createSurface(["geoFace2"], "geo2");
mesh.setMaterialToSurface(new TextureMaterial(new Texture(image)), "geo2");
/**
* 2
*/
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.5), new Point(0.5,0.5), new Point(0.5,1), "geoFace3");
mesh.createSurface(["geoFace3"], "geo3");
mesh.setMaterialToSurface(new TextureMaterial(new Texture(image)), "geo3");
/**
* 4
*/
mesh.createVertex(-100, -100, 300, "v41");
mesh.createVertex(100, -100, 300, "v42");
mesh.createVertex(100, 100, 300, "v43");
mesh.createVertex(-100, 100, 300, "v44");
mesh.createFace(["v41", "v42", "v43", "v44"], "geoFace4");
mesh.setUVsToFace(new Point(0.5, 0), new Point(1, 0), new Point(1, 0.5), "geoFace4");
mesh.createSurface(["geoFace4"], "geo4");
mesh.setMaterialToSurface(new TextureMaterial(new Texture(image)), "geo4");
/**
* 1
*/
mesh.createVertex(-100, -100, 400, "v51");
mesh.createVertex(100, -100, 400, "v52");
mesh.createVertex(100, 100, 400, "v53");
mesh.createVertex(-100, 100, 400, "v54");
mesh.createFace(["v51", "v52", "v53", "v54"], "geoFace5");
mesh.setUVsToFace(new Point(0.5, 0.5), new Point(1,0.5), new Point(1, 1), "geoFace5");
mesh.createSurface(["geoFace5"], "geo5");
mesh.setMaterialToSurface(new TextureMaterial(new Texture(image)), "geo5");
return mesh;
}
private var scene:Scene3D;
private var view:View;
private var camera:Camera3D;
private var cameraController:CameraController;
private var geo:Mesh;
private var image:BitmapData;
private var loader:Loader;
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;
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();
}
}
}