Resources

3D Webviewer JS Component

Overview

The viewer component has been developed to be a portable JavaScript Universal Module Definition (UMD) library able to be dynamically loaded and included in web apps or web components. The library includes all dependencies in the packaged component and is therefore standalone and has no dependencies.

Library Functions, Parameters, and Integration

To integrate the viewer into an existing web app or component requires including the UMD module vnview.js using an HTML script tag or dynamic loading method.

The library currently exposes one function, createvnviewer, on the global namespace vnview which creates and returns a viewer class that can be used to load and render content.

1
var viewer = vnview.createvnviewer(element, options);

The element parameter is an HTML5 DOM element that will contain the viewer. The DOM element will be used as the parent element for the <model-viewer> element.

The options parameter is a JavaScript object that defines parameters for the setup and context of the Viewer. To use an embedded viewer, please set the value of embedded to true. The following options object shows all of the possible settings that can be configured within the Viewer.

1
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
29
30
31
32
33
34
35
36
37
options = {
onProgress: (event) => {},
onSuccess: (event) => {},
onError: (event) => {},
embedded: true,
disablePoster: false,
pipelineUuid: ‘string’,
thumbnailUrl: ”,
showModelOnInteraction: false,
viewerConfigs: {
rendererConfigs: {
autoRotate: false,
showEnvironment: false,
environment: ‘Default’,
exposure: 1.0,
shadowIntensity: 4.0,
shadowSoftness: 0,
presetBg: ‘Default’,
yaw: ‘auto’,
pitch: ‘auto’,
distance: ‘auto’,
fov: ‘auto’,
targetPointX: ‘auto’,
targetPointY: ‘auto’,
targetPointZ: ‘auto’,
showHotspotNumbers: false,
orientation: {
roll: 0,
pitch: 0,
yaw: 0
},
disableZoom: false,
shadowFloorPosition: 0,
rotationSpeed: ‘100%’
}
}
}

onProgress – Any action desired while GLB is loading in viewer.

onSuccess – Any action desired on successful load of GLB in viewer.

onError – Any action desired on unsuccessful load of GLB in viewer. “Error” event can be fired for two reasons: ‘loadfailure’ and ‘webglcontextlost’. (See error under Eventshttps://modelviewer.dev/docs/index.html)

disablePoster – Disables the poster image that is displayed before the asset loads. Default is false.

pipelineUuid – The UUID of the Pipeline used for processing. Currently, the pipelineUuid only affects the viewer if it is the Custom Jewelry pipeline, but in the future, other pipelines may also have their own custom viewer settings and/or rendering. For Custom Jewelry, gem rendering will be applied. Otherwise, the pipelineUuid value is optional.

thumbnailUrl – The URL of the thumbnail to use as the poster image. The thumbnailUrl is optional; if a value is not provided, then the viewer will automatically try to access the thumbnail generated by the VNTANA Platform.

showModelOnInteraction – If set to true, the model will not be loaded until the user hovers over the viewer. This config is optional. If a value is not provided, the viewer will use its default behavior of dismissing the poster as soon as the asset has finished loading.

viewerConfigs – Object that holds rendererConfigs

rendererConfigs – Object with all of the saved configurations for the viewer settings. A null value indicates that no settings have been saved, and all values will be set to their default.

autoRotate – Enable/disable auto-rotation of model. Default is false.

showEnvironment – Show/hide the HDRI set under environment. If value is true, viewer background will be set to the environment map, and any preset background (presetBg) will be overridden. Default is false.

environment – Sets the environment map with the provided HDRI file. Default is “Default”

exposure – Sets the exposure. Default is 1.0.

shadowIntensity – Sets the intensity of the shadow cast by the model. Default is 4.0. Ranges from 0-10.

shadowSoftness – Sets the softness of the shadow. If shadowIntensity is set to 0, shadowSoftness has no effect. Default is 0. Ranges from 0-1. (Note: Softer shadows render faster).

presetBg – Sets the background color of the viewer. Default is “Default” (white background). In the future, we can expand the background options by accepting two HEX values for the radial gradient.

yaw – Sets the first value of the camera-orbit attribute, which controls the asset’s rotation about the Normal axis. Units are in radians. Default value is “auto”.

pitch – Sets the second value of the camera-orbit attribute, which controls the asset’s rotation about the Transverse axis. Units are in radians. Default value is “auto”.

distance – Sets the third value of the camera-orbit attribute, which controls the camera’s distance from the asset, in meters. Default value is “auto”.

fov – Sets the field of view of the camera, in degrees. Default value is “auto”.

targetPointX – Sets the X coordinate of the target point (pivot point). Default value is “auto,” which is the automatically calculated center of the bounding box on the X axis.

targetPointY – Sets the Y coordinate of the target point (pivot point). Default value is “auto,” which is the automatically calculated center of the bounding box on the Y axis.

targetPointZ – Sets the Z coordinate of the target point (pivot point). Default value is “auto,” which is the automatically calculated center of the bounding box on the Z axis.

showHotspotNumbers – Enable/disable hotspot numbers in Embed links. Default is false (numbers are not shown in hotspot pins).

orientation – Object that contains properties that set the asset’s orientation. Roll specifies the rotation about the Z-axis. Pitch specifies the rotation about the X-axis. Yaw specifies the rotation about the Y-axis. The default for all values (row, pitch, yaw) is 0. Changing any of these settings will reprocess the asset to change its inherent orientation, so that it appears correctly in both the viewer and in AR.

disableZoom – Disables the ability for a user to zoom in and out of the model. Default is false.

shadowFloorPosition – Sets the position of the shadow relative to the model. Negative values move the shadow floor down, farther away from the model, and positive values move the shadow floor up, closer to the model. Default is 0.

rotationSpeed – Sets the rotation speed of the model when autoRotate is enabled. The speed can be set as a percentage relative to the default, which is 100%. For example, to have the model rotate 3x as fast, the rotationSpeed value should be set to 300%. Negative values cause the model to rotate in the opposite direction (clockwise vs. counterclockwise).

Viewer Content

GLTF content can be loaded into the Viewer using the loadObject(url) method which takes a url to the model file:

1
viewer.loadObject(url)

Viewer Styles

We recommend including the following rules in your style sheet, in order for the most user friendly experience with the 3D Viewer.

1
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
model-viewer {
width: 100%;
height: 100%;
}
 
#enterFullscreen {
position: absolute;
right: 16px;
bottom: 16px;
width: 40px;
height: 40px;
background: #dbdbdb url(‘https://storage.googleapis.com/vntana-viewer/assets/images/enter_fullscreen_icon.svg’) no-repeat center;
background-size: 25px auto;
cursor: pointer;
}
 
#exitFullscreen {
position: absolute;
right: 16px;
bottom: 16px;
width: 40px;
height: 40px;
background: #dbdbdb url(‘https://storage.googleapis.com/vntana-viewer/assets/images/exit_fullscreen_icon.svg’) no-repeat center;
background-size: 25px auto;
display: none;
cursor: pointer;
}

Contact support@vntana.com to request access to our Viewer Component Library source code.

VNTANA Viewer Settings And Annotations Component Integration

Overview

The VNTANA Viewer, Settings and Annotations component is a wrapper fort the model-viewer, with a built in Settings and Annotations Panel. The viewer can display Khronos GLTF 2.0 content in browsers that provide full support for WebGL 1.0. The Settings panel exposes a variety of viewer settings, such as Camera and Lighting, that can be adjusted to create the best visual environment for your 3D asset. The Annotations panel allows users of your application to drop pins directly onto the 3D model, and leave comments and replies with text or uploaded reference images. (Accepted image file types are .png, .jpg, .jpeg, and .svg).

The component has been developed to be a portable JavaScript Universal Module Definition (UMD) library, that can be dynamically loaded and included in web applications or components.

Library Functions, Parameters, and Integration

To integrate the viewer with the settings and annotations panel into an existing web app or component requires including the UMD modules vnview-editor.js and vnview.js using HTML script tags or dynamic loading method.

The library currently exposes one function, createViewerEditor, on the global namespace vnvieweditor which creates and returns a ViewerEditor class.

1
var viewerEditor = vnvieweditor.createViewerEditor(element, options);

The element parameter is an HTML5 DOM element that will contain the component. The DOM element will be used as the parent element for the viewer and the settings and annotations panel.

The options parameter is a JavaScript object that defines parameters for the setup and context of the Viewer, Settings and Annotations. The following options object shows all of the possible settings that can be configured. Please see the above section about the Viewer Component Integration for all of the possible renderer configs options.

1
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
29
30
31
32
33
34
35
options = {
fileGLTF: ‘string’,
productUuid: ‘string’,
clientUuid: ‘string’,
onProgress: (event) => {},
onSuccess: (event) => {},
onError: (event) => {},
panelOrder: [‘annotation’, ‘settings’],
hideSaveBtn: false,
thumbnailUrl: ‘string’,
disablePoster: false,
viewerConfigs: {
rendererConfigs: {
},
saveRendererConfigs: () => {}
},
getAnnotations: () => {},
createAnnotation: (requestData) => {},
updateAnnotation: (requestData) => {},
deleteAnnotation: (annotationUuid) => {},
resolveAnnotation: (requestData) => {},
getAnnotationComments: () => {},
createComment: (requestData) => {},
updateComment: (requestData) => {},
deleteComment: (commentUuid) => {},
currentUserId: ‘string’,
usersList: [
{
‘userId’: ‘string’,
‘profileImage’: ‘string’,
‘userName’: ‘string’
}
]
}

Viewer Options

  • fileGLTF – URL of GLB file to load in viewer.
    • Example: “https://api.dev.vntana.com/assets/products/524e5f1c-635f-4eec-b73e-9ebb2f9235bb/organizations/vntana-platform/clients/test/c7c1691d-6938-402c-b5c1-178aff095480.glb”
  • productUuid – Uuid of product on VNTANA Platform
    • Example: “524e5f1c-635f-4eec-b73e-9ebb2f9235bb”
  • clientUuid – Uuid of Client on VNTANA Platform to which the product belongs
  • onProgress – Any action desired while GLB is loading in viewer. (optional)
  • onSuccess – Any action desired on successful load of GLB in viewer.
  • onError – Any action desired on unsuccessful load of GLB in viewer. “Error” event can be fired for two reasons: ‘loadfailure’ and ‘webglcontextlost’. (See error under Events: https://modelviewer.dev/docs/index.html#loading-events(optional)
  • panelOrder – An array indicating the order in which to display the different editor panels. Do not include the panelOrder property if you want to use the default order. Default order is [“settings”, “annotation”]. (optional)
  • hideSaveBtn – A boolean that toggles the visibility of the Save button in the Settings panel. Default is false. (optional)
  • thumbnailUrl – URL of poster image to load in viewer while the asset loads. (optional)
  • disablePoster – A boolean that determines whether to display the provided thumbnailUrl as the poster image before the asset loads. Default is false. (optional)

Settings

  • viewerConfigs – Object that holds rendererConfigs
    • rendererConfigs – Object with all of the saved configurations for the viewer settings. A null value indicates that no settings have been saved, and all values will be set to their default.
    • saveRendererConfigs – Endpoint to save settings.

The settings panel expects the viewerConfigs property within the options object. The viewerConfigs property contains the rendererConfigs object and the saveRendererConfigs function.

rendererConfigs contains all of the 3D viewer configurations that can be saved per asset, such as the Lighting and Camera settings. If nothing is passed to this object, all of the viewer settings will be set to their default values. saveRendererConfigs is required if the settings need to be stored for retrieval at a later time.

For a more detailed list of the available rendererConfigs and their defaults, please see the above section, VNTANA Viewer Component Integration.

Annotations

  • getAnnotations – Endpoint to retrieve annotations list.
  • createAnnotation – Endpoint to create an Annotation. (optional)
  • updateAnnotation – Endpoint to update an Annotation. (optional)
  • deleteAnnotation – Endpoint to delete an Annotation. (optional)
  • resolveAnnotation – Endpoint to resolve an Annotation. (optional)

The annotations panel requires the getAnnotations function to get the current list of annotations, in order to show the annotations history in the correct order, as well as with the correct user information.

The annotations data returned from calling the getAnnotations method is expected in the below structure:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
‘response’: {
‘annotations’: {
‘grid’: [
{
‘commentsCount’: 0,
‘created’: ‘2020-12-01T23:37:54.863Z’,
‘dimensions’: ‘string’,
‘number’: 0,
‘productUuid’: ‘string’,
‘resolved’: true,
‘text’: ‘string’,
‘updated’: ‘2020-12-01T23:37:54.863Z’,
‘userId’: ‘string’,
‘uuid’: ‘string’ // annotationUuid
}
],
‘nextNumber’: 0,
‘totalCount’: 0
}
}
}

The options object will also accept the parameters createAnnotationupdateAnnotationdeleteAnnotation, and resolveAnnotation to handle the creation, update, deletion, and resolution of individual annotations respectively.

These parameters are not required, however, as each action can also be handled outside of the component using event listeners. The component dispatches Custom Events whenever a user performs any of the annotations actions. Event handlers outside of the component can execute the desired actions (e.g. making an API call to post a new annotation), by listening for the following Custom Events:

  • _vntana_createAnnotation
  • _vntana_updateAnnotation
  • _vntana_deleteAnnotation
  • _vntana_resolveAnnotation

Regardless of the direction chosen in development, the data sent out of the component to the application is the same in both situations, and matches the request bodies for the corresponding endpoints in our Admin API.

createAnnotation request object:

1
2
3
4
5
6
{
‘dimensions’: ‘string’,
‘productUuid’: ‘string’,
‘text’: ‘string’,
‘clientUuid’: ‘string’
}
  • The createAnnotation function should also return a response object that contains the newly created annotation’s uuid.

updateAnnotation request object:

1
2
3
4
5
6
{
‘dimensions’: ‘string’,
‘text’: ‘string’,
‘uuid’: ‘string’ // annotationUuid
‘clientUuid’: ‘string’
}

deleteAnnotation request object:

1
2
3
{
‘uuid’: ‘string’ // annotationUuid
}

resolveAnnotation request object:

1
2
3
4
{
‘resolved’: true,
‘uuid’: ‘string’ // annotationUuid
}

Comments

  • getAnnotationComments – Endpoint to retrieve annotation comments list.
  • createComment – Endpoint to create a Comment. (optional)
  • updateComment – Endpoint to update a Comment. (optional)
  • deleteComment – Endpoint to delete a Comment. (optional)

The annotation comments follow a similar logic to the Annotations. The getAnnotationComments function is required to display any comments that were posted in response to an Annotation. The following request body will be passed to the getAnnotationComments function:

1
2
3
4
{
‘entityType’: ‘ANNOTATION’,
‘entityUuid’: ‘string’, // annotationUuid
}

The data returned from calling getAnnotationComments from within the component is expected in the below structure:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
‘response’: {
‘comments’: {
‘grid’: [
{
‘created’: ‘2020-12-02T00:22:04.431Z’,
‘entityType’: ‘ANNOTATION’,
‘entityUuid’: ‘string’,
‘message’: ‘string’,
‘updated’: ‘2020-12-02T00:22:04.432Z’,
‘userId’: ‘string’,
‘uuid’: ‘string’
}
],
‘totalCount’: 0
}
}
}

The viewer component also accepts the methods createCommentupdateComment, and deleteComment to handle the creation, update, and deletion of comments in response to an Annotation. As with the Annotations, these parameters are not required within the options object. The component dispatches Custom Events for each of the comments actions as well, which can be handled outside of the component with event listeners. The following Custom Events are dispatched for the creation, update, and deletion of a comment, respectively:

  • _vntana_createComment
  • _vntana_updateComment
  • _vntana_deleteComment

The data sent out of the component for each of these actions mirrors the request bodies of the Comment Resource endpoints in our Admin API, and have been copied here for convenience:

createComment request object:

1
2
3
4
5
6
{
‘entityType’: ‘ANNOTATION’,
‘entityUuid’: ‘string’, // annotationUuid
‘message’: ‘string’,
‘clientUuid’: ‘string’
}
  • The createComment function should also return a response object that contains the newly created comment’s uuid.

updateComment request object:

1
2
3
4
5
6
{
‘entityUuid’: ‘string’, // annotationUuid
‘message’: ‘string’,
‘uuid’: ‘string’ // commentUuid
‘clientUuid’: ‘string’
}

deleteComment request object:

1
2
3
{
‘uuid’: ‘string’ // commentUuid
}

User Management

  • currentUserId – The currently logged in user’s ID. Can be any string that uniquely identifies the user, such as an email address, username, or uuid. The ID is required in order to determine which Annotations and/or Comments the user can edit and delete, since only the user who posted the Annotation/Comment can edit/delete it. The currentUserId will be compared against the userId associated with each Annotation or Comment.
  • usersList – List of users with the permission to create, edit or delete Annotations and Comments. This data is needed in order to display the user’s info next to the annotation or comment he/she posted. Each user object should have the following properties:
    • userId – Unique ID of the user.
    • profileImage – URL to profile image of user. If no value is passed, no image will be shown next to the user’s name.
    • userName – Any string value to display with the Annotation or Comment to easily identify the user who created the post. For example, this can be the user’s full name, account username, or email address.

Contact support@vntana.com to request access to our Viewer Settings and Annotations Component Library source code.

Accelerate Your
Digital Transformation

Learn how our platform can automate your 3D process.

Tap the magnifying glass to the left of your screen to search our resources.