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