Created
July 23, 2014 23:20
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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