@itwin/core-frontend
Version:
iTwin.js frontend components
111 lines • 4.81 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 WebGL
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.IndexedEdgeGeometry = exports.EdgeLUT = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
const core_common_1 = require("@itwin/core-common");
const Texture_1 = require("./Texture");
const AttributeBuffers_1 = require("./AttributeBuffers");
const MeshGeometry_1 = require("./MeshGeometry");
const AttributeMap_1 = require("./AttributeMap");
const GL_1 = require("./GL");
const System_1 = require("./System");
const ColorInfo_1 = require("./ColorInfo");
const LineCode_1 = require("../../../common/internal/render/LineCode");
/** @see [[EdgeTable]]
* @internal
*/
class EdgeLUT {
texture;
numSegments;
silhouettePadding;
constructor(texture, numSegments, silhouettePadding) {
this.texture = texture;
this.numSegments = numSegments;
this.silhouettePadding = silhouettePadding;
}
[Symbol.dispose]() {
(0, core_bentley_1.dispose)(this.texture);
}
static create(table) {
const texture = Texture_1.TextureHandle.createForData(table.width, table.height, table.data);
return texture ? new EdgeLUT(texture, table.numSegments, table.silhouettePadding) : undefined;
}
get bytesUsed() {
return this.texture.bytesUsed;
}
get isDisposed() {
return this.texture.isDisposed;
}
}
exports.EdgeLUT = EdgeLUT;
/** @see [[IndexedEdgeParams]]
* @internal
*/
class IndexedEdgeGeometry extends MeshGeometry_1.MeshGeometry {
_buffers;
_indices;
_colorInfo;
_width;
_lineCode;
edgeLut;
get lutBuffers() { return this._buffers; }
get asIndexedEdge() { return this; }
constructor(mesh, indices, numIndices, lut, appearance) {
super(mesh, numIndices);
this.edgeLut = lut;
this._buffers = AttributeBuffers_1.BuffersContainer.create();
const attrPos = AttributeMap_1.AttributeMap.findAttribute("a_pos", 6 /* TechniqueId.IndexedEdge */, false);
(0, core_bentley_1.assert)(undefined !== attrPos);
this._buffers.addBuffer(indices, [AttributeBuffers_1.BufferParameters.create(attrPos.location, 3, GL_1.GL.DataType.UnsignedByte, false, 0, 0, false)]);
this._indices = indices;
this._colorInfo = appearance?.color ? ColorInfo_1.ColorInfo.createFromColorDef(appearance.color) : mesh.lut.colorInfo;
this._width = appearance?.width ?? mesh.edgeWidth;
this._lineCode = appearance?.linePixels ? (0, LineCode_1.lineCodeFromLinePixels)(appearance?.linePixels) : mesh.edgeLineCode;
}
[Symbol.dispose]() {
(0, core_bentley_1.dispose)(this._buffers);
(0, core_bentley_1.dispose)(this._indices);
(0, core_bentley_1.dispose)(this.edgeLut);
}
get isDisposed() {
return this._buffers.isDisposed && this._indices.isDisposed && this.edgeLut.isDisposed;
}
static create(mesh, params) {
const indexBuffer = AttributeBuffers_1.BufferHandle.createArrayBuffer(params.indices.data);
const lut = EdgeLUT.create(params.edges);
return indexBuffer && lut ? new IndexedEdgeGeometry(mesh, indexBuffer, params.indices.length, lut, params.appearance) : undefined;
}
collectStatistics(stats) {
stats.addIndexedEdges(this._indices.bytesUsed);
stats.addEdgeTable(this.edgeLut.bytesUsed);
}
_draw(numInstances, instances) {
const bufs = instances ?? this._buffers;
bufs.bind();
System_1.System.instance.drawArrays(GL_1.GL.PrimitiveType.Triangles, 0, this._numIndices, numInstances);
bufs.unbind();
}
_wantWoWReversal() { return true; }
_getLineCode(params) {
return params.target.computeEdgeLineCode(params.renderPass, this._lineCode);
}
_getLineWeight(params) {
return params.target.computeEdgeWeight(params.renderPass, this._width);
}
getColor(target) {
return target.computeEdgeColor(this._colorInfo);
}
get techniqueId() { return 6 /* TechniqueId.IndexedEdge */; }
getPass(target) { return this.computeEdgePass(target); }
get renderOrder() { return this.isPlanar ? 14 /* RenderOrder.PlanarEdge */ : 6 /* RenderOrder.Edge */; }
wantMonochrome(target) { return target.currentViewFlags.renderMode === core_common_1.RenderMode.Wireframe; }
}
exports.IndexedEdgeGeometry = IndexedEdgeGeometry;
//# sourceMappingURL=IndexedEdgeGeometry.js.map