|
@@ -17,6 +17,8 @@ import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
|
|
import { BufferGeometry } from '../core/BufferGeometry.js';
|
|
|
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
|
|
|
|
|
+var _vector, _camera;
|
|
|
+
|
|
|
function CameraHelper( camera ) {
|
|
|
|
|
|
var geometry = new BufferGeometry();
|
|
@@ -126,85 +128,79 @@ CameraHelper.prototype.constructor = CameraHelper;
|
|
|
|
|
|
CameraHelper.prototype.update = function () {
|
|
|
|
|
|
- var geometry, pointMap;
|
|
|
-
|
|
|
- var vector = new Vector3();
|
|
|
- var camera = new Camera();
|
|
|
-
|
|
|
- function setPoint( point, x, y, z ) {
|
|
|
-
|
|
|
- vector.set( x, y, z ).unproject( camera );
|
|
|
+ if ( _camera === undefined ) _camera = new Camera();
|
|
|
|
|
|
- var points = pointMap[ point ];
|
|
|
+ var geometry = this.geometry;
|
|
|
+ var pointMap = this.pointMap;
|
|
|
|
|
|
- if ( points !== undefined ) {
|
|
|
+ var w = 1, h = 1;
|
|
|
|
|
|
- var position = geometry.getAttribute( 'position' );
|
|
|
+ // we need just camera projection matrix inverse
|
|
|
+ // world matrix must be identity
|
|
|
|
|
|
- for ( var i = 0, l = points.length; i < l; i ++ ) {
|
|
|
+ _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
|
|
|
|
|
|
- position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
|
|
|
+ // center / target
|
|
|
|
|
|
- }
|
|
|
+ setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
|
|
|
+ setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
|
|
|
|
|
|
- }
|
|
|
+ // 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 );
|
|
|
|
|
|
- return function update() {
|
|
|
+ // far
|
|
|
|
|
|
- geometry = this.geometry;
|
|
|
- pointMap = this.pointMap;
|
|
|
+ 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 );
|
|
|
|
|
|
- var w = 1, h = 1;
|
|
|
+ // up
|
|
|
|
|
|
- // we need just camera projection matrix inverse
|
|
|
- // world matrix must be identity
|
|
|
+ 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 );
|
|
|
|
|
|
- camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
|
|
|
+ // cross
|
|
|
|
|
|
- // center / target
|
|
|
+ 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( 'c', 0, 0, - 1 );
|
|
|
- setPoint( 't', 0, 0, 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 );
|
|
|
|
|
|
- // near
|
|
|
+ geometry.getAttribute( 'position' ).needsUpdate = true;
|
|
|
|
|
|
- setPoint( 'n1', - w, - h, - 1 );
|
|
|
- setPoint( 'n2', w, - h, - 1 );
|
|
|
- setPoint( 'n3', - w, h, - 1 );
|
|
|
- setPoint( 'n4', w, h, - 1 );
|
|
|
+};
|
|
|
|
|
|
- // far
|
|
|
+function setPoint( point, pointMap, geometry, camera, x, y, z ) {
|
|
|
|
|
|
- setPoint( 'f1', - w, - h, 1 );
|
|
|
- setPoint( 'f2', w, - h, 1 );
|
|
|
- setPoint( 'f3', - w, h, 1 );
|
|
|
- setPoint( 'f4', w, h, 1 );
|
|
|
+ if ( _vector === undefined ) _vector = new Vector3();
|
|
|
|
|
|
- // up
|
|
|
+ _vector.set( x, y, z ).unproject( camera );
|
|
|
|
|
|
- setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
|
|
|
- setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
|
|
|
- setPoint( 'u3', 0, h * 2, - 1 );
|
|
|
+ var points = pointMap[ point ];
|
|
|
|
|
|
- // cross
|
|
|
+ if ( points !== undefined ) {
|
|
|
|
|
|
- setPoint( 'cf1', - w, 0, 1 );
|
|
|
- setPoint( 'cf2', w, 0, 1 );
|
|
|
- setPoint( 'cf3', 0, - h, 1 );
|
|
|
- setPoint( 'cf4', 0, h, 1 );
|
|
|
+ var position = geometry.getAttribute( 'position' );
|
|
|
|
|
|
- setPoint( 'cn1', - w, 0, - 1 );
|
|
|
- setPoint( 'cn2', w, 0, - 1 );
|
|
|
- setPoint( 'cn3', 0, - h, - 1 );
|
|
|
- setPoint( 'cn4', 0, h, - 1 );
|
|
|
+ for ( var i = 0, l = points.length; i < l; i ++ ) {
|
|
|
|
|
|
- geometry.getAttribute( 'position' ).needsUpdate = true;
|
|
|
+ position.setXYZ( points[ i ], _vector.x, _vector.y, _vector.z );
|
|
|
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
-}();
|
|
|
+ }
|
|
|
|
|
|
+}
|
|
|
|
|
|
export { CameraHelper };
|