forma-embedded-view-sdk
Version:
The Forma Embedded View SDK is a JavaScript library for creating custom extensions in Autodesk Forma (previously Spacemaker).
56 lines (54 loc) • 2.19 kB
JavaScript
/**
* Interact with the sun object in the 3D scene.
*
* @remarks
* Available via {@link auto.Forma | Forma}.{@link index.EmbeddedViewSdk.sun | sun}.
*/
export class SunApi {
#iframeMessenger;
/** @hidden */
constructor(iframeMessenger) {
this.#iframeMessenger = iframeMessenger;
}
/**
* Fetch the `Date` corresponding to the current position of the sun in the scene.
*
* @remarks
* Since `Date` objects in JavaScript are based on the instance where the script is run,
* it is important to capture the discrepancy between the machine local time and the time
* at the project location. We recommend using a library such as
* [Luxon](https://moment.github.io/luxon/) to handle this
* -- their website has a lot of good documentation on the intricacies of time zones.
*
* @returns Date for the current sun position.
*
* @example
* import { DateTime } from "luxon";
* const projectTimezone = await Forma.project.getTimezone();
* const projectDate = await Forma.sun.getDate()
* const currentDate = DateTime.fromJSDate(currentDate, { zone: projectTimezone });
*/
async getDate() {
return await this.#iframeMessenger.sendRequest("scene/sun/get-date");
}
/**
* Set the position of the sun in the scene.
*
* @remarks
* Since `Date` objects in JavaScript are based on the instance where the script is run,
* it is important to capture the discrepancy between the machine local time and the time
* at the project location. We recommend using a library such as
* [Luxon](https://moment.github.io/luxon/) to handle this
* -- their website has a lot of good documentation on the intricacies of time zones.
*
* @example
* import { DateTime } from "luxon";
*
* const projectTimezone = await Forma.project.getTimezone();
* const wantedDate = DateTime.fromISO("2023-07-01T13:37:00", { zone: projectTimezone });
* await Forma.sun.setDate({ date: wantedDate.toJSDate() });
*/
async setDate(request) {
await this.#iframeMessenger.sendRequest("scene/sun/set-date", request);
}
}