Can you share meshes between three.js Scenes?

元气小坏坏 提交于 2019-12-23 10:16:03

问题


Is it possible to share meshes or geometry between scenes?

I have multiple scenes which should the same, big, meshes, but when I try to share meshes between them I get WebGL context errors. I suspect that some variables are set on the meshes or geometry when they are added to a scene, thus preventing them from being re-used in another scene.

EDIT:

More specifcally, I'm trying to share geometry that has been loaded with the JSONLoader between different scenes. I.e. in this example 'apps' is an array of Apps with scenes:

var loader = new THREE.JSONLoader();
loader.load('obj/tree/tree.js', function(geometry) {
    apps.map(function(app) {
        var material = new THREE.MeshBasicMaterial({color: 0xff0000, opacity: 1.0}); 
        var mesh = new THREE.Mesh(geometry, geometry.materials[0]);
        app.scene.add(mesh);
    });
});

Full source here: https://github.com/bjnortier/three.js/blob/multiple_canvasses_with_json_loader/examples/webgl_multiple_canvases_grid.html

This example generates WebGL Errors:

WebGL: INVALID_OPERATION: useProgram: object not from this context
WebGL: INVALID_OPERATION: uniformMatrix4fv: location is not from current program
WebGL: INVALID_OPERATION: uniform3f: location not for current program
WebGL: INVALID_OPERATION: uniform1f: location not for current program
etc...


回答1:


You can share geometry along different Scenes.
You can't share meshes along different Scenes.
You can't share geometry/meshes/scenes along different Renderers (yet).



来源:https://stackoverflow.com/questions/11762961/can-you-share-meshes-between-three-js-scenes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!