UNPKG

molstar

Version:

A comprehensive macromolecular library.

89 lines (88 loc) 4.85 kB
"use strict"; /** * Copyright (c) 2018-2019 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.PolymerGapVisual = exports.PolymerGapParams = exports.DefaultPolymerGapCylinderProps = exports.PolymerGapCylinderParams = void 0; var tslib_1 = require("tslib"); var param_definition_1 = require("../../../mol-util/param-definition"); 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 cylinder_1 = require("../../../mol-geo/geometry/mesh/builder/cylinder"); var units_visual_1 = require("../units-visual"); var base_1 = require("../../../mol-geo/geometry/base"); var geometry_1 = require("../../../mol-math/geometry"); // import { TriangularPyramid } from '../../../mol-geo/primitive/pyramid'; var segmentCount = 10; exports.PolymerGapCylinderParams = { sizeFactor: param_definition_1.ParamDefinition.Numeric(0.2, { min: 0, max: 10, step: 0.01 }), radialSegments: param_definition_1.ParamDefinition.Numeric(16, { min: 2, max: 56, step: 2 }, base_1.BaseGeometry.CustomQualityParamInfo), }; exports.DefaultPolymerGapCylinderProps = param_definition_1.ParamDefinition.getDefaultValues(exports.PolymerGapCylinderParams); // const triangularPyramid = TriangularPyramid() // const t = Mat4.identity() // const pd = Vec3.zero() function createPolymerGapCylinderMesh(ctx, unit, structure, theme, props, mesh) { var polymerGapCount = unit.gapElements.length; if (!polymerGapCount) return mesh_1.Mesh.createEmpty(mesh); var sizeFactor = props.sizeFactor, radialSegments = props.radialSegments; var vertexCountEstimate = segmentCount * radialSegments * 2 * polymerGapCount * 2; var builderState = mesh_builder_1.MeshBuilder.createState(vertexCountEstimate, vertexCountEstimate / 10, mesh); var pos = unit.conformation.invariantPosition; var pA = linear_algebra_1.Vec3.zero(); var pB = linear_algebra_1.Vec3.zero(); var cylinderProps = { radiusTop: 1, radiusBottom: 1, topCap: true, bottomCap: true, radialSegments: radialSegments }; var i = 0; var polymerGapIt = (0, polymer_1.PolymerGapIterator)(structure, unit); while (polymerGapIt.hasNext) { var _a = polymerGapIt.move(), centerA = _a.centerA, centerB = _a.centerB; if (centerA.element === centerB.element) { // TODO // builderState.currentGroup = i // pos(centerA.element, pA) // Vec3.add(pd, pA, Vec3.create(1, 0, 0)) // Mat4.targetTo(t, pA, pd, Vec3.create(0, 1, 0)) // Mat4.setTranslation(t, pA) // Mat4.scale(t, t, Vec3.create(0.7, 0.7, 2.5)) // MeshBuilder.addPrimitive(builderState, t, triangularPyramid) } else { pos(centerA.element, pA); pos(centerB.element, pB); cylinderProps.radiusTop = cylinderProps.radiusBottom = theme.size.size(centerA) * sizeFactor; builderState.currentGroup = i; (0, cylinder_1.addFixedCountDashedCylinder)(builderState, pA, pB, 0.5, segmentCount, cylinderProps); cylinderProps.radiusTop = cylinderProps.radiusBottom = theme.size.size(centerB) * sizeFactor; builderState.currentGroup = i + 1; (0, cylinder_1.addFixedCountDashedCylinder)(builderState, pB, pA, 0.5, segmentCount, cylinderProps); } i += 2; } 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; } exports.PolymerGapParams = tslib_1.__assign(tslib_1.__assign({}, units_visual_1.UnitsMeshParams), exports.PolymerGapCylinderParams); function PolymerGapVisual(materialId) { return (0, units_visual_1.UnitsMeshVisual)({ defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.PolymerGapParams), createGeometry: createPolymerGapCylinderMesh, createLocationIterator: polymer_1.PolymerGapLocationIterator.fromGroup, getLoci: polymer_1.getPolymerGapElementLoci, eachLocation: polymer_1.eachPolymerGapElement, setUpdateState: function (state, newProps, currentProps) { state.createGeometry = (newProps.sizeFactor !== currentProps.sizeFactor || newProps.radialSegments !== currentProps.radialSegments); } }, materialId); } exports.PolymerGapVisual = PolymerGapVisual;