@loaders.gl/math 4.2.0-alpha.3 → 4.2.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/geometry/attributes/compute-bounding-box.js +35 -23
- 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.js +36 -33
- package/dist/geometry/attributes/convert-to-non-indexed.js +27 -25
- package/dist/geometry/attributes/get-attribute-from-geometry.js +23 -20
- package/dist/geometry/attributes/normalize.js +15 -12
- package/dist/geometry/colors/rgb565.js +23 -14
- package/dist/geometry/compression/attribute-compression.js +290 -114
- package/dist/geometry/constants.js +23 -21
- package/dist/geometry/gl/gl-type.js +96 -59
- package/dist/geometry/is-geometry.js +9 -2
- package/dist/geometry/iterators/attribute-iterator.js +12 -8
- package/dist/geometry/iterators/primitive-iterator.js +70 -62
- package/dist/geometry/primitives/modes.js +58 -41
- package/dist/geometry/typed-arrays/typed-array-utils.js +19 -16
- package/dist/geometry/utils/assert.js +8 -4
- package/dist/geometry/utils/coordinates.js +5 -2
- package/dist/index.cjs +19 -18
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +11 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/utils/assert.js +6 -4
- package/package.json +7 -4
- 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/utils/assert.js.map +0 -1
- package/dist/geometry/utils/coordinates.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/utils/assert.js.map +0 -1
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
import { makeAttributeIterator } from "../iterators/attribute-iterator.js";
|
|
2
2
|
import { assert } from "../utils/assert.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Getting bounding box geometry according to positions parameters
|
|
5
|
+
* @param positions
|
|
6
|
+
* @returns Bounding Box
|
|
7
|
+
*/
|
|
8
|
+
export function computeBoundingBox(positions = []) {
|
|
9
|
+
const min = [Number(Infinity), Number(Infinity), Number(Infinity)];
|
|
10
|
+
const max = [-Infinity, -Infinity, -Infinity];
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
for (const position of makeAttributeIterator(positions)) {
|
|
13
|
+
const x = position[0];
|
|
14
|
+
const y = position[1];
|
|
15
|
+
const z = position[2];
|
|
16
|
+
if (x < min[0])
|
|
17
|
+
min[0] = x;
|
|
18
|
+
if (y < min[1])
|
|
19
|
+
min[1] = y;
|
|
20
|
+
if (z < min[2])
|
|
21
|
+
min[2] = z;
|
|
22
|
+
if (x > max[0])
|
|
23
|
+
max[0] = x;
|
|
24
|
+
if (y > max[1])
|
|
25
|
+
max[1] = y;
|
|
26
|
+
if (z > max[2])
|
|
27
|
+
max[2] = z;
|
|
28
|
+
}
|
|
29
|
+
const boundingBox = { min, max };
|
|
30
|
+
validateBoundingBox(boundingBox);
|
|
31
|
+
return boundingBox;
|
|
24
32
|
}
|
|
25
33
|
function validateBoundingBox(boundingBox) {
|
|
26
|
-
|
|
34
|
+
assert(Number.isFinite(boundingBox.min[0]) &&
|
|
35
|
+
Number.isFinite(boundingBox.min[1]) &&
|
|
36
|
+
Number.isFinite(boundingBox.min[2]) &&
|
|
37
|
+
Number.isFinite(boundingBox.max[0]) &&
|
|
38
|
+
Number.isFinite(boundingBox.max[1]) &&
|
|
39
|
+
Number.isFinite(boundingBox.max[2]));
|
|
27
40
|
}
|
|
28
|
-
//# sourceMappingURL=compute-bounding-box.js.map
|
|
@@ -1,2 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
import {getPositions} from './get-attribute-from-geometry';
|
|
1
5
|
|
|
2
|
-
|
|
6
|
+
export function computeBoundingSphere(geometry: any, boundingBox: object, vector: Vector3 ) {
|
|
7
|
+
const positions = getPositions(geometry);
|
|
8
|
+
|
|
9
|
+
const center = getBoundingBox(center);
|
|
10
|
+
box.setFromBufferAttribute(position);
|
|
11
|
+
box.getCenter(center);
|
|
12
|
+
|
|
13
|
+
// hoping to find a boundingSphere with a radius smaller than the
|
|
14
|
+
// boundingSphere of the boundingBox: sqrt(3) smaller in the best case
|
|
15
|
+
|
|
16
|
+
var maxRadiusSq = 0;
|
|
17
|
+
|
|
18
|
+
for (const position of makeAttributeIterator(positions)) {
|
|
19
|
+
vector.x = position[0];
|
|
20
|
+
vector.y = position[1];
|
|
21
|
+
vector.z = position[2];
|
|
22
|
+
maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(vector));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const radius = Math.sqrt(maxRadiusSq);
|
|
26
|
+
assert(Number.isFinite(radius));
|
|
27
|
+
|
|
28
|
+
return {center, radius};
|
|
29
|
+
}
|
|
30
|
+
*/
|
|
@@ -1,2 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
export function computeTangents({indices, positions, normals, uvs}) {
|
|
4
|
+
var index = geometry.index;
|
|
5
|
+
var attributes = geometry.attributes;
|
|
1
6
|
|
|
2
|
-
|
|
7
|
+
// based on http://www.terathon.com/code/tangent.html
|
|
8
|
+
// (per vertex tangents)
|
|
9
|
+
|
|
10
|
+
if (
|
|
11
|
+
index === null ||
|
|
12
|
+
attributes.position === undefined ||
|
|
13
|
+
attributes.normal === undefined ||
|
|
14
|
+
attributes.uv === undefined
|
|
15
|
+
) {
|
|
16
|
+
console.warn(
|
|
17
|
+
'THREE.BufferGeometry: Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()'
|
|
18
|
+
);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var nVertices = positions.length / 3;
|
|
23
|
+
|
|
24
|
+
var tangents = new Float32Array(4 * nVertices); // size: 4
|
|
25
|
+
|
|
26
|
+
var tan1 = [],
|
|
27
|
+
tan2 = [];
|
|
28
|
+
|
|
29
|
+
for (var k = 0; k < nVertices; k++) {
|
|
30
|
+
tan1[k] = new THREE.Vector3();
|
|
31
|
+
tan2[k] = new THREE.Vector3();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var vA = new THREE.Vector3(),
|
|
35
|
+
vB = new THREE.Vector3(),
|
|
36
|
+
vC = new THREE.Vector3(),
|
|
37
|
+
uvA = new THREE.Vector2(),
|
|
38
|
+
uvB = new THREE.Vector2(),
|
|
39
|
+
uvC = new THREE.Vector2(),
|
|
40
|
+
sdir = new THREE.Vector3(),
|
|
41
|
+
tdir = new THREE.Vector3();
|
|
42
|
+
|
|
43
|
+
function handleTriangle(a, b, c) {
|
|
44
|
+
vA.fromArray(positions, a * 3);
|
|
45
|
+
vB.fromArray(positions, b * 3);
|
|
46
|
+
vC.fromArray(positions, c * 3);
|
|
47
|
+
|
|
48
|
+
uvA.fromArray(uvs, a * 2);
|
|
49
|
+
uvB.fromArray(uvs, b * 2);
|
|
50
|
+
uvC.fromArray(uvs, c * 2);
|
|
51
|
+
|
|
52
|
+
var x1 = vB.x - vA.x;
|
|
53
|
+
var x2 = vC.x - vA.x;
|
|
54
|
+
|
|
55
|
+
var y1 = vB.y - vA.y;
|
|
56
|
+
var y2 = vC.y - vA.y;
|
|
57
|
+
|
|
58
|
+
var z1 = vB.z - vA.z;
|
|
59
|
+
var z2 = vC.z - vA.z;
|
|
60
|
+
|
|
61
|
+
var s1 = uvB.x - uvA.x;
|
|
62
|
+
var s2 = uvC.x - uvA.x;
|
|
63
|
+
|
|
64
|
+
var t1 = uvB.y - uvA.y;
|
|
65
|
+
var t2 = uvC.y - uvA.y;
|
|
66
|
+
|
|
67
|
+
var r = 1.0 / (s1 * t2 - s2 * t1);
|
|
68
|
+
|
|
69
|
+
sdir.set((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
|
|
70
|
+
|
|
71
|
+
tdir.set((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);
|
|
72
|
+
|
|
73
|
+
tan1[a].add(sdir);
|
|
74
|
+
tan1[b].add(sdir);
|
|
75
|
+
tan1[c].add(sdir);
|
|
76
|
+
|
|
77
|
+
tan2[a].add(tdir);
|
|
78
|
+
tan2[b].add(tdir);
|
|
79
|
+
tan2[c].add(tdir);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
var groups = geometry.groups;
|
|
83
|
+
|
|
84
|
+
if (groups.length === 0) {
|
|
85
|
+
groups = [
|
|
86
|
+
{
|
|
87
|
+
start: 0,
|
|
88
|
+
count: indices.length
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (var j = 0, jl = groups.length; j < jl; ++j) {
|
|
94
|
+
var group = groups[j];
|
|
95
|
+
|
|
96
|
+
var start = group.start;
|
|
97
|
+
var count = group.count;
|
|
98
|
+
|
|
99
|
+
for (var i = start, il = start + count; i < il; i += 3) {
|
|
100
|
+
handleTriangle(indices[i + 0], indices[i + 1], indices[i + 2]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var tmp = new THREE.Vector3(),
|
|
105
|
+
tmp2 = new THREE.Vector3();
|
|
106
|
+
var n = new THREE.Vector3(),
|
|
107
|
+
n2 = new THREE.Vector3();
|
|
108
|
+
var w, t, test;
|
|
109
|
+
|
|
110
|
+
function handleVertex(v) {
|
|
111
|
+
n.fromArray(normals, v * 3);
|
|
112
|
+
n2.copy(n);
|
|
113
|
+
|
|
114
|
+
t = tan1[v];
|
|
115
|
+
|
|
116
|
+
// Gram-Schmidt orthogonalize
|
|
117
|
+
|
|
118
|
+
tmp.copy(t);
|
|
119
|
+
tmp.sub(n.multiplyScalar(n.dot(t))).normalize();
|
|
120
|
+
|
|
121
|
+
// Calculate handedness
|
|
122
|
+
|
|
123
|
+
tmp2.crossVectors(n2, t);
|
|
124
|
+
test = tmp2.dot(tan2[v]);
|
|
125
|
+
w = test < 0.0 ? -1.0 : 1.0;
|
|
126
|
+
|
|
127
|
+
tangents[v * 4] = tmp.x;
|
|
128
|
+
tangents[v * 4 + 1] = tmp.y;
|
|
129
|
+
tangents[v * 4 + 2] = tmp.z;
|
|
130
|
+
tangents[v * 4 + 3] = w;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
for (var j = 0, jl = groups.length; j < jl; ++j) {
|
|
134
|
+
var group = groups[j];
|
|
135
|
+
|
|
136
|
+
var start = group.start;
|
|
137
|
+
var count = group.count;
|
|
138
|
+
|
|
139
|
+
for (var i = start, il = start + count; i < il; i += 3) {
|
|
140
|
+
handleVertex(indices[i + 0]);
|
|
141
|
+
handleVertex(indices[i + 1]);
|
|
142
|
+
handleVertex(indices[i + 2]);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
*/
|
|
@@ -4,38 +4,41 @@ import { assert } from "../utils/assert.js";
|
|
|
4
4
|
import { makePrimitiveIterator } from "../iterators/primitive-iterator.js";
|
|
5
5
|
import { getPrimitiveModeType } from "../primitives/modes.js";
|
|
6
6
|
import { getPositions } from "./get-attribute-from-geometry.js";
|
|
7
|
+
/**
|
|
8
|
+
* Computes vertex normals for a geometry
|
|
9
|
+
* @param param0
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line max-statements
|
|
7
13
|
export function computeVertexNormals(geometry) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
values: positions
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
normals
|
|
38
|
-
}
|
|
39
|
-
return normals;
|
|
14
|
+
// Only support GL.TRIANGLES, GL.TRIANGLE_STRIP, GL.TRIANGLE_FAN
|
|
15
|
+
assert(getPrimitiveModeType(geometry.mode) === GL.TRIANGLES, 'TRIANGLES required');
|
|
16
|
+
const { values: positions } = getPositions(geometry);
|
|
17
|
+
const normals = new Float32Array(positions.length);
|
|
18
|
+
const vectorA = new Vector3();
|
|
19
|
+
const vectorB = new Vector3();
|
|
20
|
+
const vectorC = new Vector3();
|
|
21
|
+
const vectorCB = new Vector3();
|
|
22
|
+
const vectorAB = new Vector3();
|
|
23
|
+
for (const primitive of makePrimitiveIterator(geometry)) {
|
|
24
|
+
vectorA.fromArray(positions, primitive.i1 * 3);
|
|
25
|
+
vectorB.fromArray(positions, primitive.i2 * 3 + 3);
|
|
26
|
+
vectorC.fromArray(positions, primitive.i3 * 3 + 6);
|
|
27
|
+
vectorCB.subVectors(vectorC, vectorB);
|
|
28
|
+
vectorAB.subVectors(vectorA, vectorB);
|
|
29
|
+
const normal = vectorCB.cross(vectorAB);
|
|
30
|
+
normal.normalize();
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
const { primitiveIndex } = primitive;
|
|
33
|
+
normals[primitiveIndex * 9 + 0] = normal.x;
|
|
34
|
+
normals[primitiveIndex * 9 + 1] = normal.y;
|
|
35
|
+
normals[primitiveIndex * 9 + 2] = normal.z;
|
|
36
|
+
normals[primitiveIndex * 9 + 3] = normal.x;
|
|
37
|
+
normals[primitiveIndex * 9 + 4] = normal.y;
|
|
38
|
+
normals[primitiveIndex * 9 + 5] = normal.z;
|
|
39
|
+
normals[primitiveIndex * 9 + 6] = normal.x;
|
|
40
|
+
normals[primitiveIndex * 9 + 7] = normal.y;
|
|
41
|
+
normals[primitiveIndex * 9 + 8] = normal.z;
|
|
42
|
+
}
|
|
43
|
+
return normals;
|
|
40
44
|
}
|
|
41
|
-
//# sourceMappingURL=compute-vertex-normals.js.map
|
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
/**
|
|
4
|
+
* Converts indices of geometry.
|
|
5
|
+
*
|
|
6
|
+
* @param param0
|
|
7
|
+
* @returns no indexed geometry
|
|
8
|
+
*/
|
|
9
|
+
export function convertBuffersToNonIndexed({ indices, attributes }) {
|
|
10
|
+
const geometry2 = new BufferGeometry();
|
|
11
|
+
for (const name in attributes) {
|
|
12
|
+
const attribute = attributes[name];
|
|
13
|
+
const array = attribute.array;
|
|
14
|
+
const itemSize = attribute.itemSize;
|
|
15
|
+
const array2 = new array.constructor(indices.length * itemSize);
|
|
16
|
+
let index = 0, index2 = 0;
|
|
17
|
+
for (var i = 0, l = indices.length; i < l; i++) {
|
|
18
|
+
index = indices[i] * itemSize;
|
|
19
|
+
for (var j = 0; j < itemSize; j++) {
|
|
20
|
+
array2[index2++] = array[index++];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
geometry2.addAttribute(name, new BufferAttribute(array2, itemSize));
|
|
19
24
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
geometry2
|
|
24
|
-
}
|
|
25
|
-
return geometry2;
|
|
25
|
+
for (const group of this.groups) {
|
|
26
|
+
geometry2.addGroup(group.start, group.count, group.materialIndex);
|
|
27
|
+
}
|
|
28
|
+
return geometry2;
|
|
26
29
|
}
|
|
27
|
-
//# sourceMappingURL=convert-to-non-indexed.js.map
|
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import isGeometry from "../is-geometry.js";
|
|
2
2
|
import { assert } from "../utils/assert.js";
|
|
3
|
+
/**
|
|
4
|
+
* analyze positions of geometry
|
|
5
|
+
*
|
|
6
|
+
* @param geometry
|
|
7
|
+
* @returns Position| New geometry |assert
|
|
8
|
+
*/
|
|
3
9
|
export function getPositions(geometry) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
return assert(false);
|
|
10
|
+
// If geometry, extract positions
|
|
11
|
+
if (isGeometry(geometry)) {
|
|
12
|
+
const { attributes } = geometry;
|
|
13
|
+
const position = attributes.POSITION || attributes.positions;
|
|
14
|
+
assert(position);
|
|
15
|
+
return position;
|
|
16
|
+
}
|
|
17
|
+
// If arraybuffer, assume 3 components
|
|
18
|
+
if (ArrayBuffer.isView(geometry)) {
|
|
19
|
+
return { values: geometry, size: 3 };
|
|
20
|
+
}
|
|
21
|
+
// Else assume accessor object
|
|
22
|
+
if (geometry) {
|
|
23
|
+
assert(geometry.values);
|
|
24
|
+
return geometry;
|
|
25
|
+
}
|
|
26
|
+
return assert(false);
|
|
23
27
|
}
|
|
24
|
-
//# sourceMappingURL=get-attribute-from-geometry.js.map
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Setting X, Y, Z for Vector
|
|
3
|
+
* @param normals
|
|
4
|
+
* @param vector
|
|
5
|
+
*/
|
|
6
|
+
export function normalize(normals = {}, vector) {
|
|
7
|
+
//@ts-ignore
|
|
8
|
+
normals = this.attributes.normal;
|
|
9
|
+
for (let i = 0, il = normals.count; i < il; i++) {
|
|
10
|
+
vector.x = normals.getX(i);
|
|
11
|
+
vector.y = normals.getY(i);
|
|
12
|
+
vector.z = normals.getZ(i);
|
|
13
|
+
vector.normalize();
|
|
14
|
+
normals.setXYZ(i, vector.x, vector.y, vector.z);
|
|
15
|
+
}
|
|
12
16
|
}
|
|
13
|
-
//# sourceMappingURL=normalize.js.map
|
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Decode color values
|
|
3
|
+
* @param rgb565
|
|
4
|
+
* @param target
|
|
5
|
+
* @returns target
|
|
6
|
+
*/
|
|
7
|
+
export function decodeRGB565(rgb565, target = [0, 0, 0]) {
|
|
8
|
+
const r5 = (rgb565 >> 11) & 31;
|
|
9
|
+
const g6 = (rgb565 >> 5) & 63;
|
|
10
|
+
const b5 = rgb565 & 31;
|
|
11
|
+
target[0] = r5 << 3;
|
|
12
|
+
target[1] = g6 << 2;
|
|
13
|
+
target[2] = b5 << 3;
|
|
14
|
+
return target;
|
|
10
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Encode color values
|
|
18
|
+
* @param rgb
|
|
19
|
+
* @returns color
|
|
20
|
+
*/
|
|
11
21
|
export function encodeRGB565(rgb) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
const r5 = Math.floor(rgb[0] / 8) + 4;
|
|
23
|
+
const g6 = Math.floor(rgb[1] / 4) + 2;
|
|
24
|
+
const b5 = Math.floor(rgb[2] / 8) + 4;
|
|
25
|
+
return r5 + (g6 << 5) + (b5 << 11);
|
|
16
26
|
}
|
|
17
|
-
//# sourceMappingURL=rgb565.js.map
|