UNPKG

@itwin/core-frontend

Version:
135 lines 7.76 kB
/** @packageDocumentation * @module Rendering */ import { Uint16ArrayBuilder, UintArray, UintArrayBuilder } from "@itwin/core-bentley"; import { IndexedPolyface, Range2d, Range3d, Transform, XAndY, XYAndZ } from "@itwin/core-geometry"; import { QPoint2dBuffer, QPoint2dBufferBuilder, QPoint3dBuffer, QPoint3dBufferBuilder, RenderTexture } from "@itwin/core-common"; import { GltfMeshData } from "../tile/internal"; import { LayerTileData } from "../internal/render/webgl/MapLayerParams"; /** Geometry for a reality mesh to be submitted to the [[RenderSystem]] for conversion to a [[RenderGraphic]]. * A reality mesh is a simple triangle mesh to which a [RenderTexture]($common) image can be mapped. Sources of reality meshes * include [[TerrainMeshProvider]]s to which background map imagery is applied, and [ContextRealityModel]($common)s captured using * [photogrammetry](https://en.wikipedia.org/wiki/Photogrammetry). * @see [[RealityMeshParamsBuilder]] to incrementally construct a `RealityMeshParams`. * @public */ export interface RealityMeshParams { /** The 3d position of each vertex in the mesh, indexed by [[indices]]. */ positions: QPoint3dBuffer; /** The 2d texture coordinates of each vertex in the mesh, indexed by [[indices]]. */ uvs: QPoint2dBuffer; /** The optional normal vector for each vertex in the mesh, indexed by [[indices]], stored as [OctEncodedNormal]($common)s. */ normals?: Uint16Array; /** The integer indices of each triangle in the mesh. The array's length must be a multiple of 3. */ indices: UintArray; /** @alpha unused by terrain meshes */ featureID?: number; /** @alpha unused by terrain meshes */ texture?: RenderTexture; /** @internal */ tileData?: LayerTileData; } /** @public */ export declare namespace RealityMeshParams { /** @internal */ function fromGltfMesh(mesh: GltfMeshData): RealityMeshParams | undefined; /** @alpha */ function toPolyface(params: RealityMeshParams, options?: { transform?: Transform; wantNormals?: boolean; wantParams?: boolean; }): IndexedPolyface | undefined; } /** Options used to construct a [[RealityMeshParamsBuilder]]. * @beta */ export interface RealityMeshParamsBuilderOptions { /** A bounding box fully containing the positions of all vertices to be included in the mesh. * This range is used to quantize [[RealityMeshParams.positions]]. */ positionRange: Range3d; /** A range fully containing the texture coordinates of all vertices to be included in the mesh. * This range is used to quantize [[RealityMeshParams.uvs]]. * Default: [0.0, 1.0]. */ uvRange?: Range2d; /** If true, [[RealityMeshParams.normals]] will be populated. * If you set this to true, you must supply a normal for every vertex when calling [[RealityMeshParamsBuilder.addQuantizedVertex]] or [[RealityMeshParamsBuilder.addUnquantizedVertex]]. */ wantNormals?: boolean; /** If defined, memory for this number of vertices will be allocated up-front. Set this if you know the minimum number of vertices in the mesh, to * avoid unnecessary reallocations when adding vertices. */ initialVertexCapacity?: number; /** If defined, memory for this number of indices will be allocated up-front. Set this if you know the minimum number of triangles in the mesh, to avoid * unnecessary reallocations when adding triangles. The number of indices is equal to three times the number of triangles. */ initialIndexCapacity?: number; } /** Incrementally constructs a [[RealityMeshParams]]. * The following simple example produces a rectangular mesh containing two triangles. * ```ts * [[include:Build_Reality_Mesh_Params]] * ``` * @beta */ export declare class RealityMeshParamsBuilder { /** The indices of the vertices in each triangle of the mesh. * @see [[addTriangle]] to add 3 indices describing a single triangle. * @see [[addQuad]] to add 4 indices describing two triangles sharing an edge. * @see [[addIndices]] to add any number of indices. */ readonly indices: UintArrayBuilder; /** The 3d position of each vertex in the mesh. * @see [[addQuantizedVertex]] and [[addUnquantizedVertex]] to add a vertex. */ readonly positions: QPoint3dBufferBuilder; /** The 2d texture coordinates of each vertex in the mesh. * @see [[addQuantizedVertex]] and [[addUnquantizedVertex]] to add a vertex. */ readonly uvs: QPoint2dBufferBuilder; /** The normal vector of each vertex in the mesh, or `undefined` if [[RealityMeshParamsBuilderOptions.wantNormals]] was not `true` when constructing the builder. * A normal vector must be supplied to [[addQuantizedVertex]] and [[addUnquantizedVertex]] if and only if [[RealityMeshParamsBuilderOptions.wantNormals]] was * specified as `true`. * The vectors are stored as [OctEncodedNormal]($common)s. */ normals?: Uint16ArrayBuilder; private readonly _q3d; private readonly _q2d; /** Construct a builder from the specified options. */ constructor(options: RealityMeshParamsBuilderOptions); /** Add a vertex to the mesh and return its index in [[positions]]. * @param position The 3d position, which will be quantized to the [[RealityMeshParamsBuilderOptions.positionRange]] supplied to the builder's constructor. * @param uv The texture coordinates, which will be quantized to the [[RealityMeshParamsBuilderOptions.uvRange]] supplied to the builder's constructor. * @param the normal vector, to be supplied if and only if [[RealityMeshParamsBuilderOptions.wantNormals]] was `true` when the builder was constructed. * @see [[addQuantizedVertex]] if your vertex data is already quantized. * @returns the index of the new vertex in [[positions]]. */ addUnquantizedVertex(position: XYAndZ, uv: XAndY, normal?: XYAndZ): number; /** Original API had weird mix of quantized and unquantized, used by CesiumTerrainProvider. * @internal */ addVertex(position: XYAndZ, uv: XAndY, normal?: number): void; /** Add a vertex to the mesh and return its index in [[positions]]. * @param position The 3d position, quantized to the [[RealityMeshParamsBuilderOptions.positionRange]] supplied to the builder's constructor. * @param uv The texture coordinates, quantized to the [[RealityMeshParamsBuilderOptions.uvRange]] supplied to the builder's constructor. * @param normal The unsigned 16-bit [OctEncodedNormal]($common) integer representation of the normal vector, to be supplied if and only if * [[RealityMeshParamsBuilderOptions.wantNormals]] was `true` when the builder was constructed. * @see [[addUnquantizedVertex]] if your vertex data is not already quantized. * @returns the index of the new vertex in [[positions]]. * @throws Error if `normal` is `undefined` but `wantNormals` was specified at construction of the builder, or vice-versa. */ addQuantizedVertex(position: XYAndZ, uv: XAndY, normal?: number): number; /** Add a triangle corresponding to the three specified vertices. */ addTriangle(i0: number, i1: number, i2: number): void; /** Add two triangles sharing an edge. This is equivalent to calling `addTriangle(i0, i1, i2); addTriangle(i1, i3, i2);`. */ addQuad(i0: number, i1: number, i2: number, i3: number): void; /** Add all of the indices in `indices` to the index buffer. */ addIndices(indices: Iterable<number>): void; private addIndex; /** Extract the finished [[RealityMeshParams]]. * @throws Error if the mesh contains no triangles. */ finish(): RealityMeshParams; } //# sourceMappingURL=RealityMeshParams.d.ts.map