@loaders.gl/math 4.0.0-beta.1 → 4.0.0-beta.3
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/dist/{esm/geometry → geometry}/attributes/compute-bounding-box.js +2 -2
- package/dist/geometry/attributes/compute-bounding-box.js.map +1 -0
- package/dist/geometry/attributes/compute-bounding-sphere.js.map +1 -0
- package/dist/geometry/attributes/compute-tangents.js.map +1 -0
- package/dist/{esm/geometry → geometry}/attributes/compute-vertex-normals.js +5 -5
- package/dist/geometry/attributes/compute-vertex-normals.js.map +1 -0
- package/dist/geometry/attributes/convert-to-non-indexed.js.map +1 -0
- package/dist/{esm/geometry → geometry}/attributes/get-attribute-from-geometry.js +2 -2
- package/dist/geometry/attributes/get-attribute-from-geometry.js.map +1 -0
- package/dist/geometry/attributes/normalize.js.map +1 -0
- package/dist/geometry/colors/rgb565.js.map +1 -0
- package/dist/{esm/geometry → geometry}/compression/attribute-compression.js +2 -2
- package/dist/geometry/compression/attribute-compression.js.map +1 -0
- package/dist/geometry/constants.js.map +1 -0
- package/dist/{esm/geometry → geometry}/gl/gl-type.js +1 -1
- package/dist/{es5/geometry → geometry}/gl/gl-type.js.map +1 -1
- package/dist/geometry/is-geometry.js.map +1 -0
- package/dist/geometry/iterators/attribute-iterator.js.map +1 -0
- package/dist/{esm/geometry → geometry}/iterators/primitive-iterator.js +2 -2
- package/dist/geometry/iterators/primitive-iterator.js.map +1 -0
- package/dist/{esm/geometry → geometry}/primitives/modes.js +1 -1
- package/dist/geometry/primitives/modes.js.map +1 -0
- package/dist/geometry/typed-arrays/typed-array-utils.js.map +1 -0
- package/dist/geometry/utils/assert.js +6 -0
- package/dist/geometry/utils/assert.js.map +1 -0
- package/dist/geometry/utils/coordinates.js.map +1 -0
- package/dist/index.cjs +545 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/assert.js.map +1 -0
- package/package.json +15 -7
- package/src/index.ts +0 -2
- package/dist/es5/geometry/attributes/compute-bounding-box.js +0 -46
- package/dist/es5/geometry/attributes/compute-bounding-box.js.map +0 -1
- package/dist/es5/geometry/attributes/compute-bounding-sphere.js +0 -2
- package/dist/es5/geometry/attributes/compute-bounding-sphere.js.map +0 -1
- package/dist/es5/geometry/attributes/compute-tangents.js +0 -2
- package/dist/es5/geometry/attributes/compute-tangents.js.map +0 -1
- package/dist/es5/geometry/attributes/compute-vertex-normals.js +0 -56
- package/dist/es5/geometry/attributes/compute-vertex-normals.js.map +0 -1
- package/dist/es5/geometry/attributes/convert-to-non-indexed.js +0 -43
- package/dist/es5/geometry/attributes/convert-to-non-indexed.js.map +0 -1
- package/dist/es5/geometry/attributes/get-attribute-from-geometry.js +0 -29
- package/dist/es5/geometry/attributes/get-attribute-from-geometry.js.map +0 -1
- package/dist/es5/geometry/attributes/normalize.js +0 -19
- package/dist/es5/geometry/attributes/normalize.js.map +0 -1
- package/dist/es5/geometry/colors/rgb565.js +0 -24
- package/dist/es5/geometry/colors/rgb565.js.map +0 -1
- package/dist/es5/geometry/compression/attribute-compression.js +0 -178
- package/dist/es5/geometry/compression/attribute-compression.js.map +0 -1
- package/dist/es5/geometry/constants.js +0 -40
- package/dist/es5/geometry/constants.js.map +0 -1
- package/dist/es5/geometry/gl/gl-type.js +0 -92
- package/dist/es5/geometry/is-geometry.js +0 -12
- package/dist/es5/geometry/is-geometry.js.map +0 -1
- package/dist/es5/geometry/iterators/attribute-iterator.js +0 -38
- package/dist/es5/geometry/iterators/attribute-iterator.js.map +0 -1
- package/dist/es5/geometry/iterators/primitive-iterator.js +0 -102
- package/dist/es5/geometry/iterators/primitive-iterator.js.map +0 -1
- package/dist/es5/geometry/primitives/modes.js +0 -56
- package/dist/es5/geometry/primitives/modes.js.map +0 -1
- package/dist/es5/geometry/typed-arrays/typed-array-utils.js +0 -24
- package/dist/es5/geometry/typed-arrays/typed-array-utils.js.map +0 -1
- package/dist/es5/geometry/utils/assert.js +0 -12
- package/dist/es5/geometry/utils/assert.js.map +0 -1
- package/dist/es5/geometry/utils/coordinates.js +0 -10
- package/dist/es5/geometry/utils/coordinates.js.map +0 -1
- package/dist/es5/index.js +0 -167
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/utils/assert.js +0 -12
- package/dist/es5/utils/assert.js.map +0 -1
- package/dist/esm/geometry/attributes/compute-bounding-box.js.map +0 -1
- package/dist/esm/geometry/attributes/compute-bounding-sphere.js.map +0 -1
- package/dist/esm/geometry/attributes/compute-tangents.js.map +0 -1
- package/dist/esm/geometry/attributes/compute-vertex-normals.js.map +0 -1
- package/dist/esm/geometry/attributes/convert-to-non-indexed.js.map +0 -1
- package/dist/esm/geometry/attributes/get-attribute-from-geometry.js.map +0 -1
- package/dist/esm/geometry/attributes/normalize.js.map +0 -1
- package/dist/esm/geometry/colors/rgb565.js.map +0 -1
- package/dist/esm/geometry/compression/attribute-compression.js.map +0 -1
- package/dist/esm/geometry/constants.js.map +0 -1
- package/dist/esm/geometry/gl/gl-type.js.map +0 -1
- package/dist/esm/geometry/is-geometry.js.map +0 -1
- package/dist/esm/geometry/iterators/attribute-iterator.js.map +0 -1
- package/dist/esm/geometry/iterators/primitive-iterator.js.map +0 -1
- package/dist/esm/geometry/primitives/modes.js.map +0 -1
- package/dist/esm/geometry/typed-arrays/typed-array-utils.js.map +0 -1
- package/dist/esm/geometry/utils/assert.js +0 -6
- package/dist/esm/geometry/utils/assert.js.map +0 -1
- package/dist/esm/geometry/utils/coordinates.js.map +0 -1
- package/dist/esm/index.js +0 -12
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/utils/assert.js.map +0 -1
- /package/dist/{esm/geometry → geometry}/attributes/compute-bounding-sphere.js +0 -0
- /package/dist/{esm/geometry → geometry}/attributes/compute-tangents.js +0 -0
- /package/dist/{esm/geometry → geometry}/attributes/convert-to-non-indexed.js +0 -0
- /package/dist/{esm/geometry → geometry}/attributes/normalize.js +0 -0
- /package/dist/{esm/geometry → geometry}/colors/rgb565.js +0 -0
- /package/dist/{esm/geometry → geometry}/constants.js +0 -0
- /package/dist/{esm/geometry → geometry}/is-geometry.js +0 -0
- /package/dist/{esm/geometry → geometry}/iterators/attribute-iterator.js +0 -0
- /package/dist/{esm/geometry → geometry}/typed-arrays/typed-array-utils.js +0 -0
- /package/dist/{esm/geometry → geometry}/utils/coordinates.js +0 -0
- /package/dist/{esm/utils → utils}/assert.js +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
GL: () => GL,
|
|
24
|
+
GLType: () => GLType,
|
|
25
|
+
GL_TYPE: () => GL_TYPE,
|
|
26
|
+
compressTextureCoordinates: () => compressTextureCoordinates,
|
|
27
|
+
computeVertexNormals: () => computeVertexNormals,
|
|
28
|
+
concatTypedArrays: () => concatTypedArrays,
|
|
29
|
+
decodeRGB565: () => decodeRGB565,
|
|
30
|
+
decompressTextureCoordinates: () => decompressTextureCoordinates,
|
|
31
|
+
emod: () => emod,
|
|
32
|
+
encodeRGB565: () => encodeRGB565,
|
|
33
|
+
isGeometry: () => isGeometry,
|
|
34
|
+
makeAttributeIterator: () => makeAttributeIterator,
|
|
35
|
+
makePrimitiveIterator: () => makePrimitiveIterator,
|
|
36
|
+
octDecode: () => octDecode,
|
|
37
|
+
octDecodeFloat: () => octDecodeFloat,
|
|
38
|
+
octDecodeFromVector4: () => octDecodeFromVector4,
|
|
39
|
+
octDecodeInRange: () => octDecodeInRange,
|
|
40
|
+
octEncode: () => octEncode,
|
|
41
|
+
octEncodeFloat: () => octEncodeFloat,
|
|
42
|
+
octEncodeInRange: () => octEncodeInRange,
|
|
43
|
+
octEncodeToVector4: () => octEncodeToVector4,
|
|
44
|
+
octPack: () => octPack,
|
|
45
|
+
octPackFloat: () => octPackFloat,
|
|
46
|
+
octUnpack: () => octUnpack,
|
|
47
|
+
zigZagDeltaDecode: () => zigZagDeltaDecode
|
|
48
|
+
});
|
|
49
|
+
module.exports = __toCommonJS(src_exports);
|
|
50
|
+
|
|
51
|
+
// src/geometry/constants.ts
|
|
52
|
+
var GL_PRIMITIVE_MODE = {
|
|
53
|
+
POINTS: 0,
|
|
54
|
+
// Points. single points.
|
|
55
|
+
LINES: 1,
|
|
56
|
+
// Lines. Each vertex connects to the one after it.
|
|
57
|
+
LINE_LOOP: 2,
|
|
58
|
+
// Lines. Each set of two vertices is treated as a separate line segment.
|
|
59
|
+
LINE_STRIP: 3,
|
|
60
|
+
// Lines/ a connected group of line segments from the first vertex to the last
|
|
61
|
+
TRIANGLES: 4,
|
|
62
|
+
// Triangles. Each set of three vertices creates a separate triangle.
|
|
63
|
+
TRIANGLE_STRIP: 5,
|
|
64
|
+
// Triangles. A connected group of triangles.
|
|
65
|
+
TRIANGLE_FAN: 6
|
|
66
|
+
// Triangles. A connected group of triangles.
|
|
67
|
+
// Each vertex connects to the previous and the first vertex in the fan.
|
|
68
|
+
};
|
|
69
|
+
var GL_TYPE = {
|
|
70
|
+
BYTE: 5120,
|
|
71
|
+
UNSIGNED_BYTE: 5121,
|
|
72
|
+
SHORT: 5122,
|
|
73
|
+
UNSIGNED_SHORT: 5123,
|
|
74
|
+
INT: 5124,
|
|
75
|
+
UNSIGNED_INT: 5125,
|
|
76
|
+
FLOAT: 5126,
|
|
77
|
+
DOUBLE: 5130
|
|
78
|
+
};
|
|
79
|
+
var GL = {
|
|
80
|
+
...GL_PRIMITIVE_MODE,
|
|
81
|
+
...GL_TYPE
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/geometry/gl/gl-type.ts
|
|
85
|
+
var GL_TYPE_TO_ARRAY_TYPE = {
|
|
86
|
+
[GL_TYPE.DOUBLE]: Float64Array,
|
|
87
|
+
[GL_TYPE.FLOAT]: Float32Array,
|
|
88
|
+
[GL_TYPE.UNSIGNED_SHORT]: Uint16Array,
|
|
89
|
+
[GL_TYPE.UNSIGNED_INT]: Uint32Array,
|
|
90
|
+
[GL_TYPE.UNSIGNED_BYTE]: Uint8Array,
|
|
91
|
+
[GL_TYPE.BYTE]: Int8Array,
|
|
92
|
+
[GL_TYPE.SHORT]: Int16Array,
|
|
93
|
+
[GL_TYPE.INT]: Int32Array
|
|
94
|
+
};
|
|
95
|
+
var NAME_TO_GL_TYPE = {
|
|
96
|
+
DOUBLE: GL_TYPE.DOUBLE,
|
|
97
|
+
FLOAT: GL_TYPE.FLOAT,
|
|
98
|
+
UNSIGNED_SHORT: GL_TYPE.UNSIGNED_SHORT,
|
|
99
|
+
UNSIGNED_INT: GL_TYPE.UNSIGNED_INT,
|
|
100
|
+
UNSIGNED_BYTE: GL_TYPE.UNSIGNED_BYTE,
|
|
101
|
+
BYTE: GL_TYPE.BYTE,
|
|
102
|
+
SHORT: GL_TYPE.SHORT,
|
|
103
|
+
INT: GL_TYPE.INT
|
|
104
|
+
};
|
|
105
|
+
var ERR_TYPE_CONVERSION = "Failed to convert GL type";
|
|
106
|
+
var GLType = class {
|
|
107
|
+
// Signature: fromTypedArray(new Uint8Array())
|
|
108
|
+
// Signature: fromTypedArray(Uint8Array)
|
|
109
|
+
/**
|
|
110
|
+
* Returns the size, in bytes, of the corresponding datatype
|
|
111
|
+
* @param arrayOrType
|
|
112
|
+
* @returns glType a a string
|
|
113
|
+
*/
|
|
114
|
+
static fromTypedArray(arrayOrType) {
|
|
115
|
+
arrayOrType = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
|
|
116
|
+
for (const glType in GL_TYPE_TO_ARRAY_TYPE) {
|
|
117
|
+
const ArrayType = GL_TYPE_TO_ARRAY_TYPE[glType];
|
|
118
|
+
if (ArrayType === arrayOrType) {
|
|
119
|
+
return glType;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
throw new Error(ERR_TYPE_CONVERSION);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Extracts name for glType from array NAME_TO_GL_TYPE
|
|
126
|
+
* @param name
|
|
127
|
+
* @returns glType as a number
|
|
128
|
+
*/
|
|
129
|
+
static fromName(name) {
|
|
130
|
+
const glType = NAME_TO_GL_TYPE[name];
|
|
131
|
+
if (!glType) {
|
|
132
|
+
throw new Error(ERR_TYPE_CONVERSION);
|
|
133
|
+
}
|
|
134
|
+
return glType;
|
|
135
|
+
}
|
|
136
|
+
// Converts GL constant to corresponding typed array type
|
|
137
|
+
// eslint-disable-next-line complexity
|
|
138
|
+
static getArrayType(glType) {
|
|
139
|
+
switch (glType) {
|
|
140
|
+
case GL_TYPE.UNSIGNED_SHORT_5_6_5:
|
|
141
|
+
case GL_TYPE.UNSIGNED_SHORT_4_4_4_4:
|
|
142
|
+
case GL_TYPE.UNSIGNED_SHORT_5_5_5_1:
|
|
143
|
+
return Uint16Array;
|
|
144
|
+
default:
|
|
145
|
+
const ArrayType = GL_TYPE_TO_ARRAY_TYPE[glType];
|
|
146
|
+
if (!ArrayType) {
|
|
147
|
+
throw new Error(ERR_TYPE_CONVERSION);
|
|
148
|
+
}
|
|
149
|
+
return ArrayType;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Returns the size in bytes of one element of the provided WebGL type
|
|
154
|
+
* @param glType
|
|
155
|
+
* @returns size of glType
|
|
156
|
+
*/
|
|
157
|
+
static getByteSize(glType) {
|
|
158
|
+
const ArrayType = GLType.getArrayType(glType);
|
|
159
|
+
return ArrayType.BYTES_PER_ELEMENT;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Returns `true` if `glType` is a valid WebGL data type.
|
|
163
|
+
* @param glType
|
|
164
|
+
* @returns boolean
|
|
165
|
+
*/
|
|
166
|
+
static validate(glType) {
|
|
167
|
+
return Boolean(GLType.getArrayType(glType));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Creates a typed view of an array of bytes
|
|
171
|
+
* @param glType The type of typed array (ArrayBuffer view) to create
|
|
172
|
+
* @param buffer The buffer storage to use for the view.
|
|
173
|
+
* @param byteOffset The offset, in bytes, to the first element in the view
|
|
174
|
+
* @param length The number of elements in the view. Defaults to buffer length
|
|
175
|
+
* @returns A typed array view of the buffer
|
|
176
|
+
*/
|
|
177
|
+
static createTypedArray(glType, buffer, byteOffset = 0, length) {
|
|
178
|
+
if (length === void 0) {
|
|
179
|
+
length = (buffer.byteLength - byteOffset) / GLType.getByteSize(glType);
|
|
180
|
+
}
|
|
181
|
+
const ArrayType = GLType.getArrayType(glType);
|
|
182
|
+
return new ArrayType(buffer, byteOffset, length);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// src/geometry/is-geometry.ts
|
|
187
|
+
function isGeometry(geometry) {
|
|
188
|
+
return geometry && typeof geometry === "object" && geometry.mode && geometry.attributes && typeof geometry.attributes === "object";
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/geometry/iterators/attribute-iterator.ts
|
|
192
|
+
function* makeAttributeIterator(values, size) {
|
|
193
|
+
const ArrayType = values.constructor;
|
|
194
|
+
const element = new ArrayType(size);
|
|
195
|
+
for (let i = 0; i < values.length; i += size) {
|
|
196
|
+
for (let j = 0; j < size; j++) {
|
|
197
|
+
element[j] = element[i + j];
|
|
198
|
+
}
|
|
199
|
+
yield element;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/geometry/primitives/modes.ts
|
|
204
|
+
function getPrimitiveModeType(mode) {
|
|
205
|
+
switch (mode) {
|
|
206
|
+
case GL.POINTS:
|
|
207
|
+
return GL.POINTS;
|
|
208
|
+
case GL.LINES:
|
|
209
|
+
case GL.LINE_STRIP:
|
|
210
|
+
case GL.LINE_LOOP:
|
|
211
|
+
return GL.LINES;
|
|
212
|
+
case GL.TRIANGLES:
|
|
213
|
+
case GL.TRIANGLE_STRIP:
|
|
214
|
+
case GL.TRIANGLE_FAN:
|
|
215
|
+
return GL.TRIANGLES;
|
|
216
|
+
default:
|
|
217
|
+
throw new Error("Unknown primitive mode");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/geometry/iterators/primitive-iterator.ts
|
|
222
|
+
var import_loader_utils = require("@loaders.gl/loader-utils");
|
|
223
|
+
function* makePrimitiveIterator(indices, attributes = {}, mode, start = 0, end) {
|
|
224
|
+
if (indices) {
|
|
225
|
+
indices = indices.values || indices.value || indices;
|
|
226
|
+
}
|
|
227
|
+
if (end === void 0) {
|
|
228
|
+
end = indices ? indices.length : start;
|
|
229
|
+
}
|
|
230
|
+
const info = {
|
|
231
|
+
attributes,
|
|
232
|
+
type: getPrimitiveModeType(mode),
|
|
233
|
+
i1: 0,
|
|
234
|
+
i2: 0,
|
|
235
|
+
i3: 0
|
|
236
|
+
};
|
|
237
|
+
let i = start;
|
|
238
|
+
while (i < end) {
|
|
239
|
+
switch (mode) {
|
|
240
|
+
case GL.POINTS:
|
|
241
|
+
info.i1 = i;
|
|
242
|
+
i += 1;
|
|
243
|
+
break;
|
|
244
|
+
case GL.LINES:
|
|
245
|
+
info.i1 = i;
|
|
246
|
+
info.i2 = i + 1;
|
|
247
|
+
i += 2;
|
|
248
|
+
break;
|
|
249
|
+
case GL.LINE_STRIP:
|
|
250
|
+
info.i1 = i;
|
|
251
|
+
info.i2 = i + 1;
|
|
252
|
+
i += 1;
|
|
253
|
+
break;
|
|
254
|
+
case GL.LINE_LOOP:
|
|
255
|
+
info.i1 = i;
|
|
256
|
+
info.i2 = i + 1;
|
|
257
|
+
i += 1;
|
|
258
|
+
break;
|
|
259
|
+
case GL.TRIANGLES:
|
|
260
|
+
info.i1 = i;
|
|
261
|
+
info.i2 = i + 1;
|
|
262
|
+
info.i3 = i + 2;
|
|
263
|
+
i += 3;
|
|
264
|
+
break;
|
|
265
|
+
case GL.TRIANGLE_STRIP:
|
|
266
|
+
info.i1 = i;
|
|
267
|
+
info.i2 = i + 1;
|
|
268
|
+
i += 1;
|
|
269
|
+
break;
|
|
270
|
+
case GL.TRIANGLE_FAN:
|
|
271
|
+
info.i1 = 1;
|
|
272
|
+
info.i2 = i;
|
|
273
|
+
info.i3 = i + 1;
|
|
274
|
+
i += 1;
|
|
275
|
+
break;
|
|
276
|
+
default:
|
|
277
|
+
(0, import_loader_utils.assert)(false);
|
|
278
|
+
}
|
|
279
|
+
if (indices) {
|
|
280
|
+
if ("i1" in info) {
|
|
281
|
+
info.i1 = indices[info.i1];
|
|
282
|
+
info.i2 = indices[info.i2];
|
|
283
|
+
info.i3 = indices[info.i3];
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
yield info;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// src/geometry/attributes/compute-vertex-normals.ts
|
|
291
|
+
var import_core = require("@math.gl/core");
|
|
292
|
+
|
|
293
|
+
// src/geometry/utils/assert.ts
|
|
294
|
+
function assert2(condition, message) {
|
|
295
|
+
if (!condition) {
|
|
296
|
+
throw new Error(`math.gl assertion failed. ${message}`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// src/geometry/attributes/get-attribute-from-geometry.ts
|
|
301
|
+
function getPositions(geometry) {
|
|
302
|
+
if (isGeometry(geometry)) {
|
|
303
|
+
const { attributes } = geometry;
|
|
304
|
+
const position = attributes.POSITION || attributes.positions;
|
|
305
|
+
assert2(position);
|
|
306
|
+
return position;
|
|
307
|
+
}
|
|
308
|
+
if (ArrayBuffer.isView(geometry)) {
|
|
309
|
+
return { values: geometry, size: 3 };
|
|
310
|
+
}
|
|
311
|
+
if (geometry) {
|
|
312
|
+
assert2(geometry.values);
|
|
313
|
+
return geometry;
|
|
314
|
+
}
|
|
315
|
+
return assert2(false);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// src/geometry/attributes/compute-vertex-normals.ts
|
|
319
|
+
function computeVertexNormals(geometry) {
|
|
320
|
+
assert2(getPrimitiveModeType(geometry.mode) === GL.TRIANGLES, "TRIANGLES required");
|
|
321
|
+
const { values: positions } = getPositions(geometry);
|
|
322
|
+
const normals = new Float32Array(positions.length);
|
|
323
|
+
const vectorA = new import_core.Vector3();
|
|
324
|
+
const vectorB = new import_core.Vector3();
|
|
325
|
+
const vectorC = new import_core.Vector3();
|
|
326
|
+
const vectorCB = new import_core.Vector3();
|
|
327
|
+
const vectorAB = new import_core.Vector3();
|
|
328
|
+
for (const primitive of makePrimitiveIterator(geometry)) {
|
|
329
|
+
vectorA.fromArray(positions, primitive.i1 * 3);
|
|
330
|
+
vectorB.fromArray(positions, primitive.i2 * 3 + 3);
|
|
331
|
+
vectorC.fromArray(positions, primitive.i3 * 3 + 6);
|
|
332
|
+
vectorCB.subVectors(vectorC, vectorB);
|
|
333
|
+
vectorAB.subVectors(vectorA, vectorB);
|
|
334
|
+
const normal = vectorCB.cross(vectorAB);
|
|
335
|
+
normal.normalize();
|
|
336
|
+
const { primitiveIndex } = primitive;
|
|
337
|
+
normals[primitiveIndex * 9 + 0] = normal.x;
|
|
338
|
+
normals[primitiveIndex * 9 + 1] = normal.y;
|
|
339
|
+
normals[primitiveIndex * 9 + 2] = normal.z;
|
|
340
|
+
normals[primitiveIndex * 9 + 3] = normal.x;
|
|
341
|
+
normals[primitiveIndex * 9 + 4] = normal.y;
|
|
342
|
+
normals[primitiveIndex * 9 + 5] = normal.z;
|
|
343
|
+
normals[primitiveIndex * 9 + 6] = normal.x;
|
|
344
|
+
normals[primitiveIndex * 9 + 7] = normal.y;
|
|
345
|
+
normals[primitiveIndex * 9 + 8] = normal.z;
|
|
346
|
+
}
|
|
347
|
+
return normals;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// src/geometry/colors/rgb565.ts
|
|
351
|
+
function decodeRGB565(rgb565, target = [0, 0, 0]) {
|
|
352
|
+
const r5 = rgb565 >> 11 & 31;
|
|
353
|
+
const g6 = rgb565 >> 5 & 63;
|
|
354
|
+
const b5 = rgb565 & 31;
|
|
355
|
+
target[0] = r5 << 3;
|
|
356
|
+
target[1] = g6 << 2;
|
|
357
|
+
target[2] = b5 << 3;
|
|
358
|
+
return target;
|
|
359
|
+
}
|
|
360
|
+
function encodeRGB565(rgb) {
|
|
361
|
+
const r5 = Math.floor(rgb[0] / 8) + 4;
|
|
362
|
+
const g6 = Math.floor(rgb[1] / 4) + 2;
|
|
363
|
+
const b5 = Math.floor(rgb[2] / 8) + 4;
|
|
364
|
+
return r5 + (g6 << 5) + (b5 << 11);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/geometry/typed-arrays/typed-array-utils.ts
|
|
368
|
+
function concatTypedArrays(arrays = []) {
|
|
369
|
+
let byteLength = 0;
|
|
370
|
+
for (let i = 0; i < arrays.length; ++i) {
|
|
371
|
+
byteLength += arrays[i].byteLength;
|
|
372
|
+
}
|
|
373
|
+
const buffer = new Uint8Array(byteLength);
|
|
374
|
+
let byteOffset = 0;
|
|
375
|
+
for (let i = 0; i < arrays.length; ++i) {
|
|
376
|
+
const data = new Uint8Array(arrays[i].buffer);
|
|
377
|
+
byteLength = data.length;
|
|
378
|
+
for (let j = 0; j < byteLength; ++j) {
|
|
379
|
+
buffer[byteOffset++] = data[j];
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return buffer;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/geometry/compression/attribute-compression.ts
|
|
386
|
+
var import_core2 = require("@math.gl/core");
|
|
387
|
+
var RIGHT_SHIFT = 1 / 256;
|
|
388
|
+
var LEFT_SHIFT = 256;
|
|
389
|
+
var scratchVector2 = new import_core2.Vector2();
|
|
390
|
+
var scratchVector3 = new import_core2.Vector3();
|
|
391
|
+
var scratchEncodeVector2 = new import_core2.Vector2();
|
|
392
|
+
var octEncodeScratch = new import_core2.Vector2();
|
|
393
|
+
var uint8ForceArray = new Uint8Array(1);
|
|
394
|
+
function forceUint8(value) {
|
|
395
|
+
uint8ForceArray[0] = value;
|
|
396
|
+
return uint8ForceArray[0];
|
|
397
|
+
}
|
|
398
|
+
function fromSNorm(value, rangeMaximum = 255) {
|
|
399
|
+
return (0, import_core2.clamp)(value, 0, rangeMaximum) / rangeMaximum * 2 - 1;
|
|
400
|
+
}
|
|
401
|
+
function toSNorm(value, rangeMaximum = 255) {
|
|
402
|
+
return Math.round(((0, import_core2.clamp)(value, -1, 1) * 0.5 + 0.5) * rangeMaximum);
|
|
403
|
+
}
|
|
404
|
+
function signNotZero(value) {
|
|
405
|
+
return value < 0 ? -1 : 1;
|
|
406
|
+
}
|
|
407
|
+
function octEncodeInRange(vector, rangeMax, result) {
|
|
408
|
+
assert2(vector);
|
|
409
|
+
assert2(result);
|
|
410
|
+
const vector3 = scratchVector3.from(vector);
|
|
411
|
+
assert2(Math.abs(vector3.magnitudeSquared() - 1) <= import_core2._MathUtils.EPSILON6);
|
|
412
|
+
result.x = vector.x / (Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z));
|
|
413
|
+
result.y = vector.y / (Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z));
|
|
414
|
+
if (vector.z < 0) {
|
|
415
|
+
const x = result.x;
|
|
416
|
+
const y = result.y;
|
|
417
|
+
result.x = (1 - Math.abs(y)) * signNotZero(x);
|
|
418
|
+
result.y = (1 - Math.abs(x)) * signNotZero(y);
|
|
419
|
+
}
|
|
420
|
+
result.x = toSNorm(result.x, rangeMax);
|
|
421
|
+
result.y = toSNorm(result.y, rangeMax);
|
|
422
|
+
return result;
|
|
423
|
+
}
|
|
424
|
+
function octEncode(vector, result) {
|
|
425
|
+
return octEncodeInRange(vector, 255, result);
|
|
426
|
+
}
|
|
427
|
+
function octEncodeToVector4(vector, result) {
|
|
428
|
+
octEncodeInRange(vector, 65535, octEncodeScratch);
|
|
429
|
+
result.x = forceUint8(octEncodeScratch.x * RIGHT_SHIFT);
|
|
430
|
+
result.y = forceUint8(octEncodeScratch.x);
|
|
431
|
+
result.z = forceUint8(octEncodeScratch.y * RIGHT_SHIFT);
|
|
432
|
+
result.w = forceUint8(octEncodeScratch.y);
|
|
433
|
+
return result;
|
|
434
|
+
}
|
|
435
|
+
function octDecodeInRange(x, y, rangeMax, result) {
|
|
436
|
+
assert2(result);
|
|
437
|
+
if (x < 0 || x > rangeMax || y < 0 || y > rangeMax) {
|
|
438
|
+
throw new Error(`x and y must be unsigned normalized integers between 0 and ${rangeMax}`);
|
|
439
|
+
}
|
|
440
|
+
result.x = fromSNorm(x, rangeMax);
|
|
441
|
+
result.y = fromSNorm(y, rangeMax);
|
|
442
|
+
result.z = 1 - (Math.abs(result.x) + Math.abs(result.y));
|
|
443
|
+
if (result.z < 0) {
|
|
444
|
+
const oldVX = result.x;
|
|
445
|
+
result.x = (1 - Math.abs(result.y)) * signNotZero(oldVX);
|
|
446
|
+
result.y = (1 - Math.abs(oldVX)) * signNotZero(result.y);
|
|
447
|
+
}
|
|
448
|
+
return result.normalize();
|
|
449
|
+
}
|
|
450
|
+
function octDecode(x, y, result) {
|
|
451
|
+
return octDecodeInRange(x, y, 255, result);
|
|
452
|
+
}
|
|
453
|
+
function octDecodeFromVector4(encoded, result) {
|
|
454
|
+
assert2(encoded);
|
|
455
|
+
assert2(result);
|
|
456
|
+
const x = encoded.x;
|
|
457
|
+
const y = encoded.y;
|
|
458
|
+
const z = encoded.z;
|
|
459
|
+
const w = encoded.w;
|
|
460
|
+
if (x < 0 || x > 255 || y < 0 || y > 255 || z < 0 || z > 255 || w < 0 || w > 255) {
|
|
461
|
+
throw new Error("x, y, z, and w must be unsigned normalized integers between 0 and 255");
|
|
462
|
+
}
|
|
463
|
+
const xOct16 = x * LEFT_SHIFT + y;
|
|
464
|
+
const yOct16 = z * LEFT_SHIFT + w;
|
|
465
|
+
return octDecodeInRange(xOct16, yOct16, 65535, result);
|
|
466
|
+
}
|
|
467
|
+
function octPackFloat(encoded) {
|
|
468
|
+
const vector2 = scratchVector2.from(encoded);
|
|
469
|
+
return 256 * vector2.x + vector2.y;
|
|
470
|
+
}
|
|
471
|
+
function octEncodeFloat(vector) {
|
|
472
|
+
octEncode(vector, scratchEncodeVector2);
|
|
473
|
+
return octPackFloat(scratchEncodeVector2);
|
|
474
|
+
}
|
|
475
|
+
function octDecodeFloat(value, result) {
|
|
476
|
+
assert2(Number.isFinite(value));
|
|
477
|
+
const temp = value / 256;
|
|
478
|
+
const x = Math.floor(temp);
|
|
479
|
+
const y = (temp - x) * 256;
|
|
480
|
+
return octDecode(x, y, result);
|
|
481
|
+
}
|
|
482
|
+
function octPack(v1, v2, v3, result) {
|
|
483
|
+
assert2(v1);
|
|
484
|
+
assert2(v2);
|
|
485
|
+
assert2(v3);
|
|
486
|
+
assert2(result);
|
|
487
|
+
const encoded1 = octEncodeFloat(v1);
|
|
488
|
+
const encoded2 = octEncodeFloat(v2);
|
|
489
|
+
const encoded3 = octEncode(v3, scratchEncodeVector2);
|
|
490
|
+
result.x = 65536 * encoded3.x + encoded1;
|
|
491
|
+
result.y = 65536 * encoded3.y + encoded2;
|
|
492
|
+
return result;
|
|
493
|
+
}
|
|
494
|
+
function octUnpack(packed, v1, v2, v3) {
|
|
495
|
+
let temp = packed.x / 65536;
|
|
496
|
+
const x = Math.floor(temp);
|
|
497
|
+
const encodedFloat1 = (temp - x) * 65536;
|
|
498
|
+
temp = packed.y / 65536;
|
|
499
|
+
const y = Math.floor(temp);
|
|
500
|
+
const encodedFloat2 = (temp - y) * 65536;
|
|
501
|
+
octDecodeFloat(encodedFloat1, v1);
|
|
502
|
+
octDecodeFloat(encodedFloat2, v2);
|
|
503
|
+
octDecode(x, y, v3);
|
|
504
|
+
}
|
|
505
|
+
function compressTextureCoordinates(textureCoordinates) {
|
|
506
|
+
const x = textureCoordinates.x * 4095 | 0;
|
|
507
|
+
const y = textureCoordinates.y * 4095 | 0;
|
|
508
|
+
return 4096 * x + y;
|
|
509
|
+
}
|
|
510
|
+
function decompressTextureCoordinates(compressed, result) {
|
|
511
|
+
const temp = compressed / 4096;
|
|
512
|
+
const xZeroTo4095 = Math.floor(temp);
|
|
513
|
+
result.x = xZeroTo4095 / 4095;
|
|
514
|
+
result.y = (compressed - xZeroTo4095 * 4096) / 4095;
|
|
515
|
+
return result;
|
|
516
|
+
}
|
|
517
|
+
function zigZagDeltaDecode(uBuffer, vBuffer, heightBuffer) {
|
|
518
|
+
assert2(uBuffer);
|
|
519
|
+
assert2(vBuffer);
|
|
520
|
+
assert2(uBuffer.length === vBuffer.length);
|
|
521
|
+
if (heightBuffer) {
|
|
522
|
+
assert2(uBuffer.length === heightBuffer.length);
|
|
523
|
+
}
|
|
524
|
+
function zigZagDecode(value) {
|
|
525
|
+
return value >> 1 ^ -(value & 1);
|
|
526
|
+
}
|
|
527
|
+
let u = 0;
|
|
528
|
+
let v = 0;
|
|
529
|
+
let height = 0;
|
|
530
|
+
for (let i = 0; i < uBuffer.length; ++i) {
|
|
531
|
+
u += zigZagDecode(uBuffer[i]);
|
|
532
|
+
v += zigZagDecode(vBuffer[i]);
|
|
533
|
+
uBuffer[i] = u;
|
|
534
|
+
vBuffer[i] = v;
|
|
535
|
+
if (heightBuffer) {
|
|
536
|
+
height += zigZagDecode(heightBuffer[i]);
|
|
537
|
+
heightBuffer[i] = height;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/geometry/utils/coordinates.ts
|
|
543
|
+
function emod(n) {
|
|
544
|
+
return (n % 1 + 1) % 1;
|
|
545
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor |
|
|
1
|
+
export type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
|
|
2
2
|
export { GL } from './geometry/constants';
|
|
3
3
|
export { GL_TYPE } from './geometry/constants';
|
|
4
4
|
export { default as GLType } from './geometry/gl/gl-type';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAC7B,oBAAoB,GACpB,qBAAqB,GACrB,qBAAqB,GACrB,sBAAsB,GACtB,qBAAqB,GACrB,sBAAsB,GACtB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAC7B,oBAAoB,GACpB,qBAAqB,GACrB,qBAAqB,GACrB,sBAAsB,GACtB,qBAAqB,GACrB,sBAAsB,GACtB,uBAAuB,GACvB,uBAAuB,CAAC;AAE5B,OAAO,EAAC,EAAE,EAAC,MAAM,sBAAsB,CAAC;AAGxC,OAAO,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,wBAAwB,CAAC;AAG7D,OAAO,EAAC,qBAAqB,EAAC,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAC,qBAAqB,EAAC,MAAM,yCAAyC,CAAC;AAG9E,OAAO,EAAC,oBAAoB,EAAC,MAAM,8CAA8C,CAAC;AAElF,OAAO,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAGpE,OAAO,EAAC,iBAAiB,EAAC,MAAM,2CAA2C,CAAC;AAG5E,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACT,oBAAoB,EACpB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,OAAO,EACP,SAAS,EACT,0BAA0B,EAC1B,4BAA4B,EAC5B,iBAAiB,EAClB,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EAAC,IAAI,EAAC,MAAM,8BAA8B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { GL } from "./geometry/constants.js";
|
|
2
|
+
export { GL_TYPE } from "./geometry/constants.js";
|
|
3
|
+
export { default as GLType } from "./geometry/gl/gl-type.js";
|
|
4
|
+
export { default as isGeometry } from "./geometry/is-geometry.js";
|
|
5
|
+
export { makeAttributeIterator } from "./geometry/iterators/attribute-iterator.js";
|
|
6
|
+
export { makePrimitiveIterator } from "./geometry/iterators/primitive-iterator.js";
|
|
7
|
+
export { computeVertexNormals } from "./geometry/attributes/compute-vertex-normals.js";
|
|
8
|
+
export { encodeRGB565, decodeRGB565 } from "./geometry/colors/rgb565.js";
|
|
9
|
+
export { concatTypedArrays } from "./geometry/typed-arrays/typed-array-utils.js";
|
|
10
|
+
export { octEncodeInRange, octEncode, octEncodeToVector4, octDecodeInRange, octDecode, octDecodeFromVector4, octPackFloat, octEncodeFloat, octDecodeFloat, octPack, octUnpack, compressTextureCoordinates, decompressTextureCoordinates, zigZagDeltaDecode } from "./geometry/compression/attribute-compression.js";
|
|
11
|
+
export { emod } from "./geometry/utils/coordinates.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["GL","GL_TYPE","default","GLType","isGeometry","makeAttributeIterator","makePrimitiveIterator","computeVertexNormals","encodeRGB565","decodeRGB565","concatTypedArrays","octEncodeInRange","octEncode","octEncodeToVector4","octDecodeInRange","octDecode","octDecodeFromVector4","octPackFloat","octEncodeFloat","octDecodeFloat","octPack","octUnpack","compressTextureCoordinates","decompressTextureCoordinates","zigZagDeltaDecode","emod"],"sources":["../src/index.ts"],"sourcesContent":["export type TypedArrayConstructor =\n | Int8ArrayConstructor\n | Uint8ArrayConstructor\n | Int16ArrayConstructor\n | Uint16ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Float32ArrayConstructor\n | Float64ArrayConstructor;\n\nexport {GL} from './geometry/constants';\n\n// GL support\nexport {GL_TYPE} from './geometry/constants';\nexport {default as GLType} from './geometry/gl/gl-type';\n\n// Geometry\nexport {default as isGeometry} from './geometry/is-geometry';\n\n// Iterators\nexport {makeAttributeIterator} from './geometry/iterators/attribute-iterator';\nexport {makePrimitiveIterator} from './geometry/iterators/primitive-iterator';\n\n// Helper methods\nexport {computeVertexNormals} from './geometry/attributes/compute-vertex-normals';\n\nexport {encodeRGB565, decodeRGB565} from './geometry/colors/rgb565';\n\n// Typed array utils\nexport {concatTypedArrays} from './geometry/typed-arrays/typed-array-utils';\n\n// Compression\nexport {\n octEncodeInRange,\n octEncode,\n octEncodeToVector4,\n octDecodeInRange,\n octDecode,\n octDecodeFromVector4,\n octPackFloat,\n octEncodeFloat,\n octDecodeFloat,\n octPack,\n octUnpack,\n compressTextureCoordinates,\n decompressTextureCoordinates,\n zigZagDeltaDecode\n} from './geometry/compression/attribute-compression';\n\nexport {emod} from './geometry/utils/coordinates';\n"],"mappings":"SAUQA,EAAE;AAAA,SAGFC,OAAO;AAAA,SACPC,OAAO,IAAIC,MAAM;AAAA,SAGjBD,OAAO,IAAIE,UAAU;AAAA,SAGrBC,qBAAqB;AAAA,SACrBC,qBAAqB;AAAA,SAGrBC,oBAAoB;AAAA,SAEpBC,YAAY,EAAEC,YAAY;AAAA,SAG1BC,iBAAiB;AAAA,SAIvBC,gBAAgB,EAChBC,SAAS,EACTC,kBAAkB,EAClBC,gBAAgB,EAChBC,SAAS,EACTC,oBAAoB,EACpBC,YAAY,EACZC,cAAc,EACdC,cAAc,EACdC,OAAO,EACPC,SAAS,EACTC,0BAA0B,EAC1BC,4BAA4B,EAC5BC,iBAAiB;AAAA,SAGXC,IAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","names":["assert","condition","message","Error"],"sources":["../../src/utils/assert.ts"],"sourcesContent":["// Replacement for the external assert method to reduce bundle size\n// Note: We don't use the second \"message\" argument in calling code,\n// so no need to support it here\nexport function assert(condition: Boolean, message?: string): void {\n if (!condition) {\n throw new Error(message || '3d-tile loader: assertion failed.');\n }\n}\n"],"mappings":"AAGA,OAAO,SAASA,MAAMA,CAACC,SAAkB,EAAEC,OAAgB,EAAQ;EACjE,IAAI,CAACD,SAAS,EAAE;IACd,MAAM,IAAIE,KAAK,CAACD,OAAO,IAAI,mCAAmC,CAAC;EACjE;AACF"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/math",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.3",
|
|
4
4
|
"description": "Experimental math classes for loaders.gl",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"publishConfig": {
|
|
7
8
|
"access": "public"
|
|
8
9
|
},
|
|
@@ -18,8 +19,15 @@
|
|
|
18
19
|
"glTF"
|
|
19
20
|
],
|
|
20
21
|
"types": "dist/index.d.ts",
|
|
21
|
-
"main": "dist/
|
|
22
|
-
"module": "dist/
|
|
22
|
+
"main": "dist/index.cjs",
|
|
23
|
+
"module": "dist/index.js",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"require": "./dist/index.cjs",
|
|
28
|
+
"types": "./dist/index.d.ts"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
23
31
|
"sideEffects": false,
|
|
24
32
|
"files": [
|
|
25
33
|
"src",
|
|
@@ -31,9 +39,9 @@
|
|
|
31
39
|
"pre-build": "echo \"Nothing to build in @loaders.gl/math\""
|
|
32
40
|
},
|
|
33
41
|
"dependencies": {
|
|
34
|
-
"@loaders.gl/images": "4.0.0-beta.
|
|
35
|
-
"@loaders.gl/loader-utils": "4.0.0-beta.
|
|
36
|
-
"@math.gl/core": "^
|
|
42
|
+
"@loaders.gl/images": "4.0.0-beta.3",
|
|
43
|
+
"@loaders.gl/loader-utils": "4.0.0-beta.3",
|
|
44
|
+
"@math.gl/core": "^4.0.0"
|
|
37
45
|
},
|
|
38
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "7ba9621cc51c7a26c407086ac86171f35b8712af"
|
|
39
47
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.computeBoundingBox = computeBoundingBox;
|
|
7
|
-
var _attributeIterator = require("../iterators/attribute-iterator");
|
|
8
|
-
var _assert = require("../utils/assert");
|
|
9
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
10
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
-
function computeBoundingBox() {
|
|
13
|
-
var positions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
14
|
-
var min = [Number(Infinity), Number(Infinity), Number(Infinity)];
|
|
15
|
-
var max = [-Infinity, -Infinity, -Infinity];
|
|
16
|
-
var _iterator = _createForOfIteratorHelper((0, _attributeIterator.makeAttributeIterator)(positions)),
|
|
17
|
-
_step;
|
|
18
|
-
try {
|
|
19
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
20
|
-
var position = _step.value;
|
|
21
|
-
var x = position[0];
|
|
22
|
-
var y = position[1];
|
|
23
|
-
var z = position[2];
|
|
24
|
-
if (x < min[0]) min[0] = x;
|
|
25
|
-
if (y < min[1]) min[1] = y;
|
|
26
|
-
if (z < min[2]) min[2] = z;
|
|
27
|
-
if (x > max[0]) max[0] = x;
|
|
28
|
-
if (y > max[1]) max[1] = y;
|
|
29
|
-
if (z > max[2]) max[2] = z;
|
|
30
|
-
}
|
|
31
|
-
} catch (err) {
|
|
32
|
-
_iterator.e(err);
|
|
33
|
-
} finally {
|
|
34
|
-
_iterator.f();
|
|
35
|
-
}
|
|
36
|
-
var boundingBox = {
|
|
37
|
-
min: min,
|
|
38
|
-
max: max
|
|
39
|
-
};
|
|
40
|
-
validateBoundingBox(boundingBox);
|
|
41
|
-
return boundingBox;
|
|
42
|
-
}
|
|
43
|
-
function validateBoundingBox(boundingBox) {
|
|
44
|
-
(0, _assert.assert)(Number.isFinite(boundingBox.min[0]) && Number.isFinite(boundingBox.min[1]) && Number.isFinite(boundingBox.min[2]) && Number.isFinite(boundingBox.max[0]) && Number.isFinite(boundingBox.max[1]) && Number.isFinite(boundingBox.max[2]));
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=compute-bounding-box.js.map
|