UNPKG

molstar

Version:

A comprehensive macromolecular library.

116 lines (115 loc) 5.11 kB
/** * Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __assign } from "tslib"; import { ParamDefinition as PD } from '../../mol-util/param-definition'; import { DrawPass } from './draw'; import { PostprocessingParams } from './postprocessing'; import { MultiSamplePass, MultiSampleParams, MultiSampleHelper } from './multi-sample'; import { Camera } from '../camera'; import { Viewport } from '../camera/util'; import { PixelData } from '../../mol-util/image'; import { CameraHelper, CameraHelperParams } from '../helper/camera-helper'; import { MarkingParams } from './marking'; export var ImageParams = { transparentBackground: PD.Boolean(false), dpoitIterations: PD.Numeric(2, { min: 1, max: 10, step: 1 }), multiSample: PD.Group(MultiSampleParams), postprocessing: PD.Group(PostprocessingParams), marking: PD.Group(MarkingParams), cameraHelper: PD.Group(CameraHelperParams), }; var ImagePass = /** @class */ (function () { function ImagePass(webgl, assetManager, renderer, scene, camera, helper, enableWboit, enableDpoit, props) { this.webgl = webgl; this.renderer = renderer; this.scene = scene; this.camera = camera; this._width = 0; this._height = 0; this._camera = new Camera(); this.props = __assign(__assign({}, PD.getDefaultValues(ImageParams)), props); this.drawPass = new DrawPass(webgl, assetManager, 128, 128, enableWboit, enableDpoit); this.multiSamplePass = new MultiSamplePass(webgl, this.drawPass); this.multiSampleHelper = new MultiSampleHelper(this.multiSamplePass); this.helper = { camera: new CameraHelper(webgl, this.props.cameraHelper), debug: helper.debug, handle: helper.handle, }; this.setSize(1024, 768); } Object.defineProperty(ImagePass.prototype, "colorTarget", { get: function () { return this._colorTarget; }, enumerable: false, configurable: true }); Object.defineProperty(ImagePass.prototype, "width", { get: function () { return this._width; }, enumerable: false, configurable: true }); Object.defineProperty(ImagePass.prototype, "height", { get: function () { return this._height; }, enumerable: false, configurable: true }); ImagePass.prototype.updateBackground = function () { var _this = this; return new Promise(function (resolve) { _this.drawPass.postprocessing.background.update(_this.camera, _this.props.postprocessing.background, function () { resolve(); }); }); }; ImagePass.prototype.setSize = function (width, height) { if (width === this._width && height === this._height) return; this._width = width; this._height = height; this.drawPass.setSize(width, height); this.multiSamplePass.syncSize(); }; ImagePass.prototype.setProps = function (props) { if (props === void 0) { props = {}; } Object.assign(this.props, props); if (props.cameraHelper) this.helper.camera.setProps(props.cameraHelper); }; ImagePass.prototype.render = function () { Camera.copySnapshot(this._camera.state, this.camera.state); Viewport.set(this._camera.viewport, 0, 0, this._width, this._height); this._camera.update(); var ctx = { renderer: this.renderer, camera: this._camera, scene: this.scene, helper: this.helper }; if (MultiSamplePass.isEnabled(this.props.multiSample)) { this.multiSampleHelper.render(ctx, this.props, false); this._colorTarget = this.multiSamplePass.colorTarget; } else { this.drawPass.render(ctx, this.props, false); this._colorTarget = this.drawPass.getColorTarget(this.props.postprocessing); } }; ImagePass.prototype.getImageData = function (width, height, viewport) { var _a, _b; this.setSize(width, height); this.render(); this.colorTarget.bind(); var w = (_a = viewport === null || viewport === void 0 ? void 0 : viewport.width) !== null && _a !== void 0 ? _a : width, h = (_b = viewport === null || viewport === void 0 ? void 0 : viewport.height) !== null && _b !== void 0 ? _b : height; var array = new Uint8Array(w * h * 4); if (!viewport) { this.webgl.readPixels(0, 0, w, h, array); } else { this.webgl.readPixels(viewport.x, height - viewport.y - viewport.height, w, h, array); } var pixelData = PixelData.create(array, w, h); PixelData.flipY(pixelData); PixelData.divideByAlpha(pixelData); return new ImageData(new Uint8ClampedArray(array), w, h); }; return ImagePass; }()); export { ImagePass };