UNPKG

molstar

Version:

A comprehensive macromolecular library.

55 lines 2.55 kB
/** * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { ChunkedArray } from '../../../mol-data/util'; import { Spheres } from './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 = ChunkedArray.add3; var caAdd2 = ChunkedArray.add2; var caAdd = ChunkedArray.add; export 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 = ChunkedArray.create(Float32Array, 3, chunkSize, spheres ? spheres.centerBuffer.ref.value : initialCount); var mappings = ChunkedArray.create(Float32Array, 2, chunkSize, spheres ? spheres.mappingBuffer.ref.value : initialCount); var indices = ChunkedArray.create(Uint32Array, 3, chunkSize / 2, spheres ? spheres.indexBuffer.ref.value : initialCount / 2); var groups = 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 = ChunkedArray.compact(centers, true); var mb = ChunkedArray.compact(mappings, true); var ib = ChunkedArray.compact(indices, true); var gb = ChunkedArray.compact(groups, true); return Spheres.create(cb, mb, ib, gb, centers.elementCount / 4, spheres); } }; } SpheresBuilder.create = create; })(SpheresBuilder || (SpheresBuilder = {})); //# sourceMappingURL=spheres-builder.js.map