boundary.worker.js
1.77 KB
1
2
3
4
5
6
7
8
9
10
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const _worker_getMaxMinZValue = `
getMaxMinZValue = (position, matrix) => {
const e = matrix.elements;
let xMin = yMin = zMin = Infinity;
let xMax = yMax = zMax = -Infinity;
let x, y, z, w;
let cx, cy, cz;
let i = position.array.length / 3 - 1;
while (i >= 0) {
x = position.array[ i * 3 + 0];
y = position.array[ i * 3 + 1];
z = position.array[ i * 3 + 2];
w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
cx = ( e[0] * x + e[4] * y + e[8] * z + e[12] ) * w;
cy = ( e[1] * x + e[5] * y + e[9] * z + e[13] ) * w;
cz = ( e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
xMin = Math.min(cx, xMin);
yMin = Math.min(cy, yMin);
zMin = Math.min(cz, zMin);
xMax = Math.max(cx, xMax);
yMax = Math.max(cy, yMax);
zMax = Math.max(cz, zMax);
--i;
}
return {
xMax, yMax, zMax, xMin, yMin, zMin
};
};
getMaxMinZValues = (positions,matrixs) => {
let vxMin = vyMin = vzMin = Infinity;
let vxMax = vyMax = vzMax = -Infinity;
positions.forEach((el , index) => {
const { xMax, yMax, zMax, xMin, yMin, zMin } = this.getMaxMinZValue(el, matrixs[index]);
vxMin = Math.min(xMin, vxMin);
vyMin = Math.min(yMin, vyMin);
vzMin = Math.min(zMin, vzMin);
vxMax = Math.max(xMax, vxMax);
vyMax = Math.max(yMax, vyMax);
vzMax = Math.max(zMax, vzMax);
});
return {
min: { x: vxMin, y: vyMin, z: vzMin },
max: { x: vxMax, y: vyMax, z: vzMax }
};
};
onmessage = (e) => {
const {id , positions , matrixs } = e.data;
const { max, min } = this.getMaxMinZValues(positions, matrixs);
postMessage({ id: id, response: { max, min } });
close();
};
`;
export { _worker_getMaxMinZValue };