📄 displayobject3d.as
字号:
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org • blog.papervision3d.org • osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.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.
*/
// _______________________________________________________________________ DisplayObject3D
package org.papervision3d.objects
{
import com.blitzagency.xray.logger.XrayLog;
import flash.display.Sprite;
import flash.geom.Matrix;
import flash.utils.Dictionary;
import org.papervision3d.Papervision3D;
import org.papervision3d.core.Matrix3D;
import org.papervision3d.core.Number3D;
import org.papervision3d.core.geom.Face3DInstance;
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.materials.MaterialsList;
import org.papervision3d.scenes.InteractiveScene3D;
import org.papervision3d.utils.InteractiveSceneManager;
import org.papervision3d.utils.InteractiveSprite;
/**
* 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
{
// ___________________________________________________________________ P O S I T I O N
/**
* 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;
}
// ___________________________________________________________________ R O T A T I O N
/**
* 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
{
var rot:Number3D = Matrix3D.matrix2euler( this.transform );
this._rotationX = rot.x * toRADIANS;
this._rotationY = rot.y * toRADIANS;
this._rotationZ = rot.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;
}
// ___________________________________________________________________ W O R L D
/**
* 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;
}
// ___________________________________________________________________ S C R E E N
/**
* [read-only] The coordinate of the object on screen.
*/
public var screen :Number3D = new Number3D();
// ___________________________________________________________________ P R O P E R T I E S
/**
* 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 Sprite that you draw into when rendering in a MovieScene3D.
*
* While Scene3D uses a single Sprite container for all the objects, MovieScene3D renders each object in its own unique Sprite.
*
* You can use the container like any other Sprite. For example, you can add events to it, apply filters or change the blend mode.
*/
public var container :Sprite;
/**
* The default material for the object instance. Materials collect data about how objects appear when rendered.
*/
public var material :MaterialObject3D;
/**
* The list of materials for this instance.
*/
public var materials :MaterialsList;
/**
* If an InteractiveScene3D is used, this will DisplayObject3D will be registered with the InteractiveSceneManager
*/
public var interactiveSceneManager:InteractiveSceneManager;
/**
* The scene where the object belongs.
*/
protected var _scene :SceneObject3D = null;
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;
}
// if this is NOT an interactiveScene3D, just return
if(_scene is InteractiveScene3D == false) return;
// if we have an InteractiveScene3D, register this and the children to add them to the InteractiveSceneManager
interactiveSceneManager = InteractiveScene3D(_scene).interactiveSceneManager;
}
public function get scene():SceneObject3D { return _scene; }
/**
* [read-only] Indicates the DisplayObjectContainer3D object that contains this display object.
*/
public var parent :DisplayObjectContainer3D;
/**
* tells Mesh3D's render() method to sort by measuring from the center of a triangle
*/
public static const MESH_SORT_CENTER:uint = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -