@loaders.gl/math 3.1.3 → 4.0.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.
Files changed (117) hide show
  1. package/dist/geometry/attributes/compute-bounding-box.js +27 -41
  2. package/dist/geometry/attributes/compute-bounding-box.js.map +1 -0
  3. package/dist/geometry/attributes/compute-bounding-sphere.js +1 -29
  4. package/dist/{es5/geometry → geometry}/attributes/compute-bounding-sphere.js.map +0 -0
  5. package/dist/geometry/attributes/compute-tangents.js +1 -145
  6. package/dist/{es5/geometry → geometry}/attributes/compute-tangents.js.map +0 -0
  7. package/dist/geometry/attributes/compute-vertex-normals.js +42 -47
  8. package/dist/geometry/attributes/compute-vertex-normals.js.map +1 -0
  9. package/dist/geometry/attributes/convert-to-non-indexed.js +30 -31
  10. package/dist/geometry/attributes/convert-to-non-indexed.js.map +1 -0
  11. package/dist/geometry/attributes/get-attribute-from-geometry.js +26 -33
  12. package/dist/geometry/attributes/get-attribute-from-geometry.js.map +1 -0
  13. package/dist/geometry/attributes/normalize.js +11 -19
  14. package/dist/geometry/attributes/normalize.js.map +1 -0
  15. package/dist/geometry/colors/rgb565.js +14 -29
  16. package/dist/geometry/colors/rgb565.js.map +1 -0
  17. package/dist/geometry/compression/attribute-compression.js +162 -339
  18. package/dist/geometry/compression/attribute-compression.js.map +1 -0
  19. package/dist/geometry/constants.js +24 -30
  20. package/dist/geometry/constants.js.map +1 -0
  21. package/dist/geometry/gl/gl-type.js +74 -101
  22. package/dist/geometry/gl/gl-type.js.map +1 -0
  23. package/dist/geometry/is-geometry.js +3 -13
  24. package/dist/geometry/is-geometry.js.map +1 -0
  25. package/dist/geometry/iterators/attribute-iterator.js +11 -17
  26. package/dist/geometry/iterators/attribute-iterator.js.map +1 -0
  27. package/dist/geometry/iterators/primitive-iterator.js +79 -85
  28. package/dist/geometry/iterators/primitive-iterator.js.map +1 -0
  29. package/dist/geometry/primitives/modes.js +54 -67
  30. package/dist/{es5/geometry → geometry}/primitives/modes.js.map +1 -1
  31. package/dist/geometry/typed-arrays/typed-array-utils.js +20 -23
  32. package/dist/geometry/typed-arrays/typed-array-utils.js.map +1 -0
  33. package/dist/geometry/types.js +2 -2
  34. package/dist/{es5/geometry → geometry}/types.js.map +0 -0
  35. package/dist/geometry/utils/assert.js +5 -13
  36. package/dist/geometry/utils/assert.js.map +1 -0
  37. package/dist/index.js +11 -46
  38. package/dist/index.js.map +1 -0
  39. package/dist/utils/assert.js +5 -11
  40. package/dist/utils/assert.js.map +1 -0
  41. package/package.json +6 -6
  42. package/dist/es5/geometry/attributes/compute-bounding-box.js +0 -56
  43. package/dist/es5/geometry/attributes/compute-bounding-box.js.map +0 -1
  44. package/dist/es5/geometry/attributes/compute-bounding-sphere.js +0 -2
  45. package/dist/es5/geometry/attributes/compute-tangents.js +0 -2
  46. package/dist/es5/geometry/attributes/compute-vertex-normals.js +0 -71
  47. package/dist/es5/geometry/attributes/compute-vertex-normals.js.map +0 -1
  48. package/dist/es5/geometry/attributes/convert-to-non-indexed.js +0 -54
  49. package/dist/es5/geometry/attributes/convert-to-non-indexed.js.map +0 -1
  50. package/dist/es5/geometry/attributes/get-attribute-from-geometry.js +0 -36
  51. package/dist/es5/geometry/attributes/get-attribute-from-geometry.js.map +0 -1
  52. package/dist/es5/geometry/attributes/normalize.js +0 -21
  53. package/dist/es5/geometry/attributes/normalize.js.map +0 -1
  54. package/dist/es5/geometry/colors/rgb565.js +0 -26
  55. package/dist/es5/geometry/colors/rgb565.js.map +0 -1
  56. package/dist/es5/geometry/compression/attribute-compression.js +0 -212
  57. package/dist/es5/geometry/compression/attribute-compression.js.map +0 -1
  58. package/dist/es5/geometry/constants.js +0 -47
  59. package/dist/es5/geometry/constants.js.map +0 -1
  60. package/dist/es5/geometry/gl/gl-type.js +0 -112
  61. package/dist/es5/geometry/gl/gl-type.js.map +0 -1
  62. package/dist/es5/geometry/is-geometry.js +0 -15
  63. package/dist/es5/geometry/is-geometry.js.map +0 -1
  64. package/dist/es5/geometry/iterators/attribute-iterator.js +0 -49
  65. package/dist/es5/geometry/iterators/attribute-iterator.js.map +0 -1
  66. package/dist/es5/geometry/iterators/primitive-iterator.js +0 -133
  67. package/dist/es5/geometry/iterators/primitive-iterator.js.map +0 -1
  68. package/dist/es5/geometry/primitives/modes.js +0 -70
  69. package/dist/es5/geometry/typed-arrays/typed-array-utils.js +0 -30
  70. package/dist/es5/geometry/typed-arrays/typed-array-utils.js.map +0 -1
  71. package/dist/es5/geometry/types.js +0 -2
  72. package/dist/es5/geometry/utils/assert.js +0 -13
  73. package/dist/es5/geometry/utils/assert.js.map +0 -1
  74. package/dist/es5/index.js +0 -170
  75. package/dist/es5/index.js.map +0 -1
  76. package/dist/es5/utils/assert.js +0 -13
  77. package/dist/es5/utils/assert.js.map +0 -1
  78. package/dist/esm/geometry/attributes/compute-bounding-box.js +0 -30
  79. package/dist/esm/geometry/attributes/compute-bounding-box.js.map +0 -1
  80. package/dist/esm/geometry/attributes/compute-bounding-sphere.js +0 -2
  81. package/dist/esm/geometry/attributes/compute-bounding-sphere.js.map +0 -1
  82. package/dist/esm/geometry/attributes/compute-tangents.js +0 -2
  83. package/dist/esm/geometry/attributes/compute-tangents.js.map +0 -1
  84. package/dist/esm/geometry/attributes/compute-vertex-normals.js +0 -43
  85. package/dist/esm/geometry/attributes/compute-vertex-normals.js.map +0 -1
  86. package/dist/esm/geometry/attributes/convert-to-non-indexed.js +0 -32
  87. package/dist/esm/geometry/attributes/convert-to-non-indexed.js.map +0 -1
  88. package/dist/esm/geometry/attributes/get-attribute-from-geometry.js +0 -27
  89. package/dist/esm/geometry/attributes/get-attribute-from-geometry.js.map +0 -1
  90. package/dist/esm/geometry/attributes/normalize.js +0 -12
  91. package/dist/esm/geometry/attributes/normalize.js.map +0 -1
  92. package/dist/esm/geometry/colors/rgb565.js +0 -16
  93. package/dist/esm/geometry/colors/rgb565.js.map +0 -1
  94. package/dist/esm/geometry/compression/attribute-compression.js +0 -175
  95. package/dist/esm/geometry/compression/attribute-compression.js.map +0 -1
  96. package/dist/esm/geometry/constants.js +0 -28
  97. package/dist/esm/geometry/constants.js.map +0 -1
  98. package/dist/esm/geometry/gl/gl-type.js +0 -85
  99. package/dist/esm/geometry/gl/gl-type.js.map +0 -1
  100. package/dist/esm/geometry/is-geometry.js +0 -4
  101. package/dist/esm/geometry/is-geometry.js.map +0 -1
  102. package/dist/esm/geometry/iterators/attribute-iterator.js +0 -13
  103. package/dist/esm/geometry/iterators/attribute-iterator.js.map +0 -1
  104. package/dist/esm/geometry/iterators/primitive-iterator.js +0 -82
  105. package/dist/esm/geometry/iterators/primitive-iterator.js.map +0 -1
  106. package/dist/esm/geometry/primitives/modes.js +0 -58
  107. package/dist/esm/geometry/primitives/modes.js.map +0 -1
  108. package/dist/esm/geometry/typed-arrays/typed-array-utils.js +0 -22
  109. package/dist/esm/geometry/typed-arrays/typed-array-utils.js.map +0 -1
  110. package/dist/esm/geometry/types.js +0 -2
  111. package/dist/esm/geometry/types.js.map +0 -1
  112. package/dist/esm/geometry/utils/assert.js +0 -6
  113. package/dist/esm/geometry/utils/assert.js.map +0 -1
  114. package/dist/esm/index.js +0 -11
  115. package/dist/esm/index.js.map +0 -1
  116. package/dist/esm/utils/assert.js +0 -6
  117. package/dist/esm/utils/assert.js.map +0 -1
@@ -1,352 +1,175 @@
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");
1
+ import { Vector2, Vector3, clamp, _MathUtils } from '@math.gl/core';
2
+ import { assert } from '../utils/assert';
9
3
  const RIGHT_SHIFT = 1.0 / 256.0;
10
4
  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();
5
+ const scratchVector2 = new Vector2();
6
+ const scratchVector3 = new Vector3();
7
+ const scratchEncodeVector2 = new Vector2();
8
+ const octEncodeScratch = new Vector2();
15
9
  const uint8ForceArray = new Uint8Array(1);
16
- /**
17
- * Force a value to Uint8
18
- *
19
- * @param value
20
- * @returns
21
- */
10
+
22
11
  function forceUint8(value) {
23
- uint8ForceArray[0] = value;
24
- return uint8ForceArray[0];
12
+ uint8ForceArray[0] = value;
13
+ return uint8ForceArray[0];
25
14
  }
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
- */
15
+
35
16
  function fromSNorm(value, rangeMaximum = 255) {
36
- return ((0, core_1.clamp)(value, 0.0, rangeMaximum) / rangeMaximum) * 2.0 - 1.0;
17
+ return clamp(value, 0.0, rangeMaximum) / rangeMaximum * 2.0 - 1.0;
37
18
  }
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
- */
19
+
47
20
  function toSNorm(value, rangeMaximum = 255) {
48
- return Math.round(((0, core_1.clamp)(value, -1.0, 1.0) * 0.5 + 0.5) * rangeMaximum);
21
+ return Math.round((clamp(value, -1.0, 1.0) * 0.5 + 0.5) * rangeMaximum);
49
22
  }
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
- */
23
+
58
24
  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);
25
+ return value < 0.0 ? -1.0 : 1.0;
26
+ }
27
+
28
+ export function octEncodeInRange(vector, rangeMax, result) {
29
+ assert(vector);
30
+ assert(result);
31
+ const vector3 = scratchVector3.from(vector);
32
+ assert(Math.abs(vector3.magnitudeSquared() - 1.0) <= _MathUtils.EPSILON6);
33
+ result.x = vector.x / (Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z));
34
+ result.y = vector.y / (Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z));
35
+
36
+ if (vector.z < 0) {
37
+ const x = result.x;
38
+ const y = result.y;
39
+ result.x = (1.0 - Math.abs(y)) * signNotZero(x);
40
+ result.y = (1.0 - Math.abs(x)) * signNotZero(y);
41
+ }
42
+
43
+ result.x = toSNorm(result.x, rangeMax);
44
+ result.y = toSNorm(result.y, rangeMax);
45
+ return result;
46
+ }
47
+ export function octEncode(vector, result) {
48
+ return octEncodeInRange(vector, 255, result);
49
+ }
50
+ export function octEncodeToVector4(vector, result) {
51
+ octEncodeInRange(vector, 65535, octEncodeScratch);
52
+ result.x = forceUint8(octEncodeScratch.x * RIGHT_SHIFT);
53
+ result.y = forceUint8(octEncodeScratch.x);
54
+ result.z = forceUint8(octEncodeScratch.y * RIGHT_SHIFT);
55
+ result.w = forceUint8(octEncodeScratch.y);
56
+ return result;
57
+ }
58
+ export function octDecodeInRange(x, y, rangeMax, result) {
59
+ assert(result);
60
+
61
+ if (x < 0 || x > rangeMax || y < 0 || y > rangeMax) {
62
+ throw new Error("x and y must be unsigned normalized integers between 0 and ".concat(rangeMax));
63
+ }
64
+
65
+ result.x = fromSNorm(x, rangeMax);
66
+ result.y = fromSNorm(y, rangeMax);
67
+ result.z = 1.0 - (Math.abs(result.x) + Math.abs(result.y));
68
+
69
+ if (result.z < 0.0) {
70
+ const oldVX = result.x;
71
+ result.x = (1.0 - Math.abs(result.y)) * signNotZero(oldVX);
72
+ result.y = (1.0 - Math.abs(oldVX)) * signNotZero(result.y);
73
+ }
74
+
75
+ return result.normalize();
76
+ }
77
+ export function octDecode(x, y, result) {
78
+ return octDecodeInRange(x, y, 255, result);
79
+ }
80
+ export function octDecodeFromVector4(encoded, result) {
81
+ assert(encoded);
82
+ assert(result);
83
+ const x = encoded.x;
84
+ const y = encoded.y;
85
+ const z = encoded.z;
86
+ const w = encoded.w;
87
+
88
+ if (x < 0 || x > 255 || y < 0 || y > 255 || z < 0 || z > 255 || w < 0 || w > 255) {
89
+ throw new Error('x, y, z, and w must be unsigned normalized integers between 0 and 255');
90
+ }
91
+
92
+ const xOct16 = x * LEFT_SHIFT + y;
93
+ const yOct16 = z * LEFT_SHIFT + w;
94
+ return octDecodeInRange(xOct16, yOct16, 65535, result);
95
+ }
96
+ export function octPackFloat(encoded) {
97
+ const vector2 = scratchVector2.from(encoded);
98
+ return 256.0 * vector2.x + vector2.y;
99
+ }
100
+ export function octEncodeFloat(vector) {
101
+ octEncode(vector, scratchEncodeVector2);
102
+ return octPackFloat(scratchEncodeVector2);
103
+ }
104
+ export function octDecodeFloat(value, result) {
105
+ assert(Number.isFinite(value));
106
+ const temp = value / 256.0;
107
+ const x = Math.floor(temp);
108
+ const y = (temp - x) * 256.0;
109
+ return octDecode(x, y, result);
110
+ }
111
+ export function octPack(v1, v2, v3, result) {
112
+ assert(v1);
113
+ assert(v2);
114
+ assert(v3);
115
+ assert(result);
116
+ const encoded1 = octEncodeFloat(v1);
117
+ const encoded2 = octEncodeFloat(v2);
118
+ const encoded3 = octEncode(v3, scratchEncodeVector2);
119
+ result.x = 65536.0 * encoded3.x + encoded1;
120
+ result.y = 65536.0 * encoded3.y + encoded2;
121
+ return result;
122
+ }
123
+ export function octUnpack(packed, v1, v2, v3) {
124
+ let temp = packed.x / 65536.0;
125
+ const x = Math.floor(temp);
126
+ const encodedFloat1 = (temp - x) * 65536.0;
127
+ temp = packed.y / 65536.0;
128
+ const y = Math.floor(temp);
129
+ const encodedFloat2 = (temp - y) * 65536.0;
130
+ octDecodeFloat(encodedFloat1, v1);
131
+ octDecodeFloat(encodedFloat2, v2);
132
+ octDecode(x, y, v3);
133
+ }
134
+ export function compressTextureCoordinates(textureCoordinates) {
135
+ const x = textureCoordinates.x * 4095.0 | 0;
136
+ const y = textureCoordinates.y * 4095.0 | 0;
137
+ return 4096.0 * x + y;
138
+ }
139
+ export function decompressTextureCoordinates(compressed, result) {
140
+ const temp = compressed / 4096.0;
141
+ const xZeroTo4095 = Math.floor(temp);
142
+ result.x = xZeroTo4095 / 4095.0;
143
+ result.y = (compressed - xZeroTo4095 * 4096) / 4095;
144
+ return result;
145
+ }
146
+ export function zigZagDeltaDecode(uBuffer, vBuffer, heightBuffer) {
147
+ assert(uBuffer);
148
+ assert(vBuffer);
149
+ assert(uBuffer.length === vBuffer.length);
150
+
151
+ if (heightBuffer) {
152
+ assert(uBuffer.length === heightBuffer.length);
153
+ }
154
+
155
+ function zigZagDecode(value) {
156
+ return value >> 1 ^ -(value & 1);
157
+ }
158
+
159
+ let u = 0;
160
+ let v = 0;
161
+ let height = 0;
162
+
163
+ for (let i = 0; i < uBuffer.length; ++i) {
164
+ u += zigZagDecode(uBuffer[i]);
165
+ v += zigZagDecode(vBuffer[i]);
166
+ uBuffer[i] = u;
167
+ vBuffer[i] = v;
168
+
332
169
  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
- }
170
+ height += zigZagDecode(heightBuffer[i]);
171
+ heightBuffer[i] = height;
350
172
  }
173
+ }
351
174
  }
352
- exports.zigZagDeltaDecode = zigZagDeltaDecode;
175
+ //# sourceMappingURL=attribute-compression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/geometry/compression/attribute-compression.ts"],"names":["Vector2","Vector3","clamp","_MathUtils","assert","RIGHT_SHIFT","LEFT_SHIFT","scratchVector2","scratchVector3","scratchEncodeVector2","octEncodeScratch","uint8ForceArray","Uint8Array","forceUint8","value","fromSNorm","rangeMaximum","toSNorm","Math","round","signNotZero","octEncodeInRange","vector","rangeMax","result","vector3","from","abs","magnitudeSquared","EPSILON6","x","y","z","octEncode","octEncodeToVector4","w","octDecodeInRange","Error","oldVX","normalize","octDecode","octDecodeFromVector4","encoded","xOct16","yOct16","octPackFloat","vector2","octEncodeFloat","octDecodeFloat","Number","isFinite","temp","floor","octPack","v1","v2","v3","encoded1","encoded2","encoded3","octUnpack","packed","encodedFloat1","encodedFloat2","compressTextureCoordinates","textureCoordinates","decompressTextureCoordinates","compressed","xZeroTo4095","zigZagDeltaDecode","uBuffer","vBuffer","heightBuffer","length","zigZagDecode","u","v","height","i"],"mappings":"AAKA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,KAA1B,EAAiCC,UAAjC,QAAkD,eAAlD;AAEA,SAAQC,MAAR,QAAqB,iBAArB;AAEA,MAAMC,WAAW,G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AM,IAAIH,YAAY,CAACF,YAAY,CAACM,CAAD,CAAb,CAAtB;AACAN,MAAAA,YAAY,CAACM,CAAD,CAAZ,GAAkBD,MAAlB;AACD;AACF;AACF","sourcesContent":["// This file is derived from the Cesium code base under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n// Attribute compression and decompression functions.\n\nimport {Vector2, Vector3, clamp, _MathUtils} from '@math.gl/core';\nimport {Vector4} from '../types';\nimport {assert} from '../utils/assert';\n\nconst RIGHT_SHIFT = 1.0 / 256.0;\nconst LEFT_SHIFT = 256.0;\n\nconst scratchVector2 = new Vector2();\nconst scratchVector3 = new Vector3();\nconst scratchEncodeVector2 = new Vector2();\nconst octEncodeScratch = new Vector2();\n\nconst uint8ForceArray = new Uint8Array(1);\n\n/**\n * Force a value to Uint8\n *\n * @param value\n * @returns\n */\nfunction forceUint8(value: number): number {\n uint8ForceArray[0] = value;\n return uint8ForceArray[0];\n}\n\n/**\n * Converts a SNORM value in the range [0, rangeMaximum] to a scalar in the range [-1.0, 1.0].\n *\n * @param value SNORM value in the range [0, rangeMaximum]\n * @param [rangeMaximum=255] The maximum value in the SNORM range, 255 by default.\n * @returns Scalar in the range [-1.0, 1.0].\n *\n * @see CesiumMath.toSNorm\n */\nfunction fromSNorm(value: number, rangeMaximum = 255): number {\n return (clamp(value, 0.0, rangeMaximum) / rangeMaximum) * 2.0 - 1.0;\n}\n\n/**\n * Converts a scalar value in the range [-1.0, 1.0] to a SNORM in the range [0, rangeMaximum].\n *\n * @param value The scalar value in the range [-1.0, 1.0]\n * @param [rangeMaximum=255] The maximum value in the mapped range, 255 by default.\n * @returns A SNORM value, where 0 maps to -1.0 and rangeMaximum maps to 1.0.\n *\n * @see CesiumMath.fromSNorm\n */\nfunction toSNorm(value: number, rangeMaximum = 255): number {\n return Math.round((clamp(value, -1.0, 1.0) * 0.5 + 0.5) * rangeMaximum);\n}\n\n/**\n * Returns 1.0 if the given value is positive or zero, and -1.0 if it is negative.\n * This is similar to `Math.sign` except that returns 1.0 instead of\n * 0.0 when the input value is 0.0.\n *\n * @param value The value to return the sign of.\n * @returns The sign of value.\n */\nfunction signNotZero(value: number): number {\n return value < 0.0 ? -1.0 : 1.0;\n}\n\n/**\n * Encodes a normalized vector into 2 SNORM values in the range of [0-rangeMax] following the 'oct' encoding.\n *\n * Oct encoding is a compact representation of unit length vectors.\n * The 'oct' encoding is described in \"A Survey of Efficient Representations of Independent Unit Vectors\",\n * Cigolle et al 2014: {@link http://jcgt.org/published/0003/02/01/}\n *\n * @param vector The normalized vector to be compressed into 2 component 'oct' encoding.\n * @param result The 2 component oct-encoded unit length vector.\n * @param rangeMax The maximum value of the SNORM range. The encoded vector is stored in log2(rangeMax+1) bits.\n * @returns The 2 component oct-encoded unit length vector.\n *\n * @exception vector must be normalized.\n *\n * @see octDecodeInRange\n */\nexport function octEncodeInRange(vector: Vector3, rangeMax: number, result: Vector2): Vector2 {\n assert(vector);\n assert(result);\n\n const vector3 = scratchVector3.from(vector);\n\n assert(Math.abs(vector3.magnitudeSquared() - 1.0) <= _MathUtils.EPSILON6);\n\n result.x = vector.x / (Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z));\n result.y = vector.y / (Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z));\n\n if (vector.z < 0) {\n const x = result.x;\n const y = result.y;\n result.x = (1.0 - Math.abs(y)) * signNotZero(x);\n result.y = (1.0 - Math.abs(x)) * signNotZero(y);\n }\n\n result.x = toSNorm(result.x, rangeMax);\n result.y = toSNorm(result.y, rangeMax);\n\n return result;\n}\n\n/**\n * Encodes a normalized vector into 2 SNORM values in the range of [0-255] following the 'oct' encoding.\n *\n * @param vector The normalized vector to be compressed into 2 byte 'oct' encoding.\n * @param result The 2 byte oct-encoded unit length vector.\n * @returns he 2 byte oct-encoded unit length vector.\n *\n * @exception vector must be normalized.\n *\n * @see octEncodeInRange\n * @see octDecode\n */\nexport function octEncode(vector: Vector3, result: Vector2): Vector2 {\n return octEncodeInRange(vector, 255, result);\n}\n\n/**\n * Encodes a normalized vector into 4-byte vector\n * @param vector The normalized vector to be compressed into 4 byte 'oct' encoding.\n * @param result The 4 byte oct-encoded unit length vector.\n * @returns The 4 byte oct-encoded unit length vector.\n *\n * @exception vector must be normalized.\n *\n * @see octEncodeInRange\n * @see octDecodeFromVector4\n */\nexport function octEncodeToVector4(vector: Vector3, result: Vector4): Vector4 {\n octEncodeInRange(vector, 65535, octEncodeScratch);\n result.x = forceUint8(octEncodeScratch.x * RIGHT_SHIFT);\n result.y = forceUint8(octEncodeScratch.x);\n result.z = forceUint8(octEncodeScratch.y * RIGHT_SHIFT);\n result.w = forceUint8(octEncodeScratch.y);\n return result;\n}\n\n/**\n * Decodes a unit-length vector in 'oct' encoding to a normalized 3-component vector.\n *\n * @param x The x component of the oct-encoded unit length vector.\n * @param y The y component of the oct-encoded unit length vector.\n * @param rangeMax The maximum value of the SNORM range. The encoded vector is stored in log2(rangeMax+1) bits.\n * @param result The decoded and normalized vector\n * @returns The decoded and normalized vector.\n *\n * @exception x and y must be unsigned normalized integers between 0 and rangeMax.\n *\n * @see octEncodeInRange\n */\nexport function octDecodeInRange(x: number, y: number, rangeMax: number, result: Vector3): Vector3 {\n assert(result);\n if (x < 0 || x > rangeMax || y < 0 || y > rangeMax) {\n throw new Error(`x and y must be unsigned normalized integers between 0 and ${rangeMax}`);\n }\n\n result.x = fromSNorm(x, rangeMax);\n result.y = fromSNorm(y, rangeMax);\n result.z = 1.0 - (Math.abs(result.x) + Math.abs(result.y));\n\n if (result.z < 0.0) {\n const oldVX = result.x;\n result.x = (1.0 - Math.abs(result.y)) * signNotZero(oldVX);\n result.y = (1.0 - Math.abs(oldVX)) * signNotZero(result.y);\n }\n\n return result.normalize();\n}\n\n/**\n * Decodes a unit-length vector in 2 byte 'oct' encoding to a normalized 3-component vector.\n *\n * @param x The x component of the oct-encoded unit length vector.\n * @param y The y component of the oct-encoded unit length vector.\n * @param result The decoded and normalized vector.\n * @returns he decoded and normalized vector.\n *\n * @exception x and y must be an unsigned normalized integer between 0 and 255.\n *\n * @see octDecodeInRange\n */\nexport function octDecode(x: number, y: number, result: Vector3): Vector3 {\n return octDecodeInRange(x, y, 255, result);\n}\n\n/**\n * Decodes a unit-length vector in 4 byte 'oct' encoding to a normalized 3-component vector.\n *\n * @param encoded The oct-encoded unit length vector.\n * @param esult The decoded and normalized vector.\n * @returns The decoded and normalized vector.\n *\n * @exception x, y, z, and w must be unsigned normalized integers between 0 and 255.\n *\n * @see octDecodeInRange\n * @see octEncodeToVector4\n */\nexport function octDecodeFromVector4(encoded: Vector4, result: Vector3): Vector3 {\n assert(encoded);\n assert(result);\n const x = encoded.x;\n const y = encoded.y;\n const z = encoded.z;\n const w = encoded.w;\n\n if (x < 0 || x > 255 || y < 0 || y > 255 || z < 0 || z > 255 || w < 0 || w > 255) {\n throw new Error('x, y, z, and w must be unsigned normalized integers between 0 and 255');\n }\n\n const xOct16 = x * LEFT_SHIFT + y;\n const yOct16 = z * LEFT_SHIFT + w;\n return octDecodeInRange(xOct16, yOct16, 65535, result);\n}\n\n/**\n * Packs an oct encoded vector into a single floating-point number.\n *\n * @param encoded The oct encoded vector.\n * @returns The oct encoded vector packed into a single float.\n *\n */\nexport function octPackFloat(encoded: Vector2): number {\n const vector2 = scratchVector2.from(encoded);\n return 256.0 * vector2.x + vector2.y;\n}\n\n/**\n * Encodes a normalized vector into 2 SNORM values in the range of [0-255] following the 'oct' encoding and\n * stores those values in a single float-point number.\n *\n * @param vector The normalized vector to be compressed into 2 byte 'oct' encoding.\n * @returns The 2 byte oct-encoded unit length vector.\n *\n * @exception vector must be normalized.\n */\nexport function octEncodeFloat(vector: Vector3): number {\n octEncode(vector, scratchEncodeVector2);\n return octPackFloat(scratchEncodeVector2);\n}\n\n/**\n * Decodes a unit-length vector in 'oct' encoding packed in a floating-point number to a normalized 3-component vector.\n *\n * @param value The oct-encoded unit length vector stored as a single floating-point number.\n * @param result The decoded and normalized vector\n * @returns The decoded and normalized vector.\n *\n */\nexport function octDecodeFloat(value: number, result: Vector3): Vector3 {\n assert(Number.isFinite(value));\n\n const temp = value / 256.0;\n const x = Math.floor(temp);\n const y = (temp - x) * 256.0;\n\n return octDecode(x, y, result);\n}\n\n/**\n * Encodes three normalized vectors into 6 SNORM values in the range of [0-255] following the 'oct' encoding and\n * packs those into two floating-point numbers.\n *\n * @param v1 A normalized vector to be compressed.\n * @param v2 A normalized vector to be compressed.\n * @param v3 A normalized vector to be compressed.\n * @param result The 'oct' encoded vectors packed into two floating-point numbers.\n * @returns The 'oct' encoded vectors packed into two floating-point numbers.\n *\n */\nexport function octPack(v1: Vector3, v2: Vector3, v3: Vector3, result: Vector2): Vector2 {\n assert(v1);\n assert(v2);\n assert(v3);\n assert(result);\n\n const encoded1 = octEncodeFloat(v1);\n const encoded2 = octEncodeFloat(v2);\n\n const encoded3 = octEncode(v3, scratchEncodeVector2);\n result.x = 65536.0 * encoded3.x + encoded1;\n result.y = 65536.0 * encoded3.y + encoded2;\n return result;\n}\n\n/**\n * Decodes three unit-length vectors in 'oct' encoding packed into a floating-point number to a normalized 3-component vector.\n *\n * @param packed The three oct-encoded unit length vectors stored as two floating-point number.\n * @param v1 One decoded and normalized vector.\n * @param v2 One decoded and normalized vector.\n * @param v3 One decoded and normalized vector.\n */\nexport function octUnpack(packed: Vector2, v1: Vector3, v2: Vector3, v3: Vector3): void {\n let temp = packed.x / 65536.0;\n const x = Math.floor(temp);\n const encodedFloat1 = (temp - x) * 65536.0;\n\n temp = packed.y / 65536.0;\n const y = Math.floor(temp);\n const encodedFloat2 = (temp - y) * 65536.0;\n\n octDecodeFloat(encodedFloat1, v1);\n octDecodeFloat(encodedFloat2, v2);\n octDecode(x, y, v3);\n}\n\n/**\n * Pack texture coordinates into a single float. The texture coordinates will only preserve 12 bits of precision.\n *\n * @param textureCoordinates The texture coordinates to compress. Both coordinates must be in the range 0.0-1.0.\n * @returns The packed texture coordinates.\n *\n */\nexport function compressTextureCoordinates(textureCoordinates: Vector2): number {\n // Move x and y to the range 0-4095;\n const x = (textureCoordinates.x * 4095.0) | 0;\n const y = (textureCoordinates.y * 4095.0) | 0;\n return 4096.0 * x + y;\n}\n\n/**\n * Decompresses texture coordinates that were packed into a single float.\n *\n * @param compressed The compressed texture coordinates.\n * @param result The decompressed texture coordinates.\n * @returns The modified result parameter.\n *\n */\nexport function decompressTextureCoordinates(compressed: number, result: Vector2): Vector2 {\n const temp = compressed / 4096.0;\n const xZeroTo4095 = Math.floor(temp);\n result.x = xZeroTo4095 / 4095.0;\n result.y = (compressed - xZeroTo4095 * 4096) / 4095;\n return result;\n}\n\n/**\n * Decodes delta and ZigZag encoded vertices. This modifies the buffers in place.\n *\n * @param uBuffer The buffer view of u values.\n * @param vBuffer The buffer view of v values.\n * @param [heightBuffer] The buffer view of height values.\n *\n * @link https://github.com/AnalyticalGraphicsInc/quantized-mesh|quantized-mesh-1.0 terrain format\n */\nexport function zigZagDeltaDecode(\n uBuffer: Uint16Array,\n vBuffer: Uint16Array,\n heightBuffer?: Uint16Array | number[]\n) {\n assert(uBuffer);\n assert(vBuffer);\n assert(uBuffer.length === vBuffer.length);\n if (heightBuffer) {\n assert(uBuffer.length === heightBuffer.length);\n }\n\n function zigZagDecode(value: number) {\n return (value >> 1) ^ -(value & 1);\n }\n\n let u = 0;\n let v = 0;\n let height = 0;\n\n for (let i = 0; i < uBuffer.length; ++i) {\n u += zigZagDecode(uBuffer[i]);\n v += zigZagDecode(vBuffer[i]);\n\n uBuffer[i] = u;\n vBuffer[i] = v;\n\n if (heightBuffer) {\n height += zigZagDecode(heightBuffer[i]);\n heightBuffer[i] = height;\n }\n }\n}\n"],"file":"attribute-compression.js"}
@@ -1,34 +1,28 @@
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.
1
+ export const GL_PRIMITIVE = {
2
+ POINTS: 0x0000,
3
+ LINES: 0x0001,
4
+ TRIANGLES: 0x0004
9
5
  };
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.
6
+ export const GL_PRIMITIVE_MODE = {
7
+ POINTS: 0x0000,
8
+ LINES: 0x0001,
9
+ LINE_LOOP: 0x0002,
10
+ LINE_STRIP: 0x0003,
11
+ TRIANGLES: 0x0004,
12
+ TRIANGLE_STRIP: 0x0005,
13
+ TRIANGLE_FAN: 0x0006
20
14
  };
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
15
+ export const GL_TYPE = {
16
+ BYTE: 5120,
17
+ UNSIGNED_BYTE: 5121,
18
+ SHORT: 5122,
19
+ UNSIGNED_SHORT: 5123,
20
+ INT: 5124,
21
+ UNSIGNED_INT: 5125,
22
+ FLOAT: 5126,
23
+ DOUBLE: 5130
30
24
  };
31
- exports.GL = {
32
- ...exports.GL_PRIMITIVE_MODE,
33
- ...exports.GL_TYPE
25
+ export const GL = { ...GL_PRIMITIVE_MODE,
26
+ ...GL_TYPE
34
27
  };
28
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/geometry/constants.ts"],"names":["GL_PRIMITIVE","POINTS","LINES","TRIANGLES","GL_PRIMITIVE_MODE","LINE_LOOP","LINE_STRIP","TRIANGLE_STRIP","TRIANGLE_FAN","GL_TYPE","BYTE","UNSIGNED_BYTE","SHORT","UNSIGNED_SHORT","INT","UNSIGNED_INT","FLOAT","DOUBLE","GL"],"mappings":"AAEA,OAAO,MAAMA,YAAY,GAAG;AAC1BC,EAAAA,MAAM,EAAE,MADkB;AAE1BC,EAAAA,KAAK,EAAE,MAFmB;AAG1BC,EAAAA,SAAS,EAAE;AAHe,CAArB;AAOP,OAAO,MAAMC,iBAAiB,GAAG;AAC/BH,EAAAA,MAAM,EAAE,MADuB;AAE/BC,EAAAA,KAAK,EAAE,MAFwB;AAG/BG,EAAAA,SAAS,EAAE,MAHoB;AAI/BC,EAAAA,UAAU,EAAE,MAJmB;AAK/BH,EAAAA,SAAS,EAAE,MALoB;AAM/BI,EAAAA,cAAc,EAAE,MANe;AAO/BC,EAAAA,YAAY,EAAE;AAPiB,CAA1B;AAsBP,OAAO,MAAMC,OAAe,GAAG;AAC7BC,EAAAA,IAAI,EAAE,IADuB;AAE7BC,EAAAA,aAAa,EAAE,IAFc;AAG7BC,EAAAA,KAAK,EAAE,IAHsB;AAI7BC,EAAAA,cAAc,EAAE,IAJa;AAK7BC,EAAAA,GAAG,EAAE,IALwB;AAM7BC,EAAAA,YAAY,EAAE,IANe;AAO7BC,EAAAA,KAAK,EAAE,IAPsB;AAQ7BC,EAAAA,MAAM,EAAE;AARqB,CAAxB;AAWP,OAAO,MAAMC,EAAE,GAAG,EAChB,GAAGd,iBADa;AAEhB,KAAGK;AAFa,CAAX","sourcesContent":["// Subset of WebGL constants\n\nexport const GL_PRIMITIVE = {\n POINTS: 0x0000, // Points. single points.\n LINES: 0x0001, // Lines. Each vertex connects to the one after it.\n TRIANGLES: 0x0004 // Triangles. Each set of three vertices creates a separate triangle.\n};\n\n// Primitive modes\nexport const GL_PRIMITIVE_MODE = {\n POINTS: 0x0000, // Points. single points.\n LINES: 0x0001, // Lines. Each vertex connects to the one after it.\n LINE_LOOP: 0x0002, // Lines. Each set of two vertices is treated as a separate line segment.\n LINE_STRIP: 0x0003, // Lines/ a connected group of line segments from the first vertex to the last\n TRIANGLES: 0x0004, // Triangles. Each set of three vertices creates a separate triangle.\n TRIANGLE_STRIP: 0x0005, // Triangles. A connected group of triangles.\n TRIANGLE_FAN: 0x0006 // Triangles. A connected group of triangles.\n // Each vertex connects to the previous and the first vertex in the fan.\n};\n\ntype glType = {\n BYTE: number;\n UNSIGNED_BYTE: number;\n SHORT: number;\n UNSIGNED_SHORT: number;\n INT: number;\n UNSIGNED_INT: number;\n FLOAT: number;\n DOUBLE: number;\n};\n\nexport const GL_TYPE: glType = {\n BYTE: 5120,\n UNSIGNED_BYTE: 5121,\n SHORT: 5122,\n UNSIGNED_SHORT: 5123,\n INT: 5124,\n UNSIGNED_INT: 5125,\n FLOAT: 5126,\n DOUBLE: 5130\n};\n\nexport const GL = {\n ...GL_PRIMITIVE_MODE,\n ...GL_TYPE\n};\n"],"file":"constants.js"}