7

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

mrdoob
  • 19,334
  • 4
  • 63
  • 62
bjnortier
  • 2,008
  • 18
  • 18

1 Answers1

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

mrdoob
  • 19,334
  • 4
  • 63
  • 62
  • Thanks, I appreciate the answer. I clarified my question above. In my case there are multiple renderers so looks like I can't share geometry. – bjnortier Aug 08 '12 at 12:13
  • Are multiple EffectComposers allowed to use the same scene? I can get multiple renderers working fine, but adding effects to them gives the same list of WebGL errors. See [here](https://github.com/asvarga/ManyRenderersWithEffects). – Alex Varga Jan 28 '14 at 05:25
  • 6
    @mrdoob Is this still the case with r70 and r71? I'm having trouble sharing a geometry object between two renderers. – Justin Apr 16 '15 at 19:19