- Create class "player"
This commit is contained in:
Kum1ta
2024-08-18 01:48:50 +02:00
parent a265843b82
commit 44ad413120
1218 changed files with 638609 additions and 0 deletions

View File

@ -0,0 +1,17 @@
import { Light } from './Light.js';
class AmbientLight extends Light {
constructor( color, intensity ) {
super( color, intensity );
this.isAmbientLight = true;
this.type = 'AmbientLight';
}
}
export { AmbientLight };

View File

@ -0,0 +1,43 @@
import { Light } from './Light.js';
import { DirectionalLightShadow } from './DirectionalLightShadow.js';
import { Object3D } from '../core/Object3D.js';
class DirectionalLight extends Light {
constructor( color, intensity ) {
super( color, intensity );
this.isDirectionalLight = true;
this.type = 'DirectionalLight';
this.position.copy( Object3D.DEFAULT_UP );
this.updateMatrix();
this.target = new Object3D();
this.shadow = new DirectionalLightShadow();
}
dispose() {
this.shadow.dispose();
}
copy( source ) {
super.copy( source );
this.target = source.target.clone();
this.shadow = source.shadow.clone();
return this;
}
}
export { DirectionalLight };

View File

@ -0,0 +1,16 @@
import { LightShadow } from './LightShadow.js';
import { OrthographicCamera } from '../cameras/OrthographicCamera.js';
class DirectionalLightShadow extends LightShadow {
constructor() {
super( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
this.isDirectionalLightShadow = true;
}
}
export { DirectionalLightShadow };

View File

@ -0,0 +1,34 @@
import { Light } from './Light.js';
import { Color } from '../math/Color.js';
import { Object3D } from '../core/Object3D.js';
class HemisphereLight extends Light {
constructor( skyColor, groundColor, intensity ) {
super( skyColor, intensity );
this.isHemisphereLight = true;
this.type = 'HemisphereLight';
this.position.copy( Object3D.DEFAULT_UP );
this.updateMatrix();
this.groundColor = new Color( groundColor );
}
copy( source, recursive ) {
super.copy( source, recursive );
this.groundColor.copy( source.groundColor );
return this;
}
}
export { HemisphereLight };

59
site/real_game/node_modules/three/src/lights/Light.js generated vendored Normal file
View File

@ -0,0 +1,59 @@
import { Object3D } from '../core/Object3D.js';
import { Color } from '../math/Color.js';
class Light extends Object3D {
constructor( color, intensity = 1 ) {
super();
this.isLight = true;
this.type = 'Light';
this.color = new Color( color );
this.intensity = intensity;
}
dispose() {
// Empty here in base class; some subclasses override.
}
copy( source, recursive ) {
super.copy( source, recursive );
this.color.copy( source.color );
this.intensity = source.intensity;
return this;
}
toJSON( meta ) {
const data = super.toJSON( meta );
data.object.color = this.color.getHex();
data.object.intensity = this.intensity;
if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
if ( this.distance !== undefined ) data.object.distance = this.distance;
if ( this.angle !== undefined ) data.object.angle = this.angle;
if ( this.decay !== undefined ) data.object.decay = this.decay;
if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
if ( this.target !== undefined ) data.object.target = this.target.uuid;
return data;
}
}
export { Light };

View File

@ -0,0 +1,47 @@
import { SphericalHarmonics3 } from '../math/SphericalHarmonics3.js';
import { Light } from './Light.js';
class LightProbe extends Light {
constructor( sh = new SphericalHarmonics3(), intensity = 1 ) {
super( undefined, intensity );
this.isLightProbe = true;
this.sh = sh;
}
copy( source ) {
super.copy( source );
this.sh.copy( source.sh );
return this;
}
fromJSON( json ) {
this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
this.sh.fromArray( json.sh );
return this;
}
toJSON( meta ) {
const data = super.toJSON( meta );
data.object.sh = this.sh.toArray();
return data;
}
}
export { LightProbe };

View File

@ -0,0 +1,152 @@
import { Matrix4 } from '../math/Matrix4.js';
import { Vector2 } from '../math/Vector2.js';
import { Vector3 } from '../math/Vector3.js';
import { Vector4 } from '../math/Vector4.js';
import { Frustum } from '../math/Frustum.js';
const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
const _lightPositionWorld = /*@__PURE__*/ new Vector3();
const _lookTarget = /*@__PURE__*/ new Vector3();
class LightShadow {
constructor( camera ) {
this.camera = camera;
this.intensity = 1;
this.bias = 0;
this.normalBias = 0;
this.radius = 1;
this.blurSamples = 8;
this.mapSize = new Vector2( 512, 512 );
this.map = null;
this.mapPass = null;
this.matrix = new Matrix4();
this.autoUpdate = true;
this.needsUpdate = false;
this._frustum = new Frustum();
this._frameExtents = new Vector2( 1, 1 );
this._viewportCount = 1;
this._viewports = [
new Vector4( 0, 0, 1, 1 )
];
}
getViewportCount() {
return this._viewportCount;
}
getFrustum() {
return this._frustum;
}
updateMatrices( light ) {
const shadowCamera = this.camera;
const shadowMatrix = this.matrix;
_lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
shadowCamera.position.copy( _lightPositionWorld );
_lookTarget.setFromMatrixPosition( light.target.matrixWorld );
shadowCamera.lookAt( _lookTarget );
shadowCamera.updateMatrixWorld();
_projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
this._frustum.setFromProjectionMatrix( _projScreenMatrix );
shadowMatrix.set(
0.5, 0.0, 0.0, 0.5,
0.0, 0.5, 0.0, 0.5,
0.0, 0.0, 0.5, 0.5,
0.0, 0.0, 0.0, 1.0
);
shadowMatrix.multiply( _projScreenMatrix );
}
getViewport( viewportIndex ) {
return this._viewports[ viewportIndex ];
}
getFrameExtents() {
return this._frameExtents;
}
dispose() {
if ( this.map ) {
this.map.dispose();
}
if ( this.mapPass ) {
this.mapPass.dispose();
}
}
copy( source ) {
this.camera = source.camera.clone();
this.intensity = source.intensity;
this.bias = source.bias;
this.radius = source.radius;
this.mapSize.copy( source.mapSize );
return this;
}
clone() {
return new this.constructor().copy( this );
}
toJSON() {
const object = {};
if ( this.intensity !== 1 ) object.intensity = this.intensity;
if ( this.bias !== 0 ) object.bias = this.bias;
if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
if ( this.radius !== 1 ) object.radius = this.radius;
if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
object.camera = this.camera.toJSON( false ).object;
delete object.camera.matrix;
return object;
}
}
export { LightShadow };

View File

@ -0,0 +1,57 @@
import { Light } from './Light.js';
import { PointLightShadow } from './PointLightShadow.js';
class PointLight extends Light {
constructor( color, intensity, distance = 0, decay = 2 ) {
super( color, intensity );
this.isPointLight = true;
this.type = 'PointLight';
this.distance = distance;
this.decay = decay;
this.shadow = new PointLightShadow();
}
get power() {
// compute the light's luminous power (in lumens) from its intensity (in candela)
// for an isotropic light source, luminous power (lm) = 4 π luminous intensity (cd)
return this.intensity * 4 * Math.PI;
}
set power( power ) {
// set the light's intensity (in candela) from the desired luminous power (in lumens)
this.intensity = power / ( 4 * Math.PI );
}
dispose() {
this.shadow.dispose();
}
copy( source, recursive ) {
super.copy( source, recursive );
this.distance = source.distance;
this.decay = source.decay;
this.shadow = source.shadow.clone();
return this;
}
}
export { PointLight };

View File

@ -0,0 +1,96 @@
import { LightShadow } from './LightShadow.js';
import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
import { Matrix4 } from '../math/Matrix4.js';
import { Vector2 } from '../math/Vector2.js';
import { Vector3 } from '../math/Vector3.js';
import { Vector4 } from '../math/Vector4.js';
const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
const _lightPositionWorld = /*@__PURE__*/ new Vector3();
const _lookTarget = /*@__PURE__*/ new Vector3();
class PointLightShadow extends LightShadow {
constructor() {
super( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
this.isPointLightShadow = true;
this._frameExtents = new Vector2( 4, 2 );
this._viewportCount = 6;
this._viewports = [
// These viewports map a cube-map onto a 2D texture with the
// following orientation:
//
// xzXZ
// y Y
//
// X - Positive x direction
// x - Negative x direction
// Y - Positive y direction
// y - Negative y direction
// Z - Positive z direction
// z - Negative z direction
// positive X
new Vector4( 2, 1, 1, 1 ),
// negative X
new Vector4( 0, 1, 1, 1 ),
// positive Z
new Vector4( 3, 1, 1, 1 ),
// negative Z
new Vector4( 1, 1, 1, 1 ),
// positive Y
new Vector4( 3, 0, 1, 1 ),
// negative Y
new Vector4( 1, 0, 1, 1 )
];
this._cubeDirections = [
new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
];
this._cubeUps = [
new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
];
}
updateMatrices( light, viewportIndex = 0 ) {
const camera = this.camera;
const shadowMatrix = this.matrix;
const far = light.distance || camera.far;
if ( far !== camera.far ) {
camera.far = far;
camera.updateProjectionMatrix();
}
_lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
camera.position.copy( _lightPositionWorld );
_lookTarget.copy( camera.position );
_lookTarget.add( this._cubeDirections[ viewportIndex ] );
camera.up.copy( this._cubeUps[ viewportIndex ] );
camera.lookAt( _lookTarget );
camera.updateMatrixWorld();
shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
_projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
this._frustum.setFromProjectionMatrix( _projScreenMatrix );
}
}
export { PointLightShadow };

View File

@ -0,0 +1,56 @@
import { Light } from './Light.js';
class RectAreaLight extends Light {
constructor( color, intensity, width = 10, height = 10 ) {
super( color, intensity );
this.isRectAreaLight = true;
this.type = 'RectAreaLight';
this.width = width;
this.height = height;
}
get power() {
// compute the light's luminous power (in lumens) from its intensity (in nits)
return this.intensity * this.width * this.height * Math.PI;
}
set power( power ) {
// set the light's intensity (in nits) from the desired luminous power (in lumens)
this.intensity = power / ( this.width * this.height * Math.PI );
}
copy( source ) {
super.copy( source );
this.width = source.width;
this.height = source.height;
return this;
}
toJSON( meta ) {
const data = super.toJSON( meta );
data.object.width = this.width;
data.object.height = this.height;
return data;
}
}
export { RectAreaLight };

View File

@ -0,0 +1,71 @@
import { Light } from './Light.js';
import { SpotLightShadow } from './SpotLightShadow.js';
import { Object3D } from '../core/Object3D.js';
class SpotLight extends Light {
constructor( color, intensity, distance = 0, angle = Math.PI / 3, penumbra = 0, decay = 2 ) {
super( color, intensity );
this.isSpotLight = true;
this.type = 'SpotLight';
this.position.copy( Object3D.DEFAULT_UP );
this.updateMatrix();
this.target = new Object3D();
this.distance = distance;
this.angle = angle;
this.penumbra = penumbra;
this.decay = decay;
this.map = null;
this.shadow = new SpotLightShadow();
}
get power() {
// compute the light's luminous power (in lumens) from its intensity (in candela)
// by convention for a spotlight, luminous power (lm) = π * luminous intensity (cd)
return this.intensity * Math.PI;
}
set power( power ) {
// set the light's intensity (in candela) from the desired luminous power (in lumens)
this.intensity = power / Math.PI;
}
dispose() {
this.shadow.dispose();
}
copy( source, recursive ) {
super.copy( source, recursive );
this.distance = source.distance;
this.angle = source.angle;
this.penumbra = source.penumbra;
this.decay = source.decay;
this.target = source.target.clone();
this.shadow = source.shadow.clone();
return this;
}
}
export { SpotLight };

View File

@ -0,0 +1,50 @@
import { LightShadow } from './LightShadow.js';
import * as MathUtils from '../math/MathUtils.js';
import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
class SpotLightShadow extends LightShadow {
constructor() {
super( new PerspectiveCamera( 50, 1, 0.5, 500 ) );
this.isSpotLightShadow = true;
this.focus = 1;
}
updateMatrices( light ) {
const camera = this.camera;
const fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
const aspect = this.mapSize.width / this.mapSize.height;
const far = light.distance || camera.far;
if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
camera.fov = fov;
camera.aspect = aspect;
camera.far = far;
camera.updateProjectionMatrix();
}
super.updateMatrices( light );
}
copy( source ) {
super.copy( source );
this.focus = source.focus;
return this;
}
}
export { SpotLightShadow };

View File

@ -0,0 +1,25 @@
import { SpotLight } from '../SpotLight.js';
class IESSpotLight extends SpotLight {
constructor( color, intensity, distance, angle, penumbra, decay ) {
super( color, intensity, distance, angle, penumbra, decay );
this.iesMap = null;
}
copy( source, recursive ) {
super.copy( source, recursive );
this.iesMap = source.iesMap;
return this;
}
}
export default IESSpotLight;