| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- /**
- * 关键帧变换矩阵获取 Worker
- * 功能:异步获取关键帧变换矩阵(Protobuf 格式)
- */
- /**
- * 监听主线程消息
- */
- self.onmessage = function(event) {
- const { url, index } = event.data
-
- console.log(`[KeyframeTransWorker] 获取变换矩阵 ${index}:`, url)
-
- // 发送请求获取变换矩阵
- fetch(url, {
- method: 'GET',
- headers: {
- 'Content-Type': 'application/x-protobuf',
- 'Accept': 'application/x-protobuf'
- }
- })
- .then(response => {
- if (!response.ok) {
- throw new Error(`HTTP ${response.status}: ${response.statusText}`)
- }
- return response.arrayBuffer()
- })
- .then(arrayBuffer => {
- // 返回 Uint8Array 给主线程
- // 主线程会使用 Protobuf 解析这个数据
- // 数据包含:3x3 旋转矩阵 + 3D 平移向量 + 闭环索引
- const uint8Array = new Uint8Array(arrayBuffer)
- console.log(`[KeyframeTransWorker] 变换矩阵 ${index} 获取成功:`, uint8Array.length, 'bytes')
- self.postMessage({ type: 'success', data: uint8Array, index: index })
- })
- .catch((error) => {
- console.error(`[KeyframeTransWorker] 变换矩阵 ${index} 获取失败:`, error)
- self.postMessage({ type: 'error', error: error.message, index: index })
- })
- }
- /**
- * 错误处理
- */
- self.onerror = function(error) {
- console.error('Worker error:', error)
- }
|