UNPKG

@itwin/core-frontend

Version:
111 lines 6.02 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.MeshData = void 0; const core_bentley_1 = require("@itwin/core-bentley"); const core_common_1 = require("@itwin/core-common"); const LineCode_1 = require("./LineCode"); const Material_1 = require("./Material"); const VertexLUT_1 = require("./VertexLUT"); /** @internal */ class MeshData { edgeWidth; hasFeatures; uniformFeatureId; // Used strictly by BatchPrimitiveCommand.computeIsFlashed for flashing volume classification primitives. texture; normalMap; constantLodVParams; // size 3, contains texture offset x & y and fake ortho distance (which will be set during binding) constantLodFParams; // size 3, texture min and max size in worl units textureUsesConstantLod; normalMapUsesConstantLod; materialInfo; type; fillFlags; edgeLineCode; // Must call LineCode.valueFromLinePixels(val: LinePixels) and set the output to edgeLineCode isPlanar; hasBakedLighting; lut; viewIndependentOrigin; _textureAlwaysDisplayed; constructor(lut, params, viOrigin) { this.lut = lut; this.viewIndependentOrigin = viOrigin; this.hasFeatures = core_common_1.FeatureIndexType.Empty !== params.vertices.featureIndexType; if (core_common_1.FeatureIndexType.Uniform === params.vertices.featureIndexType) this.uniformFeatureId = params.vertices.uniformFeatureID; this.textureUsesConstantLod = false; this.normalMapUsesConstantLod = false; if (undefined !== params.surface.textureMapping) { this.texture = params.surface.textureMapping.texture; this._textureAlwaysDisplayed = params.surface.textureMapping.alwaysDisplayed; if (undefined !== params.surface.material && !params.surface.material.isAtlas) { const matTM = params.surface.material.material.textureMapping; if (undefined !== matTM) { this.textureUsesConstantLod = this.texture && matTM.params.useConstantLod; if (undefined !== matTM.normalMapParams) { this.normalMapUsesConstantLod = matTM.normalMapParams.useConstantLod; if (undefined !== matTM.normalMapParams.normalMap) { this.normalMap = matTM.normalMapParams.normalMap; } else { // If there are normal map params but the normal map is not present, use the texture as a normal map instead of a pattern map. this.normalMap = this.texture; this.texture = undefined; } } if (this.normalMapUsesConstantLod || this.textureUsesConstantLod) { this.constantLodVParams = new Float32Array(3); this.constantLodVParams[0] = matTM.params.constantLodParams.offset.x; // x offset this.constantLodVParams[1] = matTM.params.constantLodParams.offset.y; // y offset this.constantLodVParams[3] = 0.0; // placeholder for orto view distance this.constantLodFParams = new Float32Array(3); this.constantLodFParams[0] = matTM.params.constantLodParams.minDistClamp; // Minimum texture size this.constantLodFParams[1] = matTM.params.constantLodParams.maxDistClamp; // Maximum texture size this.constantLodFParams[2] = matTM.params.constantLodParams.repetitions; // # repetitions of pattern (to scale it) } } } } else { this.texture = undefined; this._textureAlwaysDisplayed = false; } this.materialInfo = (0, Material_1.createMaterialInfo)(params.surface.material); this.type = params.surface.type; this.fillFlags = params.surface.fillFlags; this.isPlanar = params.isPlanar; this.hasBakedLighting = params.surface.hasBakedLighting; const edges = params.edges; this.edgeWidth = undefined !== edges ? edges.weight : 1; this.edgeLineCode = LineCode_1.LineCode.valueFromLinePixels(undefined !== edges ? edges.linePixels : core_common_1.LinePixels.Solid); } static create(params, viOrigin) { const lut = VertexLUT_1.VertexLUT.createFromVertexTable(params.vertices, params.auxChannels); return undefined !== lut ? new MeshData(lut, params, viOrigin) : undefined; } get isDisposed() { return undefined === this.texture && this.lut.isDisposed; } [Symbol.dispose]() { (0, core_bentley_1.dispose)(this.lut); if (this._ownsTexture) (0, core_bentley_1.expectDefined)(this.texture)[Symbol.dispose](); } get isGlyph() { return undefined !== this.texture && this.texture.isGlyph; } get isTextureAlwaysDisplayed() { return this.isGlyph || this._textureAlwaysDisplayed; } // Returns true if no one else owns this texture. Implies that the texture should be disposed when this object is disposed, and the texture's memory should be tracked as belonging to this object. get _ownsTexture() { return undefined !== this.texture && !this.texture?.hasOwner; } collectStatistics(stats) { stats.addVertexTable(this.lut.bytesUsed); if (this._ownsTexture) stats.addTexture((0, core_bentley_1.expectDefined)(this.texture).bytesUsed); } } exports.MeshData = MeshData; //# sourceMappingURL=MeshData.js.map