使用 javascript 将 Three.js 网格发布到网络工作者

编程入门 行业动态 更新时间:2024-10-28 21:17:29
本文介绍了使用 javascript 将 Three.js 网格发布到网络工作者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个对象数组,即使用 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:

https://stackoverflow/a/33673378/607407https://stackoverflow/a/34061491/607407

只需使用普通的 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:

https://stackoverflow/a/33309300/607407

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

更多推荐

[db:关键词]

本文发布于:2023-04-30 14:44:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1395665.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   工作者   网络   javascript   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!