Home Reference Source Repository
import CanvasField from 'dh3dlib/js/base/CanvasField.js'
public class | source

CanvasField

Canvas class for 2D/3D Context

Constructor Summary

Public Constructor
public

constructor(canvasElement: HTMLCanvasElement, options: Map)

constructor

Method Summary

Public Methods
public

addObject(obj: DH3DObject | DH2DObject, alpha: boolean, notReflection: boolean): void

add object to draw

public

checkGLError(message: string): void

output WebGL errors to console

public

create message window

public

disable Drag&Drop event: not implemented

public

disableMirror(): void

disable mirror

public

drawOneFrame(): void

draw one frame without animation

public

drawPicture(): void

draw one frame

public

enableMirror(): void

enable mirror

public

get 2D canvas context

public

get camera objects

public

getContext(): WebGLRenderingContext

get WebGL context

public

getFPS(): float

get FPS

public

get Light objects

public

getProgram(): WebGLProgram

get WebGL program

public

pause(): void

pause animation

public

remove object to draw

public

reshape(force: boolean): void

reshape canvas field

public

setCamera(camera: Camera): void

add Camera object

public

setDropEvent(func: Function): void

set callback function for Drag&Drop event

public

setFPS(fps: float): void

set FPS to limit the max FPS

public

setFrameCallback(func: Function): void

set callback function which is called after each frame

public

setLights(light: Light): void

add Light object

public

setProgram(program: WebGLProgram): void

set WebGLProgram

public

start(): void

start animation

Public Constructors

public constructor(canvasElement: HTMLCanvasElement, options: Map) source

constructor

Params:

NameTypeAttributeDescription
canvasElement HTMLCanvasElement
options Map

Public Methods

public addObject(obj: DH3DObject | DH2DObject, alpha: boolean, notReflection: boolean): void source

add object to draw

Params:

NameTypeAttributeDescription
obj DH3DObject | DH2DObject

object to draw

alpha boolean

true if it has alpha channel (it needs z-sort before drawing)

notReflection boolean

true if it has reflection (like mirror)

Return:

void

public checkGLError(message: string): void source

output WebGL errors to console

Params:

NameTypeAttributeDescription
message string

extra message to add to error log

Return:

void

public createMessageWindow(): MessageWindow source

create message window

Return:

MessageWindow

MessageWindow object

public disableDropEvent(): void source

disable Drag&Drop event: not implemented

Return:

void

public disableMirror(): void source

disable mirror

Return:

void

public drawOneFrame(): void source

draw one frame without animation

Return:

void

public drawPicture(): void source

draw one frame

Return:

void

public enableMirror(): void source

enable mirror

Return:

void

public get2DContext(): CanvasRenderingContext2D source

get 2D canvas context

Return:

CanvasRenderingContext2D

2D canvas context

public getCameras(): Array<Camera> source

get camera objects

Return:

Array<Camera>

Camera objects

public getContext(): WebGLRenderingContext source

get WebGL context

Return:

WebGLRenderingContext

WebGL context

public getFPS(): float source

get FPS

Return:

float

FPS

public getLights(): Array<Light> source

get Light objects

Return:

Array<Light>

Light objects

public getProgram(): WebGLProgram source

get WebGL program

Return:

WebGLProgram

WebGL program object

public pause(): void source

pause animation

Return:

void

public removeObject(obj: DH2DObject | DH3DObject): void source

remove object to draw

Params:

NameTypeAttributeDescription
obj DH2DObject | DH3DObject

object to remove

Return:

void

public reshape(force: boolean): void source

reshape canvas field

Params:

NameTypeAttributeDescription
force boolean

Return:

void

public setCamera(camera: Camera): void source

add Camera object

Params:

NameTypeAttributeDescription
camera Camera

Camera object to add

Return:

void

public setDropEvent(func: Function): void source

set callback function for Drag&Drop event

Params:

NameTypeAttributeDescription
func Function

callback function

Return:

void

public setFPS(fps: float): void source

set FPS to limit the max FPS

Params:

NameTypeAttributeDescription
fps float

max FPS

Return:

void

public setFrameCallback(func: Function): void source

set callback function which is called after each frame

Params:

NameTypeAttributeDescription
func Function

callback function which takes an int parameter (timestamp)

Return:

void

public setLights(light: Light): void source

add Light object

Params:

NameTypeAttributeDescription
light Light

Light object to add

Return:

void

public setProgram(program: WebGLProgram): void source

set WebGLProgram

Params:

NameTypeAttributeDescription
program WebGLProgram

WebGLProgram object

Return:

void

public start(): void source

start animation

Return:

void