Skip to content

Instantly share code, notes, and snippets.

@scottbyrns
Last active August 29, 2015 13:56
Show Gist options
  • Save scottbyrns/9265950 to your computer and use it in GitHub Desktop.
Save scottbyrns/9265950 to your computer and use it in GitHub Desktop.
// First
this.frustum = new THREE.Frustum();
this.cameraViewProjectionMatrix = new THREE.Matrix4();
// Second
MessageController.sendMessage("app-controller", "add-render-stage", {name: "compute-frustum", stage:function (delta) {
MessageController.sendMessage("app-controller", "get-camera", function (camera, frustum, viewProjectionMatrix) {
camera.updateMatrixWorld(); // make sure the camera matrix is updated
camera.matrixWorldInverse.getInverse( camera.matrixWorld );
viewProjectionMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
frustum.setFromMatrix( viewProjectionMatrix );
// frustum is now ready to check all the objects you need
});
}});
// Third
MessageController.sendMessage("app-controller", "add-render-stage", {name: planet.uuid, stage:function (object) {
var geometry = new THREE.CubeGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
var placeHolder = new THREE.Mesh( geometry, material );
placeHolder.position = object.position;
MessageController.sendMessage("app-controller", "add-object-to-scene", placeHolder);
return function (delta) {
MessageController.sendMessage("app-controller", "get-camera", function (camera, frustum, viewProjectionMatrix) {
if (frustum.intersectsObject( placeHolder )) {
MessageController.sendMessage("app-controller", "add-object-to-scene", object);
}
else if (!frustum.intersectsObject( object )){
placeHolder.position = object.position;
MessageController.sendMessage("app-controller", "remove-object-from-scene", object);
}
});
}
}(planet)});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment