molstar
Version:
A comprehensive macromolecular library.
109 lines • 5.24 kB
JavaScript
"use strict";
/**
* Copyright (c) 2019-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.ImagePass = exports.ImageParams = void 0;
var tslib_1 = require("tslib");
var param_definition_1 = require("../../mol-util/param-definition");
var draw_1 = require("./draw");
var postprocessing_1 = require("./postprocessing");
var multi_sample_1 = require("./multi-sample");
var camera_1 = require("../camera");
var util_1 = require("../camera/util");
var image_1 = require("../../mol-util/image");
var camera_helper_1 = require("../helper/camera-helper");
var marking_1 = require("./marking");
exports.ImageParams = {
transparentBackground: param_definition_1.ParamDefinition.Boolean(false),
multiSample: param_definition_1.ParamDefinition.Group(multi_sample_1.MultiSampleParams),
postprocessing: param_definition_1.ParamDefinition.Group(postprocessing_1.PostprocessingParams),
marking: param_definition_1.ParamDefinition.Group(marking_1.MarkingParams),
cameraHelper: param_definition_1.ParamDefinition.Group(camera_helper_1.CameraHelperParams),
};
var ImagePass = /** @class */ (function () {
function ImagePass(webgl, renderer, scene, camera, helper, enableWboit, props) {
this.webgl = webgl;
this.renderer = renderer;
this.scene = scene;
this.camera = camera;
this._width = 0;
this._height = 0;
this._camera = new camera_1.Camera();
this.props = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, param_definition_1.ParamDefinition.getDefaultValues(exports.ImageParams)), props);
this.drawPass = new draw_1.DrawPass(webgl, 128, 128, enableWboit);
this.multiSamplePass = new multi_sample_1.MultiSamplePass(webgl, this.drawPass);
this.multiSampleHelper = new multi_sample_1.MultiSampleHelper(this.multiSamplePass);
this.helper = {
camera: new camera_helper_1.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.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_1.Camera.copySnapshot(this._camera.state, this.camera.state);
util_1.Viewport.set(this._camera.viewport, 0, 0, this._width, this._height);
this._camera.update();
if (multi_sample_1.MultiSamplePass.isEnabled(this.props.multiSample)) {
this.multiSampleHelper.render(this.renderer, this._camera, this.scene, this.helper, false, this.props.transparentBackground, this.props);
this._colorTarget = this.multiSamplePass.colorTarget;
}
else {
this.drawPass.render(this.renderer, this._camera, this.scene, this.helper, false, this.props.transparentBackground, this.props.postprocessing, this.props.marking);
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 = image_1.PixelData.create(array, w, h);
image_1.PixelData.flipY(pixelData);
image_1.PixelData.divideByAlpha(pixelData);
return new ImageData(new Uint8ClampedArray(array), w, h);
};
return ImagePass;
}());
exports.ImagePass = ImagePass;
//# sourceMappingURL=image.js.map