@xviewer.js/core 1.0.0-alpha.22 → 1.0.0-alpha.25
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 +1237 -49
- package/dist/main.js.map +1 -1
- package/dist/module.js +1228 -50
- package/dist/module.js.map +1 -1
- package/package.json +1 -1
- package/types/TextureSettings.d.ts +1 -0
- package/types/Viewer.d.ts +8 -4
- package/types/asset/aLoader.d.ts +1 -1
- package/types/index.d.ts +5 -2
- package/types/loaders/aEXRLoader.d.ts +5 -0
- package/types/loaders/aFBXLoader.d.ts +5 -0
- package/types/loaders/aGLTFLoader.d.ts +5 -0
- package/types/loaders/aHDRLoader.d.ts +5 -0
- package/types/loaders/aJSONLoader.d.ts +5 -0
- package/types/loaders/aTextureLoader.d.ts +5 -0
- package/types/loaders/index.d.ts +6 -0
- package/types/material/getShaderMaterial.d.ts +2 -2
- package/types/material/index.d.ts +1 -0
- package/types/materials/ReflectorMaterial.d.ts +20 -0
- package/types/materials/getShaderMaterial.d.ts +4 -0
- package/types/materials/glsl/boxfilterblur.glsl.d.ts +1 -0
- package/types/materials/glsl/fullscreen.glsl.d.ts +1 -0
- package/types/materials/glsl/index.d.ts +3 -0
- package/types/materials/glsl/panorama.glsl.d.ts +2 -0
- package/types/materials/index.d.ts +3 -0
- package/types/object/Reflector.d.ts +18 -0
- package/types/object/index.d.ts +1 -0
- package/types/objects/Reflector.d.ts +18 -0
- package/types/objects/index.d.ts +1 -0
- package/types/passes/MipBlurPass.d.ts +27 -0
- package/types/passes/MipBlurPass2.d.ts +27 -0
- package/types/passes/cubeuv/MergeBlurPass.d.ts +23 -0
- package/types/passes/cubeuv/MergeInfo.d.ts +5 -0
- package/types/passes/cubeuv/MergeReflectPass.d.ts +18 -0
- package/types/passes/cubeuv/utils.d.ts +9 -0
- package/types/passes/mipGaussianBlendWeight.d.ts +1 -0
- package/types/plugin/Environment.d.ts +5 -0
- package/types/plugins/BoxProjectionPlugin.d.ts +20 -0
- package/types/plugins/DebugPlugin.d.ts +10 -0
- package/types/plugins/EnvironmentPlugin.d.ts +27 -0
- package/types/plugins/EnvironmentPlugin2.d.ts +18 -0
- package/types/plugins/EnvironmentPlugin3.d.ts +19 -0
- package/types/plugins/index.d.ts +3 -0
- /package/types/{primitives → primitive}/Box.d.ts +0 -0
- /package/types/{primitives → primitive}/Plane.d.ts +0 -0
- /package/types/{primitives → primitive}/Sphere.d.ts +0 -0
- /package/types/{primitives → primitive}/index.d.ts +0 -0
package/dist/main.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var three = require('three');
|
|
4
3
|
var EXRLoader_js = require('three/examples/jsm/loaders/EXRLoader.js');
|
|
5
4
|
var FBXLoader_js = require('three/examples/jsm/loaders/FBXLoader.js');
|
|
6
5
|
var GLTFLoader_js = require('three/examples/jsm/loaders/GLTFLoader.js');
|
|
7
6
|
var DRACOLoader_js = require('three/examples/jsm/loaders/DRACOLoader.js');
|
|
8
7
|
var meshopt_decoder_module_js = require('three/examples/jsm/libs/meshopt_decoder.module.js');
|
|
8
|
+
var three = require('three');
|
|
9
9
|
var RGBELoader_js = require('three/examples/jsm/loaders/RGBELoader.js');
|
|
10
10
|
|
|
11
11
|
class EventEmitter {
|
|
@@ -1008,34 +1008,41 @@ class TweenManager {
|
|
|
1008
1008
|
|
|
1009
1009
|
class aLoader {
|
|
1010
1010
|
static _setMeshData(node) {
|
|
1011
|
-
const
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
tex
|
|
1027
|
-
|
|
1011
|
+
const keys = aLoader._texKeys;
|
|
1012
|
+
const meshes = [];
|
|
1013
|
+
const textures = {};
|
|
1014
|
+
const materials = {};
|
|
1015
|
+
const queue = [
|
|
1016
|
+
node
|
|
1017
|
+
];
|
|
1018
|
+
while(queue.length !== 0){
|
|
1019
|
+
let object = queue.shift();
|
|
1020
|
+
if (object.isMesh) {
|
|
1021
|
+
meshes.push(object);
|
|
1022
|
+
const mat = object.material;
|
|
1023
|
+
if (Array.isArray(mat)) mat.forEach((v)=>materials[v.name] = v);
|
|
1024
|
+
else materials[mat.name] = mat;
|
|
1025
|
+
keys.forEach((k)=>{
|
|
1026
|
+
let tex = mat[k];
|
|
1027
|
+
if (tex) {
|
|
1028
|
+
textures[tex.uuid] = tex;
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1028
1031
|
}
|
|
1032
|
+
object.children.forEach((v)=>queue.push(v));
|
|
1033
|
+
}
|
|
1034
|
+
node.userData.meshData = {
|
|
1035
|
+
meshes,
|
|
1036
|
+
materials,
|
|
1037
|
+
textures
|
|
1029
1038
|
};
|
|
1030
|
-
node.traverse((v)=>v instanceof three.Mesh && callback(v));
|
|
1031
|
-
node.userData.meshData = meshData;
|
|
1032
1039
|
return node;
|
|
1033
1040
|
}
|
|
1034
1041
|
constructor(manager){
|
|
1035
1042
|
this.manager = manager;
|
|
1036
1043
|
}
|
|
1037
1044
|
}
|
|
1038
|
-
aLoader.
|
|
1045
|
+
aLoader._texKeys = [
|
|
1039
1046
|
"alphaMap",
|
|
1040
1047
|
"aoMap",
|
|
1041
1048
|
"bumpMap",
|
|
@@ -2891,6 +2898,706 @@ class Plane extends three.Mesh {
|
|
|
2891
2898
|
}
|
|
2892
2899
|
}
|
|
2893
2900
|
|
|
2901
|
+
const ReflectorShader = {
|
|
2902
|
+
name: 'ReflectorShader',
|
|
2903
|
+
uniforms: {
|
|
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);
|
|
2961
|
+
const reflectorPlane = new three.Plane();
|
|
2962
|
+
const normal = new three.Vector3();
|
|
2963
|
+
const reflectorWorldPosition = new three.Vector3();
|
|
2964
|
+
const cameraWorldPosition = new three.Vector3();
|
|
2965
|
+
const rotationMatrix = new three.Matrix4();
|
|
2966
|
+
const lookAtPosition = new three.Vector3(0, 0, -1);
|
|
2967
|
+
const clipPlane = new three.Vector4();
|
|
2968
|
+
const view = new three.Vector3();
|
|
2969
|
+
const target = new three.Vector3();
|
|
2970
|
+
const q = new three.Vector4();
|
|
2971
|
+
const textureMatrix = new three.Matrix4();
|
|
2972
|
+
const virtualCamera = new three.PerspectiveCamera();
|
|
2973
|
+
virtualCamera.layers.set(options.layer || 0);
|
|
2974
|
+
const renderTarget = new three.WebGLRenderTarget(textureWidth, textureHeight, {
|
|
2975
|
+
samples: multisample,
|
|
2976
|
+
type: three.HalfFloatType
|
|
2977
|
+
});
|
|
2978
|
+
const shader = ReflectorShader;
|
|
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
|
|
2984
|
+
});
|
|
2985
|
+
if (material.uniforms.tDiffuse) {
|
|
2986
|
+
material.uniforms.tDiffuse.value = renderTarget.texture;
|
|
2987
|
+
}
|
|
2988
|
+
if (material.uniforms.textureMatrix) {
|
|
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);
|
|
2998
|
+
cameraWorldPosition.setFromMatrixPosition(camera.matrixWorld);
|
|
2999
|
+
rotationMatrix.extractRotation(scope.matrixWorld);
|
|
3000
|
+
normal.copy(defaultNormal);
|
|
3001
|
+
normal.applyMatrix4(rotationMatrix);
|
|
3002
|
+
view.subVectors(reflectorWorldPosition, cameraWorldPosition);
|
|
3003
|
+
// Avoid rendering when reflector is facing away
|
|
3004
|
+
if (view.dot(normal) > 0) return;
|
|
3005
|
+
view.reflect(normal).negate();
|
|
3006
|
+
view.add(reflectorWorldPosition);
|
|
3007
|
+
rotationMatrix.extractRotation(camera.matrixWorld);
|
|
3008
|
+
lookAtPosition.set(0, 0, -1);
|
|
3009
|
+
lookAtPosition.applyMatrix4(rotationMatrix);
|
|
3010
|
+
lookAtPosition.add(cameraWorldPosition);
|
|
3011
|
+
target.subVectors(reflectorWorldPosition, lookAtPosition);
|
|
3012
|
+
target.reflect(normal).negate();
|
|
3013
|
+
target.add(reflectorWorldPosition);
|
|
3014
|
+
virtualCamera.position.copy(view);
|
|
3015
|
+
virtualCamera.up.set(0, 1, 0);
|
|
3016
|
+
virtualCamera.up.applyMatrix4(rotationMatrix);
|
|
3017
|
+
virtualCamera.up.reflect(normal);
|
|
3018
|
+
virtualCamera.lookAt(target);
|
|
3019
|
+
virtualCamera.far = camera.far; // Used in WebGLBackground
|
|
3020
|
+
virtualCamera.updateMatrixWorld();
|
|
3021
|
+
virtualCamera.projectionMatrix.copy(camera.projectionMatrix);
|
|
3022
|
+
// Update the texture matrix
|
|
3023
|
+
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
|
+
textureMatrix.multiply(virtualCamera.projectionMatrix);
|
|
3025
|
+
textureMatrix.multiply(virtualCamera.matrixWorldInverse);
|
|
3026
|
+
textureMatrix.multiply(scope.matrixWorld);
|
|
3027
|
+
// Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
|
|
3028
|
+
// Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
|
|
3029
|
+
reflectorPlane.setFromNormalAndCoplanarPoint(normal, reflectorWorldPosition);
|
|
3030
|
+
reflectorPlane.applyMatrix4(virtualCamera.matrixWorldInverse);
|
|
3031
|
+
clipPlane.set(reflectorPlane.normal.x, reflectorPlane.normal.y, reflectorPlane.normal.z, reflectorPlane.constant);
|
|
3032
|
+
const projectionMatrix = virtualCamera.projectionMatrix;
|
|
3033
|
+
q.x = (Math.sign(clipPlane.x) + projectionMatrix.elements[8]) / projectionMatrix.elements[0];
|
|
3034
|
+
q.y = (Math.sign(clipPlane.y) + projectionMatrix.elements[9]) / projectionMatrix.elements[5];
|
|
3035
|
+
q.z = -1.0;
|
|
3036
|
+
q.w = (1.0 + projectionMatrix.elements[10]) / projectionMatrix.elements[14];
|
|
3037
|
+
// Calculate the scaled plane vector
|
|
3038
|
+
clipPlane.multiplyScalar(2.0 / clipPlane.dot(q));
|
|
3039
|
+
// Replacing the third row of the projection matrix
|
|
3040
|
+
projectionMatrix.elements[2] = clipPlane.x;
|
|
3041
|
+
projectionMatrix.elements[6] = clipPlane.y;
|
|
3042
|
+
projectionMatrix.elements[10] = clipPlane.z + 1.0 - clipBias;
|
|
3043
|
+
projectionMatrix.elements[14] = clipPlane.w;
|
|
3044
|
+
// Render
|
|
3045
|
+
scope.visible = false;
|
|
3046
|
+
const currentRenderTarget = renderer.getRenderTarget();
|
|
3047
|
+
const currentActiveCubeFace = renderer.getActiveCubeFace();
|
|
3048
|
+
const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
|
|
3049
|
+
const currentXrEnabled = renderer.xr.enabled;
|
|
3050
|
+
const currentShadowAutoUpdate = renderer.shadowMap.autoUpdate;
|
|
3051
|
+
renderer.xr.enabled = false; // Avoid camera modification
|
|
3052
|
+
renderer.shadowMap.autoUpdate = false; // Avoid re-computing shadows
|
|
3053
|
+
renderer.setRenderTarget(renderTarget);
|
|
3054
|
+
renderer.state.buffers.depth.setMask(true); // make sure the depth buffer is writable so it can be properly cleared, see #18897
|
|
3055
|
+
if (renderer.autoClear === false) renderer.clear();
|
|
3056
|
+
renderer.render(scene, virtualCamera);
|
|
3057
|
+
renderer.xr.enabled = currentXrEnabled;
|
|
3058
|
+
renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
|
|
3059
|
+
renderer.setRenderTarget(currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel);
|
|
3060
|
+
// Restore viewport
|
|
3061
|
+
const viewport = camera.viewport;
|
|
3062
|
+
if (viewport !== undefined) {
|
|
3063
|
+
renderer.state.viewport(viewport);
|
|
3064
|
+
}
|
|
3065
|
+
scope.visible = true;
|
|
3066
|
+
};
|
|
3067
|
+
this.getRenderTarget = function() {
|
|
3068
|
+
return renderTarget;
|
|
3069
|
+
};
|
|
3070
|
+
this.getTextureMatrix = function() {
|
|
3071
|
+
return textureMatrix;
|
|
3072
|
+
};
|
|
3073
|
+
this.dispose = function() {
|
|
3074
|
+
renderTarget.dispose();
|
|
3075
|
+
scope.material.dispose();
|
|
3076
|
+
};
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
|
|
3080
|
+
const vert_fullscreen = /*glsl*/ `
|
|
3081
|
+
varying vec2 vUv;
|
|
3082
|
+
void main() {
|
|
3083
|
+
vUv = position.xy * 0.5 + 0.5;
|
|
3084
|
+
gl_Position = vec4(position.xy, 1.0, 1.0);
|
|
3085
|
+
}
|
|
3086
|
+
`;
|
|
3087
|
+
|
|
3088
|
+
const frag_BoxfilterBlur = `
|
|
3089
|
+
#include <common>
|
|
3090
|
+
uniform sampler2D tLast;
|
|
3091
|
+
uniform sampler2D tBlur;
|
|
3092
|
+
uniform float uLod;
|
|
3093
|
+
uniform float uWeight;
|
|
3094
|
+
varying vec2 vUv;
|
|
3095
|
+
|
|
3096
|
+
void main() {
|
|
3097
|
+
vec3 col0 = textureLod(tLast, vUv, 0.).rgb;
|
|
3098
|
+
vec3 col1 = textureLod(tBlur, vUv, uLod).rgb;
|
|
3099
|
+
gl_FragColor = vec4(mix(col0, col1, uWeight), 1.);
|
|
3100
|
+
}
|
|
3101
|
+
`;
|
|
3102
|
+
|
|
3103
|
+
const frag_panoramaToCubeMap = `
|
|
3104
|
+
#include <xv_common>
|
|
3105
|
+
|
|
3106
|
+
varying vec2 vUv;
|
|
3107
|
+
uniform sampler2D tMain;
|
|
3108
|
+
uniform int uFace;
|
|
3109
|
+
uniform vec4 uTilingOffset;
|
|
3110
|
+
|
|
3111
|
+
vec3 uvToXYZ(int face, vec2 uv) {
|
|
3112
|
+
if (face == 0) return vec3(-1.0, uv.y, -uv.x);
|
|
3113
|
+
else if (face == 1) return vec3(1.0, uv.y, uv.x);
|
|
3114
|
+
else if (face == 2) return vec3(-uv.x, -1.0, uv.y);
|
|
3115
|
+
else if (face == 3) return vec3(-uv.x, 1.0, -uv.y);
|
|
3116
|
+
else if (face == 4) return vec3(-uv.x, uv.y, 1.0);
|
|
3117
|
+
else return vec3(uv.x, uv.y, -1.0);
|
|
3118
|
+
}
|
|
3119
|
+
|
|
3120
|
+
vec4 panoramaToCubeMap(int face, vec2 uv_i) {
|
|
3121
|
+
vec2 uv = uv_i * 2.0 - 1.0;
|
|
3122
|
+
vec3 dir = normalize(uvToXYZ(face, uv));
|
|
3123
|
+
vec2 uv_o = dirToUv(dir);
|
|
3124
|
+
uv_o = vec2(uv_o.x, uv_o.y) * uTilingOffset.xy + uTilingOffset.zw;
|
|
3125
|
+
return texture(tMain, uv_o);
|
|
3126
|
+
}
|
|
3127
|
+
|
|
3128
|
+
void main() {
|
|
3129
|
+
gl_FragColor = panoramaToCubeMap(uFace, vUv);
|
|
3130
|
+
}
|
|
3131
|
+
`;
|
|
3132
|
+
const frag_cubeMapToPanorama = `
|
|
3133
|
+
#include <xv_common>
|
|
3134
|
+
|
|
3135
|
+
varying vec2 vUv;
|
|
3136
|
+
uniform samplerCube tMain;
|
|
3137
|
+
|
|
3138
|
+
vec4 cubeMapToPanorama(vec2 uv_i) {
|
|
3139
|
+
return texture(tMain, uvToDir(uv_i));
|
|
3140
|
+
}
|
|
3141
|
+
|
|
3142
|
+
void main() {
|
|
3143
|
+
gl_FragColor = cubeMapToPanorama(vUv);
|
|
3144
|
+
}
|
|
3145
|
+
`;
|
|
3146
|
+
|
|
3147
|
+
function getShaderMaterial(uniforms, vertexShader, fragmentShader, onInit) {
|
|
3148
|
+
const material = class extends three.ShaderMaterial {
|
|
3149
|
+
constructor(parameters = {}){
|
|
3150
|
+
const entries = Object.entries(uniforms);
|
|
3151
|
+
// Create unforms and shaders
|
|
3152
|
+
super({
|
|
3153
|
+
uniforms: entries.reduce((acc, [name, value])=>{
|
|
3154
|
+
const uniform = three.UniformsUtils.clone({
|
|
3155
|
+
[name]: {
|
|
3156
|
+
value
|
|
3157
|
+
}
|
|
3158
|
+
});
|
|
3159
|
+
return {
|
|
3160
|
+
...acc,
|
|
3161
|
+
...uniform
|
|
3162
|
+
};
|
|
3163
|
+
}, {}),
|
|
3164
|
+
vertexShader,
|
|
3165
|
+
fragmentShader
|
|
3166
|
+
});
|
|
3167
|
+
// Create getter/setters
|
|
3168
|
+
entries.forEach(([name])=>Object.defineProperty(this, name, {
|
|
3169
|
+
get: ()=>this.uniforms[name].value,
|
|
3170
|
+
set: (v)=>this.uniforms[name].value = v
|
|
3171
|
+
}));
|
|
3172
|
+
// Assign parameters, this might include uniforms
|
|
3173
|
+
Object.assign(this, parameters);
|
|
3174
|
+
// Call onInit
|
|
3175
|
+
if (onInit) onInit(this);
|
|
3176
|
+
}
|
|
3177
|
+
};
|
|
3178
|
+
return material;
|
|
3179
|
+
}
|
|
3180
|
+
|
|
3181
|
+
const vert_Reflector = `
|
|
3182
|
+
uniform mat4 textureMatrix;
|
|
3183
|
+
varying vec4 vUv4;
|
|
3184
|
+
varying vec2 vUv;
|
|
3185
|
+
varying vec2 vUv1;
|
|
3186
|
+
varying vec3 vViewPosition;
|
|
3187
|
+
|
|
3188
|
+
#include <common>
|
|
3189
|
+
#include <normal_pars_vertex>
|
|
3190
|
+
#include <logdepthbuf_pars_vertex>
|
|
3191
|
+
|
|
3192
|
+
void main() {
|
|
3193
|
+
#include <beginnormal_vertex>
|
|
3194
|
+
#include <defaultnormal_vertex>
|
|
3195
|
+
|
|
3196
|
+
vec4 positionWS = modelMatrix * vec4(position, 1.0);
|
|
3197
|
+
vec4 mvPosition = viewMatrix * positionWS;
|
|
3198
|
+
|
|
3199
|
+
vUv = uv;
|
|
3200
|
+
vUv1 = uv1;
|
|
3201
|
+
vUv4 = textureMatrix * vec4(position, 1.0);
|
|
3202
|
+
|
|
3203
|
+
vViewPosition = -mvPosition.xyz;
|
|
3204
|
+
vNormal = normalize(transformedNormal);
|
|
3205
|
+
|
|
3206
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
3207
|
+
#include <logdepthbuf_vertex>
|
|
3208
|
+
}
|
|
3209
|
+
`;
|
|
3210
|
+
const frag_Reflector = `
|
|
3211
|
+
uniform vec3 color;
|
|
3212
|
+
uniform float roughness;
|
|
3213
|
+
uniform float metalness;
|
|
3214
|
+
uniform sampler2D tDiffuse;
|
|
3215
|
+
uniform sampler2D normalMap;
|
|
3216
|
+
uniform sampler2D roughnessMap;
|
|
3217
|
+
uniform sampler2D aoMap;
|
|
3218
|
+
uniform float aoMapIntensity;
|
|
3219
|
+
uniform sampler2D lightMap;
|
|
3220
|
+
uniform float lightMapIntensity;
|
|
3221
|
+
|
|
3222
|
+
varying vec4 vUv4;
|
|
3223
|
+
varying vec2 vUv;
|
|
3224
|
+
varying vec2 vUv1;
|
|
3225
|
+
varying vec3 vViewPosition;
|
|
3226
|
+
varying vec3 vNormal;
|
|
3227
|
+
|
|
3228
|
+
#include <common>
|
|
3229
|
+
#include <lights_physical_pars_fragment>
|
|
3230
|
+
#include <logdepthbuf_pars_fragment>
|
|
3231
|
+
|
|
3232
|
+
void main() {
|
|
3233
|
+
#include <logdepthbuf_fragment>
|
|
3234
|
+
|
|
3235
|
+
vec4 uv4 = vUv4;
|
|
3236
|
+
vec4 texelNormal = texture2D(normalMap, vUv);
|
|
3237
|
+
vec3 normal = normalize(vec3(texelNormal.r * 2.0 - 1.0, texelNormal.b, texelNormal.g * 2.0 - 1.0));
|
|
3238
|
+
vec3 coord = uv4.xyz / uv4.w;
|
|
3239
|
+
vec2 reflectUv = coord.xy + coord.z * normal.xz * 0.05;
|
|
3240
|
+
|
|
3241
|
+
vec3 geometryNormal = normalize(vNormal);
|
|
3242
|
+
vec3 geometryViewDir = normalize(vViewPosition);
|
|
3243
|
+
|
|
3244
|
+
vec3 singleScattering = vec3( 0.0 );
|
|
3245
|
+
vec3 multiScattering = vec3( 0.0 );
|
|
3246
|
+
|
|
3247
|
+
float metalnessFactor = metalness;
|
|
3248
|
+
vec3 diffuseColor = color.rgb * ( 1.0 - metalnessFactor );
|
|
3249
|
+
vec3 specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
|
|
3250
|
+
float specularF90 = 1.0;
|
|
3251
|
+
|
|
3252
|
+
float roughnessFactor = texture2D(roughnessMap, vUv).g * roughness;
|
|
3253
|
+
|
|
3254
|
+
computeMultiscattering( geometryNormal, geometryViewDir, specularColor, specularF90, roughnessFactor, singleScattering, multiScattering );
|
|
3255
|
+
|
|
3256
|
+
vec3 totalScattering = singleScattering + multiScattering;
|
|
3257
|
+
vec3 diffuse = diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
|
|
3258
|
+
|
|
3259
|
+
vec3 irradiance = vec3(0.);
|
|
3260
|
+
irradiance += texture2D(lightMap, vUv).rgb * lightMapIntensity;
|
|
3261
|
+
|
|
3262
|
+
float lod = roughnessFactor * (1.7 - 0.7 * roughnessFactor) * 6.;
|
|
3263
|
+
vec4 reflectColor = textureLod(tDiffuse, reflectUv, lod);
|
|
3264
|
+
|
|
3265
|
+
vec3 f_specular = vec3(0.);
|
|
3266
|
+
vec3 f_diffuse = vec3(0.);
|
|
3267
|
+
|
|
3268
|
+
f_specular += reflectColor.rgb * (1.0 - roughnessFactor * roughnessFactor) + multiScattering * irradiance;
|
|
3269
|
+
f_diffuse += diffuse * irradiance;
|
|
3270
|
+
|
|
3271
|
+
float ambientOcclusion = mix(1., texture2D(aoMap, vUv1).r, aoMapIntensity);
|
|
3272
|
+
float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
|
|
3273
|
+
f_specular *= computeSpecularOcclusion(dotNV, ambientOcclusion, roughnessFactor);
|
|
3274
|
+
|
|
3275
|
+
gl_FragColor = vec4(f_specular + f_diffuse, 1.);
|
|
3276
|
+
|
|
3277
|
+
#include <tonemapping_fragment>
|
|
3278
|
+
#include <colorspace_fragment>
|
|
3279
|
+
}
|
|
3280
|
+
`;
|
|
3281
|
+
class ReflectorMaterial extends three.ShaderMaterial {
|
|
3282
|
+
get metalness() {
|
|
3283
|
+
return this.uniforms.metalness.value;
|
|
3284
|
+
}
|
|
3285
|
+
set metalness(v) {
|
|
3286
|
+
this.uniforms.metalness.value = v;
|
|
3287
|
+
}
|
|
3288
|
+
get roughness() {
|
|
3289
|
+
return this.uniforms.roughness.value;
|
|
3290
|
+
}
|
|
3291
|
+
set roughness(v) {
|
|
3292
|
+
this.uniforms.roughness.value = v;
|
|
3293
|
+
}
|
|
3294
|
+
get roughnessMap() {
|
|
3295
|
+
return this.uniforms.roughnessMap.value;
|
|
3296
|
+
}
|
|
3297
|
+
set roughnessMap(v) {
|
|
3298
|
+
this.uniforms.roughnessMap.value = v;
|
|
3299
|
+
}
|
|
3300
|
+
get normalMap() {
|
|
3301
|
+
return this.uniforms.normalMap.value;
|
|
3302
|
+
}
|
|
3303
|
+
set normalMap(v) {
|
|
3304
|
+
this.uniforms.normalMap.value = v;
|
|
3305
|
+
}
|
|
3306
|
+
get aoMap() {
|
|
3307
|
+
return this.uniforms.aoMap.value;
|
|
3308
|
+
}
|
|
3309
|
+
set aoMap(v) {
|
|
3310
|
+
this.uniforms.aoMap.value = v;
|
|
3311
|
+
}
|
|
3312
|
+
get lightMap() {
|
|
3313
|
+
return this.uniforms.lightMap.value;
|
|
3314
|
+
}
|
|
3315
|
+
set lightMap(v) {
|
|
3316
|
+
this.uniforms.lightMap.value = v;
|
|
3317
|
+
}
|
|
3318
|
+
constructor(...args){
|
|
3319
|
+
super(...args);
|
|
3320
|
+
this.vertexShader = vert_Reflector;
|
|
3321
|
+
this.fragmentShader = frag_Reflector;
|
|
3322
|
+
this.uniforms = {
|
|
3323
|
+
color: {
|
|
3324
|
+
value: new three.Color(0xffffff)
|
|
3325
|
+
},
|
|
3326
|
+
tDiffuse: {
|
|
3327
|
+
value: null
|
|
3328
|
+
},
|
|
3329
|
+
textureMatrix: {
|
|
3330
|
+
value: null
|
|
3331
|
+
},
|
|
3332
|
+
metalness: {
|
|
3333
|
+
value: 0
|
|
3334
|
+
},
|
|
3335
|
+
roughness: {
|
|
3336
|
+
value: 1
|
|
3337
|
+
},
|
|
3338
|
+
roughnessMap: {
|
|
3339
|
+
value: null
|
|
3340
|
+
},
|
|
3341
|
+
normalMap: {
|
|
3342
|
+
value: null
|
|
3343
|
+
},
|
|
3344
|
+
aoMap: {
|
|
3345
|
+
value: null
|
|
3346
|
+
},
|
|
3347
|
+
aoMapIntensity: {
|
|
3348
|
+
value: 1
|
|
3349
|
+
},
|
|
3350
|
+
lightMap: {
|
|
3351
|
+
value: null
|
|
3352
|
+
},
|
|
3353
|
+
lightMapIntensity: {
|
|
3354
|
+
value: 1
|
|
3355
|
+
}
|
|
3356
|
+
};
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
__decorate([
|
|
3360
|
+
property({
|
|
3361
|
+
min: 0,
|
|
3362
|
+
max: 1,
|
|
3363
|
+
step: 0.01
|
|
3364
|
+
})
|
|
3365
|
+
], ReflectorMaterial.prototype, "metalness", null);
|
|
3366
|
+
__decorate([
|
|
3367
|
+
property({
|
|
3368
|
+
min: 0,
|
|
3369
|
+
max: 1,
|
|
3370
|
+
step: 0.01
|
|
3371
|
+
})
|
|
3372
|
+
], ReflectorMaterial.prototype, "roughness", null);
|
|
3373
|
+
|
|
3374
|
+
class Plugin extends ObjectInstance {
|
|
3375
|
+
constructor(...args){
|
|
3376
|
+
super(...args);
|
|
3377
|
+
this.type = "Plugin";
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
|
|
3381
|
+
class DebugPlugin extends Plugin {
|
|
3382
|
+
static Instance(viewer) {
|
|
3383
|
+
return viewer.getPlugin(DebugPlugin, true);
|
|
3384
|
+
}
|
|
3385
|
+
add(node) {
|
|
3386
|
+
this.scene.add(node);
|
|
3387
|
+
return node;
|
|
3388
|
+
}
|
|
3389
|
+
remove(node) {
|
|
3390
|
+
this.scene.remove(node);
|
|
3391
|
+
return node;
|
|
3392
|
+
}
|
|
3393
|
+
onRender(dt) {
|
|
3394
|
+
const { renderer, camera } = this.viewer;
|
|
3395
|
+
const autoClear = renderer.autoClear;
|
|
3396
|
+
renderer.autoClear = false;
|
|
3397
|
+
renderer.render(this.scene, camera);
|
|
3398
|
+
renderer.autoClear = autoClear;
|
|
3399
|
+
}
|
|
3400
|
+
constructor(...args){
|
|
3401
|
+
super(...args);
|
|
3402
|
+
this.scene = new three.Scene();
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
|
|
3406
|
+
const LOD_MIN = 4;
|
|
3407
|
+
const _flatCamera = /*@__PURE__*/ new three.OrthographicCamera();
|
|
3408
|
+
function _setViewport(target, x, y, width, height) {
|
|
3409
|
+
target.viewport.set(x, y, width, height);
|
|
3410
|
+
target.scissor.set(x, y, width, height);
|
|
3411
|
+
}
|
|
3412
|
+
function _getCommonVertexShader() {
|
|
3413
|
+
return /* glsl */ `
|
|
3414
|
+
precision mediump float;
|
|
3415
|
+
precision mediump int;
|
|
3416
|
+
|
|
3417
|
+
attribute float faceIndex;
|
|
3418
|
+
|
|
3419
|
+
varying vec3 vOutputDirection;
|
|
3420
|
+
|
|
3421
|
+
// RH coordinate system; PMREM face-indexing convention
|
|
3422
|
+
vec3 getDirection( vec2 uv, float face ) {
|
|
3423
|
+
|
|
3424
|
+
uv = 2.0 * uv - 1.0;
|
|
3425
|
+
vec3 direction = vec3( uv, 1.0 );
|
|
3426
|
+
|
|
3427
|
+
if ( face == 0.0 ) {
|
|
3428
|
+
direction = direction.zyx; // ( 1, v, u ) pos x
|
|
3429
|
+
} else if ( face == 1.0 ) {
|
|
3430
|
+
direction = direction.xzy;
|
|
3431
|
+
direction.xz *= -1.0; // ( -u, 1, -v ) pos y
|
|
3432
|
+
} else if ( face == 2.0 ) {
|
|
3433
|
+
direction.x *= -1.0; // ( -u, v, 1 ) pos z
|
|
3434
|
+
} else if ( face == 3.0 ) {
|
|
3435
|
+
direction = direction.zyx;
|
|
3436
|
+
direction.xz *= -1.0; // ( -1, v, -u ) neg x
|
|
3437
|
+
} else if ( face == 4.0 ) {
|
|
3438
|
+
direction = direction.xzy;
|
|
3439
|
+
direction.xy *= -1.0; // ( -u, -1, v ) neg y
|
|
3440
|
+
} else if ( face == 5.0 ) {
|
|
3441
|
+
direction.z *= -1.0; // ( u, v, -1 ) neg z
|
|
3442
|
+
}
|
|
3443
|
+
|
|
3444
|
+
return direction;
|
|
3445
|
+
|
|
3446
|
+
}
|
|
3447
|
+
|
|
3448
|
+
void main() {
|
|
3449
|
+
vOutputDirection = getDirection( uv, faceIndex );
|
|
3450
|
+
gl_Position = vec4( position, 1.0 );
|
|
3451
|
+
}
|
|
3452
|
+
`;
|
|
3453
|
+
}
|
|
3454
|
+
function _getClearMaterial() {
|
|
3455
|
+
return new three.ShaderMaterial({
|
|
3456
|
+
name: "Clear",
|
|
3457
|
+
uniforms: {
|
|
3458
|
+
map: {
|
|
3459
|
+
value: null
|
|
3460
|
+
},
|
|
3461
|
+
intensity: {
|
|
3462
|
+
value: 1
|
|
3463
|
+
}
|
|
3464
|
+
},
|
|
3465
|
+
vertexShader: vert_fullscreen,
|
|
3466
|
+
fragmentShader: /* glsl */ `
|
|
3467
|
+
uniform sampler2D map;
|
|
3468
|
+
uniform float intensity;
|
|
3469
|
+
varying vec2 vUv;
|
|
3470
|
+
void main() {
|
|
3471
|
+
vec4 col = texture2D(map, vUv);
|
|
3472
|
+
gl_FragColor = vec4(col.rgb * intensity, col.a);
|
|
3473
|
+
}
|
|
3474
|
+
`,
|
|
3475
|
+
blending: three.NoBlending,
|
|
3476
|
+
depthWrite: false,
|
|
3477
|
+
depthTest: false
|
|
3478
|
+
});
|
|
3479
|
+
}
|
|
3480
|
+
function _getCubeMapMaterial() {
|
|
3481
|
+
return new three.ShaderMaterial({
|
|
3482
|
+
name: "CubeMapToCubeUV",
|
|
3483
|
+
uniforms: {
|
|
3484
|
+
envMap: {
|
|
3485
|
+
value: null
|
|
3486
|
+
},
|
|
3487
|
+
lod: {
|
|
3488
|
+
value: 0
|
|
3489
|
+
}
|
|
3490
|
+
},
|
|
3491
|
+
vertexShader: _getCommonVertexShader(),
|
|
3492
|
+
fragmentShader: /* glsl */ `
|
|
3493
|
+
precision mediump float;
|
|
3494
|
+
precision mediump int;
|
|
3495
|
+
|
|
3496
|
+
varying vec3 vOutputDirection;
|
|
3497
|
+
uniform samplerCube envMap;
|
|
3498
|
+
uniform float lod;
|
|
3499
|
+
|
|
3500
|
+
void main() {
|
|
3501
|
+
gl_FragColor = textureCubeLodEXT(envMap, vOutputDirection, lod);
|
|
3502
|
+
}
|
|
3503
|
+
`,
|
|
3504
|
+
blending: three.AdditiveBlending,
|
|
3505
|
+
depthWrite: false,
|
|
3506
|
+
depthTest: false
|
|
3507
|
+
});
|
|
3508
|
+
}
|
|
3509
|
+
function _getMipCopyMaterial(lodMax, width, height) {
|
|
3510
|
+
return new three.ShaderMaterial({
|
|
3511
|
+
name: "MipBlurToCubeUV",
|
|
3512
|
+
defines: {
|
|
3513
|
+
CUBEUV_TEXEL_WIDTH: 1.0 / width,
|
|
3514
|
+
CUBEUV_TEXEL_HEIGHT: 1.0 / height,
|
|
3515
|
+
CUBEUV_MAX_MIP: `${lodMax}.0`
|
|
3516
|
+
},
|
|
3517
|
+
uniforms: {
|
|
3518
|
+
cubeUVMap: {
|
|
3519
|
+
value: null
|
|
3520
|
+
},
|
|
3521
|
+
lod: {
|
|
3522
|
+
value: 0
|
|
3523
|
+
}
|
|
3524
|
+
},
|
|
3525
|
+
vertexShader: _getCommonVertexShader(),
|
|
3526
|
+
fragmentShader: /* glsl */ `
|
|
3527
|
+
precision mediump float;
|
|
3528
|
+
precision mediump int;
|
|
3529
|
+
|
|
3530
|
+
#define ENVMAP_TYPE_CUBE_UV
|
|
3531
|
+
#include <cube_uv_reflection_fragment>
|
|
3532
|
+
|
|
3533
|
+
varying vec3 vOutputDirection;
|
|
3534
|
+
|
|
3535
|
+
uniform sampler2D cubeUVMap;
|
|
3536
|
+
uniform float lod;
|
|
3537
|
+
|
|
3538
|
+
void main() {
|
|
3539
|
+
vec3 col = bilinearCubeUV(cubeUVMap, vOutputDirection, CUBEUV_MAX_MIP - lod);
|
|
3540
|
+
gl_FragColor = vec4(col, 1.);
|
|
3541
|
+
}
|
|
3542
|
+
`,
|
|
3543
|
+
blending: three.AdditiveBlending,
|
|
3544
|
+
depthWrite: false,
|
|
3545
|
+
depthTest: false
|
|
3546
|
+
});
|
|
3547
|
+
}
|
|
3548
|
+
function _getMipBlurMaterial(lodMax, width, height) {
|
|
3549
|
+
return new three.ShaderMaterial({
|
|
3550
|
+
name: "MipBlurToCubeUV",
|
|
3551
|
+
defines: {
|
|
3552
|
+
CUBEUV_TEXEL_WIDTH: 1.0 / width,
|
|
3553
|
+
CUBEUV_TEXEL_HEIGHT: 1.0 / height,
|
|
3554
|
+
CUBEUV_MAX_MIP: `${lodMax}.0`
|
|
3555
|
+
},
|
|
3556
|
+
uniforms: {
|
|
3557
|
+
envMap: {
|
|
3558
|
+
value: null
|
|
3559
|
+
},
|
|
3560
|
+
cubeUVMap: {
|
|
3561
|
+
value: null
|
|
3562
|
+
},
|
|
3563
|
+
weight: {
|
|
3564
|
+
value: 1
|
|
3565
|
+
},
|
|
3566
|
+
lod: {
|
|
3567
|
+
value: 0
|
|
3568
|
+
},
|
|
3569
|
+
exposure: {
|
|
3570
|
+
value: 1
|
|
3571
|
+
}
|
|
3572
|
+
},
|
|
3573
|
+
vertexShader: _getCommonVertexShader(),
|
|
3574
|
+
fragmentShader: /* glsl */ `
|
|
3575
|
+
precision mediump float;
|
|
3576
|
+
precision mediump int;
|
|
3577
|
+
|
|
3578
|
+
#define ENVMAP_TYPE_CUBE_UV
|
|
3579
|
+
#include <cube_uv_reflection_fragment>
|
|
3580
|
+
|
|
3581
|
+
varying vec3 vOutputDirection;
|
|
3582
|
+
|
|
3583
|
+
uniform sampler2D cubeUVMap;
|
|
3584
|
+
uniform samplerCube envMap;
|
|
3585
|
+
uniform float weight;
|
|
3586
|
+
uniform float lod;
|
|
3587
|
+
uniform float exposure;
|
|
3588
|
+
|
|
3589
|
+
void main() {
|
|
3590
|
+
vec3 col0 = bilinearCubeUV(cubeUVMap, vOutputDirection, CUBEUV_MAX_MIP - (lod + 1.));
|
|
3591
|
+
vec3 col1 = textureCubeLodEXT(envMap, vOutputDirection, lod).rgb * exposure;
|
|
3592
|
+
gl_FragColor = vec4(mix(col0, col1, weight), 1.);
|
|
3593
|
+
}
|
|
3594
|
+
`,
|
|
3595
|
+
blending: three.NoBlending,
|
|
3596
|
+
depthWrite: false,
|
|
3597
|
+
depthTest: false
|
|
3598
|
+
});
|
|
3599
|
+
}
|
|
3600
|
+
|
|
2894
3601
|
class Caller {
|
|
2895
3602
|
get pause() {
|
|
2896
3603
|
return this._pause;
|
|
@@ -3445,8 +4152,9 @@ ResourceManager._texSettingKeys = [
|
|
|
3445
4152
|
"minFilter",
|
|
3446
4153
|
"format",
|
|
3447
4154
|
"anisotropy",
|
|
4155
|
+
"repeat",
|
|
3448
4156
|
"colorSpace",
|
|
3449
|
-
"
|
|
4157
|
+
"channel"
|
|
3450
4158
|
];
|
|
3451
4159
|
|
|
3452
4160
|
function applyProps(target, props) {
|
|
@@ -3538,14 +4246,14 @@ class Viewer extends EventEmitter {
|
|
|
3538
4246
|
}
|
|
3539
4247
|
return shadow;
|
|
3540
4248
|
}
|
|
3541
|
-
static
|
|
4249
|
+
static compileMaterial(renderer, scene, camera, target) {
|
|
3542
4250
|
Viewer.fullscreenMesh.material = target;
|
|
3543
4251
|
renderer.compile(Viewer.fullscreenMesh, camera, scene);
|
|
3544
4252
|
}
|
|
3545
|
-
static
|
|
4253
|
+
static compileObject3D(renderer, scene, camera, target) {
|
|
3546
4254
|
renderer.compile(target, camera, scene);
|
|
3547
4255
|
}
|
|
3548
|
-
static
|
|
4256
|
+
static compileTexture(renderer, target) {
|
|
3549
4257
|
if (Array.isArray(target)) {
|
|
3550
4258
|
for (let v of target){
|
|
3551
4259
|
renderer.initTexture(v);
|
|
@@ -3561,7 +4269,7 @@ class Viewer extends EventEmitter {
|
|
|
3561
4269
|
renderer.render(Viewer.fullscreenMesh, Viewer.fullscreenCamera);
|
|
3562
4270
|
renderer.setRenderTarget(RT);
|
|
3563
4271
|
}
|
|
3564
|
-
static
|
|
4272
|
+
static createFullscreenTriangle() {
|
|
3565
4273
|
let geometry = new three.BufferGeometry();
|
|
3566
4274
|
geometry.setAttribute('position', new three.Float32BufferAttribute([
|
|
3567
4275
|
-1,
|
|
@@ -3584,6 +4292,51 @@ class Viewer extends EventEmitter {
|
|
|
3584
4292
|
], 2));
|
|
3585
4293
|
return geometry;
|
|
3586
4294
|
}
|
|
4295
|
+
static findChild(node, path) {
|
|
4296
|
+
let child = null;
|
|
4297
|
+
let parts = path.split("/");
|
|
4298
|
+
let children = node.children;
|
|
4299
|
+
for (let part of parts){
|
|
4300
|
+
child = children.find((v)=>v.name === part);
|
|
4301
|
+
if (child) {
|
|
4302
|
+
children = child.children;
|
|
4303
|
+
} else {
|
|
4304
|
+
return null;
|
|
4305
|
+
}
|
|
4306
|
+
}
|
|
4307
|
+
return child;
|
|
4308
|
+
}
|
|
4309
|
+
static getChildByName(node, name) {
|
|
4310
|
+
return Viewer.getObject(node, (v)=>v.name === name && v);
|
|
4311
|
+
}
|
|
4312
|
+
static getObject(node, filter) {
|
|
4313
|
+
const queue = [
|
|
4314
|
+
node
|
|
4315
|
+
];
|
|
4316
|
+
while(queue.length !== 0){
|
|
4317
|
+
let object = queue.shift();
|
|
4318
|
+
let target = filter(object);
|
|
4319
|
+
if (target) {
|
|
4320
|
+
return target;
|
|
4321
|
+
}
|
|
4322
|
+
object.children.forEach((v)=>queue.push(v));
|
|
4323
|
+
}
|
|
4324
|
+
}
|
|
4325
|
+
static getObjects(node, filter) {
|
|
4326
|
+
const queue = [
|
|
4327
|
+
node
|
|
4328
|
+
];
|
|
4329
|
+
const objects = [];
|
|
4330
|
+
while(queue.length !== 0){
|
|
4331
|
+
let object = queue.shift();
|
|
4332
|
+
let target = filter(object);
|
|
4333
|
+
if (target) {
|
|
4334
|
+
objects.push(object);
|
|
4335
|
+
}
|
|
4336
|
+
object.children.forEach((v)=>queue.push(v));
|
|
4337
|
+
}
|
|
4338
|
+
return objects;
|
|
4339
|
+
}
|
|
3587
4340
|
get root() {
|
|
3588
4341
|
return this._root;
|
|
3589
4342
|
}
|
|
@@ -3778,16 +4531,12 @@ class Viewer extends EventEmitter {
|
|
|
3778
4531
|
this._tweenManager.killTweensOf(target);
|
|
3779
4532
|
}
|
|
3780
4533
|
traverseMaterials(callback) {
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
if (item.material) {
|
|
4534
|
+
Viewer.getObjects(this._scene, (item)=>{
|
|
4535
|
+
if (item.isMesh) {
|
|
3784
4536
|
if (Array.isArray(item.material)) item.material.forEach(callback);
|
|
3785
4537
|
else callback(item.material);
|
|
3786
4538
|
}
|
|
3787
|
-
};
|
|
3788
|
-
renderList.opaque.forEach(setMaterial);
|
|
3789
|
-
renderList.transparent.forEach(setMaterial);
|
|
3790
|
-
renderList.transmissive.forEach(setMaterial);
|
|
4539
|
+
});
|
|
3791
4540
|
}
|
|
3792
4541
|
traversePlugins(callback) {
|
|
3793
4542
|
return this._pluginManager.traversePlugins(callback);
|
|
@@ -3872,7 +4621,7 @@ class Viewer extends EventEmitter {
|
|
|
3872
4621
|
minFilter: nearest ? three.NearestFilter : mipmap ? three.LinearMipMapLinearFilter : three.LinearFilter,
|
|
3873
4622
|
type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : three.UnsignedByteType : floatType,
|
|
3874
4623
|
anisotropy: 0,
|
|
3875
|
-
colorSpace: three.
|
|
4624
|
+
colorSpace: three.LinearSRGBColorSpace,
|
|
3876
4625
|
depthBuffer: false,
|
|
3877
4626
|
stencilBuffer: false,
|
|
3878
4627
|
samples: SystemInfo.isSupportMSAA ? msaa : 0,
|
|
@@ -3887,7 +4636,7 @@ class Viewer extends EventEmitter {
|
|
|
3887
4636
|
minFilter: nearest ? three.NearestFilter : mipmap ? three.LinearMipMapLinearFilter : three.LinearFilter,
|
|
3888
4637
|
type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : three.UnsignedByteType : floatType,
|
|
3889
4638
|
anisotropy: 0,
|
|
3890
|
-
colorSpace: three.
|
|
4639
|
+
colorSpace: three.LinearSRGBColorSpace,
|
|
3891
4640
|
depthBuffer: false,
|
|
3892
4641
|
stencilBuffer: false,
|
|
3893
4642
|
samples: SystemInfo.isSupportMSAA ? msaa : 0,
|
|
@@ -3916,33 +4665,33 @@ class Viewer extends EventEmitter {
|
|
|
3916
4665
|
compile(target) {
|
|
3917
4666
|
if (Array.isArray(target)) {
|
|
3918
4667
|
if (target.every((v)=>v.isMaterial)) {
|
|
3919
|
-
Viewer.
|
|
4668
|
+
Viewer.compileMaterial(this._renderer, this._scene, this._camera, target);
|
|
3920
4669
|
} else {
|
|
3921
4670
|
throw Error("Viewer.compile: unsuport material");
|
|
3922
4671
|
}
|
|
3923
4672
|
} else if (typeof target === "object") {
|
|
3924
4673
|
if (target.isMaterial) {
|
|
3925
|
-
Viewer.
|
|
4674
|
+
Viewer.compileMaterial(this._renderer, this._scene, this._camera, target);
|
|
3926
4675
|
} else if (target.isObject3D) {
|
|
3927
4676
|
if (target.meshData.materials) {
|
|
3928
|
-
Viewer.
|
|
4677
|
+
Viewer.compileMaterial(this._renderer, this._scene, this._camera, Object.values(target.meshData.materials));
|
|
3929
4678
|
}
|
|
3930
4679
|
if (target.meshData.textures) {
|
|
3931
|
-
Viewer.
|
|
4680
|
+
Viewer.compileTexture(this._renderer, Object.values(target.meshData.textures));
|
|
3932
4681
|
}
|
|
3933
4682
|
if (!target.meshData.meshes) {
|
|
3934
|
-
Viewer.
|
|
4683
|
+
Viewer.compileObject3D(this._renderer, this._scene, this._camera, target);
|
|
3935
4684
|
}
|
|
3936
4685
|
} else if (target.isTexture) {
|
|
3937
|
-
Viewer.
|
|
4686
|
+
Viewer.compileTexture(this._renderer, target);
|
|
3938
4687
|
}
|
|
3939
4688
|
} else {
|
|
3940
|
-
Viewer.
|
|
4689
|
+
Viewer.compileObject3D(this._renderer, this._scene, this._camera, this._scene);
|
|
3941
4690
|
}
|
|
3942
4691
|
}
|
|
3943
4692
|
constructor({ root, canvas, autoStart = true, autoResize = true, shadows = false, camera = {
|
|
3944
4693
|
fov: 45,
|
|
3945
|
-
near: 1,
|
|
4694
|
+
near: 0.1,
|
|
3946
4695
|
far: 1000,
|
|
3947
4696
|
position: new three.Vector3(0, 0, 4)
|
|
3948
4697
|
}, targetFrameRate = -1, colorSpace = three.SRGBColorSpace, toneMapping = three.LinearToneMapping, toneMappingExposure = 1, maxDPR = 1.5, path = "", resourcePath = "", dracoPath = "https://www.gstatic.com/draco/v1/decoders/", loader = {}, tasker = {}, ...webglOpts } = {}){
|
|
@@ -3974,7 +4723,7 @@ class Viewer extends EventEmitter {
|
|
|
3974
4723
|
this._DATA_FLOAT_TYPE = webgl.DATA_FLOAT_TYPE;
|
|
3975
4724
|
this._dpr = Math.min(maxDPR, window.devicePixelRatio);
|
|
3976
4725
|
this._scene = new three.Scene();
|
|
3977
|
-
this._camera = new three.PerspectiveCamera();
|
|
4726
|
+
this._camera = applyProps(new three.PerspectiveCamera(), camera);
|
|
3978
4727
|
this._renderer = new three.WebGLRenderer({
|
|
3979
4728
|
canvas: el,
|
|
3980
4729
|
context: webgl.gl
|
|
@@ -4015,23 +4764,455 @@ Viewer._shadowCameraKeys = [
|
|
|
4015
4764
|
"near",
|
|
4016
4765
|
"far"
|
|
4017
4766
|
];
|
|
4018
|
-
Viewer.fullscreenMesh = new three.Mesh(Viewer.
|
|
4767
|
+
Viewer.fullscreenMesh = new three.Mesh(Viewer.createFullscreenTriangle());
|
|
4019
4768
|
Viewer.fullscreenCamera = new three.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
4020
4769
|
|
|
4021
|
-
class
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4770
|
+
class MergeRefectPass {
|
|
4771
|
+
get envMapTarget() {
|
|
4772
|
+
return this._envMapTarget;
|
|
4773
|
+
}
|
|
4774
|
+
dispose() {
|
|
4775
|
+
this._envMapTarget.dispose();
|
|
4776
|
+
this._pmremGenerator.dispose();
|
|
4777
|
+
}
|
|
4778
|
+
mergeReflect(info) {
|
|
4779
|
+
this._pmremGenerator._clearTexture(this._envMapTarget, this.envMapIntensity);
|
|
4780
|
+
this._pmremGenerator._mergeReflect(this._envMapTarget, this._reflectMap);
|
|
4781
|
+
info.envMapTarget = this._envMapTarget;
|
|
4782
|
+
info.lodMax = this._pmremGenerator._lodMeshes.length - 1;
|
|
4783
|
+
}
|
|
4784
|
+
_getPMREMExtension(renderer) {
|
|
4785
|
+
const pmremGenerator = new three.PMREMGenerator(renderer);
|
|
4786
|
+
pmremGenerator._fromTextureExtension = function(reflectMap, envMap) {
|
|
4787
|
+
const target = envMap ? this._fromTexture(envMap) : this._fromCubeTexture(reflectMap);
|
|
4788
|
+
this._cubeMapMaterial = _getCubeMapMaterial();
|
|
4789
|
+
this._copyTexMaterial = _getClearMaterial();
|
|
4790
|
+
this._copyMesh = new three.Mesh(Viewer.fullscreenMesh.geometry, this._copyTexMaterial);
|
|
4791
|
+
this._lodMeshes = this._lodPlanes.map((v)=>new three.Mesh(v, this._cubeMapMaterial));
|
|
4792
|
+
this._sourceInit = false;
|
|
4793
|
+
return target;
|
|
4794
|
+
};
|
|
4795
|
+
pmremGenerator._fromCubeTexture = function(texture) {
|
|
4796
|
+
this._setSize(texture.image.length === 0 ? 16 : texture.image[0].width || texture.image[0].image.width);
|
|
4797
|
+
return this._allocateTargets();
|
|
4798
|
+
};
|
|
4799
|
+
pmremGenerator._copyTexture = function(targetOut, texture, intensity = 1) {
|
|
4800
|
+
const uniforms = this._copyTexMaterial.uniforms;
|
|
4801
|
+
uniforms.map.value = texture;
|
|
4802
|
+
uniforms.intensity.value = intensity;
|
|
4803
|
+
const renderer = this._renderer;
|
|
4804
|
+
renderer.autoClear = true;
|
|
4805
|
+
renderer.setRenderTarget(targetOut);
|
|
4806
|
+
renderer.render(this._copyMesh, _flatCamera);
|
|
4807
|
+
renderer.setRenderTarget(null);
|
|
4808
|
+
};
|
|
4809
|
+
pmremGenerator._clearTexture = function(targetOut, intensity) {
|
|
4810
|
+
const source = this._pingPongRenderTarget;
|
|
4811
|
+
if (this._sourceInit === false) {
|
|
4812
|
+
this._sourceInit = true;
|
|
4813
|
+
source.scissorTest = false;
|
|
4814
|
+
_setViewport(source, 0, 0, source.width, source.height);
|
|
4815
|
+
this._copyTexture(source, targetOut.texture);
|
|
4816
|
+
} else {
|
|
4817
|
+
this._copyTexture(targetOut, source.texture, intensity);
|
|
4818
|
+
}
|
|
4819
|
+
};
|
|
4820
|
+
pmremGenerator._mergeReflect = function(sourceTarget, reflectMap, clear = false) {
|
|
4821
|
+
const renderer = this._renderer;
|
|
4822
|
+
const autoClear = renderer.autoClear;
|
|
4823
|
+
const cubeMapMaterial = this._cubeMapMaterial;
|
|
4824
|
+
const uniforms = this._cubeMapMaterial.uniforms;
|
|
4825
|
+
uniforms.envMap.value = reflectMap;
|
|
4826
|
+
renderer.autoClear = clear;
|
|
4827
|
+
for(let i = 0; i < this._lodMeshes.length - 1; i++){
|
|
4828
|
+
uniforms.lod.value = i < 5 ? 0 : i;
|
|
4829
|
+
this._blit(sourceTarget, i, cubeMapMaterial);
|
|
4830
|
+
}
|
|
4831
|
+
sourceTarget.scissorTest = false;
|
|
4832
|
+
_setViewport(sourceTarget, 0, 0, sourceTarget.width, sourceTarget.height);
|
|
4833
|
+
renderer.autoClear = autoClear;
|
|
4834
|
+
};
|
|
4835
|
+
pmremGenerator._blit = function(targetOut, lodOut, material) {
|
|
4836
|
+
const renderer = this._renderer;
|
|
4837
|
+
const _lodMax = this._lodMax;
|
|
4838
|
+
const outputSize = this._sizeLods[lodOut];
|
|
4839
|
+
const x = 3 * outputSize * (lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0);
|
|
4840
|
+
const y = 4 * (this._cubeSize - outputSize);
|
|
4841
|
+
_setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
|
|
4842
|
+
const lodMesh = this._lodMeshes[lodOut];
|
|
4843
|
+
lodMesh.material = material;
|
|
4844
|
+
renderer.autoClear = false;
|
|
4845
|
+
renderer.setRenderTarget(targetOut);
|
|
4846
|
+
renderer.render(lodMesh, _flatCamera);
|
|
4847
|
+
};
|
|
4848
|
+
return pmremGenerator;
|
|
4849
|
+
}
|
|
4850
|
+
constructor({ envMap, reflectMap, viewer }){
|
|
4851
|
+
this.envMapIntensity = 1;
|
|
4852
|
+
this._reflectMap = reflectMap;
|
|
4853
|
+
this._pmremGenerator = this._getPMREMExtension(viewer.renderer);
|
|
4854
|
+
this._envMapTarget = this._pmremGenerator._fromTextureExtension(reflectMap, envMap);
|
|
4855
|
+
viewer.scene.environment = this._envMapTarget.texture;
|
|
4856
|
+
}
|
|
4857
|
+
}
|
|
4858
|
+
|
|
4859
|
+
function mipGaussianBlendWeight(sigma, lod) {
|
|
4860
|
+
let sigma2 = sigma * sigma;
|
|
4861
|
+
let c = 2.0 * Math.PI * sigma2;
|
|
4862
|
+
let numerator = Math.pow(16, lod) * 1.386294361; //log(4)
|
|
4863
|
+
let denorminator = c * (Math.pow(4, lod) + c);
|
|
4864
|
+
return three.MathUtils.clamp(numerator / denorminator, 0, 1);
|
|
4865
|
+
}
|
|
4866
|
+
|
|
4867
|
+
const MAX_LOD = 10;
|
|
4868
|
+
class MergeMipBlurPass {
|
|
4869
|
+
get blurIntensity() {
|
|
4870
|
+
return this._blurIntensity;
|
|
4871
|
+
}
|
|
4872
|
+
set blurIntensity(v) {
|
|
4873
|
+
if (this._blurIntensity !== v) {
|
|
4874
|
+
this._blurIntensity = v;
|
|
4875
|
+
this._sigma = three.MathUtils.lerp(1, 40, this._blurIntensity / 10);
|
|
4876
|
+
for(let lod = 0; lod <= MAX_LOD; lod++){
|
|
4877
|
+
let w = mipGaussianBlendWeight(this._sigma, lod);
|
|
4878
|
+
if (w < 0.002) {
|
|
4879
|
+
this._blurMinLod = lod;
|
|
4880
|
+
}
|
|
4881
|
+
if (w >= 1) {
|
|
4882
|
+
this._blurMaxLod = lod;
|
|
4883
|
+
break;
|
|
4884
|
+
}
|
|
4885
|
+
}
|
|
4886
|
+
}
|
|
4887
|
+
}
|
|
4888
|
+
get envMapTarget() {
|
|
4889
|
+
return this._envMapTarget;
|
|
4890
|
+
}
|
|
4891
|
+
dispose() {
|
|
4892
|
+
this._envMapTarget.dispose();
|
|
4893
|
+
this._pmremGenerator.dispose();
|
|
4894
|
+
}
|
|
4895
|
+
mergeMipBlur(info) {
|
|
4896
|
+
const targetIn = this._pmremGenerator._applyMipBlur(this._envMapTarget, this._reflectMap, this._blurMinLod, this._blurMaxLod, this._sigma, this.exposure);
|
|
4897
|
+
this._pmremGenerator._mipCopy(info.envMapTarget, targetIn, info.lodMax, this._blurMinLod);
|
|
4898
|
+
}
|
|
4899
|
+
_getPMREMExtension(renderer) {
|
|
4900
|
+
const pmremGenerator = new three.PMREMGenerator(renderer);
|
|
4901
|
+
pmremGenerator._fromTextureExtension = function(texture) {
|
|
4902
|
+
this._setSize(texture.image.length === 0 ? 16 : texture.image[0].width || texture.image[0].image.width);
|
|
4903
|
+
const target = this._allocateTargets();
|
|
4904
|
+
this._mipBlurMaterial = _getMipBlurMaterial(this._lodMax, target.width, target.height);
|
|
4905
|
+
this._mipCopyMaterial = _getMipCopyMaterial(this._lodMax, target.width, target.height);
|
|
4906
|
+
this._lodMeshes = this._lodPlanes.map((v)=>new three.Mesh(v, this._mipBlurMaterial));
|
|
4907
|
+
return target;
|
|
4908
|
+
};
|
|
4909
|
+
pmremGenerator._applyMipBlur = function(sourceTarget, texture, blurMinLod, blurMaxLod, sigma, exposure) {
|
|
4910
|
+
const pingPongRenderTarget = this._pingPongRenderTarget;
|
|
4911
|
+
const uniforms = this._mipBlurMaterial.uniforms;
|
|
4912
|
+
uniforms.envMap.value = texture;
|
|
4913
|
+
uniforms.exposure.value = exposure;
|
|
4914
|
+
let lod = blurMaxLod;
|
|
4915
|
+
let targetOut = sourceTarget;
|
|
4916
|
+
let targetIn = pingPongRenderTarget;
|
|
4917
|
+
this._mipBlur(sourceTarget, pingPongRenderTarget, lod, 1);
|
|
4918
|
+
for(let i = 0; lod-- > blurMinLod; i++){
|
|
4919
|
+
targetOut = (i & 1) === 0 ? pingPongRenderTarget : sourceTarget;
|
|
4920
|
+
targetIn = (i & 1) === 1 ? pingPongRenderTarget : sourceTarget;
|
|
4921
|
+
this._mipBlur(targetOut, targetIn, lod, mipGaussianBlendWeight(sigma, lod));
|
|
4922
|
+
}
|
|
4923
|
+
sourceTarget.scissorTest = false;
|
|
4924
|
+
_setViewport(sourceTarget, 0, 0, sourceTarget.width, sourceTarget.height);
|
|
4925
|
+
return targetOut;
|
|
4926
|
+
};
|
|
4927
|
+
pmremGenerator._mipBlur = function(targetOut, targetIn, lodOut, weight) {
|
|
4928
|
+
const uniforms = this._mipBlurMaterial.uniforms;
|
|
4929
|
+
uniforms.cubeUVMap.value = targetIn.texture;
|
|
4930
|
+
uniforms.weight.value = weight;
|
|
4931
|
+
uniforms.lod.value = lodOut;
|
|
4932
|
+
this._blit(targetOut, lodOut, this._mipBlurMaterial);
|
|
4933
|
+
};
|
|
4934
|
+
pmremGenerator._mipCopy = function(targetOut, targetIn, lodOut, lodIn = lodOut) {
|
|
4935
|
+
const uniforms = this._mipCopyMaterial.uniforms;
|
|
4936
|
+
uniforms.cubeUVMap.value = targetIn.texture;
|
|
4937
|
+
uniforms.lod.value = lodIn;
|
|
4938
|
+
this._blit(targetOut, lodOut, this._mipCopyMaterial);
|
|
4939
|
+
targetOut.scissorTest = false;
|
|
4940
|
+
_setViewport(targetOut, 0, 0, targetOut.width, targetOut.height);
|
|
4941
|
+
};
|
|
4942
|
+
pmremGenerator._blit = function(targetOut, lodOut, material) {
|
|
4943
|
+
const renderer = this._renderer;
|
|
4944
|
+
const _lodMax = this._lodMax;
|
|
4945
|
+
const outputSize = this._sizeLods[lodOut];
|
|
4946
|
+
const x = 3 * outputSize * (lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0);
|
|
4947
|
+
const y = 4 * (this._cubeSize - outputSize);
|
|
4948
|
+
_setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
|
|
4949
|
+
const lodMesh = this._lodMeshes[lodOut];
|
|
4950
|
+
lodMesh.material = material;
|
|
4951
|
+
renderer.autoClear = false;
|
|
4952
|
+
renderer.setRenderTarget(targetOut);
|
|
4953
|
+
renderer.render(lodMesh, _flatCamera);
|
|
4954
|
+
};
|
|
4955
|
+
return pmremGenerator;
|
|
4956
|
+
}
|
|
4957
|
+
constructor({ viewer, reflectMap }){
|
|
4958
|
+
this._sigma = 2;
|
|
4959
|
+
this._blurMinLod = 0;
|
|
4960
|
+
this._blurMaxLod = MAX_LOD;
|
|
4961
|
+
this._blurIntensity = -1;
|
|
4962
|
+
this.exposure = 1;
|
|
4963
|
+
this._reflectMap = reflectMap;
|
|
4964
|
+
this._pmremGenerator = this._getPMREMExtension(viewer.renderer);
|
|
4965
|
+
this._envMapTarget = this._pmremGenerator._fromTextureExtension(reflectMap);
|
|
4966
|
+
}
|
|
4967
|
+
}
|
|
4968
|
+
|
|
4969
|
+
class EnvironmentPlugin extends Plugin {
|
|
4970
|
+
get debug() {
|
|
4971
|
+
return this._debug;
|
|
4972
|
+
}
|
|
4973
|
+
set debug(v) {
|
|
4974
|
+
if (this._debug !== v) {
|
|
4975
|
+
this._debug = v;
|
|
4976
|
+
if (v) {
|
|
4977
|
+
if (this._debugNode === null) {
|
|
4978
|
+
const viewer = this.viewer;
|
|
4979
|
+
const debugScene = DebugPlugin.Instance(viewer).scene;
|
|
4980
|
+
this._debugNode = viewer.addNode(three.Object3D, {
|
|
4981
|
+
parent: debugScene
|
|
4982
|
+
});
|
|
4983
|
+
viewer.addNode(Plane, {
|
|
4984
|
+
parent: this._debugNode,
|
|
4985
|
+
material: new three.MeshBasicMaterial({
|
|
4986
|
+
map: this._reflectPass.envMapTarget.texture
|
|
4987
|
+
}),
|
|
4988
|
+
position: new three.Vector3(1.1, 3, 0)
|
|
4989
|
+
});
|
|
4990
|
+
viewer.addNode(Plane, {
|
|
4991
|
+
parent: this._debugNode,
|
|
4992
|
+
material: new three.MeshBasicMaterial({
|
|
4993
|
+
map: this._mipBlurPass.envMapTarget.texture
|
|
4994
|
+
}),
|
|
4995
|
+
position: new three.Vector3(0, 3, 0)
|
|
4996
|
+
});
|
|
4997
|
+
}
|
|
4998
|
+
}
|
|
4999
|
+
if (this._debugNode) {
|
|
5000
|
+
this._debugNode.visible = v;
|
|
5001
|
+
}
|
|
5002
|
+
}
|
|
5003
|
+
}
|
|
5004
|
+
onRender() {
|
|
5005
|
+
const { renderer } = this.viewer;
|
|
5006
|
+
const autoClear = renderer.autoClear;
|
|
5007
|
+
const oldTarget = renderer.getRenderTarget();
|
|
5008
|
+
const oldActiveCubeFace = renderer.getActiveCubeFace();
|
|
5009
|
+
const oldActiveMipmapLevel = renderer.getActiveMipmapLevel();
|
|
5010
|
+
this._reflectPass.envMapIntensity = this.envMapIntensity;
|
|
5011
|
+
this._mipBlurPass.exposure = this.reflectExposure;
|
|
5012
|
+
this._mipBlurPass.blurIntensity = this.reflectBlurIntensity;
|
|
5013
|
+
this._cubeCamera.update(renderer, this._scene);
|
|
5014
|
+
this._reflectPass.mergeReflect(this._mergeInfo);
|
|
5015
|
+
this._mipBlurPass.mergeMipBlur(this._mergeInfo);
|
|
5016
|
+
renderer.autoClear = autoClear;
|
|
5017
|
+
renderer.setRenderTarget(oldTarget, oldActiveCubeFace, oldActiveMipmapLevel);
|
|
5018
|
+
}
|
|
5019
|
+
constructor({ envMap, scene, near, far, layer = 0, resolution = 256, floatType = three.HalfFloatType, position = new three.Vector3(0, 1, 0) } = {}){
|
|
5020
|
+
super();
|
|
5021
|
+
this._mergeInfo = {
|
|
5022
|
+
envMapTarget: null,
|
|
5023
|
+
lodMax: 0
|
|
5024
|
+
};
|
|
5025
|
+
this._debug = false;
|
|
5026
|
+
this._debugNode = null;
|
|
5027
|
+
this.envMapIntensity = 1;
|
|
5028
|
+
this.reflectExposure = 1;
|
|
5029
|
+
this.reflectBlurIntensity = 5;
|
|
5030
|
+
this.install = ()=>{
|
|
5031
|
+
const viewer = this.viewer;
|
|
5032
|
+
this._scene = scene || viewer.scene;
|
|
5033
|
+
const cubeRenderTarget = viewer.createCubeRenderTarget(resolution, false, floatType, 0, true);
|
|
5034
|
+
this._cubeCamera = new three.CubeCamera(near || viewer.camera.near, far || viewer.camera.far, cubeRenderTarget);
|
|
5035
|
+
this._cubeCamera.position.copy(position);
|
|
5036
|
+
this._cubeCamera.layers.set(layer);
|
|
5037
|
+
const reflectMap = cubeRenderTarget.texture;
|
|
5038
|
+
this._reflectPass = new MergeRefectPass({
|
|
5039
|
+
viewer,
|
|
5040
|
+
reflectMap,
|
|
5041
|
+
envMap
|
|
5042
|
+
});
|
|
5043
|
+
this._mipBlurPass = new MergeMipBlurPass({
|
|
5044
|
+
viewer,
|
|
5045
|
+
reflectMap
|
|
5046
|
+
});
|
|
5047
|
+
};
|
|
5048
|
+
this.uninstall = ()=>{
|
|
5049
|
+
this._reflectPass.dispose();
|
|
5050
|
+
this._mipBlurPass.dispose();
|
|
5051
|
+
};
|
|
4025
5052
|
}
|
|
4026
5053
|
}
|
|
5054
|
+
__decorate([
|
|
5055
|
+
property
|
|
5056
|
+
], EnvironmentPlugin.prototype, "debug", null);
|
|
5057
|
+
__decorate([
|
|
5058
|
+
property({
|
|
5059
|
+
min: 0,
|
|
5060
|
+
max: 1,
|
|
5061
|
+
step: 0.01
|
|
5062
|
+
})
|
|
5063
|
+
], EnvironmentPlugin.prototype, "envMapIntensity", void 0);
|
|
5064
|
+
__decorate([
|
|
5065
|
+
property({
|
|
5066
|
+
min: 0,
|
|
5067
|
+
max: 10,
|
|
5068
|
+
step: 0.01
|
|
5069
|
+
})
|
|
5070
|
+
], EnvironmentPlugin.prototype, "reflectExposure", void 0);
|
|
5071
|
+
__decorate([
|
|
5072
|
+
property({
|
|
5073
|
+
min: 0,
|
|
5074
|
+
max: 10,
|
|
5075
|
+
step: 0.1
|
|
5076
|
+
})
|
|
5077
|
+
], EnvironmentPlugin.prototype, "reflectBlurIntensity", void 0);
|
|
5078
|
+
|
|
5079
|
+
class BoxProjectionPlugin extends Plugin {
|
|
5080
|
+
get debug() {
|
|
5081
|
+
return this._debug;
|
|
5082
|
+
}
|
|
5083
|
+
set debug(v) {
|
|
5084
|
+
if (this._debug !== v) {
|
|
5085
|
+
this._debug = v;
|
|
5086
|
+
if (v) {
|
|
5087
|
+
if (this._helper === null) {
|
|
5088
|
+
this._helper = new three.Box3Helper(new three.Box3(this._boxMin, this._boxMax));
|
|
5089
|
+
DebugPlugin.Instance(this.viewer).add(this._helper);
|
|
5090
|
+
}
|
|
5091
|
+
}
|
|
5092
|
+
if (this._helper) {
|
|
5093
|
+
this._helper.visible = v;
|
|
5094
|
+
}
|
|
5095
|
+
}
|
|
5096
|
+
}
|
|
5097
|
+
get center() {
|
|
5098
|
+
return this._center;
|
|
5099
|
+
}
|
|
5100
|
+
set center(v) {
|
|
5101
|
+
this._center.copy(v);
|
|
5102
|
+
}
|
|
5103
|
+
get boxMin() {
|
|
5104
|
+
return this._boxMin;
|
|
5105
|
+
}
|
|
5106
|
+
set boxMin(v) {
|
|
5107
|
+
this._boxMin.copy(v);
|
|
5108
|
+
}
|
|
5109
|
+
get boxMax() {
|
|
5110
|
+
return this._boxMax;
|
|
5111
|
+
}
|
|
5112
|
+
set boxMax(v) {
|
|
5113
|
+
this._boxMax.copy(v);
|
|
5114
|
+
}
|
|
5115
|
+
onUpdate(dt) {
|
|
5116
|
+
if (this._debug) {
|
|
5117
|
+
this._helper.updateMatrixWorld();
|
|
5118
|
+
}
|
|
5119
|
+
}
|
|
5120
|
+
useBoxProjection(shader) {
|
|
5121
|
+
shader.defines.USE_BOX_PROJECTION = true;
|
|
5122
|
+
shader.uniforms.probePos = {
|
|
5123
|
+
value: this._center
|
|
5124
|
+
};
|
|
5125
|
+
shader.uniforms.probeBoxMin = {
|
|
5126
|
+
value: this._boxMin
|
|
5127
|
+
};
|
|
5128
|
+
shader.uniforms.probeBoxMax = {
|
|
5129
|
+
value: this._boxMax
|
|
5130
|
+
};
|
|
5131
|
+
}
|
|
5132
|
+
constructor(){
|
|
5133
|
+
super();
|
|
5134
|
+
this._center = new three.Vector4(0, 0.5, 0, 1);
|
|
5135
|
+
this._boxMin = new three.Vector3(0, 0, 0);
|
|
5136
|
+
this._boxMax = new three.Vector3(1, 1, 1);
|
|
5137
|
+
this._helper = null;
|
|
5138
|
+
this._debug = false;
|
|
5139
|
+
this.install = ()=>{
|
|
5140
|
+
three.ShaderLib.physical.vertexShader = three.ShaderLib.physical.vertexShader.replace(/#ifdef USE_TRANSMISSION/g, `
|
|
5141
|
+
#if defined(USE_TRANSMISSION) || defined(USE_BOX_PROJECTION)
|
|
5142
|
+
`);
|
|
5143
|
+
three.ShaderLib.physical.fragmentShader = three.ShaderLib.physical.fragmentShader.replace("varying vec3 vViewPosition;", `
|
|
5144
|
+
varying vec3 vViewPosition;
|
|
5145
|
+
#if defined(USE_BOX_PROJECTION)
|
|
5146
|
+
varying vec3 vWorldPosition;
|
|
5147
|
+
#endif
|
|
5148
|
+
`);
|
|
5149
|
+
three.ShaderChunk.worldpos_vertex = three.ShaderChunk.worldpos_vertex.replace("#if defined( USE_ENVMAP )", "#if defined( USE_ENVMAP ) || defined( USE_BOX_PROJECTION )");
|
|
5150
|
+
three.ShaderChunk.envmap_physical_pars_fragment = three.ShaderChunk.envmap_physical_pars_fragment.replace("#ifdef USE_ENVMAP", `
|
|
5151
|
+
#ifdef USE_ENVMAP
|
|
5152
|
+
|
|
5153
|
+
#if defined(USE_BOX_PROJECTION)
|
|
5154
|
+
uniform vec4 probePos;
|
|
5155
|
+
uniform vec3 probeBoxMin;
|
|
5156
|
+
uniform vec3 probeBoxMax;
|
|
5157
|
+
|
|
5158
|
+
vec3 boxProjection(vec3 nrdir, vec3 worldPos, vec3 probePos, vec3 boxMin, vec3 boxMax) {
|
|
5159
|
+
vec3 tbot = boxMin - worldPos;
|
|
5160
|
+
vec3 ttop = boxMax - worldPos;
|
|
5161
|
+
vec3 tmax = mix(tbot, ttop, step(vec3(0), nrdir));
|
|
5162
|
+
tmax /= nrdir;
|
|
5163
|
+
float t = min(min(tmax.x, tmax.y), tmax.z);
|
|
5164
|
+
return worldPos + nrdir * t - probePos;
|
|
5165
|
+
}
|
|
5166
|
+
#endif
|
|
5167
|
+
|
|
5168
|
+
`).replace("reflectVec = inverseTransformDirection( reflectVec, viewMatrix );", `
|
|
5169
|
+
reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
|
|
5170
|
+
|
|
5171
|
+
#if defined(USE_BOX_PROJECTION)
|
|
5172
|
+
if (probePos.w > 0.001) {
|
|
5173
|
+
reflectVec = boxProjection(reflectVec, vWorldPosition, probePos.xyz, probeBoxMin.xyz, probeBoxMax.xyz);
|
|
5174
|
+
}
|
|
5175
|
+
#endif
|
|
5176
|
+
|
|
5177
|
+
`).replace("vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );", `
|
|
5178
|
+
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
|
|
5179
|
+
|
|
5180
|
+
#if defined(USE_BOX_PROJECTION)
|
|
5181
|
+
if (probePos.w > 0.001) {
|
|
5182
|
+
worldNormal = boxProjection(worldNormal, vWorldPosition, probePos.xyz, probeBoxMin.xyz, probeBoxMax.xyz);
|
|
5183
|
+
}
|
|
5184
|
+
#endif
|
|
5185
|
+
|
|
5186
|
+
`);
|
|
5187
|
+
};
|
|
5188
|
+
this.uninstall = ()=>{
|
|
5189
|
+
DebugPlugin.Instance(this.viewer).remove(this._helper);
|
|
5190
|
+
};
|
|
5191
|
+
}
|
|
5192
|
+
}
|
|
5193
|
+
__decorate([
|
|
5194
|
+
property
|
|
5195
|
+
], BoxProjectionPlugin.prototype, "debug", null);
|
|
5196
|
+
__decorate([
|
|
5197
|
+
property
|
|
5198
|
+
], BoxProjectionPlugin.prototype, "center", null);
|
|
5199
|
+
__decorate([
|
|
5200
|
+
property
|
|
5201
|
+
], BoxProjectionPlugin.prototype, "boxMin", null);
|
|
5202
|
+
__decorate([
|
|
5203
|
+
property
|
|
5204
|
+
], BoxProjectionPlugin.prototype, "boxMax", null);
|
|
4027
5205
|
|
|
4028
5206
|
exports.AnimationCurve = AnimationCurve;
|
|
4029
5207
|
exports.Box = Box;
|
|
5208
|
+
exports.BoxProjectionPlugin = BoxProjectionPlugin;
|
|
4030
5209
|
exports.CinestationBlendDefinition = CinestationBlendDefinition;
|
|
4031
5210
|
exports.CinestationBrain = CinestationBrain;
|
|
4032
5211
|
exports.Component = Component;
|
|
5212
|
+
exports.DebugPlugin = DebugPlugin;
|
|
4033
5213
|
exports.DeviceInput = DeviceInput;
|
|
4034
5214
|
exports.Easing = Easing;
|
|
5215
|
+
exports.EnvironmentPlugin = EnvironmentPlugin;
|
|
4035
5216
|
exports.EventEmitter = EventEmitter;
|
|
4036
5217
|
exports.FInterpConstantTo = FInterpConstantTo;
|
|
4037
5218
|
exports.FInterpTo = FInterpTo;
|
|
@@ -4049,6 +5230,8 @@ exports.Quat_Equals = Quat_Equals;
|
|
|
4049
5230
|
exports.Quat_exponentialDamp = Quat_exponentialDamp;
|
|
4050
5231
|
exports.Quat_quarticDamp = Quat_quarticDamp;
|
|
4051
5232
|
exports.Quat_smoothDamp = Quat_smoothDamp;
|
|
5233
|
+
exports.Reflector = Reflector;
|
|
5234
|
+
exports.ReflectorMaterial = ReflectorMaterial;
|
|
4052
5235
|
exports.Sphere = Sphere;
|
|
4053
5236
|
exports.SystemInfo = SystemInfo;
|
|
4054
5237
|
exports.Tween = Tween;
|
|
@@ -4075,9 +5258,14 @@ exports.aJSONLoader = aJSONLoader;
|
|
|
4075
5258
|
exports.aLoader = aLoader;
|
|
4076
5259
|
exports.aTextureLoader = aTextureLoader;
|
|
4077
5260
|
exports.exponentialDamp = exponentialDamp;
|
|
5261
|
+
exports.frag_BoxfilterBlur = frag_BoxfilterBlur;
|
|
5262
|
+
exports.frag_cubeMapToPanorama = frag_cubeMapToPanorama;
|
|
5263
|
+
exports.frag_panoramaToCubeMap = frag_panoramaToCubeMap;
|
|
4078
5264
|
exports.getClassInstance = getClassInstance;
|
|
5265
|
+
exports.getShaderMaterial = getShaderMaterial;
|
|
4079
5266
|
exports.mixin = mixin;
|
|
4080
5267
|
exports.property = property;
|
|
4081
5268
|
exports.quarticDamp = quarticDamp;
|
|
4082
5269
|
exports.smoothDamp = smoothDamp;
|
|
5270
|
+
exports.vert_fullscreen = vert_fullscreen;
|
|
4083
5271
|
//# sourceMappingURL=main.js.map
|