UNPKG

@itwin/core-frontend

Version:
145 lines 5.98 kB
"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 WebGL */ Object.defineProperty(exports, "__esModule", { value: true }); exports.MeshGraphic = exports.MeshRenderGeometry = void 0; const core_bentley_1 = require("@itwin/core-bentley"); const SurfaceParams_1 = require("../../../common/internal/render/SurfaceParams"); const Graphic_1 = require("./Graphic"); const Primitive_1 = require("./Primitive"); const EdgeGeometry_1 = require("./EdgeGeometry"); const IndexedEdgeGeometry_1 = require("./IndexedEdgeGeometry"); const SurfaceGeometry_1 = require("./SurfaceGeometry"); const MeshData_1 = require("./MeshData"); /** @internal */ class MeshRenderGeometry { renderGeometryType = "mesh"; isInstanceable; noDispose = false; data; surface; segmentEdges; silhouetteEdges; polylineEdges; indexedEdges; range; constructor(data, params) { this.data = data; this.isInstanceable = data.viewIndependentOrigin === undefined; this.range = params.vertices.qparams.computeRange(); this.surface = SurfaceGeometry_1.SurfaceGeometry.create(data, params); const edges = params.edges; if (!edges || data.type === SurfaceParams_1.SurfaceType.VolumeClassifier) return; if (edges.silhouettes) this.silhouetteEdges = EdgeGeometry_1.SilhouetteEdgeGeometry.createSilhouettes(data, edges.silhouettes); if (edges.segments) this.segmentEdges = EdgeGeometry_1.EdgeGeometry.create(data, edges.segments); if (edges.polylineGroups) { this.polylineEdges = []; for (const group of edges.polylineGroups) { const polyline = EdgeGeometry_1.PolylineEdgeGeometry.create(data, group); if (polyline) { this.polylineEdges.push(polyline); } } } if (edges.indexed) this.indexedEdges = IndexedEdgeGeometry_1.IndexedEdgeGeometry.create(data, edges.indexed); } static create(params, viewIndependentOrigin) { const data = MeshData_1.MeshData.create(params, viewIndependentOrigin); return data ? new this(data, params) : undefined; } [Symbol.dispose]() { if (this.noDispose) { return; } (0, core_bentley_1.dispose)(this.data); (0, core_bentley_1.dispose)(this.surface); (0, core_bentley_1.dispose)(this.segmentEdges); (0, core_bentley_1.dispose)(this.silhouetteEdges); (0, core_bentley_1.disposeArray)(this.polylineEdges); (0, core_bentley_1.dispose)(this.indexedEdges); } get isDisposed() { return this.data.isDisposed && (!this.surface || this.surface.isDisposed) && (!this.segmentEdges || this.segmentEdges.isDisposed) && (!this.silhouetteEdges || this.silhouetteEdges.isDisposed) && (!this.polylineEdges || this.polylineEdges.every((x) => x.isDisposed)) && (!this.indexedEdges || this.indexedEdges.isDisposed); } collectStatistics(stats) { this.data.collectStatistics(stats); this.surface?.collectStatistics(stats); this.segmentEdges?.collectStatistics(stats); this.silhouetteEdges?.collectStatistics(stats); this.polylineEdges?.forEach((x) => x.collectStatistics(stats)); this.indexedEdges?.collectStatistics(stats); } computeRange(out) { return this.range.clone(out); } } exports.MeshRenderGeometry = MeshRenderGeometry; /** @internal */ class MeshGraphic extends Graphic_1.Graphic { meshData; _primitives = []; _instances; _meshRange; get primitives() { return this._primitives; } get meshRange() { return this._meshRange; } static create(geometry, instances) { return new MeshGraphic(geometry, instances); } addPrimitive(geometry) { if (!geometry) return; const primitive = Primitive_1.Primitive.createShared(geometry, this._instances); if (primitive) this._primitives.push(primitive); } constructor(geometry, instances) { super(); this.meshData = geometry.data; this._meshRange = geometry.range; this._instances = instances; this.addPrimitive(geometry.surface); this.addPrimitive(geometry.segmentEdges); this.addPrimitive(geometry.silhouetteEdges); this.addPrimitive(geometry.indexedEdges); geometry.polylineEdges?.forEach((x) => this.addPrimitive(x)); } get isDisposed() { return this.meshData.isDisposed && 0 === this._primitives.length; } get isPickable() { return false; } dispose() { for (const primitive of this._primitives) (0, core_bentley_1.dispose)(primitive); (0, core_bentley_1.dispose)(this.meshData); (0, core_bentley_1.dispose)(this._instances); this._primitives.length = 0; } collectStatistics(stats) { this.meshData.collectStatistics(stats); this._primitives.forEach((prim) => prim.collectStatistics(stats)); this._instances?.collectStatistics(stats); } unionRange(range) { if (this._instances) range.extendRange(this._instances.range); else range.extendRange(this._meshRange); } addCommands(cmds) { this._primitives.forEach((prim) => prim.addCommands(cmds)); } addHiliteCommands(cmds, pass) { this._primitives.forEach((prim) => prim.addHiliteCommands(cmds, pass)); } get surfaceType() { return this.meshData.type; } } exports.MeshGraphic = MeshGraphic; //# sourceMappingURL=Mesh.js.map