|
@@ -16,167 +16,169 @@ const _camera = new Camera();
|
|
|
* http://evanw.github.com/lightgl.js/tests/shadowmap.html
|
|
|
*/
|
|
|
|
|
|
-function CameraHelper( camera ) {
|
|
|
+class CameraHelper extends LineSegments {
|
|
|
|
|
|
- const geometry = new BufferGeometry();
|
|
|
- const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
|
|
|
+ constructor( camera ) {
|
|
|
|
|
|
- const vertices = [];
|
|
|
- const colors = [];
|
|
|
+ const geometry = new BufferGeometry();
|
|
|
+ const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
|
|
|
|
|
|
- const pointMap = {};
|
|
|
+ const vertices = [];
|
|
|
+ const colors = [];
|
|
|
|
|
|
- // colors
|
|
|
+ const pointMap = {};
|
|
|
|
|
|
- const colorFrustum = new Color( 0xffaa00 );
|
|
|
- const colorCone = new Color( 0xff0000 );
|
|
|
- const colorUp = new Color( 0x00aaff );
|
|
|
- const colorTarget = new Color( 0xffffff );
|
|
|
- const colorCross = new Color( 0x333333 );
|
|
|
+ // colors
|
|
|
|
|
|
- // near
|
|
|
+ const colorFrustum = new Color( 0xffaa00 );
|
|
|
+ const colorCone = new Color( 0xff0000 );
|
|
|
+ const colorUp = new Color( 0x00aaff );
|
|
|
+ const colorTarget = new Color( 0xffffff );
|
|
|
+ const colorCross = new Color( 0x333333 );
|
|
|
|
|
|
- addLine( 'n1', 'n2', colorFrustum );
|
|
|
- addLine( 'n2', 'n4', colorFrustum );
|
|
|
- addLine( 'n4', 'n3', colorFrustum );
|
|
|
- addLine( 'n3', 'n1', colorFrustum );
|
|
|
+ // near
|
|
|
|
|
|
- // far
|
|
|
+ addLine( 'n1', 'n2', colorFrustum );
|
|
|
+ addLine( 'n2', 'n4', colorFrustum );
|
|
|
+ addLine( 'n4', 'n3', colorFrustum );
|
|
|
+ addLine( 'n3', 'n1', colorFrustum );
|
|
|
|
|
|
- addLine( 'f1', 'f2', colorFrustum );
|
|
|
- addLine( 'f2', 'f4', colorFrustum );
|
|
|
- addLine( 'f4', 'f3', colorFrustum );
|
|
|
- addLine( 'f3', 'f1', colorFrustum );
|
|
|
+ // far
|
|
|
|
|
|
- // sides
|
|
|
+ addLine( 'f1', 'f2', colorFrustum );
|
|
|
+ addLine( 'f2', 'f4', colorFrustum );
|
|
|
+ addLine( 'f4', 'f3', colorFrustum );
|
|
|
+ addLine( 'f3', 'f1', colorFrustum );
|
|
|
|
|
|
- addLine( 'n1', 'f1', colorFrustum );
|
|
|
- addLine( 'n2', 'f2', colorFrustum );
|
|
|
- addLine( 'n3', 'f3', colorFrustum );
|
|
|
- addLine( 'n4', 'f4', colorFrustum );
|
|
|
+ // sides
|
|
|
|
|
|
- // cone
|
|
|
+ addLine( 'n1', 'f1', colorFrustum );
|
|
|
+ addLine( 'n2', 'f2', colorFrustum );
|
|
|
+ addLine( 'n3', 'f3', colorFrustum );
|
|
|
+ addLine( 'n4', 'f4', colorFrustum );
|
|
|
|
|
|
- addLine( 'p', 'n1', colorCone );
|
|
|
- addLine( 'p', 'n2', colorCone );
|
|
|
- addLine( 'p', 'n3', colorCone );
|
|
|
- addLine( 'p', 'n4', colorCone );
|
|
|
+ // cone
|
|
|
|
|
|
- // up
|
|
|
+ addLine( 'p', 'n1', colorCone );
|
|
|
+ addLine( 'p', 'n2', colorCone );
|
|
|
+ addLine( 'p', 'n3', colorCone );
|
|
|
+ addLine( 'p', 'n4', colorCone );
|
|
|
|
|
|
- addLine( 'u1', 'u2', colorUp );
|
|
|
- addLine( 'u2', 'u3', colorUp );
|
|
|
- addLine( 'u3', 'u1', colorUp );
|
|
|
+ // up
|
|
|
|
|
|
- // target
|
|
|
+ addLine( 'u1', 'u2', colorUp );
|
|
|
+ addLine( 'u2', 'u3', colorUp );
|
|
|
+ addLine( 'u3', 'u1', colorUp );
|
|
|
|
|
|
- addLine( 'c', 't', colorTarget );
|
|
|
- addLine( 'p', 'c', colorCross );
|
|
|
+ // target
|
|
|
|
|
|
- // cross
|
|
|
+ addLine( 'c', 't', colorTarget );
|
|
|
+ addLine( 'p', 'c', colorCross );
|
|
|
|
|
|
- addLine( 'cn1', 'cn2', colorCross );
|
|
|
- addLine( 'cn3', 'cn4', colorCross );
|
|
|
+ // cross
|
|
|
|
|
|
- addLine( 'cf1', 'cf2', colorCross );
|
|
|
- addLine( 'cf3', 'cf4', colorCross );
|
|
|
+ addLine( 'cn1', 'cn2', colorCross );
|
|
|
+ addLine( 'cn3', 'cn4', colorCross );
|
|
|
|
|
|
- function addLine( a, b, color ) {
|
|
|
+ addLine( 'cf1', 'cf2', colorCross );
|
|
|
+ addLine( 'cf3', 'cf4', colorCross );
|
|
|
|
|
|
- addPoint( a, color );
|
|
|
- addPoint( b, color );
|
|
|
+ function addLine( a, b, color ) {
|
|
|
|
|
|
- }
|
|
|
+ addPoint( a, color );
|
|
|
+ addPoint( b, color );
|
|
|
|
|
|
- function addPoint( id, color ) {
|
|
|
+ }
|
|
|
|
|
|
- vertices.push( 0, 0, 0 );
|
|
|
- colors.push( color.r, color.g, color.b );
|
|
|
+ function addPoint( id, color ) {
|
|
|
|
|
|
- if ( pointMap[ id ] === undefined ) {
|
|
|
+ vertices.push( 0, 0, 0 );
|
|
|
+ colors.push( color.r, color.g, color.b );
|
|
|
|
|
|
- pointMap[ id ] = [];
|
|
|
+ if ( pointMap[ id ] === undefined ) {
|
|
|
|
|
|
- }
|
|
|
+ pointMap[ id ] = [];
|
|
|
|
|
|
- pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
|
|
|
|
|
|
- geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
|
|
- geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
|
|
|
+ }
|
|
|
|
|
|
- LineSegments.call( this, geometry, material );
|
|
|
+ geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
|
|
+ geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
|
|
|
|
|
|
- this.type = 'CameraHelper';
|
|
|
+ super( geometry, material );
|
|
|
|
|
|
- this.camera = camera;
|
|
|
- if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
|
|
|
+ this.type = 'CameraHelper';
|
|
|
|
|
|
- this.matrix = camera.matrixWorld;
|
|
|
- this.matrixAutoUpdate = false;
|
|
|
+ this.camera = camera;
|
|
|
+ if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
|
|
|
|
|
|
- this.pointMap = pointMap;
|
|
|
+ this.matrix = camera.matrixWorld;
|
|
|
+ this.matrixAutoUpdate = false;
|
|
|
|
|
|
- this.update();
|
|
|
+ this.pointMap = pointMap;
|
|
|
|
|
|
-}
|
|
|
+ this.update();
|
|
|
|
|
|
-CameraHelper.prototype = Object.create( LineSegments.prototype );
|
|
|
-CameraHelper.prototype.constructor = CameraHelper;
|
|
|
+ }
|
|
|
+
|
|
|
+ update() {
|
|
|
|
|
|
-CameraHelper.prototype.update = function () {
|
|
|
+ const geometry = this.geometry;
|
|
|
+ const pointMap = this.pointMap;
|
|
|
|
|
|
- const geometry = this.geometry;
|
|
|
- const pointMap = this.pointMap;
|
|
|
+ const w = 1, h = 1;
|
|
|
|
|
|
- const w = 1, h = 1;
|
|
|
+ // we need just camera projection matrix inverse
|
|
|
+ // world matrix must be identity
|
|
|
|
|
|
- // we need just camera projection matrix inverse
|
|
|
- // world matrix must be identity
|
|
|
+ _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
|
|
|
|
|
|
- _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
|
|
|
+ // center / target
|
|
|
|
|
|
- // center / target
|
|
|
+ setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
|
|
|
+ setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
|
|
|
|
|
|
- setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
|
|
|
- setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
|
|
|
+ // near
|
|
|
|
|
|
- // near
|
|
|
+ setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
|
|
|
+ setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
|
|
|
+ setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
|
|
|
+ setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
|
|
|
|
|
|
- setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
|
|
|
- setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
|
|
|
- setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
|
|
|
- setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
|
|
|
+ // far
|
|
|
|
|
|
- // far
|
|
|
+ setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
|
|
|
+ setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
|
|
|
+ setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
|
|
|
+ setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
|
|
|
|
|
|
- setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
|
|
|
- setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
|
|
|
- setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
|
|
|
- setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
|
|
|
+ // up
|
|
|
|
|
|
- // up
|
|
|
+ setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
|
|
|
+ setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
|
|
|
+ setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
|
|
|
|
|
|
- setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
|
|
|
- setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
|
|
|
- setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
|
|
|
+ // cross
|
|
|
|
|
|
- // cross
|
|
|
+ setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
|
|
|
+ setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
|
|
|
+ setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
|
|
|
+ setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
|
|
|
|
|
|
- setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
|
|
|
- setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
|
|
|
- setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
|
|
|
- setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
|
|
|
+ setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
|
|
|
+ setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
|
|
|
+ setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
|
|
|
+ setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
|
|
|
|
|
|
- setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
|
|
|
- setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
|
|
|
- setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
|
|
|
- setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
|
|
|
+ geometry.getAttribute( 'position' ).needsUpdate = true;
|
|
|
|
|
|
- geometry.getAttribute( 'position' ).needsUpdate = true;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
-};
|
|
|
|
|
|
function setPoint( point, pointMap, geometry, camera, x, y, z ) {
|
|
|
|