@loaders.gl/math 4.0.0-alpha.5 → 4.0.0-alpha.6
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/es5/geometry/attributes/compute-bounding-box.js +46 -0
- package/dist/es5/geometry/attributes/compute-bounding-box.js.map +1 -0
- package/dist/es5/geometry/attributes/compute-bounding-sphere.js +2 -0
- package/dist/es5/geometry/attributes/compute-bounding-sphere.js.map +1 -0
- package/dist/es5/geometry/attributes/compute-tangents.js +2 -0
- package/dist/es5/geometry/attributes/compute-tangents.js.map +1 -0
- package/dist/es5/geometry/attributes/compute-vertex-normals.js +56 -0
- package/dist/es5/geometry/attributes/compute-vertex-normals.js.map +1 -0
- package/dist/es5/geometry/attributes/convert-to-non-indexed.js +43 -0
- package/dist/es5/geometry/attributes/convert-to-non-indexed.js.map +1 -0
- package/dist/es5/geometry/attributes/get-attribute-from-geometry.js +29 -0
- package/dist/es5/geometry/attributes/get-attribute-from-geometry.js.map +1 -0
- package/dist/es5/geometry/attributes/normalize.js +19 -0
- package/dist/es5/geometry/attributes/normalize.js.map +1 -0
- package/dist/es5/geometry/colors/rgb565.js +24 -0
- package/dist/es5/geometry/colors/rgb565.js.map +1 -0
- package/dist/es5/geometry/compression/attribute-compression.js +178 -0
- package/dist/es5/geometry/compression/attribute-compression.js.map +1 -0
- package/dist/es5/geometry/constants.js +40 -0
- package/dist/es5/geometry/constants.js.map +1 -0
- package/dist/es5/geometry/gl/gl-type.js +92 -0
- package/dist/es5/geometry/gl/gl-type.js.map +1 -0
- package/dist/es5/geometry/is-geometry.js +12 -0
- package/dist/es5/geometry/is-geometry.js.map +1 -0
- package/dist/es5/geometry/iterators/attribute-iterator.js +38 -0
- package/dist/es5/geometry/iterators/attribute-iterator.js.map +1 -0
- package/dist/es5/geometry/iterators/primitive-iterator.js +102 -0
- package/dist/es5/geometry/iterators/primitive-iterator.js.map +1 -0
- package/dist/es5/geometry/primitives/modes.js +56 -0
- package/dist/es5/geometry/primitives/modes.js.map +1 -0
- package/dist/es5/geometry/typed-arrays/typed-array-utils.js +24 -0
- package/dist/es5/geometry/typed-arrays/typed-array-utils.js.map +1 -0
- package/dist/es5/geometry/utils/assert.js +12 -0
- package/dist/es5/geometry/utils/assert.js.map +1 -0
- package/dist/es5/index.js +160 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/utils/assert.js +12 -0
- package/dist/es5/utils/assert.js.map +1 -0
- package/dist/esm/geometry/attributes/compute-bounding-box.js +28 -0
- package/dist/esm/geometry/attributes/compute-bounding-box.js.map +1 -0
- package/dist/esm/geometry/attributes/compute-bounding-sphere.js +2 -0
- package/dist/esm/geometry/attributes/compute-bounding-sphere.js.map +1 -0
- package/dist/esm/geometry/attributes/compute-tangents.js +2 -0
- package/dist/esm/geometry/attributes/compute-tangents.js.map +1 -0
- package/dist/esm/geometry/attributes/compute-vertex-normals.js +41 -0
- package/dist/esm/geometry/attributes/compute-vertex-normals.js.map +1 -0
- package/dist/esm/geometry/attributes/convert-to-non-indexed.js +27 -0
- package/dist/esm/geometry/attributes/convert-to-non-indexed.js.map +1 -0
- package/dist/esm/geometry/attributes/get-attribute-from-geometry.js +24 -0
- package/dist/esm/geometry/attributes/get-attribute-from-geometry.js.map +1 -0
- package/dist/esm/geometry/attributes/normalize.js +13 -0
- package/dist/esm/geometry/attributes/normalize.js.map +1 -0
- package/dist/esm/geometry/colors/rgb565.js +17 -0
- package/dist/esm/geometry/colors/rgb565.js.map +1 -0
- package/dist/esm/geometry/compression/attribute-compression.js +159 -0
- package/dist/esm/geometry/compression/attribute-compression.js.map +1 -0
- package/dist/esm/geometry/constants.js +29 -0
- package/dist/esm/geometry/constants.js.map +1 -0
- package/dist/esm/geometry/gl/gl-type.js +72 -0
- package/dist/esm/geometry/gl/gl-type.js.map +1 -0
- package/dist/esm/geometry/is-geometry.js +4 -0
- package/dist/esm/geometry/is-geometry.js.map +1 -0
- package/dist/esm/geometry/iterators/attribute-iterator.js +11 -0
- package/dist/esm/geometry/iterators/attribute-iterator.js.map +1 -0
- package/dist/esm/geometry/iterators/primitive-iterator.js +76 -0
- package/dist/esm/geometry/iterators/primitive-iterator.js.map +1 -0
- package/dist/esm/geometry/primitives/modes.js +48 -0
- package/dist/esm/geometry/primitives/modes.js.map +1 -0
- package/dist/esm/geometry/typed-arrays/typed-array-utils.js +18 -0
- package/dist/esm/geometry/typed-arrays/typed-array-utils.js.map +1 -0
- package/dist/esm/geometry/utils/assert.js +6 -0
- package/dist/esm/geometry/utils/assert.js.map +1 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/utils/assert.js +6 -0
- package/dist/esm/utils/assert.js.map +1 -0
- package/dist/geometry/attributes/compute-bounding-box.js +41 -27
- package/dist/geometry/attributes/compute-bounding-sphere.js +29 -1
- package/dist/geometry/attributes/compute-tangents.js +145 -1
- package/dist/geometry/attributes/compute-vertex-normals.d.ts +2 -2
- package/dist/geometry/attributes/compute-vertex-normals.d.ts.map +1 -1
- package/dist/geometry/attributes/compute-vertex-normals.js +47 -42
- package/dist/geometry/attributes/convert-to-non-indexed.js +31 -30
- package/dist/geometry/attributes/get-attribute-from-geometry.js +33 -26
- package/dist/geometry/attributes/normalize.js +19 -11
- package/dist/geometry/colors/rgb565.js +29 -14
- package/dist/geometry/compression/attribute-compression.d.ts +7 -1
- package/dist/geometry/compression/attribute-compression.d.ts.map +1 -1
- package/dist/geometry/compression/attribute-compression.js +339 -162
- package/dist/geometry/constants.d.ts +1 -1
- package/dist/geometry/constants.d.ts.map +1 -1
- package/dist/geometry/constants.js +30 -24
- package/dist/geometry/gl/gl-type.d.ts +1 -1
- package/dist/geometry/gl/gl-type.d.ts.map +1 -1
- package/dist/geometry/gl/gl-type.js +101 -74
- package/dist/geometry/is-geometry.js +13 -3
- package/dist/geometry/iterators/attribute-iterator.js +17 -11
- package/dist/geometry/iterators/primitive-iterator.js +85 -79
- package/dist/geometry/primitives/modes.js +67 -54
- package/dist/geometry/typed-arrays/typed-array-utils.js +23 -20
- package/dist/geometry/utils/assert.js +13 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -11
- package/dist/utils/assert.js +11 -5
- package/package.json +6 -6
- package/src/geometry/attributes/compute-vertex-normals.ts +1 -1
- package/src/geometry/compression/attribute-compression.ts +7 -1
- package/src/geometry/gl/gl-type.ts +1 -1
- package/src/index.ts +12 -0
- package/dist/geometry/attributes/compute-bounding-box.js.map +0 -1
- package/dist/geometry/attributes/compute-bounding-sphere.js.map +0 -1
- package/dist/geometry/attributes/compute-tangents.js.map +0 -1
- package/dist/geometry/attributes/compute-vertex-normals.js.map +0 -1
- package/dist/geometry/attributes/convert-to-non-indexed.js.map +0 -1
- package/dist/geometry/attributes/get-attribute-from-geometry.js.map +0 -1
- package/dist/geometry/attributes/normalize.js.map +0 -1
- package/dist/geometry/colors/rgb565.js.map +0 -1
- package/dist/geometry/compression/attribute-compression.js.map +0 -1
- package/dist/geometry/constants.js.map +0 -1
- package/dist/geometry/gl/gl-type.js.map +0 -1
- package/dist/geometry/is-geometry.js.map +0 -1
- package/dist/geometry/iterators/attribute-iterator.js.map +0 -1
- package/dist/geometry/iterators/primitive-iterator.js.map +0 -1
- package/dist/geometry/primitives/modes.js.map +0 -1
- package/dist/geometry/typed-arrays/typed-array-utils.js.map +0 -1
- package/dist/geometry/types.d.ts +0 -13
- package/dist/geometry/types.d.ts.map +0 -1
- package/dist/geometry/types.js +0 -2
- package/dist/geometry/types.js.map +0 -1
- package/dist/geometry/utils/assert.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/utils/assert.js.map +0 -1
- package/src/geometry/types.ts +0 -25
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalize = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Setting X, Y, Z for Vector
|
|
6
|
+
* @param normals
|
|
7
|
+
* @param vector
|
|
8
|
+
*/
|
|
9
|
+
function normalize(normals = {}, vector) {
|
|
10
|
+
//@ts-ignore
|
|
11
|
+
normals = this.attributes.normal;
|
|
12
|
+
for (let i = 0, il = normals.count; i < il; i++) {
|
|
13
|
+
vector.x = normals.getX(i);
|
|
14
|
+
vector.y = normals.getY(i);
|
|
15
|
+
vector.z = normals.getZ(i);
|
|
16
|
+
vector.normalize();
|
|
17
|
+
normals.setXYZ(i, vector.x, vector.y, vector.z);
|
|
18
|
+
}
|
|
11
19
|
}
|
|
12
|
-
|
|
20
|
+
exports.normalize = normalize;
|
|
@@ -1,16 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeRGB565 = exports.decodeRGB565 = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Decode color values
|
|
6
|
+
* @param rgb565
|
|
7
|
+
* @param target
|
|
8
|
+
* @returns target
|
|
9
|
+
*/
|
|
10
|
+
function decodeRGB565(rgb565, target = [0, 0, 0]) {
|
|
11
|
+
const r5 = (rgb565 >> 11) & 31;
|
|
12
|
+
const g6 = (rgb565 >> 5) & 63;
|
|
13
|
+
const b5 = rgb565 & 31;
|
|
14
|
+
target[0] = r5 << 3;
|
|
15
|
+
target[1] = g6 << 2;
|
|
16
|
+
target[2] = b5 << 3;
|
|
17
|
+
return target;
|
|
9
18
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
exports.decodeRGB565 = decodeRGB565;
|
|
20
|
+
/**
|
|
21
|
+
* Encode color values
|
|
22
|
+
* @param rgb
|
|
23
|
+
* @returns color
|
|
24
|
+
*/
|
|
25
|
+
function encodeRGB565(rgb) {
|
|
26
|
+
const r5 = Math.floor(rgb[0] / 8) + 4;
|
|
27
|
+
const g6 = Math.floor(rgb[1] / 4) + 2;
|
|
28
|
+
const b5 = Math.floor(rgb[2] / 8) + 4;
|
|
29
|
+
return r5 + (g6 << 5) + (b5 << 11);
|
|
15
30
|
}
|
|
16
|
-
|
|
31
|
+
exports.encodeRGB565 = encodeRGB565;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { Vector2, Vector3 } from '@math.gl/core';
|
|
2
|
-
|
|
2
|
+
type Vector4 = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
z: number;
|
|
6
|
+
w: number;
|
|
7
|
+
};
|
|
3
8
|
/**
|
|
4
9
|
* Encodes a normalized vector into 2 SNORM values in the range of [0-rangeMax] following the 'oct' encoding.
|
|
5
10
|
*
|
|
@@ -157,4 +162,5 @@ export declare function decompressTextureCoordinates(compressed: number, result:
|
|
|
157
162
|
* @link https://github.com/AnalyticalGraphicsInc/quantized-mesh|quantized-mesh-1.0 terrain format
|
|
158
163
|
*/
|
|
159
164
|
export declare function zigZagDeltaDecode(uBuffer: Uint16Array, vBuffer: Uint16Array, heightBuffer?: Uint16Array | number[]): void;
|
|
165
|
+
export {};
|
|
160
166
|
//# sourceMappingURL=attribute-compression.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attribute-compression.d.ts","sourceRoot":"","sources":["../../../src/geometry/compression/attribute-compression.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,OAAO,EAAE,OAAO,EAAoB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"attribute-compression.d.ts","sourceRoot":"","sources":["../../../src/geometry/compression/attribute-compression.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,OAAO,EAAE,OAAO,EAAoB,MAAM,eAAe,CAAC;AAGlE,KAAK,OAAO,GAAG;IACb,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AA6DF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAsB5F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAEnE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAO5E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAiBjG;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAExE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAe/E;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAGrD;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAGtD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAQtE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAavF;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAYtF;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,kBAAkB,EAAE,OAAO,GAAG,MAAM,CAK9E;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAMzF;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,WAAW,EACpB,YAAY,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE,QA6BtC"}
|
|
@@ -1,175 +1,352 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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");
|
|
3
9
|
const RIGHT_SHIFT = 1.0 / 256.0;
|
|
4
10
|
const LEFT_SHIFT = 256.0;
|
|
5
|
-
const scratchVector2 = new Vector2();
|
|
6
|
-
const scratchVector3 = new Vector3();
|
|
7
|
-
const scratchEncodeVector2 = new Vector2();
|
|
8
|
-
const octEncodeScratch = new Vector2();
|
|
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();
|
|
9
15
|
const uint8ForceArray = new Uint8Array(1);
|
|
10
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Force a value to Uint8
|
|
18
|
+
*
|
|
19
|
+
* @param value
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
11
22
|
function forceUint8(value) {
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
uint8ForceArray[0] = value;
|
|
24
|
+
return uint8ForceArray[0];
|
|
14
25
|
}
|
|
15
|
-
|
|
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
|
+
*/
|
|
16
35
|
function fromSNorm(value, rangeMaximum = 255) {
|
|
17
|
-
|
|
36
|
+
return ((0, core_1.clamp)(value, 0.0, rangeMaximum) / rangeMaximum) * 2.0 - 1.0;
|
|
18
37
|
}
|
|
19
|
-
|
|
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
|
+
*/
|
|
20
47
|
function toSNorm(value, rangeMaximum = 255) {
|
|
21
|
-
|
|
48
|
+
return Math.round(((0, core_1.clamp)(value, -1.0, 1.0) * 0.5 + 0.5) * rangeMaximum);
|
|
22
49
|
}
|
|
23
|
-
|
|
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
|
+
*/
|
|
24
58
|
function signNotZero(value) {
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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);
|
|
169
332
|
if (heightBuffer) {
|
|
170
|
-
|
|
171
|
-
|
|
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
|
+
}
|
|
172
350
|
}
|
|
173
|
-
}
|
|
174
351
|
}
|
|
175
|
-
|
|
352
|
+
exports.zigZagDeltaDecode = zigZagDeltaDecode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/geometry/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY;;;;CAIxB,CAAC;AAGF,eAAO,MAAM,iBAAiB;;;;;;;;CAS7B,CAAC;AAEF,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/geometry/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY;;;;CAIxB,CAAC;AAGF,eAAO,MAAM,iBAAiB;;;;;;;;CAS7B,CAAC;AAEF,KAAK,MAAM,GAAG;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,MASrB,CAAC;AAEF,eAAO,MAAM,EAAE;UArBP,MAAM;mBACG,MAAM;WACd,MAAM;oBACG,MAAM;SACjB,MAAM;kBACG,MAAM;WACb,MAAM;YACL,MAAM;;;;;;;;CAiBf,CAAC"}
|