Skip to content

Viewer Class

iJewel Viewer Class

The Viewer class is responsible for initializing and rendering the iJewelMiniViewer in a specified container.

Constructor

constructor(container: HTMLElement, project: Project, options?: ViewerOptions)

  • Parameters:
    • container: The HTML element in which the viewer will be rendered.
    • project: An object containing the project configuration details.
    • options: An optional object containing various viewer options.

Methods

render(project: any)

  • Parameters:

    • project: The project configuration to be rendered.
  • Description: Renders the viewer with the given project configuration. This method sets up the viewer with the specified options and displays the UI components. To update the project and the 3D model, call viewer.render(project). This will clear the previous project and render the new one.

TIP

You can call viewer.render(newProject) to load new models and clear the previous scene on the same Viewer instance.

ViewerOptions

The ViewerOptions interface provides several optional properties to control the appearance and behavior of the viewer.

PropertyTypeDescriptionDefault
viewerViewerAppAn existing viewer instance to be used for rendering. If not provided, a new viewer will be created.undefined
diamonKeystringA licence key requried for enabling diamond materials, constact us to get your key.undefined
showLogobooleanDetermines whether the logo is displayed in the viewer.true
showCardbooleanControls the visibility of the floating card that displays model details.true
showSwitchNodebooleanShow or hide swich nodes from the configurator.false
splitMaterialTabsbooleanDetermines if material options are displayed in separate tabs.undefined
hideQualitybooleanControls the visibility of quality settings in the UI.false
logoScalenumberSpecifies the scale of the logo.1
logoPositionXnumberDetermines the horizontal position of the logo on the screen. The value ranges from 0 to 1, where 0 positions the logo at the far left and 1 positions the logo at the far right.1
logoPositionYnumberSimilar to logoPositionX but vertically0
showZoomButtonsbooleanDetermines whether zoom buttons are displayed in the viewer.false
showUiButtonsbooleanDetermines whether ui buttons bar is displayed in the viewer.true
enableZoombooleanEnables or disables zoom functionality.true
enableScrollWheelbooleanEnables or disables zooming with the scroll wheel.true

Project Configuration

When initializing the iJewel Viewer, you need to provide a project configuration object that includes various settings for your 3D model, environment, materials, and more. Below is a detailed explanation of the properties that can be included in the project configuration object.

Project Properties

PropertyTypeDescription
modelUrlstringURL of the 3D model file (e.g., a .glb file).
basePathstringBase URL path where your assets are stored. Can be an empty string if not needed.
posterUrlstringURL of the poster image.
logostringURL of the logo to be displayed in the viewer.
namestringName of the project.
descriptionstringDescription of the project.
presetLibanyLibrary of presets used in the project.
materialLibanyLibrary of materials used in the project.
sceneConfigobjectConfiguration for the scene environment, including background and ground settings.
cameraConfigobjectConfiguration for the camera settings.
materialConfigobjectConfiguration for the materials used in the model.
configuratorConfigarrayConfiguration for the configurator options available in the viewer.
pluginsobjectConfiguration for the plugins used in the viewer.
categorystringSpecify the category of the model, e.g. Ring, Necklace or Watch.
tagsstring[]An array of strings containing tags for the model.

Detailed Explanation

  • modelUrl: The URL pointing to the 3D model file you want to load.
  • basePath: The base path for your assets, which can be left empty if not needed.
  • posterUrl: The URL of the poster image to be displayed before the model loads.
  • logo: The URL of the logo image to be displayed within the viewer.
  • name: name of the model to be displayed in the floating card.
  • description: A brief description of the model to be displayed in the floating card.
  • presetLib: The library of presets for the sceneConfig.
  • materialLib: The library of materials used in materialConfig and configuratorConfig .
  • sceneConfig:
    • Environment: Path to the environment HDR file.
    • GemEnvironment: Path to the gem environment EXR file.
    • Ground: Path to the ground configuration JSON file.
    • Background : Path to the background image for the 3d scene.
  • cameraConfig: Configuration for the camera settings.
  • materialConfig: The materials that are going to be applied to the model on load
    • materials: An array of material objects, each with a name and a path to the material file.
    • type: The type of material configuration, typically MaterialPresetPlugin.
  • configuratorConfig: An array of configurator option objects used in the material configurator ui, each with:
    • name: The name of the material layer in the 3d file.
    • title: The display title for the option.
    • options: An array of available options for this configurator, each with:
      • name: The name of the material or gem file.
      • type: The type of option, e.g., metal or gem.
  • plugins:
    • SimpleBackgroundEnvUiPlugin2: Configuration for the background and environment UI plugin, including:
      • sceneEnvironmentRotation: Rotation of the environment.
      • sceneEnvironmentIntensity: Intensity of the environment lighting.
      • sceneEnvironmentFixedDirection: Boolean indicating if the environment direction is fixed.
      • tonemapBackground: Boolean indicating if background tonemapping is enabled.
      • tonemapGround: Boolean indicating if ground tonemapping is enabled.
      • type: The type of the plugin, typically SimpleBackgroundEnvUiPlugin2.

TIP

The paths for the scene presets and materials can either be absolute URLs or relative to the basePath specified in your project configuration. This flexibility allows you to organize and reference your assets in a way that best fits your project structure.

Event Listener

The Viewer class emits a custom event ijewel-viewer-ready when the viewer is fully initialized and ready for interaction. You can listen for this event to perform additional actions once the viewer is ready.

Example Usage

javascript
const project = {
  modelUrl: "https://example.com/model.glb",
  basePath: "https://example.com/assets/",
  logo: "https://example.com/logo.png",
  sceneConfig: { /* scene configuration */ },
  materialConfig: { /* material configuration */ },
  configuratorConfig: [/* configurator configuration */],
};

const viewerOptions = {
  showLogo: true,
  showCard: true,
  showSwitchNode: false,
  splitMaterialTabs: true,
  useIjewelLogo: false,
  hideQuality: true,
  logoScale: 1.5,
};

const viewer = new ijewelViewer.Viewer(document.getElementById("root"), project, viewerOptions);

// To update the project and the 3D model
viewer.render(newProject);

// Event listener for viewer ready event
window.addEventListener("ijewel-viewer-ready", async (ev) => {
  const viewer = ev.detail.viewer;
  // Additional actions to perform with the viewer instance

  //Example
  //set the max and min zoom for mobile and desktop 
  viewer.scene.activeCamera.addEventListener('update', (ev)=>{
      if(window.innerWidth < window.innerHeight){
        (viewer.scene.activeCamera.getControls()).minDistance = 14;
        (viewer.scene.activeCamera.getControls()).maxDistance = 9;

      }else{
        (viewer.scene.activeCamera.getControls()).maxDistance = 12;
        (viewer.scene.activeCamera.getControls()).minDistance = 7;
      }
  });
});