molstar
Version:
A comprehensive macromolecular library.
101 lines (100 loc) • 5.87 kB
JavaScript
/**
* Copyright (c) 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.PolymerBackboneSphereMeshVisual = exports.PolymerBackboneSphereImpostorVisual = exports.PolymerBackboneSphereVisual = exports.PolymerBackboneSphereParams = void 0;
var tslib_1 = require("tslib");
var param_definition_1 = require("../../../mol-util/param-definition");
var structure_1 = require("../../../mol-model/structure");
var mesh_1 = require("../../../mol-geo/geometry/mesh/mesh");
var mesh_builder_1 = require("../../../mol-geo/geometry/mesh/mesh-builder");
var linear_algebra_1 = require("../../../mol-math/linear-algebra");
var polymer_1 = require("./util/polymer");
var units_visual_1 = require("../units-visual");
var base_1 = require("../../../mol-geo/geometry/base");
var geometry_1 = require("../../../mol-math/geometry");
var sphere_1 = require("../../../mol-geo/geometry/mesh/builder/sphere");
var sphere_2 = require("../../../mol-geo/primitive/sphere");
var spheres_1 = require("../../../mol-geo/geometry/spheres/spheres");
var spheres_builder_1 = require("../../../mol-geo/geometry/spheres/spheres-builder");
var backbone_1 = require("./util/polymer/backbone");
exports.PolymerBackboneSphereParams = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, units_visual_1.UnitsMeshParams), units_visual_1.UnitsSpheresParams), { sizeFactor: param_definition_1.ParamDefinition.Numeric(0.3, { min: 0, max: 10, step: 0.01 }), detail: param_definition_1.ParamDefinition.Numeric(0, { min: 0, max: 3, step: 1 }, base_1.BaseGeometry.CustomQualityParamInfo), tryUseImpostor: param_definition_1.ParamDefinition.Boolean(true) });
function PolymerBackboneSphereVisual(materialId, structure, props, webgl) {
return props.tryUseImpostor && webgl && webgl.extensions.fragDepth
? PolymerBackboneSphereImpostorVisual(materialId)
: PolymerBackboneSphereMeshVisual(materialId);
}
exports.PolymerBackboneSphereVisual = PolymerBackboneSphereVisual;
function createPolymerBackboneSphereImpostor(ctx, unit, structure, theme, props, spheres) {
var polymerElementCount = unit.polymerElements.length;
if (!polymerElementCount)
return spheres_1.Spheres.createEmpty(spheres);
var builder = spheres_builder_1.SpheresBuilder.create(polymerElementCount, polymerElementCount / 2, spheres);
var pos = unit.conformation.invariantPosition;
var p = (0, linear_algebra_1.Vec3)();
var add = function (index, group) {
pos(index, p);
builder.add(p[0], p[1], p[2], group);
};
(0, backbone_1.eachPolymerBackboneElement)(unit, add);
var s = builder.getSpheres();
var sphere = geometry_1.Sphere3D.expand((0, geometry_1.Sphere3D)(), unit.boundary.sphere, 1 * props.sizeFactor);
s.setBoundingSphere(sphere);
return s;
}
function PolymerBackboneSphereImpostorVisual(materialId) {
return (0, units_visual_1.UnitsSpheresVisual)({
defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.PolymerBackboneSphereParams),
createGeometry: createPolymerBackboneSphereImpostor,
createLocationIterator: polymer_1.PolymerLocationIterator.fromGroup,
getLoci: polymer_1.getPolymerElementLoci,
eachLocation: polymer_1.eachPolymerElement,
setUpdateState: function (state, newProps, currentProps) { },
mustRecreate: function (structureGroup, props, webgl) {
return !props.tryUseImpostor || !webgl;
}
}, materialId);
}
exports.PolymerBackboneSphereImpostorVisual = PolymerBackboneSphereImpostorVisual;
function createPolymerBackboneSphereMesh(ctx, unit, structure, theme, props, mesh) {
var polymerElementCount = unit.polymerElements.length;
if (!polymerElementCount)
return mesh_1.Mesh.createEmpty(mesh);
var detail = props.detail, sizeFactor = props.sizeFactor;
var vertexCount = polymerElementCount * (0, sphere_2.sphereVertexCount)(detail);
var builderState = mesh_builder_1.MeshBuilder.createState(vertexCount, vertexCount / 2, mesh);
var pos = unit.conformation.invariantPosition;
var p = (0, linear_algebra_1.Vec3)();
var center = structure_1.StructureElement.Location.create(structure, unit);
var add = function (index, group) {
center.element = index;
pos(center.element, p);
builderState.currentGroup = group;
(0, sphere_1.addSphere)(builderState, p, theme.size.size(center) * sizeFactor, detail);
};
(0, backbone_1.eachPolymerBackboneElement)(unit, add);
var m = mesh_builder_1.MeshBuilder.getMesh(builderState);
var sphere = geometry_1.Sphere3D.expand((0, geometry_1.Sphere3D)(), unit.boundary.sphere, 1 * props.sizeFactor);
m.setBoundingSphere(sphere);
return m;
}
function PolymerBackboneSphereMeshVisual(materialId) {
return (0, units_visual_1.UnitsMeshVisual)({
defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.PolymerBackboneSphereParams),
createGeometry: createPolymerBackboneSphereMesh,
createLocationIterator: polymer_1.PolymerLocationIterator.fromGroup,
getLoci: polymer_1.getPolymerElementLoci,
eachLocation: polymer_1.eachPolymerElement,
setUpdateState: function (state, newProps, currentProps) {
state.createGeometry = (newProps.sizeFactor !== currentProps.sizeFactor ||
newProps.detail !== currentProps.detail);
},
mustRecreate: function (structureGroup, props, webgl) {
return props.tryUseImpostor && !!webgl;
}
}, materialId);
}
exports.PolymerBackboneSphereMeshVisual = PolymerBackboneSphereMeshVisual;
;