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

forked* from PV3Dその3 with 3dtext.in API

Vectorvision3DがPV3Dに統合されたらしいと。
ただ、Word3D → text3Dと、VectorShapeMaterial → Letter3DMaterial となってる。
ここ以外はたぶん同じ。
// forked from sanpp's forked from: forked from: forked from: forked from: forked from: forked from: PV3Dその3
// forked from NABE6's forked from: forked from: forked from: forked from: forked from: PV3Dその3
// forked from NABE6's forked from: forked from: forked from: forked from: PV3Dその3
// forked from NABE6's forked from: forked from: forked from: PV3Dその3
// forked from NABE6's forked from: forked from: PV3Dその3
// forked from NABE6's forked from: PV3Dその3
// forked from sake's PV3Dその3
/*
    Vectorvision3DがPV3Dに統合されたらしいと。
    ただ、Word3D → text3Dと、VectorShapeMaterial → Letter3DMaterial となってる。
    ここ以外はたぶん同じ。
*/
package
{
	import caurina.transitions.Tweener;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.utils.setInterval;
	import org.papervision3d.cameras.Camera3D;
	import org.papervision3d.materials.special.Letter3DMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.view.layer.ViewportLayer;
	import org.papervision3d.core.proto.MaterialObject3D
	import org.papervision3d.materials.*;
	import org.papervision3d.events.FileLoadEvent;
	import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
	import flash.display.BitmapData;
	import flash.geom.*;
	import flash.events.*;
	import flash.net.*;
	import flash.display.Loader;
	[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="40")]
	public class PV3D_sample03 extends Sprite
	{
		private var container:Sprite;
		private var viewport:Viewport3D;
		private var scene:Scene3D;
		private var camera:Camera3D;
		private var render:BasicRenderEngine;
		private var rootNode:DisplayObject3D;
		private var words1:_3DText;
		private var words2:_3DText;
		private var words3:_3DText;
		private var theta:Number;
		private var delayTime:Number;
		private var WordMoveType:Number;
		private var txtcnt:int=0;
		private const zoom:Number=20;
		private const focus:Number=30;
		private const distance:Number = 600;
		private var mat:BitmapFileMaterial;
		private var pos:int=0;
		private var sel_arr:Array = new Array();
		public function PV3D_sample03()
		{
			theta=0;
			WordMoveType=0;
			delayTime=0;
			container=new Sprite();
			addChild(container);
			container.x=stage.stageWidth / 2;
			container.y=stage.stageHeight / 2;
			viewport=new Viewport3D(0, 0, true, true);
			scene = new Scene3D();
			camera=new Camera3D();
			render=new BasicRenderEngine();
			rootNode=scene.addChild(new DisplayObject3D("rootNode"));
			addChild(viewport);
			camera.target=DisplayObject3D.ZERO;
			camera.zoom=zoom;
			camera.focus=focus;
			mat = new BitmapFileMaterial("http://www.3dtext.in/image/0.jpg");
			mat.doubleSided = true;
			words1 = new _3DText(mat, "Papervision3D", 0, 0, "ipagp");
			words1.addEventListener(FileLoadEvent.LOAD_COMPLETE, handleFileLoaded);
			words2 = new _3DText(mat, "ようこそ!!", 0, 0, "ipagp");
			words2.addEventListener(FileLoadEvent.LOAD_COMPLETE, handleFileLoaded);
			words3 = new _3DText(mat, "3Dテキスト.in", 0, 0, "ipagp");
			words3.addEventListener(FileLoadEvent.LOAD_COMPLETE, handleFileLoaded);
			create_ctl();
		}
		protected function handleFileLoaded(e:FileLoadEvent):void
		{
			if (txtcnt++ < 2) return;
			rootNode.addChild(words1);
			rootNode.addChild(words2);
			rootNode.addChild(words3);
			words1.y=70;
			words2.y=0;
			words3.y=-70;
			words1.scale=words2.scale=words3.scale=0.2;
			dispersionWords(words1);
			dispersionWords(words2);
			dispersionWords(words3);
			setInterval(moveWords, 10000);
			addEventListener(Event.ENTER_FRAME, onFrame);
		}
		private function dispersionWords(words:_3DText):void
		{
			for each(var word:DisplayObject3D in words.letters)
			{
				word.extra={x:word.x, y:word.y, z:word.z};
				word.x=word.y=word.z=word.scale=0;
				Tweener.addTween(word, {scale:1, x:Math.random() * 2000 - 1000, y:Math.random() * 2000 - 1000, z:Math.random() * 2000 - 1000, rotationX:Math.random() * 360, rotationY:Math.random() * 360, rotationZ:Math.random() * 360, time:3, delay:2 * Math.random() + 1});
			}
		}
		private function moveWords():void
		{
			if (WordMoveType % 2 == 0)
			{
				resetWords(words1);
				resetWords(words2);
				resetWords(words3);
				delayTime=0;
				WordMoveType++;
			}
			else
			{
				breakWords(words1);
				breakWords(words2);
				breakWords(words3);
				WordMoveType++;
			}
		}
		private function resetWords(words:_3DText):void
		{
			for each(var word:DisplayObject3D in words.letters)
			{
				Tweener.addTween(word, {x:word.extra.x, y:word.extra.y, z:word.extra.z, rotationX:0, rotationY:0, rotationZ:0, time:1, transition:"easeOutBounce", delay:delayTime});
				Tweener.addTween(word, {rotationY:720, time:1, delay:delayTime + 2});
				delayTime+=0.1;
			}
		}
		private function breakWords(words:_3DText):void
		{
			for each(var word:DisplayObject3D in words.letters)
			{
				Tweener.addTween(word, {x:Math.random() * 2000 - 1000, y:Math.random() * 2000 - 1000, z:Math.random() * 2000 - 1000, rotationX:Math.random() * 360, rotationY:Math.random() * 360, rotationZ:Math.random() * 360, time:4, delay:3 * Math.random()});
			}
		}
		private function onFrame(e:Event):void
		{
			camera.x=distance * Math.sin(theta * Math.PI / 180);
			camera.z=distance * Math.cos(theta * Math.PI / 180);
			theta+=0.2;
			setBlur(words1);
			setBlur(words2);
			if(mat.loaded)scrollBitmap(mat.bitmap, -2, -2);
			render.renderScene(scene, camera, viewport);
		}
		private function DistanceFromCamera(obj:DisplayObject3D):Number
		{
			var vecX:Number=obj.sceneX - camera.x;
			var vecY:Number=obj.sceneY - camera.y;
			var vecZ:Number=obj.sceneZ - camera.z;
			return Math.sqrt((vecX * vecX) + (vecY * vecY) + (vecZ * vecZ));
		}
		private function setBlur(words:_3DText):void
		{
			for each(var word:DisplayObject3D in words.letters)
			{
				var vpl:ViewportLayer=word.createViewportLayer(viewport, true);
				var d:Number=Math.abs(DistanceFromCamera(word) - distance) / 40;
				vpl.filters=[new BlurFilter(d, d, 1)];
			}
		}
		private function create_ctl():void {
			var pl:Sprite = new Sprite();pl.x = 5;pl.y = stage.stageHeight - 27;
			pl.buttonMode = true;
			addChild(pl);
			var ld:Loader = new Loader();
			ld.load(new URLRequest("http://www.3dtext.in/image/tool.png"));
			pl.addChild(ld);
			sel_arr.push(new Sprite());sel_arr.push(new Sprite());
			pl.addChild(sel_arr[0]); pl.addChild(sel_arr[1]);
			pl.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
			pl.addEventListener(MouseEvent.ROLL_OUT, function():void{sel_arr[0].graphics.clear();});
			pl.addEventListener(MouseEvent.CLICK, mouseClickHandler);
			select_image(sel_arr[1],pos,true);
		}
		private function mouseClickHandler(e:MouseEvent):void {
			pos = e.localX / 24;
			select_image(sel_arr[1], pos, true);
			mat = new BitmapFileMaterial("http://www.3dtext.in/image/" + pos + ".jpg");
			mat.doubleSided = true;
			words1.set_letters_material(mat);
			words2.set_letters_material(mat);
			words3.set_letters_material(mat);
		}
		private function select_image(s:Sprite,a:int,b:Boolean):void {
			s.graphics.clear();
			if(b){s.graphics.lineStyle(1,0xff0000);}else{s.graphics.beginFill(0xcccccc,0.5);}
			s.graphics.drawRect(a * 24-1, 0, 24, 24);
			s.graphics.endFill();
		}
		private function mouseMoveHandler(e:MouseEvent):void {
			var x:int = e.localX / 24;
			if(x!=pos)select_image(sel_arr[0],x,false);
		}
		private function scrollBitmap(bm:BitmapData,sx:int,sy:int):void{
			var divx:int = Math.abs(sx), divy:int = Math.abs(sy);
			var rect:Array = [new Rectangle(bm.width - divx, 0, divx, bm.height), new Rectangle(0, 0, divx, bm.height),
			new Rectangle(0,0,bm.width,divy),new Rectangle(0,bm.height-divy,bm.width,divy)];
			var p:Array=[new Point(0,0),new Point(bm.width-divx,0),new Point(0,0),new Point(0,bm.height-divy)];
			var tmp:BitmapData = new BitmapData(bm.width,bm.height,bm.transparent,0x000000);
			(sx>0)?tmp.copyPixels(bm,rect[0],p[0]) : tmp.copyPixels(bm,rect[1], p[1]);
			bm.scroll(sx,0);
			(sx>0)?bm.copyPixels(tmp,rect[1],p[0]) : bm.copyPixels(tmp,rect[0], p[1]);
			(sy>0)?tmp.copyPixels(bm,rect[3],p[2]) : tmp.copyPixels(bm,rect[2], p[3]);
			bm.scroll(0,sy);
			(sy>0)?bm.copyPixels(tmp,rect[2],p[2]) : bm.copyPixels(tmp,rect[3], p[3]);
			tmp.dispose();
		}
	}
}

import org.papervision3d.core.geom.* 
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.math.*;
import org.papervision3d.core.proto.MaterialObject3D
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.materials.*;
import org.papervision3d.events.FileLoadEvent;
import flash.events.*;
import flash.net.*;
import flash.utils.*;
class _3DText extends TriangleMesh3D {
	public var loaded :Boolean;
	public var letters:Array;
	private var spacer:int = 30;
	private var _Mesh:DisplayObject3D;
	private var mat:MaterialObject3D;
	private var _filename:String;
	public function _3DText(material:MaterialObject3D,word:String,depth:Number,bevel:Number,font:String=null)
	{
		super( material, new Array(), new Array(), null );
		_Mesh = this; mat = material; letters = new Array();
		
		_filename = "http://www.3dtext.in/api/for_wonderfl_demo_key";
		var val:URLVariables = new URLVariables();
		val.text=word;		//作成する立体文字
		val.depth=depth;	//文字の厚さ
		val.bevel=bevel;	//文字べベル
		val.font = font;	//フォント名
		var req:URLRequest = new URLRequest(_filename);
		req.data=val;
	    var loader:URLLoader = new URLLoader();
		loader.dataFormat = URLLoaderDataFormat.BINARY;
		loader.addEventListener(Event.COMPLETE, completeHandler);
		loader.load(req);
	}
	public function set_letters_material(m:MaterialObject3D):void {
		for(var j:int=0;j<letters.length;j++)letters[j].material=m;
	}
	public function removeLetters():void {
		for each( var l:DisplayObject3D in letters){
			removeChild(l);	
		}
		letters.length = 0;
		parent.removeChild( this );
	}
	private function completeHandler(event:Event):void
	{
		var data:ByteArray = event.target.data;
		data.endian = Endian.LITTLE_ENDIAN
		var q:int;var sum:int=0
		try {
			while (q = data.readUnsignedShort()) {
				var t:TriangleMesh3D = new TriangleMesh3D(mat, new Array(), new Array());
				var arr: Array = new Array();
				if(q>1)for (var a:int = 0; a < q; a++) {
					var v1:Vertex3D = new Vertex3D(data.readFloat(), data.readFloat(),data.readFloat())
					var v2:Vertex3D = new Vertex3D(data.readFloat(), data.readFloat(),data.readFloat())
					var v3:Vertex3D = new Vertex3D(data.readFloat(), data.readFloat(),data.readFloat())
					t.geometry.vertices.push(v1);t.geometry.vertices.push(v2);t.geometry.vertices.push(v3);
					t.geometry.faces.push(new Triangle3D(t, [v1,v2,v3],mat, [new NumberUV(data.readFloat(),data.readFloat()),new NumberUV(data.readFloat(),data.readFloat()),new NumberUV(data.readFloat(),data.readFloat())]));
				}
				for (var i:int = 0; i < 9; i++) {arr.push(data.readFloat());}
				t.extra = { stat:arr }; sum += arr[0];
				letters.push(t);	
			}
		} catch (err:Error) {
		}finally {
			if (letters.length > 1) { sum +=(letters.length - 1)* spacer; }
			letters[0].x = -sum / 2+letters[0].extra.stat[0]/2;
			for (var i:int = 0; i < letters.length; i++ ) {
				_Mesh.addChild(letters[i]);
				if (i > 0) { letters[i].x=letters[i-1].x+spacer+(letters[i-1].extra.stat[0]/2)+(letters[i].extra.stat[0]/2); }
			}
			this.geometry.ready = true;
			var fileEvent:FileLoadEvent = new FileLoadEvent( FileLoadEvent.LOAD_COMPLETE, _filename );
			this.dispatchEvent( fileEvent );
			this.loaded = true;
		}
	}

}