UNPKG

forma-embedded-view-sdk

Version:

The Forma Embedded View SDK is a JavaScript library for creating custom extensions in Autodesk Forma (previously Spacemaker).

115 lines (114 loc) 5.09 kB
import type { IframeMessenger } from "./iframe-messenger.js"; export type WindDirectionData = { /** Degrees in clockwise orientation compared to North, i.e.: * 0: North * 45: North-East * 90: East * ... * 315: North-West */ direction: 0 | 45 | 90 | 135 | 180 | 225 | 270 | 315; /** Probability of wind coming from direction (0-1). Sum of probabilities for all directions must not exceed unity. */ probability: number; /** [Weibull parameters](https://en.wikipedia.org/wiki/Weibull_distribution) describing the probability distribution for incoming wind speed given the direction */ weibull_parameters: { scale: number; shape: number; }; }; export type WindParameters = { data: WindDirectionData[]; height: number; roughness: number; }; /** * HeightMaps represent a height raster for a given area. They are used as input to predict wind conditions for the area. * * The heightmaps should have a resolution of 500x500 provided as flat arrays in row-major order starting in north-west corner. Each pixel should represent a physical length of 1.5m. * * The area you are interested in getting a prediction for should be in the center of the 500x500 grid, as results are only provided for a 200*200 grid in the center. * * They need to be normalized with respect to the minimum and maximum height and fitted into the 0-255 (Uint8) range. * @example * // These should have length of 500*500 = 250000 * const terrainHeight = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] * const buildingAndTerrainHeight = [0, 10, 20, 60, 60, 60, 60, 70, 80, 90] * const minHeight = Math.min(...terrainHeight, ...buildingAndTerrainHeight) * const maxHeight = Math.max(...terrainHeight, buildingAndTerrainHeight) * const terrainHeightArray = terrainHeight.map((height) => { * return Math.round((height - minHeight) / (maxHeight - minHeight) * 255) * } * const buildingAndTerrainHeightArray = buildingAndTerrainHeight.map((height) => { * return Math.round((height - minHeight) / (maxHeight - minHeight) * 255) * } */ export type HeightMaps = { /** Height of terrain at each point normalized to values between 0-255 */ terrainHeightArray: number[]; /** Height of terrain+buildings at each point normalized to values between 0-255 */ buildingAndTerrainHeightArray: number[]; minHeight: number; maxHeight: number; }; export type PredictiveAnalysisGroundGrid = { /** Flat array representing row-major two dimensional grid width and height */ grid: Float32Array; /** Width of the grid */ width: number; /** Height of the grid */ height: number; /** Scale of each value in x and y direction in meters */ scale: { x: number; y: number; }; }; /** * Interact with Forma's native predictive models for [rapid analysis](https://help.autodeskforma.com/en/articles/6977396-rapid-wind-analysis). * * @remarks * Available via {@link auto.Forma | Forma}.{@link index.EmbeddedViewSdk.prediction | prediction}. */ export declare class PredictiveAnalysisApi { #private; constructor(iframeMessenger: IframeMessenger); /** * This function return the wind parameters used by Forma to predict wind conditions. * It includes a wind rose with 8 directions and a surface roughness. */ getWindParameters(): Promise<WindParameters>; /** * Predict wind conditions usings Forma's rapid wind model. * Read more about rapid wind at [Forma Help](https://help.autodeskforma.com/en/articles/6977396-rapid-wind-analysis). * * @returns 2d grid of wind conditions. For wind comfort values are 0-4 where lower is better conditions. * * @example * const windRose = await Forma.prediction.getWindParameters() * // See HeightMaps for more infor on how to create heightMaps * const heightMaps = computeHeightMaps(terrainGeometry, terrainAndBuildingsGeometry) * const prediction = await Forma.prediction.predictWind({ * heightMaps, * windRose, * type: "comfort", * roughness: windRose.roughness, * comfortScale: "lawson_lddc", * }) * // calculate statistics, mix with other grids, etc. */ predictWind(request: { /** HeightMaps represent a height raster for a given area. */ heightMaps: HeightMaps; /** Windrose with 8 directions. Value used by Forma can be retrieved using `getWindParameters`. */ windRose: { data: WindDirectionData[]; height: number; }; /** Type of wind results to predict. Only wind comfort supported for now. */ type: "comfort"; /** Surface roughness. Value used by Forma can be retrieved using `getWindParameters`. */ roughness: number; /** Read more about [Comfort scales](https://help.autodeskforma.com/en/articles/6994344-how-to-analyze-pedestrian-wind-comfort). */ comfortScale: "lawson_lddc" | "davenport" | "lawson" | "lawson_2001" | "nen8100" | "cstb"; }): Promise<PredictiveAnalysisGroundGrid>; }