Scene
Extends:
Contains the components that comprise a 3D scene.
- A Viewer has a single Scene, which it provides in Viewer#scene.
- Plugins like AxisGizmoPlugin also have their own private Scenes.
- Each Scene has a corresponding MetaScene, which the Viewer provides in Viewer#metaScene.
Getting a Viewer's Scene
var scene = viewer.scene;
Creating and accessing Scene components
As a brief introduction to creating Scene components, we'll create a Mesh that has a buildTorusGeometry and a PhongMaterial:
var teapotMesh = new Mesh(scene, {
id: "myMesh", // <<---------- ID automatically generated if not provided
geometry: new TorusGeometry(scene),
material: new PhongMaterial(scene, {
id: "myMaterial",
diffuse: [0.2, 0.2, 1.0]
})
});
teapotMesh.scene.camera.eye = [45, 45, 45];
Find components by ID in their Scene's Scene#components map:
var teapotMesh = scene.components["myMesh"];
teapotMesh.visible = false;
var teapotMaterial = scene.components["myMaterial"];
teapotMaterial.diffuse = [1,0,0]; // Change to red
A Scene also has a map of component instances for each Component subtype:
var meshes = scene.types["Mesh"];
var teapotMesh = meshes["myMesh"];
teapotMesh.xrayed = true;
var phongMaterials = scene.types["PhongMaterial"];
var teapotMaterial = phongMaterials["myMaterial"];
teapotMaterial.diffuse = [0,1,0]; // Change to green
See Node, Node and Model for how to create and access more sophisticated content.
Controlling the camera
Use the Scene's Camera to control the current viewpoint and projection:
var camera = myScene.camera;
camera.eye = [-10,0,0];
camera.look = [-10,0,0];
camera.up = [0,1,0];
camera.projection = "perspective";
camera.perspective.fov = 45;
//...
Managing the canvas
The Scene's Canvas component provides various conveniences relevant to the WebGL canvas, such as firing resize events etc:
var canvas = scene.canvas;
canvas.on("boundary", function(boundary) {
//...
});
Picking
Use Scene#pick to pick and raycast entites.
For example, to pick a point on the surface of the closest entity at the given canvas coordinates:
var pickResult = scene.pick({
pickSurface: true,
canvasPos: [23, 131]
});
if (pickResult) { // Picked an entity
var entity = pickResult.entity;
var primitive = pickResult.primitive; // Type of primitive that was picked, usually "triangles"
var primIndex = pickResult.primIndex; // Position of triangle's first index in the picked Mesh's Geometry's indices array
var indices = pickResult.indices; // UInt32Array containing the triangle's vertex indices
var localPos = pickResult.localPos; // Float64Array containing the picked Local-space position on the triangle
var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the triangle
var viewPos = pickResult.viewPos; // Float64Array containing the picked View-space position on the triangle
var bary = pickResult.bary; // Float64Array containing the picked barycentric position within the triangle
var normal = pickResult.normal; // Float64Array containing the interpolated normal vector at the picked position on the triangle
var uv = pickResult.uv; // Float64Array containing the interpolated UV coordinates at the picked position on the triangle
}
Pick masking
We can use Scene#pick's includeEntities
and excludeEntities
options to mask which Meshes we attempt to pick.
This is useful for picking through things, to pick only the Entities of interest.
To pick only Entities "gearbox#77.0"
and "gearbox#79.0"
, picking through any other Entities that are
in the way, as if they weren't there:
var pickResult = scene.pick({
canvasPos: [23, 131],
includeEntities: ["gearbox#77.0", "gearbox#79.0"]
});
if (pickResult) {
// Entity will always be either "gearbox#77.0" or "gearbox#79.0"
var entity = pickResult.entity;
}
To pick any pickable Entity, except for "gearbox#77.0"
and "gearbox#79.0"
, picking through those
Entities if they happen to be in the way:
var pickResult = scene.pick({
canvasPos: [23, 131],
excludeEntities: ["gearbox#77.0", "gearbox#79.0"]
});
if (pickResult) {
// Entity will never be "gearbox#77.0" or "gearbox#79.0"
var entity = pickResult.entity;
}
See Scene#pick for more info on picking.
Querying and tracking boundaries
Getting a Scene's World-space axis-aligned boundary (AABB):
var aabb = scene.aabb; // [xmin, ymin, zmin, xmax, ymax, zmax]
Subscribing to updates to the AABB, which occur whenever Entitys are transformed, their ReadableGeometrys have been updated, or the Camera has moved:
scene.on("boundary", function() {
var aabb = scene.aabb;
});
Getting the AABB of the Entitys with the given IDs:
scene.getAABB(); // Gets collective boundary of all Entities in the scene
scene.getAABB("saw"); // Gets boundary of an Object
scene.getAABB(["saw", "gearbox"]); // Gets collective boundary of two Objects
See Scene#getAABB and Entity for more info on querying and tracking boundaries.
Managing the viewport
The Scene's Viewport component manages the WebGL viewport:
var viewport = scene.viewport
viewport.boundary = [0, 0, 500, 400];;
Controlling rendering
You can configure a Scene to perform multiple "passes" (renders) per frame. This is useful when we want to render the scene to multiple viewports, such as for stereo effects.
In the example, below, we'll configure the Scene to render twice on each frame, each time to different viewport. We'll do this with a callback that intercepts the Scene before each render and sets its Viewport to a different portion of the canvas. By default, the Scene will clear the canvas only before the first render, allowing the two views to be shown on the canvas at the same time.
var viewport = scene.viewport;
// Configure Scene to render twice for each frame
scene.passes = 2; // Default is 1
scene.clearEachPass = false; // Default is false
// Render to a separate viewport on each render
var viewport = scene.viewport;
viewport.autoBoundary = false;
scene.on("rendering", function (e) {
switch (e.pass) {
case 0:
viewport.boundary = [0, 0, 200, 200]; // xmin, ymin, width, height
break;
case 1:
viewport.boundary = [200, 0, 200, 200];
break;
}
});
// We can also intercept the Scene after each render,
// (though we're not using this for anything here)
scene.on("rendered", function (e) {
switch (e.pass) {
case 0:
break;
case 1:
break;
}
});
Gamma correction
Within its shaders, xeokit performs shading calculations in linear space.
By default, the Scene expects color textures (eg. PhongMaterial#diffuseMap, MetallicMaterial#baseColorMap and SpecularMaterial#diffuseMap) to be in pre-multipled gamma space, so will convert those to linear space before they are used in shaders. Other textures are always expected to be in linear space.
By default, the Scene will also gamma-correct its rendered output.
You can configure the Scene to expect all those color textures to be linear space, so that it does not gamma-correct them:
scene.gammaInput = false;
You would still need to gamma-correct the output, though, if it's going straight to the canvas, so normally we would leave that enabled:
scene.gammaOutput = true;
See Texture for more information on texture encoding and gamma.
Member Summary
Public Members | ||
public get |
Gets the World-space axis-aligned 3D boundary (AABB) of this Scene. |
|
public | ||
public get |
Gets the Camera for this Scene. |
|
public |
Manages the HTML5 canvas for this Scene. |
|
public get |
Gets the World-space 3D center of this Scene. |
|
public set |
When Scene#passes is greater than |
|
public get |
When Scene#passes is greater than |
|
public |
|
|
public set |
Sets whether basic color texture rendering is enabled. |
|
public get |
Gets whether basic color texture rendering is enabled. |
|
public get |
Gets the IDs of the Entitys in Scene#colorizedObjects. |
|
public |
colorizedObjects: {String: Object} Map of currently colorized Entitys that represent objects. |
|
public |
components: {} The Components within this Scene, each mapped to its Component#id. |
|
public |
Configures Cross Sections for this Scene. |
|
public set |
Sets whether data texture scene representation (DTX) is enabled for the Scene. |
|
public get |
Gets whether data texture-based scene representation (DTX) is enabled for the Scene. |
|
public get |
Gets the default EdgeMaterial for this Scene. |
|
public get |
Whether Entity#offset is enabled. |
|
public set |
Sets the gamma factor to use when Scene#gammaOutput is set true. |
|
public get |
Gets the gamma factor to use when Scene#gammaOutput is set true. |
|
public set | ||
public get | ||
public set |
Sets whether or not to render pixels with pre-multiplied gama. |
|
public get |
Gets whether or not to render pixels with pre-multiplied gama. |
|
public get |
Gets the default Geometry for this Scene, which is a ReadableGeometry with a unit-sized box shape. |
|
public get |
Gets the default highlight EmphasisMaterial for this Scene. |
|
public get |
Gets the IDs of the Entitys in Scene#highlightedObjects. |
|
public |
highlightedObjects: {String: Object} Map of currently highlighted Entitys that represent objects. |
|
public |
Publishes input events that occur on this Scene's canvas. |
|
public |
The LightMaps in this Scene, each mapped to its LightMap#id. |
|
public | ||
public |
The LineSets in this Scene, each mapped to its LineSet#id. |
|
public get |
Gets the LinesMaterial for this Scene. |
|
public |
The number of models currently loading. |
|
public get |
Whether logarithmic depth buffer is enabled. |
|
public get |
markerZOffset: Number: * Gets the Z value of offset for Marker's OcclusionTester. The closest the value is to 0.000 the more precise OcclusionTester will be, but at the same time the less precise it will behave for Markers that are located exactly on the Surface. Default is |
|
public get |
Gets the default Material for this Scene, which is a PhongMaterial. |
|
public |
Configures this Scene's units of measurement and coordinate mapping between Real-space and World-space 3D coordinate systems. |
|
public get |
Gets the IDs of the Entitys in Scene#models. |
|
public |
Map of Entitys that represent models. |
|
public set |
Sets the number of SectionPlanes for which this Scene pre-caches resources. |
|
public get |
Gets the number of SectionPlanes for which this Scene pre-caches resources. |
|
public get |
Gets the number of Entitys in Scene#colorizedObjects. |
|
public get |
Gets the number of Entitys in Scene#highlightedObjects. |
|
public get |
Gets the number of Entitys in Scene#objects. |
|
public get |
Gets the number of Entitys in Scene#selectedObjects. |
|
public get |
Gets the number of Entitys in Scene#visibleObjects. |
|
public get |
Gets the number of Entitys in Scene#xrayedObjects. |
|
public get |
Gets the IDs of the Entitys in Scene#objects. |
|
public |
Map of Entitys that represents objects. |
|
public get |
Gets the IDs of the Entitys in Scene#offsetObjects. |
|
public |
offsetObjects: {String: Object} Map of Entitys that represent objects whose Entity#offsets were updated. |
|
public get |
Gets the IDs of the Entitys in Scene#opacityObjects. |
|
public |
opacityObjects: {String: Object} Map of Entitys that represent objects whose opacity was updated. |
|
public set |
Sets the number of times this Scene renders per frame. |
|
public get |
Gets the number of times this Scene renders per frame. |
|
public set |
Sets whether physically-based rendering is enabled. |
|
public get |
pbrEnabled: Boolean: * Gets whether physically-based rendering is enabled. |
|
public get |
pickSurfacePrecisionEnabled: * | boolean: * this get was deprecated.
Whether precision surface picking is enabled. |
|
public get |
Gets the PointsMaterial for this Scene. |
|
public get |
Whether geometry is readable. |
|
public |
The real world offset for this Scene |
|
public |
reflectionMaps: {String: ReflectionMap} The ReflectionMaps in this Scene, each mapped to its ReflectionMap#id. |
|
public |
Configures Scalable Ambient Obscurance (SAO) for this Scene. |
|
public |
sectionPlanes: {String: SectionPlane} The SectionPlanes in this Scene, each mapped to its SectionPlane#id. |
|
public get |
Gets the default selection EmphasisMaterial for this Scene. |
|
public get |
Gets the IDs of the Entitys in Scene#selectedObjects. |
|
public |
selectedObjects: {String: Object} Map of currently selected Entitys that represent objects. |
|
public |
The epoch time (in milliseconds since 1970) when this Scene was instantiated. |
|
public set |
Sets the number of "ticks" that happen between occlusion testing for Markers. |
|
public get |
Gets the number of "ticks" that happen between each render of this Scene. |
|
public set |
Sets the number of "ticks" that happen between each render or this Scene. |
|
public get |
Gets the number of "ticks" that happen between each render or this Scene. |
|
public | ||
public |
The Viewer this Scene belongs to. |
|
public get |
viewport: * Gets the Viewport for this Scene. |
|
public get |
Gets the IDs of the Entitys in Scene#visibleObjects. |
|
public |
visibleObjects: {String: Object} Map of currently visible Entitys that represent objects. |
|
public get |
Gets the default xraying EmphasisMaterial for this Scene. |
|
public get |
Gets the IDs of the Entitys in Scene#xrayedObjects. |
|
public |
xrayedObjects: {String: Object} Map of currently xrayed Entitys that represent objects. |
Method Summary
Public Methods | ||
public |
clear() Destroys all non-default Components in this Scene. |
|
public |
Destroys all Lines in this Scene. |
|
public |
Destroys all Lights in this Scene.. |
|
public |
Destroys all Lines in this Scene. |
|
public |
Destroys all SectionPlanes in this Scene. |
|
public |
destroy() Destroys this Scene. |
|
public | ||
public |
Gets the collective axis-aligned boundary (AABB) of a batch of Entitys that represent objects. |
|
public |
pick(params: *, pickResult: PickResult): PickResult Attempts to pick an Entity in this Scene. |
|
public |
Renders a single frame of this Scene. |
|
public |
setObjectsCollidable(ids: String[], collidable: Boolean): Boolean Batch-updates Entity#collidable on Entitys that represent objects. |
|
public |
setObjectsColorized(ids: String[], colorize: Number[]): Boolean Batch-updates Entity#colorize on Entitys that represent objects. |
|
public |
setObjectsCulled(ids: String[], culled: Boolean): Boolean Batch-updates Entity#culled on Entitys that represent objects. |
|
public |
setObjectsEdges(ids: String[], edges: Boolean): Boolean Batch-updates Entity#edges on Entitys that represent objects. |
|
public |
setObjectsHighlighted(ids: String[], highlighted: Boolean): Boolean Batch-updates Entity#highlighted on Entitys that represent objects. |
|
public |
setObjectsOffset(ids: String[], offset: Number[]) Batch-updates Entity#offset on Entitys that represent objects. |
|
public |
setObjectsOpacity(ids: String[], opacity: Number): Boolean Batch-updates Entity#opacity on Entitys that represent objects. |
|
public |
setObjectsPickable(ids: String[], pickable: Boolean): Boolean Batch-updates Entity#pickable on Entitys that represent objects. |
|
public |
setObjectsSelected(ids: String[], selected: Boolean): Boolean Batch-updates Entity#selected on Entitys that represent objects. |
|
public |
setObjectsVisible(ids: String[], visible: Boolean): Boolean Batch-updates Entity#visible on Entitys that represent objects. |
|
public |
setObjectsXRayed(ids: String[], xrayed: Boolean): Boolean Batch-updates Entity#xrayed on Entitys that represent objects. |
|
public |
this method was deprecated.
|
|
public |
This method will "tickify" the provided |
|
public |
withObjects(ids: String[], callback: Function): Boolean Iterates with a callback over Entitys that represent objects. |
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 |
The viewer that contains this Scene. |
|
public |
clear() Destroys all Components that are owned by this. |
|
public |
destroy() Destroys this component. |
|
public |
Logs an error for this component to the JavaScript console. |
|
public |
Fires an event on this component. |
|
public |
Returns true if there are any subscribers to the given event on this component. |
|
public |
Tests if this component is of the given type, or is a subclass of the given type. |
|
public |
Logs a console debugging message for this component. |
|
public |
Cancels an event subscription that was previously made with Component#on or Component#once. |
|
public |
Subscribes to an event on this component. |
|
public |
Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is subIdd. |
|
public |
scheduleTask(task: *) Schedule a task to perform on the next browser interval |
|
public |
Logs a warning for this component to the JavaScript console. |
Public Members
public get aabb: Number[] source
Gets the World-space axis-aligned 3D boundary (AABB) of this Scene.
The AABB is represented by a six-element Float64Array containing the min/max extents of the axis-aligned volume, ie. [xmin, ymin,zmin,xmax,ymax, zmax]
.
When the Scene has no content, will be [-100,-100,-100,100,100,100]
.
public set clearEachPass: Boolean source
When Scene#passes is greater than 1
, indicates whether or not to clear the canvas before each pass (true
) or just before the first pass (false
).
Default value is false
.
public get clearEachPass: Boolean source
When Scene#passes is greater than 1
, indicates whether or not to clear the canvas before each pass (true
) or just before the first pass (false
).
Default value is false
.
public set colorTextureEnabled: Boolean source
Sets whether basic color texture rendering is enabled.
Default is true
.
public get colorTextureEnabled: Boolean: * source
Gets whether basic color texture rendering is enabled.
Default is true
.
public get colorizedObjectIds: String[] source
Gets the IDs of the Entitys in Scene#colorizedObjects.
public colorizedObjects: {String: Object} source
Map of currently colorized Entitys that represent objects.
An Entity represents an object if Entity#isObject is true
.
Properties:
Name | Type | Attribute | Description |
colorizedObjects | * |
public components: {} source
The Components within this Scene, each mapped to its Component#id.
*@type {{String:Component}}
public set dtxEnabled: Boolean source
Sets whether data texture scene representation (DTX) is enabled for the Scene.
Even when enabled, DTX will only work if supported.
Default value is false
.
public get dtxEnabled: Boolean source
Gets whether data texture-based scene representation (DTX) is enabled for the Scene.
Even when enabled, DTX will only apply if supported.
Default value is false
.
public get edgeMaterial: EdgeMaterial source
Gets the default EdgeMaterial for this Scene.
Has EdgeMaterial#id set to "default.edgeMaterial".
Meshs in this Scene have Mesh#edgeMaterial set to this EdgeMaterial by default.
Meshs have their edges emphasized while Mesh#edges is true
.
public get entityOffsetsEnabled: Boolean: * source
Whether Entity#offset is enabled.
This is set via the Viewer constructor and is false
by default.
public set gammaFactor: Number source
Sets the gamma factor to use when Scene#gammaOutput is set true.
Default value is 2.2
.
public get gammaFactor: Number source
Gets the gamma factor to use when Scene#gammaOutput is set true.
Default value is 2.2
.
public set gammaInput: Boolean source
Sets whether or not Scene should expect all Textures and colors to have pre-multiplied gamma.
Default value is false
.
public get gammaInput: Boolean source
Gets whether or not Scene should expect all Textures and colors to have pre-multiplied gamma.
Default value is false
.
public set gammaOutput: Boolean source
Sets whether or not to render pixels with pre-multiplied gama.
Default value is false
.
public get gammaOutput: Boolean source
Gets whether or not to render pixels with pre-multiplied gama.
Default value is true
.
public get geometry: ReadableGeometry source
Gets the default Geometry for this Scene, which is a ReadableGeometry with a unit-sized box shape.
Has ReadableGeometry#id set to "default.geometry".
Meshs in this Scene have Mesh#geometry set to this ReadableGeometry by default.
public get highlightMaterial: EmphasisMaterial source
Gets the default highlight EmphasisMaterial for this Scene.
Has EmphasisMaterial#id set to "default.highlightMaterial".
Meshs in this Scene have Mesh#highlightMaterial set to this EmphasisMaterial by default.
Meshs are highlighted while Mesh#highlighted is true
.
public get highlightedObjectIds: String[] source
Gets the IDs of the Entitys in Scene#highlightedObjects.
public highlightedObjects: {String: Object} source
Map of currently highlighted Entitys that represent objects.
An Entity represents an object if Entity#isObject is true
is true, and is highlighted when Entity#highlighted is true.
Properties:
Name | Type | Attribute | Description |
highlightedObjects | * |
public input: Input source
Publishes input events that occur on this Scene's canvas.
Properties:
Name | Type | Attribute | Description |
input | * |
public lightMaps: {String: LightMap} source
The LightMaps in this Scene, each mapped to its LightMap#id.
public lineSets: {String: LineSet} source
The LineSets in this Scene, each mapped to its LineSet#id.
public loading: Number source
The number of models currently loading.
Properties:
Name | Type | Attribute | Description |
loading | * |
public get logarithmicDepthBufferEnabled: Boolean: * source
Whether logarithmic depth buffer is enabled.
This is set via the Viewer constructor and is false
by default.
public get markerZOffset: Number: * source
Gets the Z value of offset for Marker's OcclusionTester. The closest the value is to 0.000 the more precise OcclusionTester will be, but at the same time the less precise it will behave for Markers that are located exactly on the Surface.
Default is -0.001
.
public get material: PhongMaterial source
Gets the default Material for this Scene, which is a PhongMaterial.
Has PhongMaterial#id set to "default.material".
Meshs in this Scene have Mesh#material set to this PhongMaterial by default.
public metrics: Metrics source
Configures this Scene's units of measurement and coordinate mapping between Real-space and World-space 3D coordinate systems.
Properties:
Name | Type | Attribute | Description |
metrics | * |
public models: {String: Entity} source
Map of Entitys that represent models.
Each Entity is mapped here by Entity#id when Entity#isModel is true
.
Properties:
Name | Type | Attribute | Description |
models | * |
public set numCachedSectionPlanes source
Sets the number of SectionPlanes for which this Scene pre-caches resources.
This property enhances the efficiency of SectionPlane creation by proactively allocating and caching Viewer resources for a specified quantity of SectionPlanes. Introducing this parameter streamlines the initial creation speed of SectionPlanes, particularly up to the designated quantity. This parameter internally configures renderer logic for the specified number of SectionPlanes, eliminating the need for setting up logic with each SectionPlane creation and thereby enhancing responsiveness. It is important to consider that each SectionPlane impacts rendering performance, so it is recommended to set this value to a quantity that aligns with your expected usage.
Default is 0
.
public get numCachedSectionPlanes: number: * source
Gets the number of SectionPlanes for which this Scene pre-caches resources.
This property enhances the efficiency of SectionPlane creation by proactively allocating and caching Viewer resources for a specified quantity of SectionPlanes. Introducing this parameter streamlines the initial creation speed of SectionPlanes, particularly up to the designated quantity. This parameter internally configures renderer logic for the specified number of SectionPlanes, eliminating the need for setting up logic with each SectionPlane creation and thereby enhancing responsiveness. It is important to consider that each SectionPlane impacts rendering performance, so it is recommended to set this value to a quantity that aligns with your expected usage.
Default is 0
.
public get numHighlightedObjects: Number source
Gets the number of Entitys in Scene#highlightedObjects.
public objects: {String: Entity} source
Map of Entitys that represents objects.
Each Entity is mapped here by Entity#id when Entity#isObject is true
.
Properties:
Name | Type | Attribute | Description |
objects | * |
public offsetObjects: {String: Object} source
Map of Entitys that represent objects whose Entity#offsets were updated.
An Entity represents an object if Entity#isObject is true
.
Properties:
Name | Type | Attribute | Description |
offsetObjects | * |
public opacityObjects: {String: Object} source
Map of Entitys that represent objects whose opacity was updated.
An Entity represents an object if Entity#isObject is true
.
Properties:
Name | Type | Attribute | Description |
opacityObjects | * |
public set passes: Number source
Sets the number of times this Scene renders per frame.
Default value is 1
.
public get passes: Number source
Gets the number of times this Scene renders per frame.
Default value is 1
.
public get pbrEnabled: Boolean: * source
Gets whether physically-based rendering is enabled.
Default is false
.
public get pickSurfacePrecisionEnabled: * | boolean: * source
Whether precision surface picking is enabled.
public get readableGeometryEnabled: Boolean: * source
Whether geometry is readable.
This is set via the Viewer constructor and is false
by default.
The readableGeometryEnabled
option for Scene#pick
only works if this is set true
.
Note that when true
, this configuration will increase the amount of browser memory used by the Viewer.
public reflectionMaps: {String: ReflectionMap} source
The ReflectionMaps in this Scene, each mapped to its ReflectionMap#id.
public sectionPlanes: {String: SectionPlane} source
The SectionPlanes in this Scene, each mapped to its SectionPlane#id.
public get selectedMaterial: EmphasisMaterial source
Gets the default selection EmphasisMaterial for this Scene.
Has EmphasisMaterial#id set to "default.selectedMaterial".
Meshs in this Scene have Mesh#highlightMaterial set to this EmphasisMaterial by default.
Meshs are highlighted while Mesh#highlighted is true
.
public selectedObjects: {String: Object} source
Map of currently selected Entitys that represent objects.
An Entity represents an object if Entity#isObject is true, and is selected while Entity#selected is true.
Properties:
Name | Type | Attribute | Description |
selectedObjects | * |
public startTime: Number source
The epoch time (in milliseconds since 1970) when this Scene was instantiated.
Properties:
Name | Type | Attribute | Description |
timeCreated | * |
public set ticksPerOcclusionTest: Number source
Sets the number of "ticks" that happen between occlusion testing for Markers.
Default value is 20
.
public get ticksPerOcclusionTest: Number source
Gets the number of "ticks" that happen between each render of this Scene.
Default value is 1
.
public set ticksPerRender: Number source
Sets the number of "ticks" that happen between each render or this Scene.
Default value is 1
.
public get ticksPerRender: Number source
Gets the number of "ticks" that happen between each render or this Scene.
Default value is 1
.
public visibleObjects: {String: Object} source
Map of currently visible Entitys that represent objects.
An Entity represents an object if Entity#isObject is true
, and is visible when Entity#visible is true.
Properties:
Name | Type | Attribute | Description |
visibleObjects | * |
public get xrayMaterial: EmphasisMaterial source
Gets the default xraying EmphasisMaterial for this Scene.
Has EmphasisMaterial#id set to "default.xrayMaterial".
Meshs in this Scene have Mesh#xrayMaterial set to this EmphasisMaterial by default.
Meshs are xrayed while Mesh#xrayed is true
.
public xrayedObjects: {String: Object} source
Map of currently xrayed Entitys that represent objects.
An Entity represents an object if Entity#isObject is true
, and is xrayed when Entity#xrayed is true.
Properties:
Name | Type | Attribute | Description |
xrayedObjects | * |
Public Methods
public doOcclusionTest() source
Performs an occlusion test on all Markers in this Scene.
Sets each Marker#visible true
if the Marker is currently not occluded by any opaque Entitys
in the Scene, or false
if an Entity is occluding it.
public getAABB(ids: String[]): [Number, Number, Number, Number, Number, Number] source
Gets the collective axis-aligned boundary (AABB) of a batch of Entitys that represent objects.
An Entity represents an object when Entity#isObject is true
.
Each Entity on which Entity#isObject is registered by Entity#id in Scene#visibleObjects.
Each Entity is only included in the AABB when Entity#collidable is true
.
Return:
[Number, Number, Number, Number, Number, Number] | An axis-aligned World-space bounding box, given as elements |
public pick(params: *, pickResult: PickResult): PickResult source
Attempts to pick an Entity in this Scene.
Ignores Entitys with Entity#pickable set false
.
When an Entity is picked, fires a "pick" event on the Entity with the pick result as parameters.
Picking the Entity at the given canvas coordinates:
var pickResult = scene.pick({
canvasPos: [23, 131]
});
if (pickResult) { // Picked an Entity
var entity = pickResult.entity;
}
Picking, with a ray cast through the canvas, hits an Entity:
var pickResult = scene.pick({
pickSurface: true,
canvasPos: [23, 131]
});
if (pickResult) { // Picked an Entity
var entity = pickResult.entity;
if (pickResult.primitive === "triangle") {
// Picked a triangle on the entity surface
var primIndex = pickResult.primIndex; // Position of triangle's first index in the picked Entity's Geometry's indices array
var indices = pickResult.indices; // UInt32Array containing the triangle's vertex indices
var localPos = pickResult.localPos; // Float64Array containing the picked Local-space position on the triangle
var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the triangle
var viewPos = pickResult.viewPos; // Float64Array containing the picked View-space position on the triangle
var bary = pickResult.bary; // Float64Array containing the picked barycentric position within the triangle
var worldNormal = pickResult.worldNormal; // Float64Array containing the interpolated World-space normal vector at the picked position on the triangle
var uv = pickResult.uv; // Float64Array containing the interpolated UV coordinates at the picked position on the triangle
} else if (pickResult.worldPos && pickResult.worldNormal) {
// Picked a point and normal on the entity surface
var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the Entity surface
var worldNormal = pickResult.worldNormal; // Float64Array containing the picked World-space normal vector on the Entity Surface
}
}
Picking the Entity that intersects an arbitrarily-aligned World-space ray:
var pickResult = scene.pick({
pickSurface: true, // Picking with arbitrarily-positioned ray
origin: [0,0,-5], // Ray origin
direction: [0,0,1] // Ray direction
});
if (pickResult) { // Picked an Entity with the ray
var entity = pickResult.entity;
if (pickResult.primitive == "triangle") {
// Picked a triangle on the entity surface
var primitive = pickResult.primitive; // Type of primitive that was picked, usually "triangles"
var primIndex = pickResult.primIndex; // Position of triangle's first index in the picked Entity's Geometry's indices array
var indices = pickResult.indices; // UInt32Array containing the triangle's vertex indices
var localPos = pickResult.localPos; // Float64Array containing the picked Local-space position on the triangle
var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the triangle
var viewPos = pickResult.viewPos; // Float64Array containing the picked View-space position on the triangle
var bary = pickResult.bary; // Float64Array containing the picked barycentric position within the triangle
var worldNormal = pickResult.worldNormal; // Float64Array containing the interpolated World-space normal vector at the picked position on the triangle
var uv = pickResult.uv; // Float64Array containing the interpolated UV coordinates at the picked position on the triangle
var origin = pickResult.origin; // Float64Array containing the World-space ray origin
var direction = pickResult.direction; // Float64Array containing the World-space ray direction
} else if (pickResult.worldPos && pickResult.worldNormal) {
// Picked a point and normal on the entity surface
var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the Entity surface
var worldNormal = pickResult.worldNormal; // Float64Array containing the picked World-space normal vector on the Entity Surface
}
}
Params:
Name | Type | Attribute | Description |
params | * | Picking parameters. |
|
params.pickSurface | Boolean |
|
Whether to find the picked position on the surface of the Entity. |
params.pickSurfacePrecision | Boolean |
|
When picking an Entity surface position, indicates whether or not we want full-precision PickResult#worldPos. Only works when Scene#readableGeometryEnabled is |
params.pickSurfaceNormal | Boolean |
|
Whether to find the picked normal on the surface of the Entity. Only works if |
params.canvasPos | Number[] |
|
Canvas-space coordinates. When ray-picking, this will override the origin and direction parameters and will cause the ray to be fired through the canvas at this position, directly along the negative View-space Z-axis. |
params.origin | Number[] |
|
World-space ray origin when ray-picking. Ignored when canvasPos given. |
params.direction | Number[] |
|
World-space ray direction when ray-picking. Also indicates the length of the ray. Ignored when canvasPos given. |
params.matrix | Number[] |
|
4x4 transformation matrix to define the World-space ray origin and direction, as an alternative to |
params.snapRadius | Number |
|
The snap radius, in canvas pixels. |
params.snapToVertex | boolean |
|
Whether to snap to vertex. Only works when |
params.snapToEdge | boolean |
|
Whether to snap to edge. Only works when |
pickResult | PickResult |
|
Holds the results of the pick attempt. Will use the Scene's singleton PickResult if you don't supply your own. |
Return:
PickResult | Holds results of the pick attempt, returned when an Entity is picked, else null. See method comments for description. |
public render(forceRender: Boolean) source
Renders a single frame of this Scene.
The Scene will periodically render itself after any updates, but you can call this method to force a render if required.
Params:
Name | Type | Attribute | Description |
forceRender | Boolean |
|
Forces a render when true, otherwise only renders if something has changed in this Scene since the last render. |
public setObjectsCollidable(ids: String[], collidable: Boolean): Boolean source
Batch-updates Entity#collidable on Entitys that represent objects.
An Entity represents an object when Entity#isObject is true
.
public setObjectsColorized(ids: String[], colorize: Number[]): Boolean source
Batch-updates Entity#colorize on Entitys that represent objects.
An Entity represents an object when Entity#isObject is true
.
public setObjectsCulled(ids: String[], culled: Boolean): Boolean source
Batch-updates Entity#culled on Entitys that represent objects.
An Entity represents an object when Entity#isObject is true
.
public setObjectsEdges(ids: String[], edges: Boolean): Boolean source
Batch-updates Entity#edges on Entitys that represent objects.
An Entity represents an object when Entity#isObject is true
.
public setObjectsHighlighted(ids: String[], highlighted: Boolean): Boolean source
Batch-updates Entity#highlighted on Entitys that represent objects.
An Entity represents an object when Entity#isObject is true
.
Each Entity on which both Entity#isObject and Entity#highlighted are true
is
registered by Entity#id in Scene#highlightedObjects.
public setObjectsOffset(ids: String[], offset: Number[]) source
Batch-updates Entity#offset on Entitys that represent objects.
An Entity represents an object when Entity#isObject is true
.
public setObjectsOpacity(ids: String[], opacity: Number): Boolean source
Batch-updates Entity#opacity on Entitys that represent objects.
An Entity represents an object when Entity#isObject is true
.
public setObjectsPickable(ids: String[], pickable: Boolean): Boolean source
Batch-updates Entity#pickable on Entitys that represent objects.
An Entity represents an object when Entity#isObject is true
.
public setObjectsSelected(ids: String[], selected: Boolean): Boolean source
Batch-updates Entity#selected on Entitys that represent objects.
An Entity represents an object when Entity#isObject is true
.
Each Entity on which both Entity#isObject and Entity#selected are true
is
registered by Entity#id in Scene#selectedObjects.
public setObjectsVisible(ids: String[], visible: Boolean): Boolean source
Batch-updates Entity#visible on Entitys that represent objects.
An Entity represents an object when Entity#isObject is true
.
Each Entity on which both Entity#isObject and Entity#visible are true
is
registered by Entity#id in Scene#visibleObjects.
public setObjectsXRayed(ids: String[], xrayed: Boolean): Boolean source
Batch-updates Entity#xrayed on Entitys that represent objects.
An Entity represents an object when Entity#isObject is true
.
public snapPick(params: Object): * source
Params:
Name | Type | Attribute | Description |
params | Object | Picking parameters. |
|
params.canvasPos | Number[] | Canvas-space coordinates. |
|
params.snapRadius | Number |
|
The snap radius, in canvas pixels |
params.snapToVertex | boolean |
|
Whether to snap to vertex. |
params.snapToEdge | boolean |
|
Whether to snap to edge. |
Return:
* |
public tickify(cb: Function): Function source
This method will "tickify" the provided cb
function.
This means, the function will be wrapped so:
- it runs time-aligned to scene ticks
- it runs maximum once per scene-tick
Params:
Name | Type | Attribute | Description |
cb | Function | The function to tickify |