@manycore/aholo-splat-transform 1.2.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.
Files changed (88) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +33 -0
  3. package/bin/cli.js +118 -0
  4. package/dist/SplatData.d.ts +67 -0
  5. package/dist/SplatData.js +156 -0
  6. package/dist/constant.d.ts +3 -0
  7. package/dist/constant.js +13 -0
  8. package/dist/file/IFile.d.ts +5 -0
  9. package/dist/file/IFile.js +1 -0
  10. package/dist/file/index.d.ts +7 -0
  11. package/dist/file/index.js +6 -0
  12. package/dist/file/ksplat.d.ts +12 -0
  13. package/dist/file/ksplat.js +232 -0
  14. package/dist/file/lcc.d.ts +11 -0
  15. package/dist/file/lcc.js +157 -0
  16. package/dist/file/ply.d.ts +13 -0
  17. package/dist/file/ply.js +388 -0
  18. package/dist/file/sog.d.ts +80 -0
  19. package/dist/file/sog.js +504 -0
  20. package/dist/file/splat.d.ts +6 -0
  21. package/dist/file/splat.js +99 -0
  22. package/dist/file/spz.d.ts +8 -0
  23. package/dist/file/spz.js +400 -0
  24. package/dist/file/voxel.d.ts +37 -0
  25. package/dist/file/voxel.js +280 -0
  26. package/dist/index.d.ts +33 -0
  27. package/dist/index.js +54 -0
  28. package/dist/native/cpp/bin/linux/binding.node +0 -0
  29. package/dist/native/cpp/bin/windows/binding.node +0 -0
  30. package/dist/native/index.d.ts +54 -0
  31. package/dist/native/index.js +128 -0
  32. package/dist/tasks/AutoChunkLodTask.d.ts +13 -0
  33. package/dist/tasks/AutoChunkLodTask.js +117 -0
  34. package/dist/tasks/AutoLodTask.d.ts +10 -0
  35. package/dist/tasks/AutoLodTask.js +20 -0
  36. package/dist/tasks/BaseTask.d.ts +15 -0
  37. package/dist/tasks/BaseTask.js +5 -0
  38. package/dist/tasks/FlexLodTask.d.ts +12 -0
  39. package/dist/tasks/FlexLodTask.js +44 -0
  40. package/dist/tasks/ModifyTask.d.ts +9 -0
  41. package/dist/tasks/ModifyTask.js +156 -0
  42. package/dist/tasks/ReadTask.d.ts +8 -0
  43. package/dist/tasks/ReadTask.js +29 -0
  44. package/dist/tasks/SkeletonLodTask.d.ts +10 -0
  45. package/dist/tasks/SkeletonLodTask.js +156 -0
  46. package/dist/tasks/VoxelTask.d.ts +30 -0
  47. package/dist/tasks/VoxelTask.js +37 -0
  48. package/dist/tasks/WriteTask.d.ts +11 -0
  49. package/dist/tasks/WriteTask.js +70 -0
  50. package/dist/utils/BufferReader.d.ts +12 -0
  51. package/dist/utils/BufferReader.js +47 -0
  52. package/dist/utils/Logger.d.ts +11 -0
  53. package/dist/utils/Logger.js +38 -0
  54. package/dist/utils/StreamChunkDecoder.d.ts +16 -0
  55. package/dist/utils/StreamChunkDecoder.js +36 -0
  56. package/dist/utils/index.d.ts +27 -0
  57. package/dist/utils/index.js +101 -0
  58. package/dist/utils/k-means.d.ts +4 -0
  59. package/dist/utils/k-means.js +350 -0
  60. package/dist/utils/math.d.ts +46 -0
  61. package/dist/utils/math.js +351 -0
  62. package/dist/utils/quantize-1d.d.ts +4 -0
  63. package/dist/utils/quantize-1d.js +164 -0
  64. package/dist/utils/sh-rotate.d.ts +2 -0
  65. package/dist/utils/sh-rotate.js +175 -0
  66. package/dist/utils/splat.d.ts +20 -0
  67. package/dist/utils/splat.js +378 -0
  68. package/dist/utils/voxel/common.d.ts +162 -0
  69. package/dist/utils/voxel/common.js +1700 -0
  70. package/dist/utils/voxel/coplanar-merge.d.ts +63 -0
  71. package/dist/utils/voxel/coplanar-merge.js +819 -0
  72. package/dist/utils/voxel/gpu-dilation.d.ts +2 -0
  73. package/dist/utils/voxel/gpu-dilation.js +665 -0
  74. package/dist/utils/voxel/marching-cubes.d.ts +42 -0
  75. package/dist/utils/voxel/marching-cubes.js +1657 -0
  76. package/dist/utils/voxel/mesh.d.ts +3 -0
  77. package/dist/utils/voxel/mesh.js +130 -0
  78. package/dist/utils/voxel/nav.d.ts +29 -0
  79. package/dist/utils/voxel/nav.js +1043 -0
  80. package/dist/utils/voxel/postprocess.d.ts +23 -0
  81. package/dist/utils/voxel/postprocess.js +375 -0
  82. package/dist/utils/voxel/voxel-faces.d.ts +18 -0
  83. package/dist/utils/voxel/voxel-faces.js +663 -0
  84. package/dist/utils/voxel/voxelize.d.ts +33 -0
  85. package/dist/utils/voxel/voxelize.js +1193 -0
  86. package/dist/utils/webgpu.d.ts +8 -0
  87. package/dist/utils/webgpu.js +122 -0
  88. package/package.json +32 -0
@@ -0,0 +1,11 @@
1
+ import { Context, BaseTask } from './BaseTask.js';
2
+ export interface Config {
3
+ input: string;
4
+ output: string;
5
+ enableMortonSort?: boolean;
6
+ compressLevel?: number;
7
+ }
8
+ export declare class WriteTask extends BaseTask<Config> {
9
+ exec(config: Config, { logger, resources }: Context): Promise<void>;
10
+ requiresGPU(config: Config): boolean;
11
+ }
@@ -0,0 +1,70 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { Writable } from 'node:stream';
4
+ import { SplatData } from '../SplatData.js';
5
+ import { createSplatFile, detectSplatFileType, SplatFileType } from '../utils/index.js';
6
+ import { BaseTask } from './BaseTask.js';
7
+ async function writeSplatFile(filepath, data, enableMortonSort, compressLevel) {
8
+ let indices;
9
+ if (!enableMortonSort) {
10
+ indices = new Uint32Array(data.counts);
11
+ for (let i = 0; i < data.counts; i++) {
12
+ indices[i] = i;
13
+ }
14
+ }
15
+ const file = createSplatFile(filepath, undefined, compressLevel);
16
+ const stream = Writable.toWeb(fs.createWriteStream(filepath));
17
+ await file.write(stream, data, indices);
18
+ }
19
+ export class WriteTask extends BaseTask {
20
+ async exec(config, { logger, resources }) {
21
+ const { input, output, enableMortonSort = true, compressLevel } = config;
22
+ const source = resources.get(input);
23
+ if (source instanceof SplatData) {
24
+ logger.info(`writing splat -> file="${output}" count=${source.counts} SH=${source.shDegree}`);
25
+ await writeSplatFile(output, source, enableMortonSort, compressLevel);
26
+ logger.info(`writing done`);
27
+ return;
28
+ }
29
+ if (fs.existsSync(output)) {
30
+ fs.rmSync(output, { recursive: true });
31
+ logger.info(`exist dir ${output}, removed`);
32
+ }
33
+ fs.mkdirSync(output);
34
+ logger.info(`writing bundle -> dir="${output}" files=${source.length}`);
35
+ logger.silent = true;
36
+ const sogList = [];
37
+ const promises = [];
38
+ let idx = 1;
39
+ const totals = source.length;
40
+ for (let i = 0; i < source.length; i++) {
41
+ const { name, content, preserveOrder = false } = source[i];
42
+ const filepath = path.join(output, name);
43
+ if (typeof content === 'string') {
44
+ logger.info(`- ${filepath} (${idx++}/${totals})`, true);
45
+ fs.writeFileSync(filepath, content);
46
+ continue;
47
+ }
48
+ const type = detectSplatFileType(filepath);
49
+ if (type === SplatFileType.SOG) {
50
+ sogList.push({ name, content: content });
51
+ continue;
52
+ }
53
+ logger.info(`- ${filepath} (${idx++}/${totals})`, true);
54
+ const promise = writeSplatFile(filepath, content, enableMortonSort && !preserveOrder, compressLevel);
55
+ promises.push(promise);
56
+ }
57
+ await Promise.all(promises);
58
+ for (let i = 0; i < sogList.length; i++) {
59
+ const { name, content } = sogList[i];
60
+ const filepath = path.join(output, name);
61
+ logger.info(`- ${filepath} (${idx++}/${totals})`, true);
62
+ await writeSplatFile(filepath, content, false);
63
+ }
64
+ logger.silent = false;
65
+ logger.info(`writing bundle done -> dir="${output}" files=${source.length}`);
66
+ }
67
+ requiresGPU(config) {
68
+ return config.output.endsWith('sog');
69
+ }
70
+ }
@@ -0,0 +1,12 @@
1
+ export declare class BufferReader {
2
+ head: number;
3
+ tail: number;
4
+ buffer: Uint8Array;
5
+ view: DataView;
6
+ get remaining(): number;
7
+ constructor(buffer?: Uint8Array);
8
+ private grow;
9
+ private compact;
10
+ write(chunk: Uint8Array): void;
11
+ read(counts: number): Uint8Array;
12
+ }
@@ -0,0 +1,47 @@
1
+ export class BufferReader {
2
+ head = 0;
3
+ tail = 0;
4
+ buffer;
5
+ view;
6
+ get remaining() {
7
+ return this.tail - this.head;
8
+ }
9
+ constructor(buffer = new Uint8Array()) {
10
+ this.buffer = buffer;
11
+ this.view = new DataView(this.buffer.buffer);
12
+ }
13
+ grow(required) {
14
+ const newCap = Math.max(required, this.buffer.length * 2);
15
+ const next = new Uint8Array(newCap);
16
+ next.set(this.buffer.subarray(this.head, this.tail), 0);
17
+ this.tail -= this.head;
18
+ this.head = 0;
19
+ this.buffer = next;
20
+ this.view = new DataView(next.buffer);
21
+ }
22
+ compact() {
23
+ if (this.head === 0) {
24
+ return;
25
+ }
26
+ this.buffer.copyWithin(0, this.head, this.tail);
27
+ this.tail -= this.head;
28
+ this.head = 0;
29
+ }
30
+ write(chunk) {
31
+ const remaining = this.tail - this.head;
32
+ const required = remaining + chunk.length;
33
+ if (this.buffer.length < required) {
34
+ this.grow(required);
35
+ }
36
+ else if (this.head > 0 && this.buffer.length - this.tail < chunk.length) {
37
+ this.compact();
38
+ }
39
+ this.buffer.set(chunk, this.tail);
40
+ this.tail += chunk.length;
41
+ }
42
+ read(counts) {
43
+ const head = this.head;
44
+ const tail = this.head = head + counts;
45
+ return this.buffer.subarray(head, tail);
46
+ }
47
+ }
@@ -0,0 +1,11 @@
1
+ export declare class Logger {
2
+ prefix: string;
3
+ silent: boolean;
4
+ private format;
5
+ info(msg: string, force?: boolean): void;
6
+ warn(msg: string, force?: boolean): void;
7
+ error(msg: string, force?: boolean): void;
8
+ time(label: string): void;
9
+ timeEnd(label: string): void;
10
+ }
11
+ export declare const logger: Logger;
@@ -0,0 +1,38 @@
1
+ export class Logger {
2
+ prefix = '';
3
+ silent = false;
4
+ format(msg) {
5
+ return this.prefix ? `${this.prefix} ${msg}` : msg;
6
+ }
7
+ info(msg, force = false) {
8
+ if (this.silent && !force) {
9
+ return;
10
+ }
11
+ console.log(this.format(msg));
12
+ }
13
+ warn(msg, force = false) {
14
+ if (this.silent && !force) {
15
+ return;
16
+ }
17
+ console.warn(this.format(msg));
18
+ }
19
+ error(msg, force = false) {
20
+ if (this.silent && !force) {
21
+ return;
22
+ }
23
+ console.error(this.format(msg));
24
+ }
25
+ time(label) {
26
+ if (this.silent) {
27
+ return;
28
+ }
29
+ console.time(this.format(label));
30
+ }
31
+ timeEnd(label) {
32
+ if (this.silent) {
33
+ return;
34
+ }
35
+ console.timeEnd(this.format(label));
36
+ }
37
+ }
38
+ export const logger = new Logger();
@@ -0,0 +1,16 @@
1
+ import { BufferReader } from './BufferReader.js';
2
+ export interface ChunkDecoder {
3
+ init(): [number, number];
4
+ decode(offset: number, counts: number, buffer: Uint8Array): void;
5
+ }
6
+ export declare class StreamChunkDecoder {
7
+ private reader;
8
+ private decoders;
9
+ private decodedTotals;
10
+ private currentIndex;
11
+ private currentTotals;
12
+ private currentItemSize;
13
+ constructor(reader: BufferReader);
14
+ setDecoders(decoders: ChunkDecoder[]): void;
15
+ flush(): void;
16
+ }
@@ -0,0 +1,36 @@
1
+ export class StreamChunkDecoder {
2
+ reader;
3
+ decoders;
4
+ decodedTotals;
5
+ currentIndex = 0;
6
+ currentTotals;
7
+ currentItemSize;
8
+ constructor(reader) {
9
+ this.reader = reader;
10
+ }
11
+ setDecoders(decoders) {
12
+ this.decoders = decoders;
13
+ this.decodedTotals = new Uint32Array(decoders.length);
14
+ const [totals, itemSize] = decoders[this.currentIndex].init();
15
+ this.currentTotals = totals;
16
+ this.currentItemSize = itemSize;
17
+ }
18
+ flush() {
19
+ const { reader, decoders, decodedTotals, currentIndex, currentTotals, currentItemSize } = this;
20
+ const stage = decoders[currentIndex];
21
+ const decoded = decodedTotals[currentIndex];
22
+ const counts = Math.min(currentTotals - decoded, (reader.remaining / currentItemSize) | 0);
23
+ const buf = reader.read(counts * currentItemSize);
24
+ stage.decode(decoded, counts, buf);
25
+ decodedTotals[currentIndex] += counts;
26
+ if (decodedTotals[currentIndex] === currentTotals) {
27
+ this.currentIndex++;
28
+ if (this.currentIndex < decoders.length) {
29
+ const [totals, itemSize] = decoders[this.currentIndex].init();
30
+ this.currentTotals = totals;
31
+ this.currentItemSize = itemSize;
32
+ this.flush();
33
+ }
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,27 @@
1
+ interface Deferred<T = void> {
2
+ resolve: (value: T | PromiseLike<T>) => void;
3
+ reject: (reason: any) => void;
4
+ promise: Promise<T>;
5
+ }
6
+ export declare function deferred<T = void>(): Deferred<T>;
7
+ export declare function sleep(timeout: number): Promise<void>;
8
+ export declare function clamp(v: number, min: number, max: number): number;
9
+ export declare function isUrl(str: string): boolean;
10
+ export declare function extractFromRootDir(entries: Record<string, Uint8Array>): Record<string, Uint8Array>;
11
+ export declare function fromHalf(h: number): number;
12
+ export * from './Logger.js';
13
+ export * from './BufferReader.js';
14
+ export * from './StreamChunkDecoder.js';
15
+ export * from './math.js';
16
+ export * from './sh-rotate.js';
17
+ export * from './splat.js';
18
+ export * from './k-means.js';
19
+ export * from './quantize-1d.js';
20
+ export * from './webgpu.js';
21
+ export * from './voxel/common.js';
22
+ export * from './voxel/voxelize.js';
23
+ export * from './voxel/postprocess.js';
24
+ export * from './voxel/nav.js';
25
+ export * from './voxel/mesh.js';
26
+ export * from './voxel/voxel-faces.js';
27
+ export * from './voxel/gpu-dilation.js';
@@ -0,0 +1,101 @@
1
+ export function deferred() {
2
+ let resolve = () => { };
3
+ let reject = () => { };
4
+ const promise = new Promise(function (resolveInner, rejectInner) {
5
+ resolve = resolveInner;
6
+ reject = rejectInner;
7
+ });
8
+ return {
9
+ promise,
10
+ resolve,
11
+ reject,
12
+ };
13
+ }
14
+ export function sleep(timeout) {
15
+ return new Promise(resolve => {
16
+ setTimeout(resolve, timeout);
17
+ });
18
+ }
19
+ export function clamp(v, min, max) {
20
+ return Math.min(Math.max(v, min), max);
21
+ }
22
+ export function isUrl(str) {
23
+ let url;
24
+ try {
25
+ url = new URL(str);
26
+ }
27
+ catch {
28
+ return false;
29
+ }
30
+ return url.protocol === 'http:' || url.protocol === 'https:';
31
+ }
32
+ export function extractFromRootDir(entries) {
33
+ let dir = '';
34
+ for (const path in entries) {
35
+ if (path.endsWith('/')) {
36
+ dir = path;
37
+ break;
38
+ }
39
+ }
40
+ const result = {};
41
+ for (const path in entries) {
42
+ result[path.replace(dir, '')] = entries[path];
43
+ }
44
+ return result;
45
+ }
46
+ const f32buffer = new Float32Array(1);
47
+ const u32buffer = new Uint32Array(f32buffer.buffer);
48
+ export function fromHalf(h) {
49
+ const sign = (h >> 15) & 0x1;
50
+ const exp = (h >> 10) & 0x1f;
51
+ const frac = h & 0x3ff;
52
+ let f32bits;
53
+ if (exp === 0) {
54
+ if (frac === 0) {
55
+ f32bits = sign << 31;
56
+ }
57
+ else {
58
+ let mant = frac;
59
+ let e = -14;
60
+ while ((mant & 0x400) === 0) {
61
+ mant <<= 1;
62
+ e--;
63
+ }
64
+ mant &= 0x3ff;
65
+ const newExp = e + 127;
66
+ const newFrac = mant << 13;
67
+ f32bits = (sign << 31) | (newExp << 23) | newFrac;
68
+ }
69
+ }
70
+ else if (exp === 0x1f) {
71
+ if (frac === 0) {
72
+ f32bits = (sign << 31) | 0x7f800000;
73
+ }
74
+ else {
75
+ f32bits = (sign << 31) | 0x7fc00000;
76
+ }
77
+ }
78
+ else {
79
+ const newExp = exp - 15 + 127;
80
+ const newFrac = frac << 13;
81
+ f32bits = (sign << 31) | (newExp << 23) | newFrac;
82
+ }
83
+ u32buffer[0] = f32bits;
84
+ return f32buffer[0];
85
+ }
86
+ export * from './Logger.js';
87
+ export * from './BufferReader.js';
88
+ export * from './StreamChunkDecoder.js';
89
+ export * from './math.js';
90
+ export * from './sh-rotate.js';
91
+ export * from './splat.js';
92
+ export * from './k-means.js';
93
+ export * from './quantize-1d.js';
94
+ export * from './webgpu.js';
95
+ export * from './voxel/common.js';
96
+ export * from './voxel/voxelize.js';
97
+ export * from './voxel/postprocess.js';
98
+ export * from './voxel/nav.js';
99
+ export * from './voxel/mesh.js';
100
+ export * from './voxel/voxel-faces.js';
101
+ export * from './voxel/gpu-dilation.js';
@@ -0,0 +1,4 @@
1
+ export declare function kmeans(points: Float32Array[], k: number, iterations: number, device: GPUDevice): Promise<{
2
+ centroids: Float32Array<ArrayBufferLike>[];
3
+ labels: Uint32Array<ArrayBuffer>;
4
+ }>;