GuiViewer3D
Extends Autodesk.Viewing.Viewer3D
new GuiViewer3D(container, config)
Viewer component based on Viewer3D with added UI.
Parameters
| container* HTMLElement | The viewer container. |
| config* | The initial settings object. See base class for details. |
Properties
| ViewerCount | Need to keep track of viewers in document so we know when it is safe to call clearPropertyWorkerCache() |
| kDefaultCanvasConfig | Default values passed into Viewer3D#setCanvasClickBehavior specifying how the viewer canvas will react to user input as well as other 3d-canvas related options. |
Methods
getToolbar()
Returns the default toolbar of the viewer.
Returns
| type | description |
|---|---|
| ToolBar | Returns the toolbar. |
loadExtension(extensionId, options)
Loads the extension with the given id and options.
Parameters
| extensionId* string | The string id of the extension. |
| options* Object | An optional dictionary of options. |
Returns
| type | description |
|---|---|
| Promise |
|
getExtension(extensionId, callback)
Returns the loaded extension.
Parameters
| extensionId* string | The string id of the extension. |
| callback function | That receives an extension instance as argument. |
Returns
| type | description |
|---|---|
| Object |
|
getExtensionAsync(extensionId)
Returns a promise with the loaded extension.
Parameters
| extensionId* string | The string id of the extension. |
Returns
| type | description |
|---|---|
| Promise |
|
unloadExtension(extensionId)
Unloads the extension with the given id.
Parameters
| extensionId* string | The string id of the extension. |
Returns
| type | description |
|---|---|
| boolean |
|
loadExtensionLocal(extensionId, options)
Loads the extension with the given id and options. For internal use only.
Parameters
| extensionId* string | The string id of the extension. |
| options* Object | An optional dictionary of options. |
Returns
| type | description |
|---|---|
| Promise |
|
forEachExtension(callback)
Iterate over each extension that has been successfully loaded and invokes a callback function for them.
Parameters
| callback* function | That receives an extension instance as argument. |
Examples
forEachExtension(function(ext){
console.log(ext.id);
})
start(url, options, onSuccessCallback, onErrorCallback, initOptions)
Initializes the viewer and loads any extensions specified in the constructor’s config parameter. If the optional parameters are specified, the start() function will use an optimized initialization sequence that results in faster model load. The parameters are the same as the ones for Viewer3D.loadModel and you do not need to call loadModel subsequently if the model is loaded via the call to start().
Parameters
| url string | Optional URN or filepath to load on start. |
| options object | Optional path to shared property database. |
| onSuccessCallback Viewer3D~onLoadModelSuccess | Method that gets called when initial loading is done and streaming starts. |
| onErrorCallback Viewer3D~onLoadModelFailure | Method that gets called when initial loading ends with an error. |
| initOptions object | Optional: Options forwarded to viewer.initialize() |
Returns
| type | description |
|---|---|
| number | 0 if the viewer has started, an error code (same as that returned by initialize()) otherwise. |
setUp(config)
Loading extensions and initializing canvas interactions. Invoked automatically by Viewer3D#start method.
Parameters
| config object | configuration values |
| extensions Array.<string> | List of extension ids to load with the model. |
| canvasConfig object | Overrides for click/tap events on the 3D canvas. Refer to Viewer3D#setCanvasClickBehavior for details. |
tearDown(isUnloadModelsWanted)
Unloads extensions and the loaded models. Invoked automatically by Viewer3D#finish method.
Parameters
| isUnloadModelsWanted boolean | Whether to unload models at the end. Default is true. |
_onAggregatedSelectionChanged()
When selection has changed set the pivot point to be in the middle, if Autodesk.Viewing.Prefs3D.SELECTION_SETS_PIVOT is true
run()
Triggers the Viewer’s render loop. Invoked automatically by Viewer3D#start method. Refer to ViewerConfig.startOnInitialize to change start’s method behavior.
localize()
Localize the viewer. This method can be overwritten so that the subclasses can localize any additional elements. Invoked internally during initialization and automatically after resource reload on language change.
uninitialize()
Removes all created DOM elements, performs GL uninitialization that is needed and removes event listeners.
finish()
Unloads any loaded extensions and then uninitializes the viewer.
loadModel(url, options, onSuccessCallback, onErrorCallback)
Loads a model into the viewer. Can be used sequentially to load multiple 3D models into the same scene.
Parameters
| url* string | The url to the model. |
| options | Dictionary of options. |
| onSuccessCallback Viewer3D~onLoadModelSuccess | A method that gets called when model’s metadata loading is done and geometry streaming starts. |
| onErrorCallback Viewer3D~onLoadModelFailure | A method that gets called when loading fails. |
isLoadDone(include)
Check whether models are completely loaded This method checks all models in the model queue and load requests that haven’t loaded the root model yet. A model is completely loaded when the root model is loaded, all of the geometry is loaded, the property database, if present is loaded and no textures are being loaded.
Parameters
| include Object | Optional object to set the scope of the wait |
| geometry Boolean | Set to false to exclude the geometry loading from consideration. Because textures are loaded with geometry, include.textures must also be set to false to prevent geometry from being considered. Defaults to true. |
| propDb Boolean | Set to false to exclude the property data base loading from consideration. Defaults to true. |
| textures Boolean | Set to false to exclude the texture loading from consideration. Defaults to true. |
| hidden Boolean | Set to true to include hidden models for consideration. Defaults to false. |
| onlyModels Model, Array.<Model> | Limits the check to the model or models in this property. Note that checking for textures loaded cannot be limited to models. |
Returns
| type | description |
|---|---|
| Boolean | True if all models are completely loaded, otherwise false |
waitForLoadDone(include)
Wait for models to be completely loaded This method checks all models in the model queue and load requests that haven’t loaded the root model yet. A model is completely loaded when the root model is loaded, all of the geometry is loaded, the property database, if there is one, is loaded and no textures are being loaded. If this method is called before the viewer is started, then it will wait until the viewer starts and at least one model start loading to check for the load completing
Parameters
| include Object | Optional object to set the scope of the wait |
| geometry Boolean | Set to false to exclude the geometry loading from consideration. Because textures are loaded with geometry, include.textures must also be set to false to prevent waiting for geometry to load. Defaults to true. |
| propDb Boolean | Set to false to exclude the property data base loading from consideration. Defaults to true. |
| textures Boolean | Set to false to exclude the texture loading from consideration. Defaults to true. |
| hidden Boolean | Set to true to include hidden models for consideration. Defaults to false. |
| onlyModels Model, Array.<Model> | Limits the wait to the model or models in this property. Note that waiting for textures loaded cannot be limited to models. |
Returns
| type | description |
|---|---|
| Promise | resolves when all models are loaded. This promise can be rejected by a LOADER_LOAD_ERROR_EVENT event. |
unloadModel(model)
Unloads the specified model. Reference Viewer3D#hideModel to hide the model.
Parameters
| model* | The model to unload. |
loadDocumentNode(avDocument, manifestNode, options)
Parameters
| avDocument* | The Document instance, which owns the model being loaded |
| manifestNode* | The specific manifest node to load (within the Document) |
| options | Options to pass to Viewer3D#loadModel. Will be initialized internally if not specified. The options object will be augmented by automatically determined load parameters. |
Returns
| type | description |
|---|---|
| Promise |
|
unloadDocumentNode(manifestNode)
Unloads a model previously loaded by loadDocumentNode().
Reference Viewer3D#loadDocumentNode
Parameters
| manifestNode* | The specific manifest node to unload (within the Document) |
Returns
| type | description |
|---|---|
| boolean |
|
getDimensions()
Returns the dimensions of the WebGL canvas.
Returns
| type | description |
|---|---|
| object | Client rectangle bounds object { width:Number, height: Number } |
resize()
Resizes the viewer. Required when wrapping div changes dimensions due to CSS changes.
getHotkeyManager()
Returns
| type | description |
|---|---|
| HotkeyManager | The hotkey manager. |
getPreferences()
Gets the viewer preferences. Use them to read and change viewer settings, e.g. the ones in the Settings Panel, and to get notified about changes.
Returns
| type | description |
|---|---|
| Preferences | The viewer preferences. |
Examples
const prefs = viewer.getPreferences();
prefs.set(Autodesk.Viewing.Prefs3D.GROUND_SHADOW, false);
prefs.addListeners(Autodesk.Viewing.Prefs3D.GROUND_SHADOW, (value) => console.log(value));
getRenderLayers()
Gets the render layer manager. Use it to render custom scene content before, after or on top of the loaded models.
Returns
| type | description |
|---|---|
| RenderLayerManager | The render layer manager. |
Examples
const layers = viewer.getRenderLayers();
layers.create('my-overlay', { renderTarget: 'overlay' });
layers.addModel(new Autodesk.Viewing.Model(), 'my-overlay');
getCamera()
Gets the camera so it can be modified by the client.
Returns
| type | description |
|---|---|
| Camera | The active camera. |
getState(filter)
Gets the view state as a plain object. A viewer state contains data for the viewport, selection and isolation.
Reference Viewer3D#restoreState
Parameters
| filter object | Specifies which viewer values to get. |
Returns
| type | description |
|---|---|
| object | Viewer state. |
restoreState(viewerState, filter, immediate)
Restores the viewer state from a given object.
Reference Viewer3D#getState
Parameters
| viewerState* Object | |
| filter Object | Similar in structure to viewerState used to filter out values that should not be restored. |
| immediate boolean | Whether the new view is applied with (true) or without transition (false). |
Returns
| type | description |
|---|---|
| boolean | True if restore operation was successful. |
setView(viewNode, options)
Loads a view specified in the Manifest JSON. For 3D models it will use the camera values. For 2D models it will use the viewBox values.
Notice that in order that the view will be properly set according to the model’s transformation, the model has to be loaded first.
Parameters
| viewNode* | bubble node representing the view |
| options Object | |
| skipTransition boolean | true to apply instanstly instead of lerping. |
| useExactCamera boolean | whether any up vector adjustment is to be done (to keep head up view) |
| skipViewpointExtra boolean | true to skip using extra viewpoint information |
Returns
| type | description |
|---|---|
| boolean | true, if the view is applied. |
setViewFromArray(params)
Sets the view from an array of parameters.
To get the view array of the current camera use: Viewer3D#getViewArrayFromCamera. To get the camera object from the view array use Viewer3D#getCameraFromViewArray.
Parameters
| params* Array.<Number> | View parameters: [position-x, position-y, position-z, target-x, target-y, target-z, up-x, up-y, up-z, aspect, fov (radians), orthoScale, isPerspective (0=perspective, 1=ortho)] |
getCameraFromViewArray(params, model)
Returns an object representing a Camera from an unintuitive array of number. Note: To use this function in multi-model scenarios, you must pass the model parameter.
To get the view array of the current camera use: Viewer3D#getViewArrayFromCamera.
Parameters
| params* Array.<Number> | Array with 13 elements describing different aspects of a camera. |
| model | Camera is transformed in the same way as the model. Default is this.model (only sufficient for single-view scenarios). |
Returns
| type | description |
|---|---|
| ViewParams, null |
|
getViewArrayFromCamera()
Returns an Array of values that could be inserted back into a manifest to represent a view. To get the camera object from the view array use Viewer3D#getCameraFromViewArray.
Returns
| type | description |
|---|---|
| Array.<Number> |
|
setViewFromViewBox(viewbox, name, skipTransition)
Sets the view from an array representing a view box.
Not applicable to 3D.
Parameters
| viewbox* Array.<Number> | View parameters: [min-x, min-y, max-x, max-y] |
| name string | Optional named view name to also set the layer visibility state associated with this view. |
| skipTransition boolean | true to apply instanstly instead of lerping. |
activateLayerState(stateName)
Changes the active layer state. Layers is a feature usually available on 2D models and some 3D models.
Reference Viewer3D#getLayerStates
Parameters
| stateName* string | Name of the layer state to activate. |
getLayerStates()
Returns information for each layer state: name, description, active. Activate a state through Viewer3D#activateLayerState.
Returns
| type | description |
|---|---|
| Array.<Object>, null |
|
setViewFromFile(model)
Sets the view using the default view in the source file.
Parameters
| model | The model, defaults to the loaded model. |
setCanvasClickBehavior(config)
Sets the click behavior on the canvas to follow config. This is used to change the behavior of events such as selection or Center-of-Interest changed.
Parameters
| config* object | Parameter object that meets the above layout. |
Examples
{
"click": {
"onObject": [ACTIONS],
"offObject": [ACTIONS]
},
"clickCtrl": {
"onObject": [ACTIONS],
"offObject": [ACTIONS]
},
"clickShift": {
...
},
"clickCtrlShift": {
...
},
"disableSpinner": BOOLEAN
"disableMouseWheel": BOOLEAN,
"disableTwoFingerSwipe": BOOLEAN
}
Actions can be any of the following: “selectOnly”, “selectToggle”, “deselectAll”, “isolate”, “showAll”, “setCOI”, “focus”, “hide”
getIsolatedNodes(model)
Returns an array of the IDs of the currently isolated nodes.
Not yet implemented for 2D.
Parameters
| model | Model object, if passed in the isolated nodes of the model are returned |
Returns
| type | description |
|---|---|
| Array.<number> | Array of nodes that are currently isolated. |
isolate(node, model)
Isolates one of many sub-elements. You can pass in a node or an array of nodes to isolate. Pass in null to reset isolation.
Parameters
| node* Array.<number>, number | A node ID or array of node IDs from the model tree Model#getObjectTreeAsync. |
| model | the model that contains the node id. Defaults to the first loaded model. |
setBackgroundColor(red, green, blue, red2, green2, blue2)
Sets the background colors, which will be used to create a gradient. Values are in the range [0..255]
Parameters
| red* number | |
| green* number | |
| blue* number | |
| red2* number | |
| green2* number | |
| blue2* number |
setBackgroundOpacity(opacity)
Sets the background opacity.
Parameters
| opacity* number | Value is in the range [0.0..1.0] |
toggleSelect(dbid, model, selectionType)
Toggles the selection for a given dbid. If it was unselected, it is selected. If it was selected, it is unselected.
Currently three ways of node selection are supported:
- Autodesk.Viewing.SelectionType.MIXED
- Leaf nodes are selected using the overlayed selection type, and inner nodes are selected using regular selection type.
- Autodesk.Viewing.SelectionType.REGULAR
- Nodes are tinted with the selection color.
- Autodesk.Viewing.SelectionType.OVERLAYED
- Nodes are tinted with the selection color and shown on top of the not selected geometry.
Not yet implemented for 2D.
Parameters
| dbid* number | |
| model | the model that contains the dbId. Uses the initial model loaded by default. |
| selectionType* number | a member of Autodesk.Viewing.SelectionMode. |
select(dbids, model, selectionType)
Selects the array of ids. You can also pass in a single id instead of an array.
Currently three ways of node selection are supported:
- Autodesk.Viewing.SelectionType.MIXED
- Leaf nodes are selected using the overlayed selection type, and inner nodes are selected using regular selection type.
- Autodesk.Viewing.SelectionType.REGULAR
- Nodes are tinted with the selection color.
- Autodesk.Viewing.SelectionType.OVERLAYED
- Nodes are tinted with the selection color and shown on top of the not selected geometry.
Parameters
| dbids* Array.<number>, number | element or array of elements to select. |
| model | the model instance containing the ids. |
| selectionType number | a member of Autodesk.Viewing.SelectionType. |
clearSelection()
Clears the selection. See Viewer3D#select
getSelectionVisibility()
Returns information about the visibility of the current selection.
Returns
| type | description |
|---|---|
| object | {hasVisible:boolean, hasHidden:boolean} |
getSelectionCount()
Returns the number of nodes (dbIds) in the current selection.
Returns
| type | description |
|---|---|
| number |
|
setSelectionMode(mode)
Sets selection granularity mode. Supported values are:
- Autodesk.Viewing.SelectionMode.LEAF_OBJECT: Always select the leaf objects in the hierarchy.
- Autodesk.Viewing.SelectionMode.FIRST_OBJECT: For a given node, selects the first non-composite (layer, collection, model) on the path from the root to the given node, and all children.
- Autodesk.Viewing.SelectionMode.LAST_OBJECT: For a given node, selects the nearest ancestor composite node and all children. Selects the input node itself in case there is no composite node in the path to the root node.
Parameters
| mode* number | The selection mode. |
getSelection()
Returns the current selection.
Returns
| type | description |
|---|---|
| Array.<number> | Array of the nodes (dbIds) of the currently selected nodes. |
lockSelection(dbIds, lock, model)
Locks the selection of specific nodes (dbIds) in a given model. The nodes will be unselected if the lock is set to true and the nodes are already selected. The locked nodes will not be selectable.
Parameters
| dbIds* Number, Array.<Number> | dbIds to lock |
| lock* Boolean | true to lock, false otherwise |
| model | The model that contains the dbId. By default uses the initial model loaded into the scene. |
unlockSelection(dbIds, model)
This function will unlock the specified nodes (dbIds) for a specific model. If the nodes parameter is omitted then the specified model’s locked nodes will be unlocked. If the model parameter is omitted then the specified nodes will be unlocked for the viewer.model. If both parameters are omitted then all of the models in the viewer will release their locked nodes.
Parameters
| dbIds Array.<Number> | dbIds to unlock |
| model | The model associated to the nodes parameters |
isSelectionLocked(dbId, model)
Checks whether selection is locked for a node
Parameters
| dbId* number | the object’s identifier. |
| model | the model that contains the dbId. By default uses the initial model loaded into the scene. |
Returns
| type | description |
|---|---|
| boolean | True is the visibility is locked |
getAggregateSelection(callback)
Returns the selected items from all loaded models.
Parameters
| callback function | Optional callback to receive enumerated pairs of model and dbId for each selected object. If no callback is given, an array of objects is returned. |
Returns
| type | description |
|---|---|
| Array.<object> | An array of objects with a model and selectionSet properties for each model that has selected items in the scene. |
setAggregateSelection(selection, fireEvent)
Selects ids from different models. Choose this api instead of select() when selecting across many models
This fully replaces the aggregate selection: models that are not listed in selection are deselected.
Parameters
| selection* Array.<SelectionDef> | Array of selection objects defining what to select |
| fireEvent Boolean | Whether an event is fired at the end |
getAggregateIsolation()
Returns the isolated items from all loaded models.
Returns
| type | description |
|---|---|
| Array.<{model: Model, ids: Array.<number>}> | An array of objects with a model and the isolated ids in that model. |
setAggregateIsolation(isolation)
Isolate ids from different models. Choose this api instead of isolate() when isolating across many models. It will hide all other models.
Parameters
| isolation* Array.<{model: Model, ids: (Array.<number>|number)}> | An array of objects with a model and the ids to isolate in that model |
hide(node, model)
Ensures the passed in nodes (dbIds) are hidden.
Parameters
| node* Array.<number>, number | An array of nodes (dbids) or just a single node. |
| model | The model that contains the dbId. By default uses the initial model loaded into the scene. |
show(node, model)
Ensures the passed in nodes (dbIds) are shown.
Parameters
| node* Array.<number>, number | An array of nodes (dbids) or just a single node. |
| model | The model that contains the dbId. By default uses the initial model loaded into the scene. |
showAll()
Ensures everything is visible. Clears all node isolation (3D) and turns on all layers (2D).
hideAll()
Ensures all objects are hidden. Clears all nodes.
toggleVisibility(dbId, model)
Toggles the visibility of the given node (dbId).
Not yet implemented for 2D.
Parameters
| dbId* number | the object’s identifier. |
| model | the model that contains the dbId. By default uses the initial model loaded into the scene. |
areAllVisible()
Returns true if every node (dbId) is visible.
Returns
| type | description |
|---|---|
| boolean |
|
isNodeVisible(nodeId, model)
Returns true if the specified node is visible. The model argument is required only when in multi-model scenarios.
Parameters
| nodeId* number | Geometry node to check if visible. |
| model | The model that contains the specified nodeId. |
Returns
| type | description |
|---|---|
| boolean |
lockVisible(dbId, locked, model)
Ensures the passed in nodes (dbIds) are shown.
Parameters
| dbId* Array.<number>, number | array of nodes or a single node |
| locked* boolean | Set to true to lock the nodes visible. Set to false to allow the nodes to be hidden. |
| model | The model that contains the dbId. By default uses the initial model loaded into the scene. |
toggleLockVisible(dbId, model)
Toggles the visibility lock of the given node (dbId).
Not yet implemented for 2D.
Parameters
| dbId* number | the object’s identifier. |
| model | the model that contains the dbId. By default uses the initial model loaded into the scene. |
isVisibleLocked(dbId, model)
Checks whether visibility is locked for a node (dbId).
Not yet implemented for 2D.
Parameters
| dbId* number | the object’s identifier. |
| model | the model that contains the dbId. By default uses the initial model loaded into the scene. |
Returns
| type | description |
|---|---|
| boolean | True is the visibility is locked |
explode(scale, options)
Explodes the model from the center of gravity.
Not applicable to 2D.
Parameters
| scale* number | A value from 0.0-1.0 to indicate how much to explode. |
| options* Object | Additional setting for STRATEGY_HIERARCHY. |
| magnitude* Number | Controls the spread of explode. |
| depthDampening* Number | Controls the reduction of the explode effect with depth of the object in the hierarchy. |
getExplodeScale()
Returns the explode scale.
Not applicable to 2D.
Returns
| type | description |
|---|---|
| number |
|
getExplodeOptions()
Returns the explode options.
Not applicable to 2D.
Returns
| type | description |
|---|---|
| object | {magnitude:Number, depthDampening:Number} |
lockExplode(dbids, lock, model)
Lock node (dbid) so that it doesn’t explode
Not applicable to 2D.
Parameters
| dbids* Array.<number>, number | The dbids to lock or unlock |
| lock* boolean | Set to true to prevent dbids from exploding. Set to false to allow dbids to explode. |
| model | The model containing the dbids. Defaults to this.model |
Returns
| type | description |
|---|---|
| boolean | True if any dbids were changed. |
isExplodeLocked(dbid, model)
Check whether a dbid is locked so it doesn’t explode.
Not applicable to 2D.
Parameters
| dbid* number | The dbid to check |
| model | The model containing the dbids. Defaults to this.model |
Returns
| type | description |
|---|---|
| boolean | True if dbid is locked to prevent explode |
toggleLockExplode(dbid, model)
Toggle dbid lock so it doesn’t explode
Not applicable to 2D.
Parameters
| dbid* number | The dbid to lock or unlock |
| model | The model containing the dbids. Defaults to this.model |
Returns
| type | description |
|---|---|
| boolean | True if any dbids were changed. |
setQualityLevel(useSAO, useFXAA)
Enables or disables the high quality rendering settings.
Not applicable to 2D.
Parameters
| useSAO* boolean | True or false to enable screen space ambient occlusion. |
| useFXAA* boolean | True or false to enable fast approximate anti-aliasing. |
setGhosting(value)
Toggles ghosting during search and isolate.
Not applicable to 2D.
Parameters
| value* boolean | Indicates whether ghosting is on or off. |
setGroundShadow(value)
Toggles ground shadow.
Not applicable to 2D.
Parameters
| value* boolean | Indicates whether shadow is on or off. |
setGroundReflection(value)
Toggles ground reflection.
Not applicable to 2D.
Parameters
| value* boolean | Indicates whether reflection is on or off. |
setEnvMapBackground(value)
Toggles environment map for background.
Not applicable to 2D.
Parameters
| value* boolean | Indicates whether environment map for background is on or off. |
setBimWalkToolPopup(value)
Toggles the bimwalk tool popup.
Not applicable to 2D.
Parameters
| value* boolean | Indicates whether first person tool popup is showed or not. |
getBimWalkToolPopup()
Returns the state of First Person Walk tool popup
Not applicable to 2D.
Returns
| type | description |
|---|---|
| boolean | true if the First Person Walk tool popup appears, false if the First Person Walk tool popup does not appear. |
setProgressiveRendering(value)
Toggles whether progressive rendering is used. Warning: turning progressive rendering off will have serious performance implications.
Parameters
| value* boolean | whether it is on or off |
setGrayscale(value)
Overrides line colors in 2D models to render in shades of gray. Applies only to 2D models.
Parameters
| value* boolean | whether it is on or off |
setScreenSpaceLineWidth(value)
Keeps lines a constant width even when zooming in. Requires WebGPU to be enabled.
Parameters
| value* boolean | whether it is on or off |
setSwapBlackAndWhite(value)
AutoCAD drawings are commonly displayed with white lines on a black background. Setting reverse swaps (just) these two colors.
Parameters
| value* boolean | whether it is on or off |
getFOV()
Gets the current camera vertical field of view.
Returns
| type | description |
|---|---|
| number |
|
setFOV(degrees)
Sets the current cameras vertical field of view.
Parameters
| degrees* number | Field of view in degrees. |
getFocalLength()
Gets the current camera focal length.
Returns
| type | description |
|---|---|
| number |
|
setFocalLength(mm)
Sets the current cameras focal length.
Parameters
| mm* number | Focal length in millimetres |
hideLines(hide)
Hides all lines in the scene.
Parameters
| hide* boolean |
hidePoints(hide)
Hides all points in the scene.
Parameters
| hide* boolean |
setDisplayEdges(show)
Turns edge topology display on/off (where available).
Parameters
| show* boolean | true to turn edge topology display on, false to turn edge topology display off. |
fitToView(objectIds, model, immediate)
Fits camera to objects by ID. It fits the entire model if no ID is provided. Operation will fit to the model’s bounding box when its object tree is not available.
Parameters
| objectIds Array.<number>, null | array of Ids to fit into the view. Avoid passing this value to fit the entire model. |
| model Model, null | The model containing the objectIds. If falsey, the viewer’s current model will be used. |
| immediate boolean | true to avoid the default transition. |
setClickConfig(what, where, newAction)
Modifies a click action configuration entry.
Parameters
| what* string | which click config to modify (one of “click”, “clickAlt”, “clickCtrl”, “clickShift”, “clickCtrlShift”). |
| where* string | hit location selector (one of “onObject”, “offObject”). |
| newAction* Array.<string> | action list (containing any of “setCOI”, “selectOnly”, “selectToggle”, “deselectAll”, “deselectAll”, “isolate”, “showAll”, “hide”, “focus”). |
Returns
| type | description |
|---|---|
| boolean | False if specified entry is not found, otherwise true. |
getClickConfig(what, where)
Fetch a click action configuration entry.
Parameters
| what* string | which click config to fetch (one of “click”, “clickAlt”, “clickCtrl”, “clickShift”, “clickCtrlShift”). |
| where* string | hit location selector (one of “onObject”, “offObject”). |
Returns
| type | description |
|---|---|
| Array | action list for the given entry or null if not found. |
setClickToSetCOI(state, updatePrefs)
Modify the default click behaviour for the viewer. COI is Center of Interest.
Parameters
| state* boolean | If true the default is to set the center of interest. If false the default is single select. |
| updatePrefs boolean | Whether to update user preferences. Defaults to true unless explicitly set to false. |
setProfile(profile, override)
Updates viewer settings encapsulated witihn a Profile. This method will also load and unload extensions referenced by the Profile.
Parameters
| profile* | profile containing settings. |
| override boolean | If set to true this will override all existing preference with the new profile preference. Default: true |
Examples
const profileSettings = {
name: "mySettings",
settings: {
ambientShadows: false,
groundShadows: true
}
extensions: {
load: [], // Extension IDs
unload: [] // Extension IDs
}
}
const profile = new Autodesk.Viewing.Profile(profileSettings);
viewer.setProfile(profile);
setLightPreset(index)
Sets the Light Presets (Environments) for the Viewer.
Not applicable to 2D.
Sets the preference in the UI
Parameters
| index* Number | The index mapping looks like this: 0 -> Simple Grey, 1 -> Sharp Highlights, 2 -> Dark Sky, 3 -> Grey Room, 4 -> Photo Booth, 5 -> Tranquility, 6 -> Infinity Pool, 7 -> Simple White, 8 -> Riverbank, 9 -> Contrast, 1 ->0 Rim Highlights, 1 ->1 Cool Light, 1 ->2 Warm Light, 1 ->3 Soft Light, 1 ->4 Grid Light, 1 ->5 Plaza, 1 ->6 Snow Field |
setUsePivotAlways(value)
Set or unset a view navigation option which requests that orbit controls always orbit around the currently set pivot point.
Sets the preference in the UI
Parameters
| value* boolean | value of the option, true to request use of the pivot point. When false some controls may pivot around the center of the view. (Currently applies only to the view-cube orbit controls.) |
setReverseZoomDirection(value)
Set or unset a view navigation option to reverse the default direction for camera dolly (zoom) operations.
Sets the preference in the UI
Parameters
| value* boolean | value of the option, true for reverse, false for default |
setReverseHorizontalLookDirection(value)
Set or unset a view navigation option to reverse the default direction for horizontal look operations.
Not applicable to 2D.
Sets the preference in the UI
Parameters
| value* boolean | value of the option, true for reverse, false for default |
setReverseVerticalLookDirection(value)
Set or unset a view navigation option to reverse the default direction for vertical look operations.
Not applicable to 2D.
Sets the preference in the UI
Parameters
| value* boolean | value of the option, true for reverse, false for default |
setZoomTowardsPivot(value)
Get the state of the view navigation option that requests the default direction for camera dolly (zoom) operations to be towards the camera pivot point.
Sets the preference in the UI
Parameters
| value* boolean | value of the option, true for towards the pivot, false for default |
setOrbitPastWorldPoles(value)
Set or unset a view navigation option to allow the orbit controls to move the camera beyond the north and south poles (world up/down direction). In other words, when set the orbit control will allow the camera to rotate into an upside down orientation. When unset orbit navigation should stop when the camera view direction reaches the up/down direction.
Not applicable to 2D.
Sets the preference in the UI
Parameters
| value* boolean | value of the option, true to allow orbiting past the poles. |
setUseLeftHandedInput(value)
Set or unset a view navigation option which requests that mouse buttons be reversed from their default assignment (i.e. Left mouse operation becomes right mouse and vice versa).
Sets the preference in the UI
Parameters
| value* boolean | value of the option, true to request reversal of mouse button assignments. |
setZoomDragSpeed(value)
Set a sensitivity of mouse movement with the zoom tool
Sets the preference in the UI
Parameters
| value* number | value of the option, can be between 5 and 300. Default is 100. |
setZoomScrollSpeed(value)
Set a sensitivity of the mouse scroll wheel when zooming
Sets the preference in the UI
Parameters
| value* number | value of the option, can be between 0.1 and 3.0. Default is 0.6. |
setDisplayUnits(value)
Set units for quantities displayed in the property panel. Only setting linear (distance) quantity units are supported
Parameters
| value* string | display units to set. The units can be “” (file units), “mm”, “cm”, “m”, “in”, “ft”, “sft”, “ft-and-fractional-in”, “ft-and-decimal-in”, “decimal-in”, “decimal-ft”, “fractional-in”, “m-and-cm”, |
setDisplayUnitsPrecision(value)
Set the precision for quantities displayed in the property panel.
Parameters
| value* number | precision for the units The value is the number of decimal values after the “.”. For e.g., a value of 5 would be either 0.12345 or 1/32 (2^5) for fraction type units Values greater than 6 is not supported If value is not specified, it defaults to the precision in the file |
setLayerVisible(nodes, visible, isolate)
Set visibility for a single layer, or for all layers.
Parameters
| nodes* Array | An array of layer nodes, or a single layer node, or null for all layers |
| visible* boolean | true to show the layer, false to hide it |
| isolate boolean | true to isolate the layer |
isLayerVisible(node)
Returns true if the layer is visible.
Parameters
| node* Object | Layer node |
Returns
| type | description |
|---|---|
| boolean | true if the layer is visible |
setGroundShadowColor(color)
If enabled, set ground shadow color
Not applicable to 2D
Parameters
| color* THREE.Color |
setGroundShadowAlpha(alpha)
If enabled, set ground shadow alpha
Not applicable to 2D
Parameters
| alpha* number |
setGroundReflectionColor(color)
If enabled, set ground reflection color. This is reset to default when reflections toggled off.
Not applicable to 2D
Parameters
| color* THREE.Color |
setGroundReflectionAlpha(alpha)
If enabled, set ground reflection alpha. This is reset to default when reflections toggled off.
Not applicable to 2D
Parameters
| alpha* number |
getCutPlanes()
Returns a list of active cut planes
Not applicable to 2D
Returns
| type | description |
|---|---|
| Array.<Vector4> | List of Vector4 plane representation {x:a, y:b, z:c, w:d} |
setCutPlanes(planes)
Apply a list of cut planes
Not applicable to 2D
Parameters
| planes* Array.<Vector4> | List of Vector4 plane representation: {x:a, y:b, z:c, w:d} Plane general equation: ax + by + cz + d = 0 where a, b, and c are not all zero Passing an empty list or null is equivalent to setting zero cut planes |
getScreenShot(w, h, cb, overlayRenderer)
Captures the current screen image as Blob URL Blob URL can be used like a regular image url (e.g., window.open, img.src, etc) If width and height are 0, returns asynchronously and calls the callback with an image as Blob URL with dimensions equal to current canvas dimensions If width and height are given, returns asynchronously and calls the callback with the resized image as Blob URL If no callback is given, displays the image in a new window. Optional overlayRenderer can be supplied, in order to render an overlay on top of the renderer image.
Parameters
| w number | width of the requested image |
| h number | height of the requested image |
| cb function | callback |
| overlayRenderer function | overlayRenderer |
Returns
| type | description |
|---|---|
| string | screenshot image Blob URL, if no parameters are given |
worldToClient(point, camera)
Calculates the pixel position in client space coordinates of a point in world space. See also Viewer3D#clientToWorld.
Parameters
Returns
| type | description |
|---|---|
| Vector3 | Point transformed and projected into client space coordinates. Z value is 0. |
clientToWorld(clientX, clientY, ignoreTransparent, ignore2dModelBounds, ignore2dModelsOn3d)
Given coordinates in pixel screen space it returns information of the underlying geometry node. Hidden nodes will not be taken into account. Returns null if there is no geometry in the specified location. For 2d models, it will return null outside the paper, unless ignore2dModelBounds is true. See also Viewer3D#worldToClient.
- Activate a state through Viewer3D#activateLayerState.
Parameters
| clientX* Number | X coordinate where 0 is left |
| clientY* Number | Y coordinate where 0 is top |
| ignoreTransparent Boolean | Ignores transparent materials |
| ignore2dModelBounds boolean | For 2d models - whether to return a result outside of the model’s bounds. |
| ignore2dModelsOn3d boolean | Whether to ignore 2d models when in 3d mode. |
Returns
| type | description |
|---|---|
| Object, null | contains point attribute. 3d models have additional attributes. |
modelHasTopology()
Expose if the model has topology information downloaded. Only applicable to 3D models.
Returns
| type | description |
|---|---|
| boolean | value - Indicates whether the model has topology information. |
setSelectionColor(color, selectionType)
Changes the color of the selection for a particular selection type.
- Autodesk.Viewing.SelectionType.MIXED
- Sets the same color for regular and overlayed selection.
- Autodesk.Viewing.SelectionType.REGULAR
- Sets the color of regular selection.
- Autodesk.Viewing.SelectionType.OVERLAYED
- Sets the color of overlayed selection.
Parameters
| color* THREE.Color | |
| selectionType* number | a member of Autodesk.Viewing.SelectionMode. |
Examples
viewer.setSelectionColor(new THREE.Color(0xFF0000), Autodesk.Viewing.SelectionType.MIXED); // red color
set2dSelectionColor(color, opacity)
Changes the color of the selection for 2D drawings.
Parameters
| color* THREE.Color | |
| opacity* number |
Examples
viewer.set2dSelectionColor(new THREE.Color(0xFF0000), 0.1); // red color, opacity of 0.1
setTheme(name)
Sets the current UI theme of the viewer. Supported values are “light-theme” and “dark-theme”, which is the default.
Parameters
| name* string | Name of the theme, it will be added to the viewer’s container class list. |
setThemingColor(dbId, color, model, recursive)
Highlight an object with a theming color that is blended with the original object’s material.
Parameters
clearThemingColors(model)
Restore original colors for all themed shapes.
Parameters
| model | For multi-model support. |
setMaterialsToDefaults(model)
Restore original materials of a model if they were overwritten, e.g. by Autodesk.Viewing.Viewer3D#setView.”
Parameters
| model | For multi-model support. |
hideModel(model)
Temporarily remove a model from the Viewer, but keep loaders, materials, and geometry alive.
Reference Viewer3D#showModel
Parameters
| model* number, Model | model id or Model object |
Returns
| type | description |
|---|---|
| boolean | true indicates success, i.e., modelId referred to a visible model that is now hidden |
showModel(model, preserveTools)
Make a previously hidden model visible again.
Reference Viewer3D#hideModel
Parameters
| model* number, Model | model id or Model object |
| preserveTools* boolean | disable automatic activation of default tool |
Returns
| type | description |
|---|---|
| boolean | true indicates success, i.e., model referred to a hidden model that is now visible |
getVisibleModels()
Returns
| type | description |
|---|---|
| Array.<Model> |
getAllModels()
Returns all models loaded in the viewer.
Returns
| type | description |
|---|---|
| Array.<Model> |
|
getFirstModel()
Returns the first model, according to the environment. If we are in 2D, returns the first sheet. If we are in 3D, returns the first 3D model, regardless if a 2D sheet was loaded before. Note: If there’s only 2D models in a 3D environment it will return null.
Returns
| type | description |
|---|---|
| Model |
|
getUnderlayRaster(bubbleNode)
When loading a PDF document we optionally add a raster preview. This function returns the preview corresponding to the passed bubbleNode.
Parameters
| bubbleNode* |
Returns
| type | description |
|---|---|
| Array.<Model> |
disableHighlight(disable)
Disables roll-over highlighting.
Parameters
| disable* boolean | Indicates whether highlighting should be on or off. True to disable highlights, false to enable them. |
disableSelection(disable)
disable the selection of a loaded model.
Parameters
| disable* boolean | true to disable selection, false to enable selection. |
isHighlightDisabled()
check if the mouse-over highlight is disabled or not
isHighlightPaused()
check if the mouse-over highlight is paused or not
isHighlightActive()
check if the mouse-over highlight is active or not
isSelectionDisabled()
check if the selection of the loaded model is disabled or not
activateExtension(extensionID, mode)
Activates the extension based on the extensionID and mode given. By default it takes the first available mode in getmodes();
Parameters
| extensionID* string | The extension id. |
| mode string |
deactivateExtension(extensionID)
Dectivates the extension based on the extensionID specified.
Parameters
| extensionID* string | the extension ID |
Returns
| type | description |
|---|---|
| boolean |
|
isExtensionActive(extensionID, mode)
Check if the extension is active or not by passing the extensionID.
Parameters
| extensionID* string | the extension ID |
| mode* string | The model of the extension |
Returns
| type | description |
|---|---|
| boolean |
|
isExtensionLoaded(extensionID)
Check if the extension is loaded or not by passing the extensionID.
Parameters
| extensionID* string | the extension ID |
Returns
| type | description |
|---|---|
| boolean |
|
getLoadedExtensions()
Get a list of all the extensions that are currently loaded.
Returns
| type | description |
|---|---|
| Array.<string> |
|
getExtensionModes(extensionID)
Get a list of all the modes that are available for the given extensionID.
Parameters
| extensionID* string | the extension ID |
Returns
| type | description |
|---|---|
| Array.<string> |
|
hitTest(x, y, ignoreTransparent)
Returns the intersection information for point x,y. If no intersection is found this function will return null.
Parameters
| x* number | X-coordinate, i.e., horizontal distance (in pixels) from the left border of the canvas. |
| y* number | Y-coordinate, i.e., vertical distance (in pixels) from the top border of the canvas. |
| ignoreTransparent boolean | ignores any transparent objects that might intersect x,y |
Returns
| type | description |
|---|---|
| Intersection, null |
|
refresh(clear)
Clears the screen and redraws the overlays if clear is set to true. Only the overlays will be redrawn if clear is set to false. Should only be called when absolutely needed.
Parameters
| clear* boolean | clears the screen and redraws the overlays. |
chooseProfile()
Function that decides which Profile to use when a model is loaded for the first time.
Override this method to implement a different logic.
Returns
| type | description |
|---|---|
| Profile, null | a Profile |