最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can you share meshes between three.js Scenes? - Stack Overflow

programmeradmin4浏览0评论

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: .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...

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./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...

Share Improve this question edited Aug 8, 2012 at 13:07 mrdoob 19.6k4 gold badges66 silver badges62 bronze badges asked Aug 1, 2012 at 15:49 bjnortierbjnortier 2,04818 silver badges18 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 17

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).

发布评论

评论列表(0)

  1. 暂无评论