Files
QingAnVue2TV/src/components/DMT/libs/bvh/workers/generateMeshBVH.worker.js
DaLuJia Developer 2abd286d42 Initial commit: 大陆架零部件智能生产线数字孪生系统
- 实现TV1和TV2双大屏展示
- 集成ECharts数据可视化
- 实现实时数据刷新机制
- 添加刀具寿命管理模块
- 添加工单加工时长统计模块
- 添加加工中心7日工作时长统计模块
- 添加OEE分析、设备状态监控等功能
- 创建技术文档和使用说明书
2026-05-21 09:19:09 +08:00

79 lines
1.8 KiB
JavaScript

import {
BufferGeometry,
BufferAttribute
} from 'three'
import { MeshBVH } from '../core/MeshBVH.js'
onmessage = ({ data }) => {
let prevTime = performance.now()
function onProgressCallback(progress) {
// account for error
progress = Math.min(progress, 1)
const currTime = performance.now()
if (currTime - prevTime >= 10 && progress !== 1.0) {
postMessage({
error: null,
serialized: null,
position: null,
progress
})
prevTime = currTime
}
}
const { index, position, options } = data
try {
const geometry = new BufferGeometry()
geometry.setAttribute('position', new BufferAttribute(position, 3, false))
if (index) {
geometry.setIndex(new BufferAttribute(index, 1, false))
}
if (options.includedProgressCallback) {
options.onProgress = onProgressCallback
}
if (options.groups) {
const groups = options.groups
for (const i in groups) {
const group = groups[ i ]
geometry.addGroup(group.start, group.count, group.materialIndex)
}
}
const bvh = new MeshBVH(geometry, options)
const serialized = MeshBVH.serialize(bvh, { copyIndexBuffer: false })
let toTransfer = [position.buffer, ...serialized.roots]
if (serialized.index) {
toTransfer.push(serialized.index.buffer)
}
toTransfer = toTransfer.filter(v => (typeof SharedArrayBuffer === 'undefined') || !(v instanceof SharedArrayBuffer))
if (bvh._indirectBuffer) {
toTransfer.push(serialized.indirectBuffer.buffer)
}
postMessage({
error: null,
serialized,
position,
progress: 1
}, toTransfer)
} catch (error) {
postMessage({
error,
serialized: null,
position: null,
progress: 1
})
}
}