包:flare.basic
类:
class |
Description |
The Scene3D class is the main element, container and manager of all the 3d resources and objects. |
|
The Viewer3D class adds basic functionalities to the scene for camera control and easier 3d object viewing. |
Package: flare.basic
Class: public class Scene3D
Inheritance: Scene3D à Pivot3Dà flash.events.EventDispatcher
Subclasses: Viewer3D
The Scene3D class is the main element, container and manager of all the 3d resources and objects.
The Scene3D class also has a Clock3D instance that manages update and render cycles. The update event indicates the need to update scene elements and the render and postRender events allow full control before and after the render process.
Once the scene has been created, use addChild or addChildFromFile to include 3d objects. This will dispatch the progress and complete events to control the loading process for external files.
The scene also creates a Camera3D object to view the scene. The canvas size will take Stage size values by default. To change the rendering area size, use the setViewport method.
Examples:
This example shows the basic creation process of a scene: This example shows how to load external 3d objects into the scene.
import flare.basic.*
// creates the scene.
var scene:Scene3D = new Scene3D( this )
// adds the events to manage the object loading process.
scene.addEventListener( Scene3D.PROGRESS_EVENT, progressEvent )
scene.addEventListener( Scene3D.COMPLETE_EVENT, completeEvent )
// loads 3d models from external files.
scene.addChildFromFile( "myModel1.f3d" )
scene.addChildFromFile( "myModel2.f3d" )
scene.addChildFromFile( "myModel3.f3d" )
function progressEvent( e:Event ):void
{
// shows loading progress (0-100).
trace( scene.loadProgress )
}
function completeEvent( e:Event ):void
{
// once the scene loading process has been completed, elements can be accessed and the scene can be updated.
scene.addEventListener( Scene3D.UPDATE_EVENT, updateEvent )
}
function updateEvent( e:Event ):void
{
// update scene here.
}
Property Detail:
antialias:int
An int selecting anti-aliasing quality. 0 is no anti-aliasing. Correlates to the number of sub-samples; a value of 2 is generally the minimum, although some systems with anti-alias with a value of one. More anti-aliasing is more depanding on the GPU and may impact performance.
Implementation
public function get antialias():int
public function set antialias(value:int):void
autoResize:Boolean
This property forces to the scene to take the stage dimensions when the stage is resized if is setted to true. Also changes the stage.align to topLeft and sets the stage.scaleMode to noScale.
Implementation
public function get autoResize():Boolean
public function set autoResize(value:Boolean):void
camera:Camera3D
Sets or returns the camera to be used for rendering.
Implementation
public function get camera():Camera3D
public function set camera(value:Camera3D):void
public var clearColor:Vector3D
Color to use to clear the back buffer.
context:Context3D [read-only]
Returns the context used for rendering.
Implementation
public function get context():Context3D
public var defaultLight:Light3D
Sets and returns the default light. This light will always be at the same position and orientation as the current camera. You can set to any light type and properties. If you do not want to use the default light, set it to null.
public var enableLights:Boolean = true
Allow the scene to automatically update the light filter. If you don't want that the scene updates the lights automatically, set it to false and you will need to call to updateLights method to update manually.
enableUpdateAndRender:Boolean
Enables or disable the automatic update, render and postRender events of the scene. Seting this property to false will allow you to manage your own update and render loop, calling to those methods manually.
Implementation
public function get enableUpdateAndRender():Boolean
public function set enableUpdateAndRender(value:Boolean):void
frameRate:Number
Gets and sets the frame rate of the 3d scene only for the "update" event. The frame rate is defined as frames per second.
Implementation
public function get frameRate():Number
public function set frameRate(value:Number):void
public var ignoreInvisibleUnderMouse:Boolean = true
Allow to detect mouse events with non visible objects such as references or simplified geometry.
public var library:Library3D
Library3D instance that manages all scene resources.
public var lights:LightFilter
A reference to a LightFilter that manage all scene lights.
loadProgress:Number [read-only]
Gets the global loading process of the scene. The returned value is a percent value between 0 and 100.
Implementation
public function get loadProgress():Number
mouseEnabled:Boolean
Enables or disable all mouse scene events.
Implementation
public function get mouseEnabled():Boolean
public function set mouseEnabled(value:Boolean):void
paused:Boolean [read-only]
Returns 'true' if the scene is paused.
Implementation
public function get paused():Boolean
rendersPerSecond:int [read-only]
Returns the rendering frame rate for statistical purposes.
Implementation
public function get rendersPerSecond():int
renderTime:int [read-only]
Returns time taken to render the scene, including lights, object occlusion, drawing, etc.., in milliseconds. The returned time, does not include the present call.
Implementation
public function get renderTime():int
showMenu:Boolean [write-only]
Shows or hide the Flare3D version on the right click menu. This property should be setted inmediaelly after the scene creation.
Implementation
public function set showMenu(value:Boolean):void
stageIndex:int [read-only]
Gets the associated Stage3D index.
Implementation
public function get stageIndex():int
updatesPerSecond:int [read-only]
Returns the update frame rate for statistical purposes.
Implementation
public function get updatesPerSecond():int
updateTime:int [read-only]
Returns the time taken to update the scene in milliseconds.
Implementation
public function get updateTime():int
viewPort:Rectangle [read-only]
Gets the viewport area associated to the Stage3D.
Implementation
public function get viewPort():Rectangle
Constructor Detail
Scene3D |
() |
Constructor |
public function Scene3D(container:DisplayObjectContainer, file:String)
Create a new Scene3D object.
Parameters
container:DisplayObjectContainer — Object that will serve as container to render the scene. Preferably, it should be an empty MovieClip or Sprite. It must not be rotated or scaled. |
|
file:String — Optional name of the *.f3d file to be loaded into the scene. The file parameter is optional. If null, an empty scene is created. More *.f3d files can be subsequently added using the addChild or addChildFromFile method. |
Method Detail
addChildFromFile |
() |
method |
public function addChildFromFile(file:String, parent:Pivot3D = null, loaderClass:Class = null):Pivot3D
Loads and adds a Flare3D (*.f3d) file from an external file.
Parameters
file:String — File path. |
|
parent:Pivot3D (default = null) — pivot that will serve as container for the objects in the file. If ‘parent’ is null, a container with the name of the file to be added to the scene is created. |
|
loaderClass:Class (default = null) |
Returns
Pivot3D — The Flare3DLoader object that loads the file. The loaded elements will become available only after the “complete” event of the scene. |
addTextureFromFile |
() |
method |
public function addTextureFromFile(file:String, optimizeForRenderToTexture:Boolean = false, format:String = rgba):Texture3D
Loads a texture from an external file.
Parameters
file:String — File path. |
|
optimizeForRenderToTexture:Boolean (default = false) |
|
format:String (default = rgba) |
Returns
Texture3D — The loaded texture. The texture will become available after the “complete” event of the scene. |
getPointScreenCoords |
() |
method |
public function getPointScreenCoords(point:Vector3D, out:Vector3D = null):Vector3D
Returns the coordinates of an arbitrary point respect to the screen. The returned values are relative to the viewPort size that is currently used.
Parameters
point:Vector3D — If a vector is specified, this vector will be filled with the returned values. |
|
out:Vector3D (default = null) |
Returns
Vector3D — The vector with the coordinates. |
pause |
() |
method |
public function pause():void
Pauses the “update” event and starts shooting the “paused” event.
render |
() |
method |
public function render(camera:Camera3D = null, clearDepth:Boolean = false):void
Renders the current scene frame. This method is called by the scene automatically but can force the rendering if necessary or if the scene is paused. This method also will dispatch the scene 'render' event but not the 'postRender' event.
Parameters
camera:Camera3D (default = null) |
|
clearDepth:Boolean (default = false) |
resume |
() |
method |
public function resume():void
Exits pause mode.
setResolution |
() |
method |
public function setResolution(width:uint, height:uint):void
Sets the dimensions of the rendering area.
Parameters
width:uint — Canvas width |
|
height:uint — Canvas height. |
setupFrame |
() |
method |
public function setupFrame(camera:Camera3D = null, aspectRatio:Number):void
This method prepares the scene to be rendered. The render method call to this before render. You should only use this function if you want to draw manually specific objects.
Parameters
camera:Camera3D (default = null) |
|
aspectRatio:Number (default = NaN) |
setViewport |
() |
method |
public function setViewport(x:Number = 0, y:Number = 0, width:Number = 640, height:Number = 480, antialias:int = 0):void
Sets the dimensions of the canvas rendering area.
Parameters
x:Number (default = 0) — left maring of rendering area in pixels. |
|
y:Number (default = 0) — Top maring of rendering area in pixels. |
|
width:Number (default = 640) — Width of rendering area in pixels. |
|
height:Number (default = 480) — Height of rendering area in pixels. |
|
antialias:int (default = 0) — an int selecting anti-aliasing quality. 0 is no anti-aliasing. Correlates to the number of sub-samples; a value of 2 is generally the minimum, although some systems with anti-alias with a value of one. More anti-aliasing is more depanding on the GPU and may impact performance. |
update |
() |
method |
override public function update():void
Forces to update the scene and animations and will dispatch the scene 'update' event.
updateLights |
() |
method |
public function updateLights():void
Force to update the light fitler. This method is called automatically by the scene when the enableLights property is seted to true.
updateMouseEvents |
() |
method |
public function updateMouseEvents():void
This method forces to update mouse events for all 3D objects in the scene.
updateRenderList |
() |
method |
public function updateRenderList():void
Force to update the internal scene render list.
Event Detail
complete |
Event |
Event Object Type: flash.events.Event
Event.type property = flash.events.Event
This event occurs once the loading process of all the scene elements has been completed.
ioError |
Event |
Event Object Type: flash.events.IOErrorEvent
IOErrorEvent.type property = flash.events.IOErrorEvent.IO_ERROR
Dispatched if a call to load() results in a fatal error that terminates the download.
postRender |
Event |
Event Object Type: flash.events.Event
Event.type property = flash.events.Event
This event occurs after rendering the scene.
progress |
Event |
Event Object Type: flash.events.ProgressEvent
ProgressEvent.type property = flash.events.Event
This event occurs whenever the loading progress of the elements of a scene is modified.
render |
Event |
Event Object Type: flash.events.Event
Event.type property = flash.events.Event
This event occurs before rendering the scene.
update |
Event |
Event Object Type: flash.events.Event
Event.type property = flash.events.Event
This event occurs whenever the program must be updated. This event is synchronized with the frames-per-second rate defined in Device3D and bit rate is constant.
updateRenderList |
Event |
Event Object Type: flash.events.Event
Event.type property = flash.events.Event
This event occurs whenever the program must update the render list order.
Constant Detail
COMPLETE_EVENT |
Constant |
public static const COMPLETE_EVENT:String = complete
Defines the value for the “complete” event.
PAUSED_EVENT |
Constant |
public static const PAUSED_EVENT:String = paused
Defines the value for the “paused” event.
POSTRENDER_EVENT |
Constant |
public static const POSTRENDER_EVENT:String = postRender
Defines the value for the “postRender” event.
PROGRESS_EVENT |
Constant |
public static const PROGRESS_EVENT:String = progress
Defines the value for the “progress” event.
RENDER_EVENT |
Constant |
public static const RENDER_EVENT:String = render
Defines the value for the “render” event.
UPDATE_EVENT |
Constant |
public static const UPDATE_EVENT:String = update
Defines the value for the update” event.
Viewer3D
Package: |
|
Class: |
public class Viewer3D |
Inheritance |
The Viewer3D class adds basic functionalities to the scene for camera control and easier 3d object viewing.