General
start
start([callback: Function])
Start the space given by the user. Callback will be invoked with no parameter.
api.start(function() {
console.log('Viewer started');
});
stop
stop([callback: Function])
Stops/pauses the viewer, a call to start will resume the viewer. Callback will be invoked with no parameter.
api.stop(function() {
console.log('Viewer stopped');
});
startRender
startRender([callback: Function])
Starts render loop for viewer's engine
api.startRender(function() {
console.log('Render loop started');
});
stopRender
stopRender([callback: Function])
Stops render loop for viewer's engine
api.stopRender(function() {
console.log('Render loop stopped');
});
getScreenshot
getScreenshot(size: [width: number, height: number] | number, [callback: Function])
This function lets you take a screenshot of the viewer. The width and height arguments are the width and the height of the screenshot. The callback will be called with one parameter and will be a base64 encoded image.
api.getScreenshot([1920, 1080], function(base64) {
console.log(base64); // Result: 'data:image/png;base64,iVBORw0KG...'
});
api.getScreenshot(1920, function(base64) {
console.log(base64); // Result: 'data:image/png;base64,iVBORw0KG...'
});
setCanvasFocus
setCanvasFocus([callback: Function])
This function lets you set focus on viewer's canvas
api.setCanvasFocus(function () {
console.log('Focus set');
});
pickColor
pickColor(position: [x: number, y: number], [callback: Function])
Returns the color in the 3D viewer for the given screen coordinates. The callback returns a hex-color string.
api.pickColor([200, 300], function (colorHex) {
console.log(colorHex); // Result: #ffd700
});
getMinimapSize
getMinimapSize(callback: Function)
Gets current minimap size in screen pixels, if exists.
api.getMinimapSize(function (val) {
console.log(val); // Result: [100, 100]
});
showMinimap
showMinimap([callback: Function])
Show the minimap
api.showMinimap(function (val) {
console.log('Minimap visible');
});
hideMinimap
hideMinimap([callback: Function])
Hide the minimap
api.hideMinimap(function (val) {
console.log('Minimap hidden');
});
setQuality
setQuality(level: string, [callback: Function])
Set the quality level from 3d scene and reload the viewer after that automatically.
api.setQuality('HD', function () {
console.log('Level changed');
});
isAmbientSoundMuted
isAmbientSoundMuted([callback: Function])
Returns true if the ambient sound is muted, false otherwise.
api.isAmbientSoundMuted(function (isAmbientSoundMuted) {
console.log('Is ambient sound muted:', isAmbientSoundMuted);
});
muteAmbientSound
muteAmbientSound([callback: Function])
Mute the ambient sound in the background.
api.muteAmbientSound(function () {
console.log('Ambient sound muted');
});
unmuteAmbientSound
unmuteAmbientSound([callback: Function])
Unmute the ambient sound in the background.
api.unmuteAmbientSound(function () {
console.log('Ambient sound unmuted');
});
muteAllSound
muteAllSound([callback: Function])
Mute all sounds in the scene.
api.muteAllSound(function () {
console.log('All sounds muted');
});
areAllSoundsMuted
areAllSoundsMuted([callback: Function])
Returns true if all sounds are muted, false otherwise.
api.areAllSoundsMuted(function (areAllSoundsMuted) {
console.log('Are all sounds muted:', areAllSoundsMuted);
});
unmuteAllSound
unmuteAllSound([callback: Function])
Unmute all sounds in the scene.
api.unmuteAllSound(function () {
console.log('All sounds unmuted');
});
muteSpace
muteSpace([callback: Function])
Mute all sounds in the space including voice chat.
api.muteSpace(function () {
console.log('Space is muted');
});
unmuteSpace
unmuteSpace([callback: Function])
Unmute space sound.
api.unmuteSpace(function () {
console.log('Space is unmuted');
});
getIsSpaceMuted
getIsSpaceMuted(callback: Function)
Returns space's sound state.
api.getIsSpaceMuted(function (isMuted) {
console.log(isMuted); // Result: true | false
});
getVideos
getVideos(callback: Function)
Returns list of videos.
api.getVideos(function (videoIds) {
console.log(videoIds); // Result: ['1-video', '2-video']
});
playVideo
playVideo(videoId:string, [callback: Function])
Plays selected video. The videoId
is the ID of the video, which can be found via getVideos.
api.playVideo('1-video', function () {
console.log('Video is playing');
});
pauseVideo
pauseVideo(videoId:string, [callback: Function])
Pauses selected video. The videoId
is the ID of the video, which can be found via getVideos.
api.pauseVideo('1-video', function () {
console.log('Video is paused');
});
setVideoTime
setVideoTime(videoId:string, time: number, [callback: Function])
Set current time for selected video. The videoId
is the ID of the video, which can be found via getVideos. The time
is new current time in seconds.
api.setVideoTime('1-video', 10, function () {
console.log('Video current time is set to 10 sec');
});
getVideoProgressionEvents
getVideoProgressionEvents(videoId:string, [callback: Function])
Turns on progress events for the specified video. The videoId
is the ID of the video, which can be found via getVideos. The progress event can then be listened to via the video.progress
event.
api.getVideoProgressionEvents('1-video', function () {
console.log('Video progression events turned on');
});
stopVideoProgressionEvents
stopVideoProgressionEvents(videoId:string, [callback: Function])
Turns off progress events for the specified video. The videoId
is the ID of the video, which can be found via getVideos.
api.stopVideoProgressionEvents('1-video', function () {
console.log('Video progression events turned off');
});
getWorldToScreenCoordinates
getWorldToScreenCoordinates(coords: [x: number, y: number, z: number], [callback: Function])
Returns the screen coordinates for the given world coordinates.
api.getWorldToScreenCoordinates([1, 1, 1], function (coords) {
console.log(coords); // Result: [100, 100]
});
getScreenToWorldCoordinates
getScreenToWorldCoordinates(coords: [x: number, y: number], [callback: Function])
Returns the world coordinates for the given screen coordinates. The first hit point in the scene.
api.getScreenToWorldCoordinates([100, 100], function (coords) {
console.log(coords); // Result: [1, 1, 1]
});
importMesh
importMesh(url: string, filename: string, [options: Record<string, any>], [callback: Function])
Load gltf|glb file into scene. supports animation.
arguments:
- url: url where the file is located
- filename: name of gltf|glb file
- options: key:value object with more options
- transform: transform coordinates for the imported mesh
- skeletonsEnabled: boolean gets or sets a boolean indicating if skeletons are enabled on this scene
- playAnimation: string play named animation if existing
- callback: function with arry of nodeIds as arguments
api.importMesh(
'https://www.example.com/path/to/file/',
'example-file.glb',
{
transform: {
position: [Math.random(), 0, Math.random()],
rotation: [0, Math.random() * 2 * Math.PI, 0],
scale: [1, 1, 1],
},
skeletonsEnabled: true,
playAnimation: true,
},
function (result) { console.log(result) }
);
loadAssetContainer
loadAssetContainer(url: string, filename: string, [options: Record<string, any>], [callback: Function])
Load gltf|glb file as asset container and optionally creates instances of them.
arguments:
- url: url where the file is located
- filename: name of gltf|glb file
- options: key:value object with more options
- instanceTransforms: array of transform coordinates for the created instances
- transform: transform coordinates for the root node
- skeletonsEnabled: boolean gets or sets a boolean indicating if skeletons are enabled on this scene
- cloneMaterials: boolean defines an optional boolean that defines if materials must be cloned as well (false by default)
- doNotInstantiate: boolean defines if the model must be instantiated or just cloned
- playAnimation: string play named animation if existing
- callback: function with arry of nodeIds as arguments
api.loadAssetContainer(
'https://www.example.com/path/to/file/',
'example-file.glb',
{
instanceTransforms: [
{
position: [Math.random(), 0, Math.random()],
rotation: [0, Math.random() * 2 * Math.PI, 0],
scale: [1, 1, 1],
},
{
position: [Math.random(), 0, Math.random()],
rotation: [0, Math.random() * 6, 0],
scale: [1, 1, 1],
},
],
transform: {
position: [Math.random(), 0, Math.random()],
rotation: [0, Math.random() * 2 * Math.PI, 0],
scale: [2, 2, 2],
},
skeletonsEnabled: true,
cloneMaterials: false,
doNotInstantiate: false,
playAnimation: true,
},
function (result) { console.log(result) }
);
closeModal
closeModal(modalName:string, [callback: Function])
Closes an opened modal with the given modal name. The modalName
can be a known name of an opened modal or a string received with the modal.open
event when a modal is opened.
api.closeModal('Confirmation-dialog', function () {
console.log('Confirmation-dialog modal is closed');
});
openTextChat
openTextChat([callback: Function])
Opens the text chat box.
api.openTextChat(function () {
console.log('Text chat box is opened.');
});
closeTextChat
closeTextChat([callback: Function])
Closes the text chat box.
api.closeTextChat(function () {
console.log('Text chat box is closed.');
});