【问题标题】:How to pass an array with multiple mesh objects如何传递具有多个网格对象的数组
【发布时间】:2016-05-09 18:20:56
【问题描述】:

我将解析我在 web worker 中创建的数组,返回到主线程。 该数组包含大量的 THREE.Mesh 对象。 当我试图对这个数组进行字符串化时:

self.postMessage(JSON.stringify(mesh));

发生错误: three.min.js:182 Uncaught TypeError: Cannot read property '971E7ACA-8223-4A5C-9F2F-E7966B58265F' of undefined.

我该如何处理这个关于网格对象的问题???

【问题讨论】:

    标签: javascript arrays three.js mesh


    【解决方案1】:

    在现代浏览器中,您可以避免对数组进行字符串化,而是依靠structured clone algorithm 为您处理:

    self.postMessage(mesh);
    

    See the example on MDN

    【讨论】:

    • 我试过这个但还有另一个错误:Uncaught DataCloneError: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': An object could not be cloned.
    • 您的对象上是否有函数或其他无效属性?见:stackoverflow.com/questions/33035854/…
    • 其实我里面有一个函数来操作一些数据:self.onmessage = function (e) var material = new THREE.MeshNormalMaterial({transparent: true, opacity: 0.4}); var mesh= []; for (var i = 0; i < e.data.length; i++) {.... mesh.push(new THREE.Mesh(geometry, material));} function _transformCoordinates(coordinates) { some manipulation with coordinates... } self.postMessage(mesh); };
    • 看起来你不是在用网格发送函数,对吧?
    • 这可能有点疯狂,但请尝试:self.postMessage(JSON.parse(JSON.stringify(mesh))); 这可能是确保网格上没有函数的最佳方法。虽然它可能对性能没有帮助......
    猜你喜欢
    • 2021-01-14
    • 2020-08-23
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 2012-06-27
    • 1970-01-01
    • 1970-01-01
    • 2021-09-23
    相关资源
    最近更新 更多