UNPKG

molstar

Version:

A comprehensive macromolecular library.

137 lines 8.54 kB
/** * Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __assign } from "tslib"; import { ValueCell } from '../../../mol-util'; import { Sphere3D } from '../../../mol-math/geometry'; import { ParamDefinition as PD } from '../../../mol-util/param-definition'; import { LocationIterator } from '../../../mol-geo/util/location-iterator'; import { createColors } from '../color-data'; import { createMarkers } from '../marker-data'; import { BaseGeometry } from '../base'; import { createEmptyOverpaint } from '../overpaint-data'; import { createEmptyTransparency } from '../transparency-data'; import { calculateTransformBoundingSphere } from '../../../mol-gl/renderable/util'; import { createNullTexture } from '../../../mol-gl/webgl/texture'; import { Vec2, Vec4 } from '../../../mol-math/linear-algebra'; import { createEmptyClipping } from '../clipping-data'; import { NullLocation } from '../../../mol-model/location'; export var TextureMesh; (function (TextureMesh) { var DoubleBuffer = /** @class */ (function () { function DoubleBuffer() { this.index = 0; this.textures = []; } DoubleBuffer.prototype.get = function () { return this.textures[this.index]; }; DoubleBuffer.prototype.set = function (vertex, group, normal) { this.textures[this.index] = Object.assign(this.textures[this.index] || {}, { vertex: vertex, group: group, normal: normal }); this.index = (this.index + 1) % 2; }; DoubleBuffer.prototype.destroy = function () { for (var _i = 0, _a = this.textures; _i < _a.length; _i++) { var buffer = _a[_i]; buffer.vertex.destroy(); buffer.group.destroy(); buffer.normal.destroy(); } }; return DoubleBuffer; }()); TextureMesh.DoubleBuffer = DoubleBuffer; function create(vertexCount, groupCount, vertexTexture, groupTexture, normalTexture, boundingSphere, textureMesh) { var width = vertexTexture.getWidth(); var height = vertexTexture.getHeight(); if (textureMesh) { textureMesh.vertexCount = vertexCount; textureMesh.groupCount = groupCount; ValueCell.update(textureMesh.geoTextureDim, Vec2.set(textureMesh.geoTextureDim.ref.value, width, height)); ValueCell.update(textureMesh.vertexTexture, vertexTexture); ValueCell.update(textureMesh.groupTexture, groupTexture); ValueCell.update(textureMesh.normalTexture, normalTexture); textureMesh.doubleBuffer.set(vertexTexture, groupTexture, normalTexture); Sphere3D.copy(textureMesh.boundingSphere, boundingSphere); return textureMesh; } else { return { kind: 'texture-mesh', vertexCount: vertexCount, groupCount: groupCount, geoTextureDim: ValueCell.create(Vec2.create(width, height)), vertexTexture: ValueCell.create(vertexTexture), groupTexture: ValueCell.create(groupTexture), normalTexture: ValueCell.create(normalTexture), doubleBuffer: new DoubleBuffer(), boundingSphere: Sphere3D.clone(boundingSphere), }; } } TextureMesh.create = create; function createEmpty(textureMesh) { var vt = textureMesh ? textureMesh.vertexTexture.ref.value : createNullTexture(); var gt = textureMesh ? textureMesh.groupTexture.ref.value : createNullTexture(); var nt = textureMesh ? textureMesh.normalTexture.ref.value : createNullTexture(); var bs = textureMesh ? textureMesh.boundingSphere : Sphere3D(); return create(0, 0, vt, gt, nt, bs, textureMesh); } TextureMesh.createEmpty = createEmpty; TextureMesh.Params = __assign(__assign({}, BaseGeometry.Params), { doubleSided: PD.Boolean(false, BaseGeometry.CustomQualityParamInfo), flipSided: PD.Boolean(false, BaseGeometry.ShadingCategory), flatShaded: PD.Boolean(false, BaseGeometry.ShadingCategory), ignoreLight: PD.Boolean(false, BaseGeometry.ShadingCategory), xrayShaded: PD.Boolean(false, BaseGeometry.ShadingCategory) }); TextureMesh.Utils = { Params: TextureMesh.Params, createEmpty: createEmpty, createValues: createValues, createValuesSimple: createValuesSimple, updateValues: updateValues, updateBoundingSphere: updateBoundingSphere, createRenderableState: BaseGeometry.createRenderableState, updateRenderableState: BaseGeometry.updateRenderableState, createPositionIterator: function () { return LocationIterator(1, 1, 1, function () { return NullLocation; }); } }; function createValues(textureMesh, transform, locationIt, theme, props) { var instanceCount = locationIt.instanceCount, groupCount = locationIt.groupCount; var positionIt = TextureMesh.Utils.createPositionIterator(textureMesh, transform); var color = createColors(locationIt, positionIt, theme.color); var marker = createMarkers(instanceCount * groupCount); var overpaint = createEmptyOverpaint(); var transparency = createEmptyTransparency(); var clipping = createEmptyClipping(); var counts = { drawCount: textureMesh.vertexCount, vertexCount: textureMesh.vertexCount, groupCount: groupCount, instanceCount: instanceCount }; var invariantBoundingSphere = Sphere3D.clone(textureMesh.boundingSphere); var boundingSphere = calculateTransformBoundingSphere(invariantBoundingSphere, transform.aTransform.ref.value, instanceCount); return __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({ uGeoTexDim: textureMesh.geoTextureDim, tPosition: textureMesh.vertexTexture, tGroup: textureMesh.groupTexture, tNormal: textureMesh.normalTexture, boundingSphere: ValueCell.create(boundingSphere), invariantBoundingSphere: ValueCell.create(invariantBoundingSphere), uInvariantBoundingSphere: ValueCell.create(Vec4.ofSphere(invariantBoundingSphere)) }, color), marker), overpaint), transparency), clipping), transform), BaseGeometry.createValues(props, counts)), { dDoubleSided: ValueCell.create(props.doubleSided), dFlatShaded: ValueCell.create(props.flatShaded), dFlipSided: ValueCell.create(props.flipSided), dIgnoreLight: ValueCell.create(props.ignoreLight), dXrayShaded: ValueCell.create(props.xrayShaded), dGeoTexture: ValueCell.create(true) }); } function createValuesSimple(textureMesh, props, colorValue, sizeValue, transform) { var s = BaseGeometry.createSimple(colorValue, sizeValue, transform); var p = __assign(__assign({}, PD.getDefaultValues(TextureMesh.Params)), props); return createValues(textureMesh, s.transform, s.locationIterator, s.theme, p); } function updateValues(values, props) { BaseGeometry.updateValues(values, props); ValueCell.updateIfChanged(values.dDoubleSided, props.doubleSided); ValueCell.updateIfChanged(values.dFlatShaded, props.flatShaded); ValueCell.updateIfChanged(values.dFlipSided, props.flipSided); ValueCell.updateIfChanged(values.dIgnoreLight, props.ignoreLight); ValueCell.updateIfChanged(values.dXrayShaded, props.xrayShaded); } function updateBoundingSphere(values, textureMesh) { var invariantBoundingSphere = Sphere3D.clone(textureMesh.boundingSphere); var boundingSphere = calculateTransformBoundingSphere(invariantBoundingSphere, values.aTransform.ref.value, values.instanceCount.ref.value); if (!Sphere3D.equals(boundingSphere, values.boundingSphere.ref.value)) { ValueCell.update(values.boundingSphere, boundingSphere); } if (!Sphere3D.equals(invariantBoundingSphere, values.invariantBoundingSphere.ref.value)) { ValueCell.update(values.invariantBoundingSphere, invariantBoundingSphere); ValueCell.update(values.uInvariantBoundingSphere, Vec4.fromSphere(values.uInvariantBoundingSphere.ref.value, invariantBoundingSphere)); } } })(TextureMesh || (TextureMesh = {})); //# sourceMappingURL=texture-mesh.js.map