问题
I'm not sure that this is a good way of doing this (in fact i think it is not) but for convenience sake i tried to do something with the JSONLoader, thats similar to what TextureLoader does:
var loader = (function(){
var cache = {};
var loader = new THREE.JSONLoader();
function getGeometry( url ) {
enter code here
//if there is something in the cache just return that
if( cache[ url ] ) return cache[ url ];
//if not, create an instance of geometry
cache[url] = new THREE.Geometry();
//start loading data
loader.load( url , function( g ){
//put the content into the cached geometry, that got passed to meshes
cache[url].merge( g );
//signal that update is needed on elements
cache[url]... needsUpdate = true;
cache[url]... needsUpdate = true;
cache[url]... needsUpdate = true;
...
}
//give an empty proxy to the mesh to work with, before the data is loaded
return cache[url];
}
return{
getGeometry:getGeometry
}
})();
Now, i first tried using Geometry.copy, but then i realized its not even documented. Still, merge is, and should have its use case.
The idea is that i can create many meshes, in many places with:
var mesh = new THREE.Mesh( loader.getGeometry('...js') );
and they will all share the same geometry, who ever calls it first will initiate the download, once its in, all meshes will be updated.
But, nothing happens, i dont see my mesh, even though they all hold a reference to updated geometry, and update flags were turned on. It was only when i manually updated Geometry._bufferGeometry that this worked. Why arent the flags triggering this?
Out of curiosity, what kind of performance impact does this have, if two gl.bufferData calls are made, but one has zero data, or zero size?
来源:https://stackoverflow.com/questions/35069799/three-js-loading-meshes-as-a-proxy