@math.gl/geometry-utils 4.2.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +140 -0
- package/README.md +8 -0
- package/dist/attribute-compression.d.ts +50 -0
- package/dist/attribute-compression.d.ts.map +1 -0
- package/dist/attribute-compression.js +184 -0
- package/dist/attribute-compression.js.map +1 -0
- package/dist/attribute-iterator.d.ts +8 -0
- package/dist/attribute-iterator.d.ts.map +1 -0
- package/dist/attribute-iterator.js +25 -0
- package/dist/attribute-iterator.js.map +1 -0
- package/dist/compute-vertex-normals.d.ts +4 -0
- package/dist/compute-vertex-normals.d.ts.map +1 -0
- package/dist/compute-vertex-normals.js +54 -0
- package/dist/compute-vertex-normals.js.map +1 -0
- package/dist/constants.d.ts +52 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +39 -0
- package/dist/constants.js.map +1 -0
- package/dist/coordinates.d.ts +3 -0
- package/dist/coordinates.d.ts.map +1 -0
- package/dist/coordinates.js +8 -0
- package/dist/coordinates.js.map +1 -0
- package/dist/geometry.d.ts +20 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +31 -0
- package/dist/geometry.js.map +1 -0
- package/dist/gl-type.d.ts +17 -0
- package/dist/gl-type.d.ts.map +1 -0
- package/dist/gl-type.js +69 -0
- package/dist/gl-type.js.map +1 -0
- package/dist/index.cjs +535 -0
- package/dist/index.cjs.map +6 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/primitive-iterator.d.ts +21 -0
- package/dist/primitive-iterator.d.ts.map +1 -0
- package/dist/primitive-iterator.js +117 -0
- package/dist/primitive-iterator.js.map +1 -0
- package/dist/rgb565.d.ts +5 -0
- package/dist/rgb565.d.ts.map +1 -0
- package/dist/rgb565.js +24 -0
- package/dist/rgb565.js.map +1 -0
- package/dist/typed-array-utils.d.ts +3 -0
- package/dist/typed-array-utils.d.ts.map +1 -0
- package/dist/typed-array-utils.js +16 -0
- package/dist/typed-array-utils.js.map +1 -0
- package/package.json +40 -0
- package/src/attribute-compression.ts +232 -0
- package/src/attribute-iterator.ts +28 -0
- package/src/compute-vertex-normals.ts +63 -0
- package/src/constants.ts +42 -0
- package/src/coordinates.ts +8 -0
- package/src/geometry.ts +49 -0
- package/src/gl-type.ts +87 -0
- package/src/index.ts +38 -0
- package/src/primitive-iterator.ts +145 -0
- package/src/rgb565.ts +26 -0
- package/src/typed-array-utils.ts +16 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TypedArray } from '@math.gl/types';
|
|
2
|
+
/** A typed geometry attribute with either loaders.gl-style `value` or legacy `values` storage. */
|
|
3
|
+
export type GeometryAttribute = {
|
|
4
|
+
value?: TypedArray;
|
|
5
|
+
values?: TypedArray;
|
|
6
|
+
size?: number;
|
|
7
|
+
};
|
|
8
|
+
/** Minimal geometry shape understood by the geometry utilities. */
|
|
9
|
+
export type Geometry = {
|
|
10
|
+
mode: number;
|
|
11
|
+
indices?: GeometryAttribute | TypedArray;
|
|
12
|
+
attributes: Record<string, GeometryAttribute>;
|
|
13
|
+
};
|
|
14
|
+
/** Returns whether a value has the minimal geometry shape. */
|
|
15
|
+
export declare function isGeometry(value: unknown): value is Geometry;
|
|
16
|
+
/** Returns the typed array stored in a geometry attribute. */
|
|
17
|
+
export declare function getAttributeValues(attribute: GeometryAttribute | TypedArray): TypedArray;
|
|
18
|
+
/** Returns a geometry's position attribute. */
|
|
19
|
+
export declare function getPositionAttribute(geometry: Geometry): GeometryAttribute;
|
|
20
|
+
//# sourceMappingURL=geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAE/C,kGAAkG;AAClG,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,mEAAmE;AACnE,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,iBAAiB,GAAG,UAAU,CAAC;IACzC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;CAC/C,CAAC;AAEF,8DAA8D;AAC9D,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAM5D;AAED,8DAA8D;AAC9D,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,iBAAiB,GAAG,UAAU,GAAG,UAAU,CASxF;AAED,+CAA+C;AAC/C,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,iBAAiB,CAM1E"}
|
package/dist/geometry.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/** Returns whether a value has the minimal geometry shape. */
|
|
5
|
+
export function isGeometry(value) {
|
|
6
|
+
if (!value || typeof value !== 'object') {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const geometry = value;
|
|
10
|
+
return typeof geometry.mode === 'number' && Boolean(geometry.attributes);
|
|
11
|
+
}
|
|
12
|
+
/** Returns the typed array stored in a geometry attribute. */
|
|
13
|
+
export function getAttributeValues(attribute) {
|
|
14
|
+
if (ArrayBuffer.isView(attribute)) {
|
|
15
|
+
return attribute;
|
|
16
|
+
}
|
|
17
|
+
const values = attribute.value || attribute.values;
|
|
18
|
+
if (!values) {
|
|
19
|
+
throw new Error('Geometry attribute does not contain typed-array values');
|
|
20
|
+
}
|
|
21
|
+
return values;
|
|
22
|
+
}
|
|
23
|
+
/** Returns a geometry's position attribute. */
|
|
24
|
+
export function getPositionAttribute(geometry) {
|
|
25
|
+
const position = geometry.attributes['POSITION'] || geometry.attributes['positions'];
|
|
26
|
+
if (!position) {
|
|
27
|
+
throw new Error('Geometry does not contain a position attribute');
|
|
28
|
+
}
|
|
29
|
+
return position;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.js","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAkBpC,8DAA8D;AAC9D,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,QAAQ,GAAG,KAA0B,CAAC;IAC5C,OAAO,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AAC3E,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,kBAAkB,CAAC,SAAyC;IAC1E,IAAI,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;QAClC,OAAO,SAAuB,CAAC;IACjC,CAAC;IACD,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,IAAI,SAAS,CAAC,MAAM,CAAC;IACnD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,+CAA+C;AAC/C,MAAM,UAAU,oBAAoB,CAAC,QAAkB;IACrD,MAAM,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IACrF,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TypedArray, TypedArrayConstructor } from '@math.gl/types';
|
|
2
|
+
/** Converts between WebGL component constants and JavaScript typed arrays. */
|
|
3
|
+
export default class GLType {
|
|
4
|
+
/** Returns the WebGL component constant for a typed array or typed-array constructor. */
|
|
5
|
+
static fromTypedArray(arrayOrType: TypedArray | TypedArrayConstructor): number;
|
|
6
|
+
/** Returns a WebGL component constant from its uppercase name. */
|
|
7
|
+
static fromName(name: string): number;
|
|
8
|
+
/** Returns the typed-array constructor for a WebGL component constant. */
|
|
9
|
+
static getArrayType(glType: number): TypedArrayConstructor;
|
|
10
|
+
/** Returns the size in bytes of one element of a WebGL component type. */
|
|
11
|
+
static getByteSize(glType: number): number;
|
|
12
|
+
/** Returns whether a value is a supported WebGL component type. */
|
|
13
|
+
static validate(glType: number): boolean;
|
|
14
|
+
/** Creates a typed view over an ArrayBuffer or an existing ArrayBuffer view. */
|
|
15
|
+
static createTypedArray(glType: number, buffer: ArrayBufferLike | ArrayBufferView, byteOffset?: number, length?: number): TypedArray;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=gl-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gl-type.d.ts","sourceRoot":"","sources":["../src/gl-type.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAE,qBAAqB,EAAC,MAAM,gBAAgB,CAAC;AAuBtE,8EAA8E;AAC9E,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,yFAAyF;IACzF,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,UAAU,GAAG,qBAAqB,GAAG,MAAM;IAa9E,kEAAkE;IAClE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAQrC,0EAA0E;IAC1E,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB;IAQ1D,0EAA0E;IAC1E,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAI1C,mEAAmE;IACnE,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIxC,gFAAgF;IAChF,MAAM,CAAC,gBAAgB,CACrB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,eAAe,GAAG,eAAe,EACzC,UAAU,SAAI,EACd,MAAM,CAAC,EAAE,MAAM,GACd,UAAU;CASd"}
|
package/dist/gl-type.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { GL_TYPE } from "./constants.js";
|
|
5
|
+
const GL_TYPE_TO_ARRAY_TYPE = {
|
|
6
|
+
[GL_TYPE.DOUBLE]: Float64Array,
|
|
7
|
+
[GL_TYPE.FLOAT]: Float32Array,
|
|
8
|
+
[GL_TYPE.UNSIGNED_SHORT]: Uint16Array,
|
|
9
|
+
[GL_TYPE.UNSIGNED_INT]: Uint32Array,
|
|
10
|
+
[GL_TYPE.UNSIGNED_BYTE]: Uint8Array,
|
|
11
|
+
[GL_TYPE.BYTE]: Int8Array,
|
|
12
|
+
[GL_TYPE.SHORT]: Int16Array,
|
|
13
|
+
[GL_TYPE.INT]: Int32Array,
|
|
14
|
+
[GL_TYPE.UNSIGNED_SHORT_4_4_4_4]: Uint16Array,
|
|
15
|
+
[GL_TYPE.UNSIGNED_SHORT_5_5_5_1]: Uint16Array,
|
|
16
|
+
[GL_TYPE.UNSIGNED_SHORT_5_6_5]: Uint16Array
|
|
17
|
+
};
|
|
18
|
+
const NAME_TO_GL_TYPE = Object.fromEntries(Object.entries(GL_TYPE).map(([name, glType]) => [name, glType]));
|
|
19
|
+
const TYPE_CONVERSION_ERROR = 'Failed to convert GL type';
|
|
20
|
+
/** Converts between WebGL component constants and JavaScript typed arrays. */
|
|
21
|
+
export default class GLType {
|
|
22
|
+
/** Returns the WebGL component constant for a typed array or typed-array constructor. */
|
|
23
|
+
static fromTypedArray(arrayOrType) {
|
|
24
|
+
const arrayType = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
|
|
25
|
+
if (arrayType === Uint8ClampedArray) {
|
|
26
|
+
return GL_TYPE.UNSIGNED_BYTE;
|
|
27
|
+
}
|
|
28
|
+
for (const [glType, candidateArrayType] of Object.entries(GL_TYPE_TO_ARRAY_TYPE)) {
|
|
29
|
+
if (candidateArrayType === arrayType) {
|
|
30
|
+
return Number(glType);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw new Error(TYPE_CONVERSION_ERROR);
|
|
34
|
+
}
|
|
35
|
+
/** Returns a WebGL component constant from its uppercase name. */
|
|
36
|
+
static fromName(name) {
|
|
37
|
+
const glType = NAME_TO_GL_TYPE[name];
|
|
38
|
+
if (glType === undefined) {
|
|
39
|
+
throw new Error(TYPE_CONVERSION_ERROR);
|
|
40
|
+
}
|
|
41
|
+
return glType;
|
|
42
|
+
}
|
|
43
|
+
/** Returns the typed-array constructor for a WebGL component constant. */
|
|
44
|
+
static getArrayType(glType) {
|
|
45
|
+
const ArrayType = GL_TYPE_TO_ARRAY_TYPE[glType];
|
|
46
|
+
if (!ArrayType) {
|
|
47
|
+
throw new Error(TYPE_CONVERSION_ERROR);
|
|
48
|
+
}
|
|
49
|
+
return ArrayType;
|
|
50
|
+
}
|
|
51
|
+
/** Returns the size in bytes of one element of a WebGL component type. */
|
|
52
|
+
static getByteSize(glType) {
|
|
53
|
+
return GLType.getArrayType(glType).BYTES_PER_ELEMENT;
|
|
54
|
+
}
|
|
55
|
+
/** Returns whether a value is a supported WebGL component type. */
|
|
56
|
+
static validate(glType) {
|
|
57
|
+
return Boolean(GL_TYPE_TO_ARRAY_TYPE[glType]);
|
|
58
|
+
}
|
|
59
|
+
/** Creates a typed view over an ArrayBuffer or an existing ArrayBuffer view. */
|
|
60
|
+
static createTypedArray(glType, buffer, byteOffset = 0, length) {
|
|
61
|
+
const ArrayType = GLType.getArrayType(glType);
|
|
62
|
+
const arrayBuffer = ArrayBuffer.isView(buffer) ? buffer.buffer : buffer;
|
|
63
|
+
const viewByteOffset = ArrayBuffer.isView(buffer) ? buffer.byteOffset : 0;
|
|
64
|
+
const resolvedByteOffset = viewByteOffset + byteOffset;
|
|
65
|
+
const resolvedLength = length ?? Math.floor((buffer.byteLength - byteOffset) / ArrayType.BYTES_PER_ELEMENT);
|
|
66
|
+
return new ArrayType(arrayBuffer, resolvedByteOffset, resolvedLength);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=gl-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gl-type.js","sourceRoot":"","sources":["../src/gl-type.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAC,OAAO,EAAC,uBAAoB;AAEpC,MAAM,qBAAqB,GAA0C;IACnE,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY;IAC9B,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,YAAY;IAC7B,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,WAAW;IACrC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,WAAW;IACnC,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,UAAU;IACnC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS;IACzB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,UAAU;IAC3B,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,UAAU;IACzB,CAAC,OAAO,CAAC,sBAAsB,CAAC,EAAE,WAAW;IAC7C,CAAC,OAAO,CAAC,sBAAsB,CAAC,EAA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