Reference Source
public class | source

Canvas

Extends:

Component → Canvas

Manages its Scene's HTML canvas.

Member Summary

Public Members
public

Boundary of the Canvas in absolute browser window coordinates.

public

canvas: HTMLCanvasElement

The HTML canvas.

public set

Sets if the canvas background color is derived from an AmbientLight.

public get

Gets if the canvas background color is derived from an AmbientLight.

public

contextAttr: {}|*

Attributes for the WebGL context

public

gl: WebGLRenderingContext

The WebGL rendering context.

public get

spinner: *

The busy Spinner for this Canvas.

public

Indicates if this Canvas is transparent.

public

True when WebGL 2 support is enabled.

Method Summary

Public Methods
public
public

Simulates lost WebGL context.

public

readPixels(pixels: Number[], colors: Number[], size: Number, opaqueOnly: Boolean): *

Reads colors of pixels from the last rendered frame.

Inherited Summary

From class Component
public get

The Component that owns the lifecycle of this Component, if any.

public

True as soon as this Component has been destroyed

public

ID of this Component, unique within the Scene.

public

meta: *

Arbitrary, user-defined metadata on this component.

public

The parent Scene that contains this Component.

public

viewer: *

public

clear()

Destroys all Components that are owned by this.

public

Destroys this component.

public

error(message: String)

Logs an error for this component to the JavaScript console.

public

fire(event: String, value: Object, forget: Boolean)

Fires an event on this component.

public

Returns true if there are any subscribers to the given event on this component.

public

isType(type: *): *: Boolean

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

public

log(message: String)

Logs a console debugging message for this component.

public

off(subId: String)

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

public

on(event: String, callback: Function, scope: Object): String

Subscribes to an event on this component.

public

once(event: String, callback: Function, scope: Object)

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

public

warn(message: String)

Logs a warning for this component to the JavaScript console.

Public Members

public boundary: * source

Boundary of the Canvas in absolute browser window coordinates.

Usage:

var boundary = myScene.canvas.boundary;

var xmin = boundary[0];
var ymin = boundary[1];
var width = boundary[2];
var height = boundary[3];

Properties:

NameTypeAttributeDescription
boundary *

public canvas: HTMLCanvasElement source

The HTML canvas.

Properties:

NameTypeAttributeDescription
canvas *

public set clearColorAmbient: Boolean source

Sets if the canvas background color is derived from an AmbientLight.

This only has effect when the canvas is not transparent. When not enabled, the background color will be the canvas element's HTML/CSS background color.

Default value is false.

public get clearColorAmbient: Boolean source

Gets if the canvas background color is derived from an AmbientLight.

This only has effect when the canvas is not transparent. When not enabled, the background color will be the canvas element's HTML/CSS background color.

Default value is false.

public contextAttr: {}|* source

Attributes for the WebGL context

public gl: WebGLRenderingContext source

The WebGL rendering context.

Properties:

NameTypeAttributeDescription
gl *

public get spinner: * source

The busy Spinner for this Canvas.

Properties:

NameTypeAttributeDescription
spinner *

public transparent: Boolean source

Indicates if this Canvas is transparent.

Properties:

NameTypeAttributeDescription
transparent *

public webgl2: Boolean source

True when WebGL 2 support is enabled.

Properties:

NameTypeAttributeDescription
webgl2 *

Public Methods

public destroy() source

Destroys this component.

Override:

Component#destroy

public loseWebGLContext() source

Simulates lost WebGL context.

public readPixels(pixels: Number[], colors: Number[], size: Number, opaqueOnly: Boolean): * source

Reads colors of pixels from the last rendered frame.

Call this method like this:


// Ignore transparent pixels (default is false)
var opaqueOnly = true;

var colors = new Float32Array(8);

viewer.scene.canvas.readPixels([ 100, 22, 12, 33 ], colors, 2, opaqueOnly);

Then the r,g,b components of the colors will be set to the colors at those pixels.

Params:

NameTypeAttributeDescription
pixels Number[]
colors Number[]
size Number
opaqueOnly Boolean

Return:

*