Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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