Skip to main content

@novorender/web_app / View

Class: View<CameraControllerTypes, CameraControllerKind>

A view base class for Novorender content.

Template

Types of camera controllers used by this view.

Remarks

The view class wraps the complexities of the Core3D module into a high-level abstraction. Notably, it implements a render loop in the run function, which deals with a number of issues, such as:

  • Camera controllers.
  • Rendering after state changes, saving energy and battery life.
  • Adjust to resizing of canvas element.
  • Managing idle vs active rendering, i.e. lower fidelity rendering while the camera is moving for better frame rates.
  • Adaptive performance adjustment to maintain a target frame rate target.
  • Post effects.

In the likely event that you want to change or extend some of the default behaviour, you should make a derived View class of your own and override the methods you need.

Type Parameters

Type ParameterDefault typeDescription
CameraControllerTypes extends CameraControllersBuiltinCameraControllerType-
CameraControllerKind extends stringExtract<keyof CameraControllerTypes, string>The inferred camera controller kind string union.

Implements

  • Disposable

Accessors

activeController

get activeController(): BaseController

Returns

BaseController

Defined in

@novorender/web_app/view.ts:163


convert

get convert(): ScreenSpaceConversions

Convert between different spaces like world, view and screen.

Returns

ScreenSpaceConversions

Defined in

@novorender/web_app/view.ts:204


data

get data(): undefined | DataContext

Get the current data context, or undefined if no scene has been loaded or has no meta data.

See

loadSceneFromURL.

Returns

undefined | DataContext

Defined in

@novorender/web_app/view.ts:150


deviceProfile

get deviceProfile(): DeviceProfile

The current device profile.

Remarks

Setting a new device profile will force a recreation of the entire render context and should generally be avoided. Valid cases for doing so might be users manually overriding the GPU profile of their device, or for testing/diagnostics purposes.

set deviceProfile(value): void

Parameters

ParameterType
valueDeviceProfile

Returns

DeviceProfile

Defined in

@novorender/web_app/view.ts:193


measure

get measure(): undefined | MeasureView

Get the current measure view, or undefined if no scene has been loaded or has no measurement data.

See

loadSceneFromURL.

Returns

undefined | MeasureView

Defined in

@novorender/web_app/view.ts:142


offline

get offline(): undefined | OfflineContext

Get the current offline context, or undefined if no scene has been loaded.

See

loadSceneFromURL.

Returns

undefined | OfflineContext

Defined in

@novorender/web_app/view.ts:158


prevRenderState

get prevRenderState(): undefined | RenderState

Returns

undefined | RenderState

Defined in

@novorender/web_app/view.ts:178


renderContext

get renderContext(): undefined | RenderContext

Returns

undefined | RenderContext

Defined in

@novorender/web_app/view.ts:168


renderState

get renderState(): RenderState

Returns

RenderState

Defined in

@novorender/web_app/view.ts:173


statistics

get statistics(): undefined | object

Returns

undefined | object

Defined in

@novorender/web_app/view.ts:183


data

get static data(): __module

Get static data API functions that are independent of scene.

Returns

__module

Defined in

@novorender/web_app/view.ts:134

Constructors

new View()

new View<CameraControllerTypes, CameraControllerKind>(
canvas,
deviceProfile,
imports,
controllersFactory): View<CameraControllerTypes, CameraControllerKind>

Parameters

ParameterTypeDescription
canvasHTMLCanvasElementThe HtmlCanvasElement used for rendering.
deviceProfileDeviceProfileThe device profile describing the host device's GPU performance characteristics and limitations.
importsCore3DImports & MeasureImports & OfflineImportsImported, non-javascript resources.
controllersFactoryCameraControllersFactory<CameraControllerTypes>-

Returns

View<CameraControllerTypes, CameraControllerKind>

Remarks

Your browser must run in a secure and cross-origin isolated context.

Defined in

@novorender/web_app/view.ts:87

Methods

[dispose]()

dispose: void

Dispose of the view's GPU resources.

Returns

void

Implementation of

Disposable.[dispose]

Defined in

@novorender/web_app/view.ts:122


animate()?

optional animate(time): void

Override this in a derived class to modify render state just prior to rendering.

Parameters

ParameterTypeDescription
timenumberThe frame render timestamp in millisecond.

Returns

void

Defined in

@novorender/web_app/view.ts:987


assignTextureSlot()

assignTextureSlot(texture): TextureSlot

Helper function for assigning an index to the specified texture reference.

Parameters

ParameterTypeDescription
textureRenderStateTextureReferenceTexture reference to assign index to.

Returns

TextureSlot

A valid texture index slot and a flag indictating whether the slot existed or not.

Remarks

This function check if the reference object already exists in the current render state and if so, return the existing index. If not, it will find the first available slot that currently has no references, i.e. no highlight groups referring to it. In the latter case, it will update the render state to reflect the new texture reference. If the maximum amount of textures MaxActiveTextures are exceeded, this function will throw an exception.

Defined in

@novorender/web_app/view.ts:1017


availableEnvironments()

availableEnvironments(indexUrl): Promise<readonly EnvironmentDescription[]>

Parameters

ParameterType
indexUrlURL

Returns

Promise<readonly EnvironmentDescription[]>

Deprecated

Use static View.availableEnvironments instead.

Defined in

@novorender/web_app/view.ts:270


availableTextures()

availableTextures(indexUrl): Promise<readonly TextureDescription[]>

Retrieve list of available textures.

Parameters

ParameterTypeDescription
indexUrlURLThe absolute url of the index.json file.

Returns

Promise<readonly TextureDescription[]>

A promise of a list of environments.

Defined in

@novorender/web_app/view.ts:299


dispose()

dispose(): void

Dispose of the view's GPU resources.

Returns

void

Defined in

@novorender/web_app/view.ts:127


exit()

exit(): void

Signal the render loop to exit.

Returns

void

See

run.

Deprecated

Use run abortSignal instead.

Defined in

@novorender/web_app/view.ts:952


getObjectsOutlinePlaneBoundingRectInWorld()

getObjectsOutlinePlaneBoundingRectInWorld(
planeType,
planeIndex,
objectIds): undefined | AABB

Find bounding rectangle on the given plane for the selected objects, converted to world coordinates.

Parameters

ParameterTypeDescription
planeType"clipping" | "outline"choose if planes under clipping or outlines should be used
planeIndexnumberthe index of the plane to look up
objectIdsSet<number>set of object IDs to check

Returns

undefined | AABB

bounding rectangle of all the selected object ID vertices lying on the give plane. Bounds are calculated in plane coordinates and returned in world coordinates

Defined in

@novorender/web_app/view.ts:629


getOutlineDrawObjects()

getOutlineDrawObjects(
planeType,
planeIndex,
drawContext?,
settings?,
filter?): DrawProduct[]

Get current oultine drawable objects.

Parameters

ParameterTypeDescription
planeType"clipping" | "outline"choose if planes under clipping or outlines should be used
planeIndexnumberthe index of the plane to look up
drawContext?DrawContextOption to convert the 2d positions to another draw context
settings?LinesDrawSetting-
filter?Set<number>-

Returns

DrawProduct[]

Outlines as drawable objects for the 2d egnine.

Defined in

@novorender/web_app/view.ts:539


getOutlineObjectsOnScreen()

getOutlineObjectsOnScreen(): Set<number>

Get all object ids currently on screen

Returns

Set<number>

returns a set of all object ids on the screen

Defined in

@novorender/web_app/view.ts:702


inspectDeviations()

inspectDeviations(settings): Promise<undefined | DeviationInspections>

Inspect the deviations that is on screen

Parameters

ParameterTypeDescription
settingsDeviationInspectionSettingsDeviation settings,

Returns

Promise<undefined | DeviationInspections>

Spaced out labels prioritizing the smallest or highest deviation values based on settings. Also returns a line trough the points if it is able to project the points on a line and the option is given.

Defined in

@novorender/web_app/view.ts:439


isTopDown()

isTopDown(): boolean

Determine if camera is looking straight down.

Returns

boolean

Defined in

@novorender/web_app/view.ts:217


loadScene()

loadScene(
baseUrl,
sceneId,
version,
abortSignal?): Promise<SceneConfig>

Load a scene.

Parameters

ParameterTypeDescription
baseUrlURLThe absolute base url to the folder containing the scenes with optional sas-key, e.g. https://blobs.novorender.com/?sv=....
sceneIdstringThe scene id/guid.
versionstringThe hash of the desired scene version.
abortSignal?AbortSignalOptional abort controller.

Returns

Promise<SceneConfig>

Remarks

The url typically contains the scene id as the latter part of the path, i.e. https://.../<scene_guid>/.

Defined in

@novorender/web_app/view.ts:339


manageOfflineStorage()

manageOfflineStorage(): Promise<OfflineViewState>

Manage offline storage.

Returns

Promise<OfflineViewState>

An offline view state context used for offline storage management UI.

Defined in

@novorender/web_app/view.ts:212


modifyRenderState()

modifyRenderState(changes): void

Accumulate render state changes.

Parameters

ParameterTypeDescription
changesRecursivePartial<RenderState>The changes to apply to the current view render state.

Returns

void

Remarks

These changes will be applied and a single call to the modifyRenderState function just prior to rendering each frame.

Defined in

@novorender/web_app/view.ts:961


outlineLaser()

outlineLaser(
laserPosition,
planeType,
planeIndex,
rotation?,
autoAlign?): undefined | Intersection

Create a list of intersections between the x and y axis through the tracer position

Parameters

ParameterTypeDescription
laserPositionReadonlyVec3position where to calculate intersections,
planeType"clipping" | "outline"choose if planes under clipping or outlines should be used
planeIndexnumberThe index of the plane where tracer should be placed, based on the list in render state
rotation?numberrotation of the lasers in the plane, if undefined then x,y will be used
autoAlign?"closest" | "model"Auto align the lasers to the geometry, "model" will try to align to the highest number of lines it will intersect with while "closest" will align to the closest line it intersects with

Returns

undefined | Intersection

list of intersections (right, left, up ,down) results will be ordered from closest to furthest from the tracer point

Defined in

@novorender/web_app/view.ts:496


pick()

pick(
x,
y,
options?): Promise<undefined | PickSampleExt>

Query object and geometry information for given view coordinate.

Parameters

ParameterTypeDescription
xnumberCenter x coordinate in css pixels.
ynumberCenter y coordinate in css pixels.
options?PickOptionsExtra options.

Returns

Promise<undefined | PickSampleExt>

The sample within the sample disc that is closest to the camera, if any.

Defined in

@novorender/web_app/view.ts:744


pickMeasureEntity()

pickMeasureEntity(
x,
y,
options?): Promise<undefined | MeasureEntity>

Query parametric measure entity for the given coordinates

Parameters

ParameterTypeDescription
xnumberCenter x coordinate in css pixels.
ynumberCenter y coordinate in css pixels.
options?PickOptionsExtra options.

Returns

Promise<undefined | MeasureEntity>

Parametric measure entity, if non exists in the current location, the poisiton will be retuned.

Defined in

@novorender/web_app/view.ts:729


render()?

optional render(params): void

Override this in a derived class for custom rendering of e.g. 2D content, such as text and lines etc.

Parameters

ParameterType
paramsobject
params.cameraMovedboolean
params.isIdleFrameboolean

Returns

void

Defined in

@novorender/web_app/view.ts:1004


run()

run(abortSignal?): Promise<void>

Start the main render loop for the view.

Parameters

ParameterTypeDescription
abortSignal?AbortSignalSignal to abort any pending downloads and exit render loop.

Returns

Promise<void>

Remarks

This method will not exit until you signal the abortSignal.

Defined in

@novorender/web_app/view.ts:851


screenSpaceLaser()

screenSpaceLaser(__namedParameters): undefined | Intersection

Create list of laser intersections based on information already on screen

Parameters

ParameterType
__namedParametersobject
__namedParameters.autoAlign?boolean
__namedParameters.laserPositionReadonlyVec3
__namedParameters.onlyOnOutlinesboolean
__namedParameters.xDir?ReadonlyVec3
__namedParameters.yDir?ReadonlyVec3
__namedParameters.zDir?ReadonlyVec3

Returns

undefined | Intersection

list of intersections (right, left, up ,down, zUp, zDown) the lists will either contain a single intersection or none, the zDown will always be the laser position.

Defined in

@novorender/web_app/view.ts:464


selectOutlinePoint()

selectOutlinePoint(position, threshold): undefined | vec3

Select outline point based on the proximity to the input point.

Parameters

ParameterTypeDescription
positionReadonlyVec3Input position, outline points will be tested againts this.
thresholdnumberThreshold in meters, if no points are within this proxmitiy of the input point undefined will be returned

Returns

undefined | vec3

returns the closest point to the input position.

Defined in

@novorender/web_app/view.ts:668


setRenderContext()

protected readonly setRenderContext(context): void

Callback function to update render context.

Parameters

ParameterTypeDescription
contextRenderContextA new render context.

Returns

void

Remarks

A new render context may be set each time the underlying webgl context is lost and restored, or when certain state changes are made that forces a recreation of the context, such as setting a new deviceProfile.

Defined in

@novorender/web_app/view.ts:1058


switchCameraController()

switchCameraController<T>(
kind,
initialState?,
options?): Promise<CameraControllerTypes[T]>

Switch to a new kind of camera controller.

Type Parameters

Type ParameterDescription
T extends stringKind of camera controller.

Parameters

ParameterTypeDescription
kindTThe type of camera controller to switch to.
initialState?CameraControllerInitialValuesOptional initial state for the new camera controller. Undefined properties will be copied/adapted from the current render state.
options?CameraControllerOptionsSwitch options.

Returns

Promise<CameraControllerTypes[T]>

The new camera controller.

Remarks

The function will also set the camera projection model.

Defined in

@novorender/web_app/view.ts:807


validate()?

optional validate(newState, changes): void

Override this in a derived class to handle render state validation.

Parameters

ParameterTypeDescription
newStateRenderStateThe new render state about to be rendered
changesRecursivePartial<RenderState>The changes that went into the new render state.

Returns

void

Defined in

@novorender/web_app/view.ts:995


validateRenderState()

validateRenderState(changes?): readonly Error[]

Validate render state changes made since last rendered frame.

Parameters

ParameterTypeDescription
changes?RecursivePartial<RenderState>The render state changes to validate, or undefined to validate changes applied via View.modifyRenderState since last rendered frame.

Returns

readonly Error[]

An array of validation errors, if any.

See

View.modifyRenderState

Remarks

Validation is useful for catching potential bugs and problems early. It should not be performed in production code, however, since it is non-trivial in terms of performance, particularly on large sets of dynamic objects.

Defined in

@novorender/web_app/view.ts:974


worldPositionFromPixelPosition()

worldPositionFromPixelPosition(x, y): undefined | vec3

Convert 2D pixel position to 3D position.

Parameters

ParameterTypeDescription
xnumberPixel x coordinate, in CSS pixels.
ynumberPixel y coordinate, in CSS pixels.

Returns

undefined | vec3

Corresponding 3D position at the view plane in world space, or undefined if there is no active render context.

Deprecated

use view.convert.screenSpaceToWorldSpace instead

Defined in

@novorender/web_app/view.ts:231


availableEnvironments()

static availableEnvironments(indexUrl): Promise<readonly EnvironmentDescription[]>

Retrieve list of available background/IBL environments.

Parameters

ParameterTypeDescription
indexUrlURLThe absolute url of the index.json file.

Returns

Promise<readonly EnvironmentDescription[]>

A promise of a list of environments.

Defined in

@novorender/web_app/view.ts:257


downloadImports()

static downloadImports(map): Promise<ViewImports>

Parameters

ParameterType
mapViewImportmap

Returns

Promise<ViewImports>

Defined in

@novorender/web_app/view.ts:1161


environmentRequests()

static environmentRequests(...environments): readonly Request[]

Retrieve list of network requests for given environment(s) for cache/offline purposes.

Parameters

ParameterTypeDescription
...environmentsreadonly EnvironmentDescription[]The environment description objects.

Returns

readonly Request[]

Remarks

The returned requests are suitable for Cache API.

Defined in

@novorender/web_app/view.ts:280


textureRequests()

static textureRequests(...textures): readonly Request[]

Retrieve list of network requests for given texture(s) for cache/offline purposes.

Parameters

ParameterType
...texturesreadonly TextureDescription[]

Returns

readonly Request[]

Remarks

The returned requests are suitable for Cache API.

Defined in

@novorender/web_app/view.ts:320

Properties

canvas

readonly canvas: HTMLCanvasElement;

The HTMLCanvasElement used for rendering.

Defined in

@novorender/web_app/view.ts:89


controllers

controllers: CameraControllerTypes;

Available camera controller types.

Defined in

@novorender/web_app/view.ts:42


imports

readonly imports: Core3DImports & MeasureImports & OfflineImports;

Imported, non-javascript resources.

Defined in

@novorender/web_app/view.ts:90


maxHighlightGroups

readonly static maxHighlightGroups: 250 = 250;

Defined in

@novorender/web_app/view.ts:39


terrainMaxId

readonly static terrainMaxId: 99 = 99;

Defined in

@novorender/web_app/view.ts:38