General
load
load(spaceId: string, [callback: Function])
Loads a space with the given space ID. This function is typically called internally during the initialization process, but can also be used to load a different space instance.
The spaceId
is the unique identifier of the space to load.
api.load('123456789123456789', function() {
console.log('Space loaded successfully');
});
2
3
start
start([callback: Function])
Starts the space viewer. The callback will be invoked with no parameters.
api.start(function() {
console.log('Viewer started');
});
2
3
stop
stop([callback: Function])
Stops/pauses the viewer. A call to start will resume the viewer. The callback will be invoked with no parameters.
api.stop(function() {
console.log('Viewer stopped');
});
2
3
startRender
startRender([callback: Function])
Starts the render loop for the viewer's engine.
api.startRender(function() {
console.log('Render loop started');
});
2
3
stopRender
stopRender([callback: Function])
Stops the render loop for the viewer's engine.
api.stopRender(function() {
console.log('Render loop stopped');
});
2
3
getScreenshot
getScreenshot(size: [width: number, height: number] | number, callback: Function, [fileType: string])
This function allows you to take a screenshot of the viewer. The width and height arguments specify the dimensions of the screenshot. The optional fileType
parameter accepts "jpg", "png", or "webp" (defaults to "png"). The callback will be called with one parameter containing a base64-encoded image.
// Default PNG format
api.getScreenshot([1920, 1080], function(base64) {
console.log(base64); // Result: 'data:image/png;base64,/9j/4AAQ...'
});
// Explicit JPG format
api.getScreenshot([1920, 1080], function(base64) {
console.log(base64); // Result: 'data:image/jpeg;base64,/9j/4AAQ...'
}, 'jpg');
// PNG format with transparency support
api.getScreenshot([1920, 1080], function(base64) {
console.log(base64); // Result: 'data:image/png;base64,iVBORw0KG...'
}, 'image/png');
// Single number size with File type
api.getScreenshot(1920, function(base64) {
console.log(base64); // Result: 'data:image/png;base64,iVBORw0KG...'
}, 'image/png');
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
setCanvasFocus
setCanvasFocus([callback: Function])
This function allows you to set focus on the viewer's canvas.
api.setCanvasFocus(function () {
console.log('Focus set');
});
2
3
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
});
2
3
getMinimapSize
getMinimapSize(callback: Function)
Gets current minimap size in screen pixels, if exists.
api.getMinimapSize(function (val) {
console.log(val); // Result: [100, 100]
});
2
3
showMinimap
showMinimap([callback: Function])
Show the minimap
api.showMinimap(function (val) {
console.log('Minimap visible');
});
2
3
hideMinimap
hideMinimap([callback: Function])
Hide the minimap
api.hideMinimap(function (val) {
console.log('Minimap hidden');
});
2
3
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');
});
2
3
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);
});
2
3
muteAmbientSound
muteAmbientSound([callback: Function])
Mute the ambient sound in the background.
api.muteAmbientSound(function () {
console.log('Ambient sound muted');
});
2
3
unmuteAmbientSound
unmuteAmbientSound([callback: Function])
Unmute the ambient sound in the background.
api.unmuteAmbientSound(function () {
console.log('Ambient sound unmuted');
});
2
3
muteAllSound
muteAllSound([callback: Function])
Mute all sounds in the scene.
api.muteAllSound(function () {
console.log('All sounds muted');
});
2
3
areAllSoundsMuted
areAllSoundsMuted([callback: Function])
Returns true if all sounds are muted, false otherwise.
api.areAllSoundsMuted(function (areAllSoundsMuted) {
console.log('Are all sounds muted:', areAllSoundsMuted);
});
2
3
unmuteAllSound
unmuteAllSound([callback: Function])
Unmute all sounds in the scene.
api.unmuteAllSound(function () {
console.log('All sounds unmuted');
});
2
3
muteSpace
muteSpace([callback: Function])
Mute all sounds in the space including voice chat.
api.muteSpace(function () {
console.log('Space is muted');
});
2
3
unmuteSpace
unmuteSpace([callback: Function])
Unmute space sound.
api.unmuteSpace(function () {
console.log('Space is unmuted');
});
2
3
getIsSpaceMuted
getIsSpaceMuted(callback: Function)
Returns space's sound state.
api.getIsSpaceMuted(function (isMuted) {
console.log(isMuted); // Result: true | false
});
2
3
getVideos
getVideos(callback: Function)
Returns list of videos.
api.getVideos(function (videoIds) {
console.log(videoIds); // Result: ['1-video', '2-video']
});
2
3
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');
});
2
3
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');
});
2
3
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');
});
2
3
muteVideo
muteVideo(videoId: string, [callback: Function])
Mutes a specific video. The videoId
is the ID of the video, which can be found via getVideos.
api.muteVideo('1-video', function () {
console.log('Video is muted');
});
2
3
unmuteVideo
unmuteVideo(videoId: string, [callback: Function])
Unmutes a specific video. The videoId
is the ID of the video, which can be found via getVideos.
api.unmuteVideo('1-video', function () {
console.log('Video is unmuted');
});
2
3
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');
});
2
3
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');
});
2
3
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]
});
2
3
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]
});
2
3
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) }
);
2
3
4
5
6
7
8
9
10
11
12
13
14
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) }
);
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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');
});
2
3
openTextChat
openTextChat([callback: Function])
Opens the text chat box.
api.openTextChat(function () {
console.log('Text chat box is opened.');
});
2
3
closeTextChat
closeTextChat([callback: Function])
Closes the text chat box.
api.closeTextChat(function () {
console.log('Text chat box is closed.');
});
2
3