Methods¶
The 270 Viewer opens itself up to a number of methods. These are available after the Viewer is done initialising, ie on onLoadComplete()
.
disableAutoRotate¶
Disables or enables rotation of the camera around the Asset.
Identical to enableAutoRotate(false)
.
el.disableAutoRotate(true, -2);
Parameters:
- disabled:
- Type:
Boolean
- Default:
true
- Type:
- speed:
- Type:
Float
optional - Default:
previous value
Use a negative value to rotate counter clockwise.
- Type:
disableControls¶
Disallow or allow user interaction (zoom, pan, rotate).
Identical to enableControls(false)
.
el.disableControls(true);
Parameters:
- disabled:
- Type:
Boolean
- Default:
true
- Type:
disableDamping¶
Disable or enable camera weight movement.
Identical to enableDamping(false)
.
el.disableDamping(true, factor);
Parameters:
- disabled:
- Type:
Boolean
- Default:
true
- Type:
- factor:
- Type:
Float
- Default:
0.15
- Type:
Factor is clamped between 0.001 and 1 to avoid erratic camera behavior
disablePan¶
Disallow or allow user camera panning.
Identical to enablePan(false)
.
Camera panning can be disorienting for users and is therefore not recommended to enable unless you really need it. Use resetPan()
to restore original camera pan position.
el.disablePan(true);
Parameters:
- disabled:
- Type:
Boolean
- Default:
true
- Type:
disableRotate¶
Disallow or allow user camera rotation.
Identical to enableRotate(false)
.
el.disableRotate(true);
Parameters:
- disabled:
- Type:
Boolean
- Default:
true
- Type:
disableShadow¶
Hides or shows a shadow below the asset.
Identical to enableShadow(false)
.
el.disableShadow(true, false);
Parameters:
- disabled:
- Type:
Boolean
- Default:
true
- Type:
- shadowSpace:
- Type:
Boolean
optional - Default:
previous value
- Type:
disableZoom¶
Disallow or allow user camera zoom.
Identical to enableZoom(false)
.
el.disableZoom(true);
Parameters:
- disabled:
- Type:
Boolean
- Default:
true
- Type:
enableAutoRotate¶
Enable or disable rotation of the camera around the Asset.
Identical to disableAutoRotate(false)
.
el.enableAutoRotate(true, -2);
Parameters:
- enabled:
- Type:
Boolean
- Default:
true
- Type:
- speed:
- Type:
Float
optional - Default:
previous value
Use a negative value to rotate counter clockwise.
- Type:
enableControls¶
Allow or disallow user interaction (zoom, pan, rotate).
Identical to disableControls(false)
.
el.enableControls(true);
Parameters:
- enabled:
- Type:
Boolean
- Default:
true
- Type:
enableDamping¶
Enable or disable camera weight movement.
Identical to disableDamping(false)
.
el.enableDamping(true, factor);
Parameters:
- enabled:
- Type:
Boolean
- Default:
true
- Type:
- factor:
- Type:
Float
- Default:
0.15
- Type:
Factor is clamped between 0.001 and 1 to avoid erratic camera behavior
enablePan¶
Allow or disallow user camera panning.
Identical to disablePan(false)
.
Camera panning can be disorienting for users and is therefore not recommended to enable unless you really need it. Use resetPan()
to restore original camera pan position.
el.enablePan(true);
Parameters:
- enabled:
- Type:
Boolean
- Default:
true
- Type:
enableRotate¶
Allow or disallow user camera rotation.
Identical to disableRotate(false)
.
el.enableRotate(true);
Parameters:
- enabled:
- Type:
Boolean
- Default:
true
- Type:
enableShadow¶
Shows or hides a shadow below the asset.
Identical to disableShadow(false)
.
el.enableShadow(true, false);
Parameters:
- enabled:
- Type:
Boolean
- Default:
true
- Type:
- shadowSpace:
- Type:
Boolean
optional - Default:
previous value
- Type:
enableZoom¶
Allow or disallow user camera zoom.
Identical to disableZoom(false)
.
el.enableZoom(true);
Parameters:
- enabled:
- Type:
Boolean
- Default:
true
- Type:
getAnimation¶
Returns passed available animation state.
el.getAnimation('Walk');
Result:
{name: 'Walk', loop: true, reverse: false, state: 'stopped'},
getAnimations¶
Returns all available animations and their states.
el.getAnimations();
Result:
[
{name: 'Walk', loop: true, reverse: false, state: 'stopped'},
{name: 'Survey', loop: false, reverse: false, state: 'running'},
{name: 'Jump', loop: false, reverse: false, state: 'paused'},
]
getAnimationNames¶
Returns all available animation names.
el.getAnimationNames();
Result:
['Walk', 'Survey', 'Jump']
getAmbientIntensity¶
Returns the current lighting's ambient intensity:
el.getAmbientIntensity()
Result:
'1'
getCameraPosition¶
Returns the current camera position as an object:
el.getCameraPosition()
Result:
{'zoom': 0-1, 'theta': 0-360, 'phi': 0-180}
getGroup¶
Returns a specific Group by name, and its containing Objects' names.
A Group is a collection of associated Objects, as specified in the asset.
el.getGroup('Group')
Result:{name: 'Group', objects: ['Base','Plane']}
Parameters:
- name: Type:
string
The name of the group to return
getGroups¶
Returns all loaded asset Groups and their contents. A Group is a collection of associated Objects, as specified in the asset.
el.getGroups()
Result:
[
{name: 'Group', objects: ['Base','Plane']},
{name: 'SecondGroup', objects: ['Cube, Mesh']}
]
getGroupNames¶
Returns the names of all available Groups. A Group is a collection of associated Objects, as specified in the asset.
el.getGroupNames()
Result:
['Group','SecondGroup']
getHorizontalRotation¶
Returns the current horizontal rotation limits:
el.getHorizontalRotation()
Result:
{min: -Infinity, max: Infinity}
getImage¶
Returns a snapshot of the Viewer as either an image or base64 string, with passed options.
el.getImage({
size: {
width: 200,
height: 200
},
type: 'jpg',
cameraPosition: {
zoom: 1,
theta: 75,
phi: 35
}
})
Use el.getImage()
without any options to get a snapshot as is, as a base64 string.
Parameters
- options:
- Type:
object
-
keyvalues:
- size:
{width: int, height: int}
The dimensions of the image, capped at 2048x2048. Defaults to current DOM size. - type:
png
|jpeg
|jpg
|webp
Filetype of the returned image. Default ispng
-
cameraPosition: {CameraPosition}
Position of the camera for the snapshot. Defaults toel.getCameraPosition()
Pass
auto
instead of{CameraPosition}
to get a snapshot from the opening angle, regardless of user interaction -
background:
hexstring
The background color of the image. Defaults to current color.- transparent:
Boolean
Removes the background color completely. Ignored iftype
isjpeg|jpg
. Default isfalse
. - download:
Boolean
Prompts the user to download the image to disk. Default isfalse
. - filename:
string
The filename of the downloaded image. Ignored if download is false. Default is'snapshot'
- scale:
cover
|contain
How to scale the Viewer into the passedsize
. Default iscontain
.
- transparent:
contain
scales the image as large as possible within its container without cropping or stretching the image.cover
scales the image (while preserving its ratio) to the smallest possible size to fill the container (that is: both its height and width completely cover the container), leaving no empty space.
- size:
- Type:
getLighting¶
Returns the current lighting settings as an object:
el.getLighting()
Result:
{type: 'neutral', ambientIntensity: 0, sunIntensity: 0, exposure: 1, rotation: 0}
getLightingExposure¶
Returns the current lighting's exposure:
el.getLightingExposure()
Result:
'1.1'
getLightingRotation¶
Returns the current lighting's rotation in degrees:
el.getLightingRotation()
Result:
'45'
getLightingType¶
Returns the current lighting type:
el.getLightingType()
Result:
'neutral'
getSettings¶
Returns the Viewer's settings as an object.
el.getSettings('state')
Result:
{ ambientIntensity: 0, autoplayAnimation: false, autorotate: false, autorotateSpeed: -2, background: '#ff0000', cameraPosition: '30,75', cameraZoomLevel: 0.39, container: 'div.viewer', customLightingData: {}, damping: true, forceLoad: false, horizontalRotation: '-Infinity,Infinity', lazyLoad: true, lighting: 'neutral', lightingExposure: 1, lightingRotation: 0, logo: true, loopAnimation: false, model: 'generic-polo-customisable', onCreate: () => {}, onLoadComplete: () => {}, onLoadFailure: () => {}, opacity: 0.2, pan: false, plugins: ['customiser'], reverseAnimation: false, rotate: true, rotateSpeed: 1, shadow: true, shadowBlur: 6, shadowDarkness: 1, shadowOpacity: 0.4, shadowSpace: true, sunIntensity: 0, verticalRotation: '0,180', zoom: true }
Parameters:
- type
- Type:
string
- Default:
state
The state to return. Options are:
api
: the settings as retrieved from the api
init
: the settings from when the viewer was created
state
: the current settings
- Type:
getShadow¶
Returns the current shadow's settings as an object:
el.getShadow()
Result:
{visibile: true, spaced: false, darkness: 1, blur: 6, opacity: 0.4}
getShadowBlur¶
Returns the current shadow's blur setting:
el.getShadowBlur()
Result:
0.4
getShadowDarkness¶
Returns the current shadow's darkness setting:
el.getShadowDarkness()
Result:
1
getShadowOpacity¶
Returns the current shadow's opacity setting:
el.getShadowOpacity()
Result:
0.4
getSunIntensity¶
Returns the current lighting's directional light intensity:
el.getSunIntensity()
Result:
'1.2'
getObject¶
Returns a specific loaded asset objects by name.
el.getObject('Base')
Result:{name: 'Base', texture: {width: 1024, height: 1024}}
Parameters:
- name:
string
The name of the object to return
getObjects¶
Returns all loaded asset objects' names and texturesizes (if applicable), as an Array of Objects
el.getObjects()
Result:
[{name: 'Base', texture: {width: 1024, height: 1024}}, {name: 'Plane', texture: null}]
getObjectNames¶
Returns the names of all loaded asset objects.
el.getObjectNames()
Result:
['Base','Plane']
getVariant¶
Returns the current active variants, if applicable.
el.getVariant()
Result:
'leather'
getVariants¶
Returns the names of all loaded asset available variants, if any.
el.getVariants()
Result:
['leather','fabric']
getVerticalRotation¶
Returns the current vertical rotation limits:
el.getVerticalRotation()
Result:
{min: 45, max: 135}
pauseAnimation¶
Pauses the Asset's passed animation. Use startAnimation()
to resume the animation.
Passing no animation name pauses all running animations.
el.pauseAnimation({name: `Walk`});
Parameters:
- name:
- Type:
comma separated string
- Default:
''
Comma separated list of animation names.
- Type:
requestRender¶
Request a new frame to render if one wasn't queued already.
el.requestRender();
reset¶
Reset all Viewer settings back to the initially loaded state, either based on API settings or user initiated settings.
el.reset(false);
Parameters:
- useAPI:
- Type:
Boolean
- Default:
false
Whether to use the API (true
) or.create
directed (false
) defaults.
- Type:
resetPan¶
Reset the camera origin to the center of the loaded Asset. Useful after the user has panned away from the Asset when pan: true
.
el.resetPan();
resizeViewer¶
Force resize of the viewer and ratio. This is useful if the Viewer's container resizes without a window.resize event being triggered.
el.resizeViewer();
setAmbientIntensity¶
Sets the loaded lighting's minimal brightness.
Shorthand for setLighting({ambientIntensity: Float})
.
As proper model visualisation is dependant on correct lighting it is recommended to only configure this when needed.
el.setAmbientIntensity(0.5);
Parameters:
- intensity:
- Type:
Float
- Default: implicit
The lighting's minimal brightness.
Passing nothing will reset the intensity to the loaded lighting's default value.
- Type:
setAutoRotateSpeed¶
Sets the autorotate speed. Use a negative value for a clockwise rotation. Default is -2
.
el.setAutoRotateSpeed(3);
Parameters:
- speed:
Float
The camera's rotation speed.
setBackground¶
Sets the Viewer's background to a solid color (css value
), a gradient to infer depth (comma separated css values
), or an image (url
).
Note: When using a gradient or image, the
opacity
option is ignored.
el.setBackground('#ff0000', 0.5);
Parameters:
- color:
- Type:
css value
|comma separated css values
|url
The color or image to set.
- Type:
- opacity:
- Type:
Float
optional - Default:
previous value
The opacity of the background color ranging from0
to1
, where1
is fully opaque.
This value is ignored ifcolor
is set to something different than a singularcss value
.
- Type:
setCameraPosition¶
Move the camera to passed position.
el.setCameraPosition({
zoom: 0.1,
phi: 90,
theta: 130
});
All parameters in the object are optional.
Omitting an option will default to the current value of that option. For example, el.setCameraPosition({zoom:0})
will zoom the camera out while maintaining phi and theta positions
Use presets to automatically set the phi and theta to a cardinal direction.
Parameters:
- options
- Type:
object
- keyvalues:
- zoom:
Float
The zoom ratio ranging from0
to1
, where0
is furthest away. Defaults tocurrent value
. - phi:
Float
The vertical position of the camera in degrees, ranging from0
to180
, where0
is top. Defaults tocurrent value
.This value is limited by the current
verticalRotation
limits - theta:
Float
The horizontal position of the camera in degrees, ranging from0
to360
. Defaults tocurrent value
.This value is limited by the current
horizontalRotation
limits - preset:
string
Set both horizontal and vertical position to match one of the cardinal options:top
,bottom
,left
,right
,front
,back
. Using a preset overrides the passedphi
andtheta
values.This value is limited by the current
horizontalRotation
andverticalRotation
limits
- zoom:
- Type:
setHorizontalRotation¶
Limit the horizontal rotation of the camera.
el.setHorizontalRotation(20, 160);
Parameters
- min:
Float
Number ranging from0
to360
. - max:
Float
Number ranging from0
to360
.
Passing
free
as either value will remove any limits
setLighting¶
Change the lighting preset in the Viewer, along with optional granular lighting controls.
Returns a promise.
el.setLighting({
type: 'sunset',
ambientIntensity: 1,
sunIntensity: 0.4,
exposure: 1,
rotation: 45
});
All parameters in the object are optional. Omitting an option will default to the current value of that option.
Parameters
- preset:
- Type:
String
- Default:
traditional
Options areneutral
,cannon
,city
,courtyard
,forest
,interior
,night
,studio
,sunrise
,sunset
,traditional
,custom
.
- Type:
- ambientIntensity:
- Type:
Float
optional
The lighting's minimal brightness.
- Type:
- sunIntensity:
- Type:
Float
optional
The lighting's directional light brightness.
- Type:
- exposure:
- Type:
Float
optional
The lighting's exposure. Lower values result in darker lighting.
- Type:
- rotation:
- Type:
Float
optional
The lighting's rotation in degrees.
- Type:
- customLightingData:
- Type:
Object
optional
Adds a fully custom lighting setup to thecustom
slot. Refer to customLightingData options for a full data model example.
This is an advanced feature and recommended to only pass if you know what you're doing.
- Type:
As proper model visualisation is dependant on correct lighting it is recommended to only configure ambientIntensity
, sunIntensity
, exposure
, rotation
when needed.
setLightingType¶
Loads a lighting preset.
Shorthand for setLighting({type: preset})
.
Loading a preset sets all other lighting options to the passed preset's defaults.
el.setLightingType('sunset');
Parameters
- preset:
- Type:
String
- Default:
traditional
Options areneutral
,cannon
,city
,courtyard
,forest
,interior
,night
,studio
,sunrise
,sunset
,traditional
.
- Type:
setLightingExposure¶
Sets the exposure of the loaded lighting.
Shorthand for setLighting({exposure: Float})
.
el.setLightingExposure(1.2);
Parameters
- exposure:
- Type:
Float
- Default: implicit
Exposure of the loaded lighting. A lower number results in a darker lighting.
Passing nothing will reset the exposure to the loaded lighting's default value.
- Type:
setLightingRotation¶
Sets the rotation of the loaded lighting.
Shorthand for setLighting({rotation: Float})
.
el.setLightingRotation(45);
Parameters
- exposure:
- Type:
Float
- Default: implicit
Rotation of the loaded lighting in degrees.
Passing nothing will reset the rotation to the loaded lighting's default value.
- Type:
setOpacity¶
Set the Viewer's background opacity without changing the background color.
el.setOpacity(1);
Parameters
- opacity:
- Type:
Float
Range between0
and1
, where1
is fully opaque.
- Type:
setRotationSpeed¶
Set the sensitivity of the camera rotation. A higher value results in a faster rotating camera.
el.setRotationSpeed(2);
Parameters
- speed:
- Type:
Float
- Default:
options.rotateSpeed
|1
- Type:
setShadow¶
Rerender a shadow with the passed properties. Returns a promise.
el.setShadow({visible: true, spaced: true, darkness: 4, opacity: 0.4, blur: 2});
Parameters
- visible:
- Type:
Boolean
optional - Default: current shadow's visibility
Toggles visiblity of the shadow.
- Type:
- spaced:
- Type:
Boolean
optional - Default: current shadow's space
When true, adds space between the model, making the asset appear to float.
- Type:
- darkness:
- Type:
Float
optional - Default:
options.shadowDarkness
- Type:
- opacity:
- Type:
Float
optional - Default:
options.shadowOpacity
- Type:
- blur:
- Type:
Float
optional - Default:
options.shadowBlur
- Type:
setShadowBlur¶
Set the blur of the shadow.
Shorthand for setShadow({blur: Float})
.
el.setShadowBlur(0.4);
Parameters
- blur:
- Type:
Float
- Default:
options.shadowBlur
|6
- Type:
setShadowDarkness¶
Set the darkness of the shadow.
Shorthand for setShadow({darkness: Float})
.
el.setShadowDarkness(2);
Parameters
- darkness:
- Type:
Float
- Default:
options.shadowDarkness
|1
- Type:
setShadowOpacity¶
Set the opacity of the shadow.
Shorthand for setShadow({opacity: Float})
.
el.setShadowOpacity(1);
Parameters
- opacity:
- Type:
Float
- Default:
options.shadowOpacity
|0.4
- Type:
setSunIntensity¶
Sets the loaded lighting's minimal brightness.
Shorthand for setLighting({sunIntensity: Float})
.
As proper model visualisation is dependant on correct lighting it is recommended to only configure this when needed.
el.setSunIntensity(0.5);
Parameters:
- intensity:
- Type:
Float
- Default: implicit
The lighting's directional light brightness.
Passing nothing will reset the intensity to the loaded lighting's default value.
- Type:
setVariant¶
Applies the passed variant to the loaded Asset and optionally renders a new frame.
A variant is a preconfigured set of colors and/or materials, available in the loaded Asset.
Can be used as a promise.
el.setVariant({variant: 'leather', render: true})
Parameters:
- variant: Type:
string
The name of the desired variant. UsegetVariants()
to find the available variants. - render:
- Type:
Boolean
- Default:
true
Immediately renders a new frame whentrue
. If you are changing multiple items in the Viewer, consider setting this tofalse
and callrequestRender()
manually to prevent unneeded frames.
- Type:
setVerticalRotation¶
Limit the vertical rotation of the camera.
el.setVerticalRotation(45,135);
Parameters
- min:
Float
Number ranging from0
to180
. - max:
Float
Number ranging from0
to180
.
Passing
free
as either value will remove any limits
startAnimation¶
Starts the passed animations.
Passing no animation name starts all available animations.
el.startAnimation({
name: `Walk`,
loop: true,
reverse: false
});
Parameters
- name:
- Type:
comma separated string
- Default:
''
Comma separated list of animation names.
- Type:
- loop:
- Type:
Boolean
- Default: implicit Loops the animation(s). If nothing is passed it will default to the last passed state.
- Type:
- reverse:
- Type:
Boolean
- Default: implicit Reverses the animation(s) when played. If nothing is passed it will default to the last passed state.
- Type:
stopAnimation¶
Stops and rewinds the passed animations.
Passing no animation name stops all running animations.
el.stopAnimation({name: `Walk`});
Parameters:
- name:
- Type:
comma separated string
- Default:
''
Comma separated list of animation names.
- Type: