@navaramap/worker 0.0.0
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/LICENSE +8 -0
- package/README.md +3 -0
- package/dist/helpers/transferConstructedPolygonGeometry.d.ts +6 -0
- package/dist/helpers/transferConstructedPolylineGeometry.d.ts +6 -0
- package/dist/helpers/transferReturnedConstructedTerrainMesh.d.ts +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3203 -0
- package/dist/index.umd.cjs +11 -0
- package/dist/manager.d.ts +19 -0
- package/dist/pool.d.ts +17 -0
- package/dist/recyclingPool.d.ts +86 -0
- package/dist/tasks/constructPolygonBatchedFeature.d.ts +2 -0
- package/dist/tasks/constructPolylineBatchedFeature.d.ts +2 -0
- package/dist/tasks/constructQuantizedMeshTerrainMesh.d.ts +4 -0
- package/dist/tasks/constructTerrainMesh.d.ts +4 -0
- package/dist/tasks/getImageDataFromBlob.d.ts +12 -0
- package/dist/tasks/getImageDataFromImageBitmap.d.ts +1 -0
- package/dist/tasks/index.d.ts +26 -0
- package/dist/tasks/parseMvtTile.d.ts +15 -0
- package/dist/tasks/upsampleQuantizedMeshTerrainMesh.d.ts +2 -0
- package/dist/tasks/upsampleTerrainMesh.d.ts +2 -0
- package/dist/tasks/waitWasm.d.ts +8 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/toExtentRadianF32Like.d.ts +3 -0
- package/dist/utils/toPolygonMaterialLike.d.ts +3 -0
- package/dist/utils/toPolylineMaterialLike.d.ts +3 -0
- package/dist/utils/toTransferableMartiniLike.d.ts +3 -0
- package/dist/utils/toTransferablePolygonBatchedFeatureLike.d.ts +3 -0
- package/dist/utils/toTransferablePolylineBatchedFeatureLike.d.ts +3 -0
- package/dist/utils/toTransferableRasterDEMDataLike.d.ts +3 -0
- package/dist/utils/toTransferableTileLike.d.ts +5 -0
- package/dist/utils/toUpsamplableTerrainGeometryLike.d.ts +3 -0
- package/dist/utils/toVec3Like.d.ts +3 -0
- package/dist/worker/index.d.ts +4 -0
- package/dist/worker/transfer.d.ts +1 -0
- package/package.json +37 -0
- package/src/helpers/transferConstructedPolygonGeometry.ts +25 -0
- package/src/helpers/transferConstructedPolylineGeometry.ts +28 -0
- package/src/helpers/transferReturnedConstructedTerrainMesh.ts +21 -0
- package/src/index.ts +4 -0
- package/src/manager.test.ts +45 -0
- package/src/manager.ts +43 -0
- package/src/pool.test.ts +87 -0
- package/src/pool.ts +150 -0
- package/src/recyclingPool.test.ts +404 -0
- package/src/recyclingPool.ts +385 -0
- package/src/tasks/constructPolygonBatchedFeature.ts +40 -0
- package/src/tasks/constructPolylineBatchedFeature.ts +36 -0
- package/src/tasks/constructQuantizedMeshTerrainMesh.ts +36 -0
- package/src/tasks/constructTerrainMesh.ts +44 -0
- package/src/tasks/getImageDataFromBlob.ts +30 -0
- package/src/tasks/getImageDataFromImageBitmap.ts +19 -0
- package/src/tasks/index.ts +31 -0
- package/src/tasks/parseMvtTile.ts +67 -0
- package/src/tasks/upsampleQuantizedMeshTerrainMesh.ts +38 -0
- package/src/tasks/upsampleTerrainMesh.ts +40 -0
- package/src/tasks/waitWasm.ts +19 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/toExtentRadianF32Like.ts +6 -0
- package/src/utils/toPolygonMaterialLike.ts +20 -0
- package/src/utils/toPolylineMaterialLike.ts +17 -0
- package/src/utils/toTransferableMartiniLike.ts +6 -0
- package/src/utils/toTransferablePolygonBatchedFeatureLike.ts +41 -0
- package/src/utils/toTransferablePolylineBatchedFeatureLike.ts +21 -0
- package/src/utils/toTransferableRasterDEMDataLike.ts +22 -0
- package/src/utils/toTransferableTileLike.ts +34 -0
- package/src/utils/toUpsamplableTerrainGeometryLike.ts +14 -0
- package/src/utils/toVec3Like.ts +6 -0
- package/src/vite-env.d.ts +1 -0
- package/src/worker/index.ts +44 -0
- package/src/worker/transfer.ts +6 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReturnedConstructedTerrainMeshLike,
|
|
3
|
+
TransferableTileLike,
|
|
4
|
+
UpsamplableTerrainGeometryLike,
|
|
5
|
+
} from "@navaramap/core";
|
|
6
|
+
import { upsampleQuantizedMeshTerrainMesh as upsampleQuantizedMeshTerrainMeshImpl } from "@navaramap/engine-worker";
|
|
7
|
+
|
|
8
|
+
import { transfer } from "..";
|
|
9
|
+
import { transferReturnedConstructedTerrainMesh } from "../helpers/transferReturnedConstructedTerrainMesh";
|
|
10
|
+
import { toTransferableTile, toUpsamplableTerrainGeometry } from "../utils";
|
|
11
|
+
|
|
12
|
+
import { waitWasm } from "./waitWasm";
|
|
13
|
+
|
|
14
|
+
export async function upsampleQuantizedMeshTerrainMesh(
|
|
15
|
+
tile: TransferableTileLike,
|
|
16
|
+
parentTile: TransferableTileLike,
|
|
17
|
+
upsamplableGeometry: UpsamplableTerrainGeometryLike,
|
|
18
|
+
skirt: boolean,
|
|
19
|
+
skirtExaggeration: number,
|
|
20
|
+
geographic: boolean,
|
|
21
|
+
tms: boolean,
|
|
22
|
+
): Promise<ReturnedConstructedTerrainMeshLike> {
|
|
23
|
+
await waitWasm();
|
|
24
|
+
|
|
25
|
+
const mesh = upsampleQuantizedMeshTerrainMeshImpl(
|
|
26
|
+
toTransferableTile(tile),
|
|
27
|
+
toTransferableTile(parentTile),
|
|
28
|
+
toUpsamplableTerrainGeometry(upsamplableGeometry),
|
|
29
|
+
skirt,
|
|
30
|
+
skirtExaggeration,
|
|
31
|
+
geographic,
|
|
32
|
+
tms,
|
|
33
|
+
);
|
|
34
|
+
const { result, transfers } = transferReturnedConstructedTerrainMesh(mesh);
|
|
35
|
+
mesh.free();
|
|
36
|
+
|
|
37
|
+
return transfer(result, transfers);
|
|
38
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReturnedConstructedTerrainMeshLike,
|
|
3
|
+
TransferableRasterDEMDataLike,
|
|
4
|
+
TransferableTileLike,
|
|
5
|
+
UpsamplableTerrainGeometryLike,
|
|
6
|
+
} from "@navaramap/core";
|
|
7
|
+
import { upsampleTerrainMesh as upsampleTerrainMeshImpl } from "@navaramap/engine-worker";
|
|
8
|
+
|
|
9
|
+
import { transfer } from "..";
|
|
10
|
+
import { transferReturnedConstructedTerrainMesh } from "../helpers/transferReturnedConstructedTerrainMesh";
|
|
11
|
+
import { toTransferableTile, toUpsamplableTerrainGeometry } from "../utils";
|
|
12
|
+
import { toTransferableRasterDEMDataLike } from "../utils/toTransferableRasterDEMDataLike";
|
|
13
|
+
|
|
14
|
+
import { waitWasm } from "./waitWasm";
|
|
15
|
+
|
|
16
|
+
export async function upsampleTerrainMesh(
|
|
17
|
+
tile: TransferableTileLike,
|
|
18
|
+
parentTile: TransferableTileLike,
|
|
19
|
+
rasterDEMData: TransferableRasterDEMDataLike,
|
|
20
|
+
upsamplableGeometry: UpsamplableTerrainGeometryLike,
|
|
21
|
+
skirt: boolean,
|
|
22
|
+
skirtExaggeration: number,
|
|
23
|
+
tms: boolean,
|
|
24
|
+
): Promise<ReturnedConstructedTerrainMeshLike> {
|
|
25
|
+
await waitWasm();
|
|
26
|
+
|
|
27
|
+
const mesh = upsampleTerrainMeshImpl(
|
|
28
|
+
toTransferableTile(tile),
|
|
29
|
+
toTransferableTile(parentTile),
|
|
30
|
+
toTransferableRasterDEMDataLike(rasterDEMData),
|
|
31
|
+
toUpsamplableTerrainGeometry(upsamplableGeometry),
|
|
32
|
+
skirt,
|
|
33
|
+
skirtExaggeration,
|
|
34
|
+
tms,
|
|
35
|
+
);
|
|
36
|
+
const { result, transfers } = transferReturnedConstructedTerrainMesh(mesh);
|
|
37
|
+
mesh.free();
|
|
38
|
+
|
|
39
|
+
return transfer(result, transfers);
|
|
40
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import init, { type InitOutput } from "@navaramap/engine-worker";
|
|
2
|
+
|
|
3
|
+
let WASM: Promise<InitOutput> | undefined;
|
|
4
|
+
|
|
5
|
+
export async function waitWasm(): Promise<InitOutput> {
|
|
6
|
+
WASM ??= init();
|
|
7
|
+
return WASM;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Reports this worker's WASM linear memory size in bytes (0 when WASM is not
|
|
12
|
+
* initialized yet). Linear memory only grows, so the main thread probes this
|
|
13
|
+
* after settled tasks to decide when to recycle the worker.
|
|
14
|
+
*/
|
|
15
|
+
export async function getWasmMemoryUsage(): Promise<number> {
|
|
16
|
+
if (!WASM) return 0;
|
|
17
|
+
const { memory } = await WASM;
|
|
18
|
+
return memory.buffer.byteLength;
|
|
19
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ExtentRadianF32Like } from "@navaramap/core";
|
|
2
|
+
import { ExtentRadianF32 } from "@navaramap/engine-worker";
|
|
3
|
+
|
|
4
|
+
export function toExtentRadianF32Like(like: ExtentRadianF32Like) {
|
|
5
|
+
return new ExtentRadianF32(like.west, like.south, like.east, like.north);
|
|
6
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type PolygonMaterialLike } from "@navaramap/core";
|
|
2
|
+
import { PolygonMaterial } from "@navaramap/engine-worker";
|
|
3
|
+
|
|
4
|
+
export function toPolygonMaterialLike(like: PolygonMaterialLike) {
|
|
5
|
+
const mat = new PolygonMaterial(
|
|
6
|
+
like.show,
|
|
7
|
+
like.castShadow,
|
|
8
|
+
like.receiveShadow,
|
|
9
|
+
like.color,
|
|
10
|
+
like.clampToGround,
|
|
11
|
+
like.tiled,
|
|
12
|
+
like.height,
|
|
13
|
+
like.extrudedHeight,
|
|
14
|
+
like.wireframe,
|
|
15
|
+
like.outline,
|
|
16
|
+
like.perPositionHeight,
|
|
17
|
+
like.__internal__,
|
|
18
|
+
);
|
|
19
|
+
return mat;
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PolylineMaterialLike } from "@navaramap/core";
|
|
2
|
+
import { PolylineMaterial } from "@navaramap/engine-worker";
|
|
3
|
+
|
|
4
|
+
export function toPolylineMaterialLike(like: PolylineMaterialLike) {
|
|
5
|
+
return new PolylineMaterial(
|
|
6
|
+
like.show,
|
|
7
|
+
like.castShadow,
|
|
8
|
+
like.receiveShadow,
|
|
9
|
+
like.color,
|
|
10
|
+
like.clampToGround,
|
|
11
|
+
like.tiled,
|
|
12
|
+
like.height,
|
|
13
|
+
like.width,
|
|
14
|
+
like.maxWidth,
|
|
15
|
+
like.__internal__,
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { TransferablePolygonBatchedFeatureLike } from "@navaramap/core";
|
|
2
|
+
import { TransferablePolygonBatchedFeature } from "@navaramap/engine-worker";
|
|
3
|
+
|
|
4
|
+
export function toTransferablePolygonBatchedFeatureLike(
|
|
5
|
+
like: TransferablePolygonBatchedFeatureLike,
|
|
6
|
+
) {
|
|
7
|
+
const t = new TransferablePolygonBatchedFeature(like.crs, like.length);
|
|
8
|
+
|
|
9
|
+
t.setOuterRing(like.outer_ring.length, (b: Float64Array) => {
|
|
10
|
+
b.set(like.outer_ring);
|
|
11
|
+
});
|
|
12
|
+
t.setOuterRingSizes(like.outer_ring_sizes.length, (b: Uint32Array) => {
|
|
13
|
+
b.set(like.outer_ring_sizes);
|
|
14
|
+
});
|
|
15
|
+
t.setHoles(like.holes.length, (b: Float64Array) => {
|
|
16
|
+
b.set(like.holes);
|
|
17
|
+
});
|
|
18
|
+
t.setHolesSizes(like.holes_sizes.length, (b: Uint32Array) => {
|
|
19
|
+
b.set(like.holes_sizes);
|
|
20
|
+
});
|
|
21
|
+
t.setHolesTotalSizes(like.holes_total_sizes.length, (b: Uint32Array) => {
|
|
22
|
+
b.set(like.holes_total_sizes);
|
|
23
|
+
});
|
|
24
|
+
t.setHolesBoundaries(like.holes_boundaries.length, (b: Uint32Array) => {
|
|
25
|
+
b.set(like.holes_boundaries);
|
|
26
|
+
});
|
|
27
|
+
t.setExpectedWindingOrders(
|
|
28
|
+
like.expected_winding_orders.length,
|
|
29
|
+
(b: Uint32Array) => {
|
|
30
|
+
b.set(like.expected_winding_orders);
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
t.setBatchIds(like.batch_ids.length, (b: Uint32Array) => {
|
|
34
|
+
b.set(like.batch_ids);
|
|
35
|
+
});
|
|
36
|
+
t.setBatchIndices(like.batch_indices.length, (b: Uint32Array) => {
|
|
37
|
+
b.set(like.batch_indices);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return t;
|
|
41
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { TransferablePolylineBatchedFeatureLike } from "@navaramap/core";
|
|
2
|
+
import { TransferablePolylineBatchedFeature } from "@navaramap/engine-worker";
|
|
3
|
+
|
|
4
|
+
export function toTransferablePolylineBatchedFeatureLike(
|
|
5
|
+
like: TransferablePolylineBatchedFeatureLike,
|
|
6
|
+
) {
|
|
7
|
+
const t = new TransferablePolylineBatchedFeature(like.crs, like.length);
|
|
8
|
+
t.setPoints(like.points.length, (b: Float64Array) => {
|
|
9
|
+
b.set(like.points);
|
|
10
|
+
});
|
|
11
|
+
t.setPointsSizes(like.points_sizes.length, (b: Uint32Array) => {
|
|
12
|
+
b.set(like.points_sizes);
|
|
13
|
+
});
|
|
14
|
+
t.setBatchIds(like.batch_ids.length, (b: Uint32Array) => {
|
|
15
|
+
b.set(like.batch_ids);
|
|
16
|
+
});
|
|
17
|
+
t.setBatchIndices(like.batch_indices.length, (b: Uint32Array) => {
|
|
18
|
+
b.set(like.batch_indices);
|
|
19
|
+
});
|
|
20
|
+
return t;
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TransferableRasterDEMDataLike } from "@navaramap/core";
|
|
2
|
+
import {
|
|
3
|
+
ElevationDecoder,
|
|
4
|
+
TransferableRasterDEMData,
|
|
5
|
+
} from "@navaramap/engine-worker";
|
|
6
|
+
|
|
7
|
+
export function toTransferableRasterDEMDataLike(
|
|
8
|
+
like: TransferableRasterDEMDataLike,
|
|
9
|
+
) {
|
|
10
|
+
return new TransferableRasterDEMData(
|
|
11
|
+
new ElevationDecoder(
|
|
12
|
+
like.decoder.r_scaler,
|
|
13
|
+
like.decoder.g_scaler,
|
|
14
|
+
like.decoder.b_scaler,
|
|
15
|
+
like.decoder.offset,
|
|
16
|
+
like.decoder.max_offset,
|
|
17
|
+
like.decoder.min_offset,
|
|
18
|
+
like.decoder.boundary,
|
|
19
|
+
like.decoder.epsilon,
|
|
20
|
+
),
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TransferableTileLike,
|
|
3
|
+
TileXYZLike,
|
|
4
|
+
CachedMeshHandleLike,
|
|
5
|
+
} from "@navaramap/core";
|
|
6
|
+
import {
|
|
7
|
+
CachedMeshHandle,
|
|
8
|
+
TileXYZ,
|
|
9
|
+
TransferableTile,
|
|
10
|
+
} from "@navaramap/engine-worker";
|
|
11
|
+
|
|
12
|
+
export function toTransferableTile(like: TransferableTileLike) {
|
|
13
|
+
return new TransferableTile(
|
|
14
|
+
toTileXYZ(like.coords),
|
|
15
|
+
like.max_height,
|
|
16
|
+
like.min_height,
|
|
17
|
+
like.cached_mesh_handle
|
|
18
|
+
? toCachedMeshHandle(like.cached_mesh_handle)
|
|
19
|
+
: undefined,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function toTileXYZ(like: TileXYZLike) {
|
|
24
|
+
return new TileXYZ(like.x, like.y, like.z);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function toCachedMeshHandle(like: CachedMeshHandleLike) {
|
|
28
|
+
return new CachedMeshHandle(
|
|
29
|
+
like.vertices,
|
|
30
|
+
like.indices,
|
|
31
|
+
like.uvs,
|
|
32
|
+
like.heights,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { UpsamplableTerrainGeometryLike } from "@navaramap/core";
|
|
2
|
+
import { UpsamplableTerrainGeometry } from "@navaramap/engine-worker";
|
|
3
|
+
|
|
4
|
+
export function toUpsamplableTerrainGeometry(
|
|
5
|
+
like: UpsamplableTerrainGeometryLike,
|
|
6
|
+
) {
|
|
7
|
+
return new UpsamplableTerrainGeometry(
|
|
8
|
+
like.uvs,
|
|
9
|
+
like.indices,
|
|
10
|
+
like.heights,
|
|
11
|
+
like.normals,
|
|
12
|
+
like.watermask,
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import workerpool from "workerpool";
|
|
2
|
+
|
|
3
|
+
import { commonTasks } from "../tasks";
|
|
4
|
+
|
|
5
|
+
export { type CommonTasks } from "../tasks";
|
|
6
|
+
|
|
7
|
+
export * from "./transfer";
|
|
8
|
+
|
|
9
|
+
let isInitialized = false;
|
|
10
|
+
export const registerTasks = (
|
|
11
|
+
...args: Parameters<typeof workerpool.worker>
|
|
12
|
+
) => {
|
|
13
|
+
if (!isInitialized) {
|
|
14
|
+
workerpool.worker(commonTasks);
|
|
15
|
+
keepWorkerAliveOnAbort();
|
|
16
|
+
isInitialized = true;
|
|
17
|
+
}
|
|
18
|
+
return workerpool.worker(...args);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Register a no-op abort listener so a cancelled task does not terminate this
|
|
23
|
+
* worker. Without any listener, workerpool kills the worker on
|
|
24
|
+
* cancel-while-running and the next task pays a fresh WASM cold start
|
|
25
|
+
* (`minWorkers: 0`, so nothing re-warms it) — expensive under fast camera
|
|
26
|
+
* movement, where cancellations are routine. A synchronous WASM task cannot
|
|
27
|
+
* be interrupted anyway; letting it finish and dropping the result costs the
|
|
28
|
+
* same compute while keeping the warm worker in the pool.
|
|
29
|
+
*
|
|
30
|
+
* workerpool exposes `addAbortListener` only as a `worker` property it
|
|
31
|
+
* attaches to each registered method (`worker.methods[name].worker`), hence
|
|
32
|
+
* the lookup through a just-registered task.
|
|
33
|
+
*
|
|
34
|
+
* This only works together with the pool-side `workerTerminateTimeout` (see
|
|
35
|
+
* `recyclingPool.ts`): the busy worker cannot even receive the cleanup
|
|
36
|
+
* message until the running task finishes, so with the 1s default the pool
|
|
37
|
+
* would force-terminate it anyway for any task with more than ~1s remaining.
|
|
38
|
+
*/
|
|
39
|
+
function keepWorkerAliveOnAbort() {
|
|
40
|
+
const registered = commonTasks.warmUp as {
|
|
41
|
+
worker?: { addAbortListener: (listener: () => Promise<void>) => void };
|
|
42
|
+
};
|
|
43
|
+
registered.worker?.addAbortListener(async () => {});
|
|
44
|
+
}
|