mage-engine 3.23.9 → 3.23.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/mage.js +39 -36
  2. package/package.json +1 -1
package/dist/mage.js CHANGED
@@ -57798,7 +57798,7 @@ function applyMiddleware() {
57798
57798
 
57799
57799
  var thunk = createThunkMiddleware();
57800
57800
  thunk.withExtraArgument = createThunkMiddleware;var name$1 = "mage-engine";
57801
- var version$1 = "3.23.9";
57801
+ var version$1 = "3.23.10";
57802
57802
  var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
57803
57803
  var main = "dist/mage.js";
57804
57804
  var author$1 = {
@@ -60038,14 +60038,14 @@ var prepareModel = function prepareModel(model) {
60038
60038
  return model;
60039
60039
  };
60040
60040
  var serializeVector = function serializeVector(vector) {
60041
- return {
60041
+ return vector && {
60042
60042
  x: vector.x,
60043
60043
  y: vector.y,
60044
60044
  z: vector.z
60045
60045
  };
60046
60046
  };
60047
60047
  var serializeQuaternion = function serializeQuaternion(quaternion) {
60048
- return {
60048
+ return quaternion && {
60049
60049
  x: quaternion.x,
60050
60050
  y: quaternion.y,
60051
60051
  z: quaternion.z,
@@ -60053,7 +60053,7 @@ var serializeQuaternion = function serializeQuaternion(quaternion) {
60053
60053
  };
60054
60054
  };
60055
60055
  var serializeColor = function serializeColor(color) {
60056
- return {
60056
+ return color && {
60057
60057
  r: color.r,
60058
60058
  g: color.g,
60059
60059
  b: color.b
@@ -91631,9 +91631,10 @@ var addHitBox = function addHitBox(element) {
91631
91631
  key: "toJSON",
91632
91632
  value: function toJSON() {
91633
91633
  var parseJSON = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
91634
+ var color = this.getColor();
91634
91635
  return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(Light.prototype), "toJSON", this).call(this, parseJSON)), {}, {
91635
91636
  type: this.getEntityType(),
91636
- color: this.getColor(),
91637
+ color: parseJSON ? serializeColor(color) : color,
91637
91638
  intensity: this.getIntensity(),
91638
91639
  name: this.getName(),
91639
91640
  castShadow: this.getCastShadow()
@@ -91972,7 +91973,7 @@ var SunLight = /*#__PURE__*/function (_Light) {
91972
91973
  value: function toJSON() {
91973
91974
  var parseJSON = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
91974
91975
  return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(SunLight.prototype), "toJSON", this).call(this, parseJSON)), {}, {
91975
- target: this.getTarget(),
91976
+ target: parseJSON ? this.getTarget().toJSON(parseJSON) : this.getTarget(),
91976
91977
  bias: this.getBias(),
91977
91978
  mapSize: this.getMapSize(),
91978
91979
  shadowCamera: _objectSpread2$1(_objectSpread2$1({}, this.getShadowCameraNearFar()), {}, {
@@ -92502,7 +92503,7 @@ var SpotLight = /*#__PURE__*/function (_Light) {
92502
92503
  value: function toJSON() {
92503
92504
  var parseJSON = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
92504
92505
  return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(SpotLight.prototype), "toJSON", this).call(this, parseJSON)), {}, {
92505
- target: this.getTarget(),
92506
+ target: parseJSON ? this.getTarget().toJSON(parseJSON) : this.getTarget(),
92506
92507
  distance: this.getDistance(),
92507
92508
  decay: this.getDecay(),
92508
92509
  bias: this.getBias(),
@@ -92748,9 +92749,10 @@ var SpotLight = /*#__PURE__*/function (_Light) {
92748
92749
  key: "toJSON",
92749
92750
  value: function toJSON() {
92750
92751
  var parseJSON = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
92752
+ var color = this.getColor();
92751
92753
  return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(Light.prototype), "toJSON", this).call(this, parseJSON)), {}, {
92752
92754
  type: this.getEntityType(),
92753
- color: this.getColor(),
92755
+ color: parseJSON ? serializeColor(color) : color,
92754
92756
  intensity: this.getIntensity(),
92755
92757
  name: this.getName(),
92756
92758
  castShadow: this.getCastShadow()
@@ -92880,8 +92882,9 @@ var HemisphereLight = /*#__PURE__*/function (_Light) {
92880
92882
  key: "toJSON",
92881
92883
  value: function toJSON() {
92882
92884
  var parseJSON = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
92885
+ var color = this.getColor();
92883
92886
  return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(HemisphereLight.prototype), "toJSON", this).call(this, parseJSON)), {}, {
92884
- color: this.getColor()
92887
+ color: parseJSON ? serializeColor(color) : color
92885
92888
  });
92886
92889
  }
92887
92890
  }]);
@@ -94198,41 +94201,41 @@ var Water = /*#__PURE__*/function (_Element) {
94198
94201
  }, {
94199
94202
  key: "vertexShader",
94200
94203
  value: function vertexShader() {
94201
- return ['uniform vec3 sunPosition;', 'uniform float rayleigh;', 'uniform float turbidity;', 'uniform float mieCoefficient;', 'varying vec3 vWorldPosition;', 'varying vec3 vSunDirection;', 'varying float vSunfade;', 'varying vec3 vBetaR;', 'varying vec3 vBetaM;', 'varying float vSunE;', 'const vec3 up = vec3( 0.0, 1.0, 0.0 );', // constants for atmospheric scattering
94202
- 'const float e = 2.71828182845904523536028747135266249775724709369995957;', 'const float pi = 3.141592653589793238462643383279502884197169;', // wavelength of used primaries, according to preetham
94203
- 'const vec3 lambda = vec3( 680E-9, 550E-9, 450E-9 );', // this pre-calcuation replaces older TotalRayleigh(vec3 lambda) function:
94204
+ return ["uniform vec3 sunPosition;", "uniform float rayleigh;", "uniform float turbidity;", "uniform float mieCoefficient;", "varying vec3 vWorldPosition;", "varying vec3 vSunDirection;", "varying float vSunfade;", "varying vec3 vBetaR;", "varying vec3 vBetaM;", "varying float vSunE;", "const vec3 up = vec3( 0.0, 1.0, 0.0 );", // constants for atmospheric scattering
94205
+ "const float e = 2.71828182845904523536028747135266249775724709369995957;", "const float pi = 3.141592653589793238462643383279502884197169;", // wavelength of used primaries, according to preetham
94206
+ "const vec3 lambda = vec3( 680E-9, 550E-9, 450E-9 );", // this pre-calcuation replaces older TotalRayleigh(vec3 lambda) function:
94204
94207
  // (8.0 * pow(pi, 3.0) * pow(pow(n, 2.0) - 1.0, 2.0) * (6.0 + 3.0 * pn)) / (3.0 * N * pow(lambda, vec3(4.0)) * (6.0 - 7.0 * pn))
94205
- 'const vec3 totalRayleigh = vec3( 5.804542996261093E-6, 1.3562911419845635E-5, 3.0265902468824876E-5 );', // mie stuff
94208
+ "const vec3 totalRayleigh = vec3( 5.804542996261093E-6, 1.3562911419845635E-5, 3.0265902468824876E-5 );", // mie stuff
94206
94209
  // K coefficient for the primaries
94207
- 'const float v = 4.0;', 'const vec3 K = vec3( 0.686, 0.678, 0.666 );', // MieConst = pi * pow( ( 2.0 * pi ) / lambda, vec3( v - 2.0 ) ) * K
94208
- 'const vec3 MieConst = vec3( 1.8399918514433978E14, 2.7798023919660528E14, 4.0790479543861094E14 );', // earth shadow hack
94210
+ "const float v = 4.0;", "const vec3 K = vec3( 0.686, 0.678, 0.666 );", // MieConst = pi * pow( ( 2.0 * pi ) / lambda, vec3( v - 2.0 ) ) * K
94211
+ "const vec3 MieConst = vec3( 1.8399918514433978E14, 2.7798023919660528E14, 4.0790479543861094E14 );", // earth shadow hack
94209
94212
  // cutoffAngle = pi / 1.95;
94210
- 'const float cutoffAngle = 1.6110731556870734;', 'const float steepness = 1.5;', 'const float EE = 1000.0;', 'float sunIntensity( float zenithAngleCos ) {', ' zenithAngleCos = clamp( zenithAngleCos, -1.0, 1.0 );', ' return EE * max( 0.0, 1.0 - pow( e, -( ( cutoffAngle - acos( zenithAngleCos ) ) / steepness ) ) );', '}', 'vec3 totalMie( float T ) {', ' float c = ( 0.2 * T ) * 10E-18;', ' return 0.434 * c * MieConst;', '}', 'void main() {', ' vec4 worldPosition = modelMatrix * vec4( position, 1.0 );', ' vWorldPosition = worldPosition.xyz;', ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );', ' gl_Position.z = gl_Position.w;', // set z to camera.far
94211
- ' vSunDirection = normalize( sunPosition );', ' vSunE = sunIntensity( dot( vSunDirection, up ) );', ' vSunfade = 1.0 - clamp( 1.0 - exp( ( sunPosition.y / 450000.0 ) ), 0.0, 1.0 );', ' float rayleighCoefficient = rayleigh - ( 1.0 * ( 1.0 - vSunfade ) );', // extinction (absorbtion + out scattering)
94213
+ "const float cutoffAngle = 1.6110731556870734;", "const float steepness = 1.5;", "const float EE = 1000.0;", "float sunIntensity( float zenithAngleCos ) {", " zenithAngleCos = clamp( zenithAngleCos, -1.0, 1.0 );", " return EE * max( 0.0, 1.0 - pow( e, -( ( cutoffAngle - acos( zenithAngleCos ) ) / steepness ) ) );", "}", "vec3 totalMie( float T ) {", " float c = ( 0.2 * T ) * 10E-18;", " return 0.434 * c * MieConst;", "}", "void main() {", " vec4 worldPosition = modelMatrix * vec4( position, 1.0 );", " vWorldPosition = worldPosition.xyz;", " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", " gl_Position.z = gl_Position.w;", // set z to camera.far
94214
+ " vSunDirection = normalize( sunPosition );", " vSunE = sunIntensity( dot( vSunDirection, up ) );", " vSunfade = 1.0 - clamp( 1.0 - exp( ( sunPosition.y / 450000.0 ) ), 0.0, 1.0 );", " float rayleighCoefficient = rayleigh - ( 1.0 * ( 1.0 - vSunfade ) );", // extinction (absorbtion + out scattering)
94212
94215
  // rayleigh coefficients
94213
- ' vBetaR = totalRayleigh * rayleighCoefficient;', // mie coefficients
94214
- ' vBetaM = totalMie( turbidity ) * mieCoefficient;', '}'].join('\n');
94216
+ " vBetaR = totalRayleigh * rayleighCoefficient;", // mie coefficients
94217
+ " vBetaM = totalMie( turbidity ) * mieCoefficient;", "}"].join("\n");
94215
94218
  }
94216
94219
  }, {
94217
94220
  key: "fragmentShader",
94218
94221
  value: function fragmentShader() {
94219
- return ['varying vec3 vWorldPosition;', 'varying vec3 vSunDirection;', 'varying float vSunfade;', 'varying vec3 vBetaR;', 'varying vec3 vBetaM;', 'varying float vSunE;', 'uniform float luminance;', 'uniform float mieDirectionalG;', 'const vec3 cameraPos = vec3( 0.0, 0.0, 0.0 );', // constants for atmospheric scattering
94220
- 'const float pi = 3.141592653589793238462643383279502884197169;', 'const float n = 1.0003;', // refractive index of air
94221
- 'const float N = 2.545E25;', // number of molecules per unit volume for air at
94222
+ return ["varying vec3 vWorldPosition;", "varying vec3 vSunDirection;", "varying float vSunfade;", "varying vec3 vBetaR;", "varying vec3 vBetaM;", "varying float vSunE;", "uniform float luminance;", "uniform float mieDirectionalG;", "const vec3 cameraPos = vec3( 0.0, 0.0, 0.0 );", // constants for atmospheric scattering
94223
+ "const float pi = 3.141592653589793238462643383279502884197169;", "const float n = 1.0003;", // refractive index of air
94224
+ "const float N = 2.545E25;", // number of molecules per unit volume for air at
94222
94225
  // 288.15K and 1013mb (sea level -45 celsius)
94223
94226
  // optical length at zenith for molecules
94224
- 'const float rayleighZenithLength = 8.4E3;', 'const float mieZenithLength = 1.25E3;', 'const vec3 up = vec3( 0.0, 1.0, 0.0 );', // 66 arc seconds -> degrees, and the cosine of that
94225
- 'const float sunAngularDiameterCos = 0.999956676946448443553574619906976478926848692873900859324;', // 3.0 / ( 16.0 * pi )
94226
- 'const float THREE_OVER_SIXTEENPI = 0.05968310365946075;', // 1.0 / ( 4.0 * pi )
94227
- 'const float ONE_OVER_FOURPI = 0.07957747154594767;', 'float rayleighPhase( float cosTheta ) {', ' return THREE_OVER_SIXTEENPI * ( 1.0 + pow( cosTheta, 2.0 ) );', '}', 'float hgPhase( float cosTheta, float g ) {', ' float g2 = pow( g, 2.0 );', ' float inverse = 1.0 / pow( 1.0 - 2.0 * g * cosTheta + g2, 1.5 );', ' return ONE_OVER_FOURPI * ( ( 1.0 - g2 ) * inverse );', '}', // Filmic ToneMapping http://filmicgames.com/archives/75
94228
- 'const float A = 0.15;', 'const float B = 0.50;', 'const float C = 0.10;', 'const float D = 0.20;', 'const float E = 0.02;', 'const float F = 0.30;', 'const float whiteScale = 1.0748724675633854;', // 1.0 / Uncharted2Tonemap(1000.0)
94229
- 'vec3 Uncharted2Tonemap( vec3 x ) {', ' return ( ( x * ( A * x + C * B ) + D * E ) / ( x * ( A * x + B ) + D * F ) ) - E / F;', '}', 'void main() {', // optical length
94227
+ "const float rayleighZenithLength = 8.4E3;", "const float mieZenithLength = 1.25E3;", "const vec3 up = vec3( 0.0, 1.0, 0.0 );", // 66 arc seconds -> degrees, and the cosine of that
94228
+ "const float sunAngularDiameterCos = 0.999956676946448443553574619906976478926848692873900859324;", // 3.0 / ( 16.0 * pi )
94229
+ "const float THREE_OVER_SIXTEENPI = 0.05968310365946075;", // 1.0 / ( 4.0 * pi )
94230
+ "const float ONE_OVER_FOURPI = 0.07957747154594767;", "float rayleighPhase( float cosTheta ) {", " return THREE_OVER_SIXTEENPI * ( 1.0 + pow( cosTheta, 2.0 ) );", "}", "float hgPhase( float cosTheta, float g ) {", " float g2 = pow( g, 2.0 );", " float inverse = 1.0 / pow( 1.0 - 2.0 * g * cosTheta + g2, 1.5 );", " return ONE_OVER_FOURPI * ( ( 1.0 - g2 ) * inverse );", "}", // Filmic ToneMapping http://filmicgames.com/archives/75
94231
+ "const float A = 0.15;", "const float B = 0.50;", "const float C = 0.10;", "const float D = 0.20;", "const float E = 0.02;", "const float F = 0.30;", "const float whiteScale = 1.0748724675633854;", // 1.0 / Uncharted2Tonemap(1000.0)
94232
+ "vec3 Uncharted2Tonemap( vec3 x ) {", " return ( ( x * ( A * x + C * B ) + D * E ) / ( x * ( A * x + B ) + D * F ) ) - E / F;", "}", "void main() {", // optical length
94230
94233
  // cutoff angle at 90 to avoid singularity in next formula.
94231
- ' float zenithAngle = acos( max( 0.0, dot( up, normalize( vWorldPosition - cameraPos ) ) ) );', ' float inverse = 1.0 / ( cos( zenithAngle ) + 0.15 * pow( 93.885 - ( ( zenithAngle * 180.0 ) / pi ), -1.253 ) );', ' float sR = rayleighZenithLength * inverse;', ' float sM = mieZenithLength * inverse;', // combined extinction factor
94232
- ' vec3 Fex = exp( -( vBetaR * sR + vBetaM * sM ) );', // in scattering
94233
- ' float cosTheta = dot( normalize( vWorldPosition - cameraPos ), vSunDirection );', ' float rPhase = rayleighPhase( cosTheta * 0.5 + 0.5 );', ' vec3 betaRTheta = vBetaR * rPhase;', ' float mPhase = hgPhase( cosTheta, mieDirectionalG );', ' vec3 betaMTheta = vBetaM * mPhase;', ' vec3 Lin = pow( vSunE * ( ( betaRTheta + betaMTheta ) / ( vBetaR + vBetaM ) ) * ( 1.0 - Fex ), vec3( 1.5 ) );', ' Lin *= mix( vec3( 1.0 ), pow( vSunE * ( ( betaRTheta + betaMTheta ) / ( vBetaR + vBetaM ) ) * Fex, vec3( 1.0 / 2.0 ) ), clamp( pow( 1.0 - dot( up, vSunDirection ), 5.0 ), 0.0, 1.0 ) );', // nightsky
94234
- ' vec3 direction = normalize( vWorldPosition - cameraPos );', ' float theta = acos( direction.y ); // elevation --> y-axis, [-pi/2, pi/2]', ' float phi = atan( direction.z, direction.x ); // azimuth --> x-axis [-pi/2, pi/2]', ' vec2 uv = vec2( phi, theta ) / vec2( 2.0 * pi, pi ) + vec2( 0.5, 0.0 );', ' vec3 L0 = vec3( 0.1 ) * Fex;', // composition + solar disc
94235
- ' float sundisk = smoothstep( sunAngularDiameterCos, sunAngularDiameterCos + 0.00002, cosTheta );', ' L0 += ( vSunE * 19000.0 * Fex ) * sundisk;', ' vec3 texColor = ( Lin + L0 ) * 0.04 + vec3( 0.0, 0.0003, 0.00075 );', ' vec3 curr = Uncharted2Tonemap( ( log2( 2.0 / pow( luminance, 4.0 ) ) ) * texColor );', ' vec3 color = curr * whiteScale;', ' vec3 retColor = pow( color, vec3( 1.0 / ( 1.2 + ( 1.2 * vSunfade ) ) ) );', ' gl_FragColor = vec4( retColor, 1.0 );', '}'].join('\n');
94234
+ " float zenithAngle = acos( max( 0.0, dot( up, normalize( vWorldPosition - cameraPos ) ) ) );", " float inverse = 1.0 / ( cos( zenithAngle ) + 0.15 * pow( 93.885 - ( ( zenithAngle * 180.0 ) / pi ), -1.253 ) );", " float sR = rayleighZenithLength * inverse;", " float sM = mieZenithLength * inverse;", // combined extinction factor
94235
+ " vec3 Fex = exp( -( vBetaR * sR + vBetaM * sM ) );", // in scattering
94236
+ " float cosTheta = dot( normalize( vWorldPosition - cameraPos ), vSunDirection );", " float rPhase = rayleighPhase( cosTheta * 0.5 + 0.5 );", " vec3 betaRTheta = vBetaR * rPhase;", " float mPhase = hgPhase( cosTheta, mieDirectionalG );", " vec3 betaMTheta = vBetaM * mPhase;", " vec3 Lin = pow( vSunE * ( ( betaRTheta + betaMTheta ) / ( vBetaR + vBetaM ) ) * ( 1.0 - Fex ), vec3( 1.5 ) );", " Lin *= mix( vec3( 1.0 ), pow( vSunE * ( ( betaRTheta + betaMTheta ) / ( vBetaR + vBetaM ) ) * Fex, vec3( 1.0 / 2.0 ) ), clamp( pow( 1.0 - dot( up, vSunDirection ), 5.0 ), 0.0, 1.0 ) );", // nightsky
94237
+ " vec3 direction = normalize( vWorldPosition - cameraPos );", " float theta = acos( direction.y ); // elevation --> y-axis, [-pi/2, pi/2]", " float phi = atan( direction.z, direction.x ); // azimuth --> x-axis [-pi/2, pi/2]", " vec2 uv = vec2( phi, theta ) / vec2( 2.0 * pi, pi ) + vec2( 0.5, 0.0 );", " vec3 L0 = vec3( 0.1 ) * Fex;", // composition + solar disc
94238
+ " float sundisk = smoothstep( sunAngularDiameterCos, sunAngularDiameterCos + 0.00002, cosTheta );", " L0 += ( vSunE * 19000.0 * Fex ) * sundisk;", " vec3 texColor = ( Lin + L0 ) * 0.04 + vec3( 0.0, 0.0003, 0.00075 );", " vec3 curr = Uncharted2Tonemap( ( log2( 2.0 / pow( luminance, 4.0 ) ) ) * texColor );", " vec3 color = curr * whiteScale;", " vec3 retColor = pow( color, vec3( 1.0 / ( 1.2 + ( 1.2 * vSunfade ) ) ) );", " gl_FragColor = vec4( retColor, 1.0 );", "}"].join("\n");
94236
94239
  }
94237
94240
  }]);
94238
94241
 
@@ -94240,10 +94243,10 @@ var Water = /*#__PURE__*/function (_Element) {
94240
94243
  }();
94241
94244
  var DEFAULT_SCALE = 10000;
94242
94245
  var DEFAULT_TURBIDITY = 10;
94243
- var DEFAULT_RALEIGH = .8;
94246
+ var DEFAULT_RALEIGH = 0.8;
94244
94247
  var DEFAULT_MIE_COEFFICIENT = 0.005;
94245
- var DEFAULT_MIE_DIRECTIONAL_G = .8;
94246
- var DEFAULT_SUN_INCLINATION = .49;
94248
+ var DEFAULT_MIE_DIRECTIONAL_G = 0.8;
94249
+ var DEFAULT_SUN_INCLINATION = 0.49;
94247
94250
  var DEFAULT_SUN_AZIMUTH = 0.205;
94248
94251
  var DEFAULT_SUN_DISTANCE = 100;
94249
94252
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mage-engine",
3
- "version": "3.23.9",
3
+ "version": "3.23.10",
4
4
  "description": "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.",
5
5
  "main": "dist/mage.js",
6
6
  "author": {