Site
- starting pong game 3d
This commit is contained in:
17
site/node_modules/three/src/cameras/ArrayCamera.js
generated
vendored
Normal file
17
site/node_modules/three/src/cameras/ArrayCamera.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
import { PerspectiveCamera } from './PerspectiveCamera.js';
|
||||
|
||||
class ArrayCamera extends PerspectiveCamera {
|
||||
|
||||
constructor( array = [] ) {
|
||||
|
||||
super();
|
||||
|
||||
this.isArrayCamera = true;
|
||||
|
||||
this.cameras = array;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { ArrayCamera };
|
69
site/node_modules/three/src/cameras/Camera.js
generated
vendored
Normal file
69
site/node_modules/three/src/cameras/Camera.js
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
import { WebGLCoordinateSystem } from '../constants.js';
|
||||
import { Matrix4 } from '../math/Matrix4.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
|
||||
class Camera extends Object3D {
|
||||
|
||||
constructor() {
|
||||
|
||||
super();
|
||||
|
||||
this.isCamera = true;
|
||||
|
||||
this.type = 'Camera';
|
||||
|
||||
this.matrixWorldInverse = new Matrix4();
|
||||
|
||||
this.projectionMatrix = new Matrix4();
|
||||
this.projectionMatrixInverse = new Matrix4();
|
||||
|
||||
this.coordinateSystem = WebGLCoordinateSystem;
|
||||
|
||||
}
|
||||
|
||||
copy( source, recursive ) {
|
||||
|
||||
super.copy( source, recursive );
|
||||
|
||||
this.matrixWorldInverse.copy( source.matrixWorldInverse );
|
||||
|
||||
this.projectionMatrix.copy( source.projectionMatrix );
|
||||
this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
|
||||
|
||||
this.coordinateSystem = source.coordinateSystem;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
getWorldDirection( target ) {
|
||||
|
||||
return super.getWorldDirection( target ).negate();
|
||||
|
||||
}
|
||||
|
||||
updateMatrixWorld( force ) {
|
||||
|
||||
super.updateMatrixWorld( force );
|
||||
|
||||
this.matrixWorldInverse.copy( this.matrixWorld ).invert();
|
||||
|
||||
}
|
||||
|
||||
updateWorldMatrix( updateParents, updateChildren ) {
|
||||
|
||||
super.updateWorldMatrix( updateParents, updateChildren );
|
||||
|
||||
this.matrixWorldInverse.copy( this.matrixWorld ).invert();
|
||||
|
||||
}
|
||||
|
||||
clone() {
|
||||
|
||||
return new this.constructor().copy( this );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Camera };
|
173
site/node_modules/three/src/cameras/CubeCamera.js
generated
vendored
Normal file
173
site/node_modules/three/src/cameras/CubeCamera.js
generated
vendored
Normal file
@ -0,0 +1,173 @@
|
||||
import { WebGLCoordinateSystem, WebGPUCoordinateSystem } from '../constants.js';
|
||||
import { Object3D } from '../core/Object3D.js';
|
||||
import { PerspectiveCamera } from './PerspectiveCamera.js';
|
||||
|
||||
const fov = - 90; // negative fov is not an error
|
||||
const aspect = 1;
|
||||
|
||||
class CubeCamera extends Object3D {
|
||||
|
||||
constructor( near, far, renderTarget ) {
|
||||
|
||||
super();
|
||||
|
||||
this.type = 'CubeCamera';
|
||||
|
||||
this.renderTarget = renderTarget;
|
||||
this.coordinateSystem = null;
|
||||
this.activeMipmapLevel = 0;
|
||||
|
||||
const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraPX.layers = this.layers;
|
||||
this.add( cameraPX );
|
||||
|
||||
const cameraNX = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraNX.layers = this.layers;
|
||||
this.add( cameraNX );
|
||||
|
||||
const cameraPY = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraPY.layers = this.layers;
|
||||
this.add( cameraPY );
|
||||
|
||||
const cameraNY = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraNY.layers = this.layers;
|
||||
this.add( cameraNY );
|
||||
|
||||
const cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraPZ.layers = this.layers;
|
||||
this.add( cameraPZ );
|
||||
|
||||
const cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
|
||||
cameraNZ.layers = this.layers;
|
||||
this.add( cameraNZ );
|
||||
|
||||
}
|
||||
|
||||
updateCoordinateSystem() {
|
||||
|
||||
const coordinateSystem = this.coordinateSystem;
|
||||
|
||||
const cameras = this.children.concat();
|
||||
|
||||
const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = cameras;
|
||||
|
||||
for ( const camera of cameras ) this.remove( camera );
|
||||
|
||||
if ( coordinateSystem === WebGLCoordinateSystem ) {
|
||||
|
||||
cameraPX.up.set( 0, 1, 0 );
|
||||
cameraPX.lookAt( 1, 0, 0 );
|
||||
|
||||
cameraNX.up.set( 0, 1, 0 );
|
||||
cameraNX.lookAt( - 1, 0, 0 );
|
||||
|
||||
cameraPY.up.set( 0, 0, - 1 );
|
||||
cameraPY.lookAt( 0, 1, 0 );
|
||||
|
||||
cameraNY.up.set( 0, 0, 1 );
|
||||
cameraNY.lookAt( 0, - 1, 0 );
|
||||
|
||||
cameraPZ.up.set( 0, 1, 0 );
|
||||
cameraPZ.lookAt( 0, 0, 1 );
|
||||
|
||||
cameraNZ.up.set( 0, 1, 0 );
|
||||
cameraNZ.lookAt( 0, 0, - 1 );
|
||||
|
||||
} else if ( coordinateSystem === WebGPUCoordinateSystem ) {
|
||||
|
||||
cameraPX.up.set( 0, - 1, 0 );
|
||||
cameraPX.lookAt( - 1, 0, 0 );
|
||||
|
||||
cameraNX.up.set( 0, - 1, 0 );
|
||||
cameraNX.lookAt( 1, 0, 0 );
|
||||
|
||||
cameraPY.up.set( 0, 0, 1 );
|
||||
cameraPY.lookAt( 0, 1, 0 );
|
||||
|
||||
cameraNY.up.set( 0, 0, - 1 );
|
||||
cameraNY.lookAt( 0, - 1, 0 );
|
||||
|
||||
cameraPZ.up.set( 0, - 1, 0 );
|
||||
cameraPZ.lookAt( 0, 0, 1 );
|
||||
|
||||
cameraNZ.up.set( 0, - 1, 0 );
|
||||
cameraNZ.lookAt( 0, 0, - 1 );
|
||||
|
||||
} else {
|
||||
|
||||
throw new Error( 'THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: ' + coordinateSystem );
|
||||
|
||||
}
|
||||
|
||||
for ( const camera of cameras ) {
|
||||
|
||||
this.add( camera );
|
||||
|
||||
camera.updateMatrixWorld();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
update( renderer, scene ) {
|
||||
|
||||
if ( this.parent === null ) this.updateMatrixWorld();
|
||||
|
||||
const { renderTarget, activeMipmapLevel } = this;
|
||||
|
||||
if ( this.coordinateSystem !== renderer.coordinateSystem ) {
|
||||
|
||||
this.coordinateSystem = renderer.coordinateSystem;
|
||||
|
||||
this.updateCoordinateSystem();
|
||||
|
||||
}
|
||||
|
||||
const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = this.children;
|
||||
|
||||
const currentRenderTarget = renderer.getRenderTarget();
|
||||
const currentActiveCubeFace = renderer.getActiveCubeFace();
|
||||
const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
|
||||
|
||||
const currentXrEnabled = renderer.xr.enabled;
|
||||
|
||||
renderer.xr.enabled = false;
|
||||
|
||||
const generateMipmaps = renderTarget.texture.generateMipmaps;
|
||||
|
||||
renderTarget.texture.generateMipmaps = false;
|
||||
|
||||
renderer.setRenderTarget( renderTarget, 0, activeMipmapLevel );
|
||||
renderer.render( scene, cameraPX );
|
||||
|
||||
renderer.setRenderTarget( renderTarget, 1, activeMipmapLevel );
|
||||
renderer.render( scene, cameraNX );
|
||||
|
||||
renderer.setRenderTarget( renderTarget, 2, activeMipmapLevel );
|
||||
renderer.render( scene, cameraPY );
|
||||
|
||||
renderer.setRenderTarget( renderTarget, 3, activeMipmapLevel );
|
||||
renderer.render( scene, cameraNY );
|
||||
|
||||
renderer.setRenderTarget( renderTarget, 4, activeMipmapLevel );
|
||||
renderer.render( scene, cameraPZ );
|
||||
|
||||
// mipmaps are generated during the last call of render()
|
||||
// at this point, all sides of the cube render target are defined
|
||||
|
||||
renderTarget.texture.generateMipmaps = generateMipmaps;
|
||||
|
||||
renderer.setRenderTarget( renderTarget, 5, activeMipmapLevel );
|
||||
renderer.render( scene, cameraNZ );
|
||||
|
||||
renderer.setRenderTarget( currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel );
|
||||
|
||||
renderer.xr.enabled = currentXrEnabled;
|
||||
|
||||
renderTarget.texture.needsPMREMUpdate = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { CubeCamera };
|
136
site/node_modules/three/src/cameras/OrthographicCamera.js
generated
vendored
Executable file
136
site/node_modules/three/src/cameras/OrthographicCamera.js
generated
vendored
Executable file
@ -0,0 +1,136 @@
|
||||
import { Camera } from './Camera.js';
|
||||
|
||||
class OrthographicCamera extends Camera {
|
||||
|
||||
constructor( left = - 1, right = 1, top = 1, bottom = - 1, near = 0.1, far = 2000 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.isOrthographicCamera = true;
|
||||
|
||||
this.type = 'OrthographicCamera';
|
||||
|
||||
this.zoom = 1;
|
||||
this.view = null;
|
||||
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.top = top;
|
||||
this.bottom = bottom;
|
||||
|
||||
this.near = near;
|
||||
this.far = far;
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
copy( source, recursive ) {
|
||||
|
||||
super.copy( source, recursive );
|
||||
|
||||
this.left = source.left;
|
||||
this.right = source.right;
|
||||
this.top = source.top;
|
||||
this.bottom = source.bottom;
|
||||
this.near = source.near;
|
||||
this.far = source.far;
|
||||
|
||||
this.zoom = source.zoom;
|
||||
this.view = source.view === null ? null : Object.assign( {}, source.view );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
|
||||
|
||||
if ( this.view === null ) {
|
||||
|
||||
this.view = {
|
||||
enabled: true,
|
||||
fullWidth: 1,
|
||||
fullHeight: 1,
|
||||
offsetX: 0,
|
||||
offsetY: 0,
|
||||
width: 1,
|
||||
height: 1
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
this.view.enabled = true;
|
||||
this.view.fullWidth = fullWidth;
|
||||
this.view.fullHeight = fullHeight;
|
||||
this.view.offsetX = x;
|
||||
this.view.offsetY = y;
|
||||
this.view.width = width;
|
||||
this.view.height = height;
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
clearViewOffset() {
|
||||
|
||||
if ( this.view !== null ) {
|
||||
|
||||
this.view.enabled = false;
|
||||
|
||||
}
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
updateProjectionMatrix() {
|
||||
|
||||
const dx = ( this.right - this.left ) / ( 2 * this.zoom );
|
||||
const dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
|
||||
const cx = ( this.right + this.left ) / 2;
|
||||
const cy = ( this.top + this.bottom ) / 2;
|
||||
|
||||
let left = cx - dx;
|
||||
let right = cx + dx;
|
||||
let top = cy + dy;
|
||||
let bottom = cy - dy;
|
||||
|
||||
if ( this.view !== null && this.view.enabled ) {
|
||||
|
||||
const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
|
||||
const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
|
||||
|
||||
left += scaleW * this.view.offsetX;
|
||||
right = left + scaleW * this.view.width;
|
||||
top -= scaleH * this.view.offsetY;
|
||||
bottom = top - scaleH * this.view.height;
|
||||
|
||||
}
|
||||
|
||||
this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far, this.coordinateSystem );
|
||||
|
||||
this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
|
||||
|
||||
}
|
||||
|
||||
toJSON( meta ) {
|
||||
|
||||
const data = super.toJSON( meta );
|
||||
|
||||
data.object.zoom = this.zoom;
|
||||
data.object.left = this.left;
|
||||
data.object.right = this.right;
|
||||
data.object.top = this.top;
|
||||
data.object.bottom = this.bottom;
|
||||
data.object.near = this.near;
|
||||
data.object.far = this.far;
|
||||
|
||||
if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { OrthographicCamera };
|
268
site/node_modules/three/src/cameras/PerspectiveCamera.js
generated
vendored
Normal file
268
site/node_modules/three/src/cameras/PerspectiveCamera.js
generated
vendored
Normal file
@ -0,0 +1,268 @@
|
||||
import { Camera } from './Camera.js';
|
||||
import * as MathUtils from '../math/MathUtils.js';
|
||||
import { Vector2 } from '../math/Vector2.js';
|
||||
import { Vector3 } from '../math/Vector3.js';
|
||||
|
||||
const _v3 = /*@__PURE__*/ new Vector3();
|
||||
const _minTarget = /*@__PURE__*/ new Vector2();
|
||||
const _maxTarget = /*@__PURE__*/ new Vector2();
|
||||
|
||||
|
||||
class PerspectiveCamera extends Camera {
|
||||
|
||||
constructor( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {
|
||||
|
||||
super();
|
||||
|
||||
this.isPerspectiveCamera = true;
|
||||
|
||||
this.type = 'PerspectiveCamera';
|
||||
|
||||
this.fov = fov;
|
||||
this.zoom = 1;
|
||||
|
||||
this.near = near;
|
||||
this.far = far;
|
||||
this.focus = 10;
|
||||
|
||||
this.aspect = aspect;
|
||||
this.view = null;
|
||||
|
||||
this.filmGauge = 35; // width of the film (default in millimeters)
|
||||
this.filmOffset = 0; // horizontal film offset (same unit as gauge)
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
copy( source, recursive ) {
|
||||
|
||||
super.copy( source, recursive );
|
||||
|
||||
this.fov = source.fov;
|
||||
this.zoom = source.zoom;
|
||||
|
||||
this.near = source.near;
|
||||
this.far = source.far;
|
||||
this.focus = source.focus;
|
||||
|
||||
this.aspect = source.aspect;
|
||||
this.view = source.view === null ? null : Object.assign( {}, source.view );
|
||||
|
||||
this.filmGauge = source.filmGauge;
|
||||
this.filmOffset = source.filmOffset;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the FOV by focal length in respect to the current .filmGauge.
|
||||
*
|
||||
* The default film gauge is 35, so that the focal length can be specified for
|
||||
* a 35mm (full frame) camera.
|
||||
*
|
||||
* Values for focal length and film gauge must have the same unit.
|
||||
*/
|
||||
setFocalLength( focalLength ) {
|
||||
|
||||
/** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
|
||||
const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
|
||||
|
||||
this.fov = MathUtils.RAD2DEG * 2 * Math.atan( vExtentSlope );
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the focal length from the current .fov and .filmGauge.
|
||||
*/
|
||||
getFocalLength() {
|
||||
|
||||
const vExtentSlope = Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov );
|
||||
|
||||
return 0.5 * this.getFilmHeight() / vExtentSlope;
|
||||
|
||||
}
|
||||
|
||||
getEffectiveFOV() {
|
||||
|
||||
return MathUtils.RAD2DEG * 2 * Math.atan(
|
||||
Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom );
|
||||
|
||||
}
|
||||
|
||||
getFilmWidth() {
|
||||
|
||||
// film not completely covered in portrait format (aspect < 1)
|
||||
return this.filmGauge * Math.min( this.aspect, 1 );
|
||||
|
||||
}
|
||||
|
||||
getFilmHeight() {
|
||||
|
||||
// film not completely covered in landscape format (aspect > 1)
|
||||
return this.filmGauge / Math.max( this.aspect, 1 );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction.
|
||||
* Sets minTarget and maxTarget to the coordinates of the lower-left and upper-right corners of the view rectangle.
|
||||
*/
|
||||
getViewBounds( distance, minTarget, maxTarget ) {
|
||||
|
||||
_v3.set( - 1, - 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
|
||||
|
||||
minTarget.set( _v3.x, _v3.y ).multiplyScalar( - distance / _v3.z );
|
||||
|
||||
_v3.set( 1, 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
|
||||
|
||||
maxTarget.set( _v3.x, _v3.y ).multiplyScalar( - distance / _v3.z );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.
|
||||
* Copies the result into the target Vector2, where x is width and y is height.
|
||||
*/
|
||||
getViewSize( distance, target ) {
|
||||
|
||||
this.getViewBounds( distance, _minTarget, _maxTarget );
|
||||
|
||||
return target.subVectors( _maxTarget, _minTarget );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an offset in a larger frustum. This is useful for multi-window or
|
||||
* multi-monitor/multi-machine setups.
|
||||
*
|
||||
* For example, if you have 3x2 monitors and each monitor is 1920x1080 and
|
||||
* the monitors are in grid like this
|
||||
*
|
||||
* +---+---+---+
|
||||
* | A | B | C |
|
||||
* +---+---+---+
|
||||
* | D | E | F |
|
||||
* +---+---+---+
|
||||
*
|
||||
* then for each monitor you would call it like this
|
||||
*
|
||||
* const w = 1920;
|
||||
* const h = 1080;
|
||||
* const fullWidth = w * 3;
|
||||
* const fullHeight = h * 2;
|
||||
*
|
||||
* --A--
|
||||
* camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
|
||||
* --B--
|
||||
* camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
|
||||
* --C--
|
||||
* camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
|
||||
* --D--
|
||||
* camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
|
||||
* --E--
|
||||
* camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
|
||||
* --F--
|
||||
* camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
|
||||
*
|
||||
* Note there is no reason monitors have to be the same size or in a grid.
|
||||
*/
|
||||
setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
|
||||
|
||||
this.aspect = fullWidth / fullHeight;
|
||||
|
||||
if ( this.view === null ) {
|
||||
|
||||
this.view = {
|
||||
enabled: true,
|
||||
fullWidth: 1,
|
||||
fullHeight: 1,
|
||||
offsetX: 0,
|
||||
offsetY: 0,
|
||||
width: 1,
|
||||
height: 1
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
this.view.enabled = true;
|
||||
this.view.fullWidth = fullWidth;
|
||||
this.view.fullHeight = fullHeight;
|
||||
this.view.offsetX = x;
|
||||
this.view.offsetY = y;
|
||||
this.view.width = width;
|
||||
this.view.height = height;
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
clearViewOffset() {
|
||||
|
||||
if ( this.view !== null ) {
|
||||
|
||||
this.view.enabled = false;
|
||||
|
||||
}
|
||||
|
||||
this.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
updateProjectionMatrix() {
|
||||
|
||||
const near = this.near;
|
||||
let top = near * Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom;
|
||||
let height = 2 * top;
|
||||
let width = this.aspect * height;
|
||||
let left = - 0.5 * width;
|
||||
const view = this.view;
|
||||
|
||||
if ( this.view !== null && this.view.enabled ) {
|
||||
|
||||
const fullWidth = view.fullWidth,
|
||||
fullHeight = view.fullHeight;
|
||||
|
||||
left += view.offsetX * width / fullWidth;
|
||||
top -= view.offsetY * height / fullHeight;
|
||||
width *= view.width / fullWidth;
|
||||
height *= view.height / fullHeight;
|
||||
|
||||
}
|
||||
|
||||
const skew = this.filmOffset;
|
||||
if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
|
||||
|
||||
this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far, this.coordinateSystem );
|
||||
|
||||
this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
|
||||
|
||||
}
|
||||
|
||||
toJSON( meta ) {
|
||||
|
||||
const data = super.toJSON( meta );
|
||||
|
||||
data.object.fov = this.fov;
|
||||
data.object.zoom = this.zoom;
|
||||
|
||||
data.object.near = this.near;
|
||||
data.object.far = this.far;
|
||||
data.object.focus = this.focus;
|
||||
|
||||
data.object.aspect = this.aspect;
|
||||
|
||||
if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
|
||||
|
||||
data.object.filmGauge = this.filmGauge;
|
||||
data.object.filmOffset = this.filmOffset;
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { PerspectiveCamera };
|
100
site/node_modules/three/src/cameras/StereoCamera.js
generated
vendored
Normal file
100
site/node_modules/three/src/cameras/StereoCamera.js
generated
vendored
Normal file
@ -0,0 +1,100 @@
|
||||
import { Matrix4 } from '../math/Matrix4.js';
|
||||
import * as MathUtils from '../math/MathUtils.js';
|
||||
import { PerspectiveCamera } from './PerspectiveCamera.js';
|
||||
|
||||
const _eyeRight = /*@__PURE__*/ new Matrix4();
|
||||
const _eyeLeft = /*@__PURE__*/ new Matrix4();
|
||||
const _projectionMatrix = /*@__PURE__*/ new Matrix4();
|
||||
|
||||
class StereoCamera {
|
||||
|
||||
constructor() {
|
||||
|
||||
this.type = 'StereoCamera';
|
||||
|
||||
this.aspect = 1;
|
||||
|
||||
this.eyeSep = 0.064;
|
||||
|
||||
this.cameraL = new PerspectiveCamera();
|
||||
this.cameraL.layers.enable( 1 );
|
||||
this.cameraL.matrixAutoUpdate = false;
|
||||
|
||||
this.cameraR = new PerspectiveCamera();
|
||||
this.cameraR.layers.enable( 2 );
|
||||
this.cameraR.matrixAutoUpdate = false;
|
||||
|
||||
this._cache = {
|
||||
focus: null,
|
||||
fov: null,
|
||||
aspect: null,
|
||||
near: null,
|
||||
far: null,
|
||||
zoom: null,
|
||||
eyeSep: null
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
update( camera ) {
|
||||
|
||||
const cache = this._cache;
|
||||
|
||||
const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
|
||||
cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
|
||||
cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
|
||||
|
||||
if ( needsUpdate ) {
|
||||
|
||||
cache.focus = camera.focus;
|
||||
cache.fov = camera.fov;
|
||||
cache.aspect = camera.aspect * this.aspect;
|
||||
cache.near = camera.near;
|
||||
cache.far = camera.far;
|
||||
cache.zoom = camera.zoom;
|
||||
cache.eyeSep = this.eyeSep;
|
||||
|
||||
// Off-axis stereoscopic effect based on
|
||||
// http://paulbourke.net/stereographics/stereorender/
|
||||
|
||||
_projectionMatrix.copy( camera.projectionMatrix );
|
||||
const eyeSepHalf = cache.eyeSep / 2;
|
||||
const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
|
||||
const ymax = ( cache.near * Math.tan( MathUtils.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
|
||||
let xmin, xmax;
|
||||
|
||||
// translate xOffset
|
||||
|
||||
_eyeLeft.elements[ 12 ] = - eyeSepHalf;
|
||||
_eyeRight.elements[ 12 ] = eyeSepHalf;
|
||||
|
||||
// for left eye
|
||||
|
||||
xmin = - ymax * cache.aspect + eyeSepOnProjection;
|
||||
xmax = ymax * cache.aspect + eyeSepOnProjection;
|
||||
|
||||
_projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
|
||||
_projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
|
||||
|
||||
this.cameraL.projectionMatrix.copy( _projectionMatrix );
|
||||
|
||||
// for right eye
|
||||
|
||||
xmin = - ymax * cache.aspect - eyeSepOnProjection;
|
||||
xmax = ymax * cache.aspect - eyeSepOnProjection;
|
||||
|
||||
_projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
|
||||
_projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
|
||||
|
||||
this.cameraR.projectionMatrix.copy( _projectionMatrix );
|
||||
|
||||
}
|
||||
|
||||
this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
|
||||
this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { StereoCamera };
|
Reference in New Issue
Block a user