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).
123 lines (122 loc) • 5.31 kB
JavaScript
/**
* The Forma Site Design element system is composed of internal (private) representation and
* derived (public) representation. The RepresentationsApi allows you to access
* the derived representations of elements. The internal is owned by the authoring
* application and is private to all other components of the system.
*
* For a given element you can inspect the `representations` property to see what
* representations are available.
*
* One important point is that the representations are given in the local coordinate
* system of the element. These need to be transformed to the global coordinate system
* of the proposal to be used in the context of the proposal. To do this you can use the
* `Forma.elements.getWorldTransform` method, and then applying this as an affine
* transformation to the representation.
*
* @example
* void Forma.selection.subscribe(({ paths }) => {
* const { element } = await Forma.elements.getByPath({ path: paths[0] })
* if (element.representations?.volumeMesh) {
* const volume = await Forma.elements.representations.volumeMesh(element)
* }
* })
*
*
* @remarks
* Avaliable via {@link auto.Forma | Forma}.{@link index.EmbeddedViewSdk.elements | elements}.{@link index.EmbeddedViewSdk.elements.representations | representations}.
*/
export class RepresentationsApi {
#iframeMessenger;
/** @hidden */
constructor(iframeMessenger) {
this.#iframeMessenger = iframeMessenger;
}
/**
* Get the volume mesh for the element, the volume mesh is a triangulated visual model.
* The data is returned as a buffer of gltf data.
*
* Refer to the Typescript type of `element.representations.volumeMesh` for a
* detailed description of the volume mesh representation.
*
* If the `id` field is set, then the returned volume mesh is a batch where you
* need to extract the mesh with the given id. The id is set as a name property
* on the mesh inside the gltf file.
*
* @param request urn of the element
*
* @example
* const { element } = await Forma.elements.get({ urn })
* if (element.representations?.volumeMesh) {
* const volume = await Forma.elements.representations.volumeMesh(element)
* }
*
* @returns The volume mesh representation of the element
*/
async volumeMesh(request) {
return await this.#iframeMessenger.sendRequest("elements/representations/volume-mesh", request);
}
/**
* Get the footprint of the element, the footprint is a 2D representation of
* the space the element occupies on the ground plane.
*
* Refer to the Typescript type of `element.representations.footprint` for a
* detailed description of the footprint representation.
*
* If the `id` field is set, then the returned footprints is a batch where you
* need to extract the feature with the given id. The id is set as the id property
* on the Feature inside the FeatureCollection.
*
* @param request urn of the element
*
* @example
* const { element } = await Forma.elements.get({ urn })
* if (element.representations?.footprint) {
* const {id, data} = await Forma.elements.representations.footprint(element)
*
* const feature = data.features.find(f => f.id === id)
* }
*
* @returns The footprint representation of the element
*/
async footprint(request) {
return await this.#iframeMessenger.sendRequest("elements/representations/footprint", request);
}
/**
* Get the gross floor area of the element as a set of 3d positined polygons.
*
* Refer to the Typescript type of `element.representations.grossFloorAreaPolygons` for a
* detailed description of the gross floor area polygons representation.
*
* @param request urn of the element
*
* @example
* const { element } = await Forma.elements.get({ urn })
* if (element.representations?.grossFloorAreaPolygons) {
* const grossFloorAreaPolygons = await Forma.elements.representations.grossFloorAreaPolygons(element)
* }
*
* @returns The gross floor area polygons representation of the element
*/
async grossFloorAreaPolygons(request) {
return await this.#iframeMessenger.sendRequest("elements/representations/gross-floor-area-polygons", request);
}
/**
* The graph building describes the partitioning of space for a building. The representation is composed of an ordered set of vertically-aligned levels and an unordered set of units, which may span multiple levels.
*
* Refer to the Typescript type of `element.representations.graphBuilding` for a
* detailed description of the graph building representation.
*
* @param request urn of the element
*
* @example
* const { element } = await Forma.elements.get({ urn })
* if (element.representations?.graphBuilding) {
* const graphBuilding = await Forma.elements.representations.graphBuilding(element)
* }
*
* @returns The graph building representation of the element
*/
async graphBuilding(request) {
return await this.#iframeMessenger.sendRequest("elements/representations/graph-building", request);
}
}