📄 basemesh.as
字号:
package away3d.core.base{ import away3d.core.*; import away3d.core.draw.*; import away3d.core.render.*; import away3d.core.utils.*; import away3d.events.*; import away3d.materials.*; import flash.events.Event; import flash.utils.*; /** * Dispatched when the animation object completes all frame sequences. * * @eventType away3d.events.AnimationEvent */ [Event(name="sequencedone",type="away3d.events.AnimationEvent")] /** * Dispatched when the animation object completes a single sequence cycle. * * @eventType away3d.events.AnimationEvent */ [Event(name="cycle",type="away3d.events.AnimationEvent")] /** * Abstract 3d object containing unspecified elements. * Not intended for direct use - use <code>Mesh</code> or <code>WireMesh</code>. */ public class BaseMesh extends Object3D { use namespace arcane; /** @private */ arcane function createDrawSegment(material:ISegmentMaterial, projection:Projection, v0:ScreenVertex, v1:ScreenVertex):DrawSegment { if (_dsStore.length) { _dsActive.push(_seg = _dsStore.pop()); _seg.create = createDrawSegment; } else { _dsActive.push(_seg = new DrawSegment()); _seg.source = this; _seg.create = createDrawSegment; } _seg.material = material; _seg.projection = projection; _seg.v0 = v0; _seg.v1 = v1; _seg.calc(); return _seg; } private var _vertices:Array; private var _verticesDirty:Boolean = true; private var _boundingRadiusElement:IMeshElement = null; private var _boundingRadiusDirty:Boolean = false; private var _boundingRadius:Number = 0; private var _maxXElement:IMeshElement = null; private var _maxXDirty:Boolean = false; private var _maxX:Number = -Infinity; private var _minXElement:IMeshElement = null; private var _minXDirty:Boolean = false; private var _minX:Number = Infinity; private var _maxYElement:IMeshElement = null; private var _maxYDirty:Boolean = false; private var _maxY:Number = -Infinity; private var _minYElement:IMeshElement = null; private var _minYDirty:Boolean = false; private var _minY:Number = Infinity; private var _maxZElement:IMeshElement = null; private var _maxZDirty:Boolean = false; private var _maxZ:Number = -Infinity; private var _minZElement:IMeshElement = null; private var _minZDirty:Boolean = false; private var _minZ:Number = Infinity; private var _needNotifyRadiusChange:Boolean = false; private var _needNotifyDimensionsChange:Boolean = false; private var _frame:int; private var _animation:Animation; private var _animationgroup:AnimationGroup; private var _sequencedone:Event; private var _cycle:Event; private var _activeprefix:String; private var _seg:DrawSegment; private var _dsStore:Array = new Array(); private var _dsActive:Array = new Array(); private function launchNotifies():void { if (_needNotifyRadiusChange) { _needNotifyRadiusChange = false; notifyRadiusChange(); } if (_needNotifyDimensionsChange) { _needNotifyDimensionsChange = false; notifyDimensionsChange(); } } private function rememberElementRadius(element:IMeshElement):void { var r2:Number = element.radius2; if (r2 > _boundingRadius*_boundingRadius) { _boundingRadius = Math.sqrt(r2); _boundingRadiusElement = element; _boundingRadiusDirty = false; _needNotifyRadiusChange = true; } var mxX:Number = element.maxX; if (mxX > _maxX) { _maxX = mxX; _maxXElement = element; _maxXDirty = false; _needNotifyDimensionsChange = true; } var mnX:Number = element.minX; if (mnX < _minX) { _minX = mnX; _minXElement = element; _minXDirty = false; _needNotifyDimensionsChange = true; } var mxY:Number = element.maxY; if (mxY > _maxY) { _maxY = mxY; _maxYElement = element; _maxYDirty = false; _needNotifyDimensionsChange = true; } var mnY:Number = element.minY; if (mnY < _minY) { _minY = mnY; _minYElement = element; _minYDirty = false; _needNotifyDimensionsChange = true; } var mxZ:Number = element.maxZ; if (mxZ > _maxZ) { _maxZ = mxZ; _maxZElement = element; _maxZDirty = false; _needNotifyDimensionsChange = true; } var mnZ:Number = element.minZ; if (mnZ < _minZ) { _minZ = mnZ; _minZElement = element; _minZDirty = false; _needNotifyDimensionsChange = true; } } private function forgetElementRadius(element:IMeshElement):void { if (element == _boundingRadiusElement) { _boundingRadiusElement = null; _boundingRadiusDirty = true; _needNotifyRadiusChange = true; } if (element == _maxXElement) { _maxXElement = null; _maxXDirty = true; _needNotifyDimensionsChange = true; } if (element == _minXElement) { _minXElement = null; _minXDirty = true; _needNotifyDimensionsChange = true; } if (element == _maxYElement) { _maxYElement = null; _maxYDirty = true; _needNotifyDimensionsChange = true; } if (element == _minYElement) { _minYElement = null; _minYDirty = true; _needNotifyDimensionsChange = true; } if (element == _maxZElement) { _maxZElement = null; _maxZDirty = true; _needNotifyDimensionsChange = true; } if (element == _minZElement) { _minZElement = null; _minZDirty = true; _needNotifyDimensionsChange = true; } } private function onElementVertexChange(event:MeshElementEvent):void { var element:IMeshElement = event.element; forgetElementRadius(element); rememberElementRadius(element); _verticesDirty = true; launchNotifies(); } private function onElementVertexValueChange(event:MeshElementEvent):void { var element:IMeshElement = event.element; forgetElementRadius(element); rememberElementRadius(element); launchNotifies(); } /* private function clear():void { throw new Error("Not implemented"); } */ private function updatePlaySequence(e:Event):void { if(_animationgroup.playlist.length == 0 ){ _animation.removeEventListener(AnimationEvent.SQUENCE_UPDATE, updatePlaySequence); _animation.sequenceEvent = false; if (hasSequenceEvent) { if (_sequencedone == null) _sequencedone = new Event(AnimationEvent.SQUENCE_DONE); dispatchEvent(_sequencedone); } } else{ if(_animationgroup.playlist.length == 1 ) loop = _animationgroup.loopLast; play(_animationgroup.playlist.shift()); } } /** * Scales the contents of the mesh using 3 axis values. * * @param scaleX The scaling value along the x-axis * @param scaleY The scaling value along the y-axis * @param scaleZ The scaling value along the z-axis */ protected function scaleXYZ(scaleX:Number, scaleY:Number, scaleZ:Number):void { for each (var vertex:Vertex in vertices) { vertex.x *= scaleX; vertex.y *= scaleY; vertex.z *= scaleZ; } } /** * Adds an element to the mesh object. * * @param element The element to be added to the mesh. */ protected function addElement(element:IMeshElement):void { _verticesDirty = true; element.addOnVertexChange(onElementVertexChange); element.addOnVertexValueChange(onElementVertexValueChange); rememberElementRadius(element); launchNotifies(); } /** * Removes an element to the mesh object. * * @param element The element to be removed from the mesh. */ protected function removeElement(element:IMeshElement):void { forgetElementRadius(element); element.removeOnVertexValueChange(onElementVertexValueChange); element.removeOnVertexChange(onElementVertexChange); _verticesDirty = true; launchNotifies(); } /** * A dictionary containing all frames of the mesh */ public var frames:Dictionary; /** * A dictionary containing all frame names of the mesh */ public var framenames:Dictionary; /** * Elements use their furthest point from the camera when z-sorting */ public var pushback:Boolean; /** * Elements use their nearest point to the camera when z-sorting */ public var pushfront:Boolean; /** * String defining the source of the mesh. * * If the mesh has been created internally, the string is used to display the package name of the creating object. * Used to display information in the stats panel * * @see away3d.core.stats.Stats */ public var url:String; /** * String defining the type of class used to generate the mesh. * Used to display information in the stats panel * * @see away3d.core.stats.Stats */ public var type:String; /** * Returns an array of the elements contained in the mesh object * * @throws Error Not implemented */ public function get elements():Array { throw new Error("Not implemented"); } /** * Returns an array of the vertices contained in the mesh object */ public function get vertices():Array { if (_verticesDirty) { _vertices = []; var processed:Dictionary = new Dictionary(); for each (var element:IMeshElement in elements) for each (var vertex:Vertex in element.vertices) if (!processed[vertex]) { _vertices.push(vertex); processed[vertex] = true; } _verticesDirty = false; } return _vertices; } /** * @inheritDoc */ public override function get boundingRadius():Number { if (_boundingRadiusDirty) { _boundingRadiusElement = null; var mr:Number = 0; for each (var element:IMeshElement in elements) { var r2:Number = element.radius2; if (r2 > mr) { mr = r2; _boundingRadiusElement = element; } } _boundingRadius = Math.sqrt(mr); _boundingRadiusDirty = false; } return _boundingRadius; } /** * @inheritDoc */ public override function get maxX():Number { if (_maxXDirty) { _maxXElement = null; var extrval:Number = -Infinity; for each (var element:IMeshElement in elements) { var val:Number = element.maxX; if (val > extrval) { extrval = val; _maxXElement = element; } } _maxX = extrval; _maxXDirty = false; } return _maxX; } /** * @inheritDoc */ public override function get minX():Number {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -