📄 displayobject3d.as
字号:
package org.papervision3d.objects{ import org.papervision3d.Papervision3D; import org.papervision3d.core.culling.FrustumTestMethod; import org.papervision3d.core.culling.IObjectCuller; import org.papervision3d.core.data.UserData; import org.papervision3d.core.math.Matrix3D; import org.papervision3d.core.math.Number3D; import org.papervision3d.core.math.Quaternion; import org.papervision3d.core.ns.pv3dview; import org.papervision3d.core.proto.CameraObject3D; import org.papervision3d.core.proto.DisplayObjectContainer3D; import org.papervision3d.core.proto.GeometryObject3D; import org.papervision3d.core.proto.MaterialObject3D; import org.papervision3d.core.proto.SceneObject3D; import org.papervision3d.core.render.data.RenderSessionData; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.view.layer.ViewportLayer; /** * The DisplayObject class represents instances of 3D objects that are contained in the scene. * <p/> * That includes all objects in the scene, not only those that can be rendered, but also the camera and its target. * <p/> * The DisplayObject3D class supports basic functionality like the x, y and z position of an object, as well as rotationX, rotationY, rotationZ, scaleX, scaleY and scaleZ and visible. It also supports more advanced properties of the object such as its transform Matrix3D. * <p/> * <p/> * DisplayObject3D is not an abstract base class; therefore, you can call DisplayObject3D directly. Invoking new DisplayObject() creates a new empty object in 3D space, like when you used createEmptyMovieClip(). * */ public class DisplayObject3D extends DisplayObjectContainer3D { private static var _tempMatrix :Matrix3D = Matrix3D.IDENTITY; private static var _tempQuat :Quaternion = new Quaternion(); private static var _totalDisplayObjects :int = 0; private static var toDEGREES :Number = 180/Math.PI; private static var toRADIANS :Number = Math.PI/180; /** * [internal-use] */ protected var _transformDirty :Boolean = false; private var _rotationX :Number; private var _rotationY :Number; private var _rotationZ :Number; /** * pre-made Number3Ds and Matrix3Ds for use in the lookAt function * and others * */ private var position : Number3D = Number3D.ZERO; private var target : Number3D = Number3D.ZERO; private var zAxis : Number3D = Number3D.ZERO; private var xAxis : Number3D = Number3D.ZERO; private var yAxis : Number3D = Number3D.ZERO; private var _rotation :Number3D = Number3D.ZERO; private var _rotationDirty :Boolean = false; private var _scaleX :Number; private var _scaleY :Number; private var _scaleZ :Number; private var _scaleDirty :Boolean = false; private var _numClones :uint = 0; protected var _sorted :Array; protected var _useOwnContainer:Boolean; protected var _containerSortMode:int; protected var _containerBlendMode:int; protected var _filters:Array; protected var _userData:UserData; private var _material:MaterialObject3D; /** * Defines how the object should be frustum-checked. */ public var frustumTestMethod:int = FrustumTestMethod.BOUNDING_SPHERE; /** * An Number that sets the X coordinate of a object relative to the origin of its parent. */ public function get x():Number { return this.transform.n14; } public function set x( value:Number ):void { this.transform.n14 = value; } /** * An Number that sets the Y coordinate of a object relative to the origin of its parent. */ public function get y():Number { return this.transform.n24; } public function set y( value:Number ):void { this.transform.n24 = value; } /** * An Number that sets the Z coordinate of a object relative to the origin of its parent. */ public function get z():Number { return this.transform.n34; } public function set z( value:Number ):void { this.transform.n34 = value; } /** * Specifies the rotation around the X axis from its original orientation. */ public function get rotationX():Number { if( this._rotationDirty ) updateRotation(); return Papervision3D.useDEGREES? -this._rotationX * toDEGREES : -this._rotationX; } public function set rotationX( rot:Number ):void { this._rotationX = Papervision3D.useDEGREES? -rot * toRADIANS : -rot; this._transformDirty = true; } /** * Specifies the rotation around the Y axis from its original orientation. */ public function get rotationY():Number { if( this._rotationDirty ) updateRotation(); return Papervision3D.useDEGREES? -this._rotationY * toDEGREES : -this._rotationY; } public function set rotationY( rot:Number ):void { this._rotationY = Papervision3D.useDEGREES? -rot * toRADIANS : -rot; this._transformDirty = true; } /** * Specifies the rotation around the Z axis from its original orientation. */ public function get rotationZ():Number { if( this._rotationDirty ) updateRotation(); return Papervision3D.useDEGREES? -this._rotationZ * toDEGREES : -this._rotationZ; } public function set rotationZ( rot:Number ):void { this._rotationZ = Papervision3D.useDEGREES? -rot * toRADIANS : -rot; this._transformDirty = true; } // Update rotation values private function updateRotation():void { _rotation = Matrix3D.matrix2euler( this.transform, _rotation); this._rotationX = _rotation.x * toRADIANS; this._rotationY = _rotation.y * toRADIANS; this._rotationZ = _rotation.z * toRADIANS; this._rotationDirty = false; } // ___________________________________________________________________ S C A L E /** * Sets the 3D scale as applied from the registration point of the object. */ public function get scale():Number { if( this._scaleX == this._scaleY && this._scaleX == this._scaleZ ) if( Papervision3D.usePERCENT ) return this._scaleX * 100; else return this._scaleX; else return NaN; } public function set scale( scale:Number ):void { if( Papervision3D.usePERCENT ) scale /= 100; this._scaleX = this._scaleY = this._scaleZ = scale; this._transformDirty = true; } /** * Sets the scale along the local X axis as applied from the registration point of the object. */ public function get scaleX():Number { if( Papervision3D.usePERCENT ) return this._scaleX * 100; else return this._scaleX; } public function set scaleX( scale:Number ):void { if( Papervision3D.usePERCENT ) this._scaleX = scale / 100; else this._scaleX = scale; this._transformDirty = true; } /** * Sets the scale along the local Y axis as applied from the registration point of the object. */ public function get scaleY():Number { if( Papervision3D.usePERCENT ) return this._scaleY * 100; else return this._scaleY; } public function set scaleY( scale:Number ):void { if( Papervision3D.usePERCENT ) this._scaleY = scale / 100; else this._scaleY = scale; this._transformDirty = true; } /** * Sets the scale along the local Z axis as applied from the registration point of the object. */ public function get scaleZ():Number { if( Papervision3D.usePERCENT ) return this._scaleZ * 100; else return this._scaleZ; } public function set scaleZ( scale:Number ):void { if( Papervision3D.usePERCENT ) this._scaleZ = scale / 100; else this._scaleZ = scale; this._transformDirty = true; } /** * The X coordinate of a object relative to the scene coordinate system. */ public function get sceneX():Number { return this.world.n14; } /** * The Y coordinate of a object relative to the scene coordinate system. */ public function get sceneY():Number { return this.world.n24; } /** * The Z coordinate of a object relative to the scene coordinate system. */ public function get sceneZ():Number { return this.world.n34; } /** * [read-only] The coordinate of the object on screen. */ public var screen :Number3D = new Number3D(); /** * Whether or not the display object is visible. * <p/> * A Boolean value that indicates whether the object is projected, transformed and rendered. A value of false will effectively ignore the object. The default value is true. */ public var visible :Boolean; /** * An optional object name. */ public var name :String; /** * [read-only] Unique id of this instance. */ public var id :int; /** * An object that contains user defined properties. * <p/> * All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available. */ public var extra :Object; // = {}; TBD /** * The default material for the object instance. Materials collect data about how objects appear when rendered. */ public function set material(material:MaterialObject3D):void { if(_material){ _material.unregisterObject(this); } _material = material; _material.registerObject(this); } public function get material():MaterialObject3D { return _material; } /** * The list of materials for this instance. */ public var materials :MaterialsList; /** * The scene where the object belongs. */ protected var _scene :SceneObject3D = null; private static var entry_count:uint = 0; public function set scene(p_scene:SceneObject3D):void { // set scene property _scene = p_scene; for each( var child:DisplayObject3D in this._childrenByName ) { if(child.scene == null) child.scene = _scene; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -