forma-embedded-view-sdk
Version:
The Forma Embedded View SDK is a JavaScript library for creating custom extensions in Autodesk Forma Site Design (previously Spacemaker).
108 lines (107 loc) • 3.4 kB
TypeScript
import type { IframeMessenger } from "../iframe-messenger.js";
/** State of the camera object in the 3D scene */
export type CameraState = {
/** Position where the camera is located */
position: {
x: number;
y: number;
z: number;
};
/** Target which the camera is pointing towards */
target: {
x: number;
y: number;
z: number;
};
/** Perspective type provides sense of depth ("3D"), while orthographic
* projection preserves parallell lines ("2D top view"). */
type: "perspective" | "orthographic";
};
/**
* Interact with the camera in the 3D scene of designmode.
*
* @remarks
* Available via {@link auto.Forma | Forma}.{@link index.EmbeddedViewSdk.camera | camera}.
*/
export declare class CameraApi {
#private;
/** @hidden */
constructor(iframeMessenger: IframeMessenger);
/**
* Move camera view to a new position.
*
* @example
* // Move camera to view down on the center of the proposal from directly
* // above, spending 1 second on the transition.
* await Forma.camera.move({
* position: { x: 0, y: 0, z: 100 },
* target: { x: 0, y: 0, z: 0 },
* transitionTimeMs: 1000,
* })
*/
move(request: {
/** Wanted position to move camera to. */
position: {
x: number;
y: number;
z: number;
};
/** Target to point camera towards. */
target?: {
x: number;
y: number;
z: number;
} | undefined;
/** Zoom level to set camera to. */
zoom?: number | undefined;
/** Duration of transition in milliseconds. */
transitionTimeMs?: number | undefined;
}): Promise<void>;
/**
* Toggle between perspective and orthographic camera.
*
* @example
* await Forma.camera.switchPerspective()
*/
switchPerspective(): Promise<void>;
/**
* Capture a screenshot of the current camera view as a canvas.
*
* @returns Canvas with the captured screenshot.
*
* @example
* // Capture a 100x100 pixel screenshot of the current camera view.
* const canvas = await Forma.camera.capture({ width: 100, height: 100 })
*/
capture(request: {
/** Width of the canvas to capture. */
width: number;
/** Height of the canvas to capture. */
height: number;
}): Promise<HTMLCanvasElement>;
/**
* Fetch the current camera state in the designmode scene.
*
* @returns Current camera state.
*
* @example
* const currentCameraState = await Forma.camera.getCurrent()
*/
getCurrent(): Promise<CameraState>;
/**
* Subscribe to camera changes.
*
* @example
* const { unsubscribe } = await Forma.camera.subscribe((cameraState: CameraState) => {
* console.log("Camera was updated", cameraState)
* })
* // Later, when you want to stop listening for changes:
* unsubscribe()
*
* @param callback event handler for each camera change. Callback receives the new camera state as an argument.
* @returns { unsubscribe: () => void } object with an `unsubscribe` method to stop listening for changes
*/
subscribe(callback: (payload: CameraState) => void): Promise<{
unsubscribe: () => void;
}>;
}