molstar
Version:
A comprehensive macromolecular library.
173 lines • 9.86 kB
JavaScript
"use strict";
/**
* Copyright (c) 2018-2021 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.Points = 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 Points;
(function (Points) {
function create(centers, groups, pointCount, points) {
return points ?
update(centers, groups, pointCount, points) :
fromArrays(centers, groups, pointCount);
}
Points.create = create;
function createEmpty(points) {
var cb = points ? points.centerBuffer.ref.value : new Float32Array(0);
var gb = points ? points.groupBuffer.ref.value : new Float32Array(0);
return create(cb, gb, 0, points);
}
Points.createEmpty = createEmpty;
function hashCode(points) {
return (0, util_3.hashFnv32a)([
points.pointCount, points.centerBuffer.ref.version, points.groupBuffer.ref.version,
]);
}
function fromArrays(centers, groups, pointCount) {
var boundingSphere = (0, geometry_1.Sphere3D)();
var groupMapping;
var currentHash = -1;
var currentGroup = -1;
var points = {
kind: 'points',
pointCount: pointCount,
centerBuffer: mol_util_1.ValueCell.create(centers),
groupBuffer: mol_util_1.ValueCell.create(groups),
get boundingSphere() {
var newHash = hashCode(points);
if (newHash !== currentHash) {
var b = (0, util_2.calculateInvariantBoundingSphere)(points.centerBuffer.ref.value, points.pointCount, 1);
geometry_1.Sphere3D.copy(boundingSphere, b);
currentHash = newHash;
}
return boundingSphere;
},
get groupMapping() {
if (points.groupBuffer.ref.version !== currentGroup) {
groupMapping = (0, util_1.createGroupMapping)(points.groupBuffer.ref.value, points.pointCount);
currentGroup = points.groupBuffer.ref.version;
}
return groupMapping;
},
setBoundingSphere: function (sphere) {
geometry_1.Sphere3D.copy(boundingSphere, sphere);
currentHash = hashCode(points);
}
};
return points;
}
function update(centers, groups, pointCount, points) {
points.pointCount = pointCount;
mol_util_1.ValueCell.update(points.centerBuffer, centers);
mol_util_1.ValueCell.update(points.groupBuffer, groups);
return points;
}
function transform(points, t) {
var c = points.centerBuffer.ref.value;
(0, util_1.transformPositionArray)(t, c, 0, points.pointCount);
mol_util_1.ValueCell.update(points.centerBuffer, c);
}
Points.transform = transform;
//
Points.StyleTypes = {
'square': 'Square',
'circle': 'Circle',
'fuzzy': 'Fuzzy',
};
Points.StyleTypeNames = Object.keys(Points.StyleTypes);
Points.Params = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, base_1.BaseGeometry.Params), { sizeFactor: param_definition_1.ParamDefinition.Numeric(3, { min: 0, max: 10, step: 0.1 }), pointSizeAttenuation: param_definition_1.ParamDefinition.Boolean(false), pointStyle: param_definition_1.ParamDefinition.Select('square', param_definition_1.ParamDefinition.objectToOptions(Points.StyleTypes)) });
Points.Utils = {
Params: Points.Params,
createEmpty: createEmpty,
createValues: createValues,
createValuesSimple: createValuesSimple,
updateValues: updateValues,
updateBoundingSphere: updateBoundingSphere,
createRenderableState: createRenderableState,
updateRenderableState: updateRenderableState,
createPositionIterator: createPositionIterator
};
function createPositionIterator(points, transform) {
var groupCount = points.pointCount;
var instanceCount = transform.instanceCount.ref.value;
var location = (0, location_iterator_1.PositionLocation)();
var p = location.position;
var v = points.centerBuffer.ref.value;
var m = transform.aTransform.ref.value;
var getLocation = function (groupIndex, instanceIndex) {
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, 1, getLocation);
}
function createValues(points, transform, locationIt, theme, props) {
var instanceCount = locationIt.instanceCount, groupCount = locationIt.groupCount;
var positionIt = createPositionIterator(points, 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: points.pointCount, vertexCount: points.pointCount, groupCount: groupCount, instanceCount: instanceCount };
var invariantBoundingSphere = geometry_1.Sphere3D.clone(points.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)({ aPosition: points.centerBuffer, aGroup: points.groupBuffer, 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), base_1.BaseGeometry.createValues(props, counts)), { uSizeFactor: mol_util_1.ValueCell.create(props.sizeFactor), dPointSizeAttenuation: mol_util_1.ValueCell.create(props.pointSizeAttenuation), dPointStyle: mol_util_1.ValueCell.create(props.pointStyle) });
}
function createValuesSimple(points, 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(Points.Params)), props);
return createValues(points, 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);
mol_util_1.ValueCell.updateIfChanged(values.dPointSizeAttenuation, props.pointSizeAttenuation);
mol_util_1.ValueCell.updateIfChanged(values.dPointStyle, props.pointStyle);
}
function updateBoundingSphere(values, points) {
var invariantBoundingSphere = geometry_1.Sphere3D.clone(points.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.pointStyle !== 'fuzzy';
state.writeDepth = state.opaque;
}
})(Points = exports.Points || (exports.Points = {}));
//# sourceMappingURL=points.js.map