Last active
August 29, 2015 13:56
-
-
Save scottbyrns/9265950 to your computer and use it in GitHub Desktop.
This file contains 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
// 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