Skip to content

Instantly share code, notes, and snippets.

@mflux
Created July 23, 2014 23:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mflux/86dac07cdc6a16baafe1 to your computer and use it in GitHub Desktop.
Save mflux/86dac07cdc6a16baafe1 to your computer and use it in GitHub Desktop.
A small hacky module for THREE.js that forces a mesh and its texture to be uploaded into the GPU regardless of it's seen on-screen or not, preventing lag when the object comes into view.
ForceGPULoad = (function(){
var renderer;
var scene;
var camera;
return {
buffer: function( object3D ){
// push
var originalPosition = object3D.position.clone();
object3D.position.set( 0,0,0 );
var parent = object3D.parent;
parent.remove( object3D );
scene.add( object3D );
var culling = object3D.frustumCulled;
object3D.frustumCulled = false;
// render
renderer.render( scene, camera );
object3D.position.copy( originalPosition );
// pop
scene.remove( object3D );
parent.add( object3D );
object3D.frustumCulled = culling;
},
init: function( r, s, c ){
renderer = r;
scene = s;
camera = c;
},
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment