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

[Stardust][PV3D] TwitterBird

...
@author paq89
/**
 * Copyright paq ( http://wonderfl.net/user/paq )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/b7zr
 */

package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.BlurFilter;
	import frocessing.shape.FShapeSVG;
	import idv.cjcat.stardust.common.clocks.SteadyClock;
	import idv.cjcat.stardust.common.particles.ParticleIterator;
	import idv.cjcat.stardust.common.particles.Particle;
	import idv.cjcat.stardust.threeD.papervision3d.renderers.PV3DDisplayObject3DRenderer;
	import org.papervision3d.core.clipping.FrustumClipping;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
	
	/**
	 * ...
	 * @author paq89
	 */
	[SWF(width=465, height=465, frameRate=60)]
	public class Main extends BasicView
	{
		private var _container:DisplayObject3D;
		private var _emitter:BirdEmitter;
		private var _blurFilter:Array = [];
		
		private var _modifier:ModifierStack;
		private var _modifier2:ModifierStack;
		
		/**
         * コンストラクタ
         */
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			initPV3D();
			initStardust();
			
			addEventListener(Event.ENTER_FRAME, loop);
			stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
		}
		
		private function initPV3D():void
		{
			// 背景色
			opaqueBackground = 0x6CC5C3;
			
			// パーティクルを格納するためのコンテナを作る
			_container = new DisplayObject3D();
			scene.addChild(_container);
			
			// カメラ
			camera.zoom = 2;
			camera.focus = 300;
			
			//renderer.clipping = new FrustumClipping(FrustumClipping.NEAR);
			
			var sea:Plane = new Plane(new ColorMaterial(0xFFFFFF), 2000, 2000, 10, 10);
			sea.rotationX = 90;
			_container.addChild(sea);
			
			var sea2:Plane = new Plane(new ColorMaterial(0xF15A22), 2000, 2000, 10, 10);
			sea2.rotationX = 90;
			sea2.y = -200;
			_container.addChild(sea2);
			
			// 軽量化のため、フィルターをあらかじめ作っておく
            for (var i:int = 0; i < 20; i++) 
            {
                _blurFilter[i] = new BlurFilter(i, i, 1);
            }
			
			_modifier = new ModifierStack(new LibraryPv3d(), sea);
			var perlin:Perlin = new Perlin(1);
            perlin.setFalloff(1, 1);
			_modifier.addModifier(perlin);
			
			_modifier2 = new ModifierStack(new LibraryPv3d(), sea2);
			var perlin2:Perlin = new Perlin(1);
            perlin2.setFalloff(1, 1);
			_modifier2.addModifier(perlin2);
		}
		
		/**
		 * パーティクルシステムの構築
		 */
		private function initStardust():void
		{
			// エミッター
			_emitter = new BirdEmitter(new SteadyClock(0.1));
			
            // レンダラー
			var renderer:PV3DDisplayObject3DRenderer = new PV3DDisplayObject3DRenderer(_container);
            renderer.addEmitter(_emitter);
		}
		
		/**
        * エンターフレームイベント
        */
        private function loop(e:Event):void 
        {
            // エミッター更新
            _emitter.step();
            
            // Papervision3Dのレンダリング
            singleRender();
			
			_modifier.apply();
			_modifier2.apply();
			
			setBlur();
        }
		
		/**
         * マウスの位置に合わせてカメラを移動
         */
        private function onMouseMove(e:MouseEvent):void 
        {
            camera.x += (2000 * Math.sin(mouseX / stage.stageWidth * 360 * Math.PI / 180) - camera.x) * .1;
            camera.z += (2000 * Math.cos(mouseX / stage.stageWidth * 360 * Math.PI / 180) - camera.z) * .1;
            camera.y += (2000 * mouseY / stage.stageHeight - camera.y) * .1;
        }
		
		/**
         * 被写界深度を適用
         */
        private function setBlur():void 
        {
            //var len:int = _particlesList.length;
            var iter:ParticleIterator = _emitter.getParticles().getIterator();
            var p:Particle;
            while (p = iter.particle) {
                var o:DisplayObject3D = p.target;
                if (!o.visible) o.visible = true;
                
                // 距離の算出
                var deg:Number = Math.abs(calcPointDistanceFromCamera(o) - 2000);
                
                // ぼかしの適用値
                var blurVal:int = Math.min(10, deg * 0.008 << 1 ) >> 0;;
                if (blurVal > 19) blurVal = 19;
                var blurFilter:BlurFilter = _blurFilter[blurVal];
                
                // フィルター適用
                o.filters = [blurFilter];
                
                iter.next();
            }
        }
		
		/**
         * カメラからの距離を算出します
         * @param    obj 計測したいオブジェクト
         * @return    カメラからの距離(3D空間内のpx値)
         */
        private function calcPointDistanceFromCamera(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));
        }
	}
	
}
//-------------------------------------------------------------

import flash.display.BitmapData;
import flash.display.Sprite;
import frocessing.shape.FShapeSVG;
import idv.cjcat.stardust.common.actions.Age;
import idv.cjcat.stardust.common.actions.DeathLife;
import idv.cjcat.stardust.common.actions.ScaleCurve;
import idv.cjcat.stardust.common.clocks.Clock;
import idv.cjcat.stardust.common.initializers.Life;
import idv.cjcat.stardust.common.initializers.Scale;
import idv.cjcat.stardust.common.math.UniformRandom;
import idv.cjcat.stardust.threeD.actions.Deflect3D;
import idv.cjcat.stardust.threeD.actions.Gravity3D;
import idv.cjcat.stardust.threeD.actions.Move3D;
import idv.cjcat.stardust.threeD.actions.SpeedLimit3D;
import idv.cjcat.stardust.threeD.actions.Spin3D;
import idv.cjcat.stardust.threeD.deflectors.PlaneDeflector;
import idv.cjcat.stardust.threeD.emitters.Emitter3D;
import idv.cjcat.stardust.threeD.fields.UniformField3D;
import idv.cjcat.stardust.threeD.initializers.DisplayObjectClass3D;
import idv.cjcat.stardust.threeD.initializers.Omega3D;
import idv.cjcat.stardust.threeD.initializers.Position3D;
import idv.cjcat.stardust.threeD.initializers.Rotation3D;
import idv.cjcat.stardust.threeD.initializers.Velocity3D;
import idv.cjcat.stardust.threeD.zones.CubeZone;
import idv.cjcat.stardust.threeD.zones.SinglePoint3D;
import idv.cjcat.stardust.threeD.zones.SphereCap;
import idv.cjcat.stardust.threeD.zones.Surface;
import idv.cjcat.stardust.twoD.actions.SpeedLimit;
import idv.cjcat.stardust.twoD.zones.LazySectorZone;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.objects.primitives.Plane;

//-------------------------------------------------------------

class BirdEmitter extends Emitter3D
{
	public function BirdEmitter(clock:Clock):void 
	{
		super(clock);
		
		var cap:SphereCap = new SphereCap(0, 100, 0, 0, 50, 15);
        
        var omegaRand:UniformRandom = new UniformRandom(0, 4);
        
		var svg:XML = <svg><path fill="#F15A22" d="M0,16.609c0,0,2.959-2.25,3.084-2.791c0.125-0.543,2.459-4.709,6.375-4.709s7.916,6.25,9.833,6.25	s-1.5-2.833,2.25-7.25c5.493-6.469,13-4,14.083-8c0.263-0.972,2.584,4.75,2.584,9.083c0,4.333-3.417,9.917-3.417,9.917	s0.417,0.666,2.5,0.666s5.75-3.5,5.75-3.5s2.834,19.417-19.584,19.417c-6.481,0-14.372-5.372-16.811-11.433	c-0.988-2.455-0.428-4.499-2.781-6.188C3.394,17.732,0.621,16.137,0,16.609z"/><path fill="#FFFFFF" d="M24.542,16.359c2.931,3.35,13-1.75,8-11C32.542,5.359,19.292,10.359,24.542,16.359z"/><circle fill="#FFFFFF" cx="8.126" cy="13.86" r="1.777"/></svg>
		var fshape:FShapeSVG = new FShapeSVG(svg);
		var sprite:Sprite = fshape.toSprite();
		var bmpd:BitmapData = new BitmapData(sprite.width, sprite.height, true, 0x00000000);
		bmpd.draw(sprite);
		var mat:BitmapMaterial = new BitmapMaterial(bmpd); 
		mat.doubleSided = true;
		
        // パーティクルの属性を定義
        addInitializer(new DisplayObjectClass3D(BirdParticle, [mat]));
        addInitializer(new Life(new UniformRandom(200, 0)));
        addInitializer(new Scale(new UniformRandom(1, 1.2)));
        addInitializer(new Position3D(new CubeZone(-1000, 0, -1000, 2000, 2000, 2000)));
        addInitializer(new Velocity3D(cap));
        addInitializer(new Rotation3D(new UniformRandom(0, 0), new UniformRandom(0, 180)));
        addInitializer(new Omega3D(new UniformRandom(0, 0), new UniformRandom(0, 4)));
		
		// 重力を定義
        var field:UniformField3D = new UniformField3D(0, 0.1, 0);
        var gravity:Gravity3D = new Gravity3D();
        gravity.addField(field);
		
		// デフレクトを定義
        var deflect:Deflect3D = new Deflect3D();
        deflect.addDeflector(new PlaneDeflector(0, 100, 0, 0, 1, 0));
		
		// デフレクトを定義
        var deflect2:Deflect3D = new Deflect3D();
        deflect2.addDeflector(new PlaneDeflector(0, 700, 0, 0, -1, 0));
		
        // パーティクルのアクションを定義
		addAction(deflect);
		addAction(deflect2);
        addAction(gravity);
		addAction(new Move3D());
		addAction(new Age());
        addAction(new DeathLife());
		addAction(new ScaleCurve(5, 20));
		addAction(new Spin3D());
		addAction(new SpeedLimit3D(10));
	}
}

class BirdParticle extends Plane
{
	public function BirdParticle(mat:MaterialObject3D):void 
	{
		super(mat, 100, 100, 1, 1);
		useOwnContainer = true;
	}
}

/**
 * Copyright (c) 2008 Bartek Drozdz (http://www.everydayflash.com)
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * Same license applies to every file in this package and its subpackages.  
 */
internal class Phase {private var v:Number;public function Phase() {v = 0;}public function get value():Number {return v;}public function set value(v:Number):void {this.v = v;}public function get phasedValue():Number {return Math.sin(v);}public function get absPhasedValue():Number {return Math.abs(phasedValue);}}internal class Library3d {public function get id():String {return "";}public function get meshClass():String {return "";}public function get vertexClass():String {return "";}}internal class XMath {public static function normalize(start:Number, end:Number, val:Number):Number{var range:Number = end - start;var normal:Number;if (range == 0) {normal = 1;} else {normal = (Math.min (Math.max ((val - start) / end, 0.0), 1.0));}return normal;}}internal class ModifierStack  {private var lib3d:Library3d;private var baseMesh:MeshProxy;private var stack:Array;public function ModifierStack(lib3d:Library3d, mesh:*) {this.lib3d = lib3d;baseMesh = PluginFactory.getMeshProxy(lib3d);baseMesh.setMesh(mesh);baseMesh.analyzeGeometry();stack = new Array();}public function get mesh():MeshProxy {return baseMesh;}public function addModifier(mod:IModifier):void {mod.setModifiable(baseMesh);stack.push(mod);}public function apply():void {baseMesh.resetGeometry();for (var i:int = 0; i < stack.length; i++) {(stack[i] as IModifier).apply();}}public function collapse():void {apply();baseMesh.collapseGeometry();stack = new Array();}public function clear():void {stack = new Array();}}internal interface IModifier {function setModifiable(mod:MeshProxy):void;function apply():void;}internal class Modifier {protected var mod:MeshProxy;public function setModifiable(mod:MeshProxy):void {this.mod = mod;}public function getVertices():Array {return mod.getVertices();}}internal class Twist extends Modifier implements IModifier {private var _vector:Vector3D = new Vector3D(0, 1, 0);private var _angle:Number;public var center:Vector3D = new Vector3D();public function Twist(a:Number = 0) {_angle = a;}public function get angle():Number { return _angle; }public function set angle(value:Number):void { _angle = value; }public function get vector():Vector3D { return _vector; }public function set vector(value:Vector3D):void { _vector = value; }public function apply():void {_vector.normalize();var dv:Vector3D = new Vector3D(mod.maxX / 2, mod.maxY / 2, mod.maxZ / 2);var d:Number = -Vector3D.dot(_vector, center);for(var i:int = 0;i < mod.getVertices().length; i++) {var vertex:VertexProxy = mod.getVertices()[i];var dd:Number = Vector3D.dot(new Vector3D(vertex.x, vertex.y, vertex.z), _vector) + d;twistPoint(vertex, (dd / dv.modulo) * _angle);}}private function twistPoint(v:VertexProxy, a:Number):void {var mat:Matrix3D = Matrix3D.translationMatrix(v.x, v.y, v.z);mat = Matrix3D.multiply(Matrix3D.rotationMatrix(_vector.x, _vector.y, _vector.z, a), mat);v.x = mat.n14;v.y = mat.n24;v.z = mat.n34;}}internal class Bend extends Modifier implements IModifier {private var frc:Number;private var ofs:Number;private var cst:int = ModConstant.NONE;private var maa:int = ModConstant.NONE;private var mia:int = ModConstant.NONE;public function Bend(f:Number=0, o:Number=.5) {force = f;offset = o;}public function set force(f:Number):void {frc = f;}public function set offset(o:Number):void {ofs = o;ofs = Math.max(0, o);ofs = Math.min(1, o);}public function set constraint(c:int):void {cst = c; }public function get force():Number {return frc;}public function get offset():Number {return ofs;}public function get constraint():int {return cst; }public function set bendAxis(a:int):void {maa = a;}public function set pointAxis(a:int):void {mia = a;}public function apply():void {if(force == 0) return;if (maa == ModConstant.NONE) maa = mod.maxAxis;if (mia == ModConstant.NONE) mia = mod.minAxis;var pto:Number = mod.getMin(maa);var ptd:Number = mod.getMax(maa) - pto;var vs:Array = mod.getVertices();var vc:int = vs.length;var distance:Number = pto + ptd * offset;var radius:Number = ptd / Math.PI / force;var angle:Number = Math.PI * 2 * (ptd / (radius * Math.PI * 2));for (var i:int = 0; i < vc; i++) {var v:VertexProxy = vs[i] as VertexProxy;var p:Number = v.getRatio(maa);if (constraint == ModConstant.LEFT && p <= offset) continue;if (constraint == ModConstant.RIGHT && p >= offset) continue;var fa:Number = ((Math.PI / 2) - angle * offset) + (angle * p);var op:Number = Math.sin(fa) * (radius + v.getValue(mia)) - radius;var ow:Number = distance - Math.cos(fa) * (radius + v.getValue(mia));v.setValue(mia, op);v.setValue(maa, ow);}}}internal class Bloat extends Modifier implements IModifier {private var _x:Number = 0;public function get x ():Number { return _x; }public function set x (v:Number):void { _x = v; }private var _y:Number = 0;public function get y ():Number { return _y; }public function set y (v:Number):void { _y = v; }private var _z:Number = 0;public function get z ():Number { return _z; }public function set z (v:Number):void { _z = v; }private var _r:Number = 0;public function get r ():Number { return _r; }public function set r (v:Number):void { _r = Math.max (0, v); }private var _a:Number = 1e-2;public function get a ():Number { return _a; }public function set a (v:Number):void { _a = Math.max (0, v); }public function apply():void {var vs:Array = mod.getVertices();var vc:int = vs.length;for (var i:int = 0; i < vc; i++) {var v:VertexProxy = VertexProxy (vs [i]);var ux:Number = v.x - _x;var uy:Number = v.y - _y;var uz:Number = v.z - _z;var ur:Number = Math.sqrt (ux * ux + uy * uy + uz * uz);if (ur > 0) {ux /= ur; uy /= ur; uz /= ur;} else {ux = 1.0;}ur += _r * Math.exp ( -ur * _a);v.x = _x + ux * ur;v.y = _y + uy * ur;v.z = _z + uz * ur;}}}internal class Noise extends Modifier implements IModifier {private var frc:Number;private var axc:int = ModConstant.NONE;private var start:Number = 0;private var end:Number = 0;public function Noise(f:Number=0) {this.frc = f;}public function set force(f:Number):void {frc = f;}public function get force():Number {return frc;}public function constraintAxes(c:int):void {this.axc = c;}public function setFalloff(start:Number=0, end:Number=1):void {this.start = start;this.end = end;}public function apply():void {var vs:Array = mod.getVertices();var vc:int = vs.length;for (var i:int = 0; i < vc; i++) {var v:VertexProxy = vs[i] as VertexProxy;var r:Number = (Math.random() * force) - (force / 2);var p:Number = v.getRatio(mod.maxAxis);if(start < end) {if (p < start) p = 0;if (p > end) p = 1;} else if(start > end) {p = 1 - p;if (p > start) p = 0;if (p < end) p = 1;} else {p = 1;}if (!(axc & 1)) v.x += r * p;if (!(axc >> 1 & 1)) v.y += r * p;if (!(axc >> 2 & 1)) v.z += r * p;}}}import flash.display.Bitmap;import flash.display.BitmapData;import flash.display.BitmapDataChannel;import flash.geom.Point;internal class Perlin extends Modifier implements IModifier {private var b:BitmapData = null;private var off:Number;private var frc:Number;private var seed:Number;private var start:Number = 0;private var end:Number = 0;public function Perlin(f:Number=1) {frc = f;b = new BitmapData(25, 11);off = 0;seed = Math.random() * 1000;}public function setFalloff(start:Number=0, end:Number=1):void {this.start = start;this.end = end;}public function set force(f:Number):void {frc = f;}public function get previev():Bitmap {var pr:Bitmap = new Bitmap(b);pr.scaleX = pr.scaleY = 4;return pr;}public function get force():Number {return frc;}public function apply():void {var p:Point = new Point(off++, 0);b.perlinNoise(25, 11, 1, seed, false, true, BitmapDataChannel.RED, true, [p, p, p]);var vs:Array = mod.getVertices();var vc:int = vs.length;for (var i:int = 0; i < vc; i++) {var v:VertexProxy = vs[i] as VertexProxy;var py:int = Math.round(v.getRatio(mod.maxAxis) * 24);var px:int = Math.round(v.getRatio(mod.midAxis) * 10);var vzpos:Number = b.getPixel(py, px) & 0xff;var fa:Number = v.getRatio(mod.maxAxis);if(start < end) {if (fa < start) fa = 0;if (fa > end) fa = 1;} else if(start > end) {fa = 1 - fa;if (fa > start) fa = 0;if (fa < end) fa = 1;} else {fa = 1;}v.setValue(mod.minAxis, v.getValue(mod.minAxis) + (128 - vzpos) * frc * fa);}}}internal class Skew extends Modifier implements IModifier{private var frc:Number;public function Skew(f:Number) {f = force;}public function set force(f:Number):void {frc = f;}public function get force():Number {return frc;}public function apply():void {var vs:Array = mod.getVertices();var vc:int = vs.length;for (var i:int = 0; i < vc; i++) {var v:VertexProxy = vs[i] as VertexProxy;var vl:Number = v.getValue(mod.minAxis) + force * Math.pow(v.getRatio(mod.maxAxis), 2);v.setValue(mod.minAxis, vl);}}}internal class Taper extends Modifier implements IModifier{private var frc:Number;private var pow:Number;private var start:Number = 0;private var end:Number = 1;public function Taper(f:Number) {frc = f;pow = 1;}public function setFalloff(start:Number=0, end:Number=1):void {this.start = start;this.end = end;}public function set force(value:Number):void {frc = value;}public function get force():Number {return frc;}public function get power():Number { return pow; }public function set power(value:Number):void { pow = value; }public function apply():void {var vs:Array = mod.getVertices();var vc:int = vs.length;for (var i:int = 0; i < vc; i++) {var v:VertexProxy = vs[i] as VertexProxy;var ar:Number = Math.pow(XMath.normalize(start, end, v.getRatio(mod.maxAxis)), pow);var sc:Number = frc * ar;var m:Matrix3D = Matrix3D.scaleMatrix(1+sc, 1+sc, 1);var n:Vector3D = new Vector3D(v.getValue(mod.minAxis), v.getValue(mod.midAxis), v.getValue(mod.maxAxis));Matrix3D.multiplyVector(m, n);v.setValue(mod.minAxis, n.x);v.setValue(mod.midAxis, n.y);}}}internal class Matrix3D {public var n11:Number;public var n12:Number;public var n13:Number;public var n14:Number;public var n21:Number;public var n22:Number;public var n23:Number;public var n24:Number;public var n31:Number;public var n32:Number;public var n33:Number;public var n34:Number;public var n41:Number;public var n42:Number;public var n43:Number;public var n44:Number;public function Matrix3D(pn11:Number = 1, pn12:Number = 0 , pn13:Number = 0 , pn14:Number = 0,pn21:Number = 0, pn22:Number = 1 , pn23:Number = 0 , pn24:Number = 0,pn31:Number = 0, pn32:Number = 0 , pn33:Number = 1 , pn34:Number = 0,pn41:Number = 0, pn42:Number = 0 , pn43:Number = 0 , pn44:Number = 1 ) {n11 = pn11; n12 = pn12; n13 = pn13; n14 = pn14;n21 = pn21; n22 = pn22; n23 = pn23; n24 = pn24;n31 = pn31; n32 = pn32; n33 = pn33; n34 = pn34;n41 = pn41; n42 = pn42; n43 = pn43; n44 = pn44;}public static function translationMatrix( x:Number, y:Number, z:Number ):Matrix3D {var m:Matrix3D = new Matrix3D();m.n14 = x;m.n24 = y;m.n34 = z;return m;}public static function scaleMatrix( x:Number, y:Number, z:Number ):Matrix3D {var m:Matrix3D = new Matrix3D();m.n11 = x;m.n22 = y;m.n33 = z;return m;}public static function rotationMatrix( x:Number, y:Number, z:Number, rad:Number, targetmatrix:Matrix3D = null ):Matrix3D {var m:Matrix3D;if(!targetmatrix) m = new Matrix3D();else m = targetmatrix; var nCos:Number = Math.cos(rad);var nSin:Number = Math.sin(rad);var scos:Number = 1 - nCos;var sxy:Number = x * y * scos;var syz:Number = y * z * scos;var sxz:Number = x * z * scos;var sz:Number = nSin * z;var sy:Number = nSin * y;var sx:Number = nSin * x;m.n11 = nCos + x * x * scos;m.n12 = -sz + sxy;m.n13 = sy + sxz;m.n14 = 0;m.n21 = sz + sxy;m.n22 = nCos + y * y * scos;m.n23 = -sx + syz;m.n24 = 0;m.n31 = -sy + sxz;m.n32 = sx + syz;m.n33 = nCos + z * z * scos;m.n34 = 0;return m;}public function calculateMultiply( a:Matrix3D, b:Matrix3D ):void {var a11:Number = a.n11; var b11:Number = b.n11;var a21:Number = a.n21; var b21:Number = b.n21;var a31:Number = a.n31; var b31:Number = b.n31;var a12:Number = a.n12; var b12:Number = b.n12;var a22:Number = a.n22; var b22:Number = b.n22;var a32:Number = a.n32; var b32:Number = b.n32;var a13:Number = a.n13; var b13:Number = b.n13;var a23:Number = a.n23; var b23:Number = b.n23;var a33:Number = a.n33; var b33:Number = b.n33;var a14:Number = a.n14; var b14:Number = b.n14;var a24:Number = a.n24; var b24:Number = b.n24;var a34:Number = a.n34; var b34:Number = b.n34;this.n11 = a11 * b11 + a12 * b21 + a13 * b31;this.n12 = a11 * b12 + a12 * b22 + a13 * b32;this.n13 = a11 * b13 + a12 * b23 + a13 * b33;this.n14 = a11 * b14 + a12 * b24 + a13 * b34 + a14;this.n21 = a21 * b11 + a22 * b21 + a23 * b31;this.n22 = a21 * b12 + a22 * b22 + a23 * b32;this.n23 = a21 * b13 + a22 * b23 + a23 * b33;this.n24 = a21 * b14 + a22 * b24 + a23 * b34 + a24;this.n31 = a31 * b11 + a32 * b21 + a33 * b31;this.n32 = a31 * b12 + a32 * b22 + a33 * b32;this.n33 = a31 * b13 + a32 * b23 + a33 * b33;this.n34 = a31 * b14 + a32 * b24 + a33 * b34 + a34;}public static function multiply( a:Matrix3D, b:Matrix3D ):Matrix3D {var m:Matrix3D = new Matrix3D();m.calculateMultiply(a, b);return m;}public static function multiplyVector( m:Matrix3D, v:Vector3D ):void {var vx:Number = v.x;var vy:Number = v.y;var vz:Number = v.z;v.x = vx * m.n11 + vy * m.n12 + vz * m.n13 + m.n14;v.y = vx * m.n21 + vy * m.n22 + vz * m.n23 + m.n24;v.z = vx * m.n31 + vy * m.n32 + vz * m.n33 + m.n34;}}internal class Vector3D {public var x:Number;public var y:Number;public var z:Number;public function Vector3D( x:Number = 0, y:Number = 0, z:Number = 0 ) {this.x = x;this.y = y;this.z = z;}public function get modulo():Number {return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);}public function normalize():void {var mod:Number = this.modulo;if( mod != 0 && mod != 1) {this.x /= mod;this.y /= mod;this.z /= mod;}}public static function dot( v:Vector3D, w:Vector3D ):Number {return ( v.x * w.x + v.y * w.y + w.z * v.z );}}internal class ModConstant {public static const NONE:int = 0;public static const X:int = 1;public static const Y:int = 2;public static const Z:int = 4;public static var LEFT:int = -1;public static var RIGHT:int = 1;}internal class VertexProxy {private var _ratioX:Number;private var _ratioY:Number;private var _ratioZ:Number;protected var ox:Number;protected var oy:Number;protected var oz:Number;public function VertexProxy() {}public function setVertex(vertex:*):void {}public function setRatios(rx:Number, ry:Number, rz:Number):void {_ratioX = rx;_ratioY = ry;_ratioZ = rz;}public function setOriginalPosition(ox:Number, oy:Number, oz:Number):void {this.ox = ox;this.oy = oy;this.oz = oz;}public function get x():Number {return 0;}public function get y():Number {return 0;}public function get z():Number {return 0;}public function set x(v:Number):void {}public function set y(v:Number):void {}public function set z(v:Number):void {}public function getValue(axis:int):Number {switch(axis) {case ModConstant.X: return x;case ModConstant.Y: return y;case ModConstant.Z: return z;}return 0;}public function setValue(axis:int, v:Number):void {switch(axis) {case ModConstant.X: x = v; break;case ModConstant.Y: y = v; break;case ModConstant.Z: z = v; break;}}public function get ratioX():Number {return _ratioX;}public function get ratioY():Number {return _ratioY;}public function get ratioZ():Number {return _ratioZ;}public function getRatio(axis:int):Number {switch(axis) {case ModConstant.X: return _ratioX;case ModConstant.Y: return _ratioY;case ModConstant.Z: return _ratioZ;}return -1;}public function get originalX():Number {return ox;}public function get originalY():Number {return oy;}public function get originalZ():Number {return oz;}public function getOriginalValue(axis:int):Number {switch(axis) {case ModConstant.X: return ox;case ModConstant.Y: return oy;case ModConstant.Z: return oz;}return 0;}public function reset():void {x = ox;y = oy;z = oz;}public function collapse():void {ox = x;oy = y;oz = z;}}internal class MeshProxy {protected var vertices:Array;protected var _maxX:Number;protected var _maxY:Number;protected var _maxZ:Number;protected var _minX:Number;protected var _minY:Number;protected var _minZ:Number;protected var _maxAxis:int;protected var _midAxis:int;protected var _minAxis:int;protected var _sizeX:Number;protected var _sizeY:Number;protected var _sizeZ:Number;public function MeshProxy() {vertices = new Array();}public function setMesh(mesh:*):void {}public function getVertices():Array {return vertices;}public function analyzeGeometry():void {var vc:int = getVertices().length;var i:int;var v:VertexProxy;for (i = 0; i < vc; i++) {v = getVertices()[i] as VertexProxy;if (i == 0) {_minX = _maxX = v.x;_minY = _maxY = v.y;_minZ = _maxZ = v.z;} else  {_minX = Math.min(_minX, v.x);_minY = Math.min(_minY, v.y);_minZ = Math.min(_minZ, v.z);_maxX = Math.max(_maxX, v.x); _maxY = Math.max(_maxY, v.y); _maxZ = Math.max(_maxZ, v.z); }v.setOriginalPosition(v.x, v.y, v.z);}_sizeX = _maxX - _minX;_sizeY = _maxY - _minY;_sizeZ = _maxZ - _minZ;var maxe:Number = Math.max(_sizeX, Math.max(_sizeY, _sizeZ));var mine:Number = Math.min(_sizeX, Math.min(_sizeY, _sizeZ));if (maxe == _sizeX && mine == _sizeY) {_minAxis = ModConstant.Y;_midAxis = ModConstant.Z;_maxAxis = ModConstant.X;} else if (maxe == _sizeX && mine == _sizeZ) {_minAxis = ModConstant.Z;_midAxis = ModConstant.Y;_maxAxis = ModConstant.X;} else if (maxe == _sizeY && mine == _sizeX) {_minAxis = ModConstant.X;_midAxis = ModConstant.Z;_maxAxis = ModConstant.Y;} else if (maxe == _sizeY && mine == _sizeZ) {_minAxis = ModConstant.Z;_midAxis = ModConstant.X;_maxAxis = ModConstant.Y;} else if (maxe == _sizeZ && mine == _sizeX) {_minAxis = ModConstant.X;_midAxis = ModConstant.Y;_maxAxis = ModConstant.Z;} else if (maxe == _sizeZ && mine == _sizeY) {_minAxis = ModConstant.Y;_midAxis = ModConstant.X;_maxAxis = ModConstant.Z;}for (i = 0; i < vc; i++) {v = getVertices()[i] as VertexProxy;v.setRatios((v.x - _minX) / _sizeX, (v.y - _minY) / _sizeY, (v.z - _minZ) / _sizeZ);}}public function resetGeometry():void {var vc:int = getVertices().length;for (var i:int = 0; i < vc; i++) {var v:VertexProxy = getVertices()[i] as VertexProxy;v.reset();}}public function collapseGeometry():void {var vc:int = getVertices().length;for (var i:int = 0; i < vc; i++) {var v:VertexProxy = getVertices()[i] as VertexProxy;v.collapse();}analyzeGeometry();}public function get minX():Number {return _minX;}public function get minY():Number {return _minY;}public function get minZ():Number {return _minZ;}public function getMin(axis:int):Number {switch(axis) {case ModConstant.X: return _minX;case ModConstant.Y: return _minY;case ModConstant.Z: return _minZ;}return -1;}public function get maxX():Number {return _maxX;}public function get maxY():Number {return _maxY;}public function get maxZ():Number {return _maxZ;}public function getMax(axis:int):Number {switch(axis) {case ModConstant.X: return _maxX;case ModConstant.Y: return _maxY;case ModConstant.Z: return _maxZ;}return -1;}public function get maxAxis():int {return _maxAxis;}public function get midAxis():int {return _midAxis;}public function get minAxis():int {return _minAxis;}}import org.papervision3d.core.geom.renderables.Vertex3D;import org.papervision3d.objects.DisplayObject3D;internal class Pv3dMesh extends MeshProxy {private var do3d:DisplayObject3D;override public function setMesh(mesh:*):void {do3d = mesh as DisplayObject3D;var vs:Array = do3d.geometry.vertices;var vc:int = vs.length;for (var i:int = 0; i < vc; i++) {var nv:Pv3dVertex = new Pv3dVertex();nv.setVertex(vs[i] as Vertex3D);vertices.push(nv);}}}import flash.utils.getDefinitionByName;internal class PluginFactory {public static function getMeshProxy(lib3d:Library3d):MeshProxy {return new Pv3dMesh();}}internal class LibraryPv3d extends Library3d {public function LibraryPv3d() {var m:MeshProxy = new Pv3dMesh();var v:VertexProxy = new Pv3dVertex();}override public function get id():String {return "pv3d";}override public function get meshClass():String {return "Pv3dMesh";}override public function get vertexClass():String {return "com.as3dmod.plugins.pv3d.Pv3dVertex";}}import org.papervision3d.core.geom.renderables.Vertex3D;internal class Pv3dVertex extends VertexProxy {private var vx:Vertex3D;public function Pv3dVertex() {}override public function setVertex(vertex:*):void {vx = vertex as Vertex3D;ox = vx.x;oy = vx.y;oz = vx.z;}override public function get x():Number {return vx.x;}override public function get y():Number {return vx.y;}override public function get z():Number {return vx.z;}override public function set x(v:Number):void {vx.x = v;}override public function set y(v:Number):void {vx.y = v;}override public function set z(v:Number):void { vx.z = v; }}