molstar
Version:
A comprehensive macromolecular library.
156 lines (155 loc) • 8.51 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.BaseGeometry = exports.getColorSmoothingProps = exports.hasColorSmoothingProp = exports.ColorSmoothingParams = exports.VisualQualityOptions = exports.VisualQualityNames = exports.VisualQualityInfo = void 0;
var mol_util_1 = require("../../mol-util");
var location_iterator_1 = require("../util/location-iterator");
var param_definition_1 = require("../../mol-util/param-definition");
var transform_data_1 = require("./transform-data");
var names_1 = require("../../mol-util/color/names");
var location_1 = require("../../mol-model/location");
var uniform_1 = require("../../mol-theme/color/uniform");
var uniform_2 = require("../../mol-theme/size/uniform");
var interpolate_1 = require("../../mol-math/interpolate");
var material_1 = require("../../mol-util/material");
var clip_1 = require("../../mol-util/clip");
exports.VisualQualityInfo = {
'custom': {},
'auto': {},
'highest': {},
'higher': {},
'high': {},
'medium': {},
'low': {},
'lower': {},
'lowest': {},
};
exports.VisualQualityNames = Object.keys(exports.VisualQualityInfo);
exports.VisualQualityOptions = param_definition_1.ParamDefinition.arrayToOptions(exports.VisualQualityNames);
//
exports.ColorSmoothingParams = {
smoothColors: param_definition_1.ParamDefinition.MappedStatic('auto', {
auto: param_definition_1.ParamDefinition.Group({}),
on: param_definition_1.ParamDefinition.Group({
resolutionFactor: param_definition_1.ParamDefinition.Numeric(2, { min: 0.5, max: 6, step: 0.1 }),
sampleStride: param_definition_1.ParamDefinition.Numeric(3, { min: 1, max: 12, step: 1 }),
}),
off: param_definition_1.ParamDefinition.Group({})
}),
};
function hasColorSmoothingProp(props) {
return !!props.smoothColors;
}
exports.hasColorSmoothingProp = hasColorSmoothingProp;
function getColorSmoothingProps(smoothColors, preferSmoothing, resolution) {
if ((smoothColors.name === 'on' || (smoothColors.name === 'auto' && preferSmoothing)) && resolution && resolution < 3) {
var stride = 3;
if (smoothColors.name === 'on') {
resolution *= smoothColors.params.resolutionFactor;
stride = smoothColors.params.sampleStride;
}
else {
// https://graphtoy.com/?f1(x,t)=(2-smoothstep(0,1.1,x))*x&coords=0.7,0.6,1.8
resolution *= 2 - (0, interpolate_1.smoothstep)(0, 1.1, resolution);
resolution = Math.max(0.5, resolution);
if (resolution > 1.2)
stride = 2;
}
return { resolution: resolution, stride: stride };
}
;
}
exports.getColorSmoothingProps = getColorSmoothingProps;
//
var BaseGeometry;
(function (BaseGeometry) {
BaseGeometry.MaterialCategory = { category: 'Material' };
BaseGeometry.ShadingCategory = { category: 'Shading' };
BaseGeometry.CustomQualityParamInfo = {
category: 'Custom Quality',
hideIf: function (params) { return typeof params.quality !== 'undefined' && params.quality !== 'custom'; }
};
BaseGeometry.Params = {
alpha: param_definition_1.ParamDefinition.Numeric(1, { min: 0, max: 1, step: 0.01 }, { label: 'Opacity', isEssential: true, description: 'How opaque/transparent the representation is rendered.' }),
quality: param_definition_1.ParamDefinition.Select('auto', exports.VisualQualityOptions, { isEssential: true, description: 'Visual/rendering quality of the representation.' }),
material: material_1.Material.getParam(),
clip: param_definition_1.ParamDefinition.Group(clip_1.Clip.Params),
instanceGranularity: param_definition_1.ParamDefinition.Boolean(false, { description: 'Use instance granularity for marker, transparency, clipping, overpaint, substance data to save memory.' }),
};
function createSimple(colorValue, sizeValue, transform) {
if (colorValue === void 0) { colorValue = names_1.ColorNames.grey; }
if (sizeValue === void 0) { sizeValue = 1; }
if (!transform)
transform = (0, transform_data_1.createIdentityTransform)();
var locationIterator = (0, location_iterator_1.LocationIterator)(1, transform.instanceCount.ref.value, 1, function () { return location_1.NullLocation; }, false, function () { return false; });
var theme = {
color: (0, uniform_1.UniformColorTheme)({}, { value: colorValue }),
size: (0, uniform_2.UniformSizeTheme)({}, { value: sizeValue })
};
return { transform: transform, locationIterator: locationIterator, theme: theme };
}
BaseGeometry.createSimple = createSimple;
function createValues(props, counts) {
var clip = clip_1.Clip.getClip(props.clip);
return {
alpha: mol_util_1.ValueCell.create(props.alpha),
uAlpha: mol_util_1.ValueCell.create(props.alpha),
uVertexCount: mol_util_1.ValueCell.create(counts.vertexCount),
uGroupCount: mol_util_1.ValueCell.create(counts.groupCount),
drawCount: mol_util_1.ValueCell.create(counts.drawCount),
uMetalness: mol_util_1.ValueCell.create(props.material.metalness),
uRoughness: mol_util_1.ValueCell.create(props.material.roughness),
uBumpiness: mol_util_1.ValueCell.create(props.material.bumpiness),
dLightCount: mol_util_1.ValueCell.create(1),
dColorMarker: mol_util_1.ValueCell.create(true),
dClipObjectCount: mol_util_1.ValueCell.create(clip.objects.count),
dClipVariant: mol_util_1.ValueCell.create(clip.variant),
uClipObjectType: mol_util_1.ValueCell.create(clip.objects.type),
uClipObjectInvert: mol_util_1.ValueCell.create(clip.objects.invert),
uClipObjectPosition: mol_util_1.ValueCell.create(clip.objects.position),
uClipObjectRotation: mol_util_1.ValueCell.create(clip.objects.rotation),
uClipObjectScale: mol_util_1.ValueCell.create(clip.objects.scale),
instanceGranularity: mol_util_1.ValueCell.create(props.instanceGranularity),
};
}
BaseGeometry.createValues = createValues;
function updateValues(values, props) {
mol_util_1.ValueCell.updateIfChanged(values.alpha, props.alpha); // `uAlpha` is set in renderable.render
mol_util_1.ValueCell.updateIfChanged(values.uMetalness, props.material.metalness);
mol_util_1.ValueCell.updateIfChanged(values.uRoughness, props.material.roughness);
mol_util_1.ValueCell.updateIfChanged(values.uBumpiness, props.material.bumpiness);
var clip = clip_1.Clip.getClip(props.clip);
mol_util_1.ValueCell.update(values.dClipObjectCount, clip.objects.count);
mol_util_1.ValueCell.update(values.dClipVariant, clip.variant);
mol_util_1.ValueCell.update(values.uClipObjectType, clip.objects.type);
mol_util_1.ValueCell.update(values.uClipObjectInvert, clip.objects.invert);
mol_util_1.ValueCell.update(values.uClipObjectPosition, clip.objects.position);
mol_util_1.ValueCell.update(values.uClipObjectRotation, clip.objects.rotation);
mol_util_1.ValueCell.update(values.uClipObjectScale, clip.objects.scale);
mol_util_1.ValueCell.updateIfChanged(values.instanceGranularity, props.instanceGranularity);
}
BaseGeometry.updateValues = updateValues;
function createRenderableState(props) {
if (props === void 0) { props = {}; }
var opaque = props.alpha === undefined ? true : props.alpha === 1;
return {
disposed: false,
visible: true,
alphaFactor: 1,
pickable: true,
colorOnly: false,
opaque: opaque,
writeDepth: opaque,
};
}
BaseGeometry.createRenderableState = createRenderableState;
function updateRenderableState(state, props) {
state.opaque = props.alpha * state.alphaFactor >= 1;
state.writeDepth = state.opaque;
}
BaseGeometry.updateRenderableState = updateRenderableState;
})(BaseGeometry = exports.BaseGeometry || (exports.BaseGeometry = {}));
;