32 lines
1.9 KiB
JavaScript
32 lines
1.9 KiB
JavaScript
|
|
// Read-only local export verification; no scanner controls or business writes.
|
||
|
|
import fs from 'node:fs'
|
||
|
|
import { parseScannerModelAsync } from '../am-web/src/views/lab/scan-task/scannerModelWorker.mjs'
|
||
|
|
import { nodeModelWorker } from '../am-web/src/views/lab/scan-task/scannerModelWorkerTestHelper.mjs'
|
||
|
|
import { hydrateScannerModel } from '../am-web/src/views/lab/scan-task/scannerModelTransfer.mjs'
|
||
|
|
import { disposeScannerModel } from '../am-web/src/views/lab/scan-task/scannerModel.mjs'
|
||
|
|
|
||
|
|
if (!process.argv.slice(2).length) throw new Error('Provide local PLY/STL/OBJ file paths')
|
||
|
|
for (const path of process.argv.slice(2)) {
|
||
|
|
const bytes = fs.readFileSync(path)
|
||
|
|
const name = fs.existsSync(path + '.json')
|
||
|
|
? JSON.parse(fs.readFileSync(path + '.json', 'utf8')).name
|
||
|
|
: path.split(/[\\/]/).pop()
|
||
|
|
const started = performance.now()
|
||
|
|
let ticks = 0
|
||
|
|
const timer = setInterval(() => ticks++, 5)
|
||
|
|
try {
|
||
|
|
const data = await parseScannerModelAsync(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength), name, undefined, nodeModelWorker)
|
||
|
|
const hydrateStarted = performance.now()
|
||
|
|
const model = hydrateScannerModel(data)
|
||
|
|
try {
|
||
|
|
console.log(JSON.stringify({ name, bytes: bytes.byteLength,
|
||
|
|
vertices: model.vertices, triangles: model.triangles, points: model.points,
|
||
|
|
workerParseMs: Math.round(data.parseMs), hydrateMs: Math.round(performance.now() - hydrateStarted),
|
||
|
|
totalMs: Math.round(performance.now() - started), eventLoopTicks: ticks,
|
||
|
|
bounds: { min: model.bounds.min.toArray(), max: model.bounds.max.toArray() },
|
||
|
|
gpuBytes: data.drawables.reduce((sum, drawable) => sum + Object.values(drawable.attributes)
|
||
|
|
.reduce((size, attribute) => size + attribute.array.byteLength, 0) + (drawable.index?.byteLength || 0), 0) }))
|
||
|
|
} finally { disposeScannerModel(model.object) }
|
||
|
|
} finally { clearInterval(timer) }
|
||
|
|
}
|