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

アニメ風擬音

TriangleMesh3Dを貼り合わして、アニメの擬音風に、文字を飛びださせてみました。
クリックすると始まります。

「課題」
 TriangleMesh3Dを箱のように組み上げて表示した時、見えてはいけない面が一部見えて、
 まだら模様になる。普通、zソートすればいいのかもしれないが、TriangleMesh3Dのモデル
 は、x,y,zが0,0,0だから、zソートがうまく行くか疑問だ。それに、見えてはいけない面が一
 部見えてしまう原因がはっきりしないのが最大の問題だ(大汗)。
Get Adobe Flash player
by hankuro 15 Oct 2009
    Embed
/**
 * Copyright hankuro ( http://wonderfl.net/user/hankuro )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/9o1e
 */

package 
{
	import caurina.transitions.Tweener;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import org.papervision3d.core.effects.view.ReflectionView;
	import org.papervision3d.core.geom.renderables.Triangle3D;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	import org.papervision3d.core.geom.TriangleMesh3D;
	import org.papervision3d.core.geom.Vertices3D;
	import org.papervision3d.core.material.TriangleMaterial;
	import org.papervision3d.core.math.NumberUV;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.BitmapColorMaterial;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.MovieMaterial;
	import org.papervision3d.materials.shadematerials.GouraudMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.materials.special.Letter3DMaterial;
	import org.papervision3d.typography.Text3D;
	import org.papervision3d.typography.fonts.HelveticaBold;
	import org.papervision3d.typography.fonts.HelveticaRoman;
	
	
	[SWF(width = 500, height = 500, backgroundColor = 0x000000)]
	
	/**
	 * TriangleMesh3Dを貼り合わして、アニメの擬音風に、文字を飛びださせてみました。
	 * クリックすると始まります。
	 * 
	 * 「課題」
	 *  TriangleMesh3Dを箱のように組み上げて表示した時、見えてはいけない面が一部見えて、
	 *  まだら模様になる。普通、zソートすればいいのかもしれないが、TriangleMesh3Dのモデル
	 *  は、x,y,zが0,0,0だから、zソートがうまく行くか疑問だ。それに、見えてはいけない面が一
	 *  部見えてしまう原因がはっきりしないのが最大の問題だ(大汗)。
	 * 
	 */
	public class Main extends  ReflectionView
	{ 
		public var plane:Plane;
		public var plane_moji:Plane;
		public var obj3D:DisplayObject3D;
		public var mesh_array:Array;
		public var mesh_s_array:Array;
		public var v0:Vertex3D;
		public var v1:Vertex3D;
		public var v2:Vertex3D;
		public var uvA:NumberUV;
		public var uvB:NumberUV;
		public var uvC:NumberUV;
		private var meshface:Triangle3D;
		private var mm1:ColorMaterial;
		private var mm2:ColorMaterial;
		private var mm3:ColorMaterial;
		private var max_triangle:Number;
		private var max_moji:Number;
		private var zoom:Number = 0;
		private var scenario_num:Number = -1;
		private var wait_num:Number = 0;
		private var mm:ColorMaterial;
		private var moji_alpha:Number = 1;
		
		public function Main() 
		{
			super(500, 500, false, false);
			camera.z = -400;
			surfaceHeight = -200;
			obj3D = new DisplayObject3D();			
			scene.addChild(obj3D);
			var pointLight:PointLight3D = new PointLight3D();
			pointLight.x = 0;
			pointLight.y = -100;
			pointLight.z = -100;
			var s:Sprite = new Sprite();
			var text:TextField = new TextField();
			var fmt:TextFormat = new TextFormat();
			text.text = "イタッ!";
			text.width = 200;
			fmt.size = 60;
			fmt.color = 0xFF0000;
			text.setTextFormat(fmt);
			s.addChild(text);
			var material:MovieMaterial = new MovieMaterial(s);
			plane_moji = new Plane(material, 200, 100, 1, 1);
			obj3D.addChild(plane_moji);
			plane_moji.z = 50;
/*			
			var letterformat:Letter3DMaterial = new Letter3DMaterial(0xFF0000 , 0.8);
			var text:Text3D = new Text3D("Ouch!" , new HelveticaBold() , letterformat);
			text.scaleX = 0.6;
			text.scaleX = 0.6;
			text.scaleZ = 0.6;
			text.rotationY = -20;
			text.z = 50;
*/
//			obj3D.addChild(text);
			var mat:GouraudMaterial = new GouraudMaterial(pointLight, 0x00FFFF, 0x000000);
			mat.doubleSided = true;
			plane = new Plane(mat, 200, 200, 24, 20);
			obj3D.addChild(plane);
			obj3D.rotationY = -20;
//			obj3D.rotationX = -10;
			var max_num:Number = Math.max((Const_data.moji[0].length+Const_data.moji[1].length+Const_data.moji[2].length),
										  (Const_data.moji[3].length+Const_data.moji[4].length+Const_data.moji[5].length),
										  (Const_data.moji[6].length+Const_data.moji[7].length+Const_data.moji[8].length));
			mesh_array = new Array(max_num);
			var j:Number = 0;
			mm = new ColorMaterial(0xFFFFFF);
			mm1 = new ColorMaterial(0x00FFFF);
			mm2 = new ColorMaterial(0x01AAAA);
			mm3 = new ColorMaterial(0x00FFFF);
			mm1.doubleSided = true;
			mm2.doubleSided = true;
			mesh_s_array = new Array(max_num*4);
//			moji_out(0, 100);
			zoom = 0;
			wait_num = 2;
//			startRendering();
//			Tweener.addTween(plane, { y:-100  ,rotationX:-90, time:3, transition:"easeInOutCirc" } );
			singleRender();
			addEventListener(Event.ENTER_FRAME, onRun);
			var ss:Sprite = new Sprite();
			ss.graphics.beginFill(0x000000, 0);
			ss.graphics.drawRect(0, 0, 500, 500);
			ss.graphics.endFill();
			addChild(ss);
			ss.buttonMode = true;
			ss:addEventListener(MouseEvent.CLICK,onClick);
		}
		public function onClick(evet:MouseEvent):void {
			removeEventListener(MouseEvent.CLICK, onClick);
			scenario_num = 0;
		}
		public function moji_out(p1:Number,p2:Number):void {
			var k:Number = 0;
			var g:Number = 0;
			for (var i:Number = 0; i<Const_data.moji_point[p1].length; i++) {
				var n:Number = Const_data.moji_point[p1][i];
				for (var j:Number = 0; j < Const_data.moji[n].length; j++) {
					var e:Number = Const_data.moji[n][j];
					mesh_array[k] = make_mesh(mm);
					for (var h:Number = 0; h < 3; h++) {
						mesh_array[k].geometry.vertices[h].x = plane.geometry.faces[e].vertices[h].x;
						mesh_array[k].geometry.vertices[h].y = plane.geometry.faces[e].vertices[h].y;
						mesh_array[k].geometry.vertices[h].z = plane.geometry.faces[e].vertices[h].z - p2;
					}
					if (!check_point(e, n,0)) {
						mesh_s_array[g] = make_mesh(mm1);					
						mesh_s_array[g].geometry.vertices[0].x = plane.geometry.faces[e].vertices[0].x;
						mesh_s_array[g].geometry.vertices[0].y = plane.geometry.faces[e].vertices[0].y;
						mesh_s_array[g].geometry.vertices[0].z = plane.geometry.faces[e].vertices[0].z;
						mesh_s_array[g].geometry.vertices[1].x = plane.geometry.faces[e].vertices[1].x;
						mesh_s_array[g].geometry.vertices[1].y = plane.geometry.faces[e].vertices[1].y;
						mesh_s_array[g].geometry.vertices[1].z = plane.geometry.faces[e].vertices[1].z;
						mesh_s_array[g].geometry.vertices[2].x = mesh_array[k].geometry.vertices[1].x;
						mesh_s_array[g].geometry.vertices[2].y = mesh_array[k].geometry.vertices[1].y;
						mesh_s_array[g].geometry.vertices[2].z = mesh_array[k].geometry.vertices[1].z;
						g++;
					}
					if (!check_point(e, n,0)) {
						mesh_s_array[g] = make_mesh(mm1);					
						mesh_s_array[g].geometry.vertices[0].x = mesh_array[k].geometry.vertices[0].x;
						mesh_s_array[g].geometry.vertices[0].y = mesh_array[k].geometry.vertices[0].y;
						mesh_s_array[g].geometry.vertices[0].z = mesh_array[k].geometry.vertices[0].z;
						mesh_s_array[g].geometry.vertices[1].x = mesh_array[k].geometry.vertices[1].x;
						mesh_s_array[g].geometry.vertices[1].y = mesh_array[k].geometry.vertices[1].y;
						mesh_s_array[g].geometry.vertices[1].z = mesh_array[k].geometry.vertices[1].z;
						mesh_s_array[g].geometry.vertices[2].x = plane.geometry.faces[e].vertices[0].x;
						mesh_s_array[g].geometry.vertices[2].y = plane.geometry.faces[e].vertices[0].y;
						mesh_s_array[g].geometry.vertices[2].z = plane.geometry.faces[e].vertices[0].z;
						g++;
					}
					if (!check_point(e, n,1)) {
						mesh_s_array[g] = make_mesh(mm2);
						mesh_s_array[g].geometry.vertices[0].x = plane.geometry.faces[e].vertices[0].x;
						mesh_s_array[g].geometry.vertices[0].y = plane.geometry.faces[e].vertices[0].y;
						mesh_s_array[g].geometry.vertices[0].z = plane.geometry.faces[e].vertices[0].z;
						mesh_s_array[g].geometry.vertices[1].x = plane.geometry.faces[e].vertices[2].x;
						mesh_s_array[g].geometry.vertices[1].y = plane.geometry.faces[e].vertices[2].y;
						mesh_s_array[g].geometry.vertices[1].z = plane.geometry.faces[e].vertices[2].z;
						mesh_s_array[g].geometry.vertices[2].x = mesh_array[k].geometry.vertices[2].x;
						mesh_s_array[g].geometry.vertices[2].y = mesh_array[k].geometry.vertices[2].y;
						mesh_s_array[g].geometry.vertices[2].z = mesh_array[k].geometry.vertices[2].z;
						g++;
					}
					if (!check_point(e, n,1)) {
						mesh_s_array[g] = make_mesh(mm2);					
						mesh_s_array[g].geometry.vertices[0].x = mesh_array[k].geometry.vertices[0].x;
						mesh_s_array[g].geometry.vertices[0].y = mesh_array[k].geometry.vertices[0].y;
						mesh_s_array[g].geometry.vertices[0].z = mesh_array[k].geometry.vertices[0].z;
						mesh_s_array[g].geometry.vertices[1].x = mesh_array[k].geometry.vertices[2].x;
						mesh_s_array[g].geometry.vertices[1].y = mesh_array[k].geometry.vertices[2].y;
						mesh_s_array[g].geometry.vertices[1].z = mesh_array[k].geometry.vertices[2].z;
						mesh_s_array[g].geometry.vertices[2].x = plane.geometry.faces[e].vertices[0].x;
						mesh_s_array[g].geometry.vertices[2].y = plane.geometry.faces[e].vertices[0].y;
						mesh_s_array[g].geometry.vertices[2].z = plane.geometry.faces[e].vertices[0].z;
						g++;
					}
					k++;
//					if (j == 8) return;
				}
				
			}
			max_triangle = g;
			max_moji = k;
			
		}
		public function make_mesh(p:ColorMaterial): TriangleMesh3D{
			var mesh:TriangleMesh3D = new TriangleMesh3D(p, new Array(), new Array(), null );
			v0 = new Vertex3D( 0, 0, 0 );
			v1 = new Vertex3D( 0, 0, 0 );
			v2 = new Vertex3D( 0, 0, 0 );
			mesh.geometry.vertices.push( v0 );
			mesh.geometry.vertices.push( v1 );
			mesh.geometry.vertices.push( v2 );
			uvA = new NumberUV( 0, 0 );
			uvC = new NumberUV( 1, 0 );
			uvB = new NumberUV( 0, 1 );
			mesh.geometry.faces.push( new Triangle3D( mesh, new Array(v0,v1,v2), null, new Array(uvA,uvC,uvB) ));
			mesh.geometry.ready = true;
			obj3D.addChild(mesh);
			return mesh;
		}
		public function check_point(p1:Number, p2:Number,p3:Number):Boolean {
			var rtn:Boolean = false;
			if (p1 % 2 == 0) {
				switch(p3) {
					case 0:
							if (p1 % 40 != 0) {
								if (check_no(p1 - 1, p2)) rtn = true;
							}
							break;
					case 1:
							if (p1 < 39) rtn = false;
							else if (check_no(p1 - 40, p2)) rtn = true;
							else rtn = false;
				}
			}else {
				switch(p3) {
					case 0:
							if (p1 % 39 != 0) {
								if (check_no(p1 + 1, p2)) rtn = true;
							}
							break;							
					case 1:
							if (p1 + 20 > 20 * 24 - 1) rtn = false;
							else if (check_no(p1 + 40, p2)) rtn = true;
							else rtn = false;
				}				
			}
			return rtn;			
		}
		public function check_no(p1:Number, p2:Number):Boolean {
			for (var i:Number = 0; i < Const_data.moji[p2].length; i++) {
				if (Const_data.moji[p2][i] == p1) return true;
			}
			return false;
		}
		public function cler_mesh(p:Boolean = false):void {
			if(!p){
				for (var i:Number = 0; i < max_triangle; i++) {
					obj3D.removeChild(mesh_s_array[i]);				
				}
			}
			if(p){
				for (i = 0; i < max_moji; i++) {
					obj3D.removeChild(mesh_array[i]);
				}	
			}
		}
		private function onRun(evt:Event):void {

			var mousePos:Point = new Point(mouseX,mouseY);
			mousePos.offset( -stage.stageWidth / 2, -stage.stageHeight / 2);
			switch(scenario_num) {
				case 0:
					if (wait_num == 0) {
						moji_out(1, 50);
						wait_num = 4;
						scenario_num = 1;
					}else{
						wait_num--;
					}
					break;
				case 1:	
					if (wait_num == 0) {
						cler_mesh();
						cler_mesh(true);
						wait_num = 3;
						scenario_num = 3;
					}else{
						wait_num--;
					}
					break;
				case 3:
					if (wait_num == 0) {
						moji_out(2, 50);
						wait_num = 4;
						scenario_num = 4;
					}else{
						wait_num--;
					}
					break;
				case 4:	
					if (wait_num == 0) {
						cler_mesh();
						cler_mesh(true);
						wait_num = 4;
						scenario_num = 5;
					}else{
						wait_num--;
					}
					break;
				case 5:
					if (wait_num == 0) {
						moji_out(0, 200);
						wait_num = 3;
						scenario_num = 6;
					}else{
						wait_num--;
					}
					break;
				case 6:
					if (wait_num == 0) {
						cler_mesh();
						scenario_num = 7;
					}else{
						wait_num--;
					}
					break;
				case 7:
					trace(moji_alpha);
					if (moji_alpha < 0) {
						cler_mesh(true);
						scenario_num = 8;
					}else {
						moji_alpha -= .1;
						for (var i:Number = 0; i < mesh_array.length; i ++ ) {
							 mesh_array[i].alpha -= .1;
						}
					}
					break;
				case 8:
					scenario_num = 9;
					Tweener.addTween(plane, { y:-100  ,rotationX:-90, time:3, transition:"easeInOutCirc" } );
			}
			 
			singleRender();
		}
	}
	
}
    class Const_data 
	{
		
		public static const moji:Array = [
											[ 46, 47, 66, 67, 68, 69, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
											 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 128, 129, 130, 131, 132, 133, 134, 135,
											 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 164, 165,
											 186, 187, 188, 189, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
											 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 232, 233, 236, 237, 246, 247,
											 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265,
											 266, 267, 268, 269, 272, 273, 276, 277],
											[342, 343, 344, 345, 346, 347, 348, 349, 364, 365, 376, 377, 378, 379, 382, 383, 384, 385,
											 386, 387, 388, 389, 404, 405, 406, 407, 416, 417, 418, 419, 426, 427, 428, 429, 446, 447,
											 448, 449, 456, 457, 458, 459, 466, 467, 468, 469, 488, 489, 490, 491, 492, 493, 494, 495,
											 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 530, 531, 532, 533,
											 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549],
											[604, 605, 606, 607, 622, 623, 624, 625, 626, 627, 628, 629, 644, 645, 646, 647, 662, 663,
											 664, 665, 666, 667, 668, 669, 684, 685, 686, 687, 724, 725, 726, 727, 728, 729, 730, 731,
											 768, 769, 770, 771, 772, 773, 774, 775, 812, 813, 814, 815, 816, 817, 818, 819, 856, 857,
											 858, 859, 860, 861, 862, 863, 900, 901, 902, 903],
											[72, 73, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 142, 143, 152, 153, 184, 185, 186,
											 187, 188, 189, 190, 191, 192, 193, 234, 235, 276, 277],
											[312, 313, 350, 351, 352, 353, 354, 355, 382, 383, 392, 393, 424, 425, 426, 427, 428, 429, 430,
											 431, 432, 433, 434, 435, 472, 473],
											[508, 509, 582, 583, 588, 589, 624, 625, 666, 667, 668, 669],
											[322, 323, 332, 333, 362, 363, 372, 373, 402, 403, 412, 413, 442, 443, 444, 445, 446, 447, 448,
											 449, 450, 451, 452, 453, 494, 495, 536, 537],
											[562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 610, 611, 650, 651],
											[722, 723, 730, 731, 762, 763, 770, 771, 804, 805, 846, 847, 888, 889]	
											
										 ];
		 public static const moji_point:Array = [ [0, 1, 2], [3, 4, 5], [6, 7, 8]];
	}