molstar
Version:
A comprehensive macromolecular library.
58 lines • 2.77 kB
JavaScript
/**
* Copyright (c) 2019-2020 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.SpheresBuilder = void 0;
var util_1 = require("../../../mol-data/util");
var spheres_1 = require("./spheres");
var quadMapping = new Float32Array([
-1.0, 1.0,
-1.0, -1.0,
1.0, 1.0,
1.0, -1.0
]);
var quadIndices = new Uint16Array([
0, 1, 2,
1, 3, 2
]);
// avoiding namespace lookup improved performance in Chrome (Aug 2020)
var caAdd3 = util_1.ChunkedArray.add3;
var caAdd2 = util_1.ChunkedArray.add2;
var caAdd = util_1.ChunkedArray.add;
var SpheresBuilder;
(function (SpheresBuilder) {
function create(initialCount, chunkSize, spheres) {
if (initialCount === void 0) { initialCount = 2048; }
if (chunkSize === void 0) { chunkSize = 1024; }
initialCount *= 4;
chunkSize *= 4;
var centers = util_1.ChunkedArray.create(Float32Array, 3, chunkSize, spheres ? spheres.centerBuffer.ref.value : initialCount);
var mappings = util_1.ChunkedArray.create(Float32Array, 2, chunkSize, spheres ? spheres.mappingBuffer.ref.value : initialCount);
var indices = util_1.ChunkedArray.create(Uint32Array, 3, chunkSize / 2, spheres ? spheres.indexBuffer.ref.value : initialCount / 2);
var groups = util_1.ChunkedArray.create(Float32Array, 1, chunkSize, spheres ? spheres.groupBuffer.ref.value : initialCount);
return {
add: function (x, y, z, group) {
var offset = centers.elementCount;
for (var i = 0; i < 4; ++i) {
caAdd3(centers, x, y, z);
caAdd2(mappings, quadMapping[i * 2], quadMapping[i * 2 + 1]);
caAdd(groups, group);
}
caAdd3(indices, offset + quadIndices[0], offset + quadIndices[1], offset + quadIndices[2]);
caAdd3(indices, offset + quadIndices[3], offset + quadIndices[4], offset + quadIndices[5]);
},
getSpheres: function () {
var cb = util_1.ChunkedArray.compact(centers, true);
var mb = util_1.ChunkedArray.compact(mappings, true);
var ib = util_1.ChunkedArray.compact(indices, true);
var gb = util_1.ChunkedArray.compact(groups, true);
return spheres_1.Spheres.create(cb, mb, ib, gb, centers.elementCount / 4, spheres);
}
};
}
SpheresBuilder.create = create;
})(SpheresBuilder = exports.SpheresBuilder || (exports.SpheresBuilder = {}));
//# sourceMappingURL=spheres-builder.js.map
;