diff --git a/examples/index.js b/examples/index.js index 2085620..8550ac1 100644 --- a/examples/index.js +++ b/examples/index.js @@ -14,6 +14,8 @@ "image", "instancing", "msaa", + "multi-draw", + "multi-draw-instanced", "picking", "primitives", "project", diff --git a/examples/multi-draw-instanced.js b/examples/multi-draw-instanced.js new file mode 100644 index 0000000..dbc2d48 --- /dev/null +++ b/examples/multi-draw-instanced.js @@ -0,0 +1,148 @@ +//Requires: WEBGL_multi_draw +//Requires: WEBGL_multi_draw_instanced_base_vertex_base_instance +import createContext from "../index.js"; + +import { perspective as createCamera, orbiter as createOrbiter } from "pex-cam"; + +import { cube, sphere, torus } from "primitive-geometry"; +import typedArrayConcat from "typed-array-concat"; + +import basicFrag from "./shaders/basic.frag.js"; +// import merge from "geom-merge"; + +const ctx = createContext({ pixelRatio: devicePixelRatio }); + +const CellsConstructor = Uint16Array; + +const sphereGeometry = sphere({ radius: 0.2 }); +const cubeGeometry = cube({ sx: 0.3 }); +const torusGeometry = torus({ radius: 0.2, minorRadius: 0.05 }); +const geometries = [sphereGeometry, cubeGeometry, torusGeometry]; + +let geom = { + positions: typedArrayConcat( + Float32Array, + ...geometries.map((g) => g.positions) + ), + normals: typedArrayConcat(Float32Array, ...geometries.map((g) => g.normals)), + uvs: typedArrayConcat(Float32Array, ...geometries.map((g) => g.uvs)), + cells: typedArrayConcat(CellsConstructor, ...geometries.map((g) => g.cells)), +}; +// geom = merge(geometries); + +const camera = createCamera({ + position: [0, 0, 7], +}); +createOrbiter({ camera }); + +const clearCmd = { + pass: ctx.pass({ + clearColor: [0.2, 0.2, 0.2, 1], + clearDepth: 1, + }), +}; + +const counts = new Int32Array(geometries.length); +const offsets = new Int32Array(geometries.length); +const baseVertices = new Int32Array(geometries.length); +const baseInstances = new Int32Array(geometries.length); +const instanceCounts = new Int32Array([3, 6, 9]); + +const instancePositions = []; + +for (let i = 0; i < geometries.length; i++) { + const numInstancesPerShape = instanceCounts[i]; + for (let j = 0; j < numInstancesPerShape; j++) { + instancePositions.push([j - 4, i - (geometries.length - 1) / 2, 0]); + } + + counts[i] = geometries[i].cells.length; + + if (i > 0) { + offsets[i] = + offsets[i - 1] + + geometries[i - 1].cells.length * CellsConstructor.BYTES_PER_ELEMENT; + + // baseVertices[i] = 0 //when using geom-merge + baseVertices[i] = + baseVertices[i - 1] + geometries[i - 1].positions.length / 3; + + baseInstances[i] = baseInstances[i - 1] + instanceCounts[i - 1]; + } +} + +const drawCmd = { + pipeline: ctx.pipeline({ + depthTest: true, + vert: /* glsl */ ` +#extension GL_ANGLE_multi_draw: require + +attribute vec3 aPosition; +attribute vec3 aOffset; + +uniform mat4 uProjectionMatrix; +uniform mat4 uViewMatrix; + +varying vec4 vColor; + +void main () { + if (gl_DrawID == 0) { + vColor = vec4(1.0, 0.0, 0.0, 1.0); + } else if (gl_DrawID == 1) { + vColor = vec4(0.0, 1.0, 0.0, 1.0); + } else if (gl_DrawID == 2) { + vColor = vec4(0.0, 0.0, 1.0, 1.0); + } else { + vColor = vec4(1.0, 1.0, 0.0, 1.0); + } + + gl_Position = uProjectionMatrix * uViewMatrix * vec4(aPosition + aOffset, 1.0); +}`, + frag: basicFrag, + }), + attributes: { + aPosition: ctx.vertexBuffer(geom.positions), + aNormal: ctx.vertexBuffer(geom.normals), + aTexCoord: ctx.vertexBuffer(geom.uvs), + aOffset: { + buffer: ctx.vertexBuffer(instancePositions), + divisor: 1, + }, + }, + indices: ctx.indexBuffer(geom.cells), + multiDraw: { + counts, + offsets, + instanceCounts, + baseVertices: baseVertices, + baseInstances: baseInstances, + }, + uniforms: { + uProjectionMatrix: camera.projectionMatrix, + uViewMatrix: camera.viewMatrix, + }, +}; + +const onResize = () => { + const W = window.innerWidth; + const H = window.innerHeight; + ctx.set({ width: W, height: H }); + camera.set({ aspect: W / H }); +}; +window.addEventListener("resize", onResize); +onResize(); + +ctx.frame(() => { + ctx.submit(clearCmd); + + ctx.submit(drawCmd, { + uniforms: { + uProjectionMatrix: camera.projectionMatrix, + uViewMatrix: camera.viewMatrix, + }, + }); + + ctx.debug(false); + + window.dispatchEvent(new CustomEvent("pex-screenshot")); +}); diff --git a/examples/multi-draw.js b/examples/multi-draw.js new file mode 100644 index 0000000..abef364 --- /dev/null +++ b/examples/multi-draw.js @@ -0,0 +1,116 @@ +import createContext from "../index.js"; + +import { perspective as createCamera, orbiter as createOrbiter } from "pex-cam"; + +import { cube, sphere, torus } from "primitive-geometry"; +import merge from "geom-merge"; + +import basicFrag from "./shaders/basic.frag.js"; + +const ctx = createContext({ pixelRatio: devicePixelRatio }); + +const CellsConstructor = Uint16Array; + +const sphereGeometry = sphere(); +sphereGeometry.positions = sphereGeometry.positions.map((value, i) => + i % 3 === 0 ? value - 1.25 : value +); +const cubeGeometry = cube(); + +const torusGeometry = torus(); +torusGeometry.positions = torusGeometry.positions.map((value, i) => + i % 3 === 0 ? value + 1.25 : value +); +const geometries = [sphereGeometry, cubeGeometry, torusGeometry]; +const geometry = merge(geometries); + +const camera = createCamera({ + position: [0, 0, 3], +}); +createOrbiter({ camera }); + +const clearCmd = { + pass: ctx.pass({ + clearColor: [0.2, 0.2, 0.2, 1], + clearDepth: 1, + }), +}; + +const counts = new Int32Array(geometries.length); +const offsets = new Int32Array(geometries.length); + +for (let i = 0; i < geometries.length; i++) { + counts[i] = geometries[i].cells.length; + + if (i > 0) { + offsets[i] = + offsets[i - 1] + + geometries[i - 1].cells.length * CellsConstructor.BYTES_PER_ELEMENT; + } +} + +const drawCmd = { + pipeline: ctx.pipeline({ + depthTest: true, + vert: /* glsl */ ` +#extension GL_ANGLE_multi_draw: require + +attribute vec3 aPosition; + +uniform mat4 uProjectionMatrix; +uniform mat4 uViewMatrix; + +varying vec4 vColor; + +void main () { + if (gl_DrawID == 0) { + vColor = vec4(1.0, 0.0, 0.0, 1.0); + } else if (gl_DrawID == 1) { + vColor = vec4(0.0, 1.0, 0.0, 1.0); + } else if (gl_DrawID == 2) { + vColor = vec4(0.0, 0.0, 1.0, 1.0); + } else { + vColor = vec4(1.0, 1.0, 0.0, 1.0); + } + + gl_Position = uProjectionMatrix * uViewMatrix * vec4(aPosition, 1.0); +}`, + frag: basicFrag, + }), + attributes: { + aPosition: ctx.vertexBuffer(geometry.positions), + }, + indices: ctx.indexBuffer(geometry.cells), + multiDraw: { + counts, + offsets, + }, + uniforms: { + uProjectionMatrix: camera.projectionMatrix, + uViewMatrix: camera.viewMatrix, + }, +}; + +const onResize = () => { + const W = window.innerWidth; + const H = window.innerHeight; + ctx.set({ width: W, height: H }); + camera.set({ aspect: W / H }); +}; +window.addEventListener("resize", onResize); +onResize(); + +ctx.frame(() => { + ctx.submit(clearCmd); + + ctx.submit(drawCmd, { + uniforms: { + uProjectionMatrix: camera.projectionMatrix, + uViewMatrix: camera.viewMatrix, + }, + }); + + ctx.debug(false); + + window.dispatchEvent(new CustomEvent("pex-screenshot")); +}); diff --git a/index.js b/index.js index 66d7eb9..0ae3863 100644 --- a/index.js +++ b/index.js @@ -98,6 +98,7 @@ function createContext(options = {}) { ? !!gl.getExtension("EXT_color_buffer_float") : !!gl.getExtension("WEBGL_color_buffer_float"), colorBufferHalfFloat: !!gl.getExtension("EXT_color_buffer_half_float"), + multiDraw: !!gl.getExtension("WEBGL_multi_draw"), }, /** * Getter for `gl.drawingBufferWidth` @@ -1091,22 +1092,103 @@ function createContext(options = {}) { this.state.indexBuffer.type; if (instanced) { - gl.drawElementsInstanced( - primitive, - count, - type, - offset, - cmd.instances - ); + if (cmd.multiDraw && ctx.capabilities.multiDraw) { + const ext = gl.getExtension("WEBGL_multi_draw"); + + if (cmd.multiDraw.baseVertices && cmd.multiDraw.baseInstances) { + const baseVertexBaseInstanceExt = gl.getExtension( + "WEBGL_multi_draw_instanced_base_vertex_base_instance" + ); + if (!baseVertexBaseInstanceExt) { + throw new Error( + "WEBGL_multi_draw_instanced_base_vertex_base_instance not supported" + ); + } + baseVertexBaseInstanceExt.multiDrawElementsInstancedBaseVertexBaseInstanceWEBGL( + primitive, + cmd.multiDraw.counts, + cmd.multiDraw.countsOffset || 0, + type, + cmd.multiDraw.offsets, + cmd.multiDraw.offsetsOffset || 0, + cmd.multiDraw.instanceCounts, + cmd.multiDraw.instanceCountsOffset || 0, + cmd.multiDraw.baseVertices, + cmd.multiDraw.baseVerticesOffset || 0, + cmd.multiDraw.baseInstances, + cmd.multiDraw.baseInstancesOffset || 0, + cmd.multiDraw.counts.length + ); + } else { + ext.multiDrawElementsInstancedWEBGL( + primitive, + cmd.multiDraw.counts, + cmd.multiDraw.countsOffset || 0, + type, + cmd.multiDraw.offsets, + cmd.multiDraw.offsetsOffset || 0, + cmd.multiDraw.instanceCounts, + cmd.multiDraw.instanceCountsOffset || 0, + cmd.multiDraw.counts.length + ); + } + } else { + gl.drawElementsInstanced( + primitive, + count, + type, + offset, + cmd.instances + ); + } } else { - gl.drawElements(primitive, count, type, offset); + if (cmd.multiDraw && ctx.capabilities.multiDraw) { + const ext = gl.getExtension("WEBGL_multi_draw"); + ext.multiDrawElementsWEBGL( + primitive, + cmd.multiDraw.counts, + cmd.multiDraw.countsOffset || 0, + type, + cmd.multiDraw.offsets, + cmd.multiDraw.offsetsOffset || 0, + cmd.multiDraw.counts.length + ); + } else { + gl.drawElements(primitive, count, type, offset); + } } } else if (cmd.count) { const first = 0; if (instanced) { - gl.drawArraysInstanced(primitive, first, cmd.count, cmd.instances); + if (cmd.multiDraw && ctx.capabilities.multiDraw) { + const ext = gl.getExtension("WEBGL_multi_draw"); + ext.multiDrawArraysInstancedWEBGL( + primitive, + cmd.multiDraw.firsts, + cmd.multiDraw.firstsOffset || 0, + cmd.multiDraw.counts, + cmd.multiDraw.countsOffset || 0, + cmd.multiDraw.instanceCounts, + cmd.multiDraw.instanceCountsOffset || 0, + cmd.multiDraw.firsts.length + ); + } else { + gl.drawArraysInstanced(primitive, first, cmd.count, cmd.instances); + } } else { - gl.drawArrays(primitive, first, cmd.count); + if (cmd.multiDraw && ctx.capabilities.multiDraw) { + const ext = gl.getExtension("WEBGL_multi_draw"); + ext.multiDrawArraysWEBGL( + primitive, + cmd.multiDraw.firsts, + cmd.multiDraw.firstsOffset || 0, + cmd.multiDraw.counts, + cmd.multiDraw.countsOffset || 0, + cmd.multiDraw.firsts.length + ); + } else { + gl.drawArrays(primitive, first, cmd.count); + } } } else { throw new Error("Vertex arrays requires elements or count to draw"); diff --git a/package-lock.json b/package-lock.json index ac4e23c..4247312 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "bunny": "^1.0.1", "es-module-shims": "^1.6.3", "geom-center-and-normalize": "^1.0.3", + "geom-merge": "^2.0.0", "normals": "^1.1.0", "pex-cam": "^3.0.0-alpha.1", "pex-color": "^2.0.0-alpha.2", @@ -23,7 +24,8 @@ "pex-io": "^3.0.0-alpha.0", "pex-math": "^4.0.0-alpha.2", "pex-random": "^2.0.0-alpha.1", - "primitive-geometry": "^2.9.1" + "primitive-geometry": "^2.9.1", + "typed-array-concat": "^3.0.0" }, "engines": { "node": ">=16.0.0", @@ -74,6 +76,20 @@ "integrity": "sha512-ieBwiAavIo2kf13DRZfzR3aQ03bE62bvoO165Gw54f/TGCkVcORf9+urMckLZi3GreZVAZIaHSbVnF6zc6gAdA==", "dev": true }, + "node_modules/geom-merge": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/geom-merge/-/geom-merge-2.0.0.tgz", + "integrity": "sha512-oEZTNVnXtXDRZILx/3NutupJtJH+kL189ByFR1fdSdQalmseamlo9T38WJ35xTbOA8Y+/skuWxy/WptLyWs7+g==", + "dev": true, + "dependencies": { + "typed-array-concat": "^3.0.0", + "typed-array-constructor": "^1.0.1" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + } + }, "node_modules/interpolate-angle": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/interpolate-angle/-/interpolate-angle-1.0.2.tgz", @@ -264,6 +280,46 @@ "integrity": "sha512-ciRAxJnRdQhFhZ7+yZKxk8bQJoIq2J2UPO2pbzy1vcrWFq70P4hNCCmcCTkBKDCIeXZVd/yKjL8Fmh8Aeu5+6g==", "dev": true }, + "node_modules/typed-array-concat": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/typed-array-concat/-/typed-array-concat-3.0.0.tgz", + "integrity": "sha512-IctbEtBzcCkWq9HDdTDigdnYFB4s6M+PfHJoyndoESYu0Ygxb1VLA3DNqnLOJ6heJev26fqICNlALuoWJH2GMw==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://paypal.me/dmnsgn" + }, + { + "type": "individual", + "url": "https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3" + } + ], + "engines": { + "node": ">=15.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/typed-array-constructor": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/typed-array-constructor/-/typed-array-constructor-1.0.1.tgz", + "integrity": "sha512-u0C7NyHOh4nPdFy5BsjEQuDXsuCg8PvinJ7b35IXdQ/dcOrwavzMh3YYo0Gj2Oq+69nNDOlxwKcVAV++x+m/8A==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://paypal.me/dmnsgn" + }, + { + "type": "individual", + "url": "https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3" + } + ], + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + } + }, "node_modules/xyz-to-latlon": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/xyz-to-latlon/-/xyz-to-latlon-1.0.2.tgz", @@ -315,6 +371,16 @@ } } }, + "geom-merge": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/geom-merge/-/geom-merge-2.0.0.tgz", + "integrity": "sha512-oEZTNVnXtXDRZILx/3NutupJtJH+kL189ByFR1fdSdQalmseamlo9T38WJ35xTbOA8Y+/skuWxy/WptLyWs7+g==", + "dev": true, + "requires": { + "typed-array-concat": "^3.0.0", + "typed-array-constructor": "^1.0.1" + } + }, "interpolate-angle": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/interpolate-angle/-/interpolate-angle-1.0.2.tgz", @@ -452,6 +518,18 @@ "integrity": "sha512-ciRAxJnRdQhFhZ7+yZKxk8bQJoIq2J2UPO2pbzy1vcrWFq70P4hNCCmcCTkBKDCIeXZVd/yKjL8Fmh8Aeu5+6g==", "dev": true }, + "typed-array-concat": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/typed-array-concat/-/typed-array-concat-3.0.0.tgz", + "integrity": "sha512-IctbEtBzcCkWq9HDdTDigdnYFB4s6M+PfHJoyndoESYu0Ygxb1VLA3DNqnLOJ6heJev26fqICNlALuoWJH2GMw==", + "dev": true + }, + "typed-array-constructor": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/typed-array-constructor/-/typed-array-constructor-1.0.1.tgz", + "integrity": "sha512-u0C7NyHOh4nPdFy5BsjEQuDXsuCg8PvinJ7b35IXdQ/dcOrwavzMh3YYo0Gj2Oq+69nNDOlxwKcVAV++x+m/8A==", + "dev": true + }, "xyz-to-latlon": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/xyz-to-latlon/-/xyz-to-latlon-1.0.2.tgz", diff --git a/package.json b/package.json index 7f27b21..7cb20e4 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "bunny": "^1.0.1", "es-module-shims": "^1.6.3", "geom-center-and-normalize": "^1.0.3", + "geom-merge": "^2.0.0", "normals": "^1.1.0", "pex-cam": "^3.0.0-alpha.1", "pex-color": "^2.0.0-alpha.2", @@ -50,7 +51,8 @@ "pex-io": "^3.0.0-alpha.0", "pex-math": "^4.0.0-alpha.2", "pex-random": "^2.0.0-alpha.1", - "primitive-geometry": "^2.9.1" + "primitive-geometry": "^2.9.1", + "typed-array-concat": "^3.0.0" }, "engines": { "node": ">=16.0.0", diff --git a/web_modules/common/async-iterator-iteration-026ee04a.js b/web_modules/common/async-iterator-iteration-026ee04a.js new file mode 100644 index 0000000..5df66b7 --- /dev/null +++ b/web_modules/common/async-iterator-iteration-026ee04a.js @@ -0,0 +1,100 @@ +import { g as getIteratorDirect, z as getBuiltIn, a as aCallable, m as anObject, n as functionCall, R as asyncIteratorClose, v as isObject } from './classof-a3d4c9bc.js'; + +var $TypeError = TypeError; +var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF; // 2 ** 53 - 1 == 9007199254740991 + +var doesNotExceedSafeInteger = function (it) { + if (it > MAX_SAFE_INTEGER) throw $TypeError('Maximum allowed index exceeded'); + return it; +}; + +// https://github.com/tc39/proposal-iterator-helpers +// https://github.com/tc39/proposal-array-from-async + + + + + + + + + +var createMethod = function (TYPE) { + var IS_TO_ARRAY = TYPE == 0; + var IS_FOR_EACH = TYPE == 1; + var IS_EVERY = TYPE == 2; + var IS_SOME = TYPE == 3; + return function (object, fn, target) { + var record = getIteratorDirect(object); + var Promise = getBuiltIn('Promise'); + var iterator = record.iterator; + var next = record.next; + var counter = 0; + var MAPPING = fn !== undefined; + if (MAPPING || !IS_TO_ARRAY) aCallable(fn); + + return new Promise(function (resolve, reject) { + var ifAbruptCloseAsyncIterator = function (error) { + asyncIteratorClose(iterator, reject, error, reject); + }; + + var loop = function () { + try { + if (MAPPING) try { + doesNotExceedSafeInteger(counter); + } catch (error5) { ifAbruptCloseAsyncIterator(error5); } + Promise.resolve(anObject(functionCall(next, iterator))).then(function (step) { + try { + if (anObject(step).done) { + if (IS_TO_ARRAY) { + target.length = counter; + resolve(target); + } else resolve(IS_SOME ? false : IS_EVERY || undefined); + } else { + var value = step.value; + try { + if (MAPPING) { + var result = fn(value, counter); + + var handler = function ($result) { + if (IS_FOR_EACH) { + loop(); + } else if (IS_EVERY) { + $result ? loop() : asyncIteratorClose(iterator, resolve, false, reject); + } else if (IS_TO_ARRAY) { + try { + target[counter++] = $result; + loop(); + } catch (error4) { ifAbruptCloseAsyncIterator(error4); } + } else { + $result ? asyncIteratorClose(iterator, resolve, IS_SOME || value, reject) : loop(); + } + }; + + if (isObject(result)) Promise.resolve(result).then(handler, ifAbruptCloseAsyncIterator); + else handler(result); + } else { + target[counter++] = value; + loop(); + } + } catch (error3) { ifAbruptCloseAsyncIterator(error3); } + } + } catch (error2) { reject(error2); } + }, reject); + } catch (error) { reject(error); } + }; + + loop(); + }); + }; +}; + +var asyncIteratorIteration = { + toArray: createMethod(0), + forEach: createMethod(1), + every: createMethod(2), + some: createMethod(3), + find: createMethod(4) +}; + +export { asyncIteratorIteration as a }; diff --git a/web_modules/common/classof-b64a2315.js b/web_modules/common/classof-a3d4c9bc.js similarity index 97% rename from web_modules/common/classof-b64a2315.js rename to web_modules/common/classof-a3d4c9bc.js index 4279a70..aa8d0f3 100644 --- a/web_modules/common/classof-b64a2315.js +++ b/web_modules/common/classof-a3d4c9bc.js @@ -1459,4 +1459,4 @@ var classof = toStringTagSupport ? classofRaw : function (it) { : (result = classofRaw(O)) == 'Object' && isCallable(O.callee) ? 'Arguments' : result; }; -export { createPropertyDescriptor as A, copyConstructorProperties as B, descriptors as C, objectGetPrototypeOf as D, uid as E, internalState as F, defineBuiltIn as G, toIntegerOrInfinity as H, toObject as I, indexedObject as J, classofRaw as K, inspectSource as L, objectCreate as M, toPropertyKey as N, toPrimitive as O, toAbsoluteIndex as P, asyncIteratorCreateProxy as Q, createIterResultObject as R, iteratorCreateProxy as S, callWithSafeIterationClosing as T, createCommonjsModule as U, getDefaultExportFromNamespaceIfNotNamed as V, _export as _, aCallable as a, getBuiltIn as b, commonjsGlobal as c, anObject as d, asyncIteratorClose as e, functionCall as f, getIteratorDirect as g, global_1 as h, isObject as i, isCallable as j, fails as k, hasOwnProperty_1 as l, createNonEnumerableProperty as m, iteratorsCore as n, objectIsPrototypeOf as o, isNullOrUndefined as p, getMethod as q, classof as r, functionBindContext as s, tryToString as t, lengthOfArrayLike as u, iteratorClose as v, wellKnownSymbol as w, functionBindNative as x, functionUncurryThis as y, objectDefineProperty as z }; +export { copyConstructorProperties as A, descriptors as B, objectGetPrototypeOf as C, uid as D, internalState as E, defineBuiltIn as F, toIntegerOrInfinity as G, toObject as H, indexedObject as I, classofRaw as J, inspectSource as K, objectCreate as L, toPropertyKey as M, toPrimitive as N, toAbsoluteIndex as O, asyncIteratorCreateProxy as P, createIterResultObject as Q, asyncIteratorClose as R, iteratorCreateProxy as S, callWithSafeIterationClosing as T, createCommonjsModule as U, getDefaultExportFromNamespaceIfNotNamed as V, _export as _, aCallable as a, global_1 as b, commonjsGlobal as c, createNonEnumerableProperty as d, iteratorsCore as e, fails as f, getIteratorDirect as g, hasOwnProperty_1 as h, isCallable as i, isNullOrUndefined as j, getMethod as k, classof as l, anObject as m, functionCall as n, objectIsPrototypeOf as o, functionBindContext as p, lengthOfArrayLike as q, iteratorClose as r, functionBindNative as s, tryToString as t, objectDefineProperty as u, isObject as v, wellKnownSymbol as w, functionUncurryThis as x, createPropertyDescriptor as y, getBuiltIn as z }; diff --git a/web_modules/common/es.error.cause-80fb3656.js b/web_modules/common/es.error.cause-0747567f.js similarity index 81% rename from web_modules/common/es.error.cause-80fb3656.js rename to web_modules/common/es.error.cause-0747567f.js index bdc6ec1..7a44142 100644 --- a/web_modules/common/es.error.cause-80fb3656.js +++ b/web_modules/common/es.error.cause-0747567f.js @@ -1,4 +1,5 @@ -import { x as functionBindNative, j as isCallable, y as functionUncurryThis, d as anObject, z as objectDefineProperty, i as isObject, r as classof, m as createNonEnumerableProperty, k as fails, A as createPropertyDescriptor, b as getBuiltIn, l as hasOwnProperty_1, o as objectIsPrototypeOf, B as copyConstructorProperties, C as descriptors, h as global_1, _ as _export } from './classof-b64a2315.js'; +import { s as functionBindNative, u as objectDefineProperty, i as isCallable, v as isObject, l as classof, d as createNonEnumerableProperty, x as functionUncurryThis, f as fails, y as createPropertyDescriptor, z as getBuiltIn, h as hasOwnProperty_1, o as objectIsPrototypeOf, A as copyConstructorProperties, B as descriptors, b as global_1, _ as _export } from './classof-a3d4c9bc.js'; +import { o as objectSetPrototypeOf } from './object-set-prototype-of-eadd3696.js'; var FunctionPrototype = Function.prototype; var apply = FunctionPrototype.apply; @@ -9,42 +10,6 @@ var functionApply = typeof Reflect == 'object' && Reflect.apply || (functionBind return call.apply(apply, arguments); }); -var $String = String; -var $TypeError = TypeError; - -var aPossiblePrototype = function (argument) { - if (typeof argument == 'object' || isCallable(argument)) return argument; - throw $TypeError("Can't set " + $String(argument) + ' as a prototype'); -}; - -/* eslint-disable no-proto -- safe */ - - - - -// `Object.setPrototypeOf` method -// https://tc39.es/ecma262/#sec-object.setprototypeof -// Works with __proto__ only. Old v8 can't work with null proto objects. -// eslint-disable-next-line es/no-object-setprototypeof -- safe -var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? function () { - var CORRECT_SETTER = false; - var test = {}; - var setter; - try { - // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe - setter = functionUncurryThis(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set); - setter(test, []); - CORRECT_SETTER = test instanceof Array; - } catch (error) { /* empty */ } - return function setPrototypeOf(O, proto) { - anObject(O); - aPossiblePrototype(proto); - if (CORRECT_SETTER) setter(O, proto); - else O.__proto__ = proto; - return O; - }; -}() : undefined); - var defineProperty = objectDefineProperty.f; var proxyAccessor = function (Target, Source, key) { @@ -70,11 +35,11 @@ var inheritIfRequired = function ($this, dummy, Wrapper) { return $this; }; -var $String$1 = String; +var $String = String; var toString_1 = function (argument) { if (classof(argument) === 'Symbol') throw TypeError('Cannot convert a Symbol value to a string'); - return $String$1(argument); + return $String(argument); }; var normalizeStringArgument = function (argument, $default) { @@ -217,5 +182,3 @@ exportWebAssemblyErrorCauseWrapper('LinkError', function (init) { exportWebAssemblyErrorCauseWrapper('RuntimeError', function (init) { return function RuntimeError(message) { return functionApply(init, this, arguments); }; }); - -export { objectSetPrototypeOf as o }; diff --git a/web_modules/common/esnext.iterator.filter-c3958098.js b/web_modules/common/esnext.iterator.filter-81df7261.js similarity index 91% rename from web_modules/common/esnext.iterator.filter-c3958098.js rename to web_modules/common/esnext.iterator.filter-81df7261.js index 1186558..741cffc 100644 --- a/web_modules/common/esnext.iterator.filter-c3958098.js +++ b/web_modules/common/esnext.iterator.filter-81df7261.js @@ -1,4 +1,4 @@ -import { _ as _export, g as getIteratorDirect, a as aCallable, Q as asyncIteratorCreateProxy, d as anObject, f as functionCall, R as createIterResultObject, i as isObject, e as asyncIteratorClose, S as iteratorCreateProxy, T as callWithSafeIterationClosing } from './classof-b64a2315.js'; +import { _ as _export, g as getIteratorDirect, a as aCallable, P as asyncIteratorCreateProxy, m as anObject, n as functionCall, Q as createIterResultObject, v as isObject, R as asyncIteratorClose, S as iteratorCreateProxy, T as callWithSafeIterationClosing } from './classof-a3d4c9bc.js'; // https://github.com/tc39/proposal-iterator-helpers diff --git a/web_modules/common/esnext.typed-array.with-8b639300.js b/web_modules/common/esnext.typed-array.with-b6f846b8.js similarity index 96% rename from web_modules/common/esnext.typed-array.with-8b639300.js rename to web_modules/common/esnext.typed-array.with-b6f846b8.js index a9b5843..571bb4b 100644 --- a/web_modules/common/esnext.typed-array.with-8b639300.js +++ b/web_modules/common/esnext.typed-array.with-b6f846b8.js @@ -1,5 +1,5 @@ -import { h as global_1, D as objectGetPrototypeOf, w as wellKnownSymbol, E as uid, r as classof, j as isCallable, C as descriptors, l as hasOwnProperty_1, i as isObject, m as createNonEnumerableProperty, z as objectDefineProperty, F as internalState, o as objectIsPrototypeOf, t as tryToString, G as defineBuiltIn, u as lengthOfArrayLike, H as toIntegerOrInfinity, I as toObject, J as indexedObject, s as functionBindContext, K as classofRaw, b as getBuiltIn, y as functionUncurryThis, k as fails, L as inspectSource, p as isNullOrUndefined, d as anObject, M as objectCreate, N as toPropertyKey, a as aCallable, O as toPrimitive, P as toAbsoluteIndex } from './classof-b64a2315.js'; -import { o as objectSetPrototypeOf } from './es.error.cause-80fb3656.js'; +import { b as global_1, C as objectGetPrototypeOf, w as wellKnownSymbol, D as uid, l as classof, i as isCallable, B as descriptors, h as hasOwnProperty_1, v as isObject, d as createNonEnumerableProperty, u as objectDefineProperty, E as internalState, o as objectIsPrototypeOf, t as tryToString, F as defineBuiltIn, q as lengthOfArrayLike, G as toIntegerOrInfinity, H as toObject, I as indexedObject, p as functionBindContext, J as classofRaw, z as getBuiltIn, x as functionUncurryThis, f as fails, K as inspectSource, j as isNullOrUndefined, m as anObject, L as objectCreate, M as toPropertyKey, a as aCallable, N as toPrimitive, O as toAbsoluteIndex } from './classof-a3d4c9bc.js'; +import { o as objectSetPrototypeOf } from './object-set-prototype-of-eadd3696.js'; // eslint-disable-next-line es/no-typed-arrays -- safe var arrayBufferBasicDetection = typeof ArrayBuffer != 'undefined' && typeof DataView != 'undefined'; @@ -684,3 +684,5 @@ exportTypedArrayMethod$a('with', { 'with': function (index, value) { var actualValue = isBigIntArray(O) ? toBigInt(value) : +value; return arrayWith(O, getTypedArrayConstructor$5(O), relativeIndex, actualValue); } }['with'], !PROPER_ORDER$1); + +export { arrayIterationFromLast as a, speciesConstructor as s }; diff --git a/web_modules/common/hsl-5dfe9087.js b/web_modules/common/hsl-d415d8ba.js similarity index 98% rename from web_modules/common/hsl-5dfe9087.js rename to web_modules/common/hsl-d415d8ba.js index 35b28f9..e6b9b37 100644 --- a/web_modules/common/hsl-5dfe9087.js +++ b/web_modules/common/hsl-d415d8ba.js @@ -1,5 +1,6 @@ -import { _ as _export, g as getIteratorDirect, a as aCallable } from './classof-b64a2315.js'; -import { a as asyncIteratorIteration, i as iterate } from './iterate-e1e675f3.js'; +import { _ as _export, g as getIteratorDirect, a as aCallable } from './classof-a3d4c9bc.js'; +import { a as asyncIteratorIteration } from './async-iterator-iteration-026ee04a.js'; +import { i as iterate } from './iterate-54b5a051.js'; // https://github.com/tc39/proposal-iterator-helpers diff --git a/web_modules/common/iterate-e1e675f3.js b/web_modules/common/iterate-54b5a051.js similarity index 50% rename from web_modules/common/iterate-e1e675f3.js rename to web_modules/common/iterate-54b5a051.js index e668817..87c25a9 100644 --- a/web_modules/common/iterate-e1e675f3.js +++ b/web_modules/common/iterate-54b5a051.js @@ -1,107 +1,10 @@ -import { g as getIteratorDirect, b as getBuiltIn, a as aCallable, d as anObject, f as functionCall, e as asyncIteratorClose, i as isObject, o as objectIsPrototypeOf, w as wellKnownSymbol, h as global_1, j as isCallable, k as fails, l as hasOwnProperty_1, m as createNonEnumerableProperty, _ as _export, n as iteratorsCore, p as isNullOrUndefined, q as getMethod, r as classof, t as tryToString, s as functionBindContext, u as lengthOfArrayLike, v as iteratorClose } from './classof-b64a2315.js'; +import { o as objectIsPrototypeOf, w as wellKnownSymbol, b as global_1, i as isCallable, f as fails, h as hasOwnProperty_1, d as createNonEnumerableProperty, _ as _export, e as iteratorsCore, j as isNullOrUndefined, k as getMethod, l as classof, a as aCallable, m as anObject, n as functionCall, t as tryToString, p as functionBindContext, q as lengthOfArrayLike, r as iteratorClose } from './classof-a3d4c9bc.js'; var $TypeError = TypeError; -var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF; // 2 ** 53 - 1 == 9007199254740991 - -var doesNotExceedSafeInteger = function (it) { - if (it > MAX_SAFE_INTEGER) throw $TypeError('Maximum allowed index exceeded'); - return it; -}; - -// https://github.com/tc39/proposal-iterator-helpers -// https://github.com/tc39/proposal-array-from-async - - - - - - - - - -var createMethod = function (TYPE) { - var IS_TO_ARRAY = TYPE == 0; - var IS_FOR_EACH = TYPE == 1; - var IS_EVERY = TYPE == 2; - var IS_SOME = TYPE == 3; - return function (object, fn, target) { - var record = getIteratorDirect(object); - var Promise = getBuiltIn('Promise'); - var iterator = record.iterator; - var next = record.next; - var counter = 0; - var MAPPING = fn !== undefined; - if (MAPPING || !IS_TO_ARRAY) aCallable(fn); - - return new Promise(function (resolve, reject) { - var ifAbruptCloseAsyncIterator = function (error) { - asyncIteratorClose(iterator, reject, error, reject); - }; - - var loop = function () { - try { - if (MAPPING) try { - doesNotExceedSafeInteger(counter); - } catch (error5) { ifAbruptCloseAsyncIterator(error5); } - Promise.resolve(anObject(functionCall(next, iterator))).then(function (step) { - try { - if (anObject(step).done) { - if (IS_TO_ARRAY) { - target.length = counter; - resolve(target); - } else resolve(IS_SOME ? false : IS_EVERY || undefined); - } else { - var value = step.value; - try { - if (MAPPING) { - var result = fn(value, counter); - - var handler = function ($result) { - if (IS_FOR_EACH) { - loop(); - } else if (IS_EVERY) { - $result ? loop() : asyncIteratorClose(iterator, resolve, false, reject); - } else if (IS_TO_ARRAY) { - try { - target[counter++] = $result; - loop(); - } catch (error4) { ifAbruptCloseAsyncIterator(error4); } - } else { - $result ? asyncIteratorClose(iterator, resolve, IS_SOME || value, reject) : loop(); - } - }; - - if (isObject(result)) Promise.resolve(result).then(handler, ifAbruptCloseAsyncIterator); - else handler(result); - } else { - target[counter++] = value; - loop(); - } - } catch (error3) { ifAbruptCloseAsyncIterator(error3); } - } - } catch (error2) { reject(error2); } - }, reject); - } catch (error) { reject(error); } - }; - - loop(); - }); - }; -}; - -var asyncIteratorIteration = { - toArray: createMethod(0), - forEach: createMethod(1), - every: createMethod(2), - some: createMethod(3), - find: createMethod(4) -}; - -var $TypeError$1 = TypeError; var anInstance = function (it, Prototype) { if (objectIsPrototypeOf(Prototype, it)) return it; - throw $TypeError$1('Incorrect invocation'); + throw $TypeError('Incorrect invocation'); }; // https://github.com/tc39/proposal-iterator-helpers @@ -162,15 +65,15 @@ var getIteratorMethod = function (it) { || iterators[classof(it)]; }; -var $TypeError$2 = TypeError; +var $TypeError$1 = TypeError; var getIterator = function (argument, usingIterator) { var iteratorMethod = arguments.length < 2 ? getIteratorMethod(argument) : usingIterator; if (aCallable(iteratorMethod)) return anObject(functionCall(iteratorMethod, argument)); - throw $TypeError$2(tryToString(argument) + ' is not iterable'); + throw $TypeError$1(tryToString(argument) + ' is not iterable'); }; -var $TypeError$3 = TypeError; +var $TypeError$2 = TypeError; var Result = function (stopped, result) { this.stopped = stopped; @@ -206,7 +109,7 @@ var iterate = function (iterable, unboundFunction, options) { iterator = iterable; } else { iterFn = getIteratorMethod(iterable); - if (!iterFn) throw $TypeError$3(tryToString(iterable) + ' is not iterable'); + if (!iterFn) throw $TypeError$2(tryToString(iterable) + ' is not iterable'); // optimisation for array iterators if (isArrayIteratorMethod(iterFn)) { for (index = 0, length = lengthOfArrayLike(iterable); length > index; index++) { @@ -228,4 +131,4 @@ var iterate = function (iterable, unboundFunction, options) { } return new Result(false); }; -export { asyncIteratorIteration as a, iterate as i }; +export { iterate as i }; diff --git a/web_modules/common/map-emplace-0ed8f736.js b/web_modules/common/map-emplace-0ed8f736.js new file mode 100644 index 0000000..eb48fce --- /dev/null +++ b/web_modules/common/map-emplace-0ed8f736.js @@ -0,0 +1,36 @@ +import { m as anObject, a as aCallable, n as functionCall } from './classof-a3d4c9bc.js'; + +// https://github.com/tc39/collection-methods +var collectionDeleteAll = function deleteAll(/* ...elements */) { + var collection = anObject(this); + var remover = aCallable(collection['delete']); + var allDeleted = true; + var wasDeleted; + for (var k = 0, len = arguments.length; k < len; k++) { + wasDeleted = functionCall(remover, collection, arguments[k]); + allDeleted = allDeleted && wasDeleted; + } + return !!allDeleted; +}; + +// `Map.prototype.emplace` method +// https://github.com/thumbsupep/proposal-upsert +var mapEmplace = function emplace(key, handler) { + var map = anObject(this); + var get = aCallable(map.get); + var has = aCallable(map.has); + var set = aCallable(map.set); + var value, inserted; + if (functionCall(has, map, key)) { + value = functionCall(get, map, key); + if ('update' in handler) { + value = handler.update(value, key, map); + functionCall(set, map, key, value); + } return value; + } + inserted = handler.insert(key, map); + functionCall(set, map, key, inserted); + return inserted; +}; + +export { collectionDeleteAll as c, mapEmplace as m }; diff --git a/web_modules/common/object-set-prototype-of-eadd3696.js b/web_modules/common/object-set-prototype-of-eadd3696.js new file mode 100644 index 0000000..64a6000 --- /dev/null +++ b/web_modules/common/object-set-prototype-of-eadd3696.js @@ -0,0 +1,39 @@ +import { i as isCallable, x as functionUncurryThis, m as anObject } from './classof-a3d4c9bc.js'; + +var $String = String; +var $TypeError = TypeError; + +var aPossiblePrototype = function (argument) { + if (typeof argument == 'object' || isCallable(argument)) return argument; + throw $TypeError("Can't set " + $String(argument) + ' as a prototype'); +}; + +/* eslint-disable no-proto -- safe */ + + + + +// `Object.setPrototypeOf` method +// https://tc39.es/ecma262/#sec-object.setprototypeof +// Works with __proto__ only. Old v8 can't work with null proto objects. +// eslint-disable-next-line es/no-object-setprototypeof -- safe +var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? function () { + var CORRECT_SETTER = false; + var test = {}; + var setter; + try { + // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe + setter = functionUncurryThis(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set); + setter(test, []); + CORRECT_SETTER = test instanceof Array; + } catch (error) { /* empty */ } + return function setPrototypeOf(O, proto) { + anObject(O); + aPossiblePrototype(proto); + if (CORRECT_SETTER) setter(O, proto); + else O.__proto__ = proto; + return O; + }; +}() : undefined); + +export { objectSetPrototypeOf as o }; diff --git a/web_modules/es-module-shims.js b/web_modules/es-module-shims.js index fc33a02..92060bd 100644 --- a/web_modules/es-module-shims.js +++ b/web_modules/es-module-shims.js @@ -1,8 +1,10 @@ -import { _ as _export, g as getIteratorDirect, a as aCallable, c as commonjsGlobal } from './common/classof-b64a2315.js'; -import { a as asyncIteratorIteration, i as iterate } from './common/iterate-e1e675f3.js'; -import './common/es.error.cause-80fb3656.js'; -import './common/esnext.typed-array.with-8b639300.js'; -import './common/esnext.iterator.filter-c3958098.js'; +import { _ as _export, g as getIteratorDirect, a as aCallable, c as commonjsGlobal } from './common/classof-a3d4c9bc.js'; +import { a as asyncIteratorIteration } from './common/async-iterator-iteration-026ee04a.js'; +import { i as iterate } from './common/iterate-54b5a051.js'; +import './common/es.error.cause-0747567f.js'; +import './common/esnext.typed-array.with-b6f846b8.js'; +import './common/esnext.iterator.filter-81df7261.js'; +import './common/object-set-prototype-of-eadd3696.js'; // https://github.com/tc39/proposal-iterator-helpers diff --git a/web_modules/geom-center-and-normalize.js b/web_modules/geom-center-and-normalize.js index 584dbe6..0e934c2 100644 --- a/web_modules/geom-center-and-normalize.js +++ b/web_modules/geom-center-and-normalize.js @@ -1,50 +1,8 @@ -/** - * @module aabb - */ - -/** - * @typedef {number[][]} aabb An axis-aligned bounding box defined by two min and max 3D points. - */ - -/** - * Creates a new bounding box. - * @returns {aabb} - */ function create() { - // [min, max] - return [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]]; -} - -/** - * Reset a bounding box. - * @param {aabb} a - * @returns {rect} - */ -function empty(a) { - a[0][0] = Infinity; - a[0][1] = Infinity; - a[0][2] = Infinity; - a[1][0] = -Infinity; - a[1][1] = -Infinity; - a[1][2] = -Infinity; - return a; + var min = [Infinity, Infinity, Infinity]; + var max = [-Infinity, -Infinity, -Infinity]; + return [min, max]; } - -/** - * Copies a bounding box. - * @param {aabb} a - * @returns {aabb} - */ -function copy(a) { - return [a[0].slice(), a[1].slice()]; -} - -/** - * Sets a bounding box to another. - * @param {aabb} a - * @param {aabb} b - * @returns {aabb} - */ function set(a, b) { a[0][0] = b[0][0]; a[0][1] = b[0][1]; @@ -52,110 +10,48 @@ function set(a, b) { a[1][0] = b[1][0]; a[1][1] = b[1][1]; a[1][2] = b[1][2]; - return a; } - -/** - * Checks if a bounding box is empty. - * @param {aabb} aabb - * @returns {boolean} - */ -function isEmpty(a) { - return a[0][0] > a[1][0] || a[0][1] > a[1][1] || a[0][2] > a[1][2]; +function copy(b) { + var a = create(); + set(a, b); + return a; } - -/** - * Creates a bounding box from a list of points. - * @param {import("pex-math").vec3[]} points - * @returns {aabb} - */ function fromPoints(points) { - return setPoints(create(), points); -} - -/** - * Updates a bounding box from a list of points. - * @param {aabb} a - * @param {import("pex-math").vec3[]} points - * @returns {aabb} - */ -function setPoints(a, points) { - for (let i = 0; i < points.length; i++) { - includePoint(a, points[i]); + var aabb = create(); + var min = aabb[0]; + var max = aabb[1]; + for (var i = 0, len = points.length; i < len; i++) { + var p = points[i]; + min[0] = Math.min(min[0], p[0]); + min[1] = Math.min(min[1], p[1]); + min[2] = Math.min(min[2], p[2]); + max[0] = Math.max(max[0], p[0]); + max[1] = Math.max(max[1], p[1]); + max[2] = Math.max(max[2], p[2]); } - return a; + return aabb; } - -/** - * @private - */ -function setVec3(v = [], x, y, z) { - v[0] = x; - v[1] = y; - v[2] = z; - return v; -} - -/** - * Returns a list of 8 points from a bounding box. - * @param {aabb} aabb - * @param {import("pex-math").vec3[]} points - * @returns {import("pex-math").vec3[]} - */ -function getPoints(a, points = []) { - points[0] = setVec3(points[0], a[0][0], a[0][1], a[0][2]); - points[1] = setVec3(points[1], a[1][0], a[0][1], a[0][2]); - points[2] = setVec3(points[2], a[1][0], a[0][1], a[1][2]); - points[3] = setVec3(points[3], a[0][0], a[0][1], a[1][2]); - points[4] = setVec3(points[4], a[0][0], a[1][1], a[0][2]); - points[5] = setVec3(points[5], a[1][0], a[1][1], a[0][2]); - points[6] = setVec3(points[6], a[1][0], a[1][1], a[1][2]); - points[7] = setVec3(points[7], a[0][0], a[1][1], a[1][2]); - return points; -} - -/** - * Returns the center of a bounding box. - * @param {aabb} a - * @param {import("pex-math").vec3} out - * @returns {import("pex-math").vec3} - */ -function center(a, out = [0, 0, 0]) { - out[0] = (a[0][0] + a[1][0]) / 2; - out[1] = (a[0][1] + a[1][1]) / 2; - out[2] = (a[0][2] + a[1][2]) / 2; +function center(aabb, out) { + if (out === undefined) { + out = [0, 0, 0]; + } + out[0] = (aabb[0][0] + aabb[1][0]) / 2; + out[1] = (aabb[0][1] + aabb[1][1]) / 2; + out[2] = (aabb[0][2] + aabb[1][2]) / 2; return out; } - -/** - * Returns the size of a bounding box. - * @param {aabb} a - * @param {import("pex-math").vec3} out - * @returns {import("pex-math").vec3} - */ -function size(a, out = [0, 0, 0]) { - out[0] = Math.abs(a[1][0] - a[0][0]); - out[1] = Math.abs(a[1][1] - a[0][1]); - out[2] = Math.abs(a[1][2] - a[0][2]); +function size(aabb, out) { + if (out === undefined) { + out = [0, 0, 0]; + } + out[0] = Math.abs(aabb[1][0] - aabb[0][0]); + out[1] = Math.abs(aabb[1][1] - aabb[0][1]); + out[2] = Math.abs(aabb[1][2] - aabb[0][2]); return out; } - -/** - * Checks if a point is inside a bounding box. - * @param {bbox} a - * @param {import("pex-math").vec3} p - * @returns {boolean} - */ -function containsPoint(a, [x, y, z]) { - return x >= a[0][0] && x <= a[1][0] && y >= a[0][1] && y <= a[1][1] && z >= a[0][2] && z <= a[1][2]; +function isEmpty(aabb) { + return aabb[0][0] > aabb[1][0] || aabb[0][1] > aabb[1][1] || aabb[0][2] > aabb[1][2]; } - -/** - * Includes a bounding box in another. - * @param {aabb} a - * @param {aabb} b - * @returns {aabb} - */ function includeAABB(a, b) { if (isEmpty(a)) { set(a, b); @@ -169,13 +65,6 @@ function includeAABB(a, b) { } return a; } - -/** - * Includes a point in a bounding box. - * @param {aabb} a - * @param {import("pex-math").vec3} p - * @returns {import("pex-math").vec3} - */ function includePoint(a, p) { a[0][0] = Math.min(a[0][0], p[0]); a[0][1] = Math.min(a[0][1], p[1]); @@ -185,23 +74,17 @@ function includePoint(a, p) { a[1][2] = Math.max(a[1][2], p[2]); return a; } - -var aabb = /*#__PURE__*/Object.freeze({ - __proto__: null, +var aabb = { create: create, - empty: empty, - copy: copy, set: set, - isEmpty: isEmpty, + copy: copy, fromPoints: fromPoints, - setPoints: setPoints, - getPoints: getPoints, center: center, size: size, - containsPoint: containsPoint, + isEmpty: isEmpty, includeAABB: includeAABB, includePoint: includePoint -}); +}; function create$1() { return [0, 0, 0]; diff --git a/web_modules/geom-merge.js b/web_modules/geom-merge.js new file mode 100644 index 0000000..4bba5e0 --- /dev/null +++ b/web_modules/geom-merge.js @@ -0,0 +1,390 @@ +import { z as getBuiltIn, _ as _export, g as getIteratorDirect, a as aCallable, m as anObject, n as functionCall, v as isObject, R as asyncIteratorClose, p as functionBindContext, w as wellKnownSymbol, L as objectCreate, u as objectDefineProperty } from './common/classof-a3d4c9bc.js'; +import { i as iterate } from './common/iterate-54b5a051.js'; +import typedArrayConcat from './typed-array-concat.js'; +import { c as collectionDeleteAll, m as mapEmplace } from './common/map-emplace-0ed8f736.js'; +import { s as speciesConstructor, a as arrayIterationFromLast } from './common/esnext.typed-array.with-b6f846b8.js'; +import './common/object-set-prototype-of-eadd3696.js'; + +// https://github.com/tc39/proposal-iterator-helpers + + + + + + + + + +var Promise = getBuiltIn('Promise'); +var $TypeError = TypeError; + +_export({ target: 'AsyncIterator', proto: true, real: true, forced: true }, { + reduce: function reduce(reducer /* , initialValue */) { + var record = getIteratorDirect(this); + var iterator = record.iterator; + var next = record.next; + var noInitial = arguments.length < 2; + var accumulator = noInitial ? undefined : arguments[1]; + var counter = 0; + aCallable(reducer); + + return new Promise(function (resolve, reject) { + var ifAbruptCloseAsyncIterator = function (error) { + asyncIteratorClose(iterator, reject, error, reject); + }; + + var loop = function () { + try { + Promise.resolve(anObject(functionCall(next, iterator))).then(function (step) { + try { + if (anObject(step).done) { + noInitial ? reject($TypeError('Reduce of empty iterator with no initial value')) : resolve(accumulator); + } else { + var value = step.value; + if (noInitial) { + noInitial = false; + accumulator = value; + loop(); + } else try { + var result = reducer(accumulator, value, counter); + + var handler = function ($result) { + accumulator = $result; + loop(); + }; + + if (isObject(result)) Promise.resolve(result).then(handler, ifAbruptCloseAsyncIterator); + else handler(result); + } catch (error3) { ifAbruptCloseAsyncIterator(error3); } + } + counter++; + } catch (error2) { reject(error2); } + }, reject); + } catch (error) { reject(error); } + }; + + loop(); + }); + } +}); + +// https://github.com/tc39/proposal-iterator-helpers + + + + + +var $TypeError$1 = TypeError; + +_export({ target: 'Iterator', proto: true, real: true, forced: true }, { + reduce: function reduce(reducer /* , initialValue */) { + var record = getIteratorDirect(this); + aCallable(reducer); + var noInitial = arguments.length < 2; + var accumulator = noInitial ? undefined : arguments[1]; + var counter = 0; + iterate(record, function (value) { + if (noInitial) { + noInitial = false; + accumulator = value; + } else { + accumulator = reducer(accumulator, value, counter); + } + counter++; + }, { IS_RECORD: true }); + if (noInitial) throw $TypeError$1('Reduce of empty iterator with no initial value'); + return accumulator; + } +}); + +// `Map.prototype.deleteAll` method +// https://github.com/tc39/proposal-collection-methods +_export({ target: 'Map', proto: true, real: true, forced: true }, { + deleteAll: collectionDeleteAll +}); + +// `Map.prototype.emplace` method +// https://github.com/thumbsupep/proposal-upsert +_export({ target: 'Map', proto: true, real: true, forced: true }, { + emplace: mapEmplace +}); + +var getMapIterator = function (it) { + // eslint-disable-next-line es/no-map -- safe + return functionCall(Map.prototype.entries, it); +}; + +// `Map.prototype.every` method +// https://github.com/tc39/proposal-collection-methods +_export({ target: 'Map', proto: true, real: true, forced: true }, { + every: function every(callbackfn /* , thisArg */) { + var map = anObject(this); + var iterator = getMapIterator(map); + var boundFunction = functionBindContext(callbackfn, arguments.length > 1 ? arguments[1] : undefined); + return !iterate(iterator, function (key, value, stop) { + if (!boundFunction(value, key, map)) return stop(); + }, { AS_ENTRIES: true, IS_ITERATOR: true, INTERRUPTED: true }).stopped; + } +}); + +// `Map.prototype.filter` method +// https://github.com/tc39/proposal-collection-methods +_export({ target: 'Map', proto: true, real: true, forced: true }, { + filter: function filter(callbackfn /* , thisArg */) { + var map = anObject(this); + var iterator = getMapIterator(map); + var boundFunction = functionBindContext(callbackfn, arguments.length > 1 ? arguments[1] : undefined); + var newMap = new (speciesConstructor(map, getBuiltIn('Map')))(); + var setter = aCallable(newMap.set); + iterate(iterator, function (key, value) { + if (boundFunction(value, key, map)) functionCall(setter, newMap, key, value); + }, { AS_ENTRIES: true, IS_ITERATOR: true }); + return newMap; + } +}); + +// `Map.prototype.find` method +// https://github.com/tc39/proposal-collection-methods +_export({ target: 'Map', proto: true, real: true, forced: true }, { + find: function find(callbackfn /* , thisArg */) { + var map = anObject(this); + var iterator = getMapIterator(map); + var boundFunction = functionBindContext(callbackfn, arguments.length > 1 ? arguments[1] : undefined); + return iterate(iterator, function (key, value, stop) { + if (boundFunction(value, key, map)) return stop(value); + }, { AS_ENTRIES: true, IS_ITERATOR: true, INTERRUPTED: true }).result; + } +}); + +// `Map.prototype.findKey` method +// https://github.com/tc39/proposal-collection-methods +_export({ target: 'Map', proto: true, real: true, forced: true }, { + findKey: function findKey(callbackfn /* , thisArg */) { + var map = anObject(this); + var iterator = getMapIterator(map); + var boundFunction = functionBindContext(callbackfn, arguments.length > 1 ? arguments[1] : undefined); + return iterate(iterator, function (key, value, stop) { + if (boundFunction(value, key, map)) return stop(key); + }, { AS_ENTRIES: true, IS_ITERATOR: true, INTERRUPTED: true }).result; + } +}); + +// `SameValueZero` abstract operation +// https://tc39.es/ecma262/#sec-samevaluezero +var sameValueZero = function (x, y) { + // eslint-disable-next-line no-self-compare -- NaN check + return x === y || x != x && y != y; +}; + +// `Map.prototype.includes` method +// https://github.com/tc39/proposal-collection-methods +_export({ target: 'Map', proto: true, real: true, forced: true }, { + includes: function includes(searchElement) { + return iterate(getMapIterator(anObject(this)), function (key, value, stop) { + if (sameValueZero(value, searchElement)) return stop(); + }, { AS_ENTRIES: true, IS_ITERATOR: true, INTERRUPTED: true }).stopped; + } +}); + +// `Map.prototype.keyOf` method +// https://github.com/tc39/proposal-collection-methods +_export({ target: 'Map', proto: true, real: true, forced: true }, { + keyOf: function keyOf(searchElement) { + return iterate(getMapIterator(anObject(this)), function (key, value, stop) { + if (value === searchElement) return stop(key); + }, { AS_ENTRIES: true, IS_ITERATOR: true, INTERRUPTED: true }).result; + } +}); + +// `Map.prototype.mapKeys` method +// https://github.com/tc39/proposal-collection-methods +_export({ target: 'Map', proto: true, real: true, forced: true }, { + mapKeys: function mapKeys(callbackfn /* , thisArg */) { + var map = anObject(this); + var iterator = getMapIterator(map); + var boundFunction = functionBindContext(callbackfn, arguments.length > 1 ? arguments[1] : undefined); + var newMap = new (speciesConstructor(map, getBuiltIn('Map')))(); + var setter = aCallable(newMap.set); + iterate(iterator, function (key, value) { + functionCall(setter, newMap, boundFunction(value, key, map), value); + }, { AS_ENTRIES: true, IS_ITERATOR: true }); + return newMap; + } +}); + +// `Map.prototype.mapValues` method +// https://github.com/tc39/proposal-collection-methods +_export({ target: 'Map', proto: true, real: true, forced: true }, { + mapValues: function mapValues(callbackfn /* , thisArg */) { + var map = anObject(this); + var iterator = getMapIterator(map); + var boundFunction = functionBindContext(callbackfn, arguments.length > 1 ? arguments[1] : undefined); + var newMap = new (speciesConstructor(map, getBuiltIn('Map')))(); + var setter = aCallable(newMap.set); + iterate(iterator, function (key, value) { + functionCall(setter, newMap, key, boundFunction(value, key, map)); + }, { AS_ENTRIES: true, IS_ITERATOR: true }); + return newMap; + } +}); + +// `Map.prototype.merge` method +// https://github.com/tc39/proposal-collection-methods +_export({ target: 'Map', proto: true, real: true, arity: 1, forced: true }, { + // eslint-disable-next-line no-unused-vars -- required for `.length` + merge: function merge(iterable /* ...iterables */) { + var map = anObject(this); + var setter = aCallable(map.set); + var argumentsLength = arguments.length; + var i = 0; + while (i < argumentsLength) { + iterate(arguments[i++], setter, { that: map, AS_ENTRIES: true }); + } + return map; + } +}); + +var $TypeError$2 = TypeError; + +// `Map.prototype.reduce` method +// https://github.com/tc39/proposal-collection-methods +_export({ target: 'Map', proto: true, real: true, forced: true }, { + reduce: function reduce(callbackfn /* , initialValue */) { + var map = anObject(this); + var iterator = getMapIterator(map); + var noInitial = arguments.length < 2; + var accumulator = noInitial ? undefined : arguments[1]; + aCallable(callbackfn); + iterate(iterator, function (key, value) { + if (noInitial) { + noInitial = false; + accumulator = value; + } else { + accumulator = callbackfn(accumulator, value, key, map); + } + }, { AS_ENTRIES: true, IS_ITERATOR: true }); + if (noInitial) throw $TypeError$2('Reduce of empty map with no initial value'); + return accumulator; + } +}); + +// `Set.prototype.some` method +// https://github.com/tc39/proposal-collection-methods +_export({ target: 'Map', proto: true, real: true, forced: true }, { + some: function some(callbackfn /* , thisArg */) { + var map = anObject(this); + var iterator = getMapIterator(map); + var boundFunction = functionBindContext(callbackfn, arguments.length > 1 ? arguments[1] : undefined); + return iterate(iterator, function (key, value, stop) { + if (boundFunction(value, key, map)) return stop(); + }, { AS_ENTRIES: true, IS_ITERATOR: true, INTERRUPTED: true }).stopped; + } +}); + +var $TypeError$3 = TypeError; + +// `Set.prototype.update` method +// https://github.com/tc39/proposal-collection-methods +_export({ target: 'Map', proto: true, real: true, forced: true }, { + update: function update(key, callback /* , thunk */) { + var map = anObject(this); + var get = aCallable(map.get); + var has = aCallable(map.has); + var set = aCallable(map.set); + var length = arguments.length; + aCallable(callback); + var isPresentInMap = functionCall(has, map, key); + if (!isPresentInMap && length < 3) { + throw $TypeError$3('Updating absent value'); + } + var value = isPresentInMap ? functionCall(get, map, key) : aCallable(length > 2 ? arguments[2] : undefined)(key, map); + functionCall(set, map, key, callback(value, key, map)); + return map; + } +}); + +var defineProperty = objectDefineProperty.f; + +var UNSCOPABLES = wellKnownSymbol('unscopables'); +var ArrayPrototype = Array.prototype; + +// Array.prototype[@@unscopables] +// https://tc39.es/ecma262/#sec-array.prototype-@@unscopables +if (ArrayPrototype[UNSCOPABLES] == undefined) { + defineProperty(ArrayPrototype, UNSCOPABLES, { + configurable: true, + value: objectCreate(null) + }); +} + +// add a key to Array.prototype[@@unscopables] +var addToUnscopables = function (key) { + ArrayPrototype[UNSCOPABLES][key] = true; +}; + +var $findLastIndex = arrayIterationFromLast.findLastIndex; + + +// `Array.prototype.findLastIndex` method +// https://github.com/tc39/proposal-array-find-from-last +_export({ target: 'Array', proto: true }, { + findLastIndex: function findLastIndex(callbackfn /* , that = undefined */) { + return $findLastIndex(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); + } +}); + +addToUnscopables('findLastIndex'); + +/** + * @module typedArrayConstructor + */ + +const upperBounds = new Map(); +upperBounds.set([Int8Array, Uint8Array], 255); +upperBounds.set([Int16Array, Uint16Array], 65535); +upperBounds.set([Int32Array, Uint32Array], 4294967295); +upperBounds.set([BigInt64Array, BigUint64Array], 2 ** 64 - 1); +const upperBoundsArray = Array.from(upperBounds.entries()); + +/** + * Get a typed array constructor based on the hypothetical max value it could contain. Signed or unsigned. + * + * @alias module:typedArrayConstructor + * @param {number} maxValue The max value expected. + * @param {boolean} signed Get a signed or unsigned array. + * @returns {(Uint8Array|Uint16Array|Uint32Array|BigInt64Array|Int8Array|Int16Array|Int32Array|BigInt64Array)} + * @see [MDN TypedArray objects]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#typedarray_objects} + */ +const typedArrayConstructor = (maxValue, signed) => { + const value = signed ? Math.abs(maxValue) : Math.max(0, maxValue); + return upperBoundsArray[upperBoundsArray.findLastIndex(([_, bound]) => value > Math[Math.sign(maxValue) === -1 ? "ceil" : "floor"](bound / (signed ? 2 : 1))) + 1][0][signed ? 0 : 1]; +}; + +function merge(geometries) { + const isTypedArray = !Array.isArray(geometries[0].positions); + const CellsConstructor = isTypedArray ? typedArrayConstructor(geometries.reduce((sum, geometry) => sum + geometry.positions.length / (isTypedArray ? 3 : 1), 0)) : Array; + const mergedGeometry = { + cells: new CellsConstructor() + }; + let vertexOffset = 0; + for (let i = 0; i < geometries.length; i++) { + const geometry = geometries[i]; + const vertexCount = geometry.positions.length / (isTypedArray ? 3 : 1); + for (let attribute of Object.keys(geometry)) { + if (attribute === "cells") { + mergedGeometry.cells = isTypedArray ? typedArrayConcat(CellsConstructor, mergedGeometry.cells, + // Add previous geometry vertex offset mapped via a new typed array + // because new value could be larger than what current type supports + new (typedArrayConstructor(vertexOffset + vertexCount))(geometry.cells).map(n => vertexOffset + n)) : mergedGeometry.cells.concat(geometry.cells.map(cell => cell.map(n => vertexOffset + n))); + } else { + const isAttributeTypedArray = !Array.isArray(geometry[attribute]); + mergedGeometry[attribute] ||= isAttributeTypedArray ? new geometry[attribute].constructor() : []; + mergedGeometry[attribute] = isAttributeTypedArray ? typedArrayConcat(mergedGeometry[attribute].constructor, mergedGeometry[attribute], geometry[attribute]) : mergedGeometry[attribute].concat(geometry[attribute]); + } + } + vertexOffset += vertexCount; + } + return mergedGeometry; +} + +export default merge; diff --git a/web_modules/import-map.json b/web_modules/import-map.json index b4d1f00..36e0b69 100644 --- a/web_modules/import-map.json +++ b/web_modules/import-map.json @@ -4,6 +4,7 @@ "bunny": "./bunny.js", "es-module-shims": "./es-module-shims.js", "geom-center-and-normalize": "./geom-center-and-normalize.js", + "geom-merge": "./geom-merge.js", "normals": "./normals.js", "pex-cam": "./pex-cam.js", "pex-color": "./pex-color.js", @@ -12,6 +13,7 @@ "pex-io": "./pex-io.js", "pex-math": "./pex-math.js", "pex-random": "./pex-random.js", - "primitive-geometry": "./primitive-geometry.js" + "primitive-geometry": "./primitive-geometry.js", + "typed-array-concat": "./typed-array-concat.js" } } \ No newline at end of file diff --git a/web_modules/pex-color.js b/web_modules/pex-color.js index bebdde7..6e1eb30 100644 --- a/web_modules/pex-color.js +++ b/web_modules/pex-color.js @@ -1,7 +1,8 @@ -import { f as fromLinear$1, s as setAlpha, t as toLinear$1, a as fromHSL, b as toHSL, m, c as minv, g as getStMax, o as oklabToLinearSrgb, T as TMP, d as fromOklab, l as linearSrgbToOklab, e as toe, h as toeInv, i as findCusp, j as luvToXyz, k as lchToLuv, n as luvToLch, x as xyzToLuv, L as L_EPSILON, p as getBounds, q as floorArray } from './common/hsl-5dfe9087.js'; -export { a as fromHSL, r as fromHex, d as fromOklab, l as linearSrgbToOklab, o as oklabToLinearSrgb, b as toHSL, v as toHex, w as toOklab, u as utils } from './common/hsl-5dfe9087.js'; -import './common/classof-b64a2315.js'; -import './common/iterate-e1e675f3.js'; +import { f as fromLinear$1, s as setAlpha, t as toLinear$1, a as fromHSL, b as toHSL, m, c as minv, g as getStMax, o as oklabToLinearSrgb, T as TMP, d as fromOklab, l as linearSrgbToOklab, e as toe, h as toeInv, i as findCusp, j as luvToXyz, k as lchToLuv, n as luvToLch, x as xyzToLuv, L as L_EPSILON, p as getBounds, q as floorArray } from './common/hsl-d415d8ba.js'; +export { a as fromHSL, r as fromHex, d as fromOklab, l as linearSrgbToOklab, o as oklabToLinearSrgb, b as toHSL, v as toHex, w as toOklab, u as utils } from './common/hsl-d415d8ba.js'; +import './common/classof-a3d4c9bc.js'; +import './common/async-iterator-iteration-026ee04a.js'; +import './common/iterate-54b5a051.js'; /** * Updates a color based on linear r, g, b, a values. diff --git a/web_modules/pex-gui.js b/web_modules/pex-gui.js index 8546f91..d3cfd35 100644 --- a/web_modules/pex-gui.js +++ b/web_modules/pex-gui.js @@ -1,9 +1,12 @@ -import './common/es.error.cause-80fb3656.js'; -import { v as toHex, b as toHSL, a as fromHSL } from './common/hsl-5dfe9087.js'; -import './common/iterate-e1e675f3.js'; -import './common/esnext.iterator.filter-c3958098.js'; -import { d as anObject, a as aCallable, f as functionCall, _ as _export } from './common/classof-b64a2315.js'; +import './common/es.error.cause-0747567f.js'; +import { v as toHex, b as toHSL, a as fromHSL } from './common/hsl-d415d8ba.js'; +import './common/iterate-54b5a051.js'; +import './common/esnext.iterator.filter-81df7261.js'; +import { _ as _export } from './common/classof-a3d4c9bc.js'; +import { c as collectionDeleteAll, m as mapEmplace } from './common/map-emplace-0ed8f736.js'; import { m as map, c as clamp } from './common/utils-7e499548.js'; +import './common/object-set-prototype-of-eadd3696.js'; +import './common/async-iterator-iteration-026ee04a.js'; function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { @@ -41,45 +44,12 @@ function _classPrivateFieldSet(receiver, privateMap, value) { return value; } -// https://github.com/tc39/collection-methods -var collectionDeleteAll = function deleteAll(/* ...elements */) { - var collection = anObject(this); - var remover = aCallable(collection['delete']); - var allDeleted = true; - var wasDeleted; - for (var k = 0, len = arguments.length; k < len; k++) { - wasDeleted = functionCall(remover, collection, arguments[k]); - allDeleted = allDeleted && wasDeleted; - } - return !!allDeleted; -}; - // `WeakMap.prototype.deleteAll` method // https://github.com/tc39/proposal-collection-methods _export({ target: 'WeakMap', proto: true, real: true, forced: true }, { deleteAll: collectionDeleteAll }); -// `Map.prototype.emplace` method -// https://github.com/thumbsupep/proposal-upsert -var mapEmplace = function emplace(key, handler) { - var map = anObject(this); - var get = aCallable(map.get); - var has = aCallable(map.has); - var set = aCallable(map.set); - var value, inserted; - if (functionCall(has, map, key)) { - value = functionCall(get, map, key); - if ('update' in handler) { - value = handler.update(value, key, map); - functionCall(set, map, key, value); - } return value; - } - inserted = handler.insert(key, map); - functionCall(set, map, key, inserted); - return inserted; -}; - // `WeakMap.prototype.emplace` method // https://github.com/tc39/proposal-upsert _export({ target: 'WeakMap', proto: true, real: true, forced: true }, { diff --git a/web_modules/pex-io.js b/web_modules/pex-io.js index 47b4bc3..f8c4727 100644 --- a/web_modules/pex-io.js +++ b/web_modules/pex-io.js @@ -1,6 +1,8 @@ -import './common/es.error.cause-80fb3656.js'; -import { _ as _export, g as getIteratorDirect, a as aCallable } from './common/classof-b64a2315.js'; -import { a as asyncIteratorIteration, i as iterate } from './common/iterate-e1e675f3.js'; +import './common/es.error.cause-0747567f.js'; +import { _ as _export, g as getIteratorDirect, a as aCallable } from './common/classof-a3d4c9bc.js'; +import { a as asyncIteratorIteration } from './common/async-iterator-iteration-026ee04a.js'; +import { i as iterate } from './common/iterate-54b5a051.js'; +import './common/object-set-prototype-of-eadd3696.js'; // https://github.com/tc39/proposal-iterator-helpers diff --git a/web_modules/pex-random.js b/web_modules/pex-random.js index 6565e48..847b882 100644 --- a/web_modules/pex-random.js +++ b/web_modules/pex-random.js @@ -1,35 +1,9 @@ -import './common/es.error.cause-80fb3656.js'; -import { U as createCommonjsModule, c as commonjsGlobal, V as getDefaultExportFromNamespaceIfNotNamed } from './common/classof-b64a2315.js'; -import './common/esnext.typed-array.with-8b639300.js'; - -function _typeof(obj) { - "@babel/helpers - typeof"; - - return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { - return typeof obj; - } : function (obj) { - return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }, _typeof(obj); -} - -function _toPrimitive(input, hint) { - if (_typeof(input) !== "object" || input === null) return input; - var prim = input[Symbol.toPrimitive]; - if (prim !== undefined) { - var res = prim.call(input, hint || "default"); - if (_typeof(res) !== "object") return res; - throw new TypeError("@@toPrimitive must return a primitive value."); - } - return (hint === "string" ? String : Number)(input); -} - -function _toPropertyKey(arg) { - var key = _toPrimitive(arg, "string"); - return _typeof(key) === "symbol" ? key : String(key); -} +import './common/es.error.cause-0747567f.js'; +import { U as createCommonjsModule, c as commonjsGlobal, V as getDefaultExportFromNamespaceIfNotNamed } from './common/classof-a3d4c9bc.js'; +import './common/esnext.typed-array.with-b6f846b8.js'; +import './common/object-set-prototype-of-eadd3696.js'; function _defineProperty(obj, key, value) { - key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, diff --git a/web_modules/primitive-geometry.js b/web_modules/primitive-geometry.js index ce904d5..1765c58 100644 --- a/web_modules/primitive-geometry.js +++ b/web_modules/primitive-geometry.js @@ -1,6 +1,7 @@ -import './common/esnext.typed-array.with-8b639300.js'; -import './common/es.error.cause-80fb3656.js'; -import './common/classof-b64a2315.js'; +import './common/esnext.typed-array.with-b6f846b8.js'; +import './common/es.error.cause-0747567f.js'; +import './common/classof-a3d4c9bc.js'; +import './common/object-set-prototype-of-eadd3696.js'; /** @module utils */ diff --git a/web_modules/typed-array-concat.js b/web_modules/typed-array-concat.js new file mode 100644 index 0000000..a6a40d5 --- /dev/null +++ b/web_modules/typed-array-concat.js @@ -0,0 +1,27 @@ +/** + * @module typedArrayConcat + */ + +/** + * Concatenate n typed arrays + * + * @alias module:typedArrayConcat + * @param {TypedArray} ResultConstructor Returned typed array constructor + * @param {...TypedArray} arrays Arrays to concatenate + * @returns {TypedArray} + */ +function typedArrayConcat(ResultConstructor, ...arrays) { + let totalLength = 0; + for (const arr of arrays) { + totalLength += arr.length; + } + const result = new ResultConstructor(totalLength); + let offset = 0; + for (const arr of arrays) { + result.set(arr, offset); + offset += arr.length; + } + return result; +} + +export default typedArrayConcat;