UNPKG

@qctrl/visualizer

Version:

The Q-CTRL Visualizer is a package for displaying animated 3d Bloch sphere visualizations.

80 lines (79 loc) 3.85 kB
import { Scene, Raycaster, Vector3, Vector3Tuple, PerspectiveCamera } from "three"; import { OrbitControls } from "three/examples/jsm/controls/OrbitControls"; import ObjectsManager from "../objects"; import { SCENE_OBJECT_UPDATE_TYPES } from "../../constants"; import { Styles } from "../../styles/theme"; import { CustomLabel, Labels } from "../../types"; import type { Props, ThemeSettings } from "../../VisualizerEntryPoint"; export interface UpdateDataProps { data: Vector3Tuple[]; nonErrorStateData?: Vector3Tuple[]; segmentIndexes: number[]; initialFrameIndex: number; finalFrameIndex: number; continuousSegments?: boolean; drawArcs?: boolean; drawPaths: boolean; skipLastLineDraw?: boolean; } interface VisualizationViewportProps extends UpdateDataProps { div: HTMLElement; style: Styles; customLabels?: CustomLabel[]; onControlsStart?: () => void; onControlsEnd?: () => void; onControlsChange?: () => void; } export interface UpdateMethodProps { frameIndex: number; currentSegmentNumber: number; updates: { method: SCENE_OBJECT_UPDATE_TYPES; args?: unknown; }[]; props: Props; } /** * A class representing an "Element" of the visualization and can also be described as a subscene of a multiple camera/viewport {@link https://threejs.org/docs/index.html#api/en/scenes/Scene|three js scene} * comprising of a three js scene object to render the subscene/element to a particular viewport in the main scene/rendering context, a {@link https://threejs.org/docs/index.html#api/en/cameras/PerspectiveCamera|three js camera} object, {@link https://threejs.org/docs/index.html#examples/en/controls/OrbitControls|three js orbit controls} for the scene * and some {@link raycasters|https://threejs.org/docs/index.html#api/en/core/Raycaster} for the pulse path and sprite objects in the element/subscene */ declare class VisualizationViewport { div: HTMLElement; style: Styles; scene?: Scene; objectsManager?: ObjectsManager; camera?: PerspectiveCamera; cameraPresetVector: Vector3; shouldSlerpCamera: boolean; slerpDelta: number; controls?: OrbitControls; mouseSegmentRaycaster: Raycaster; labelRaycaster: Raycaster; perspective: number; labels: Partial<Record<keyof Labels, HTMLElement | SVGSVGElement>>; customLabels: CustomLabel[] | undefined; raycaster: undefined; constructor({ div, data, nonErrorStateData, style, initialFrameIndex, finalFrameIndex, continuousSegments, segmentIndexes, drawArcs, drawPaths, skipLastLineDraw, customLabels, onControlsStart, onControlsEnd, onControlsChange, }: VisualizationViewportProps); /** * Sets the new camera position for the subscene/element from the passed in camera preset name */ setCameraPreset(presetName: string, shouldAnimatePresets: boolean): void; setLabels(props?: Props): void; /** * Traverses the subscene and cleans up/disposes of any geometry or disposable objects * then loses references for the other members of the subscene/element */ threeCleanup(hasNewData: boolean): void; /** * Updates the visualized data by creating a new scene with new scene/element objects. Cleans up old objects first. */ updateData({ data: newData, nonErrorStateData: newNonErrorStateData, segmentIndexes, initialFrameIndex, finalFrameIndex, continuousSegments, drawArcs, drawPaths, skipLastLineDraw, }: UpdateDataProps): void; setNewThemeSettings(settings: ThemeSettings): void; /** * Calls any methods in this Element instance that are in the updates array * then calls the update method of the child elementObjects class instance */ update({ frameIndex, currentSegmentNumber, updates, props, }: UpdateMethodProps): void; } export default VisualizationViewport;