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).
166 lines (165 loc) • 5.11 kB
TypeScript
import type { IframeMessenger } from "../iframe-messenger.js";
import { ElementColorApi } from "./element-colors.js";
import { RenderGeojsonApi } from "./renderGeoJson.js";
import { RenderGlbApi } from "./renderGlb.js";
/**
* Flattened list of a standard 4x4 affine transform matrix in column-major order.
* Translation values use metres as unit.
* */
export type Transform = [
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number,
number
];
/**
* Data format for generic triangulated mesh geometry.
*/
export type GeometryData = {
/** A flat array of x,y,z vertices. Each x,y,z tuple is know as a vertex. */
position: Float32Array;
/** The UV used for texture mapping for each vertex. Should be given as a u,v pair for each x,y,z position */
uv?: Float32Array | undefined;
/** A normal vector for each vertex */
normal?: Float32Array | undefined;
/** Flattened indexes for reusing vertices across triangles. Each three indices represents a triangle */
index?: number[] | undefined;
/** A flat list of r,g,b,a color per vertices. Each x,y,z tuple has a coorresponding r,g,b,a value. */
color?: Uint8Array | undefined;
};
/**
* Render or color objects and elements in the 3D scene.
*
* These APIs will only do visual changes to the proposal while extension is open.
* None of the changes will be saved to the proposal. And when the extension is
* closed we automatically clean up all changes made by these APIs.
*
* @remarks
* Available via {@link auto.Forma | Forma}.{@link index.EmbeddedViewSdk.render | render}.
*/
export declare class RenderApi {
#private;
glb: RenderGlbApi;
geojson: RenderGeojsonApi;
elementColors: ElementColorApi;
/** @hidden */
constructor(iframeMessenger: IframeMessenger);
/**
* Hide an element from the scene.
*
* @example
* await Forma.render.hideElement({ path: "root/myElementPath" })
*/
hideElement(request: {
path: string;
}): Promise<void>;
/**
* Hide a set of elements from the scene.
*
* @example
* await Forma.render.hideElementsBatch({ paths: ["root/myElement1", "root/myElement2"] })
*/
hideElementsBatch(request: {
paths: string[];
}): Promise<void>;
/**
* Unhide an element from the scene.
*
* @example
* await Forma.render.unhideElement({ path: "root/myElementPath" })
*/
unhideElement(request: {
path: string;
}): Promise<void>;
/**
* Unhide a set of elements from the scene.
*
* @example
* await Forma.render.unhideElementsBatch({ paths: ["root/myElement1", "root/myElement2"] })
*/
unhideElementsBatch(request: {
paths: string[];
}): Promise<void>;
/**
* Hides or unhides elements from the scene based on the `visible` parameter for each path.
*
* @example
* await Forma.render.setElementsVisibility( { [ { "root/myElement1", true}, { "root/myElement2", false} ] } )
*/
setElementsVisibility(request: {
paths: {
path: string;
visible: boolean;
}[];
}): Promise<void>;
/**
* Unhide all elements added by the hideElements function of this API from the scene.
*
* Called automatically when the extension is unloaded.
*
* @example
* await Forma.render.unhideAllElements()
*/
unhideAllElements(): Promise<void>;
/**
* Add a mesh to the scene.
*
* @returns Unique identifier of the mesh object in the scene.
*
* @example
* const {id} = await Forma.render.addMesh({ geometryData }),
*/
addMesh(request: {
/** Data describing the mesh to be added. */
geometryData: GeometryData;
/** Transform to position the element relative to the project reference point. Defaults to identity matrix. */
transform?: Transform | undefined;
}): Promise<{
id: string;
}>;
/**
* Upsert an mesh in the scene. If the mesh does not exist, it will be added.
*
* @example
* await Forma.render.updateMesh({ id: "myPreviouslyAddedGlbId", geometryData })
*/
updateMesh(request: {
/** Scene identifier of the mesh object to update. */
id: string;
/** Updated data describing the mesh. */
geometryData: GeometryData;
/** Updated transform to apply. */
transform?: Transform | undefined;
}): Promise<void>;
/**
* Remove an existing mesh from the scene.
*
* @example
* await Forma.render.remove({ id: "myPreviouslyAddedMeshId" })
*/
remove(request: {
/** Scene identifier of the mesh object to remove. */
id: string;
}): Promise<void>;
/**
* Remove all meshes added by this API from the scene.
*
* Called automatically when the extension is unloaded.
*
* @example
* await Forma.render.cleanup()
*/
cleanup(): Promise<void>;
}