Methods

The rhinoartisan-web-3d web component exposes the following methods that can be called directly on the element.

📋 Method Categories

  • Materials

  • Items

  • Camera & Controls

  • Capture

  • Selection

  • Model Loading & Cache

  • Presets

  • Configuration

  • Material Customization


Materials

setMaterialByName(materialName)

Sets the material for the currently selected item(s). If no item is selected, applies to the last selected item.

Parameters:

  • materialName (string): Name of the material to apply (e.g., "gold-polished", "silver-polished", "diamond")

Returns: void

Example:


setMaterialByUuidAndName(uuid, materialName)

Sets the material for a specific item by its UUID.

Parameters:

  • uuid (string): UUID of the item

  • materialName (string): Name of the material to apply

Returns: void

Example:


Items

getItems()

Returns an array of all items/parts in the loaded model.

Returns: Array of item objects with properties:

  • uuid (string): Unique identifier

  • material (string): Current material name

  • selected (boolean): Selection state

Example:


getSelectedItems()

Returns an array of currently selected items.

Returns: Array of selected item objects

Example:


getItemByUuid(uuid)

Gets a specific item by its UUID.

Parameters:

  • uuid (string): UUID of the item

Returns: Item object or undefined if not found

Example:


Camera & Controls

zoomExtents()

Fits the camera view to show the entire model with appropriate padding.

Returns: void

Example:


zoomIn()

Zooms the camera in (closer to the model).

Returns: void

Example:


zoomOut()

Zooms the camera out (farther from the model).

Returns: void

Example:


setAutorotate(enabled)

Enables or disables automatic rotation of the model.

Parameters:

  • enabled (boolean): True to enable, false to disable

Returns: void

Example:


getCameraView()

Gets the current camera view configuration.

Returns: Object with:

  • position (array): [x, y, z] camera position

  • target (array): [x, y, z] look-at target

  • fov (number): Field of view in degrees

Example:


setCameraView({ position, target, fov })

Sets the camera view configuration.

Parameters:

  • position (array): [x, y, z] camera position

  • target (array): [x, y, z] look-at target

  • fov (number): Field of view in degrees

Returns: void

Example:


Capture

getScreenshot(format, quality, width, height)

Captures a screenshot of the current view.

Parameters:

  • format (string, optional): Image format. Default: "image/png". Options: "image/png", "image/jpeg", "image/webp"

  • quality (number, optional): Image quality (0-1). Default: 0.92

  • width (number, optional): Output width in pixels. Default: 1920

  • height (number, optional): Output height in pixels. Default: 1080

Returns: Data URL string of the image

Example:


downloadImage(filename)

Downloads a screenshot of the current view.

Parameters:

  • filename (string, optional): Name of the file. Default: "screenshot.png"

Returns: void

Example:


startVideoRecording(duration)

Starts recording a video of the viewer (turntable animation).

Parameters:

  • duration (number, optional): Duration in seconds. Default: 5

Returns: void

Example:


stopVideoRecording()

Stops the current video recording and downloads the file.

Returns: void

Example:


Selection

setObjectSelectionEnabled(enabled)

Enables or disables the ability to select objects by clicking.

Parameters:

  • enabled (boolean): True to enable, false to disable

Returns: void

Example:


Model Loading & Cache

setModelUrl(url)

Loads a new 3D model from the specified URL.

Parameters:

  • url (string): URL of the GLTF/GLB model to load

Returns: boolean - True if successful, false on error

Example:


preloadModel(url)

Preloads a model into cache without displaying it.

Parameters:

  • url (string): URL of the model to preload

Returns: Promise

Example:


clearModelCache(url)

Clears a specific model from the cache.

Parameters:

  • url (string, optional): URL of the model to clear. If not provided, clears all models.

Returns: void

Example:


Presets

loadPreset(presetName)

Loads a predefined visual preset (combination of lights, shadows, environment, etc.).

Parameters:

  • presetName (string): Name of the preset to load

Returns: boolean - True if successful, false if preset not found

Available Presets:

  • studio-bright - Bright studio lighting

  • studio-soft - Soft, diffused studio lighting

  • outdoor-sunset - Warm sunset lighting

  • outdoor-overcast - Cloudy day lighting

  • dramatic-dark - High contrast, dramatic lighting

  • minimal-clean - Minimal, clean aesthetic

Example:


getAvailablePresets()

Gets a list of all available presets.

Returns: Array of preset objects with:

  • name (string): Preset identifier

  • displayName (string): Human-readable name

  • description (string): Preset description

  • category (string): Preset category

Example:


getCurrentPreset()

Gets the currently active preset (if any).

Returns: Preset object or null if no preset matches current configuration

Example:


Configuration

exportConfiguration()

Exports the current viewer configuration as a JSON object.

Returns: Configuration object containing:

  • version (string): Configuration format version

  • timestamp (string): ISO timestamp

  • items (array): All items with their materials

  • camera (object): Camera view configuration

  • viewerOptions (object): Viewer settings

Example:


importConfiguration(config)

Imports a previously exported configuration.

Parameters:

  • config (object): Configuration object from exportConfiguration()

Returns: boolean - True if successful, false on error

Example:


downloadConfiguration(filename)

Downloads the current configuration as a JSON file.

Parameters:

  • filename (string, optional): Name of the file. Default: "viewer-config.json"

Returns: void

Example:


Material Customization

updateMaterialProperties(uuid, properties)

Updates specific material properties for an item.

Parameters:

  • uuid (string): UUID of the item

  • properties (object): Properties to update:

    • color (string): Hex color (e.g., "#ff0000")

    • metalness (number): 0-1

    • roughness (number): 0-1

    • emissive (string): Hex color

    • emissiveIntensity (number): 0-1+

    • normalScale (number): Normal map intensity

    • envMapIntensity (number): Environment reflection intensity

    • opacity (number): 0-1

Returns: boolean - True if successful

Example:


getMaterialProperties(uuid)

Gets the current material properties of an item.

Parameters:

  • uuid (string): UUID of the item

Returns: Object with material properties or null

Example:


saveCustomMaterial(name, properties)

Saves custom material properties to localStorage for later use.

Parameters:

  • name (string): Name for the custom material

  • properties (object): Material properties (same as updateMaterialProperties)

Returns: boolean - True if successful

Example:


getCustomMaterials()

Gets all saved custom materials from localStorage.

Returns: Array of custom material objects

Example:


deleteCustomMaterial(name)

Deletes a saved custom material from localStorage.

Parameters:

  • name (string): Name of the custom material to delete

Returns: boolean - True if successful

Example:


💡 Usage Tips

Accessing Methods

All methods are directly accessible on the web component element:

Method Chaining

Some methods return values, but most return void. You can still execute multiple operations:

Error Handling

Methods that can fail (like setModelUrl, loadPreset) return boolean values:


🔗 See Also

  • Events - Available events

  • Configuration - Configuration options

  • Examples - Usage examples

Last updated

Was this helpful?