@loaders.gl/math 4.0.0-alpha.9 → 4.0.0-beta.2

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.
Files changed (34) hide show
  1. package/dist/es5/geometry/utils/coordinates.js +10 -0
  2. package/dist/es5/geometry/utils/coordinates.js.map +1 -0
  3. package/dist/es5/index.js +7 -0
  4. package/dist/es5/index.js.map +1 -1
  5. package/dist/esm/geometry/utils/coordinates.js +4 -0
  6. package/dist/esm/geometry/utils/coordinates.js.map +1 -0
  7. package/dist/esm/index.js +1 -0
  8. package/dist/esm/index.js.map +1 -1
  9. package/dist/geometry/utils/coordinates.d.ts +6 -0
  10. package/dist/geometry/utils/coordinates.d.ts.map +1 -0
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/package.json +4 -4
  14. package/src/geometry/utils/coordinates.ts +7 -0
  15. package/src/index.ts +2 -0
  16. package/dist/geometry/attributes/compute-bounding-box.js +0 -44
  17. package/dist/geometry/attributes/compute-bounding-sphere.js +0 -30
  18. package/dist/geometry/attributes/compute-tangents.js +0 -146
  19. package/dist/geometry/attributes/compute-vertex-normals.js +0 -48
  20. package/dist/geometry/attributes/convert-to-non-indexed.js +0 -33
  21. package/dist/geometry/attributes/get-attribute-from-geometry.js +0 -34
  22. package/dist/geometry/attributes/normalize.js +0 -20
  23. package/dist/geometry/colors/rgb565.js +0 -31
  24. package/dist/geometry/compression/attribute-compression.js +0 -352
  25. package/dist/geometry/constants.js +0 -34
  26. package/dist/geometry/gl/gl-type.js +0 -112
  27. package/dist/geometry/is-geometry.js +0 -14
  28. package/dist/geometry/iterators/attribute-iterator.js +0 -19
  29. package/dist/geometry/iterators/primitive-iterator.js +0 -88
  30. package/dist/geometry/primitives/modes.js +0 -71
  31. package/dist/geometry/typed-arrays/typed-array-utils.js +0 -25
  32. package/dist/geometry/utils/assert.js +0 -14
  33. package/dist/index.js +0 -46
  34. package/dist/utils/assert.js +0 -12
@@ -1,352 +0,0 @@
1
- "use strict";
2
- // This file is derived from the Cesium code base under Apache 2 license
3
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.zigZagDeltaDecode = exports.decompressTextureCoordinates = exports.compressTextureCoordinates = exports.octUnpack = exports.octPack = exports.octDecodeFloat = exports.octEncodeFloat = exports.octPackFloat = exports.octDecodeFromVector4 = exports.octDecode = exports.octDecodeInRange = exports.octEncodeToVector4 = exports.octEncode = exports.octEncodeInRange = void 0;
6
- // Attribute compression and decompression functions.
7
- const core_1 = require("@math.gl/core");
8
- const assert_1 = require("../utils/assert");
9
- const RIGHT_SHIFT = 1.0 / 256.0;
10
- const LEFT_SHIFT = 256.0;
11
- const scratchVector2 = new core_1.Vector2();
12
- const scratchVector3 = new core_1.Vector3();
13
- const scratchEncodeVector2 = new core_1.Vector2();
14
- const octEncodeScratch = new core_1.Vector2();
15
- const uint8ForceArray = new Uint8Array(1);
16
- /**
17
- * Force a value to Uint8
18
- *
19
- * @param value
20
- * @returns
21
- */
22
- function forceUint8(value) {
23
- uint8ForceArray[0] = value;
24
- return uint8ForceArray[0];
25
- }
26
- /**
27
- * Converts a SNORM value in the range [0, rangeMaximum] to a scalar in the range [-1.0, 1.0].
28
- *
29
- * @param value SNORM value in the range [0, rangeMaximum]
30
- * @param [rangeMaximum=255] The maximum value in the SNORM range, 255 by default.
31
- * @returns Scalar in the range [-1.0, 1.0].
32
- *
33
- * @see CesiumMath.toSNorm
34
- */
35
- function fromSNorm(value, rangeMaximum = 255) {
36
- return ((0, core_1.clamp)(value, 0.0, rangeMaximum) / rangeMaximum) * 2.0 - 1.0;
37
- }
38
- /**
39
- * Converts a scalar value in the range [-1.0, 1.0] to a SNORM in the range [0, rangeMaximum].
40
- *
41
- * @param value The scalar value in the range [-1.0, 1.0]
42
- * @param [rangeMaximum=255] The maximum value in the mapped range, 255 by default.
43
- * @returns A SNORM value, where 0 maps to -1.0 and rangeMaximum maps to 1.0.
44
- *
45
- * @see CesiumMath.fromSNorm
46
- */
47
- function toSNorm(value, rangeMaximum = 255) {
48
- return Math.round(((0, core_1.clamp)(value, -1.0, 1.0) * 0.5 + 0.5) * rangeMaximum);
49
- }
50
- /**
51
- * Returns 1.0 if the given value is positive or zero, and -1.0 if it is negative.
52
- * This is similar to `Math.sign` except that returns 1.0 instead of
53
- * 0.0 when the input value is 0.0.
54
- *
55
- * @param value The value to return the sign of.
56
- * @returns The sign of value.
57
- */
58
- function signNotZero(value) {
59
- return value < 0.0 ? -1.0 : 1.0;
60
- }
61
- /**
62
- * Encodes a normalized vector into 2 SNORM values in the range of [0-rangeMax] following the 'oct' encoding.
63
- *
64
- * Oct encoding is a compact representation of unit length vectors.
65
- * The 'oct' encoding is described in "A Survey of Efficient Representations of Independent Unit Vectors",
66
- * Cigolle et al 2014: {@link http://jcgt.org/published/0003/02/01/}
67
- *
68
- * @param vector The normalized vector to be compressed into 2 component 'oct' encoding.
69
- * @param result The 2 component oct-encoded unit length vector.
70
- * @param rangeMax The maximum value of the SNORM range. The encoded vector is stored in log2(rangeMax+1) bits.
71
- * @returns The 2 component oct-encoded unit length vector.
72
- *
73
- * @exception vector must be normalized.
74
- *
75
- * @see octDecodeInRange
76
- */
77
- function octEncodeInRange(vector, rangeMax, result) {
78
- (0, assert_1.assert)(vector);
79
- (0, assert_1.assert)(result);
80
- const vector3 = scratchVector3.from(vector);
81
- (0, assert_1.assert)(Math.abs(vector3.magnitudeSquared() - 1.0) <= core_1._MathUtils.EPSILON6);
82
- result.x = vector.x / (Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z));
83
- result.y = vector.y / (Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z));
84
- if (vector.z < 0) {
85
- const x = result.x;
86
- const y = result.y;
87
- result.x = (1.0 - Math.abs(y)) * signNotZero(x);
88
- result.y = (1.0 - Math.abs(x)) * signNotZero(y);
89
- }
90
- result.x = toSNorm(result.x, rangeMax);
91
- result.y = toSNorm(result.y, rangeMax);
92
- return result;
93
- }
94
- exports.octEncodeInRange = octEncodeInRange;
95
- /**
96
- * Encodes a normalized vector into 2 SNORM values in the range of [0-255] following the 'oct' encoding.
97
- *
98
- * @param vector The normalized vector to be compressed into 2 byte 'oct' encoding.
99
- * @param result The 2 byte oct-encoded unit length vector.
100
- * @returns he 2 byte oct-encoded unit length vector.
101
- *
102
- * @exception vector must be normalized.
103
- *
104
- * @see octEncodeInRange
105
- * @see octDecode
106
- */
107
- function octEncode(vector, result) {
108
- return octEncodeInRange(vector, 255, result);
109
- }
110
- exports.octEncode = octEncode;
111
- /**
112
- * Encodes a normalized vector into 4-byte vector
113
- * @param vector The normalized vector to be compressed into 4 byte 'oct' encoding.
114
- * @param result The 4 byte oct-encoded unit length vector.
115
- * @returns The 4 byte oct-encoded unit length vector.
116
- *
117
- * @exception vector must be normalized.
118
- *
119
- * @see octEncodeInRange
120
- * @see octDecodeFromVector4
121
- */
122
- function octEncodeToVector4(vector, result) {
123
- octEncodeInRange(vector, 65535, octEncodeScratch);
124
- result.x = forceUint8(octEncodeScratch.x * RIGHT_SHIFT);
125
- result.y = forceUint8(octEncodeScratch.x);
126
- result.z = forceUint8(octEncodeScratch.y * RIGHT_SHIFT);
127
- result.w = forceUint8(octEncodeScratch.y);
128
- return result;
129
- }
130
- exports.octEncodeToVector4 = octEncodeToVector4;
131
- /**
132
- * Decodes a unit-length vector in 'oct' encoding to a normalized 3-component vector.
133
- *
134
- * @param x The x component of the oct-encoded unit length vector.
135
- * @param y The y component of the oct-encoded unit length vector.
136
- * @param rangeMax The maximum value of the SNORM range. The encoded vector is stored in log2(rangeMax+1) bits.
137
- * @param result The decoded and normalized vector
138
- * @returns The decoded and normalized vector.
139
- *
140
- * @exception x and y must be unsigned normalized integers between 0 and rangeMax.
141
- *
142
- * @see octEncodeInRange
143
- */
144
- function octDecodeInRange(x, y, rangeMax, result) {
145
- (0, assert_1.assert)(result);
146
- if (x < 0 || x > rangeMax || y < 0 || y > rangeMax) {
147
- throw new Error(`x and y must be unsigned normalized integers between 0 and ${rangeMax}`);
148
- }
149
- result.x = fromSNorm(x, rangeMax);
150
- result.y = fromSNorm(y, rangeMax);
151
- result.z = 1.0 - (Math.abs(result.x) + Math.abs(result.y));
152
- if (result.z < 0.0) {
153
- const oldVX = result.x;
154
- result.x = (1.0 - Math.abs(result.y)) * signNotZero(oldVX);
155
- result.y = (1.0 - Math.abs(oldVX)) * signNotZero(result.y);
156
- }
157
- return result.normalize();
158
- }
159
- exports.octDecodeInRange = octDecodeInRange;
160
- /**
161
- * Decodes a unit-length vector in 2 byte 'oct' encoding to a normalized 3-component vector.
162
- *
163
- * @param x The x component of the oct-encoded unit length vector.
164
- * @param y The y component of the oct-encoded unit length vector.
165
- * @param result The decoded and normalized vector.
166
- * @returns he decoded and normalized vector.
167
- *
168
- * @exception x and y must be an unsigned normalized integer between 0 and 255.
169
- *
170
- * @see octDecodeInRange
171
- */
172
- function octDecode(x, y, result) {
173
- return octDecodeInRange(x, y, 255, result);
174
- }
175
- exports.octDecode = octDecode;
176
- /**
177
- * Decodes a unit-length vector in 4 byte 'oct' encoding to a normalized 3-component vector.
178
- *
179
- * @param encoded The oct-encoded unit length vector.
180
- * @param esult The decoded and normalized vector.
181
- * @returns The decoded and normalized vector.
182
- *
183
- * @exception x, y, z, and w must be unsigned normalized integers between 0 and 255.
184
- *
185
- * @see octDecodeInRange
186
- * @see octEncodeToVector4
187
- */
188
- function octDecodeFromVector4(encoded, result) {
189
- (0, assert_1.assert)(encoded);
190
- (0, assert_1.assert)(result);
191
- const x = encoded.x;
192
- const y = encoded.y;
193
- const z = encoded.z;
194
- const w = encoded.w;
195
- if (x < 0 || x > 255 || y < 0 || y > 255 || z < 0 || z > 255 || w < 0 || w > 255) {
196
- throw new Error('x, y, z, and w must be unsigned normalized integers between 0 and 255');
197
- }
198
- const xOct16 = x * LEFT_SHIFT + y;
199
- const yOct16 = z * LEFT_SHIFT + w;
200
- return octDecodeInRange(xOct16, yOct16, 65535, result);
201
- }
202
- exports.octDecodeFromVector4 = octDecodeFromVector4;
203
- /**
204
- * Packs an oct encoded vector into a single floating-point number.
205
- *
206
- * @param encoded The oct encoded vector.
207
- * @returns The oct encoded vector packed into a single float.
208
- *
209
- */
210
- function octPackFloat(encoded) {
211
- const vector2 = scratchVector2.from(encoded);
212
- return 256.0 * vector2.x + vector2.y;
213
- }
214
- exports.octPackFloat = octPackFloat;
215
- /**
216
- * Encodes a normalized vector into 2 SNORM values in the range of [0-255] following the 'oct' encoding and
217
- * stores those values in a single float-point number.
218
- *
219
- * @param vector The normalized vector to be compressed into 2 byte 'oct' encoding.
220
- * @returns The 2 byte oct-encoded unit length vector.
221
- *
222
- * @exception vector must be normalized.
223
- */
224
- function octEncodeFloat(vector) {
225
- octEncode(vector, scratchEncodeVector2);
226
- return octPackFloat(scratchEncodeVector2);
227
- }
228
- exports.octEncodeFloat = octEncodeFloat;
229
- /**
230
- * Decodes a unit-length vector in 'oct' encoding packed in a floating-point number to a normalized 3-component vector.
231
- *
232
- * @param value The oct-encoded unit length vector stored as a single floating-point number.
233
- * @param result The decoded and normalized vector
234
- * @returns The decoded and normalized vector.
235
- *
236
- */
237
- function octDecodeFloat(value, result) {
238
- (0, assert_1.assert)(Number.isFinite(value));
239
- const temp = value / 256.0;
240
- const x = Math.floor(temp);
241
- const y = (temp - x) * 256.0;
242
- return octDecode(x, y, result);
243
- }
244
- exports.octDecodeFloat = octDecodeFloat;
245
- /**
246
- * Encodes three normalized vectors into 6 SNORM values in the range of [0-255] following the 'oct' encoding and
247
- * packs those into two floating-point numbers.
248
- *
249
- * @param v1 A normalized vector to be compressed.
250
- * @param v2 A normalized vector to be compressed.
251
- * @param v3 A normalized vector to be compressed.
252
- * @param result The 'oct' encoded vectors packed into two floating-point numbers.
253
- * @returns The 'oct' encoded vectors packed into two floating-point numbers.
254
- *
255
- */
256
- function octPack(v1, v2, v3, result) {
257
- (0, assert_1.assert)(v1);
258
- (0, assert_1.assert)(v2);
259
- (0, assert_1.assert)(v3);
260
- (0, assert_1.assert)(result);
261
- const encoded1 = octEncodeFloat(v1);
262
- const encoded2 = octEncodeFloat(v2);
263
- const encoded3 = octEncode(v3, scratchEncodeVector2);
264
- result.x = 65536.0 * encoded3.x + encoded1;
265
- result.y = 65536.0 * encoded3.y + encoded2;
266
- return result;
267
- }
268
- exports.octPack = octPack;
269
- /**
270
- * Decodes three unit-length vectors in 'oct' encoding packed into a floating-point number to a normalized 3-component vector.
271
- *
272
- * @param packed The three oct-encoded unit length vectors stored as two floating-point number.
273
- * @param v1 One decoded and normalized vector.
274
- * @param v2 One decoded and normalized vector.
275
- * @param v3 One decoded and normalized vector.
276
- */
277
- function octUnpack(packed, v1, v2, v3) {
278
- let temp = packed.x / 65536.0;
279
- const x = Math.floor(temp);
280
- const encodedFloat1 = (temp - x) * 65536.0;
281
- temp = packed.y / 65536.0;
282
- const y = Math.floor(temp);
283
- const encodedFloat2 = (temp - y) * 65536.0;
284
- octDecodeFloat(encodedFloat1, v1);
285
- octDecodeFloat(encodedFloat2, v2);
286
- octDecode(x, y, v3);
287
- }
288
- exports.octUnpack = octUnpack;
289
- /**
290
- * Pack texture coordinates into a single float. The texture coordinates will only preserve 12 bits of precision.
291
- *
292
- * @param textureCoordinates The texture coordinates to compress. Both coordinates must be in the range 0.0-1.0.
293
- * @returns The packed texture coordinates.
294
- *
295
- */
296
- function compressTextureCoordinates(textureCoordinates) {
297
- // Move x and y to the range 0-4095;
298
- const x = (textureCoordinates.x * 4095.0) | 0;
299
- const y = (textureCoordinates.y * 4095.0) | 0;
300
- return 4096.0 * x + y;
301
- }
302
- exports.compressTextureCoordinates = compressTextureCoordinates;
303
- /**
304
- * Decompresses texture coordinates that were packed into a single float.
305
- *
306
- * @param compressed The compressed texture coordinates.
307
- * @param result The decompressed texture coordinates.
308
- * @returns The modified result parameter.
309
- *
310
- */
311
- function decompressTextureCoordinates(compressed, result) {
312
- const temp = compressed / 4096.0;
313
- const xZeroTo4095 = Math.floor(temp);
314
- result.x = xZeroTo4095 / 4095.0;
315
- result.y = (compressed - xZeroTo4095 * 4096) / 4095;
316
- return result;
317
- }
318
- exports.decompressTextureCoordinates = decompressTextureCoordinates;
319
- /**
320
- * Decodes delta and ZigZag encoded vertices. This modifies the buffers in place.
321
- *
322
- * @param uBuffer The buffer view of u values.
323
- * @param vBuffer The buffer view of v values.
324
- * @param [heightBuffer] The buffer view of height values.
325
- *
326
- * @link https://github.com/AnalyticalGraphicsInc/quantized-mesh|quantized-mesh-1.0 terrain format
327
- */
328
- function zigZagDeltaDecode(uBuffer, vBuffer, heightBuffer) {
329
- (0, assert_1.assert)(uBuffer);
330
- (0, assert_1.assert)(vBuffer);
331
- (0, assert_1.assert)(uBuffer.length === vBuffer.length);
332
- if (heightBuffer) {
333
- (0, assert_1.assert)(uBuffer.length === heightBuffer.length);
334
- }
335
- function zigZagDecode(value) {
336
- return (value >> 1) ^ -(value & 1);
337
- }
338
- let u = 0;
339
- let v = 0;
340
- let height = 0;
341
- for (let i = 0; i < uBuffer.length; ++i) {
342
- u += zigZagDecode(uBuffer[i]);
343
- v += zigZagDecode(vBuffer[i]);
344
- uBuffer[i] = u;
345
- vBuffer[i] = v;
346
- if (heightBuffer) {
347
- height += zigZagDecode(heightBuffer[i]);
348
- heightBuffer[i] = height;
349
- }
350
- }
351
- }
352
- exports.zigZagDeltaDecode = zigZagDeltaDecode;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- // Subset of WebGL constants
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.GL = exports.GL_TYPE = exports.GL_PRIMITIVE_MODE = exports.GL_PRIMITIVE = void 0;
5
- exports.GL_PRIMITIVE = {
6
- POINTS: 0x0000,
7
- LINES: 0x0001,
8
- TRIANGLES: 0x0004 // Triangles. Each set of three vertices creates a separate triangle.
9
- };
10
- // Primitive modes
11
- exports.GL_PRIMITIVE_MODE = {
12
- POINTS: 0x0000,
13
- LINES: 0x0001,
14
- LINE_LOOP: 0x0002,
15
- LINE_STRIP: 0x0003,
16
- TRIANGLES: 0x0004,
17
- TRIANGLE_STRIP: 0x0005,
18
- TRIANGLE_FAN: 0x0006 // Triangles. A connected group of triangles.
19
- // Each vertex connects to the previous and the first vertex in the fan.
20
- };
21
- exports.GL_TYPE = {
22
- BYTE: 5120,
23
- UNSIGNED_BYTE: 5121,
24
- SHORT: 5122,
25
- UNSIGNED_SHORT: 5123,
26
- INT: 5124,
27
- UNSIGNED_INT: 5125,
28
- FLOAT: 5126,
29
- DOUBLE: 5130
30
- };
31
- exports.GL = {
32
- ...exports.GL_PRIMITIVE_MODE,
33
- ...exports.GL_TYPE
34
- };
@@ -1,112 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const constants_1 = require("../constants");
4
- const GL_TYPE_TO_ARRAY_TYPE = {
5
- [constants_1.GL_TYPE.DOUBLE]: Float64Array,
6
- [constants_1.GL_TYPE.FLOAT]: Float32Array,
7
- [constants_1.GL_TYPE.UNSIGNED_SHORT]: Uint16Array,
8
- [constants_1.GL_TYPE.UNSIGNED_INT]: Uint32Array,
9
- [constants_1.GL_TYPE.UNSIGNED_BYTE]: Uint8Array,
10
- [constants_1.GL_TYPE.BYTE]: Int8Array,
11
- [constants_1.GL_TYPE.SHORT]: Int16Array,
12
- [constants_1.GL_TYPE.INT]: Int32Array
13
- };
14
- const NAME_TO_GL_TYPE = {
15
- DOUBLE: constants_1.GL_TYPE.DOUBLE,
16
- FLOAT: constants_1.GL_TYPE.FLOAT,
17
- UNSIGNED_SHORT: constants_1.GL_TYPE.UNSIGNED_SHORT,
18
- UNSIGNED_INT: constants_1.GL_TYPE.UNSIGNED_INT,
19
- UNSIGNED_BYTE: constants_1.GL_TYPE.UNSIGNED_BYTE,
20
- BYTE: constants_1.GL_TYPE.BYTE,
21
- SHORT: constants_1.GL_TYPE.SHORT,
22
- INT: constants_1.GL_TYPE.INT
23
- };
24
- const ERR_TYPE_CONVERSION = 'Failed to convert GL type';
25
- // Converts TYPED ARRAYS to corresponding GL constant
26
- // Used to auto deduce gl parameter types
27
- class GLType {
28
- // Signature: fromTypedArray(new Uint8Array())
29
- // Signature: fromTypedArray(Uint8Array)
30
- /**
31
- * Returns the size, in bytes, of the corresponding datatype
32
- * @param arrayOrType
33
- * @returns glType a a string
34
- */
35
- static fromTypedArray(arrayOrType) {
36
- // If typed array, look up constructor
37
- arrayOrType = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
38
- for (const glType in GL_TYPE_TO_ARRAY_TYPE) {
39
- const ArrayType = GL_TYPE_TO_ARRAY_TYPE[glType];
40
- if (ArrayType === arrayOrType) {
41
- return glType;
42
- }
43
- }
44
- throw new Error(ERR_TYPE_CONVERSION);
45
- }
46
- /**
47
- * Extracts name for glType from array NAME_TO_GL_TYPE
48
- * @param name
49
- * @returns glType as a number
50
- */
51
- static fromName(name) {
52
- const glType = NAME_TO_GL_TYPE[name];
53
- if (!glType) {
54
- throw new Error(ERR_TYPE_CONVERSION);
55
- }
56
- return glType;
57
- }
58
- // Converts GL constant to corresponding typed array type
59
- // eslint-disable-next-line complexity
60
- static getArrayType(glType) {
61
- switch (glType) {
62
- /*eslint-disable*/
63
- // @ts-ignore
64
- case constants_1.GL_TYPE.UNSIGNED_SHORT_5_6_5:
65
- // @ts-ignore
66
- case constants_1.GL_TYPE.UNSIGNED_SHORT_4_4_4_4:
67
- // @ts-ignore
68
- case constants_1.GL_TYPE.UNSIGNED_SHORT_5_5_5_1:
69
- /* eslint-enable*/
70
- return Uint16Array;
71
- default:
72
- const ArrayType = GL_TYPE_TO_ARRAY_TYPE[glType];
73
- if (!ArrayType) {
74
- throw new Error(ERR_TYPE_CONVERSION);
75
- }
76
- return ArrayType;
77
- }
78
- }
79
- /**
80
- * Returns the size in bytes of one element of the provided WebGL type
81
- * @param glType
82
- * @returns size of glType
83
- */
84
- static getByteSize(glType) {
85
- const ArrayType = GLType.getArrayType(glType);
86
- return ArrayType.BYTES_PER_ELEMENT;
87
- }
88
- /**
89
- * Returns `true` if `glType` is a valid WebGL data type.
90
- * @param glType
91
- * @returns boolean
92
- */
93
- static validate(glType) {
94
- return Boolean(GLType.getArrayType(glType));
95
- }
96
- /**
97
- * Creates a typed view of an array of bytes
98
- * @param glType The type of typed array (ArrayBuffer view) to create
99
- * @param buffer The buffer storage to use for the view.
100
- * @param byteOffset The offset, in bytes, to the first element in the view
101
- * @param length The number of elements in the view. Defaults to buffer length
102
- * @returns A typed array view of the buffer
103
- */
104
- static createTypedArray(glType, buffer, byteOffset = 0, length) {
105
- if (length === undefined) {
106
- length = (buffer.byteLength - byteOffset) / GLType.getByteSize(glType);
107
- }
108
- const ArrayType = GLType.getArrayType(glType);
109
- return new ArrayType(buffer, byteOffset, length);
110
- }
111
- }
112
- exports.default = GLType;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * Checking if it is geometry
5
- * @param geometry
6
- */
7
- function isGeometry(geometry) {
8
- return (geometry &&
9
- typeof geometry === 'object' &&
10
- geometry.mode &&
11
- geometry.attributes &&
12
- typeof geometry.attributes === 'object');
13
- }
14
- exports.default = isGeometry;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeAttributeIterator = void 0;
4
- /**
5
- * Iterates over a single attribute
6
- * NOTE: For performance, re-yields the same modified element
7
- * @param param0
8
- */
9
- function* makeAttributeIterator(values, size) {
10
- const ArrayType = values.constructor;
11
- const element = new ArrayType(size);
12
- for (let i = 0; i < values.length; i += size) {
13
- for (let j = 0; j < size; j++) {
14
- element[j] = element[i + j];
15
- }
16
- yield element;
17
- }
18
- }
19
- exports.makeAttributeIterator = makeAttributeIterator;
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makePrimitiveIterator = void 0;
4
- const constants_1 = require("../constants");
5
- const modes_1 = require("../primitives/modes");
6
- const loader_utils_1 = require("@loaders.gl/loader-utils");
7
- /**
8
- * Will iterate over each primitive, expanding (dereferencing) indices
9
- * @param indices
10
- * @param attributes
11
- * @param mode
12
- * @param start
13
- * @param end
14
- */
15
- // eslint-disable-next-line complexity
16
- function* makePrimitiveIterator(indices, attributes = {}, mode, start = 0, end) {
17
- // support indices being an object with a values array
18
- if (indices) {
19
- indices = indices.values || indices.value || indices;
20
- }
21
- // Autodeduce length from indices
22
- if (end === undefined) {
23
- end = indices ? indices.length : start;
24
- }
25
- // iteration info
26
- const info = {
27
- attributes,
28
- type: (0, modes_1.getPrimitiveModeType)(mode),
29
- i1: 0,
30
- i2: 0,
31
- i3: 0
32
- };
33
- let i = start;
34
- // @ts-ignore
35
- while (i < end) {
36
- switch (mode) {
37
- case constants_1.GL.POINTS: // draw single points.
38
- info.i1 = i;
39
- i += 1;
40
- break;
41
- case constants_1.GL.LINES: // draw lines. Each set of two vertices is treated as a separate line segment.
42
- info.i1 = i;
43
- info.i2 = i + 1;
44
- i += 2;
45
- break;
46
- case constants_1.GL.LINE_STRIP: // draw lines. Each vertex connects to the one after it.
47
- info.i1 = i;
48
- info.i2 = i + 1;
49
- i += 1;
50
- break;
51
- case constants_1.GL.LINE_LOOP: // draw a connected group of line segments from the first vertex to the last
52
- info.i1 = i;
53
- info.i2 = i + 1;
54
- i += 1;
55
- break;
56
- case constants_1.GL.TRIANGLES: // draw triangles. Each set of three vertices creates a separate triangle.
57
- info.i1 = i;
58
- info.i2 = i + 1;
59
- info.i3 = i + 2;
60
- i += 3;
61
- break;
62
- case constants_1.GL.TRIANGLE_STRIP: // draw a connected group of triangles.
63
- info.i1 = i;
64
- info.i2 = i + 1;
65
- i += 1;
66
- break;
67
- case constants_1.GL.TRIANGLE_FAN: // draw a connected group of triangles.
68
- info.i1 = 1;
69
- info.i2 = i;
70
- info.i3 = i + 1;
71
- i += 1;
72
- break;
73
- default:
74
- (0, loader_utils_1.assert)(false);
75
- }
76
- // if indices are present, lookup actual vertices in indices
77
- if (indices) {
78
- if ('i1' in info) {
79
- info.i1 = indices[info.i1];
80
- info.i2 = indices[info.i2];
81
- info.i3 = indices[info.i3];
82
- }
83
- }
84
- // @ts-ignore
85
- yield info;
86
- }
87
- }
88
- exports.makePrimitiveIterator = makePrimitiveIterator;
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPrimitiveModeExpandedLength = exports.isPrimitiveModeExpandable = exports.getPrimitiveModeType = void 0;
4
- const constants_1 = require("../constants");
5
- /**
6
- * Different methods of working with geometries depending on glType
7
- /**
8
-
9
- /**
10
- * @param mode
11
- * @returns draw points | lines | triangles
12
- */
13
- function getPrimitiveModeType(mode) {
14
- switch (mode) {
15
- case constants_1.GL.POINTS: // draw single points.
16
- return constants_1.GL.POINTS;
17
- case constants_1.GL.LINES: // draw lines. Each set of two vertices is treated as a separate line segment.
18
- case constants_1.GL.LINE_STRIP: // draw lines. Each vertex connects to the one after it.
19
- case constants_1.GL.LINE_LOOP: // draw a connected group of line segments from the first vertex to the last
20
- return constants_1.GL.LINES;
21
- case constants_1.GL.TRIANGLES:
22
- case constants_1.GL.TRIANGLE_STRIP:
23
- case constants_1.GL.TRIANGLE_FAN: // draw a connected group of triangles.
24
- return constants_1.GL.TRIANGLES;
25
- default:
26
- throw new Error('Unknown primitive mode');
27
- }
28
- }
29
- exports.getPrimitiveModeType = getPrimitiveModeType;
30
- /**
31
- * @param mode
32
- * @returns true | false
33
- */
34
- function isPrimitiveModeExpandable(mode) {
35
- switch (mode) {
36
- case constants_1.GL.LINE_STRIP: // draw lines. Each vertex connects to the one after it.
37
- case constants_1.GL.LINE_LOOP: // draw a connected group of line segments from the first vertex to the last
38
- case constants_1.GL.TRIANGLE_STRIP: // draw a connected group of triangles.
39
- case constants_1.GL.TRIANGLE_FAN: // draw a connected group of triangles.
40
- return true;
41
- default:
42
- return false;
43
- }
44
- }
45
- exports.isPrimitiveModeExpandable = isPrimitiveModeExpandable;
46
- /**
47
- * Returns new length depends on glType
48
- * @param mode
49
- * @param length
50
- * @returns new length
51
- */
52
- function getPrimitiveModeExpandedLength(mode, length) {
53
- switch (mode) {
54
- case constants_1.GL.POINTS: // draw single points.
55
- return length;
56
- case constants_1.GL.LINES: // draw lines. Each set of two vertices is treated as a separate line segment.
57
- return length;
58
- case constants_1.GL.LINE_STRIP: // draw lines. Each vertex connects to the one after it.
59
- return length;
60
- case constants_1.GL.LINE_LOOP: // draw a connected group of line segments from the first vertex to the last
61
- return length + 1;
62
- case constants_1.GL.TRIANGLES: // draw triangles. Each set of three vertices creates a separate triangle.
63
- return length;
64
- case constants_1.GL.TRIANGLE_STRIP: // draw a connected group of triangles.
65
- case constants_1.GL.TRIANGLE_FAN: // draw a connected group of triangles.
66
- return (length - 2) * 3;
67
- default:
68
- throw new Error('Unknown length');
69
- }
70
- }
71
- exports.getPrimitiveModeExpandedLength = getPrimitiveModeExpandedLength;