使用 javascript 将 Three.js 网格发布到网络工作者 [英] Posting Three.js meshes to web worker using javascript

查看:17
本文介绍了使用 javascript 将 Three.js 网格发布到网络工作者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象数组,即使用 Three.js 创建的网格,我想在 Web Worker 中执行一些操作.所以问题是我如何将它们发布给工作人员?

I have an array on objects, meshes created with Three.js, that I want to do some operations in a web worker. So the questions is how do I post them to the worker?

据我所知,有一种叫做可转移对象的东西,它使用了一种叫做 ArrayBuffer 的东西,但我找不到任何关于如何将我的对象数组转换成它的信息.或者这可能是不可能的?

From what I understand there's something called transferable objects that uses something called ArrayBuffer but I can't find any info about how to convert my array of objects to that. Or is this perhaps not possible?

推荐答案

除非您的对象已经是二进制缓冲区格式,否则在将其转换为该格式并返回时不会带来性能优势.出于某种原因,这是大多数 Web Socket 用户无法掌握的东西——这样的问题一直被问到.我的回答总是一样的——如果你关心的是性能,不要转换任何东西:

Unless your object is already in binary buffer format, there is not performance benefit in converting it into that format and back. For some reason, this is something most Web Socket users fail to grasp - questions like this are asked all the time. My answer is always the same - if your concern is performance, do not convert anything:

只需使用普通的 ol':

Just use plain good ol':

worker.postMessage(myArray);

worker.postMessage(myArray);

如果您出于某种原因认为我对性能的看法有误,请随时使用此答案中的交互式代码段对我的声明进行事实检查:

If you for some reason think I'm wrong about the performance, feel free to fact-check my claims using interactive snippet in this answer:

这篇关于使用 javascript 将 Three.js 网格发布到网络工作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆