molstar
Version:
A comprehensive macromolecular library.
193 lines • 12.6 kB
JavaScript
"use strict";
/**
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cylinders = void 0;
var tslib_1 = require("tslib");
var mol_util_1 = require("../../../mol-util");
var linear_algebra_1 = require("../../../mol-math/linear-algebra");
var util_1 = require("../../util");
var color_data_1 = require("../color-data");
var marker_data_1 = require("../marker-data");
var size_data_1 = require("../size-data");
var location_iterator_1 = require("../../util/location-iterator");
var param_definition_1 = require("../../../mol-util/param-definition");
var util_2 = require("../../../mol-gl/renderable/util");
var geometry_1 = require("../../../mol-math/geometry");
var base_1 = require("../base");
var overpaint_data_1 = require("../overpaint-data");
var transparency_data_1 = require("../transparency-data");
var util_3 = require("../../../mol-data/util");
var clipping_data_1 = require("../clipping-data");
var Cylinders;
(function (Cylinders) {
function create(mappings, indices, groups, starts, ends, scales, caps, cylinderCount, cylinders) {
return cylinders ?
update(mappings, indices, groups, starts, ends, scales, caps, cylinderCount, cylinders) :
fromArrays(mappings, indices, groups, starts, ends, scales, caps, cylinderCount);
}
Cylinders.create = create;
function createEmpty(cylinders) {
var mb = cylinders ? cylinders.mappingBuffer.ref.value : new Float32Array(0);
var ib = cylinders ? cylinders.indexBuffer.ref.value : new Uint32Array(0);
var gb = cylinders ? cylinders.groupBuffer.ref.value : new Float32Array(0);
var sb = cylinders ? cylinders.startBuffer.ref.value : new Float32Array(0);
var eb = cylinders ? cylinders.endBuffer.ref.value : new Float32Array(0);
var ab = cylinders ? cylinders.scaleBuffer.ref.value : new Float32Array(0);
var cb = cylinders ? cylinders.capBuffer.ref.value : new Float32Array(0);
return create(mb, ib, gb, sb, eb, ab, cb, 0, cylinders);
}
Cylinders.createEmpty = createEmpty;
function hashCode(cylinders) {
return (0, util_3.hashFnv32a)([
cylinders.cylinderCount, cylinders.mappingBuffer.ref.version, cylinders.indexBuffer.ref.version,
cylinders.groupBuffer.ref.version, cylinders.startBuffer.ref.version, cylinders.endBuffer.ref.version, cylinders.scaleBuffer.ref.version, cylinders.capBuffer.ref.version
]);
}
function fromArrays(mappings, indices, groups, starts, ends, scales, caps, cylinderCount) {
var boundingSphere = (0, geometry_1.Sphere3D)();
var groupMapping;
var currentHash = -1;
var currentGroup = -1;
var cylinders = {
kind: 'cylinders',
cylinderCount: cylinderCount,
mappingBuffer: mol_util_1.ValueCell.create(mappings),
indexBuffer: mol_util_1.ValueCell.create(indices),
groupBuffer: mol_util_1.ValueCell.create(groups),
startBuffer: mol_util_1.ValueCell.create(starts),
endBuffer: mol_util_1.ValueCell.create(ends),
scaleBuffer: mol_util_1.ValueCell.create(scales),
capBuffer: mol_util_1.ValueCell.create(caps),
get boundingSphere() {
var newHash = hashCode(cylinders);
if (newHash !== currentHash) {
var s = (0, util_2.calculateInvariantBoundingSphere)(cylinders.startBuffer.ref.value, cylinders.cylinderCount * 6, 6);
var e = (0, util_2.calculateInvariantBoundingSphere)(cylinders.endBuffer.ref.value, cylinders.cylinderCount * 6, 6);
geometry_1.Sphere3D.expandBySphere(boundingSphere, s, e);
currentHash = newHash;
}
return boundingSphere;
},
get groupMapping() {
if (cylinders.groupBuffer.ref.version !== currentGroup) {
groupMapping = (0, util_1.createGroupMapping)(cylinders.groupBuffer.ref.value, cylinders.cylinderCount, 6);
currentGroup = cylinders.groupBuffer.ref.version;
}
return groupMapping;
},
setBoundingSphere: function (sphere) {
geometry_1.Sphere3D.copy(boundingSphere, sphere);
currentHash = hashCode(cylinders);
}
};
return cylinders;
}
function update(mappings, indices, groups, starts, ends, scales, caps, cylinderCount, cylinders) {
if (cylinderCount > cylinders.cylinderCount) {
mol_util_1.ValueCell.update(cylinders.mappingBuffer, mappings);
mol_util_1.ValueCell.update(cylinders.indexBuffer, indices);
}
cylinders.cylinderCount = cylinderCount;
mol_util_1.ValueCell.update(cylinders.groupBuffer, groups);
mol_util_1.ValueCell.update(cylinders.startBuffer, starts);
mol_util_1.ValueCell.update(cylinders.endBuffer, ends);
mol_util_1.ValueCell.update(cylinders.scaleBuffer, scales);
mol_util_1.ValueCell.update(cylinders.capBuffer, caps);
return cylinders;
}
function transform(cylinders, t) {
var start = cylinders.startBuffer.ref.value;
(0, util_1.transformPositionArray)(t, start, 0, cylinders.cylinderCount * 6);
mol_util_1.ValueCell.update(cylinders.startBuffer, start);
var end = cylinders.endBuffer.ref.value;
(0, util_1.transformPositionArray)(t, end, 0, cylinders.cylinderCount * 6);
mol_util_1.ValueCell.update(cylinders.endBuffer, end);
}
Cylinders.transform = transform;
//
Cylinders.Params = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, base_1.BaseGeometry.Params), { sizeFactor: param_definition_1.ParamDefinition.Numeric(1, { min: 0, max: 10, step: 0.1 }), sizeAspectRatio: param_definition_1.ParamDefinition.Numeric(1, { min: 0, max: 3, step: 0.01 }), doubleSided: param_definition_1.ParamDefinition.Boolean(false, base_1.BaseGeometry.CustomQualityParamInfo), ignoreLight: param_definition_1.ParamDefinition.Boolean(false, base_1.BaseGeometry.ShadingCategory), xrayShaded: param_definition_1.ParamDefinition.Boolean(false, base_1.BaseGeometry.ShadingCategory) });
Cylinders.Utils = {
Params: Cylinders.Params,
createEmpty: createEmpty,
createValues: createValues,
createValuesSimple: createValuesSimple,
updateValues: updateValues,
updateBoundingSphere: updateBoundingSphere,
createRenderableState: createRenderableState,
updateRenderableState: updateRenderableState,
createPositionIterator: createPositionIterator
};
function createPositionIterator(cylinders, transform) {
var groupCount = cylinders.cylinderCount * 6;
var instanceCount = transform.instanceCount.ref.value;
var location = (0, location_iterator_1.PositionLocation)();
var p = location.position;
var s = cylinders.startBuffer.ref.value;
var e = cylinders.endBuffer.ref.value;
var m = transform.aTransform.ref.value;
var getLocation = function (groupIndex, instanceIndex) {
var v = groupIndex % 6 === 0 ? s : e;
if (instanceIndex < 0) {
linear_algebra_1.Vec3.fromArray(p, v, groupIndex * 3);
}
else {
linear_algebra_1.Vec3.transformMat4Offset(p, v, m, 0, groupIndex * 3, instanceIndex * 16);
}
return location;
};
return (0, location_iterator_1.LocationIterator)(groupCount, instanceCount, 2, getLocation);
}
function createValues(cylinders, transform, locationIt, theme, props) {
var instanceCount = locationIt.instanceCount, groupCount = locationIt.groupCount;
var positionIt = createPositionIterator(cylinders, transform);
var color = (0, color_data_1.createColors)(locationIt, positionIt, theme.color);
var size = (0, size_data_1.createSizes)(locationIt, theme.size);
var marker = (0, marker_data_1.createMarkers)(instanceCount * groupCount);
var overpaint = (0, overpaint_data_1.createEmptyOverpaint)();
var transparency = (0, transparency_data_1.createEmptyTransparency)();
var clipping = (0, clipping_data_1.createEmptyClipping)();
var counts = { drawCount: cylinders.cylinderCount * 4 * 3, vertexCount: cylinders.cylinderCount * 6, groupCount: groupCount, instanceCount: instanceCount };
var padding = (0, size_data_1.getMaxSize)(size) * props.sizeFactor;
var invariantBoundingSphere = geometry_1.Sphere3D.clone(cylinders.boundingSphere);
var boundingSphere = (0, util_2.calculateTransformBoundingSphere)(invariantBoundingSphere, transform.aTransform.ref.value, instanceCount);
return (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({ aMapping: cylinders.mappingBuffer, aGroup: cylinders.groupBuffer, aStart: cylinders.startBuffer, aEnd: cylinders.endBuffer, aScale: cylinders.scaleBuffer, aCap: cylinders.capBuffer, elements: cylinders.indexBuffer, boundingSphere: mol_util_1.ValueCell.create(boundingSphere), invariantBoundingSphere: mol_util_1.ValueCell.create(invariantBoundingSphere), uInvariantBoundingSphere: mol_util_1.ValueCell.create(linear_algebra_1.Vec4.ofSphere(invariantBoundingSphere)) }, color), size), marker), overpaint), transparency), clipping), transform), { padding: mol_util_1.ValueCell.create(padding) }), base_1.BaseGeometry.createValues(props, counts)), { uSizeFactor: mol_util_1.ValueCell.create(props.sizeFactor * props.sizeAspectRatio), dDoubleSided: mol_util_1.ValueCell.create(props.doubleSided), dIgnoreLight: mol_util_1.ValueCell.create(props.ignoreLight), dXrayShaded: mol_util_1.ValueCell.create(props.xrayShaded) });
}
function createValuesSimple(cylinders, props, colorValue, sizeValue, transform) {
var s = base_1.BaseGeometry.createSimple(colorValue, sizeValue, transform);
var p = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, param_definition_1.ParamDefinition.getDefaultValues(Cylinders.Params)), props);
return createValues(cylinders, s.transform, s.locationIterator, s.theme, p);
}
function updateValues(values, props) {
base_1.BaseGeometry.updateValues(values, props);
mol_util_1.ValueCell.updateIfChanged(values.uSizeFactor, props.sizeFactor * props.sizeAspectRatio);
mol_util_1.ValueCell.updateIfChanged(values.dDoubleSided, props.doubleSided);
mol_util_1.ValueCell.updateIfChanged(values.dIgnoreLight, props.ignoreLight);
mol_util_1.ValueCell.updateIfChanged(values.dXrayShaded, props.xrayShaded);
}
function updateBoundingSphere(values, cylinders) {
var invariantBoundingSphere = geometry_1.Sphere3D.clone(cylinders.boundingSphere);
var boundingSphere = (0, util_2.calculateTransformBoundingSphere)(invariantBoundingSphere, values.aTransform.ref.value, values.instanceCount.ref.value);
if (!geometry_1.Sphere3D.equals(boundingSphere, values.boundingSphere.ref.value)) {
mol_util_1.ValueCell.update(values.boundingSphere, boundingSphere);
}
if (!geometry_1.Sphere3D.equals(invariantBoundingSphere, values.invariantBoundingSphere.ref.value)) {
mol_util_1.ValueCell.update(values.invariantBoundingSphere, invariantBoundingSphere);
mol_util_1.ValueCell.update(values.uInvariantBoundingSphere, linear_algebra_1.Vec4.fromSphere(values.uInvariantBoundingSphere.ref.value, invariantBoundingSphere));
}
}
function createRenderableState(props) {
var state = base_1.BaseGeometry.createRenderableState(props);
updateRenderableState(state, props);
return state;
}
function updateRenderableState(state, props) {
base_1.BaseGeometry.updateRenderableState(state, props);
state.opaque = state.opaque && !props.xrayShaded;
state.writeDepth = state.opaque;
}
})(Cylinders = exports.Cylinders || (exports.Cylinders = {}));
//# sourceMappingURL=cylinders.js.map