API / geotoolkit3d / Plot / Plot

Class: Plot

geotoolkit3d.Plot.Plot

A Plot with 3D capabilities.
Unlike a geotoolkit 2D plot, this plot requires a DIV element to be passed and not a canvas.
Requires WebGL2 device support (since Toolkit v4.1), see WebGL Report.

The plot is internally structured as a SceneGraph using THREE.Scene.
It uses a camera system to represent user's eye location in 3D space.
This camera position can be moved anywhere in the plot and can look in any direction (although controller are encouraged to limit this freedom to ensure meaningful displays)
The camera type and option can be configured at creation or on the fly using setOptions().

To increase rendering accuracy the plot will try to compute ideal near/far planes positions and simplify transformation matrices.
This mechanism relies on the fact that the plot can compute its own modellimits and that those limits are reasonably small.
The rendering accuracy might suffer if modellimits are too big because of GPU floating point computing accuracy.

To render its content to the plot a render cycle made is of the following steps:

  • Call updateObject on all nodes: Offers a chance to each node to update its status before rendering occurs. This should not trigger any invalidation event though.
  • Call prepareRender: Simplifies transformation matrices, move near/far planes to increase accuracy.
  • Call beforeRender on visible nodes. This can be used to update nodes 'on the fly' in the render pass. However be careful when overriding this function as it heavily impacts the rendering logic.
  • Render: The WebGLRenderer traverses the scene, rendering node using WebGL (all GL operations occur at this stage).
  • Call finishRender: Restores the matrices, revert near/far planes.

The updateObject phase differs from beforeRender as it is executed before the plot's matrices/transformation have been simplified&optimized.
Which means that its implementation modifies a transformation that will be taken into account during this render pass for the simplification step.
However beforeRender is executed after the simplification, any modification done in this function will be rendered but will not be used for simplification.
Also, beforeRender expose a bit more of the internal plot logic and usage of those elements that are not part of the public API should be done with caution.
Generally, updateObject is used to implement application level changes.
And beforeRender is generally used to execute low level operations like GPU resource loading and management.

The plot also exposes some rendering options like anti-aliasing, clear-color or preferred GPU precision.
Some of them cannot be changed on the fly though like the transparency of the background.

A notification system using EventDispatcher exposes the events occurring in the plot (object added, removed, invalidate, camera changes, etc).
One could listen to events occurring on any node of the plot by listening to the Plot's events.
Note that you can also send custom events from your nodes to implement your application's logic.
See geotoolkit3d.Event.Type for the built-in events.

When an event is fired and caught by the plot, it marks itself as dirty.
Whenever the next renderCycle occurs (based on requestanimationframe), this flag will be checked.
If it's true then a render cycle will occur, otherwise the plot will hibernate until the next requestanimationframe lands.
That's why one may need to manually call invalidateObject() on a node after modifying it through direct access (like position, scale, rotation, etc).
It will flag the plot as dirty (through the event notification system), resulting in a render.
Note that because the rendering is asynchronous, during invalidate several time in a row will trigger only one render.

The plot also offers some useful features like built-in lighting (ambient light and camera headlight) and global scale.
Those options can be enabled/disabled and configured through the setOptions().

Like a geotoolkit widget, the plot uses a Tool system to catch, process and dispatch user input. (See [AbstractTool](../classes/geotoolkit3d.tool.abstracttool.abstracttool.md)).
One of those tools is the controller, it's a special tool that allow the user to manipulate the camera using an input device (mouse, touch screen, ...).

The plot will also have a compass added to it (as an overlay).
This compass can be configured/changed and also replaced by a custom one.

The plot provides postprocessing effects like anti-aliasing and outline highlighting. Since post processing is enabled by default, an EffectComposer will be created and will replace WebGLRenderer in animation loop.
It renders scene into a 2D image on a render target, and applies some passes to the result before drawing it to the canvas.

Throws

Will throw an error if the browser does not support WebGL

Hierarchy

Table of contents

Constructors
Methods

Contents

Constructors

new Plot(options)

new Plot(options)

Create plot

Parameters

Name Type Description
optionsOptionsoptions to create plot

Overrides

EventDispatcher.constructor

Methods

addMultipass

addMultipass(pass): void

Add postprocessing pass to the renderer.
The pass to be added must inherit AbstractPass.
The order of passes affects the final output, please use getMultipass and setOptions for ordering.

Deprecated

since 4.1, please use addPostProcessingPass instead.

Parameters

Name Type Description
passAbstractPassthe postprocessing pass

Returns

void


addPostProcessingPass

addPostProcessingPass(pass): void

Add postprocessing pass to the renderer.
The pass to be added must inherit AbstractPass.
The order of passes affects the final output, please use getMultipass and setOptions for ordering.

Parameters

Name Type Description
passAbstractPassthe postprocessing pass

Returns

void


addTool

addTool(tool): Plot

Adds and initializes the given tool.
The tool will be notified it has been added, and it will attach its system-event listeners.

Parameters

Name Type Description
toolAbstractToolThe tool to initialize and add.

Returns

Plot

this


dispose

dispose(): void

Disposes the plot and all its resources.
To do so, all objects contained in the scene will be disposed.
The tools registered on this plot will also be disposed.

Returns

void

Overrides

EventDispatcher.dispose


fitCamera

fitCamera(direction?, animate?, animationDuration?, distanceFactor?, ignoreZScale?): Plot

This function will try to adjust the camera position along the direction axis so that most of the scene fits into the view. It will also change the camera anchor point to the scene center. If the there is no visible geometry in the scene this function will silently fail.

Parameters

Name Type Description
Optional directionVector3Direction to move the camera in, will use scene center to camera if null.
Optional animatebooleanAnimate the camera change
Optional animationDurationnumberDuration of the animation in milliseconds
Optional distanceFactornumberDistance factor when fitting the camera. Greater than 1 means further from scene center.
Optional ignoreZScalebooleanIf true, z scale will be ignored

Returns

Plot

this


getAnimationManager

getAnimationManager(): AnimationManager

Returns the scene graph animation manager.
This manager should be used to perform smooth animations in the plot.
See AnimationManager for more details.

Returns

AnimationManager

The animation manager


getCamera

getCamera(): PerspectiveCamera | OrthographicCamera

Gets camera

Returns

PerspectiveCamera | OrthographicCamera


getCameraLocation

getCameraLocation(target?): Vector3

Returns camera location in user coordinates.

Parameters

Name Type Description
Optional targetVector3Optional target vector

Returns

Vector3

The camera location


getCameraLookAt

getCameraLookAt(target?): Vector3

Returns the camera lookat point in user coordinates IF such information is available (depends on the controller used).
Otherwise returns camera.location + camera.direction.

Parameters

Name Type Description
Optional targetVector3Optional target vector

Returns

Vector3

The camera lookat


getCanvasElement

getCanvasElement(): HTMLCanvasElement

Gets canvas element where the scene is drawn

Returns

HTMLCanvasElement

canvas element where the scene is drawn


getClassName

getClassName(): string

Returns

string

Inherited from

EventDispatcher.getClassName


getCompass

getCompass(): Compass

Returns the compass object.
The returned compass can be configured/modified.
See Compass for more details.

Returns

Compass

The compass object


getContainer

getContainer(): HTMLElement

Gets container where canvas is added

Returns

HTMLElement

container


getDefaultAA

getDefaultAA(pixelScale, screen): AntiAliasing

Get the default antialiasing method according to the pixel scale, screen size and device type The default AA for retina and 2K (2560x1440) and above monitor is fast approximate AA (FXAA), and super-resolution AA (SRAA) for lower resolution. The FXAA requires less computing power hence it is the default AA mode for a mobile

Deprecated

since 4.1, it was not meant to be public. Default AntiAliasing mode is the default plot mode, unless specified by users. To have the plot use the default AntiAliasing mode, use Plot.setOptions with advancedrendering.antialias.mode: AntiAliasing.AUTO instead

Parameters

Name Type
pixelScalenumber
screenScreen

Returns

AntiAliasing

antialiasing type


getModelLimits

getModelLimits(viewModelLimits?, filter?): Box3

Returns a copy of the modellimits in world coordinates.
The returned limits are either the one provided through the setOptions() or the one automatically computed by the plot.

Deprecated

since 5.0, because this method would inconsistently return the result with and without the Plot's scale reverted. Please use Plot.getSceneBoundingBox instead.

Parameters

Name Type Description
Optional viewModelLimitsbooleangets the modelLimits that includes grid sprites and children of objects with a getWorldBoundingBox
Optional filterFilterCallbackthat gets applied to the compute the model limits

Returns

Box3

The model limits


getModelOrigin

getModelOrigin(): Vector3

Returns a copy of the model origin in world coordinates.
The model origin is the center of the modellimits.

Returns

Vector3

The model origin


getMultipass

getMultipass(): AbstractPass[]

Get the current user custom postprocessing passes as an array. This return the original array so the order can be modified.

Deprecated

since 4.1, please use getPostProcessingPasses() instead. If getMultipass() was used to enable highlight on an object, please instead use highlightObject().

Returns

AbstractPass[]


getOptions

getOptions(): Options

Get the Plot options

Returns

Options


getPerformanceMetrics

getPerformanceMetrics(): PerformanceMetrics

Get performance metrics

Returns

PerformanceMetrics

Plot.PerformanceMetrics


getPostProcessingPasses

getPostProcessingPasses(): AbstractPass[]

Get the current user custom postprocessing passes as an array. This return the original array so the order can be modified.

Returns

AbstractPass[]


getRenderer

getRenderer(): WebGLRenderer

Gets the WebGLRenderer

Returns

WebGLRenderer

renderer


getRoot

getRoot(): Object3D<Object3DEventMap>

Returns the scene graph root.
One should use it to append nodes to the scene using the add() function.

Returns

Object3D<Object3DEventMap>

The root node


getScene

getScene(): Scene

Returns the scene.
Recommended uses are limited to:

  • Insert 'absolute' positioned objects like directional lights.
  • Used as parameter to [Grid#getMode](../classes/geotoolkit3d.scene-3.grid-1.grid.grid.md#getmode)().

Returns

Scene


getSceneBoundingBox

getSceneBoundingBox(target?, options?): Box3

Returns a copy of the scene bounding box based on specified SceneBoundingBoxOptions.
The returned scene bounding box are either the one provided through the setOptions() or the one automatically computed by the plot.
By default, it returns the bounding box in Business coordinates, which has inverse plot scale applied.
To get the bounding box in world coordinate, set options.coordinate to Coordinate.World.

Parameters

Name Type Description
Optional targetBox3Target bounding box
Optional optionsSceneBoundingBoxOptionsSceneBoundingBoxOptions

Returns

Box3

the scene bounding box


getSize

getSize(target?): Dimension

Returns the 'virtual device' size of the plot.

This returns the raw size given at initialization or through the setSize function.
Ignoring any pixelRatio that could have been set on the WebGL renderer.

Parameters

Name Type Description
Optional targetDimensionoptional object to store the dimensions

Returns

Dimension

The plot size


getToolByName

getToolByName(name): AbstractTool

Finds the tool matching the given name.
If several tool match this name, the 'first' is returned.

Parameters

Name Type Description
namestringThe name of the tool to look for

Returns

AbstractTool


getUsageStatistics

getUsageStatistics(): WebGLInfo

Returns usage statistics like WebGl calls per frame or amount of vertices rendered per frame.

Returns

WebGLInfo

The statistics see THREE.WebGLRenderer.info for more details.


hasEventListener

hasEventListener(type, callback?): boolean

Check if a list of event listeners for this type contains this listener

Parameters

Name Type Description
typestringtype of event or property
Optional callbackFunctionto be called, if null, check if any callback is registered

Returns

boolean

Inherited from

EventDispatcher.hasEventListener


highlightObject

highlightObject(object?): void

Manually set the given object to be highlighted.
Passing 'null' or an empty parameter will remove the highlight of the currently highlighted object.
Conditions required for highlight:

  • The advanced rendering option is enabled in the plot (enabled by default, unless the browser is not WebGL2 compliant)
  • The given object exist in the scene, and have of highlight capabilities.

Parameters

Name Type
Optional objectObject3D<Object3DEventMap>

Returns

void


invalidateObject

invalidateObject<T>(event?): Plot

Set the plot as 'dirty' so it gets redrawn during the next render phase.
This also propagates an event notifying the plot's listeners that an invalidation has occurred.

See Type for built-in events, custom event types can also be used.

Type parameters

Name
T

Parameters

Name Type Description
Optional eventEvent<T>The event that should be propagated as the reason of the invalidation

Returns

Plot

this


isDisposed

isDisposed(): boolean

Returns whether this object has been disposed

Returns

boolean

Inherited from

EventDispatcher.isDisposed


isGPUPerformanceSupported

isGPUPerformanceSupported(): boolean

Check if GPU Performance Metric is supported

Returns

boolean

true if supported, otherwise false


isSilent

isSilent(): boolean

Return true if the event dispatcher doesn't notify any events

Returns

boolean

Inherited from

EventDispatcher.isSilent


listTool

listTool(): AbstractTool[]

List all tools in the plot

Returns

AbstractTool[]

tools


moveCamera

moveCamera(position?, lookAt?, animate?, animationDuration?, upVector?): Plot

Moves the camera to the given position and rotate it to look at the given lookat.
Note that the given points should be in user coordinates (world coordinates without global scaling).

Parameters

Name Type Description
Optional positionVector3The position to move to in USER coordinates
Optional lookAtVector3The point to look at (in USER coordinates)
Optional animatebooleanAnimate the camera change
Optional animationDurationnumberDuration of the animation in milliseconds
Optional upVectorVector3up vector

Returns

Plot

this


notify

notify<E>(type, source, args?): Plot

Notify listeners

Type parameters

NameType
Eextends string

Parameters

Name Type Description
typeEevent types
sourcePlotof the event
Optional argsEventMap[E]arguments of the event

Returns

Plot

this

Overrides

EventDispatcher.notify


off

off<E>(type?, callback?): Plot

Detach listener on event. Calling .off() with no arguments removes all attached listeners. Calling .off(type) with no callback removes all attached listeners for specific type.

Type parameters

NameType
Eextends string

Parameters

Name Type Description
Optional typeEtype of the event
Optional callback(eventType: E, sender: Plot, args: EventMap[E]) => voidfunction to be called

Returns

Plot

this

Overrides

EventDispatcher.off


on

on<E>(type, callback): Plot

Attach listener on event that will be called whenever the specified event is delivered to the target

If the callback function is already in the list of event listeners for this target, the function is not added a second time.

If a particular anonymous function is in the list of event listeners registered for a certain target, and then later in the code, an identical anonymous function is given in an "on" call, the second function will also be added to the list of event listeners for that target.

Type parameters

NameType
Eextends string

Parameters

Name Type Description
typeEtype of event or property
callback(eventType: E, sender: Plot, args: EventMap[E]) => voidto be called

Returns

Plot

this

Overrides

EventDispatcher.on


project

project(point): Vector3

Project the given (world) point to virtual screen space in place.

Parameters

Name Type Description
pointVector3The point to project in world coordinates.

Returns

Vector3

The projected point


removeTool

removeTool(tool): Plot

Removes a tool (and disposes it).
The given tool will be disposed only if it does belong to this plot.

Parameters

Name Type Description
toolAbstractToolThe tool to remove and dispose

Returns

Plot

this


renderQualityPass

renderQualityPass(): void

Force plot to trigger quality pass

Returns

void


resetCamera

resetCamera(animate?, animationDuration?): Plot

This function will try to reset the camera position along the y-axis so most of the scene fits into the view.
It will also change the camera anchor point to the scene center.
If the there is no visible geometry in the scene this will silently fail.

Parameters

Name Type Description
Optional animatebooleanAnimate the camera change
Optional animationDurationnumberDuration of the animation in milliseconds

Returns

Plot

this


rootScale

rootScale(vector3): Vector3

Converts user coordinates to world coordinates in place (modifies the given object).

User coordinates are world coordinates without global scaling applies.
Use .setOptions({ scale: ... }) to change the global scaling.

Parameters

Name Type Description
vector3Vector3Source AND target vector3

Returns

Vector3

The converted coordinates


rootScaleInv

rootScaleInv(vector3): Vector3

Converts world coordinates to user coordinates in place (modifies the given object).

User coordinates are world coordinates without global scaling applies.
Use #setOptions({ scale: ... }) to change the global scaling.

Parameters

Name Type Description
vector3Vector3Source AND target vector3

Returns

Vector3

The converted coordinates


setCameraLocation

setCameraLocation(position, animate?, animationDuration?): Plot

Sets camera location in user coordinates.
It is recommended to use #moveCamera() instead as it handles both the location and the direction of the camera.

Parameters

Name Type Description
positionVector3The position to move to (in USER coordinates)
Optional animatebooleanAnimate the camera change
Optional animationDurationnumberDuration of the animation in milliseconds

Returns

Plot

this


setCameraLookAt

setCameraLookAt(lookat, animate?, animationDuration?): Plot

Sets camera target in user coordinates.
It is recommended to use #moveCamera() instead as it handles both the location and the direction of the camera.

Parameters

Name Type Description
lookatVector3The point to look at (in USER coordinates)
Optional animatebooleanAnimate the camera change
Optional animationDurationnumberDuration of the animation in milliseconds

Returns

Plot

this


setOptions

setOptions(options): Plot

Set options, the given json will be merged with the object's state so that only the given options will be changed.

Parameters

Name Type Description
optionsOptionsBaseoptions to set on this object

Returns

Plot

this


setOriginTranslation

setOriginTranslation(enabled): void

Apply a translation to the root and camera for higher precision.
Because renderer has a high precision error when working with large positions, set the root and camera closer to origin improves the accuracy. Note that it temporarily changes camera's position, i.e. during beforeRender().

Parameters

Name Type Description
enabledbooleanto enable

Returns

void


setSilent

setSilent(bool): Plot

Set silent mode

Parameters

Name Type Description
boolbooleanflag to enable silent mode

Returns

Plot

this

Inherited from

EventDispatcher.setSilent


setSize

setSize(width, height, pixelDeviceRatio?): Plot

Set size of the Plot.
This increase the rendering-area size (canvas) to the given dimension.
It also notifies the WebGl renderer.
The given pixelDeviceRatio can be used to take into account the current Browser zoom level.

Parameters

Name Type Description
widthnumberThe new width that should be set
heightnumberThe new height that should be set
Optional pixelDeviceRationumberThe pixel device ratio, if unset, will use the value provided by the window if available.

Returns

Plot

this


setWatermark

setWatermark(watermark): Plot

Set watermark to draw over plot 3d

Parameters

Name Type Description
watermarkAnchoredShapewatermark

Returns

Plot

this


updateModelLimits

updateModelLimits(filter?, alwaysTraverseChildren?): Plot

Updates the model limits of the Plot by computing it using the current scene state.

If 'autoupdatemodellimits' is enabled, this should be called automatically when some operations occur (adding, removing a node, etc).

However it should be called manually if an object in the scene is moved outside the current modellimits manually.
For example by changing its position attribute.

The modellimits are used internally to improves accuracy of rendering & picking.
Note: this method can have side effects if non-standard filter was used.

Parameters

Name Type Description
Optional filterFilterCallbackgets applied to the compute of model limits
Optional alwaysTraverseChildrenbooleanForces the calculation to traverse children to get the extents of the whole view

Returns

Plot

this


getClassName

Static getClassName(): string

Returns

string

Inherited from

EventDispatcher.getClassName