⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basemesh.as

📁 著名的flash 3d引擎 away 3d的源代码
💻 AS
📖 第 1 页 / 共 2 页
字号:
            if (_minXDirty)            {                _minXElement = null;                var extrval:Number = Infinity;                for each (var element:IMeshElement in elements)                {                    var val:Number = element.minX;                    if (val < extrval)                    {                        extrval = val;                        _minXElement = element;                    }                }                _minX = extrval;                _minXDirty = false;            }            return _minX;        }        		/**		 * @inheritDoc		 */        public override function get maxY():Number        {            if (_maxYDirty)            {                var extrval:Number = -Infinity;                _maxYElement = null;                for each (var element:IMeshElement in elements)                {                    var val:Number = element.maxY;                    if (val > extrval)                    {                        extrval = val;                        _maxYElement = element;                    }                }                _maxY = extrval;                _maxYDirty = false;            }            return _maxY;        }        		/**		 * @inheritDoc		 */        public override function get minY():Number        {            if (_minYDirty)            {                var extrval:Number = Infinity;                _minYElement = null;                for each (var element:IMeshElement in elements)                {                    var val:Number = element.minY;                    if (val < extrval)                    {                        extrval = val;                        _minYElement = element;                    }                }                _minY = extrval;                _minYDirty = false;            }            return _minY;        }        		/**		 * @inheritDoc		 */        public override function get maxZ():Number        {            if (_maxZDirty)            {                var extrval:Number = -Infinity;                _maxZElement = null;                for each (var element:IMeshElement in elements)                {                    var val:Number = element.maxZ;                    if (val > extrval)                    {                        extrval = val;                        _maxZElement = element;                    }                }                _maxZ = extrval;                _maxZDirty = false;            }            return _maxZ;        }        		/**		 * @inheritDoc		 */        public override function get minZ():Number        {            if (_minZDirty)            {                var extrval:Number = Infinity;                _minZElement = null;                for each (var element:IMeshElement in elements)                {                    var val:Number = element.minZ;                    if (val < extrval)                    {                        extrval = val;                        _minZElement = element;                    }                }                _minZ = extrval;                _minZDirty = false;            }            return _minZ;        }				/**		 * Indicates the current frame of animation		 */        public function get frame():int        {            return _animation.frame;        }                public function set frame(value:int):void        {            if (_animation.frame == value)                return;			_frame = value;            _animation.frame = value;            frames[value].adjust(1);        }        		/**		 * Indicates whether the animation has a cycle event listener		 */		public function get hasCycleEvent():Boolean        {			return _animation.hasEventListener(AnimationEvent.CYCLE);        }        		/**		 * Indicates whether the animation has a sequencedone event listener		 */		public function get hasSequenceEvent():Boolean        {			return hasEventListener(AnimationEvent.SQUENCE_DONE);        }        		/**		 * Determines the frames per second at which the animation will run.		 */		public function set fps(value:int):void		{			_animation.fps = (value>=1)? value : 1;		}				/**		 * Determines whether the animation will loop.		 */		public function set loop(loop:Boolean):void		{			_animation.loop = loop;		}                /**        * Determines whether the animation will smooth motion (interpolate) between frames.        */		public function set smooth(smooth:Boolean):void		{			_animation.smooth = smooth;		}				/**		 * Indicates whether the animation is currently running.		 */		public function get isRunning():Boolean		{			return _animation.isRunning;		}				/**		 * Creates a new <code>BaseMesh</code> object.		 *		 * @param	init			[optional]	An initialisation object for specifying default instance properties		 */        public function BaseMesh(init:Object = null)        {            super(init);                        pushback = ini.getBoolean("pushback", false);            pushfront = ini.getBoolean("pushfront", false);        }            	/**    	 * Scales the contents of the mesh.    	 *     	 * @param	scale	The scaling value    	 */        public override function scale(scale:Number):void        {            scaleXYZ(scale, scale, scale);        }		    	/**    	 * Scales the contents of the mesh along the x-axis.    	 *     	 * @param	scaleX	The scaling value    	 */        public function scaleX(scaleX:Number):void        {            if (scaleX != 1)                scaleXYZ(scaleX, 1, 1);        }		    	/**    	 * Scales the contents of the mesh along the y-axis.    	 *     	 * @param	scaleX	The scaling value    	 */        public function scaleY(scaleY:Number):void        {            if (scaleY != 1)                scaleXYZ(1, scaleY, 1);        }		    	/**    	 * Scales the contents of the mesh along the z-axis.    	 *     	 * @param	scaleX	The scaling value    	 */        public function scaleZ(scaleZ:Number):void        {            if (scaleZ != 1)                scaleXYZ(1, 1, scaleZ);        }        		/**		 * @inheritDoc		 *     	 * @see	away3d.core.traverse.PrimitiveTraverser    	 * @see	away3d.core.draw.DrawPrimitive		 */		override public function primitives(consumer:IPrimitiveConsumer, session:AbstractRenderSession):void        {        	super.primitives(consumer, session);        	_dsStore = _dsStore.concat(_dsActive);        	_dsActive = new Array();        }				/**		 * Starts playing the animation at the specified frame.		 * 		 * @param	value		A number representing the frame number.		 */		public function gotoAndPlay(value:int):void		{			_frame = _animation.frame = value;						if(!_animation.isRunning)				_animation.start();		}				/**		 * Brings the animation to the specifed frame and stops it there.		 * 		 * @param	value		A number representing the frame number.		 */		public function gotoAndStop(value:int):void		{			_frame = _animation.frame = value;						if(_animation.isRunning)				_animation.stop();		}				/**		 * Passes an array of animationsequence objects to be added to the animation.		 * 		 * @param	playlist				An array of animationsequence objects.		 * @param	loopLast	[optional]	Determines whether the last sequence will loop. Defaults to false.		 */		public function setPlaySequences(playlist:Array, loopLast:Boolean = false):void		{			if(playlist.length == 0)				return;						if(!_animation)				_animation = new Animation(this); 						_animationgroup = new AnimationGroup();			_animationgroup.loopLast = loopLast;			_animationgroup.playlist = [];						for(var i:int = 0;i<playlist.length;i++ )				_animationgroup.playlist[i] = new AnimationSequence(playlist[i].prefix, playlist[i].smooth, true, playlist[i].fps);			 			if(!_animation.hasEventListener(AnimationEvent.SQUENCE_UPDATE))				_animation.addEventListener(AnimationEvent.SQUENCE_UPDATE, updatePlaySequence);						_animation.sequenceEvent = true;			loop = true;			play(_animationgroup.playlist.shift());		}				/**		 * Default method for adding a squencedone event listener		 * 		 * @param	listener		The listener function		 */		public function addOnSequenceDone(listener:Function):void        {            addEventListener(AnimationEvent.SQUENCE_DONE, listener, false, 0, false);        }				/**		 * Default method for removing a squencedone event listener		 * 		 * @param	listener		The listener function		 */		public function removeOnSequenceDone(listener:Function):void        {            removeEventListener(AnimationEvent.SQUENCE_DONE, listener, false);        }				/**		 * Default method for adding a cycle event listener		 * 		 * @param	listener		The listener function		 */		public function addOnCycle(listener:Function):void        {			_animation.cycleEvent = true;			_cycle = new Event(AnimationEvent.CYCLE);			_animation.addEventListener(AnimationEvent.CYCLE, listener, false, 0, false);        }				/**		 * Default method for removing a cycle event listener		 * 		 * @param	listener		The listener function		 */		public function removeOnCycle(listener:Function):void        {			_animation.cycleEvent = false;            _animation.removeEventListener(AnimationEvent.CYCLE, listener, false);        }				/**		 * Called by the <code>TickTraverser</code>.		 * 		 * updates the animation object		 * 		 * @param	time		The absolute time at the start of the render cycle		 * 		 * @see away3d.core.traverse.TickTraverser		 * @see away3d.core.basr.Animation#update()		 */        public override function tick(time:int):void        {            if ((_animation != null) && (frames != null))                _animation.update(this);        }				/**		 * Scales the vertex positions contained within all animation frames		 * 		 * @param	scale	The scaling value		 */		public function scaleAnimation(scale:Number):void		{			var tmpnames:Array = new Array();			var i:int = 0;			var y:int = 0;			for (var framename:String in framenames){				tmpnames.push(framename);			}							var fr:Frame;			for (i = 0;i<tmpnames.length;i++){				fr = frames[framenames[tmpnames[i]]];				for(y = 0; y<fr.vertexpositions.length ;y++){					fr.vertexpositions[y].x *= scale;					fr.vertexpositions[y].y *= scale;					fr.vertexpositions[y].z *= scale;				}			}						}				/**		 * Plays a sequence of frames		 * 		 * @param	sequence	The animationsequence to play		 */        public function play(sequence:AnimationSequence):void        {			if(!_animation){            	_animation = new Animation(this); 			} else{				_animation.sequence = new Array();			}			            _animation.fps = sequence.fps;            _animation.smooth = sequence.smooth;            _animation.loop = sequence.loop;			            if (sequence.prefix != null){				var bvalidprefix:Boolean;                for (var framename:String in framenames){                    if (framename.indexOf(sequence.prefix) == 0){						bvalidprefix = true;						_activeprefix = (_activeprefix != sequence.prefix)? sequence.prefix : _activeprefix ;                        _animation.sequence.push(new AnimationFrame(framenames[framename], "" + parseInt(framename.substring(sequence.prefix.length))));					}				}								if(bvalidprefix){					_animation.sequence.sortOn("sort", Array.NUMERIC );            					frames[_frame].adjust(1);					_animation.start();					//trace(">>>>>>>> [  start "+activeprefix+"  ]");				} else{					trace("--------- \n--> unable to play animation: unvalid prefix ["+sequence.prefix+"]\n--------- ");				}			}        }    }}                                

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -