@itwin/core-frontend
Version:
iTwin.js frontend components
100 lines • 4.53 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.VertexLUT = exports.AuxChannelLUT = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
const ColorInfo_1 = require("./ColorInfo");
const AttributeBuffers_1 = require("./AttributeBuffers");
const Texture_1 = require("./Texture");
/** @internal */
class AuxChannelLUT {
texture;
numVertices;
numBytesPerVertex;
displacements;
normals;
params;
constructor(texture, table) {
this.texture = texture;
this.numVertices = table.numVertices;
this.numBytesPerVertex = table.numBytesPerVertex;
this.initChannels(table, "displacements");
this.initChannels(table, "normals");
this.initChannels(table, "params");
}
initChannels(table, name) {
const channels = table[name];
if (undefined === channels)
return;
const map = new Map();
// TS2322: Type 'Map<string, T>' is not assignable to type 'Map<string, AuxChannel> & Map<string, AuxDisplacementChannel> & Map<string, AuxParamChannel>'.
// (Compiler cannot detect that the specific property name is matched to the correct subtype at each call site - but we know that).
this[name] = map;
for (const channel of channels)
map.set(channel.name, channel);
}
get bytesUsed() { return this.texture.bytesUsed; }
get hasScalarAnimation() { return undefined !== this.params; }
get isDisposed() { return this.texture.isDisposed; }
[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 undefined !== texture ? new AuxChannelLUT(texture, table) : undefined;
}
}
exports.AuxChannelLUT = AuxChannelLUT;
/** Represents the finished lookup table ready for submission to GPU.
* @internal
*/
class VertexLUT {
texture; // Texture containing vertex data
numVertices;
numRgbaPerVertex;
colorInfo;
usesQuantizedPositions; // If true, positions are 16-bit integers quantized to qOrigin and qScale; otherwise they are unquantized 32-bit floats.
qOrigin; // Origin of quantized range
qScale; // Scale of quantized range
uvQParams; // If vertices contain texture UV params, quantization parameters as [origin.x, origin.y, scale.x, scale.y ]
auxChannels;
get hasAnimation() { return undefined !== this.auxChannels; }
get hasScalarAnimation() { return undefined !== this.auxChannels && this.auxChannels.hasScalarAnimation; }
get bytesUsed() {
let bytesUsed = this.texture.bytesUsed;
if (undefined !== this.auxChannels)
bytesUsed += this.auxChannels.bytesUsed;
return bytesUsed;
}
static createFromVertexTable(vt, aux) {
const texture = Texture_1.TextureHandle.createForData(vt.width, vt.height, vt.data);
if (undefined === texture)
return undefined;
const auxLUT = undefined !== aux ? AuxChannelLUT.create(aux) : undefined;
return new VertexLUT(texture, vt, ColorInfo_1.ColorInfo.createFromVertexTable(vt), vt.qparams, !vt.usesUnquantizedPositions, vt.uvParams, auxLUT);
}
constructor(texture, table, colorInfo, qparams, positionsAreQuantized, uvParams, auxChannels) {
this.texture = texture;
this.numVertices = table.numVertices;
this.numRgbaPerVertex = table.numRgbaPerVertex;
this.colorInfo = colorInfo;
this.qOrigin = (0, AttributeBuffers_1.qorigin3dToArray)(qparams.origin);
this.qScale = (0, AttributeBuffers_1.qscale3dToArray)(qparams.scale);
this.usesQuantizedPositions = positionsAreQuantized;
this.auxChannels = auxChannels;
if (undefined !== uvParams)
this.uvQParams = (0, AttributeBuffers_1.qparams2dToArray)(uvParams);
}
get isDisposed() { return this.texture.isDisposed; }
[Symbol.dispose]() {
(0, core_bentley_1.dispose)(this.texture);
}
}
exports.VertexLUT = VertexLUT;
//# sourceMappingURL=VertexLUT.js.map