molstar
Version:
A comprehensive macromolecular library.
83 lines (82 loc) • 3.86 kB
JavaScript
/**
* Copyright (c) 2018-2022 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.ElementPointVisual = exports.createElementPoint = exports.ElementPointParams = void 0;
var tslib_1 = require("tslib");
var param_definition_1 = require("../../../mol-util/param-definition");
var units_visual_1 = require("../units-visual");
var points_1 = require("../../../mol-geo/geometry/points/points");
var points_builder_1 = require("../../../mol-geo/geometry/points/points-builder");
var linear_algebra_1 = require("../../../mol-math/linear-algebra");
var element_1 = require("./util/element");
var geometry_1 = require("../../../mol-math/geometry");
// avoiding namespace lookup improved performance in Chrome (Aug 2020)
var v3add = linear_algebra_1.Vec3.add;
exports.ElementPointParams = tslib_1.__assign(tslib_1.__assign({}, units_visual_1.UnitsPointsParams), { pointSizeAttenuation: param_definition_1.ParamDefinition.Boolean(false), ignoreHydrogens: param_definition_1.ParamDefinition.Boolean(false), traceOnly: param_definition_1.ParamDefinition.Boolean(false) });
// TODO size
function createElementPoint(ctx, unit, structure, theme, props, points) {
// TODO sizeFactor
var child = structure.child;
if (child && !child.unitMap.get(unit.id))
return points_1.Points.createEmpty(points);
var elements = unit.elements;
var n = elements.length;
var builder = points_builder_1.PointsBuilder.create(n, n / 10, points);
var p = (0, linear_algebra_1.Vec3)();
var pos = unit.conformation.invariantPosition;
var ignore = (0, element_1.makeElementIgnoreTest)(structure, unit, props);
var center = (0, linear_algebra_1.Vec3)();
var count = 0;
if (ignore) {
for (var i = 0; i < n; ++i) {
if (ignore(elements[i]))
continue;
pos(elements[i], p);
v3add(center, center, p);
count += 1;
builder.add(p[0], p[1], p[2], i);
}
}
else {
for (var i = 0; i < n; ++i) {
pos(elements[i], p);
v3add(center, center, p);
count += 1;
builder.add(p[0], p[1], p[2], i);
}
}
var oldBoundingSphere = points ? geometry_1.Sphere3D.clone(points.boundingSphere) : undefined;
var pt = builder.getPoints();
if (count === 0)
return pt;
// re-use boundingSphere if it has not changed much
var boundingSphere;
linear_algebra_1.Vec3.scale(center, center, 1 / count);
if (oldBoundingSphere && linear_algebra_1.Vec3.distance(center, oldBoundingSphere.center) / oldBoundingSphere.radius < 1.0) {
boundingSphere = oldBoundingSphere;
}
else {
boundingSphere = geometry_1.Sphere3D.expand((0, geometry_1.Sphere3D)(), unit.boundary.sphere, 1 * props.sizeFactor);
}
pt.setBoundingSphere(boundingSphere);
return pt;
}
exports.createElementPoint = createElementPoint;
function ElementPointVisual(materialId) {
return (0, units_visual_1.UnitsPointsVisual)({
defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.ElementPointParams),
createGeometry: createElementPoint,
createLocationIterator: element_1.ElementIterator.fromGroup,
getLoci: element_1.getElementLoci,
eachLocation: element_1.eachElement,
setUpdateState: function (state, newProps, currentProps) {
state.createGeometry = (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens ||
newProps.traceOnly !== currentProps.traceOnly);
}
}, materialId);
}
exports.ElementPointVisual = ElementPointVisual;
;