UNPKG

@itwin/core-common

Version:

iTwin.js components common to frontend and backend

108 lines 5.61 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Rendering */ import { ColorDef } from "./ColorDef"; /** As part of a [[ColorIndex]], describes per-vertex colors for a [MeshArgs]($frontend) or [PolylineArgs]($frontend). * The [[colors]] array holds the set of unique colors. The [[indices]] array describes the color of each vertex as an index into [[colors]]. * @note A `NonUniformColor` table cannot contain a mix of opaque and translucent colors. If any color in [[colors]] has a transparency greater * than zero, all of them must have a transparency greater than zero. * @public */ export class NonUniformColor { /** An array of 32-bit [[ColorDef]] values in `tbgr` format, indexed by [[indices]]. */ colors; /** For each vertex, an index into [[colors]] indicating the color of that vertex. */ indices; /** If `true`, indicates none of the [[colors]] have a transparency greater than zero; otherwise, all of * the colors have a transparency greater than zero. */ isOpaque; /** Constructor. * @param colors See [[colors]]. * @param indices See [[indices]] * @param hasAlpha `true` if all `colors` have a transparency greater than zero, or `false` if they all have a transparency of zero. */ constructor(colors, indices, hasAlpha) { this.colors = new Uint32Array(colors.buffer); this.indices = Uint16Array.from(indices); this.isOpaque = !hasAlpha; } } /** Describes the color(s) of the vertices of a [MeshArgs]($frontend) or [PolylineArgs]($frontend). * This may be a uniform color to be applied to every vertex, or a table specifying individual per-vertex colors. * @public */ export class ColorIndex { _color; /** Whether the color(s) in this index have transparency. */ get hasAlpha() { return !this._color.isOpaque; } /** Whether this index specifies a single uniform color for the entire mesh or polyline. */ get isUniform() { return this._color instanceof ColorDef; } // Note: this.nonUniform will always return a value if this.isUniform is false. /** The number of colors in this index. */ get numColors() { return this.isUniform ? 1 : this.nonUniform.colors.length; } // eslint-disable-line @typescript-eslint/no-non-null-assertion /** Construct a default index specifying a uniform white color. */ constructor() { this._color = ColorDef.white; } /** Reset this index to specify a uniform white color. */ reset() { this._color = ColorDef.white; } /** Returns the single color to be applied to all vertices, if [[isUniform]] is `true`; or `undefined` otherwise. */ get uniform() { return this.isUniform ? this._color : undefined; } /** Set the specified color to be applied to all vertices. */ initUniform(color) { this._color = typeof color === "number" ? ColorDef.fromJSON(color) : color; } /** Returns the per-vertex colors, if [[isUniform]] is `false`; or `undefined` otherwise. */ get nonUniform() { return !this.isUniform ? this._color : undefined; } /** Set the per-vertex colors. * @param colors See [[NonUniformColor.colors]]. * @param indices See [[NonUniformColor.indices]]. * @param hasAlpha `true` if all `colors` have a transparency greater than zero, or `false` if they all have a transparency of zero. */ initNonUniform(colors, indices, hasAlpha) { this._color = new NonUniformColor(colors, indices, hasAlpha); } } /** Describes the type of a [[FeatureIndex]]. * @public */ export var FeatureIndexType; (function (FeatureIndexType) { /** Indicates that the index contains no features. */ FeatureIndexType[FeatureIndexType["Empty"] = 0] = "Empty"; /** Indicates that the index contains exactly one feature. */ FeatureIndexType[FeatureIndexType["Uniform"] = 1] = "Uniform"; /** Indicates that the index contains more than one feature. */ FeatureIndexType[FeatureIndexType["NonUniform"] = 2] = "NonUniform"; })(FeatureIndexType || (FeatureIndexType = {})); /** Describes the set of [[Feature]]s associated with a [MeshArgs]($frontend) or [PolylineArgs]($frontend). * The mesh or polyline may have zero or one features; or, individual vertices may be associated with different features. * The features are expressed as unsigned 32-bit integer Ids of [[Feature]]s within a [[FeatureTable]]. * @public */ export class FeatureIndex { /** Describes the quantity (zero, one, or more than one) of features in this index. */ type = FeatureIndexType.Empty; /** If [[type]] is [[FeatureIndexType.Uniform]], the Id of the single feature. */ featureID = 0; /** If [[type]] is [[FeatureIndexType.NonUniform]], the per-vertex feature Ids, indexed by the mesh or polyline's vertex indices. */ featureIDs; /** True if [[type]] is [[FeatureIndexType.Uniform]]. */ get isUniform() { return FeatureIndexType.Uniform === this.type; } /** True if [[type]] is [[FeatureIndexType.Empty]]. */ get isEmpty() { return FeatureIndexType.Empty === this.type; } /** Reset to an empty index. */ reset() { this.type = FeatureIndexType.Empty; this.featureID = 0; this.featureIDs = undefined; } } //# sourceMappingURL=FeatureIndex.js.map