@itwin/core-frontend
Version:
iTwin.js frontend components
188 lines • 8.92 kB
JavaScript
"use strict";
/*---------------------------------------------------------------------------------------------
* 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
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Pixel = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
const core_common_1 = require("@itwin/core-common");
const HitDetail_1 = require("../HitDetail");
/** Describes aspects of a pixel as read from a [[Viewport]].
* @see [[Viewport.readPixels]].
* @public
* @extensions
*/
var Pixel;
(function (Pixel) {
/** Describes a single pixel within a [[Pixel.Buffer]]. */
class Data {
/** The feature that produced the pixel. */
feature;
modelId;
/** The pixel's depth in [[CoordSystem.Npc]] coordinates (0 to 1), or -1 if depth was not written or not requested. */
distanceFraction;
/** The type of geometry that produced the pixel. */
type;
/** The planarity of the geometry that produced the pixel. */
planarity;
/** @internal */
batchType;
/** The iModel from which the geometry producing the pixel originated. */
iModel;
/** Information about the [contour line]($docs/learning/display/ContourDisplay.md), if any, that generated this pixel.
* @beta
*/
contour;
/** @internal */
transformFromIModel;
/** @internal */
tileId;
/** The Id of the [ViewAttachment]($backend), if any, from which the pixel originated.
* @beta
*/
viewAttachmentId;
/** True if the pixel originated from a [[SpatialViewState]] attached via a [SectionDrawing]($backend).
* @beta
*/
inSectionDrawingAttachment;
/** @internal */
get isClassifier() {
return undefined !== this.batchType && core_common_1.BatchType.Primary !== this.batchType;
}
/** @internal */
constructor(args) {
this.distanceFraction = args?.distanceFraction ?? -1;
this.type = args?.type ?? GeometryType.Unknown;
this.planarity = args?.planarity ?? Planarity.Unknown;
this.inSectionDrawingAttachment = true === args?.inSectionDrawingAttachment;
if (!args) {
return;
}
if (args.feature) {
this.feature = new core_common_1.Feature(args.feature.elementId, args.feature.subCategoryId, args.feature.geometryClass);
}
this.modelId = args.feature?.modelId;
this.iModel = args.iModel;
this.tileId = args.tileId;
this.viewAttachmentId = args.viewAttachmentId;
this.transformFromIModel = args.transformFromIModel;
this.contour = args.contour;
}
/** The Id of the element that produced the pixel. */
get elementId() {
return this.feature?.elementId;
}
/** The Id of the [SubCategory]($backend) that produced the pixel. */
get subCategoryId() {
return this.feature?.subCategoryId;
}
/** The class of geometry that produced the pixel. */
get geometryClass() {
return this.feature?.geometryClass;
}
/** Computes the [[HitPriority]] of this pixel based on its [[type]] and [[planarity]]. */
computeHitPriority() {
switch (this.type) {
case Pixel.GeometryType.Surface:
return Pixel.Planarity.Planar === this.planarity ? HitDetail_1.HitPriority.PlanarSurface : HitDetail_1.HitPriority.NonPlanarSurface;
case Pixel.GeometryType.Linear:
return HitDetail_1.HitPriority.WireEdge;
case Pixel.GeometryType.Edge:
return Pixel.Planarity.Planar === this.planarity ? HitDetail_1.HitPriority.PlanarEdge : HitDetail_1.HitPriority.NonPlanarEdge;
case Pixel.GeometryType.Silhouette:
return HitDetail_1.HitPriority.SilhouetteEdge;
default:
return HitDetail_1.HitPriority.Unknown;
}
}
/** Convert this pixel to a [[Pixel.HitProps]] suitable for constructing a [[HitDetail]].
* @param viewport The viewport in which the hit originated.
*/
toHitProps(viewport) {
let path;
if (this.viewAttachmentId) {
const attachmentViewport = viewport.view.getAttachmentViewport({ viewAttachmentId: this.viewAttachmentId });
if (attachmentViewport) {
path = {
viewAttachment: {
viewport: attachmentViewport,
id: this.viewAttachmentId,
},
};
}
}
if (this.inSectionDrawingAttachment) {
const checkVp = path?.viewAttachment?.viewport ?? viewport;
const attachVp = checkVp.view.getAttachmentViewport({ inSectionDrawingAttachment: true });
if (attachVp) {
path = path ?? {};
path.sectionDrawingAttachment = { viewport: attachVp };
}
}
return {
sourceId: this.elementId ?? core_bentley_1.Id64.invalid,
priority: this.computeHitPriority(),
distFraction: this.distanceFraction,
subCategoryId: this.subCategoryId,
geometryClass: this.geometryClass,
modelId: this.modelId,
tileId: this.tileId,
isClassifier: this.isClassifier,
sourceIModel: this.iModel,
transformFromSourceIModel: this.transformFromIModel,
path,
contour: this.contour,
};
}
}
Pixel.Data = Data;
/** Describes the type of geometry that produced the [[Pixel.Data]]. */
let GeometryType;
(function (GeometryType) {
/** [[Pixel.Selector.GeometryAndDistance]] was not specified, or the type could not be determined. */
GeometryType[GeometryType["Unknown"] = 0] = "Unknown";
/** No geometry was rendered to this pixel. */
GeometryType[GeometryType["None"] = 1] = "None";
/** A surface produced this pixel. */
GeometryType[GeometryType["Surface"] = 2] = "Surface";
/** A point primitive or polyline produced this pixel. */
GeometryType[GeometryType["Linear"] = 3] = "Linear";
/** This pixel was produced by an edge of a surface. */
GeometryType[GeometryType["Edge"] = 4] = "Edge";
/** This pixel was produced by a silhouette edge of a curved surface. */
GeometryType[GeometryType["Silhouette"] = 5] = "Silhouette";
})(GeometryType = Pixel.GeometryType || (Pixel.GeometryType = {}));
/** Describes the planarity of the foremost geometry which produced the pixel. */
let Planarity;
(function (Planarity) {
/** [[Pixel.Selector.GeometryAndDistance]] was not specified, or the planarity could not be determined. */
Planarity[Planarity["Unknown"] = 0] = "Unknown";
/** No geometry was rendered to this pixel. */
Planarity[Planarity["None"] = 1] = "None";
/** Planar geometry produced this pixel. */
Planarity[Planarity["Planar"] = 2] = "Planar";
/** Non-planar geometry produced this pixel. */
Planarity[Planarity["NonPlanar"] = 3] = "NonPlanar";
})(Planarity = Pixel.Planarity || (Pixel.Planarity = {}));
/**
* Bit-mask by which callers of [[Viewport.readPixels]] specify which aspects are of interest.
* Aspects not specified will be omitted from the returned data.
*/
let Selector;
(function (Selector) {
Selector[Selector["None"] = 0] = "None";
/** Select the [[Feature]] which produced each pixel. */
Selector[Selector["Feature"] = 1] = "Feature";
/** Select the type and planarity of geometry which produced each pixel as well as the fraction of its distance between the near and far planes. */
Selector[Selector["GeometryAndDistance"] = 4] = "GeometryAndDistance";
/** Select the [[ContourHit]]s describing which if any contour line produced each pixel. */
Selector[Selector["Contours"] = 8] = "Contours";
/** Select all aspects of each pixel. */
Selector[Selector["All"] = 13] = "All";
})(Selector = Pixel.Selector || (Pixel.Selector = {}));
})(Pixel || (exports.Pixel = Pixel = {}));
//# sourceMappingURL=Pixel.js.map