@xviewer.js/core 1.0.0-alpha.27 → 1.0.0-alpha.29
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.
- package/dist/main.js +192 -163
- package/dist/main.js.map +1 -1
- package/dist/module.js +193 -164
- package/dist/module.js.map +1 -1
- package/package.json +1 -1
- package/types/components/Reflector.d.ts +15 -0
- package/types/index.d.ts +1 -1
- package/types/materials/ReflectorMaterial.d.ts +6 -2
- package/types/passes/cubeuv/MergeBlurPass.d.ts +1 -3
- package/types/passes/cubeuv/MergeInfo.d.ts +4 -0
- package/types/passes/cubeuv/MergeReflectPass.d.ts +2 -2
- package/types/passes/cubeuv/utils.d.ts +7 -1
- package/types/plugins/EnvironmentPlugin.d.ts +7 -0
- package/types/tween/TweenChain.d.ts +1 -0
- package/types/loader/aEXRLoader.d.ts +0 -5
- package/types/loader/aFBXLoader.d.ts +0 -5
- package/types/loader/aGLTFLoader.d.ts +0 -5
- package/types/loader/aHDRLoader.d.ts +0 -5
- package/types/loader/aJSONLoader.d.ts +0 -5
- package/types/loader/aTextureLoader.d.ts +0 -5
- package/types/loader/index.d.ts +0 -6
- package/types/material/getShaderMaterial.d.ts +0 -4
- package/types/material/glsl/boxfilterblur.glsl.d.ts +0 -1
- package/types/material/glsl/copy.glsl.d.ts +0 -1
- package/types/material/glsl/fullscreen.glsl.d.ts +0 -1
- package/types/material/glsl/panorama.glsl.d.ts +0 -2
- package/types/material/index.d.ts +0 -1
- package/types/object/Reflector.d.ts +0 -18
- package/types/passes/MipBlurPass2.d.ts +0 -27
- package/types/plugin/Environment.d.ts +0 -5
- package/types/plugins/EnvironmentPlugin2.d.ts +0 -18
- package/types/plugins/EnvironmentPlugin3.d.ts +0 -19
- /package/types/{object → components}/index.d.ts +0 -0
package/dist/module.js
CHANGED
|
@@ -3,7 +3,7 @@ import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js';
|
|
|
3
3
|
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
|
4
4
|
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
|
|
5
5
|
import { MeshoptDecoder } from 'three/examples/jsm/libs/meshopt_decoder.module.js';
|
|
6
|
-
import { EquirectangularReflectionMapping, FileLoader, TextureLoader, SRGBColorSpace, MathUtils, Vector3, Quaternion, Raycaster, Vector2, LinearInterpolant, Spherical, Object3D, Mesh, BoxGeometry, SphereGeometry, PlaneGeometry,
|
|
6
|
+
import { EquirectangularReflectionMapping, FileLoader, TextureLoader, SRGBColorSpace, MathUtils, Vector3, Quaternion, Raycaster, Vector2, LinearInterpolant, Spherical, Object3D, Mesh, BoxGeometry, SphereGeometry, PlaneGeometry, Plane as Plane$1, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget, HalfFloatType, LinearMipMapLinearFilter, LinearFilter, ShaderMaterial, UniformsUtils, Color, Scene, OrthographicCamera, NoBlending, AdditiveBlending, FloatType, UnsignedByteType, BufferGeometry, Float32BufferAttribute, ClampToEdgeWrapping, NearestFilter, LinearSRGBColorSpace, WebGLCubeRenderTarget, DataTexture, RGBAFormat, UVMapping, WebGLRenderer, PCFSoftShadowMap, LoadingManager, LinearToneMapping, PMREMGenerator, MeshBasicMaterial, CubeCamera, Box3Helper, Box3, ShaderLib, ShaderChunk } from 'three';
|
|
7
7
|
import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';
|
|
8
8
|
|
|
9
9
|
class EventEmitter {
|
|
@@ -971,7 +971,7 @@ class TweenChain {
|
|
|
971
971
|
_chainTween() {
|
|
972
972
|
let tween = this._tween;
|
|
973
973
|
if (this._chainedTween) {
|
|
974
|
-
tween = new Tween(this._object);
|
|
974
|
+
tween = new Tween(this._object, this._group);
|
|
975
975
|
this._chainedTween.chain(tween);
|
|
976
976
|
}
|
|
977
977
|
this._chainedTween = tween;
|
|
@@ -979,6 +979,7 @@ class TweenChain {
|
|
|
979
979
|
}
|
|
980
980
|
constructor(object, group){
|
|
981
981
|
this._object = object;
|
|
982
|
+
this._group = group;
|
|
982
983
|
this._tween = new Tween(object, group);
|
|
983
984
|
}
|
|
984
985
|
}
|
|
@@ -2896,68 +2897,11 @@ class Plane extends Mesh {
|
|
|
2896
2897
|
}
|
|
2897
2898
|
}
|
|
2898
2899
|
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
color: {
|
|
2903
|
-
value: null
|
|
2904
|
-
},
|
|
2905
|
-
tDiffuse: {
|
|
2906
|
-
value: null
|
|
2907
|
-
},
|
|
2908
|
-
textureMatrix: {
|
|
2909
|
-
value: null
|
|
2910
|
-
}
|
|
2911
|
-
},
|
|
2912
|
-
vertexShader: /* glsl */ `
|
|
2913
|
-
uniform mat4 textureMatrix;
|
|
2914
|
-
varying vec4 vUv;
|
|
2915
|
-
|
|
2916
|
-
#include <common>
|
|
2917
|
-
#include <logdepthbuf_pars_vertex>
|
|
2918
|
-
|
|
2919
|
-
void main() {
|
|
2920
|
-
vUv = textureMatrix * vec4( position, 1.0 );
|
|
2921
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
2922
|
-
#include <logdepthbuf_vertex>
|
|
2923
|
-
}`,
|
|
2924
|
-
fragmentShader: /* glsl */ `
|
|
2925
|
-
uniform vec3 color;
|
|
2926
|
-
uniform sampler2D tDiffuse;
|
|
2927
|
-
varying vec4 vUv;
|
|
2928
|
-
|
|
2929
|
-
#include <logdepthbuf_pars_fragment>
|
|
2930
|
-
|
|
2931
|
-
float blendOverlay( float base, float blend ) {
|
|
2932
|
-
return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
|
|
2933
|
-
}
|
|
2934
|
-
|
|
2935
|
-
vec3 blendOverlay( vec3 base, vec3 blend ) {
|
|
2936
|
-
return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );
|
|
2937
|
-
}
|
|
2938
|
-
|
|
2939
|
-
void main() {
|
|
2940
|
-
#include <logdepthbuf_fragment>
|
|
2941
|
-
|
|
2942
|
-
vec4 base = texture2DProj( tDiffuse, vUv );
|
|
2943
|
-
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
|
|
2944
|
-
|
|
2945
|
-
#include <tonemapping_fragment>
|
|
2946
|
-
#include <colorspace_fragment>
|
|
2947
|
-
}`
|
|
2948
|
-
};
|
|
2949
|
-
class Reflector extends Mesh {
|
|
2950
|
-
constructor(options = {}){
|
|
2951
|
-
super(options.geometry || new PlaneGeometry());
|
|
2952
|
-
this.isReflector = true;
|
|
2953
|
-
const color = options.color !== undefined ? new Color(options.color) : new Color(0x7F7F7F);
|
|
2954
|
-
const textureWidth = options.textureWidth || 512;
|
|
2955
|
-
const textureHeight = options.textureHeight || 512;
|
|
2956
|
-
const clipBias = options.clipBias || 0;
|
|
2957
|
-
const multisample = options.multisample !== undefined ? options.multisample : 4;
|
|
2958
|
-
const defaultNormal = options.normal || new Vector3(0, 0, 1);
|
|
2900
|
+
class Reflector extends Component {
|
|
2901
|
+
constructor({ textureWidth = 512, textureHeight = 512, clipBias = 0, multisample = 4, layer = 0, normal = new Vector3(0, 0, 1), mipmap = false } = {}){
|
|
2902
|
+
super();
|
|
2959
2903
|
const reflectorPlane = new Plane$1();
|
|
2960
|
-
const
|
|
2904
|
+
const reflectorNormal = new Vector3();
|
|
2961
2905
|
const reflectorWorldPosition = new Vector3();
|
|
2962
2906
|
const cameraWorldPosition = new Vector3();
|
|
2963
2907
|
const rotationMatrix = new Matrix4();
|
|
@@ -2968,51 +2912,37 @@ class Reflector extends Mesh {
|
|
|
2968
2912
|
const q = new Vector4();
|
|
2969
2913
|
const textureMatrix = new Matrix4();
|
|
2970
2914
|
const virtualCamera = new PerspectiveCamera();
|
|
2971
|
-
virtualCamera.layers.set(
|
|
2915
|
+
virtualCamera.layers.set(layer);
|
|
2972
2916
|
const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight, {
|
|
2973
2917
|
samples: multisample,
|
|
2974
|
-
type: HalfFloatType
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
const material = options.material || new ShaderMaterial({
|
|
2978
|
-
name: shader.name ,
|
|
2979
|
-
uniforms: UniformsUtils.clone(shader.uniforms),
|
|
2980
|
-
fragmentShader: shader.fragmentShader,
|
|
2981
|
-
vertexShader: shader.vertexShader
|
|
2918
|
+
type: HalfFloatType,
|
|
2919
|
+
minFilter: mipmap ? LinearMipMapLinearFilter : LinearFilter,
|
|
2920
|
+
generateMipmaps: mipmap
|
|
2982
2921
|
});
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
material.uniforms.textureMatrix.value = textureMatrix;
|
|
2988
|
-
}
|
|
2989
|
-
if (material.uniforms.color) {
|
|
2990
|
-
material.uniforms.color.value = color;
|
|
2991
|
-
}
|
|
2992
|
-
this.material = material;
|
|
2993
|
-
const scope = this;
|
|
2994
|
-
this.onBeforeRender = function(renderer, scene, camera) {
|
|
2995
|
-
reflectorWorldPosition.setFromMatrixPosition(scope.matrixWorld);
|
|
2922
|
+
this.update = ()=>{
|
|
2923
|
+
const node = this.node;
|
|
2924
|
+
const { renderer, camera, scene } = this.viewer;
|
|
2925
|
+
reflectorWorldPosition.setFromMatrixPosition(node.matrixWorld);
|
|
2996
2926
|
cameraWorldPosition.setFromMatrixPosition(camera.matrixWorld);
|
|
2997
|
-
rotationMatrix.extractRotation(
|
|
2998
|
-
|
|
2999
|
-
|
|
2927
|
+
rotationMatrix.extractRotation(node.matrixWorld);
|
|
2928
|
+
reflectorNormal.copy(normal);
|
|
2929
|
+
reflectorNormal.applyMatrix4(rotationMatrix);
|
|
3000
2930
|
view.subVectors(reflectorWorldPosition, cameraWorldPosition);
|
|
3001
2931
|
// Avoid rendering when reflector is facing away
|
|
3002
|
-
if (view.dot(
|
|
3003
|
-
view.reflect(
|
|
2932
|
+
if (view.dot(reflectorNormal) > 0) return;
|
|
2933
|
+
view.reflect(reflectorNormal).negate();
|
|
3004
2934
|
view.add(reflectorWorldPosition);
|
|
3005
2935
|
rotationMatrix.extractRotation(camera.matrixWorld);
|
|
3006
2936
|
lookAtPosition.set(0, 0, -1);
|
|
3007
2937
|
lookAtPosition.applyMatrix4(rotationMatrix);
|
|
3008
2938
|
lookAtPosition.add(cameraWorldPosition);
|
|
3009
2939
|
target.subVectors(reflectorWorldPosition, lookAtPosition);
|
|
3010
|
-
target.reflect(
|
|
2940
|
+
target.reflect(reflectorNormal).negate();
|
|
3011
2941
|
target.add(reflectorWorldPosition);
|
|
3012
2942
|
virtualCamera.position.copy(view);
|
|
3013
2943
|
virtualCamera.up.set(0, 1, 0);
|
|
3014
2944
|
virtualCamera.up.applyMatrix4(rotationMatrix);
|
|
3015
|
-
virtualCamera.up.reflect(
|
|
2945
|
+
virtualCamera.up.reflect(reflectorNormal);
|
|
3016
2946
|
virtualCamera.lookAt(target);
|
|
3017
2947
|
virtualCamera.far = camera.far; // Used in WebGLBackground
|
|
3018
2948
|
virtualCamera.updateMatrixWorld();
|
|
@@ -3021,10 +2951,10 @@ class Reflector extends Mesh {
|
|
|
3021
2951
|
textureMatrix.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);
|
|
3022
2952
|
textureMatrix.multiply(virtualCamera.projectionMatrix);
|
|
3023
2953
|
textureMatrix.multiply(virtualCamera.matrixWorldInverse);
|
|
3024
|
-
textureMatrix.multiply(
|
|
2954
|
+
textureMatrix.multiply(node.matrixWorld);
|
|
3025
2955
|
// Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
|
|
3026
2956
|
// Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
|
|
3027
|
-
reflectorPlane.setFromNormalAndCoplanarPoint(
|
|
2957
|
+
reflectorPlane.setFromNormalAndCoplanarPoint(reflectorNormal, reflectorWorldPosition);
|
|
3028
2958
|
reflectorPlane.applyMatrix4(virtualCamera.matrixWorldInverse);
|
|
3029
2959
|
clipPlane.set(reflectorPlane.normal.x, reflectorPlane.normal.y, reflectorPlane.normal.z, reflectorPlane.constant);
|
|
3030
2960
|
const projectionMatrix = virtualCamera.projectionMatrix;
|
|
@@ -3040,7 +2970,7 @@ class Reflector extends Mesh {
|
|
|
3040
2970
|
projectionMatrix.elements[10] = clipPlane.z + 1.0 - clipBias;
|
|
3041
2971
|
projectionMatrix.elements[14] = clipPlane.w;
|
|
3042
2972
|
// Render
|
|
3043
|
-
|
|
2973
|
+
node.visible = false;
|
|
3044
2974
|
const currentRenderTarget = renderer.getRenderTarget();
|
|
3045
2975
|
const currentActiveCubeFace = renderer.getActiveCubeFace();
|
|
3046
2976
|
const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
|
|
@@ -3060,7 +2990,7 @@ class Reflector extends Mesh {
|
|
|
3060
2990
|
if (viewport !== undefined) {
|
|
3061
2991
|
renderer.state.viewport(viewport);
|
|
3062
2992
|
}
|
|
3063
|
-
|
|
2993
|
+
node.visible = true;
|
|
3064
2994
|
};
|
|
3065
2995
|
this.getRenderTarget = function() {
|
|
3066
2996
|
return renderTarget;
|
|
@@ -3068,9 +2998,8 @@ class Reflector extends Mesh {
|
|
|
3068
2998
|
this.getTextureMatrix = function() {
|
|
3069
2999
|
return textureMatrix;
|
|
3070
3000
|
};
|
|
3071
|
-
this.
|
|
3001
|
+
this.onDestroy = function() {
|
|
3072
3002
|
renderTarget.dispose();
|
|
3073
|
-
scope.material.dispose();
|
|
3074
3003
|
};
|
|
3075
3004
|
}
|
|
3076
3005
|
}
|
|
@@ -3203,7 +3132,13 @@ void main() {
|
|
|
3203
3132
|
#include <beginnormal_vertex>
|
|
3204
3133
|
#include <defaultnormal_vertex>
|
|
3205
3134
|
|
|
3206
|
-
vec4
|
|
3135
|
+
vec4 transformed = vec4(position, 1.);
|
|
3136
|
+
|
|
3137
|
+
#ifdef USE_INSTANCING
|
|
3138
|
+
transformed = instanceMatrix * transformed;
|
|
3139
|
+
#endif
|
|
3140
|
+
|
|
3141
|
+
vec4 positionWS = modelMatrix * transformed;
|
|
3207
3142
|
vec4 mvPosition = viewMatrix * positionWS;
|
|
3208
3143
|
|
|
3209
3144
|
vUv = uv;
|
|
@@ -3220,26 +3155,29 @@ void main() {
|
|
|
3220
3155
|
vUv3 = uv2;
|
|
3221
3156
|
#endif
|
|
3222
3157
|
|
|
3223
|
-
vUv4 = textureMatrix *
|
|
3158
|
+
vUv4 = textureMatrix * transformed;
|
|
3224
3159
|
|
|
3225
3160
|
vViewPosition = -mvPosition.xyz;
|
|
3226
3161
|
vNormal = normalize(transformedNormal);
|
|
3227
3162
|
|
|
3228
3163
|
gl_Position = projectionMatrix * mvPosition;
|
|
3164
|
+
|
|
3229
3165
|
#include <logdepthbuf_vertex>
|
|
3230
3166
|
}
|
|
3231
3167
|
`;
|
|
3232
3168
|
const frag_Reflector = `
|
|
3233
3169
|
uniform vec3 color;
|
|
3170
|
+
uniform float alpha;
|
|
3234
3171
|
uniform float roughness;
|
|
3235
3172
|
uniform float metalness;
|
|
3236
|
-
uniform sampler2D
|
|
3173
|
+
uniform sampler2D map;
|
|
3237
3174
|
uniform sampler2D normalMap;
|
|
3238
3175
|
uniform sampler2D roughnessMap;
|
|
3239
3176
|
uniform sampler2D aoMap;
|
|
3240
3177
|
uniform float aoMapIntensity;
|
|
3241
3178
|
uniform sampler2D lightMap;
|
|
3242
3179
|
uniform float lightMapIntensity;
|
|
3180
|
+
uniform sampler2D tReflect;
|
|
3243
3181
|
|
|
3244
3182
|
varying vec2 vUv;
|
|
3245
3183
|
|
|
@@ -3278,7 +3216,15 @@ void main() {
|
|
|
3278
3216
|
vec3 multiScattering = vec3( 0.0 );
|
|
3279
3217
|
|
|
3280
3218
|
float metalnessFactor = metalness;
|
|
3281
|
-
|
|
3219
|
+
|
|
3220
|
+
vec4 diffuseColor = vec4(color, alpha);
|
|
3221
|
+
|
|
3222
|
+
#ifdef USE_MAP
|
|
3223
|
+
diffuseColor *= texture2D(map, vUv);
|
|
3224
|
+
#endif
|
|
3225
|
+
|
|
3226
|
+
diffuseColor.rgb = diffuseColor.rgb * ( 1.0 - metalnessFactor );
|
|
3227
|
+
|
|
3282
3228
|
vec3 specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
|
|
3283
3229
|
float specularF90 = 1.0;
|
|
3284
3230
|
|
|
@@ -3287,13 +3233,13 @@ void main() {
|
|
|
3287
3233
|
computeMultiscattering( geometryNormal, geometryViewDir, specularColor, specularF90, roughnessFactor, singleScattering, multiScattering );
|
|
3288
3234
|
|
|
3289
3235
|
vec3 totalScattering = singleScattering + multiScattering;
|
|
3290
|
-
vec3 diffuse = diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
|
|
3236
|
+
vec3 diffuse = diffuseColor.rgb * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
|
|
3291
3237
|
|
|
3292
3238
|
vec3 irradiance = vec3(0.);
|
|
3293
3239
|
irradiance += texture2D(lightMap, UV_LIGHTMAP).rgb * lightMapIntensity;
|
|
3294
3240
|
|
|
3295
3241
|
float lod = roughnessFactor * (1.7 - 0.7 * roughnessFactor) * 6.;
|
|
3296
|
-
vec4 reflectColor = textureLod(
|
|
3242
|
+
vec4 reflectColor = textureLod(tReflect, reflectUv, lod);
|
|
3297
3243
|
|
|
3298
3244
|
vec3 f_specular = vec3(0.);
|
|
3299
3245
|
vec3 f_diffuse = vec3(0.);
|
|
@@ -3305,14 +3251,14 @@ void main() {
|
|
|
3305
3251
|
float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
|
|
3306
3252
|
f_specular *= computeSpecularOcclusion(dotNV, ambientOcclusion, roughnessFactor);
|
|
3307
3253
|
|
|
3308
|
-
gl_FragColor = vec4(f_specular + f_diffuse,
|
|
3254
|
+
gl_FragColor = vec4(f_specular + f_diffuse, diffuseColor.a);
|
|
3309
3255
|
|
|
3310
3256
|
#include <tonemapping_fragment>
|
|
3311
3257
|
#include <colorspace_fragment>
|
|
3312
3258
|
}
|
|
3313
3259
|
`;
|
|
3314
3260
|
class ReflectorMaterial extends ShaderMaterial {
|
|
3315
|
-
onBeforeCompile(shader
|
|
3261
|
+
onBeforeCompile(shader) {
|
|
3316
3262
|
const channels = [];
|
|
3317
3263
|
if (this.aoMap && this.aoMap.channel) {
|
|
3318
3264
|
channels.push([
|
|
@@ -3342,6 +3288,12 @@ class ReflectorMaterial extends ShaderMaterial {
|
|
|
3342
3288
|
shader.defines[key] = "vUv" + channel;
|
|
3343
3289
|
});
|
|
3344
3290
|
}
|
|
3291
|
+
get alpha() {
|
|
3292
|
+
return this.uniforms.alpha.value;
|
|
3293
|
+
}
|
|
3294
|
+
set alpha(v) {
|
|
3295
|
+
this.uniforms.alpha.value = v;
|
|
3296
|
+
}
|
|
3345
3297
|
get metalness() {
|
|
3346
3298
|
return this.uniforms.metalness.value;
|
|
3347
3299
|
}
|
|
@@ -3354,33 +3306,35 @@ class ReflectorMaterial extends ShaderMaterial {
|
|
|
3354
3306
|
set roughness(v) {
|
|
3355
3307
|
this.uniforms.roughness.value = v;
|
|
3356
3308
|
}
|
|
3309
|
+
get map() {
|
|
3310
|
+
return this.uniforms.map.value;
|
|
3311
|
+
}
|
|
3312
|
+
set map(v) {
|
|
3313
|
+
this.uniforms.map.value = v;
|
|
3314
|
+
}
|
|
3357
3315
|
get roughnessMap() {
|
|
3358
3316
|
return this.uniforms.roughnessMap.value;
|
|
3359
3317
|
}
|
|
3360
3318
|
set roughnessMap(v) {
|
|
3361
3319
|
this.uniforms.roughnessMap.value = v;
|
|
3362
|
-
this.needsUpdate = true;
|
|
3363
3320
|
}
|
|
3364
3321
|
get normalMap() {
|
|
3365
3322
|
return this.uniforms.normalMap.value;
|
|
3366
3323
|
}
|
|
3367
3324
|
set normalMap(v) {
|
|
3368
3325
|
this.uniforms.normalMap.value = v;
|
|
3369
|
-
this.needsUpdate = true;
|
|
3370
3326
|
}
|
|
3371
3327
|
get aoMap() {
|
|
3372
3328
|
return this.uniforms.aoMap.value;
|
|
3373
3329
|
}
|
|
3374
3330
|
set aoMap(v) {
|
|
3375
3331
|
this.uniforms.aoMap.value = v;
|
|
3376
|
-
this.needsUpdate = true;
|
|
3377
3332
|
}
|
|
3378
3333
|
get lightMap() {
|
|
3379
3334
|
return this.uniforms.lightMap.value;
|
|
3380
3335
|
}
|
|
3381
3336
|
set lightMap(v) {
|
|
3382
3337
|
this.uniforms.lightMap.value = v;
|
|
3383
|
-
this.needsUpdate = true;
|
|
3384
3338
|
}
|
|
3385
3339
|
constructor(...args){
|
|
3386
3340
|
super(...args);
|
|
@@ -3396,12 +3350,18 @@ class ReflectorMaterial extends ShaderMaterial {
|
|
|
3396
3350
|
color: {
|
|
3397
3351
|
value: new Color(0xffffff)
|
|
3398
3352
|
},
|
|
3399
|
-
|
|
3353
|
+
alpha: {
|
|
3354
|
+
value: 1
|
|
3355
|
+
},
|
|
3356
|
+
map: {
|
|
3400
3357
|
value: null
|
|
3401
3358
|
},
|
|
3402
|
-
|
|
3359
|
+
tReflect: {
|
|
3403
3360
|
value: null
|
|
3404
3361
|
},
|
|
3362
|
+
textureMatrix: {
|
|
3363
|
+
value: new Matrix4()
|
|
3364
|
+
},
|
|
3405
3365
|
metalness: {
|
|
3406
3366
|
value: 0
|
|
3407
3367
|
},
|
|
@@ -3429,6 +3389,13 @@ class ReflectorMaterial extends ShaderMaterial {
|
|
|
3429
3389
|
};
|
|
3430
3390
|
}
|
|
3431
3391
|
}
|
|
3392
|
+
__decorate([
|
|
3393
|
+
property({
|
|
3394
|
+
min: 0,
|
|
3395
|
+
max: 1,
|
|
3396
|
+
step: 0.01
|
|
3397
|
+
})
|
|
3398
|
+
], ReflectorMaterial.prototype, "alpha", null);
|
|
3432
3399
|
__decorate([
|
|
3433
3400
|
property({
|
|
3434
3401
|
min: 0,
|
|
@@ -3478,6 +3445,28 @@ class DebugPlugin extends Plugin {
|
|
|
3478
3445
|
|
|
3479
3446
|
const LOD_MIN = 4;
|
|
3480
3447
|
const _flatCamera = /*@__PURE__*/ new OrthographicCamera();
|
|
3448
|
+
// Golden Ratio
|
|
3449
|
+
const PHI = (1 + Math.sqrt(5)) / 2;
|
|
3450
|
+
const INV_PHI = 1 / PHI;
|
|
3451
|
+
// Vertices of a dodecahedron (except the opposites, which represent the
|
|
3452
|
+
// same axis), used as axis directions evenly spread on a sphere.
|
|
3453
|
+
const _axisDirections = [
|
|
3454
|
+
/*@__PURE__*/ new Vector3(1, 1, 1),
|
|
3455
|
+
/*@__PURE__*/ new Vector3(-1, 1, 1),
|
|
3456
|
+
/*@__PURE__*/ new Vector3(1, 1, -1),
|
|
3457
|
+
/*@__PURE__*/ new Vector3(-1, 1, -1),
|
|
3458
|
+
/*@__PURE__*/ new Vector3(0, PHI, INV_PHI),
|
|
3459
|
+
/*@__PURE__*/ new Vector3(0, PHI, -INV_PHI),
|
|
3460
|
+
/*@__PURE__*/ new Vector3(INV_PHI, 0, PHI),
|
|
3461
|
+
/*@__PURE__*/ new Vector3(-INV_PHI, 0, PHI),
|
|
3462
|
+
/*@__PURE__*/ new Vector3(PHI, INV_PHI, 0),
|
|
3463
|
+
/*@__PURE__*/ new Vector3(-PHI, INV_PHI, 0)
|
|
3464
|
+
];
|
|
3465
|
+
const _Performance = {
|
|
3466
|
+
HIGH: 0,
|
|
3467
|
+
MEDIUM: 1,
|
|
3468
|
+
LOW: 2
|
|
3469
|
+
};
|
|
3481
3470
|
function _setViewport(target, x, y, width, height) {
|
|
3482
3471
|
target.viewport.set(x, y, width, height);
|
|
3483
3472
|
target.scissor.set(x, y, width, height);
|
|
@@ -3559,6 +3548,9 @@ function _getCubeMapMaterial() {
|
|
|
3559
3548
|
},
|
|
3560
3549
|
lod: {
|
|
3561
3550
|
value: 0
|
|
3551
|
+
},
|
|
3552
|
+
exposure: {
|
|
3553
|
+
value: 1
|
|
3562
3554
|
}
|
|
3563
3555
|
},
|
|
3564
3556
|
vertexShader: _getCommonVertexShader(),
|
|
@@ -3569,9 +3561,11 @@ function _getCubeMapMaterial() {
|
|
|
3569
3561
|
varying vec3 vOutputDirection;
|
|
3570
3562
|
uniform samplerCube envMap;
|
|
3571
3563
|
uniform float lod;
|
|
3564
|
+
uniform float exposure;
|
|
3572
3565
|
|
|
3573
3566
|
void main() {
|
|
3574
3567
|
gl_FragColor = textureCubeLodEXT(envMap, vOutputDirection, lod);
|
|
3568
|
+
gl_FragColor.rgb *= exposure;
|
|
3575
3569
|
}
|
|
3576
3570
|
`,
|
|
3577
3571
|
blending: AdditiveBlending,
|
|
@@ -4848,12 +4842,13 @@ class MergeRefectPass {
|
|
|
4848
4842
|
return this._envMapTarget;
|
|
4849
4843
|
}
|
|
4850
4844
|
dispose() {
|
|
4845
|
+
this._sourceTarget.dispose();
|
|
4851
4846
|
this._envMapTarget.dispose();
|
|
4852
4847
|
this._pmremGenerator.dispose();
|
|
4853
4848
|
}
|
|
4854
4849
|
mergeReflect(info) {
|
|
4855
|
-
this._pmremGenerator.
|
|
4856
|
-
this._pmremGenerator._mergeReflect(this._envMapTarget, this._reflectMap);
|
|
4850
|
+
this._pmremGenerator._copyTexture(this._envMapTarget, this._sourceTarget.texture, info.envMapIntensity);
|
|
4851
|
+
this._pmremGenerator._mergeReflect(this._envMapTarget, this._reflectMap, info.performance);
|
|
4857
4852
|
info.envMapTarget = this._envMapTarget;
|
|
4858
4853
|
info.lodMax = this._pmremGenerator._lodMeshes.length - 1;
|
|
4859
4854
|
}
|
|
@@ -4876,6 +4871,8 @@ class MergeRefectPass {
|
|
|
4876
4871
|
const uniforms = this._copyTexMaterial.uniforms;
|
|
4877
4872
|
uniforms.map.value = texture;
|
|
4878
4873
|
uniforms.intensity.value = intensity;
|
|
4874
|
+
targetOut.scissorTest = false;
|
|
4875
|
+
_setViewport(targetOut, 0, 0, targetOut.width, targetOut.height);
|
|
4879
4876
|
const renderer = this._renderer;
|
|
4880
4877
|
renderer.autoClear = true;
|
|
4881
4878
|
renderer.setRenderTarget(targetOut);
|
|
@@ -4883,31 +4880,45 @@ class MergeRefectPass {
|
|
|
4883
4880
|
renderer.setRenderTarget(null);
|
|
4884
4881
|
};
|
|
4885
4882
|
pmremGenerator._clearTexture = function(targetOut, intensity) {
|
|
4886
|
-
|
|
4887
|
-
if (this._sourceInit === false) {
|
|
4888
|
-
this._sourceInit = true;
|
|
4889
|
-
source.scissorTest = false;
|
|
4890
|
-
_setViewport(source, 0, 0, source.width, source.height);
|
|
4891
|
-
this._copyTexture(source, targetOut.texture);
|
|
4892
|
-
} else {
|
|
4893
|
-
this._copyTexture(targetOut, source.texture, intensity);
|
|
4894
|
-
}
|
|
4883
|
+
this._copyTexture(targetOut, this._sourceTarget.texture, intensity);
|
|
4895
4884
|
};
|
|
4896
|
-
pmremGenerator._mergeReflect = function(sourceTarget, reflectMap,
|
|
4885
|
+
pmremGenerator._mergeReflect = function(sourceTarget, reflectMap, performance) {
|
|
4897
4886
|
const renderer = this._renderer;
|
|
4898
4887
|
const autoClear = renderer.autoClear;
|
|
4899
4888
|
const cubeMapMaterial = this._cubeMapMaterial;
|
|
4900
4889
|
const uniforms = this._cubeMapMaterial.uniforms;
|
|
4901
4890
|
uniforms.envMap.value = reflectMap;
|
|
4902
|
-
renderer.autoClear =
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4891
|
+
renderer.autoClear = false;
|
|
4892
|
+
if (performance === _Performance.HIGH) {
|
|
4893
|
+
for(let i = 0; i < this._lodMeshes.length - 1; i++){
|
|
4894
|
+
uniforms.lod.value = i < 5 ? 0 : i;
|
|
4895
|
+
this._blit(sourceTarget, i, cubeMapMaterial);
|
|
4896
|
+
}
|
|
4897
|
+
} else if (performance === _Performance.MEDIUM) {
|
|
4898
|
+
for(let i = 0; i < this._lodMeshes.length; i++){
|
|
4899
|
+
if (i < 4) {
|
|
4900
|
+
uniforms.lod.value = 0;
|
|
4901
|
+
this._blit(sourceTarget, i, cubeMapMaterial);
|
|
4902
|
+
} else {
|
|
4903
|
+
this._pmremblur(sourceTarget, i - 1, i);
|
|
4904
|
+
}
|
|
4905
|
+
}
|
|
4906
|
+
} else {
|
|
4907
|
+
uniforms.lod.value = 0;
|
|
4908
|
+
this._blit(sourceTarget, 0, cubeMapMaterial);
|
|
4909
|
+
for(let i = 1; i < this._lodMeshes.length; i++){
|
|
4910
|
+
this._pmremblur(sourceTarget, i - 1, i);
|
|
4911
|
+
}
|
|
4906
4912
|
}
|
|
4907
4913
|
sourceTarget.scissorTest = false;
|
|
4908
4914
|
_setViewport(sourceTarget, 0, 0, sourceTarget.width, sourceTarget.height);
|
|
4909
4915
|
renderer.autoClear = autoClear;
|
|
4910
4916
|
};
|
|
4917
|
+
pmremGenerator._pmremblur = function(targetOut, lodIn, lodOut) {
|
|
4918
|
+
const sigma = Math.sqrt(this._sigmas[lodOut] * this._sigmas[lodOut] - this._sigmas[lodIn] * this._sigmas[lodIn]);
|
|
4919
|
+
const poleAxis = _axisDirections[lodIn % _axisDirections.length];
|
|
4920
|
+
this._blur(targetOut, lodIn, lodOut, sigma, poleAxis);
|
|
4921
|
+
};
|
|
4911
4922
|
pmremGenerator._blit = function(targetOut, lodOut, material) {
|
|
4912
4923
|
const renderer = this._renderer;
|
|
4913
4924
|
const _lodMax = this._lodMax;
|
|
@@ -4924,10 +4935,11 @@ class MergeRefectPass {
|
|
|
4924
4935
|
return pmremGenerator;
|
|
4925
4936
|
}
|
|
4926
4937
|
constructor({ envMap, reflectMap, viewer }){
|
|
4927
|
-
this.envMapIntensity = 1;
|
|
4928
4938
|
this._reflectMap = reflectMap;
|
|
4929
4939
|
this._pmremGenerator = this._getPMREMExtension(viewer.renderer);
|
|
4930
4940
|
this._envMapTarget = this._pmremGenerator._fromTextureExtension(reflectMap, envMap);
|
|
4941
|
+
this._sourceTarget = this._envMapTarget.clone();
|
|
4942
|
+
this._pmremGenerator._copyTexture(this._sourceTarget, this._envMapTarget.texture);
|
|
4931
4943
|
viewer.scene.environment = this._envMapTarget.texture;
|
|
4932
4944
|
}
|
|
4933
4945
|
}
|
|
@@ -4942,12 +4954,21 @@ function mipGaussianBlendWeight(sigma, lod) {
|
|
|
4942
4954
|
|
|
4943
4955
|
const MAX_LOD = 10;
|
|
4944
4956
|
class MergeMipBlurPass {
|
|
4945
|
-
get
|
|
4946
|
-
return this.
|
|
4957
|
+
get envMapTarget() {
|
|
4958
|
+
return this._envMapTarget;
|
|
4959
|
+
}
|
|
4960
|
+
dispose() {
|
|
4961
|
+
this._envMapTarget.dispose();
|
|
4962
|
+
this._pmremGenerator.dispose();
|
|
4963
|
+
}
|
|
4964
|
+
mergeMipBlur(info) {
|
|
4965
|
+
this._setBlurIntensity(info.blurIntensity);
|
|
4966
|
+
const targetIn = this._pmremGenerator._applyMipBlur(this._envMapTarget, this._reflectMap, this._blurMinLod, this._blurMaxLod, this._sigma, info.exposure);
|
|
4967
|
+
this._pmremGenerator._mipCopy(info.envMapTarget, targetIn, info.lodMax, this._blurMinLod);
|
|
4947
4968
|
}
|
|
4948
|
-
|
|
4949
|
-
if (this._blurIntensity !==
|
|
4950
|
-
this._blurIntensity =
|
|
4969
|
+
_setBlurIntensity(blurIntensity) {
|
|
4970
|
+
if (this._blurIntensity !== blurIntensity) {
|
|
4971
|
+
this._blurIntensity = blurIntensity;
|
|
4951
4972
|
this._sigma = MathUtils.lerp(1, 40, this._blurIntensity / 10);
|
|
4952
4973
|
for(let lod = 0; lod <= MAX_LOD; lod++){
|
|
4953
4974
|
let w = mipGaussianBlendWeight(this._sigma, lod);
|
|
@@ -4961,17 +4982,6 @@ class MergeMipBlurPass {
|
|
|
4961
4982
|
}
|
|
4962
4983
|
}
|
|
4963
4984
|
}
|
|
4964
|
-
get envMapTarget() {
|
|
4965
|
-
return this._envMapTarget;
|
|
4966
|
-
}
|
|
4967
|
-
dispose() {
|
|
4968
|
-
this._envMapTarget.dispose();
|
|
4969
|
-
this._pmremGenerator.dispose();
|
|
4970
|
-
}
|
|
4971
|
-
mergeMipBlur(info) {
|
|
4972
|
-
const targetIn = this._pmremGenerator._applyMipBlur(this._envMapTarget, this._reflectMap, this._blurMinLod, this._blurMaxLod, this._sigma, this.exposure);
|
|
4973
|
-
this._pmremGenerator._mipCopy(info.envMapTarget, targetIn, info.lodMax, this._blurMinLod);
|
|
4974
|
-
}
|
|
4975
4985
|
_getPMREMExtension(renderer) {
|
|
4976
4986
|
const pmremGenerator = new PMREMGenerator(renderer);
|
|
4977
4987
|
pmremGenerator._fromTextureExtension = function(texture) {
|
|
@@ -4982,7 +4992,7 @@ class MergeMipBlurPass {
|
|
|
4982
4992
|
this._lodMeshes = this._lodPlanes.map((v)=>new Mesh(v, this._mipBlurMaterial));
|
|
4983
4993
|
return target;
|
|
4984
4994
|
};
|
|
4985
|
-
pmremGenerator._applyMipBlur = function(sourceTarget, texture, blurMinLod, blurMaxLod, sigma, exposure) {
|
|
4995
|
+
pmremGenerator._applyMipBlur = function(sourceTarget, texture, blurMinLod, blurMaxLod, sigma, exposure = 1) {
|
|
4986
4996
|
const pingPongRenderTarget = this._pingPongRenderTarget;
|
|
4987
4997
|
const uniforms = this._mipBlurMaterial.uniforms;
|
|
4988
4998
|
uniforms.envMap.value = texture;
|
|
@@ -5035,7 +5045,6 @@ class MergeMipBlurPass {
|
|
|
5035
5045
|
this._blurMinLod = 0;
|
|
5036
5046
|
this._blurMaxLod = MAX_LOD;
|
|
5037
5047
|
this._blurIntensity = -1;
|
|
5038
|
-
this.exposure = 1;
|
|
5039
5048
|
this._reflectMap = reflectMap;
|
|
5040
5049
|
this._pmremGenerator = this._getPMREMExtension(viewer.renderer);
|
|
5041
5050
|
this._envMapTarget = this._pmremGenerator._fromTextureExtension(reflectMap);
|
|
@@ -5063,13 +5072,15 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5063
5072
|
}),
|
|
5064
5073
|
position: new Vector3(1.1, 3, 0)
|
|
5065
5074
|
});
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5075
|
+
if (this._mipBlurPass) {
|
|
5076
|
+
viewer.addNode(Plane, {
|
|
5077
|
+
parent: this._debugNode,
|
|
5078
|
+
material: new MeshBasicMaterial({
|
|
5079
|
+
map: this._mipBlurPass.envMapTarget.texture
|
|
5080
|
+
}),
|
|
5081
|
+
position: new Vector3(0, 3, 0)
|
|
5082
|
+
});
|
|
5083
|
+
}
|
|
5073
5084
|
}
|
|
5074
5085
|
}
|
|
5075
5086
|
if (this._debugNode) {
|
|
@@ -5083,24 +5094,38 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5083
5094
|
const oldTarget = renderer.getRenderTarget();
|
|
5084
5095
|
const oldActiveCubeFace = renderer.getActiveCubeFace();
|
|
5085
5096
|
const oldActiveMipmapLevel = renderer.getActiveMipmapLevel();
|
|
5086
|
-
this._reflectPass.envMapIntensity = this.envMapIntensity;
|
|
5087
|
-
this._mipBlurPass.exposure = this.reflectExposure;
|
|
5088
|
-
this._mipBlurPass.blurIntensity = this.reflectBlurIntensity;
|
|
5089
5097
|
renderer.autoClear = true;
|
|
5090
5098
|
this._cubeCamera.update(renderer, this._scene);
|
|
5099
|
+
this._mergeInfo.performance = this.performance;
|
|
5100
|
+
this._mergeInfo.exposure = this.reflectExposure;
|
|
5101
|
+
this._mergeInfo.envMapIntensity = this.envMapIntensity;
|
|
5102
|
+
this._mergeInfo.blurIntensity = this.reflectBlurIntensity;
|
|
5091
5103
|
this._reflectPass.mergeReflect(this._mergeInfo);
|
|
5092
|
-
this.
|
|
5104
|
+
if (this.performance === _Performance.HIGH) {
|
|
5105
|
+
if (this._mipBlurPass === undefined) {
|
|
5106
|
+
this._mipBlurPass = new MergeMipBlurPass({
|
|
5107
|
+
viewer: this.viewer,
|
|
5108
|
+
reflectMap: this._cubeCamera.renderTarget.texture
|
|
5109
|
+
});
|
|
5110
|
+
}
|
|
5111
|
+
this._mipBlurPass.mergeMipBlur(this._mergeInfo);
|
|
5112
|
+
}
|
|
5093
5113
|
renderer.autoClear = autoClear;
|
|
5094
5114
|
renderer.setRenderTarget(oldTarget, oldActiveCubeFace, oldActiveMipmapLevel);
|
|
5095
5115
|
}
|
|
5096
5116
|
constructor({ envMap, scene, near, far, layer = 0, resolution = 256, floatType = HalfFloatType, position = new Vector3(0, 1, 0) } = {}){
|
|
5097
5117
|
super();
|
|
5098
5118
|
this._mergeInfo = {
|
|
5119
|
+
performance: _Performance.HIGH,
|
|
5099
5120
|
envMapTarget: null,
|
|
5100
|
-
|
|
5121
|
+
envMapIntensity: 1,
|
|
5122
|
+
blurIntensity: 1,
|
|
5123
|
+
lodMax: 0,
|
|
5124
|
+
exposure: 1
|
|
5101
5125
|
};
|
|
5102
5126
|
this._debug = false;
|
|
5103
5127
|
this._debugNode = null;
|
|
5128
|
+
this.performance = _Performance.LOW;
|
|
5104
5129
|
this.envMapIntensity = 1;
|
|
5105
5130
|
this.reflectExposure = 1;
|
|
5106
5131
|
this.reflectBlurIntensity = 5;
|
|
@@ -5117,20 +5142,24 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5117
5142
|
reflectMap,
|
|
5118
5143
|
envMap
|
|
5119
5144
|
});
|
|
5120
|
-
this._mipBlurPass = new MergeMipBlurPass({
|
|
5121
|
-
viewer,
|
|
5122
|
-
reflectMap
|
|
5123
|
-
});
|
|
5124
5145
|
};
|
|
5125
5146
|
this.uninstall = ()=>{
|
|
5126
5147
|
this._reflectPass.dispose();
|
|
5127
|
-
this._mipBlurPass
|
|
5148
|
+
if (this._mipBlurPass) {
|
|
5149
|
+
this._mipBlurPass.dispose();
|
|
5150
|
+
}
|
|
5128
5151
|
};
|
|
5129
5152
|
}
|
|
5130
5153
|
}
|
|
5154
|
+
EnvironmentPlugin.Performance = _Performance;
|
|
5131
5155
|
__decorate([
|
|
5132
5156
|
property
|
|
5133
5157
|
], EnvironmentPlugin.prototype, "debug", null);
|
|
5158
|
+
__decorate([
|
|
5159
|
+
property({
|
|
5160
|
+
value: _Performance
|
|
5161
|
+
})
|
|
5162
|
+
], EnvironmentPlugin.prototype, "performance", void 0);
|
|
5134
5163
|
__decorate([
|
|
5135
5164
|
property({
|
|
5136
5165
|
min: 0,
|