Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you share meshes between three.js Scenes?

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

like image 858
bjnortier Avatar asked Aug 01 '12 15:08

bjnortier


People also ask

What is a mesh in three js?

A Three. js Mesh is a base class that inherits from Object3d and is used to instantiate polygonal objects by combining a Geometry with a Material. Mesh is also the base class for the more advanced MorphAnimMesh and SkinnedMesh classes.

Does Three js use WebGL?

js. Three. js is a cross-browser JavaScript library and application programming interface (API) used to create and display animated 3D computer graphics in a web browser using WebGL.

What are three js scenes?

Scenes allow you to set up what and where is to be rendered by three. js. This is where you place objects, lights and cameras.


1 Answers

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

like image 155
mrdoob Avatar answered Nov 02 '22 18:11

mrdoob