@itwin/core-common
Version:
iTwin.js components common to frontend and backend
451 lines • 25.9 kB
TypeScript
import { BentleyStatus, Id64String } from "@itwin/core-bentley";
import { Angle, GeometryQuery, Point2d, Point3d, Range3d, Transform, Vector3d, YawPitchRollAngles } from "@itwin/core-geometry";
import { TextString, TextStringGlyphData, TextStringProps } from "./TextString";
import { GeometryParams } from "../GeometryParams";
import { BRepEntity } from "./GeometryStream";
import { ImageGraphic, ImageGraphicProps } from "./ImageGraphic";
import { ElementAlignedBox3d, Placement3d } from "./Placement";
import { PlacementProps } from "../ElementProps";
import { TextBlockGeometryProps } from "../annotation/TextBlockGeometryProps";
/** Specifies the type of an entry in a geometry stream.
* @see [[ElementGeometryDataEntry.opcode]].
* @public
* @extensions
*/
export declare enum ElementGeometryOpcode {
/** Local range of the next geometric primitive in the geometry stream. */
SubGraphicRange = 2,
/** A reference to a [GeometryPart]($backend). */
PartReference = 3,
/** Sets symbology for subsequent geometry to override [SubCategory]($backend) appearance */
BasicSymbology = 4,
/** A line, line string, shape, or point string (automatic simplification of a [CurvePrimitive]($core-geometry) or [CurveCollection]($core-geometry)) */
PointPrimitive = 5,
/** A 2d line, line string, shape, or point string (automatic simplification of a [CurvePrimitive]($core-geometry) or [CurveCollection]($core-geometry)) */
PointPrimitive2d = 6,
/** Arc or ellipse (automatic simplification of a [CurvePrimitive]($core-geometry) or [CurveCollection]($core-geometry)) */
ArcPrimitive = 7,
/** [CurveCollection]($core-geometry) */
CurveCollection = 8,
/** [Polyface]($core-geometry) */
Polyface = 9,
/** [CurvePrimitive]($core-geometry) */
CurvePrimitive = 10,
/** [SolidPrimitive]($core-geometry) */
SolidPrimitive = 11,
/** [BSplineSurface3d]($core-geometry) */
BsplineSurface = 12,
/** Opaque and [[Gradient]] fills. */
Fill = 19,
/** Hatch, cross-hatch, or [[AreaPattern]]. */
Pattern = 20,
/** [[RenderMaterial]] */
Material = 21,
/** [[TextString]] */
TextString = 22,
/** Specifies line style overrides as a [[LineStyle.Modifier]] */
LineStyleModifiers = 23,
/** Boundary representation solid, sheet, or wire body as a [[BRepEntity.DataProps]] */
BRep = 25,
/** Small single-tile raster image as an [[ImageGraphic]] */
Image = 28
}
/** Describes an entry in a geometry stream as an op-code plus the binary flatbuffer representation of the associated data.
* @see [[FlatBufferGeometryStream]].
* @public
* @extensions
*/
export interface ElementGeometryDataEntry {
/** The type of this entry. */
opcode: ElementGeometryOpcode;
/** Zero-based flatbuffer-encoded data. */
data: Uint8Array;
}
/** Information provided to [[ElementGeometryFunction]].
* @beta
*/
export interface ElementGeometryInfo {
/** ID for the [Category]($core-backend), undefined for geometry parts */
categoryId?: Id64String;
/** A row-major storage 4x3 transform to world coordinate, undefined for geometry parts */
sourceToWorld?: Float64Array;
/** The element aligned bounding box for the geometry stream stored as 6 values for low/high */
bbox?: Float64Array;
/** If true, geometry displays oriented to face the camera */
viewIndependent?: boolean;
/** If true, geometry stream contained breps that were omitted or replaced as requested */
brepsPresent?: boolean;
/** The geometry stream data */
entryArray: ElementGeometryDataEntry[];
}
/** A callback function that receives geometry stream data.
* @see [IModelDb.elementGeometryRequest]($core-backend)
* @beta
*/
export type ElementGeometryFunction = (info: ElementGeometryInfo) => void;
/** Parameters for [IModelDb.elementGeometryRequest]($core-backend)
* @beta
*/
export interface ElementGeometryRequest {
/** The source element for the geometry stream */
elementId: Id64String;
/** A function to call for the geometry stream data */
onGeometry: ElementGeometryFunction;
/** Whether to omit BRep data */
skipBReps?: boolean;
/** When not omitting BReps, whether to return a mesh or curve representation instead of the brep data */
replaceBReps?: boolean;
/** Option for replaceBReps, max distance from a face to the original geometry, see [StrokeOptions]($core-geometry) */
chordTol?: number;
/** Option for replaceBReps, max angle difference in radians for approximated face, see [StrokeOptions]($core-geometry) */
angleTol?: number;
/** Option for replaceBReps, max length of any edge in generated faces, see [StrokeOptions]($core-geometry) */
maxEdgeLength?: number;
/** Option for replaceBReps, ignore faces with bounding boxes smaller than this size when facetting */
minBRepFeatureSize?: number;
}
/** Parameters for building the geometry stream of a [GeometricElement]($backend) using [[ElementGeometry.Builder]].
* You can assign an object of this type to [[GeometricElementProps.elementGeometryBuilderParams]] when inserting or updating a geometric element.
* @note The geometry stream is always in local coordinates - that is, relative to the element's [[Placement]].
* @public
*/
export interface ElementGeometryBuilderParams {
/** The geometry stream data. Calling update element with a zero length array will clear the geometry stream and invalidate the placement. */
entryArray: ElementGeometryDataEntry[];
/** If true, create geometry that always displays oriented to face the camera */
viewIndependent?: boolean;
}
/** Parameters for building the geometry stream of a [GeometryPart]($backend) using [[ElementGeometry.Builder]].
* You can assign an object of this type to [[GeometryPartProps.elementGeometryBuilderParams]] when inserting or updating a part.
* @public
*/
export interface ElementGeometryBuilderParamsForPart {
/** The geometry stream data */
entryArray: ElementGeometryDataEntry[];
/** If true, create geometry part with 2d geometry */
is2dPart?: boolean;
}
/** Request parameters for [IModelDb.updateElementGeometryCache]($core-backend)
* @beta
*/
export interface ElementGeometryCacheRequestProps {
/** Geometric element to populate geometry cache for. Clear cache for all elements when undefined. */
id?: Id64String;
}
/** Response parameters for [IModelDb.updateElementGeometryCache]($core-backend)
* @beta
*/
export interface ElementGeometryCacheResponseProps {
/** Cache creation status */
status: BentleyStatus;
/** Count of displayable entries in element's geometry stream */
numGeom?: number;
/** Count of part references in element's geometry stream */
numPart?: number;
/** Count of solid/volumetric geometry in element's geometry stream */
numSolid?: number;
/** Count of surface/region geometry in element's geometry stream */
numSurface?: number;
/** Count of curve/path geometry in element's geometry stream */
numCurve?: number;
/** Count of text/image/non-geometric displayable entries in element's geometry stream */
numOther?: number;
}
/** Request parameters for [IModelDb.elementGeometryCacheOperation]($core-backend)
* @beta
*/
export interface ElementGeometryCacheOperationRequestProps {
/** Target element id, tool element ids can be supplied by parameters... */
id: Id64String;
/** Requested operation */
op: number;
/** Parameters for operation */
params?: any;
/** Callback for result when element's geometry stream is requested in flatbuffer or graphic formats */
onGeometry?: ElementGeometryFunction;
}
/** Values for [[BRepGeometryCreate.operation]]
* @alpha
*/
export declare enum BRepGeometryOperation {
/** Unite target (first entry) with one or more tool entities. */
Unite = 0,
/** Subtract one or more tool entities from target entity (first entry) */
Subtract = 1,
/** Intersect target (first entry) with one or more tool entities */
Intersect = 2,
/** Sew the given set of surfaces together by joining those that share edges in common */
Sew = 3,
/** Create a cut in the target (first entry) using a planar region (second entry) and optional depth */
Cut = 4,
/** Create a pad or pocket in the target (first entry) using a planar region (second entry) */
Emboss = 5,
/** Create a solid from a surface by offsetting using the specified forward and backward distances */
Thicken = 6,
/** Create a shelled solid by offsetting all faces by the supplied distance */
Hollow = 7,
/** Create a solid or surface by sweeping a planar profile (first entry) along a path (second entry) */
Sweep = 8,
/** Create a solid or surface by lofting through a set of paths or regions */
Loft = 9,
/** Create a solid or sheet with all non-smooth/non-laminar edges rounded */
Round = 10,
/** Offset all faces of a solid or sheet target by the supplied distance. */
Offset = 11
}
/** Parameters for [[BRepGeometryOperation.Cut]]
* @alpha
*/
export interface BRepCutProps {
/** Optional cut depth; through solid if not specified */
distance?: number;
/** Optional cut direction; in direction of profile normal if not specified */
bothDirections?: boolean;
}
/** Parameters for [[BRepGeometryOperation.Thicken]]
* @alpha
*/
export interface BRepThickenProps {
/** Offset to apply in surface normal direction; at least one of frontDistance or backDistance must be specified */
frontDistance?: number;
/** Offset to apply in reverse surface normal direction */
backDistance?: number;
}
/** Parameters for [[BRepGeometryOperation.Hollow]]
* @alpha
*/
export interface BRepHollowProps {
/** Offset to apply to all faces; positive value shells outwards, negative value shells inwards */
distance: number;
}
/** Parameters for [[BRepGeometryOperation.Round]]
* @alpha
*/
export interface BRepRoundProps {
/** Radius to apply to all non-laminar/non-smooth edges */
radius: number;
}
/** Parameters for [[BRepGeometryOperation.Offset]]
* @alpha
*/
export interface BRepOffsetProps {
/** Offset to apply to all faces; positive value offsets outwards, negative value offsets inwards */
distance: number;
}
/** Parameters for [IModelDb.createBRepGeometry]($core-backend)
* @alpha
*/
export interface BRepGeometryCreate {
/** The operation to perform on the input geometry */
operation: BRepGeometryOperation;
/** The input target and tool geometry (curves, surfaces, and solids) to perform the given operation on */
entryArray: ElementGeometryDataEntry[];
/** A function to call for the result geometry */
onResult: BRepGeometryFunction;
/** Whether disjoint results should be returned as multiple entries or a single disjoint body */
separateDisjoint?: boolean;
/** Options and parameters for this operation */
parameters?: BRepCutProps | BRepThickenProps | BRepHollowProps | BRepRoundProps | BRepOffsetProps;
}
/** Information provided to [[BRepGeometryFunction]].
* @alpha
*/
export interface BRepGeometryInfo {
/** The result geometry if the operation was successful */
entryArray: ElementGeometryDataEntry[];
}
/** A callback function that receives brep operation result geometry.
* @see [IModelDb.createBRepGeometry]($core-backend)
* @alpha
*/
export type BRepGeometryFunction = (info: BRepGeometryInfo) => void;
/** Provides utility functions for working with [[ElementGeometryDataEntry]].
* @beta
*/
export declare namespace ElementGeometry {
/** [[ElementGeometry.Builder]] is a helper class for populating a [[ElementGeometryDataEntry]] array needed to create a [[GeometricElement]] or [[GeometryPart]]. */
class Builder {
private _localToWorld?;
private _worldToLocal?;
/** GeometryStream entries */
readonly entries: ElementGeometryDataEntry[];
/** Current placement transform, converts local coordinate (placement relative) input to world */
get localToWorld(): Transform | undefined;
/** Current inverse placement transform, converts world coordinate input to local (placement relative) */
get worldToLocal(): Transform | undefined;
/** Supply optional local to world transform. Used to transform world coordinate input relative to element placement.
* For a [[GeometricElement]]'s placement to be meaningful, world coordinate geometry should never be appended to an element with an identity placement.
* Can be called with undefined or identity transform to start appending geometry supplied in local coordinates again.
*/
setLocalToWorld(localToWorld?: Transform): void;
/** Supply local to world transform from a Point3d and optional YawPitchRollAngles.
* @see [[Placement3d]]
*/
setLocalToWorld3d(origin: Point3d, angles?: YawPitchRollAngles): void;
/** Supply local to world transform from a Point2d and optional Angle.
* @see [[Placement2d]]
*/
setLocalToWorld2d(origin: Point2d, angle?: Angle): void;
/** Supply local to world transform from a PlacementProps2d or PlacementProps3d.
* @see [[PlacementProps]]
*/
setLocalToWorldFromPlacement(props: PlacementProps): void;
/** Compute angles suitable for passing to [[setLocalToWorld3d]] from an array of 3d points. */
static placementAnglesFromPoints(pts: Point3d[], defaultUp?: Vector3d, result?: YawPitchRollAngles): YawPitchRollAngles;
/** Compute angle suitable for passing to [[setLocalToWorld2d]] from an array of xy plane points. */
static placementAngleFromPoints(pts: Point3d[], result?: Angle): Angle;
/** Store local ranges for all subsequent geometry appended. Can improve performance of range testing for elements with a GeometryStream
* containing more than one [[GeometryQuery]] differentiable by range. Not useful for a single [[GeometryQuery]] as its range and that of the [[GeometricElement]] are the same.
* Ignored when defining a [[GeometryPart]] and not needed when only appending [[GeometryPart]] instances to a [[GeometricElement]] as these store their own range.
*/
appendGeometryRanges(): boolean;
/** Change [[GeometryParams]] for subsequent geometry.
* It is not valid to change the sub-category when defining a [[GeometryPart]]. A [[GeometryPart]] inherits the symbology of their instance for anything not explicitly overridden.
*/
appendGeometryParamsChange(geomParams: GeometryParams): boolean;
/** Append a [[GeometryQuery]] supplied in either local or world coordinates to the [[ElementGeometryDataEntry]] array */
appendGeometryQuery(geometry: GeometryQuery): boolean;
/** Append a [[TextString]] supplied in either local or world coordinates to the [[ElementGeometryDataEntry]] array */
appendTextString(text: TextString): boolean;
/** Append a series of entries representing a [[TextBlock]] to the [[ElementGeometryDataEntry]] array.
* @beta
*/
appendTextBlock(block: TextBlockGeometryProps, geomParams?: GeometryParams): boolean;
/** Append a [[ImageGraphic]] supplied in either local or world coordinates to the [[ElementGeometryDataEntry]] array */
appendImageGraphic(image: ImageGraphic): boolean;
/** Append a [[BRepEntity.DataProps]] supplied in either local or world coordinates to the [[ElementGeometryDataEntry]] array.
* Provided for compatibility with GeometryStreamBuilder only.
* Backend code should use IModelDb.createBRepGeometry to create a brep [[ElementGeometryDataEntry]] directly.
*/
appendBRepData(brep: BRepEntity.DataProps): boolean;
/** Append a [[GeometryPart]] instance with relative transform to the [[ElementGeometryDataEntry]] array for creating a [[GeometricElement]].
* Not valid when defining a [[GeometryPart]] as nesting of parts is not supported.
*/
appendGeometryPart(partId: Id64String, partTransform?: Transform): boolean;
/** Append a [[GeometryPart]] instance with relative position, orientation, and scale to the [[ElementGeometryDataEntry]] array for creating a [[GeometricElement3d]].
* Not valid when defining a [[GeometryPart]] as nesting of parts is not supported.
*/
appendGeometryPart3d(partId: Id64String, instanceOrigin?: Point3d, instanceRotation?: YawPitchRollAngles, instanceScale?: number): boolean;
/** Append a [[GeometryPart]] instance with relative position, orientation, and scale to the [[ElementGeometryDataEntry]] array for creating a [[GeometricElement2d]].
* Not valid when defining a [[GeometryPart]] as nesting of parts is not supported.
*/
appendGeometryPart2d(partId: Id64String, instanceOrigin?: Point2d, instanceRotation?: Angle, instanceScale?: number): boolean;
}
/** Current state information for [[ElementGeometry.Iterator]] */
interface IteratorData {
/** A [[GeometryParams]] representing the appearance of the current geometric entry */
readonly geomParams: GeometryParams;
/** Placement transform, used for converting placement relative, local coordinate entries to world */
readonly localToWorld?: Transform;
/** Optional stored local range for the current geometric entry */
readonly localRange?: Range3d;
/** The current displayable opcode */
readonly value: ElementGeometryDataEntry;
}
class IteratorEntry implements IteratorData {
readonly geomParams: GeometryParams;
readonly localToWorld?: Transform;
localRange?: Range3d;
private _value?;
private readonly _applyLocalToWorld;
constructor(geomParams: GeometryParams, localToWorld: Transform, applyLocalToWorld?: boolean);
get value(): ElementGeometryDataEntry;
set value(value: ElementGeometryDataEntry);
get outputTransform(): Transform | undefined;
/** Return the [[GeometryQuery]] representation for the current entry */
toGeometryQuery(): GeometryQuery | undefined;
/** Return the [[BRepEntity.DataProps]] representation for the current entry for checking brep type and face attachments. */
toBRepData(wantBRepData?: boolean): BRepEntity.DataProps | undefined;
/** Return the [[TextString]] representation for the current entry */
toTextString(): TextString | undefined;
/** Return the [[ImageGraphic]] representation for the current entry */
toImageGraphic(): ImageGraphic | undefined;
/** Return the GeometryPart information for the current entry */
toGeometryPart(partToLocal?: Transform, partToWorld?: Transform): Id64String | undefined;
}
/** [[ElementGeometry.Iterator]] is a helper class for iterating a [[ElementGeometryDataEntry]] array.
* Each [[ElementGeometryDataEntry]] returned by the iterator represents exactly one displayable entry.
*/
class Iterator implements IterableIterator<IteratorEntry> {
/** GeometryStream entries */
readonly entryArray: ElementGeometryDataEntry[];
/** The geometric element's placement or geometry part's local range (placement.bbox) */
readonly placement: Placement3d;
/** If true, geometry displays oriented to face the camera */
readonly viewIndependent?: boolean;
/** If true, geometry stream contained breps that were omitted or replaced as requested */
readonly brepsPresent?: boolean;
/** Current entry position */
private _index;
/** Allocated on first call to next() and reused thereafter */
private _entry?;
/** Used to initialize this._entry */
private readonly _appearance;
private readonly _localToWorld;
/** Whether deserialized entry data is returned in world or local coordinates */
private _applyLocalToWorld;
/** Construct a new Iterator given a [[ElementGeometryInfo]] from either a [[GeometricElement3d]], [[GeometricElement2d]], or [[GeometryPart]].
* Supply the optional [[GeometryParams]] and localToWorld transform to iterate a [[GeometryPart]] in the context of a [[GeometricElement]] reference.
*/
constructor(info: ElementGeometryInfo, categoryOrGeometryParams?: Id64String | GeometryParams, localToWorld?: Transform);
/** Call to return deserialized entry data in world coordinates */
requestWorldCoordinates(): void;
private get entry();
/** Advance to next displayable opcode (geometric entry or geometry part) while updating the current [[GeometryParams]] from appearance related opcodes. */
next(): IteratorResult<IteratorEntry>;
[Symbol.iterator](): IterableIterator<IteratorEntry>;
}
/** Return whether the supplied entry can be represented as a [[GeometryQuery]] */
function isGeometryQueryEntry(entry: ElementGeometryDataEntry): boolean;
/** Return whether the supplied entry is displayable geometry [[GeometryQuery]], [[BRepEntity.DataProps]], [[TextString]], or [[ImageGraphic]] */
function isGeometricEntry(entry: ElementGeometryDataEntry): boolean;
/** Return whether the supplied entry is geometric or a part reference */
function isDisplayableEntry(entry: ElementGeometryDataEntry): boolean;
/** Return whether the supplied entry represents appearance information */
function isAppearanceEntry(entry: ElementGeometryDataEntry): boolean;
/** Return whether the supplied entry represents a single open curve or path */
function isCurve(entry: ElementGeometryDataEntry): boolean;
/** Return whether the supplied entry represents a loop, planar region, open polyface, or sheet body */
function isSurface(entry: ElementGeometryDataEntry): boolean;
/** Return whether the supplied entry represents a capped solid, closed polyface, or solid body */
function isSolid(entry: ElementGeometryDataEntry): boolean;
/** Return the body type that would be used to represent the supplied entry */
function getBRepEntityType(entry: ElementGeometryDataEntry): BRepEntity.Type | undefined;
/** Return entry as a [[GeometryQuery]] */
function toGeometryQuery(entry: ElementGeometryDataEntry, localToWorld?: Transform): GeometryQuery | undefined;
/** Create entry from a [[GeometryQuery]] */
function fromGeometryQuery(geom: GeometryQuery, worldToLocal?: Transform): ElementGeometryDataEntry | undefined;
/** Return entry as a [[TextString]] */
function toTextString(entry: ElementGeometryDataEntry, localToWorld?: Transform): TextStringProps | undefined;
/** Returns only the [[TextStringGlyphData]] embedded in the [[TextString]] flatbuffer. This data is only internal to the native display libaries. */
function toTextStringGlyphData(entry: ElementGeometryDataEntry): TextStringGlyphData | undefined;
/** Create entry from a [[TextString]] */
function fromTextString(text: TextStringProps, worldToLocal?: Transform, glyphs?: TextStringGlyphData): ElementGeometryDataEntry | undefined;
/** Return entry as a [[ImageGraphic]] */
function toImageGraphic(entry: ElementGeometryDataEntry, localToWorld?: Transform): ImageGraphicProps | undefined;
/** Create entry from a [[ImageGraphic]] */
function fromImageGraphic(image: ImageGraphicProps, worldToLocal?: Transform): ElementGeometryDataEntry | undefined;
/** Return entry as a [[BRepEntity.DataProps]] for checking brep type and face attachments. */
function toBRep(entry: ElementGeometryDataEntry, wantBRepData?: boolean, localToWorld?: Transform): BRepEntity.DataProps | undefined;
/** Create entry from a [[BRepEntity.DataProps]]. Provided for compatibility with GeometryStreamBuilder only. */
function fromBRep(brep: BRepEntity.DataProps, worldToLocal?: Transform): ElementGeometryDataEntry | undefined;
/** Apply transform directly to ElementGeometryDataEntry for a BRep */
function transformBRep(entry: ElementGeometryDataEntry, inputTransform: Transform): boolean;
/** Update the supplied [[GeometryParams]] from an entry with appearance information */
function updateGeometryParams(entry: ElementGeometryDataEntry, geomParams: GeometryParams, localToWorld?: Transform): boolean;
/** Append entries to represent a [[GeometryParams]] */
function appendGeometryParams(geomParams: GeometryParams, entries: ElementGeometryDataEntry[], worldToLocal?: Transform): boolean;
/** Return entry as [[GeometryPart]] id and instance transform */
function toGeometryPart(entry: ElementGeometryDataEntry, partToElement?: Transform): Id64String | undefined;
/** Create entry from a [[GeometryPart]] id and instance transform */
function fromGeometryPart(partId: Id64String, partTransform?: Transform, worldToLocal?: Transform): ElementGeometryDataEntry | undefined;
/** Return entry as a [[ElementAlignedBox3d]] representing the local range of a geometric entry */
function toSubGraphicRange(entry: ElementGeometryDataEntry): ElementAlignedBox3d | undefined;
/** Create entry from a [[ElementAlignedBox3d]] to compute and store local ranges for subsequent geometric entries */
function fromSubGraphicRange(bbox: ElementAlignedBox3d): ElementGeometryDataEntry | undefined;
/** Create [[Transform]] from row-major storage 4x3 Float64Array */
function toTransform(sourceToWorld: Float64Array): Transform | undefined;
/** Create [[ElementAlignedBox3d]] from lowX, lowY, lowZ, highX, highY, highZ Float64Array */
function toElementAlignedBox3d(bbox: Float64Array): ElementAlignedBox3d | undefined;
}
//# sourceMappingURL=ElementGeometry.d.ts.map