Skip to main content

@novorender/api / View

Class: View<CameraControllerTypes, CameraControllerKind>

Defined in: @novorender/src/web_app/view.ts:90

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 Signature​

get activeController(): BaseController;

Defined in: @novorender/src/web_app/view.ts:248

Returns​

BaseController


convert​

Get Signature​

get convert(): ScreenSpaceConversions;

Defined in: @novorender/src/web_app/view.ts:291

Convert between different spaces like world, view and screen.

Returns​

ScreenSpaceConversions


data​

Get Signature​

get data(): undefined | DataContext;

Defined in: @novorender/src/web_app/view.ts:235

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

See​

loadSceneFromURL.

Returns​

undefined | DataContext


deviceProfile​

Get Signature​

get deviceProfile(): DeviceProfile;

Defined in: @novorender/src/web_app/view.ts:278

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.

Returns​

DeviceProfile

Set Signature​

set deviceProfile(value): void;

Defined in: @novorender/src/web_app/view.ts:281

Parameters​
ParameterType
valueDeviceProfile
Returns​

void


measure​

Get Signature​

get measure(): undefined | MeasureView;

Defined in: @novorender/src/web_app/view.ts:227

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

See​

loadSceneFromURL.

Returns​

undefined | MeasureView


offline​

Get Signature​

get offline(): undefined | OfflineContext;

Defined in: @novorender/src/web_app/view.ts:243

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

See​

loadSceneFromURL.

Returns​

undefined | OfflineContext


prevRenderState​

Get Signature​

get prevRenderState(): undefined | RenderState;

Defined in: @novorender/src/web_app/view.ts:263

Returns​

undefined | RenderState


renderContext​

Get Signature​

get renderContext(): undefined | RenderContext;

Defined in: @novorender/src/web_app/view.ts:253

Returns​

undefined | RenderContext


renderState​

Get Signature​

get renderState(): RenderState;

Defined in: @novorender/src/web_app/view.ts:258

Returns​

RenderState


statistics​

Get Signature​

get statistics(): 
| undefined
| {
render: RenderStatistics;
view: ViewStatistics;
};

Defined in: @novorender/src/web_app/view.ts:268

Returns​

| undefined | { render: RenderStatistics; view: ViewStatistics; }

Constructors​

Constructor​

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

Defined in: @novorender/src/web_app/view.ts:156

Parameters​

ParameterTypeDescription
canvasHTMLCanvasElementThe HtmlCanvasElement used for rendering.
deviceProfileDeviceProfileThe device profile describing the host device's GPU performance characteristics and limitations.
controllersFactoryCameraControllersFactory<CameraControllerTypes>-
__namedParameters{ listenToDocumentEvents?: boolean; showWatermark?: boolean; }-
__namedParameters.listenToDocumentEvents?boolean-
__namedParameters.showWatermark?boolean-

Returns​

View<CameraControllerTypes, CameraControllerKind>

Remarks​

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

Methods​

[dispose]()​

dispose: void;

Defined in: @novorender/src/web_app/view.ts:212

Dispose of the view's GPU resources.

Returns​

void

Implementation of​

Disposable.[dispose]

animate()?​

optional animate(time): void;

Defined in: @novorender/src/web_app/view.ts:1370

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

Parameters​

ParameterTypeDescription
timenumberThe frame render timestamp in millisecond.

Returns​

void


assignTextureSlot()​

assignTextureSlot(texture): TextureSlot;

Defined in: @novorender/src/web_app/view.ts:1400

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.


availableEnvironments()​

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

Defined in: @novorender/src/web_app/view.ts:384

Parameters​

ParameterType
indexUrlURL

Returns​

Promise<readonly EnvironmentDescription[]>

Deprecated​

Use static View.availableEnvironments instead.


availableTextures()​

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

Defined in: @novorender/src/web_app/view.ts:417

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.


dispose()​

dispose(): void;

Defined in: @novorender/src/web_app/view.ts:217

Dispose of the view's GPU resources.

Returns​

void


exit()​

exit(): void;

Defined in: @novorender/src/web_app/view.ts:1332

Signal the render loop to exit.

Returns​

void

See​

run.

Deprecated​

Use run abortSignal instead.


getNonParametricEdgeDirAtPoints()​

getNonParametricEdgeDirAtPoints(points, tolerance): Promise<undefined | (null | ReadonlyVec3)[]>;

Defined in: @novorender/src/web_app/view.ts:971

For each point find an edge nearby:

  • If point is close to an edge of object with the same objectId - return that edge direction.
  • If point is close to another triangle - return cross product of that triangle's normal and the point's normal. Function can be used to find edge directions for points on the surface of a mesh e.g. to have nice laser line endings.

Parameters​

ParameterTypeDescription
pointsobject[]points to query, each point should contain a position, normal and objectId
tolerancenumbermaximum distance to the edge or other triangle

Returns​

Promise<undefined | (null | ReadonlyVec3)[]>

array of edge directions or nulls, same size as points


getObjectsOutlinePlaneBoundingRectInWorld()​

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

Defined in: @novorender/src/web_app/view.ts:852

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


getOfflineViewState()​

getOfflineViewState(): Promise<undefined | OfflineViewState>;

Defined in: @novorender/src/web_app/view.ts:299

Manage offline storage.

Returns​

Promise<undefined | OfflineViewState>

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


getOutlineDrawObjects()​

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

Defined in: @novorender/src/web_app/view.ts:740

Get current outline 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.


getOutlineObjectsOnScreen()​

getOutlineObjectsOnScreen(): Set<number>;

Defined in: @novorender/src/web_app/view.ts:942

Get all object ids currently on screen

Returns​

Set<number>

returns a set of all object ids on the screen


inspectDeviations()​

inspectDeviations(settings): Promise<
| undefined
| DeviationInspections>;

Defined in: @novorender/src/web_app/view.ts:587

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.


isSceneResolved()​

isSceneResolved(): boolean;

Defined in: @novorender/src/web_app/view.ts:318

The scene is considered resolved when it is done loading all nodes for the current render state.

Returns​

boolean

if the scene is currently resolved


isTopDown()​

isTopDown(): boolean;

Defined in: @novorender/src/web_app/view.ts:306

Determine if camera is looking straight down.

Returns​

boolean


loadScene()​

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

Defined in: @novorender/src/web_app/view.ts:468

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>/.


modifyRenderState()​

modifyRenderState(changes): void;

Defined in: @novorender/src/web_app/view.ts:1341

Accumulate render state changes.

Parameters​

ParameterTypeDescription
changesRenderStateChangesThe 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.


outlineLaser()​

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

Defined in: @novorender/src/web_app/view.ts:660

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


pick()​

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

Defined in: @novorender/src/web_app/view.ts:1009

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.


pickMeasureEntity()​

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

Defined in: @novorender/src/web_app/view.ts:988

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.


render()?​

optional render(params): void;

Defined in: @novorender/src/web_app/view.ts:1387

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

Parameters​

ParameterType
params{ cameraMoved: boolean; isIdleFrame: boolean; }
params.cameraMovedboolean
params.isIdleFrameboolean

Returns​

void


run()​

run(abortSignal?): Promise<void>;

Defined in: @novorender/src/web_app/view.ts:1182

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.


screenSpaceLaser()​

screenSpaceLaser(__namedParameters): undefined | Intersection;

Defined in: @novorender/src/web_app/view.ts:613

Create list of laser intersections based on information already on screen

Parameters​

ParameterType
__namedParameters{ autoAlign?: boolean; laserPosition: ReadonlyVec3; onlyOnOutlines: boolean; xDir?: ReadonlyVec3; yDir?: ReadonlyVec3; zDir?: ReadonlyVec3; }
__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.


selectOutlinePoint()​

selectOutlinePoint(position, threshold): undefined | vec3;

Defined in: @novorender/src/web_app/view.ts:908

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.


setRenderContext()​

protected readonly setRenderContext(context): void;

Defined in: @novorender/src/web_app/view.ts:1445

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.


switchCameraController()​

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

Defined in: @novorender/src/web_app/view.ts:1106

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.


validate()?​

optional validate(newState, changes): void;

Defined in: @novorender/src/web_app/view.ts:1378

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

Parameters​

ParameterTypeDescription
newStateRenderStateThe new render state about to be rendered
changesRenderStateChangesThe changes that went into the new render state.

Returns​

void


validateRenderState()​

validateRenderState(changes?): readonly Error[];

Defined in: @novorender/src/web_app/view.ts:1357

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.


worldPositionFromPixelPosition()​

worldPositionFromPixelPosition(x, y): undefined | vec3;

Defined in: @novorender/src/web_app/view.ts:329

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


availableEnvironments()​

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

Defined in: @novorender/src/web_app/view.ts:365

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.


environmentRequests()​

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

Defined in: @novorender/src/web_app/view.ts:396

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.


textureRequests()​

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

Defined in: @novorender/src/web_app/view.ts:447

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.

Properties​

canvas​

readonly canvas: HTMLCanvasElement;

Defined in: @novorender/src/web_app/view.ts:158

The HTMLCanvasElement used for rendering.


controllers​

controllers: CameraControllerTypes;

Defined in: @novorender/src/web_app/view.ts:102

Available camera controller types.


maxHighlightGroups​

readonly static maxHighlightGroups: 250 = 250;

Defined in: @novorender/src/web_app/view.ts:99


terrainMaxId​

readonly static terrainMaxId: 99 = 99;

Defined in: @novorender/src/web_app/view.ts:98