Class: SpiffCommerce3DPreviewService
An example implementation of the ThreeDPreviewService interface. The inclusion of 3D previews is designed to be optional, anyone can come along and implement their own 3D preview service or they can use this one to get things running more quickly.
Implements
Constructors
Constructor
new SpiffCommerce3DPreviewService(
options?):SpiffCommerce3DPreviewService
Parameters
options?
Returns
SpiffCommerce3DPreviewService
Methods
animateToLastCameraFocus()
animateToLastCameraFocus():
Promise<void>
Restores the product camera to it's last set focus point. If the user has been panning this will animate the camera to the original focus point. If the camera is still focused on it's origin point this function is a noop.
Returns
Promise<void>
Implementation of
ThreeDPreviewService.animateToLastCameraFocus
executeCameraAnimation()
executeCameraAnimation(
animation):Promise<void>
Executes an animation of the camera.
Parameters
animation
The animation to execute.
Returns
Promise<void>
Implementation of
ThreeDPreviewService.executeCameraAnimation
fireResizeEvent()
fireResizeEvent():
void
When called will trigger the internal engine to match the current view size. This ensures the image renders correctly in the view and also prevents performance problems.
Returns
void
Implementation of
ThreeDPreviewService.fireResizeEvent
flipTransform()
flipTransform(
position?,rotation?,scale?):object
Flips a transform around the origin.
Parameters
position?
rotation?
scale?
Returns
object
position
position:
Vector
rotation
rotation:
Vector
scale
scale:
Vector
Implementation of
ThreeDPreviewService.flipTransform
forceStopCameraAnimations()
forceStopCameraAnimations():
void
Forces the camera to stop any animations that are currently running. Note this will not resolve any existing promises.
Returns
void
Implementation of
ThreeDPreviewService.forceStopCameraAnimations
getAllModels()
getAllModels(): readonly
ModelContainer[]
Returns all loaded models.
Returns
readonly ModelContainer[]
A map of id to model container.
Implementation of
ThreeDPreviewService.getAllModels
getCameraPose()
getCameraPose():
CameraPose|undefined
Returns the values of the Arc Rotate Camera
Returns
CameraPose | undefined
Implementation of
ThreeDPreviewService.getCameraPose
getCurrentConfiguration()
getCurrentConfiguration():
PreviewOptions|undefined
Returns the current configuration object applied to the scene.
Returns
PreviewOptions | undefined
Implementation of
ThreeDPreviewService.getCurrentConfiguration
getEngineContext()
getEngineContext():
object
Returns
object
camera
camera:
ProductCamera
engine
engine:
Engine
scene
scene:
Scene
getGlowLayerManager()
getGlowLayerManager():
GlowLayerManager
Returns
GlowLayerManager
getInitializationComplete()
getInitializationComplete():
boolean
True when the preview has been initialized. This is when the initializationPromise resolves.
Returns
boolean
Implementation of
ThreeDPreviewService.getInitializationComplete
getInitializationPromise()
getInitializationPromise():
Promise<void>
Returns a promise which resolves when the preview has been initialized.
Returns
Promise<void>
Implementation of
ThreeDPreviewService.getInitializationPromise
getModelById()
getModelById(
id):ModelContainer|undefined
Retrieves a loaded model by it's id.
Parameters
id
string
The id of the model to retrieve.
Returns
ModelContainer | undefined
The model container if it exists, undefined otherwise.
Implementation of
ThreeDPreviewService.getModelById
getNumViewports()
getNumViewports():
number
Returns the number of active viewports registered with the preview. Useful for avoiding unnecessary rendering when there are no active viewers.
Returns
number
Implementation of
ThreeDPreviewService.getNumViewports
loadModel()
loadModel(
modelDetails,options?):ModelContainer
Loads a model into the scene.
Parameters
modelDetails
The details of the model to load.
options?
Optional configuration.
progressHandler?
(event) => void
refocusCamera?
boolean
Returns
A reference to the model container. Call getInitializationPromise() to wait for the model to be loaded.
Implementation of
ThreeDPreviewService.loadModel
modelUnloaded()
modelUnloaded(
modelContainer):void
Parameters
modelContainer
Returns
void
orbitEnabled()
orbitEnabled():
boolean
Returns true when the current configuration allows the user to rotate around the product.
Returns
boolean
Implementation of
ThreeDPreviewService.orbitEnabled
preloadModel()
preloadModel(
url):Promise<void>
Preloads a model into the scene. This will load the model into memory, but it will not be visible in the scene.
Parameters
url
string
The url of the model to preload.
Returns
Promise<void>
Implementation of
ThreeDPreviewService.preloadModel
registerFocusLostListener()
registerFocusLostListener(
listener):void
Allows listeners to be aware of the camera losing focus of the main product.
Parameters
listener
() => void
A function to be called when focus is lost.
Returns
void
Implementation of
ThreeDPreviewService.registerFocusLostListener
registerModelLoadEventListener()
registerModelLoadEventListener(
listener):void
Provides listeners with information about model load events.
Parameters
listener
(e) => void
A function to get load events. The eventType will be 'load' or 'unload', and the modelContainer will be the model that was loaded or unloaded.
Returns
void
Implementation of
ThreeDPreviewService.registerModelLoadEventListener
registerPlugin()
registerPlugin(
plugin):void
Registers a plugin with the preview service.
Parameters
plugin
The plugin to register.
Returns
void
Implementation of
ThreeDPreviewService.registerPlugin
registerView()
registerView(
canvas):void
Request that the preview renders to a given view. For a canvas-based engine (e.g. the 3D preview) this is an HTMLCanvasElement; other engines (e.g. the 2D preview) may render into any element, such as a container to mount live SVG/DOM content into.
Parameters
canvas
HTMLCanvasElement
Returns
void
Implementation of
ThreeDPreviewService.registerView
renderSceneScreenshot()
renderSceneScreenshot(
resolution,camAnim):Promise<string>
Takes a screenshot of the scene using a given camera animation otherwise using the existing orientation of the camera in the scene. A resolution must be provided to render the scene at.
Parameters
resolution
number
camAnim
Returns
Promise<string>
Implementation of
ThreeDPreviewService.renderSceneScreenshot
setAutoRotation()
setAutoRotation(
shouldAutoRotate):void
When configuration has allowed for auto rotation we can pause the rotation via this function.
Parameters
shouldAutoRotate
boolean
When true rotation is running, paused otherwise.
Returns
void
Implementation of
ThreeDPreviewService.setAutoRotation
setCameraPose()
setCameraPose(
cameraPose):void
Sets the values of the Arc Rotate Camera
Parameters
cameraPose
Returns
void
Implementation of
ThreeDPreviewService.setCameraPose
setCameraState()
setCameraState(
rigType):void
Controls the current control state of the camera.
Parameters
rigType
The control type to use.
Returns
void
Implementation of
ThreeDPreviewService.setCameraState
setHighlightMaterials()
setHighlightMaterials(
materials):void
Takes a list of material names supported by the highlighter. This function must be notified of materials for highlighting to work.
Parameters
materials
string[]
A list of material names to allow highlighting on.
Returns
void
Implementation of
ThreeDPreviewService.setHighlightMaterials
setHighlights()
setHighlights(
materials):void
Designed for use when utilizing the 3D preview in an editor format. Given a list of material names, highlights the associated meshes in the scene.
Parameters
materials
readonly MaterialHandle[]
Returns
void
Implementation of
ThreeDPreviewService.setHighlights
setRenderingPipelineConfiguration()
setRenderingPipelineConfiguration(
renderingPipelineConfiguration):void
Sets the rendering pipeline configuration for the scene. Overwrites any existing configuration.
Parameters
renderingPipelineConfiguration
RenderingPipelineConfiguration
The configuration to apply. Empty values will be set to default.
Returns
void
Implementation of
ThreeDPreviewService.setRenderingPipelineConfiguration
shutdown()
shutdown():
void
Shuts down the preview engine. Noop if the engine is not initialized.
Returns
void
Implementation of
ThreeDPreviewService.shutdown
unregisterFocusLostListener()
unregisterFocusLostListener(
listener):void
Removes a listener from the focusLost observers. The listener will no longer be notified
Parameters
listener
() => void
The listener to remove.
Returns
void
Implementation of
ThreeDPreviewService.unregisterFocusLostListener
unregisterModelLoadEventListener()
unregisterModelLoadEventListener(
listener):void
Allows you to pass any function that originally called registerModelLoadEventListener() to have it excluded from load events. If the function was never registered this call has no effect.
Parameters
listener
(e) => void
The listener to exclude from load events.
Returns
void
Implementation of
ThreeDPreviewService.unregisterModelLoadEventListener
unregisterPlugin()
unregisterPlugin(
plugin):void
Removes a plugin from the preview service.
Parameters
plugin
The plugin to remove.
Returns
void
Implementation of
ThreeDPreviewService.unregisterPlugin
unregisterView()
unregisterView(
canvas):void
Tells the preview that we no longer want the given view to be rendered to.
Parameters
canvas
HTMLCanvasElement
Returns
void
Implementation of
ThreeDPreviewService.unregisterView
updatePreviewOptions()
updatePreviewOptions(
options):void
Sets the preview options for the scene. Certain options may not be applied, as they are only applicable upon initialization.
Parameters
options
The options to apply.
Returns
void
Implementation of
ThreeDPreviewService.updatePreviewOptions
isSupported()
staticisSupported():boolean
Returns
boolean