API Docs for: 1.0.0

CardboardEffect

Extends Entity
Module: effects
Parent Module: xeogl

A CardboardEffect sets up a stereo view for its Scene.

Overview

Examples

Usage

Stereo view of an Entity using the Scene's default Camera and Viewport:

// Both the Entity and the CardboardEffect use their Scene's default Camera and Viewport

var entity = new xeogl.Entity({
    geometry: new xeogl.TorusGeometry()
});

var CardboardEffect = new xeogl.CardboardEffect({
    fov: 45, // Default
    active: true // Default
});

Stereo view of an Entity using a custom Camera and Viewport:

var camera = new xeogl.Camera({
    view: new xeogl.Lookat({
        eye: [0, 0, 10],
        look: [0, 0, 0],
        up: [0, 1, 0]
    }),
    project: new xeogl.Frustum()
});

var viewport = new xeogl.Viewport();

var entity = new xeogl.Entity({
    camera: camera,
    viewport: viewport,
    geometry: new xeogl.TorusGeometry()
});

var CardboardEffect = new xeogl.CardboardEffect({
    camera: camera,
    viewport: viewport,
    fov: 45, // Default
    active: true // Default
});

Constructor

CardboardEffect

(
  • [scene]
  • [cfg]
)

Parameters:

  • [scene] Scene optional

    Parent Scene - creates this CardboardEffect in the default Scene when omitted.

  • [cfg] optional

    Configs

    • [id] String optional

      Optional ID, unique among all components in the parent Scene, generated automatically when omitted.

    • [meta] String:Object optional

      Optional map of user-defined metadata to attach to this CardboardEffect.

    • [camera] String | Camera optional

      ID or instance of a Camera for this CardboardEffect. Must be within the same Scene as this CardboardEffect. Defaults to the parent Scene's default instance, camera.

    • [viewport] String | Viewport optional

      ID or instance of a Viewport for this CardboardEffect. Must be within the same Scene as this CardboardEffect. Defaults to the parent Scene's default instance, viewport.

    • [fov=45] optional

      fov angle in degrees.

    • [active=true] Boolean optional

      Whether or not this CardboardEffect is active.

Methods

create

(
  • [cfg]
  • [instanceId]
)

Convenience method for creating a Component within this Component's Scene.

You would typically use this method to conveniently instantiate components that you'd want to share (ie. "instance") among your Entities.

The method is given a component type, configuration and optional instance ID, like so:

var material = myComponent.create({
     type: "xeogl.PhongMaterial",
     diffuse: [1,0,0],
     specular: [1,1,0]
}, "myMaterial");

The first time you call this method for the given type and instanceId, this method will create the PhongMaterial, passing the given attributes to the component's constructor.

If you call this method again, specifying the same type and instanceId, the method will return the same component instance that it returned the first time, and will ignore the new configuration:

var material2 = component.create({ type: "xeogl.PhongMaterial", specular: [1,1,0] }, "myMaterial");

So in this example, our PhongMaterial will continue to have the red specular and diffuse color that we specified the first time.

Each time you call this method with the same type and instanceId, the Scene will internally increment a reference count for the component instance.

Parameters:

  • [cfg] optional

    Configuration for the component instance - only used if this is the first time you are getting the component, ignored when reusing an existing instance.

  • [instanceId] String | Number optional

    Identifies the shared component instance. Note that this is not used as the ID of the component - you can specify the component ID in the cfg parameter.

Returns:

:

destroy

()

Destroys this component.

Fires a destroyed event on this Component.

Automatically disassociates this component from other components, causing them to fall back on any defaults that this component overrode on them.

TODO: describe effect with respect to #create

error

(
  • message
)

Logs an error for this component to the JavaScript console.

The console message will have this format: [ERROR] [<component type> =<component id>: <message>

Also fires the message as an error event on the parent Scene.

Parameters:

  • message String

    The message to log

fire

(
  • event
  • value
  • [forget=false]
)

Fires an event on this component.

Notifies existing subscribers to the event, optionally retains the event to give to any subsequent notifications on the event as they are made.

Parameters:

  • event String

    The event type name

  • value Object

    The event parameters

  • [forget=false] Boolean optional

    When true, does not retain for subsequent subscribers

isType

(
  • type
)
Boolean

Tests if this component is of the given type, or is a subclass of the given type.

The type may be given as either a string or a component constructor.

This method works by walking up the inheritance type chain, which this component provides in property superTypes, returning true as soon as one of the type strings in the chain matches the given type, of false if none match.

Examples:

var myRotate = new xeogl.Rotate({ ... });

myRotate.isType(xeogl.Component); // Returns true for all xeogl components
myRotate.isType("xeogl.Component"); // Returns true for all xeogl components
myRotate.isType(xeogl.Rotate); // Returns true
myRotate.isType(xeogl.Transform); // Returns true
myRotate.isType("xeogl.Transform"); // Returns true
myRotate.isType(xeogl.Entity); // Returns false, because xeogl.Rotate does not (even indirectly) extend xeogl.Entity

Parameters:

  • type String | Function

    Component type to compare with, eg "xeogl.PhongMaterial", or a xeogl component constructor.

Returns:

Boolean:

True if this component is of given type or is subclass of the given type.

log

(
  • message
)

Logs a console debugging message for this component.

The console message will have this format: [LOG] [<component type> <component id>: <message>

Also fires the message as a log event on the parent Scene.

Parameters:

  • message String

    The message to log

off

(
  • handle
)

Cancels an event subscription that was previously made with on or once.

Parameters:

  • handle String

    Publication handle

on

(
  • event
  • callback
  • [scope=this]
)
String

Subscribes to an event on this component.

The callback is be called with this component as scope.

Parameters:

  • event String

    The event

  • callback Function

    Called fired on the event

  • [scope=this] Object optional

    Scope for the callback

Returns:

String:

Handle to the subscription, which may be used to unsubscribe with {@link #off}.

once

(
  • event
  • callback
  • [scope=this]
)

Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is handled.

This is equivalent to calling on, and then calling off inside the callback function.

Parameters:

  • event String

    Data event to listen to

  • callback Function(data)

    Called when fresh data is available at the event

  • [scope=this] Object optional

    Scope for the callback

warn

(
  • message
)

Logs a warning for this component to the JavaScript console.

The console message will have this format: [WARN] [<component type> =<component id>: <message>

Also fires the message as a warn event on the parent Scene.

Parameters:

  • message String

    The message to log

Properties

active

Boolean

Flag which indicates whether this CardboardEffect is active or not.

Fires an active event on change.

Default: true

billboard

String

Specifies the billboarding behaviour for this Entity.

Options are:

  • "none" - (default) - No billboarding.
  • "spherical" - Entity is billboarded to face the viewpoint, rotating both vertically and horizontally.
  • "cylindrical" - Entity is billboarded to face the viewpoint, rotating only about its vertically axis. Use this mode for things like trees on a landscape.

Fires an billboard event on change.

Default: "none"

camera

Camera

Inherited from Entity but overwritten in examples/js/effects/cardboardEffect.js:99

The Camera attached to this CardboardEffect.

This CardboardEffect will attach a Frustum to its Camera if the Camera does not have one already, replacing the projection transform component that was already attached.

Must be within the same Scene as this CardboardEffect. Defaults to the parent Scene's default camera when set to a null or undefined value.

canvasBoundary

Boundary2D final

Canvas-space 2D boundary.

This is a Boundary2D that encloses this Entity's geometry after transformation by this Entity's modelling transform and Camera view and projection transforms.

The Boundary2D will fire an updated event whenever there are any changes to the Geometry, transform or Camera that would affect its extents.

The a Boundary2D is lazy-instantiated the first time that this property is referenced. If destroy is then called on it, then this property will be assigned to a fresh Boundary2D instance next time it's referenced.

Performance

To minimize performance overhead, only reference this property if you need it, and destroy the Boundary2D as soon as you don't need it anymore.

castShadow

Boolean

Indicates whether this Entity casts shadows.

Fires a castShadow event on change.

Default: true

clippable

Boolean

Indicates whether this Entity is clippable by Clips components.

Fires a clippable event on change.

Default: true

clips

Clips

The Clips attached to this Entity.

Must be within the same Scene as this Entity. Defaults to the parent Scene's default clips when set to a null or undefined value.

Fires an clips event on change.

collidable

Boolean

Indicates whether this Entity is included in boundary calculations.

Set this false if the Entity is a helper or indicator that should not be included in boundary calculations.

For example, when set false, the World-space boundary of all attached Entities would not be considered when calculating the World-space boundary of their Scene.

Fires a collidable event on change.

Default: true

culled

Boolean

Indicates whether or not this Entity is currently culled from view.

The Entity is only rendered when visible is true and culled is false.

Fires a culled event on change.

Default: false

destroyed

Boolean

True as soon as this Component has been destroyed

fov

Number

fov angle in degrees.

Fires an fov event on change.

Default: 45

geometry

Geometry

The Geometry attached to this Entity.

Must be within the same Scene as this Entity. Defaults to the parent Scene's default geometry (a simple box) when set to a null or undefined value.

Fires an geometry event on change.

Updates Entity/boundary, Entity/worldObb and Entity/center

glsl

JSON final

JSON object containing the (GLSL) source code of the shaders for this Entity.

This is sometimes useful to have as a reference when constructing your own custom Shader components.

Will return null if xeogl has not yet rendered this Entity.

glslString

String final

The (GLSL) source code of the shaders for this Entity, as a string.

This is sometimes useful to have as a reference when constructing your own custom Shader components.

Will return null if xeogl has not yet rendered this Entity.

id

String final

Unique ID for this Component within its parent Scene.

isDefault

Boolean

Indicates whether this is one of the Scene's built-in Components.

json

JSON final

JSON object containing the state of this Component.

layer

Number

Indicates this Entity's rendering order.

This can be set on multiple transparent Entities, to make them render in a specific order
for correct alpha blending.

Fires a Layer/layer:event event on change.

Default: 0

lights

Lights

The Lights attached to this Entity.

Must be within the same Scene as this Entity. Defaults to the parent Scene's default lights when set to a null or undefined value.

Fires an lights event on change.

localBoundary

Boundary3D final

Local-space 3D boundary of this Entity.

This is a Boundary3D that encloses the Geometry that is attached to this Entity.

The Boundary3D will fire an updated event whenever this Entity's geometry is linked to a new Geometry, or whenever the Geometry's positions are updated.

The a Boundary3D is lazy-instantiated the first time that this property is referenced. If destroy is then called on it, then this property will be assigned to a fresh Boundary3D instance next time it's referenced.

material

Material

The Material attached to this Entity.

Must be within the same Scene as this Entity. Defaults to the parent Scene's default material when set to a null or undefined value.

Fires an material event on change.

metadata

Object

Arbitrary, user-defined metadata on this component.

morphTargets

MorphTargets private

The MorphTargets attached to this Entity.

Must be within the same Scene as this Entity. Defaults to the parent Scene's default morphTargets when set to a null or undefined value.

Fires an morphTargets event on change.

outline

Outline

The Outline effect attached to this Entity.

Must be within the same Scene as this Entity. Defaults to the parent Scene's default Outline when set to a null or undefined value.

Fires an Entity/outline:event event on change.

outlined

Boolean

Indicates whether this Entity is rendered with an outline.

The outline effect is configured via the Entity's outline component.

Fires a outlined event on change.

Default: false

pickable

Boolean

Indicates whether this entity is pickable or not.

Picking is done via calls to Canvas/pick:method.

Fires a pickable event on change.

Default: true

receiveShadow

Boolean

Indicates whether this Entity receives shadows.

Fires a receiveShadow event on change.

Default: true

scene

Scene final

The parent Scene that contains this Component.

stationary

Boolean

Flag which indicates whether this Entity is stationary or not.

Setting this true will disable the effect of view transform translations for this Entity, while still alowing it to rotate. This is useful for skybox Entities.

Fires an stationary event on change.

Default: false

string

String final

Inherited from Component but overwritten in src/component.js:1055

String containing the serialized JSON state of this Component.

superTypes

Array of String final

An array of strings that indicates the chain of super-types within this component's inheritance hierarchy.

For example, if this component is a Rotate, which extends Transform, which in turn extends Component, then this property will have the value:

["xeogl.Component", "xeogl.Transform"]
                    

Note that the chain is ordered downwards in the hierarchy, ie. from super-class down towards sub-class.

transform

Transform

The Local-to-World-space (modelling) Transform attached to this Entity.

Must be within the same Scene as this Entity. Defaults to the parent Scene's default transform (an identity matrix) when set to a null or undefined value.

Fires an transform event on change.

Updates Entity/boundary, Entity/worldObb and Entity/center

type

String final

JavaScript class name for this Component.

This is used when loading Scenes from JSON, and is included in the JSON representation of this Component, so that this class may be instantiated when loading it from the JSON representation.

For example: "xeogl.AmbientLight", "xeogl.ColorTarget", "xeogl.Lights" etc.

viewBoundary

Boundary3D final

View-space 3D boundary of this Entity.

This is a Boundary3D that encloses the Geometry that is attached to this Entity after transformation by this Entity's modelling transform and Camera view transform.

The Boundary3D will fire an updated event whenever there are any changes to the Geometry, transform or Camera that would affect its extents.

The a Boundary3D is lazy-instantiated the first time that this property is referenced. If destroy is then called on it, then this property will be assigned to a fresh Boundary3D instance next time it's referenced.

Performance

To minimize performance overhead, only reference this property if you need it, and destroy the Boundary3D as soon as you don't need it anymore.

Viewport

Viewport

The Viewport attached to this CardboardEffect.

Must be within the same Scene as this CardboardEffect. Defaults to the parent Scene's default Viewport when set to a null or undefined value.

viewport

Viewport

The Viewport attached to this Entity.

Must be within the same Scene as this Entity. When set to a null or undefined value, defaults to the parent Scene's default viewport, which automatically resizes to the canvas.

Fires an viewport event on change.

visible

Boolean

Indicates whether this Entity is visible or not.

The Entity is only rendered when visible is true and culled is false.

Fires a visible event on change.

Default: true

worldBoundary

Boundary3D final

World-space 3D boundary of this Entity.

This is a Boundary3D that encloses the Geometry that is attached to this Entity after transformation by this Entity's modelling transform.

The Boundary3D will fire an updated event whenever this Entity's geometry is linked to a new Geometry, or whenever the Geometry's positions are updated.

The a Boundary3D is lazy-instantiated the first time that this property is referenced. If destroy is then called on it, then this property will be assigned to a fresh Boundary3D instance next time it's referenced.

Example

here

Performance

To minimize performance overhead, only reference this property if you need it, and destroy the Boundary3D as soon as you don't need it anymore.

worpdPositions

Float32Array final

World-space vertex positions of this Entity.

These are internally generated on-demand and cached. To free the cached vertex World positions when you're done with them, set this property to null or undefined.

xray

XRay

The XRay effect attached to this Entity.

Must be within the same Scene as this Entity. Defaults to the parent Scene's default XRay when set to a null or undefined value.

Fires an Entity/xray:event event on change.

xrayed

Boolean

Indicates whether this Entity is rendered X-rayed (transparent).

The X-ray effect is configured via the Entity's outline component.

Fires a xrayed event on change.

Default: false

Events

active

Fired whenever this CardboardEffect's active property changes.

Event Payload:

  • value Object

    The property's new value

billboard

Fired whenever this Entity's billboard property changes.

Event Payload:

  • value Object

    The property's new value

camera

Inherited from Entity but overwritten in examples/js/effects/cardboardEffect.js:117

Fired whenever this CardboardEffect's camera property changes.

Event Payload:

  • value Object

    The property's new value

castShadow

Fired whenever this Entity's castShadow property changes.

Event Payload:

  • value Object

    The property's new value

clippable

Fired whenever this Entity's clippable property changes.

Event Payload:

  • value Object

    The property's new value

clips

Fired whenever this Entity's clips property changes.

Event Payload:

  • value Object

    The property's new value

collidable

Fired whenever this Entity's collidable property changes.

Event Payload:

  • value Object

    The property's new value

culled

Fired whenever this Entity's culled property changes.

Event Payload:

  • value Boolean

    The property's new value

destroyed

Fired when this Component is destroyed.

fov

Fired whenever this CardboardEffect's fov property changes.

Event Payload:

  • value Object

    The property's new value

geometry

Fired whenever this Entity's geometry property changes.

Event Payload:

  • value Object

    The property's new value

layer

Fired whenever this Entity's Layer/layer:property property changes.

Event Payload:

  • value Object

    The property's new value

lights

Fired whenever this Entity's lights property changes.

Event Payload:

  • value Object

    The property's new value

material

Fired whenever this Entity's material property changes.

Event Payload:

  • value Object

    The property's new value

morphTargets

Fired whenever this Entity's morphTargets property changes.

Event Payload:

  • value Object

    The property's new value

Outline

Fired whenever this Entity's Entity/Outline:property property changes.

Event Payload:

  • value Object

    The property's new value

outlined

Fired whenever this Entity' outlined property changes.

Event Payload:

  • value Object

    The property's new value

pickable

Fired whenever this Entity's pickable property changes.

Event Payload:

  • value Object

    The property's new value

picked

Fired when this Entity is picked via a call to the Canvas/pick:method method on the parent Scene's Canvas.

Event Payload:

  • entityId String

    The ID of this Entity.

  • canvasX Number

    The X-axis Canvas coordinate that was picked.

  • canvasY Number

    The Y-axis Canvas coordinate that was picked.

receiveShadow

Fired whenever this Entity's receiveShadow property changes.

Event Payload:

  • value Object

    The property's new value

stationary

Fired whenever this Entity's stationary property changes.

Event Payload:

  • value Object

    The property's new value

transform

Fired whenever this Entity's transform property changes.

Event Payload:

  • value Object

    The property's new value

Viewport

Fired whenever this CardboardEffect's Viewport property changes.

Event Payload:

  • value Object

    The property's new value

viewport

Fired whenever this Entity's viewport property changes.

Event Payload:

  • value Object

    The property's new value

visible

Fired whenever this Entity's visible property changes.

Event Payload:

  • value Boolean

    The property's new value

XRay

Fired whenever this Entity's Entity/XRay:property property changes.

Event Payload:

  • value Object

    The property's new value

xrayed

Fired whenever this Entity's xrayed property changes.

Event Payload:

  • value Object

    The property's new value