@xviewer.js/core 1.0.0-alpha.21 → 1.0.0-alpha.23
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 +1230 -146
- package/dist/main.js.map +1 -1
- package/dist/module.js +1220 -147
- package/dist/module.js.map +1 -1
- package/package.json +1 -1
- package/types/TextureSettings.d.ts +1 -0
- package/types/Viewer.d.ts +4 -1
- package/types/asset/aLoader.d.ts +1 -0
- package/types/index.d.ts +6 -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/module.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Mesh, EquirectangularReflectionMapping, FileLoader, TextureLoader, SRGBColorSpace, MathUtils, Vector3, Quaternion, Raycaster, Vector2, LinearInterpolant, Spherical, Object3D, BoxGeometry, SphereGeometry, PlaneGeometry, HalfFloatType, FloatType, UnsignedByteType, OrthographicCamera, BufferGeometry, Float32BufferAttribute, WebGLRenderTarget, ClampToEdgeWrapping, NearestFilter, LinearFilter, LinearMipMapLinearFilter, WebGLCubeRenderTarget, DataTexture, RGBAFormat, UVMapping, Scene, LinearToneMapping, PerspectiveCamera, WebGLRenderer, PCFSoftShadowMap, LoadingManager } from 'three';
|
|
2
1
|
import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js';
|
|
3
2
|
import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js';
|
|
4
3
|
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
|
5
4
|
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
|
|
6
5
|
import { MeshoptDecoder } from 'three/examples/jsm/libs/meshopt_decoder.module.js';
|
|
6
|
+
import { EquirectangularReflectionMapping, FileLoader, TextureLoader, SRGBColorSpace, MathUtils, Vector3, Quaternion, Raycaster, Vector2, LinearInterpolant, Spherical, Object3D, Mesh, BoxGeometry, SphereGeometry, PlaneGeometry, Color, Plane as Plane$1, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget, HalfFloatType, ShaderMaterial, UniformsUtils, Scene, OrthographicCamera, NoBlending, AdditiveBlending, FloatType, UnsignedByteType, BufferGeometry, Float32BufferAttribute, ClampToEdgeWrapping, NearestFilter, LinearFilter, LinearMipMapLinearFilter, LinearSRGBColorSpace, WebGLCubeRenderTarget, DataTexture, RGBAFormat, UVMapping, WebGLRenderer, PCFSoftShadowMap, LoadingManager, LinearToneMapping, PMREMGenerator, MeshBasicMaterial, CubeCamera, Box3Helper, Box3, ShaderLib, ShaderChunk } from 'three';
|
|
7
7
|
import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';
|
|
8
8
|
|
|
9
9
|
class EventEmitter {
|
|
@@ -1004,7 +1004,43 @@ class TweenManager {
|
|
|
1004
1004
|
}
|
|
1005
1005
|
}
|
|
1006
1006
|
|
|
1007
|
-
|
|
1007
|
+
class aLoader {
|
|
1008
|
+
static _setMeshData(node) {
|
|
1009
|
+
const keys = aLoader._texKeys;
|
|
1010
|
+
const meshes = [];
|
|
1011
|
+
const textures = {};
|
|
1012
|
+
const materials = {};
|
|
1013
|
+
const queue = [
|
|
1014
|
+
node
|
|
1015
|
+
];
|
|
1016
|
+
while(queue.length !== 0){
|
|
1017
|
+
let object = queue.shift();
|
|
1018
|
+
if (object.isMesh) {
|
|
1019
|
+
meshes.push(object);
|
|
1020
|
+
const mat = object.material;
|
|
1021
|
+
if (Array.isArray(mat)) mat.forEach((v)=>materials[v.name] = v);
|
|
1022
|
+
else materials[mat.name] = mat;
|
|
1023
|
+
keys.forEach((k)=>{
|
|
1024
|
+
let tex = mat[k];
|
|
1025
|
+
if (tex) {
|
|
1026
|
+
textures[tex.uuid] = tex;
|
|
1027
|
+
}
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
object.children.forEach((v)=>queue.push(v));
|
|
1031
|
+
}
|
|
1032
|
+
node.userData.meshData = {
|
|
1033
|
+
meshes,
|
|
1034
|
+
materials,
|
|
1035
|
+
textures
|
|
1036
|
+
};
|
|
1037
|
+
return node;
|
|
1038
|
+
}
|
|
1039
|
+
constructor(manager){
|
|
1040
|
+
this.manager = manager;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
aLoader._texKeys = [
|
|
1008
1044
|
"alphaMap",
|
|
1009
1045
|
"aoMap",
|
|
1010
1046
|
"bumpMap",
|
|
@@ -1017,35 +1053,6 @@ const materialMapKeys = [
|
|
|
1017
1053
|
"roughnessMap",
|
|
1018
1054
|
"specularMap"
|
|
1019
1055
|
];
|
|
1020
|
-
class aLoader {
|
|
1021
|
-
static _setMeshData(node) {
|
|
1022
|
-
const meshData = {
|
|
1023
|
-
meshes: [],
|
|
1024
|
-
materials: {},
|
|
1025
|
-
textures: {}
|
|
1026
|
-
};
|
|
1027
|
-
const callback = (node)=>{
|
|
1028
|
-
const materials = Array.isArray(node.material) ? node.material : [
|
|
1029
|
-
node.material
|
|
1030
|
-
];
|
|
1031
|
-
for (let mat of materials){
|
|
1032
|
-
meshData.meshes.push(node);
|
|
1033
|
-
meshData.materials[mat.name] = mat;
|
|
1034
|
-
let tex = null;
|
|
1035
|
-
for (let v of materialMapKeys){
|
|
1036
|
-
tex = mat[v];
|
|
1037
|
-
tex && (meshData.textures[tex.uuid] = tex);
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
};
|
|
1041
|
-
node.traverse((v)=>v instanceof Mesh && callback(v));
|
|
1042
|
-
node.userData.meshData = meshData;
|
|
1043
|
-
return node;
|
|
1044
|
-
}
|
|
1045
|
-
constructor(manager){
|
|
1046
|
-
this.manager = manager;
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
1056
|
|
|
1050
1057
|
class aEXRLoader extends aLoader {
|
|
1051
1058
|
load({ url, onLoad, onProgress, onError, texSettings }) {
|
|
@@ -2889,51 +2896,704 @@ class Plane extends Mesh {
|
|
|
2889
2896
|
}
|
|
2890
2897
|
}
|
|
2891
2898
|
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2899
|
+
const ReflectorShader = {
|
|
2900
|
+
name: 'ReflectorShader',
|
|
2901
|
+
uniforms: {
|
|
2902
|
+
color: {
|
|
2903
|
+
value: null
|
|
2904
|
+
},
|
|
2905
|
+
tDiffuse: {
|
|
2906
|
+
value: null
|
|
2907
|
+
},
|
|
2908
|
+
textureMatrix: {
|
|
2909
|
+
value: null
|
|
2910
|
+
}
|
|
2911
|
+
},
|
|
2912
|
+
vertexShader: /* glsl */ `
|
|
2913
|
+
uniform mat4 textureMatrix;
|
|
2914
|
+
varying vec4 vUv;
|
|
2906
2915
|
|
|
2907
|
-
|
|
2908
|
-
|
|
2916
|
+
#include <common>
|
|
2917
|
+
#include <logdepthbuf_pars_vertex>
|
|
2909
2918
|
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2919
|
+
void main() {
|
|
2920
|
+
vUv = textureMatrix * vec4( position, 1.0 );
|
|
2921
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
2922
|
+
#include <logdepthbuf_vertex>
|
|
2923
|
+
}`,
|
|
2924
|
+
fragmentShader: /* glsl */ `
|
|
2925
|
+
uniform vec3 color;
|
|
2926
|
+
uniform sampler2D tDiffuse;
|
|
2927
|
+
varying vec4 vUv;
|
|
2913
2928
|
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2929
|
+
#include <logdepthbuf_pars_fragment>
|
|
2930
|
+
|
|
2931
|
+
float blendOverlay( float base, float blend ) {
|
|
2932
|
+
return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
|
|
2933
|
+
}
|
|
2917
2934
|
|
|
2918
|
-
|
|
2935
|
+
vec3 blendOverlay( vec3 base, vec3 blend ) {
|
|
2936
|
+
return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );
|
|
2937
|
+
}
|
|
2938
|
+
|
|
2939
|
+
void main() {
|
|
2940
|
+
#include <logdepthbuf_fragment>
|
|
2941
|
+
|
|
2942
|
+
vec4 base = texture2DProj( tDiffuse, vUv );
|
|
2943
|
+
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
|
|
2944
|
+
|
|
2945
|
+
#include <tonemapping_fragment>
|
|
2946
|
+
#include <colorspace_fragment>
|
|
2947
|
+
}`
|
|
2948
|
+
};
|
|
2949
|
+
class Reflector extends Mesh {
|
|
2950
|
+
constructor(options = {}){
|
|
2951
|
+
super(options.geometry || new PlaneGeometry());
|
|
2952
|
+
this.isReflector = true;
|
|
2953
|
+
const color = options.color !== undefined ? new Color(options.color) : new Color(0x7F7F7F);
|
|
2954
|
+
const textureWidth = options.textureWidth || 512;
|
|
2955
|
+
const textureHeight = options.textureHeight || 512;
|
|
2956
|
+
const clipBias = options.clipBias || 0;
|
|
2957
|
+
const multisample = options.multisample !== undefined ? options.multisample : 4;
|
|
2958
|
+
const defaultNormal = options.normal || new Vector3(0, 0, 1);
|
|
2959
|
+
const reflectorPlane = new Plane$1();
|
|
2960
|
+
const normal = new Vector3();
|
|
2961
|
+
const reflectorWorldPosition = new Vector3();
|
|
2962
|
+
const cameraWorldPosition = new Vector3();
|
|
2963
|
+
const rotationMatrix = new Matrix4();
|
|
2964
|
+
const lookAtPosition = new Vector3(0, 0, -1);
|
|
2965
|
+
const clipPlane = new Vector4();
|
|
2966
|
+
const view = new Vector3();
|
|
2967
|
+
const target = new Vector3();
|
|
2968
|
+
const q = new Vector4();
|
|
2969
|
+
const textureMatrix = new Matrix4();
|
|
2970
|
+
const virtualCamera = new PerspectiveCamera();
|
|
2971
|
+
virtualCamera.layers.set(options.layer || 0);
|
|
2972
|
+
const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight, {
|
|
2973
|
+
samples: multisample,
|
|
2974
|
+
type: HalfFloatType
|
|
2919
2975
|
});
|
|
2976
|
+
const shader = ReflectorShader;
|
|
2977
|
+
const material = options.material || new ShaderMaterial({
|
|
2978
|
+
name: shader.name ,
|
|
2979
|
+
uniforms: UniformsUtils.clone(shader.uniforms),
|
|
2980
|
+
fragmentShader: shader.fragmentShader,
|
|
2981
|
+
vertexShader: shader.vertexShader
|
|
2982
|
+
});
|
|
2983
|
+
if (material.uniforms.tDiffuse) {
|
|
2984
|
+
material.uniforms.tDiffuse.value = renderTarget.texture;
|
|
2985
|
+
}
|
|
2986
|
+
if (material.uniforms.textureMatrix) {
|
|
2987
|
+
material.uniforms.textureMatrix.value = textureMatrix;
|
|
2988
|
+
}
|
|
2989
|
+
if (material.uniforms.color) {
|
|
2990
|
+
material.uniforms.color.value = color;
|
|
2991
|
+
}
|
|
2992
|
+
this.material = material;
|
|
2993
|
+
const scope = this;
|
|
2994
|
+
this.onBeforeRender = function(renderer, scene, camera) {
|
|
2995
|
+
reflectorWorldPosition.setFromMatrixPosition(scope.matrixWorld);
|
|
2996
|
+
cameraWorldPosition.setFromMatrixPosition(camera.matrixWorld);
|
|
2997
|
+
rotationMatrix.extractRotation(scope.matrixWorld);
|
|
2998
|
+
normal.copy(defaultNormal);
|
|
2999
|
+
normal.applyMatrix4(rotationMatrix);
|
|
3000
|
+
view.subVectors(reflectorWorldPosition, cameraWorldPosition);
|
|
3001
|
+
// Avoid rendering when reflector is facing away
|
|
3002
|
+
if (view.dot(normal) > 0) return;
|
|
3003
|
+
view.reflect(normal).negate();
|
|
3004
|
+
view.add(reflectorWorldPosition);
|
|
3005
|
+
rotationMatrix.extractRotation(camera.matrixWorld);
|
|
3006
|
+
lookAtPosition.set(0, 0, -1);
|
|
3007
|
+
lookAtPosition.applyMatrix4(rotationMatrix);
|
|
3008
|
+
lookAtPosition.add(cameraWorldPosition);
|
|
3009
|
+
target.subVectors(reflectorWorldPosition, lookAtPosition);
|
|
3010
|
+
target.reflect(normal).negate();
|
|
3011
|
+
target.add(reflectorWorldPosition);
|
|
3012
|
+
virtualCamera.position.copy(view);
|
|
3013
|
+
virtualCamera.up.set(0, 1, 0);
|
|
3014
|
+
virtualCamera.up.applyMatrix4(rotationMatrix);
|
|
3015
|
+
virtualCamera.up.reflect(normal);
|
|
3016
|
+
virtualCamera.lookAt(target);
|
|
3017
|
+
virtualCamera.far = camera.far; // Used in WebGLBackground
|
|
3018
|
+
virtualCamera.updateMatrixWorld();
|
|
3019
|
+
virtualCamera.projectionMatrix.copy(camera.projectionMatrix);
|
|
3020
|
+
// Update the texture matrix
|
|
3021
|
+
textureMatrix.set(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);
|
|
3022
|
+
textureMatrix.multiply(virtualCamera.projectionMatrix);
|
|
3023
|
+
textureMatrix.multiply(virtualCamera.matrixWorldInverse);
|
|
3024
|
+
textureMatrix.multiply(scope.matrixWorld);
|
|
3025
|
+
// Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
|
|
3026
|
+
// Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
|
|
3027
|
+
reflectorPlane.setFromNormalAndCoplanarPoint(normal, reflectorWorldPosition);
|
|
3028
|
+
reflectorPlane.applyMatrix4(virtualCamera.matrixWorldInverse);
|
|
3029
|
+
clipPlane.set(reflectorPlane.normal.x, reflectorPlane.normal.y, reflectorPlane.normal.z, reflectorPlane.constant);
|
|
3030
|
+
const projectionMatrix = virtualCamera.projectionMatrix;
|
|
3031
|
+
q.x = (Math.sign(clipPlane.x) + projectionMatrix.elements[8]) / projectionMatrix.elements[0];
|
|
3032
|
+
q.y = (Math.sign(clipPlane.y) + projectionMatrix.elements[9]) / projectionMatrix.elements[5];
|
|
3033
|
+
q.z = -1.0;
|
|
3034
|
+
q.w = (1.0 + projectionMatrix.elements[10]) / projectionMatrix.elements[14];
|
|
3035
|
+
// Calculate the scaled plane vector
|
|
3036
|
+
clipPlane.multiplyScalar(2.0 / clipPlane.dot(q));
|
|
3037
|
+
// Replacing the third row of the projection matrix
|
|
3038
|
+
projectionMatrix.elements[2] = clipPlane.x;
|
|
3039
|
+
projectionMatrix.elements[6] = clipPlane.y;
|
|
3040
|
+
projectionMatrix.elements[10] = clipPlane.z + 1.0 - clipBias;
|
|
3041
|
+
projectionMatrix.elements[14] = clipPlane.w;
|
|
3042
|
+
// Render
|
|
3043
|
+
scope.visible = false;
|
|
3044
|
+
const currentRenderTarget = renderer.getRenderTarget();
|
|
3045
|
+
const currentActiveCubeFace = renderer.getActiveCubeFace();
|
|
3046
|
+
const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
|
|
3047
|
+
const currentXrEnabled = renderer.xr.enabled;
|
|
3048
|
+
const currentShadowAutoUpdate = renderer.shadowMap.autoUpdate;
|
|
3049
|
+
renderer.xr.enabled = false; // Avoid camera modification
|
|
3050
|
+
renderer.shadowMap.autoUpdate = false; // Avoid re-computing shadows
|
|
3051
|
+
renderer.setRenderTarget(renderTarget);
|
|
3052
|
+
renderer.state.buffers.depth.setMask(true); // make sure the depth buffer is writable so it can be properly cleared, see #18897
|
|
3053
|
+
if (renderer.autoClear === false) renderer.clear();
|
|
3054
|
+
renderer.render(scene, virtualCamera);
|
|
3055
|
+
renderer.xr.enabled = currentXrEnabled;
|
|
3056
|
+
renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
|
|
3057
|
+
renderer.setRenderTarget(currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel);
|
|
3058
|
+
// Restore viewport
|
|
3059
|
+
const viewport = camera.viewport;
|
|
3060
|
+
if (viewport !== undefined) {
|
|
3061
|
+
renderer.state.viewport(viewport);
|
|
3062
|
+
}
|
|
3063
|
+
scope.visible = true;
|
|
3064
|
+
};
|
|
3065
|
+
this.getRenderTarget = function() {
|
|
3066
|
+
return renderTarget;
|
|
3067
|
+
};
|
|
3068
|
+
this.getTextureMatrix = function() {
|
|
3069
|
+
return textureMatrix;
|
|
3070
|
+
};
|
|
3071
|
+
this.dispose = function() {
|
|
3072
|
+
renderTarget.dispose();
|
|
3073
|
+
scope.material.dispose();
|
|
3074
|
+
};
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
|
|
3078
|
+
const vert_fullscreen = /*glsl*/ `
|
|
3079
|
+
varying vec2 vUv;
|
|
3080
|
+
void main() {
|
|
3081
|
+
vUv = position.xy * 0.5 + 0.5;
|
|
3082
|
+
gl_Position = vec4(position.xy, 1.0, 1.0);
|
|
3083
|
+
}
|
|
3084
|
+
`;
|
|
3085
|
+
|
|
3086
|
+
const frag_BoxfilterBlur = `
|
|
3087
|
+
#include <common>
|
|
3088
|
+
uniform sampler2D tLast;
|
|
3089
|
+
uniform sampler2D tBlur;
|
|
3090
|
+
uniform float uLod;
|
|
3091
|
+
uniform float uWeight;
|
|
3092
|
+
varying vec2 vUv;
|
|
3093
|
+
|
|
3094
|
+
void main() {
|
|
3095
|
+
vec3 col0 = textureLod(tLast, vUv, 0.).rgb;
|
|
3096
|
+
vec3 col1 = textureLod(tBlur, vUv, uLod).rgb;
|
|
3097
|
+
gl_FragColor = vec4(mix(col0, col1, uWeight), 1.);
|
|
3098
|
+
}
|
|
3099
|
+
`;
|
|
3100
|
+
|
|
3101
|
+
const frag_panoramaToCubeMap = `
|
|
3102
|
+
#include <xv_common>
|
|
3103
|
+
|
|
3104
|
+
varying vec2 vUv;
|
|
3105
|
+
uniform sampler2D tMain;
|
|
3106
|
+
uniform int uFace;
|
|
3107
|
+
uniform vec4 uTilingOffset;
|
|
3108
|
+
|
|
3109
|
+
vec3 uvToXYZ(int face, vec2 uv) {
|
|
3110
|
+
if (face == 0) return vec3(-1.0, uv.y, -uv.x);
|
|
3111
|
+
else if (face == 1) return vec3(1.0, uv.y, uv.x);
|
|
3112
|
+
else if (face == 2) return vec3(-uv.x, -1.0, uv.y);
|
|
3113
|
+
else if (face == 3) return vec3(-uv.x, 1.0, -uv.y);
|
|
3114
|
+
else if (face == 4) return vec3(-uv.x, uv.y, 1.0);
|
|
3115
|
+
else return vec3(uv.x, uv.y, -1.0);
|
|
3116
|
+
}
|
|
3117
|
+
|
|
3118
|
+
vec4 panoramaToCubeMap(int face, vec2 uv_i) {
|
|
3119
|
+
vec2 uv = uv_i * 2.0 - 1.0;
|
|
3120
|
+
vec3 dir = normalize(uvToXYZ(face, uv));
|
|
3121
|
+
vec2 uv_o = dirToUv(dir);
|
|
3122
|
+
uv_o = vec2(uv_o.x, uv_o.y) * uTilingOffset.xy + uTilingOffset.zw;
|
|
3123
|
+
return texture(tMain, uv_o);
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
void main() {
|
|
3127
|
+
gl_FragColor = panoramaToCubeMap(uFace, vUv);
|
|
3128
|
+
}
|
|
3129
|
+
`;
|
|
3130
|
+
const frag_cubeMapToPanorama = `
|
|
3131
|
+
#include <xv_common>
|
|
3132
|
+
|
|
3133
|
+
varying vec2 vUv;
|
|
3134
|
+
uniform samplerCube tMain;
|
|
3135
|
+
|
|
3136
|
+
vec4 cubeMapToPanorama(vec2 uv_i) {
|
|
3137
|
+
return texture(tMain, uvToDir(uv_i));
|
|
3138
|
+
}
|
|
3139
|
+
|
|
3140
|
+
void main() {
|
|
3141
|
+
gl_FragColor = cubeMapToPanorama(vUv);
|
|
3142
|
+
}
|
|
3143
|
+
`;
|
|
3144
|
+
|
|
3145
|
+
function getShaderMaterial(uniforms, vertexShader, fragmentShader, onInit) {
|
|
3146
|
+
const material = class extends ShaderMaterial {
|
|
3147
|
+
constructor(parameters = {}){
|
|
3148
|
+
const entries = Object.entries(uniforms);
|
|
3149
|
+
// Create unforms and shaders
|
|
3150
|
+
super({
|
|
3151
|
+
uniforms: entries.reduce((acc, [name, value])=>{
|
|
3152
|
+
const uniform = UniformsUtils.clone({
|
|
3153
|
+
[name]: {
|
|
3154
|
+
value
|
|
3155
|
+
}
|
|
3156
|
+
});
|
|
3157
|
+
return {
|
|
3158
|
+
...acc,
|
|
3159
|
+
...uniform
|
|
3160
|
+
};
|
|
3161
|
+
}, {}),
|
|
3162
|
+
vertexShader,
|
|
3163
|
+
fragmentShader
|
|
3164
|
+
});
|
|
3165
|
+
// Create getter/setters
|
|
3166
|
+
entries.forEach(([name])=>Object.defineProperty(this, name, {
|
|
3167
|
+
get: ()=>this.uniforms[name].value,
|
|
3168
|
+
set: (v)=>this.uniforms[name].value = v
|
|
3169
|
+
}));
|
|
3170
|
+
// Assign parameters, this might include uniforms
|
|
3171
|
+
Object.assign(this, parameters);
|
|
3172
|
+
// Call onInit
|
|
3173
|
+
if (onInit) onInit(this);
|
|
3174
|
+
}
|
|
2920
3175
|
};
|
|
3176
|
+
return material;
|
|
3177
|
+
}
|
|
3178
|
+
|
|
3179
|
+
const vert_Reflector = `
|
|
3180
|
+
uniform mat4 textureMatrix;
|
|
3181
|
+
varying vec4 vUv4;
|
|
3182
|
+
varying vec2 vUv;
|
|
3183
|
+
varying vec2 vUv1;
|
|
3184
|
+
varying vec3 vViewPosition;
|
|
3185
|
+
|
|
3186
|
+
#include <common>
|
|
3187
|
+
#include <normal_pars_vertex>
|
|
3188
|
+
#include <logdepthbuf_pars_vertex>
|
|
3189
|
+
|
|
3190
|
+
void main() {
|
|
3191
|
+
#include <beginnormal_vertex>
|
|
3192
|
+
#include <defaultnormal_vertex>
|
|
3193
|
+
|
|
3194
|
+
vec4 positionWS = modelMatrix * vec4(position, 1.0);
|
|
3195
|
+
vec4 mvPosition = viewMatrix * positionWS;
|
|
3196
|
+
|
|
3197
|
+
vUv = uv;
|
|
3198
|
+
vUv1 = uv1;
|
|
3199
|
+
vUv4 = textureMatrix * vec4(position, 1.0);
|
|
3200
|
+
|
|
3201
|
+
vViewPosition = -mvPosition.xyz;
|
|
3202
|
+
vNormal = normalize(transformedNormal);
|
|
3203
|
+
|
|
3204
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
3205
|
+
#include <logdepthbuf_vertex>
|
|
2921
3206
|
}
|
|
3207
|
+
`;
|
|
3208
|
+
const frag_Reflector = `
|
|
3209
|
+
uniform vec3 color;
|
|
3210
|
+
uniform float roughness;
|
|
3211
|
+
uniform float metalness;
|
|
3212
|
+
uniform sampler2D tDiffuse;
|
|
3213
|
+
uniform sampler2D normalMap;
|
|
3214
|
+
uniform sampler2D roughnessMap;
|
|
3215
|
+
uniform sampler2D aoMap;
|
|
3216
|
+
uniform float aoMapIntensity;
|
|
3217
|
+
uniform sampler2D lightMap;
|
|
3218
|
+
uniform float lightMapIntensity;
|
|
2922
3219
|
|
|
2923
|
-
|
|
2924
|
-
|
|
3220
|
+
varying vec4 vUv4;
|
|
3221
|
+
varying vec2 vUv;
|
|
3222
|
+
varying vec2 vUv1;
|
|
3223
|
+
varying vec3 vViewPosition;
|
|
3224
|
+
varying vec3 vNormal;
|
|
2925
3225
|
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
3226
|
+
#include <common>
|
|
3227
|
+
#include <lights_physical_pars_fragment>
|
|
3228
|
+
#include <logdepthbuf_pars_fragment>
|
|
2929
3229
|
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
3230
|
+
void main() {
|
|
3231
|
+
#include <logdepthbuf_fragment>
|
|
3232
|
+
|
|
3233
|
+
vec4 uv4 = vUv4;
|
|
3234
|
+
vec4 texelNormal = texture2D(normalMap, vUv);
|
|
3235
|
+
vec3 normal = normalize(vec3(texelNormal.r * 2.0 - 1.0, texelNormal.b, texelNormal.g * 2.0 - 1.0));
|
|
3236
|
+
vec3 coord = uv4.xyz / uv4.w;
|
|
3237
|
+
vec2 reflectUv = coord.xy + coord.z * normal.xz * 0.05;
|
|
3238
|
+
|
|
3239
|
+
vec3 geometryNormal = normalize(vNormal);
|
|
3240
|
+
vec3 geometryViewDir = normalize(vViewPosition);
|
|
3241
|
+
|
|
3242
|
+
vec3 singleScattering = vec3( 0.0 );
|
|
3243
|
+
vec3 multiScattering = vec3( 0.0 );
|
|
3244
|
+
|
|
3245
|
+
float metalnessFactor = metalness;
|
|
3246
|
+
vec3 diffuseColor = color.rgb * ( 1.0 - metalnessFactor );
|
|
3247
|
+
vec3 specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
|
|
3248
|
+
float specularF90 = 1.0;
|
|
3249
|
+
|
|
3250
|
+
float roughnessFactor = texture2D(roughnessMap, vUv).g * roughness;
|
|
3251
|
+
|
|
3252
|
+
computeMultiscattering( geometryNormal, geometryViewDir, specularColor, specularF90, roughnessFactor, singleScattering, multiScattering );
|
|
3253
|
+
|
|
3254
|
+
vec3 totalScattering = singleScattering + multiScattering;
|
|
3255
|
+
vec3 diffuse = diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
|
|
3256
|
+
|
|
3257
|
+
vec3 irradiance = vec3(0.);
|
|
3258
|
+
irradiance += texture2D(lightMap, vUv).rgb * lightMapIntensity;
|
|
3259
|
+
|
|
3260
|
+
float lod = roughnessFactor * (1.7 - 0.7 * roughnessFactor) * 6.;
|
|
3261
|
+
vec4 reflectColor = textureLod(tDiffuse, reflectUv, lod);
|
|
3262
|
+
|
|
3263
|
+
vec3 f_specular = vec3(0.);
|
|
3264
|
+
vec3 f_diffuse = vec3(0.);
|
|
3265
|
+
|
|
3266
|
+
f_specular += reflectColor.rgb * (1.0 - roughnessFactor * roughnessFactor) + multiScattering * irradiance;
|
|
3267
|
+
f_diffuse += diffuse * irradiance;
|
|
3268
|
+
|
|
3269
|
+
float ambientOcclusion = mix(1., texture2D(aoMap, vUv1).r, aoMapIntensity);
|
|
3270
|
+
float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
|
|
3271
|
+
f_specular *= computeSpecularOcclusion(dotNV, ambientOcclusion, roughnessFactor);
|
|
3272
|
+
|
|
3273
|
+
gl_FragColor = vec4(f_specular + f_diffuse, 1.);
|
|
3274
|
+
|
|
3275
|
+
#include <tonemapping_fragment>
|
|
3276
|
+
#include <colorspace_fragment>
|
|
3277
|
+
}
|
|
3278
|
+
`;
|
|
3279
|
+
class ReflectorMaterial extends ShaderMaterial {
|
|
3280
|
+
get metalness() {
|
|
3281
|
+
return this.uniforms.metalness.value;
|
|
3282
|
+
}
|
|
3283
|
+
set metalness(v) {
|
|
3284
|
+
this.uniforms.metalness.value = v;
|
|
3285
|
+
}
|
|
3286
|
+
get roughness() {
|
|
3287
|
+
return this.uniforms.roughness.value;
|
|
3288
|
+
}
|
|
3289
|
+
set roughness(v) {
|
|
3290
|
+
this.uniforms.roughness.value = v;
|
|
3291
|
+
}
|
|
3292
|
+
get roughnessMap() {
|
|
3293
|
+
return this.uniforms.roughnessMap.value;
|
|
3294
|
+
}
|
|
3295
|
+
set roughnessMap(v) {
|
|
3296
|
+
this.uniforms.roughnessMap.value = v;
|
|
3297
|
+
}
|
|
3298
|
+
get normalMap() {
|
|
3299
|
+
return this.uniforms.normalMap.value;
|
|
3300
|
+
}
|
|
3301
|
+
set normalMap(v) {
|
|
3302
|
+
this.uniforms.normalMap.value = v;
|
|
3303
|
+
}
|
|
3304
|
+
get aoMap() {
|
|
3305
|
+
return this.uniforms.aoMap.value;
|
|
3306
|
+
}
|
|
3307
|
+
set aoMap(v) {
|
|
3308
|
+
this.uniforms.aoMap.value = v;
|
|
3309
|
+
}
|
|
3310
|
+
get lightMap() {
|
|
3311
|
+
return this.uniforms.lightMap.value;
|
|
3312
|
+
}
|
|
3313
|
+
set lightMap(v) {
|
|
3314
|
+
this.uniforms.lightMap.value = v;
|
|
3315
|
+
}
|
|
3316
|
+
constructor(...args){
|
|
3317
|
+
super(...args);
|
|
3318
|
+
this.vertexShader = vert_Reflector;
|
|
3319
|
+
this.fragmentShader = frag_Reflector;
|
|
3320
|
+
this.uniforms = {
|
|
3321
|
+
color: {
|
|
3322
|
+
value: new Color(0xffffff)
|
|
3323
|
+
},
|
|
3324
|
+
tDiffuse: {
|
|
3325
|
+
value: null
|
|
3326
|
+
},
|
|
3327
|
+
textureMatrix: {
|
|
3328
|
+
value: null
|
|
3329
|
+
},
|
|
3330
|
+
metalness: {
|
|
3331
|
+
value: 0
|
|
3332
|
+
},
|
|
3333
|
+
roughness: {
|
|
3334
|
+
value: 1
|
|
3335
|
+
},
|
|
3336
|
+
roughnessMap: {
|
|
3337
|
+
value: null
|
|
3338
|
+
},
|
|
3339
|
+
normalMap: {
|
|
3340
|
+
value: null
|
|
3341
|
+
},
|
|
3342
|
+
aoMap: {
|
|
3343
|
+
value: null
|
|
3344
|
+
},
|
|
3345
|
+
aoMapIntensity: {
|
|
3346
|
+
value: 1
|
|
3347
|
+
},
|
|
3348
|
+
lightMap: {
|
|
3349
|
+
value: null
|
|
3350
|
+
},
|
|
3351
|
+
lightMapIntensity: {
|
|
3352
|
+
value: 1
|
|
3353
|
+
}
|
|
3354
|
+
};
|
|
2934
3355
|
}
|
|
3356
|
+
}
|
|
3357
|
+
__decorate([
|
|
3358
|
+
property({
|
|
3359
|
+
min: 0,
|
|
3360
|
+
max: 1,
|
|
3361
|
+
step: 0.01
|
|
3362
|
+
})
|
|
3363
|
+
], ReflectorMaterial.prototype, "metalness", null);
|
|
3364
|
+
__decorate([
|
|
3365
|
+
property({
|
|
3366
|
+
min: 0,
|
|
3367
|
+
max: 1,
|
|
3368
|
+
step: 0.01
|
|
3369
|
+
})
|
|
3370
|
+
], ReflectorMaterial.prototype, "roughness", null);
|
|
2935
3371
|
|
|
2936
|
-
|
|
3372
|
+
class Plugin extends ObjectInstance {
|
|
3373
|
+
constructor(...args){
|
|
3374
|
+
super(...args);
|
|
3375
|
+
this.type = "Plugin";
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
|
|
3379
|
+
class DebugPlugin extends Plugin {
|
|
3380
|
+
static Instance(viewer) {
|
|
3381
|
+
return viewer.getPlugin(DebugPlugin, true);
|
|
3382
|
+
}
|
|
3383
|
+
add(node) {
|
|
3384
|
+
this.scene.add(node);
|
|
3385
|
+
return node;
|
|
3386
|
+
}
|
|
3387
|
+
remove(node) {
|
|
3388
|
+
this.scene.remove(node);
|
|
3389
|
+
return node;
|
|
3390
|
+
}
|
|
3391
|
+
onRender(dt) {
|
|
3392
|
+
const { renderer, camera } = this.viewer;
|
|
3393
|
+
const autoClear = renderer.autoClear;
|
|
3394
|
+
renderer.autoClear = false;
|
|
3395
|
+
renderer.render(this.scene, camera);
|
|
3396
|
+
renderer.autoClear = autoClear;
|
|
3397
|
+
}
|
|
3398
|
+
constructor(...args){
|
|
3399
|
+
super(...args);
|
|
3400
|
+
this.scene = new Scene();
|
|
3401
|
+
}
|
|
3402
|
+
}
|
|
3403
|
+
|
|
3404
|
+
const LOD_MIN = 4;
|
|
3405
|
+
const _flatCamera = /*@__PURE__*/ new OrthographicCamera();
|
|
3406
|
+
function _setViewport(target, x, y, width, height) {
|
|
3407
|
+
target.viewport.set(x, y, width, height);
|
|
3408
|
+
target.scissor.set(x, y, width, height);
|
|
3409
|
+
}
|
|
3410
|
+
function _getCommonVertexShader() {
|
|
3411
|
+
return /* glsl */ `
|
|
3412
|
+
precision mediump float;
|
|
3413
|
+
precision mediump int;
|
|
3414
|
+
|
|
3415
|
+
attribute float faceIndex;
|
|
3416
|
+
|
|
3417
|
+
varying vec3 vOutputDirection;
|
|
3418
|
+
|
|
3419
|
+
// RH coordinate system; PMREM face-indexing convention
|
|
3420
|
+
vec3 getDirection( vec2 uv, float face ) {
|
|
3421
|
+
|
|
3422
|
+
uv = 2.0 * uv - 1.0;
|
|
3423
|
+
vec3 direction = vec3( uv, 1.0 );
|
|
3424
|
+
|
|
3425
|
+
if ( face == 0.0 ) {
|
|
3426
|
+
direction = direction.zyx; // ( 1, v, u ) pos x
|
|
3427
|
+
} else if ( face == 1.0 ) {
|
|
3428
|
+
direction = direction.xzy;
|
|
3429
|
+
direction.xz *= -1.0; // ( -u, 1, -v ) pos y
|
|
3430
|
+
} else if ( face == 2.0 ) {
|
|
3431
|
+
direction.x *= -1.0; // ( -u, v, 1 ) pos z
|
|
3432
|
+
} else if ( face == 3.0 ) {
|
|
3433
|
+
direction = direction.zyx;
|
|
3434
|
+
direction.xz *= -1.0; // ( -1, v, -u ) neg x
|
|
3435
|
+
} else if ( face == 4.0 ) {
|
|
3436
|
+
direction = direction.xzy;
|
|
3437
|
+
direction.xy *= -1.0; // ( -u, -1, v ) neg y
|
|
3438
|
+
} else if ( face == 5.0 ) {
|
|
3439
|
+
direction.z *= -1.0; // ( u, v, -1 ) neg z
|
|
3440
|
+
}
|
|
3441
|
+
|
|
3442
|
+
return direction;
|
|
3443
|
+
|
|
3444
|
+
}
|
|
3445
|
+
|
|
3446
|
+
void main() {
|
|
3447
|
+
vOutputDirection = getDirection( uv, faceIndex );
|
|
3448
|
+
gl_Position = vec4( position, 1.0 );
|
|
3449
|
+
}
|
|
3450
|
+
`;
|
|
3451
|
+
}
|
|
3452
|
+
function _getClearMaterial() {
|
|
3453
|
+
return new ShaderMaterial({
|
|
3454
|
+
name: "Clear",
|
|
3455
|
+
uniforms: {
|
|
3456
|
+
map: {
|
|
3457
|
+
value: null
|
|
3458
|
+
},
|
|
3459
|
+
intensity: {
|
|
3460
|
+
value: 1
|
|
3461
|
+
}
|
|
3462
|
+
},
|
|
3463
|
+
vertexShader: vert_fullscreen,
|
|
3464
|
+
fragmentShader: /* glsl */ `
|
|
3465
|
+
uniform sampler2D map;
|
|
3466
|
+
uniform float intensity;
|
|
3467
|
+
varying vec2 vUv;
|
|
3468
|
+
void main() {
|
|
3469
|
+
vec4 col = texture2D(map, vUv);
|
|
3470
|
+
gl_FragColor = vec4(col.rgb * intensity, col.a);
|
|
3471
|
+
}
|
|
3472
|
+
`,
|
|
3473
|
+
blending: NoBlending,
|
|
3474
|
+
depthWrite: false,
|
|
3475
|
+
depthTest: false
|
|
3476
|
+
});
|
|
3477
|
+
}
|
|
3478
|
+
function _getCubeMapMaterial() {
|
|
3479
|
+
return new ShaderMaterial({
|
|
3480
|
+
name: "CubeMapToCubeUV",
|
|
3481
|
+
uniforms: {
|
|
3482
|
+
envMap: {
|
|
3483
|
+
value: null
|
|
3484
|
+
},
|
|
3485
|
+
lod: {
|
|
3486
|
+
value: 0
|
|
3487
|
+
}
|
|
3488
|
+
},
|
|
3489
|
+
vertexShader: _getCommonVertexShader(),
|
|
3490
|
+
fragmentShader: /* glsl */ `
|
|
3491
|
+
precision mediump float;
|
|
3492
|
+
precision mediump int;
|
|
3493
|
+
|
|
3494
|
+
varying vec3 vOutputDirection;
|
|
3495
|
+
uniform samplerCube envMap;
|
|
3496
|
+
uniform float lod;
|
|
3497
|
+
|
|
3498
|
+
void main() {
|
|
3499
|
+
gl_FragColor = textureCubeLodEXT(envMap, vOutputDirection, lod);
|
|
3500
|
+
}
|
|
3501
|
+
`,
|
|
3502
|
+
blending: AdditiveBlending,
|
|
3503
|
+
depthWrite: false,
|
|
3504
|
+
depthTest: false
|
|
3505
|
+
});
|
|
3506
|
+
}
|
|
3507
|
+
function _getMipCopyMaterial(lodMax, width, height) {
|
|
3508
|
+
return new ShaderMaterial({
|
|
3509
|
+
name: "MipBlurToCubeUV",
|
|
3510
|
+
defines: {
|
|
3511
|
+
CUBEUV_TEXEL_WIDTH: 1.0 / width,
|
|
3512
|
+
CUBEUV_TEXEL_HEIGHT: 1.0 / height,
|
|
3513
|
+
CUBEUV_MAX_MIP: `${lodMax}.0`
|
|
3514
|
+
},
|
|
3515
|
+
uniforms: {
|
|
3516
|
+
cubeUVMap: {
|
|
3517
|
+
value: null
|
|
3518
|
+
},
|
|
3519
|
+
lod: {
|
|
3520
|
+
value: 0
|
|
3521
|
+
}
|
|
3522
|
+
},
|
|
3523
|
+
vertexShader: _getCommonVertexShader(),
|
|
3524
|
+
fragmentShader: /* glsl */ `
|
|
3525
|
+
precision mediump float;
|
|
3526
|
+
precision mediump int;
|
|
3527
|
+
|
|
3528
|
+
#define ENVMAP_TYPE_CUBE_UV
|
|
3529
|
+
#include <cube_uv_reflection_fragment>
|
|
3530
|
+
|
|
3531
|
+
varying vec3 vOutputDirection;
|
|
3532
|
+
|
|
3533
|
+
uniform sampler2D cubeUVMap;
|
|
3534
|
+
uniform float lod;
|
|
3535
|
+
|
|
3536
|
+
void main() {
|
|
3537
|
+
vec3 col = bilinearCubeUV(cubeUVMap, vOutputDirection, CUBEUV_MAX_MIP - lod);
|
|
3538
|
+
gl_FragColor = vec4(col, 1.);
|
|
3539
|
+
}
|
|
3540
|
+
`,
|
|
3541
|
+
blending: AdditiveBlending,
|
|
3542
|
+
depthWrite: false,
|
|
3543
|
+
depthTest: false
|
|
3544
|
+
});
|
|
3545
|
+
}
|
|
3546
|
+
function _getMipBlurMaterial(lodMax, width, height) {
|
|
3547
|
+
return new ShaderMaterial({
|
|
3548
|
+
name: "MipBlurToCubeUV",
|
|
3549
|
+
defines: {
|
|
3550
|
+
CUBEUV_TEXEL_WIDTH: 1.0 / width,
|
|
3551
|
+
CUBEUV_TEXEL_HEIGHT: 1.0 / height,
|
|
3552
|
+
CUBEUV_MAX_MIP: `${lodMax}.0`
|
|
3553
|
+
},
|
|
3554
|
+
uniforms: {
|
|
3555
|
+
envMap: {
|
|
3556
|
+
value: null
|
|
3557
|
+
},
|
|
3558
|
+
cubeUVMap: {
|
|
3559
|
+
value: null
|
|
3560
|
+
},
|
|
3561
|
+
weight: {
|
|
3562
|
+
value: 1
|
|
3563
|
+
},
|
|
3564
|
+
lod: {
|
|
3565
|
+
value: 0
|
|
3566
|
+
},
|
|
3567
|
+
exposure: {
|
|
3568
|
+
value: 1
|
|
3569
|
+
}
|
|
3570
|
+
},
|
|
3571
|
+
vertexShader: _getCommonVertexShader(),
|
|
3572
|
+
fragmentShader: /* glsl */ `
|
|
3573
|
+
precision mediump float;
|
|
3574
|
+
precision mediump int;
|
|
3575
|
+
|
|
3576
|
+
#define ENVMAP_TYPE_CUBE_UV
|
|
3577
|
+
#include <cube_uv_reflection_fragment>
|
|
3578
|
+
|
|
3579
|
+
varying vec3 vOutputDirection;
|
|
3580
|
+
|
|
3581
|
+
uniform sampler2D cubeUVMap;
|
|
3582
|
+
uniform samplerCube envMap;
|
|
3583
|
+
uniform float weight;
|
|
3584
|
+
uniform float lod;
|
|
3585
|
+
uniform float exposure;
|
|
3586
|
+
|
|
3587
|
+
void main() {
|
|
3588
|
+
vec3 col0 = bilinearCubeUV(cubeUVMap, vOutputDirection, CUBEUV_MAX_MIP - (lod + 1.));
|
|
3589
|
+
vec3 col1 = textureCubeLodEXT(envMap, vOutputDirection, lod).rgb * exposure;
|
|
3590
|
+
gl_FragColor = vec4(mix(col0, col1, weight), 1.);
|
|
3591
|
+
}
|
|
3592
|
+
`,
|
|
3593
|
+
blending: NoBlending,
|
|
3594
|
+
depthWrite: false,
|
|
3595
|
+
depthTest: false
|
|
3596
|
+
});
|
|
2937
3597
|
}
|
|
2938
3598
|
|
|
2939
3599
|
class Caller {
|
|
@@ -3440,12 +4100,7 @@ class ResourceManager {
|
|
|
3440
4100
|
this._loaders.set(ext, loader);
|
|
3441
4101
|
}
|
|
3442
4102
|
}
|
|
3443
|
-
loadAsset(
|
|
3444
|
-
var { url, ext, onProgress } = _param, props = _object_without_properties_loose(_param, [
|
|
3445
|
-
"url",
|
|
3446
|
-
"ext",
|
|
3447
|
-
"onProgress"
|
|
3448
|
-
]);
|
|
4103
|
+
loadAsset({ url, ext, onProgress, ...props }) {
|
|
3449
4104
|
return new Promise((resolve, reject)=>{
|
|
3450
4105
|
const info = ResourceManager._parseURL(url);
|
|
3451
4106
|
const texSettings = ResourceManager._splitTextureSettings(props);
|
|
@@ -3495,8 +4150,9 @@ ResourceManager._texSettingKeys = [
|
|
|
3495
4150
|
"minFilter",
|
|
3496
4151
|
"format",
|
|
3497
4152
|
"anisotropy",
|
|
4153
|
+
"repeat",
|
|
3498
4154
|
"colorSpace",
|
|
3499
|
-
"
|
|
4155
|
+
"channel"
|
|
3500
4156
|
];
|
|
3501
4157
|
|
|
3502
4158
|
function applyProps(target, props) {
|
|
@@ -3611,7 +4267,7 @@ class Viewer extends EventEmitter {
|
|
|
3611
4267
|
renderer.render(Viewer.fullscreenMesh, Viewer.fullscreenCamera);
|
|
3612
4268
|
renderer.setRenderTarget(RT);
|
|
3613
4269
|
}
|
|
3614
|
-
static
|
|
4270
|
+
static CreateFullscreenTriangle() {
|
|
3615
4271
|
let geometry = new BufferGeometry();
|
|
3616
4272
|
geometry.setAttribute('position', new Float32BufferAttribute([
|
|
3617
4273
|
-1,
|
|
@@ -3634,6 +4290,37 @@ class Viewer extends EventEmitter {
|
|
|
3634
4290
|
], 2));
|
|
3635
4291
|
return geometry;
|
|
3636
4292
|
}
|
|
4293
|
+
static GetChildByName(node, name) {
|
|
4294
|
+
return Viewer.GetObject(node, (v)=>v.name === name && v);
|
|
4295
|
+
}
|
|
4296
|
+
static GetObject(node, filter) {
|
|
4297
|
+
const queue = [
|
|
4298
|
+
node
|
|
4299
|
+
];
|
|
4300
|
+
while(queue.length !== 0){
|
|
4301
|
+
let object = queue.shift();
|
|
4302
|
+
let target = filter(object);
|
|
4303
|
+
if (target) {
|
|
4304
|
+
return target;
|
|
4305
|
+
}
|
|
4306
|
+
object.children.forEach((v)=>queue.push(v));
|
|
4307
|
+
}
|
|
4308
|
+
}
|
|
4309
|
+
static GetObjects(node, filter) {
|
|
4310
|
+
const queue = [
|
|
4311
|
+
node
|
|
4312
|
+
];
|
|
4313
|
+
const objects = [];
|
|
4314
|
+
while(queue.length !== 0){
|
|
4315
|
+
let object = queue.shift();
|
|
4316
|
+
let target = filter(object);
|
|
4317
|
+
if (target) {
|
|
4318
|
+
objects.push(object);
|
|
4319
|
+
}
|
|
4320
|
+
object.children.forEach((v)=>queue.push(v));
|
|
4321
|
+
}
|
|
4322
|
+
return objects;
|
|
4323
|
+
}
|
|
3637
4324
|
get root() {
|
|
3638
4325
|
return this._root;
|
|
3639
4326
|
}
|
|
@@ -3803,30 +4490,20 @@ class Viewer extends EventEmitter {
|
|
|
3803
4490
|
addLoader(Loader) {
|
|
3804
4491
|
this._resourceManager.addLoader(Loader);
|
|
3805
4492
|
}
|
|
3806
|
-
load(
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
const node = yield _this.loadAsset({
|
|
3817
|
-
url,
|
|
3818
|
-
ext,
|
|
3819
|
-
onProgress
|
|
4493
|
+
async load({ url, ext, onProgress, castShadow = false, receiveShadow = false, ...props }) {
|
|
4494
|
+
const node = await this.loadAsset({
|
|
4495
|
+
url,
|
|
4496
|
+
ext,
|
|
4497
|
+
onProgress
|
|
4498
|
+
});
|
|
4499
|
+
if (castShadow || receiveShadow) {
|
|
4500
|
+
node.userData.meshData.meshes.forEach((v)=>{
|
|
4501
|
+
v.castShadow = castShadow;
|
|
4502
|
+
v.receiveShadow = receiveShadow;
|
|
3820
4503
|
});
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
v.receiveShadow = receiveShadow;
|
|
3825
|
-
});
|
|
3826
|
-
}
|
|
3827
|
-
_this.addNode(node, props);
|
|
3828
|
-
return node;
|
|
3829
|
-
})();
|
|
4504
|
+
}
|
|
4505
|
+
this.addNode(node, props);
|
|
4506
|
+
return node;
|
|
3830
4507
|
}
|
|
3831
4508
|
tween(target) {
|
|
3832
4509
|
return this._tweenManager.tween(target);
|
|
@@ -3838,16 +4515,12 @@ class Viewer extends EventEmitter {
|
|
|
3838
4515
|
this._tweenManager.killTweensOf(target);
|
|
3839
4516
|
}
|
|
3840
4517
|
traverseMaterials(callback) {
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
if (item.material) {
|
|
4518
|
+
Viewer.GetObjects(this._scene, (item)=>{
|
|
4519
|
+
if (item.isMesh) {
|
|
3844
4520
|
if (Array.isArray(item.material)) item.material.forEach(callback);
|
|
3845
4521
|
else callback(item.material);
|
|
3846
4522
|
}
|
|
3847
|
-
};
|
|
3848
|
-
renderList.opaque.forEach(setMaterial);
|
|
3849
|
-
renderList.transparent.forEach(setMaterial);
|
|
3850
|
-
renderList.transmissive.forEach(setMaterial);
|
|
4523
|
+
});
|
|
3851
4524
|
}
|
|
3852
4525
|
traversePlugins(callback) {
|
|
3853
4526
|
return this._pluginManager.traversePlugins(callback);
|
|
@@ -3875,18 +4548,7 @@ class Viewer extends EventEmitter {
|
|
|
3875
4548
|
removeComponent(node, component) {
|
|
3876
4549
|
return this._componentManager.removeComponent(node, component);
|
|
3877
4550
|
}
|
|
3878
|
-
addNode(object,
|
|
3879
|
-
var { args, debug, scale, position, rotation, shadowArgs, makeDefault, component, parent = this._scene } = _param, props = _object_without_properties_loose(_param, [
|
|
3880
|
-
"args",
|
|
3881
|
-
"debug",
|
|
3882
|
-
"scale",
|
|
3883
|
-
"position",
|
|
3884
|
-
"rotation",
|
|
3885
|
-
"shadowArgs",
|
|
3886
|
-
"makeDefault",
|
|
3887
|
-
"component",
|
|
3888
|
-
"parent"
|
|
3889
|
-
]);
|
|
4551
|
+
addNode(object, { args, debug, scale, position, rotation, shadowArgs, makeDefault, component, parent = this._scene, ...props } = {}) {
|
|
3890
4552
|
let node = null;
|
|
3891
4553
|
let ins = getClassInstance(object, args);
|
|
3892
4554
|
if (ins.isObject3D) {
|
|
@@ -3943,7 +4605,7 @@ class Viewer extends EventEmitter {
|
|
|
3943
4605
|
minFilter: nearest ? NearestFilter : mipmap ? LinearMipMapLinearFilter : LinearFilter,
|
|
3944
4606
|
type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : UnsignedByteType : floatType,
|
|
3945
4607
|
anisotropy: 0,
|
|
3946
|
-
colorSpace:
|
|
4608
|
+
colorSpace: LinearSRGBColorSpace,
|
|
3947
4609
|
depthBuffer: false,
|
|
3948
4610
|
stencilBuffer: false,
|
|
3949
4611
|
samples: SystemInfo.isSupportMSAA ? msaa : 0,
|
|
@@ -3958,7 +4620,7 @@ class Viewer extends EventEmitter {
|
|
|
3958
4620
|
minFilter: nearest ? NearestFilter : mipmap ? LinearMipMapLinearFilter : LinearFilter,
|
|
3959
4621
|
type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : UnsignedByteType : floatType,
|
|
3960
4622
|
anisotropy: 0,
|
|
3961
|
-
colorSpace:
|
|
4623
|
+
colorSpace: LinearSRGBColorSpace,
|
|
3962
4624
|
depthBuffer: false,
|
|
3963
4625
|
stencilBuffer: false,
|
|
3964
4626
|
samples: SystemInfo.isSupportMSAA ? msaa : 0,
|
|
@@ -4011,30 +4673,12 @@ class Viewer extends EventEmitter {
|
|
|
4011
4673
|
Viewer.CompileObject3D(this._renderer, this._scene, this._camera, this._scene);
|
|
4012
4674
|
}
|
|
4013
4675
|
}
|
|
4014
|
-
constructor(
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
}, targetFrameRate = -1, colorSpace = SRGBColorSpace, toneMapping = LinearToneMapping, toneMappingExposure = 1, maxDPR = 1.5, path = "", resourcePath = "", dracoPath = "https://www.gstatic.com/draco/v1/decoders/", loader = {}, tasker = {} } = _param, webglOpts = _object_without_properties_loose(_param, [
|
|
4021
|
-
"root",
|
|
4022
|
-
"canvas",
|
|
4023
|
-
"autoStart",
|
|
4024
|
-
"autoResize",
|
|
4025
|
-
"shadows",
|
|
4026
|
-
"camera",
|
|
4027
|
-
"targetFrameRate",
|
|
4028
|
-
"colorSpace",
|
|
4029
|
-
"toneMapping",
|
|
4030
|
-
"toneMappingExposure",
|
|
4031
|
-
"maxDPR",
|
|
4032
|
-
"path",
|
|
4033
|
-
"resourcePath",
|
|
4034
|
-
"dracoPath",
|
|
4035
|
-
"loader",
|
|
4036
|
-
"tasker"
|
|
4037
|
-
]);
|
|
4676
|
+
constructor({ root, canvas, autoStart = true, autoResize = true, shadows = false, camera = {
|
|
4677
|
+
fov: 45,
|
|
4678
|
+
near: 0.1,
|
|
4679
|
+
far: 1000,
|
|
4680
|
+
position: new Vector3(0, 0, 4)
|
|
4681
|
+
}, targetFrameRate = -1, colorSpace = SRGBColorSpace, toneMapping = LinearToneMapping, toneMappingExposure = 1, maxDPR = 1.5, path = "", resourcePath = "", dracoPath = "https://www.gstatic.com/draco/v1/decoders/", loader = {}, tasker = {}, ...webglOpts } = {}){
|
|
4038
4682
|
super();
|
|
4039
4683
|
this._dpr = 1;
|
|
4040
4684
|
this._width = 1;
|
|
@@ -4063,7 +4707,7 @@ class Viewer extends EventEmitter {
|
|
|
4063
4707
|
this._DATA_FLOAT_TYPE = webgl.DATA_FLOAT_TYPE;
|
|
4064
4708
|
this._dpr = Math.min(maxDPR, window.devicePixelRatio);
|
|
4065
4709
|
this._scene = new Scene();
|
|
4066
|
-
this._camera = new PerspectiveCamera();
|
|
4710
|
+
this._camera = applyProps(new PerspectiveCamera(), camera);
|
|
4067
4711
|
this._renderer = new WebGLRenderer({
|
|
4068
4712
|
canvas: el,
|
|
4069
4713
|
context: webgl.gl
|
|
@@ -4104,15 +4748,444 @@ Viewer._shadowCameraKeys = [
|
|
|
4104
4748
|
"near",
|
|
4105
4749
|
"far"
|
|
4106
4750
|
];
|
|
4107
|
-
Viewer.fullscreenMesh = new Mesh(Viewer.
|
|
4751
|
+
Viewer.fullscreenMesh = new Mesh(Viewer.CreateFullscreenTriangle());
|
|
4108
4752
|
Viewer.fullscreenCamera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
4109
4753
|
|
|
4110
|
-
class
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4754
|
+
class MergeRefectPass {
|
|
4755
|
+
get envMapTarget() {
|
|
4756
|
+
return this._envMapTarget;
|
|
4757
|
+
}
|
|
4758
|
+
dispose() {
|
|
4759
|
+
this._envMapTarget.dispose();
|
|
4760
|
+
this._pmremGenerator.dispose();
|
|
4761
|
+
}
|
|
4762
|
+
mergeReflect(info) {
|
|
4763
|
+
this._pmremGenerator._clearTexture(this._envMapTarget, this.envMapIntensity);
|
|
4764
|
+
this._pmremGenerator._mergeReflect(this._envMapTarget, this._reflectMap);
|
|
4765
|
+
info.envMapTarget = this._envMapTarget;
|
|
4766
|
+
info.lodMax = this._pmremGenerator._lodMeshes.length - 1;
|
|
4767
|
+
}
|
|
4768
|
+
_getPMREMExtension(renderer) {
|
|
4769
|
+
const pmremGenerator = new PMREMGenerator(renderer);
|
|
4770
|
+
pmremGenerator._fromTextureExtension = function(reflectMap, envMap) {
|
|
4771
|
+
const target = envMap ? this._fromTexture(envMap) : this._fromCubeTexture(reflectMap);
|
|
4772
|
+
this._cubeMapMaterial = _getCubeMapMaterial();
|
|
4773
|
+
this._copyTexMaterial = _getClearMaterial();
|
|
4774
|
+
this._copyMesh = new Mesh(Viewer.fullscreenMesh.geometry, this._copyTexMaterial);
|
|
4775
|
+
this._lodMeshes = this._lodPlanes.map((v)=>new Mesh(v, this._cubeMapMaterial));
|
|
4776
|
+
this._sourceInit = false;
|
|
4777
|
+
return target;
|
|
4778
|
+
};
|
|
4779
|
+
pmremGenerator._fromCubeTexture = function(texture) {
|
|
4780
|
+
this._setSize(texture.image.length === 0 ? 16 : texture.image[0].width || texture.image[0].image.width);
|
|
4781
|
+
return this._allocateTargets();
|
|
4782
|
+
};
|
|
4783
|
+
pmremGenerator._copyTexture = function(targetOut, texture, intensity = 1) {
|
|
4784
|
+
const uniforms = this._copyTexMaterial.uniforms;
|
|
4785
|
+
uniforms.map.value = texture;
|
|
4786
|
+
uniforms.intensity.value = intensity;
|
|
4787
|
+
const renderer = this._renderer;
|
|
4788
|
+
renderer.autoClear = true;
|
|
4789
|
+
renderer.setRenderTarget(targetOut);
|
|
4790
|
+
renderer.render(this._copyMesh, _flatCamera);
|
|
4791
|
+
renderer.setRenderTarget(null);
|
|
4792
|
+
};
|
|
4793
|
+
pmremGenerator._clearTexture = function(targetOut, intensity) {
|
|
4794
|
+
const source = this._pingPongRenderTarget;
|
|
4795
|
+
if (this._sourceInit === false) {
|
|
4796
|
+
this._sourceInit = true;
|
|
4797
|
+
source.scissorTest = false;
|
|
4798
|
+
_setViewport(source, 0, 0, source.width, source.height);
|
|
4799
|
+
this._copyTexture(source, targetOut.texture);
|
|
4800
|
+
} else {
|
|
4801
|
+
this._copyTexture(targetOut, source.texture, intensity);
|
|
4802
|
+
}
|
|
4803
|
+
};
|
|
4804
|
+
pmremGenerator._mergeReflect = function(sourceTarget, reflectMap, clear = false) {
|
|
4805
|
+
const renderer = this._renderer;
|
|
4806
|
+
const autoClear = renderer.autoClear;
|
|
4807
|
+
const cubeMapMaterial = this._cubeMapMaterial;
|
|
4808
|
+
const uniforms = this._cubeMapMaterial.uniforms;
|
|
4809
|
+
uniforms.envMap.value = reflectMap;
|
|
4810
|
+
renderer.autoClear = clear;
|
|
4811
|
+
for(let i = 0; i < this._lodMeshes.length - 1; i++){
|
|
4812
|
+
uniforms.lod.value = i < 5 ? 0 : i;
|
|
4813
|
+
this._blit(sourceTarget, i, cubeMapMaterial);
|
|
4814
|
+
}
|
|
4815
|
+
sourceTarget.scissorTest = false;
|
|
4816
|
+
_setViewport(sourceTarget, 0, 0, sourceTarget.width, sourceTarget.height);
|
|
4817
|
+
renderer.autoClear = autoClear;
|
|
4818
|
+
};
|
|
4819
|
+
pmremGenerator._blit = function(targetOut, lodOut, material) {
|
|
4820
|
+
const renderer = this._renderer;
|
|
4821
|
+
const _lodMax = this._lodMax;
|
|
4822
|
+
const outputSize = this._sizeLods[lodOut];
|
|
4823
|
+
const x = 3 * outputSize * (lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0);
|
|
4824
|
+
const y = 4 * (this._cubeSize - outputSize);
|
|
4825
|
+
_setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
|
|
4826
|
+
const lodMesh = this._lodMeshes[lodOut];
|
|
4827
|
+
lodMesh.material = material;
|
|
4828
|
+
renderer.autoClear = false;
|
|
4829
|
+
renderer.setRenderTarget(targetOut);
|
|
4830
|
+
renderer.render(lodMesh, _flatCamera);
|
|
4831
|
+
};
|
|
4832
|
+
return pmremGenerator;
|
|
4833
|
+
}
|
|
4834
|
+
constructor({ envMap, reflectMap, viewer }){
|
|
4835
|
+
this.envMapIntensity = 1;
|
|
4836
|
+
this._reflectMap = reflectMap;
|
|
4837
|
+
this._pmremGenerator = this._getPMREMExtension(viewer.renderer);
|
|
4838
|
+
this._envMapTarget = this._pmremGenerator._fromTextureExtension(reflectMap, envMap);
|
|
4839
|
+
viewer.scene.environment = this._envMapTarget.texture;
|
|
4840
|
+
}
|
|
4841
|
+
}
|
|
4842
|
+
|
|
4843
|
+
function mipGaussianBlendWeight(sigma, lod) {
|
|
4844
|
+
let sigma2 = sigma * sigma;
|
|
4845
|
+
let c = 2.0 * Math.PI * sigma2;
|
|
4846
|
+
let numerator = Math.pow(16, lod) * 1.386294361; //log(4)
|
|
4847
|
+
let denorminator = c * (Math.pow(4, lod) + c);
|
|
4848
|
+
return MathUtils.clamp(numerator / denorminator, 0, 1);
|
|
4849
|
+
}
|
|
4850
|
+
|
|
4851
|
+
const MAX_LOD = 10;
|
|
4852
|
+
class MergeMipBlurPass {
|
|
4853
|
+
get blurIntensity() {
|
|
4854
|
+
return this._blurIntensity;
|
|
4855
|
+
}
|
|
4856
|
+
set blurIntensity(v) {
|
|
4857
|
+
if (this._blurIntensity !== v) {
|
|
4858
|
+
this._blurIntensity = v;
|
|
4859
|
+
this._sigma = MathUtils.lerp(1, 40, this._blurIntensity / 10);
|
|
4860
|
+
for(let lod = 0; lod <= MAX_LOD; lod++){
|
|
4861
|
+
let w = mipGaussianBlendWeight(this._sigma, lod);
|
|
4862
|
+
if (w < 0.002) {
|
|
4863
|
+
this._blurMinLod = lod;
|
|
4864
|
+
}
|
|
4865
|
+
if (w >= 1) {
|
|
4866
|
+
this._blurMaxLod = lod;
|
|
4867
|
+
break;
|
|
4868
|
+
}
|
|
4869
|
+
}
|
|
4870
|
+
}
|
|
4871
|
+
}
|
|
4872
|
+
get envMapTarget() {
|
|
4873
|
+
return this._envMapTarget;
|
|
4874
|
+
}
|
|
4875
|
+
dispose() {
|
|
4876
|
+
this._envMapTarget.dispose();
|
|
4877
|
+
this._pmremGenerator.dispose();
|
|
4878
|
+
}
|
|
4879
|
+
mergeMipBlur(info) {
|
|
4880
|
+
const targetIn = this._pmremGenerator._applyMipBlur(this._envMapTarget, this._reflectMap, this._blurMinLod, this._blurMaxLod, this._sigma, this.exposure);
|
|
4881
|
+
this._pmremGenerator._mipCopy(info.envMapTarget, targetIn, info.lodMax, this._blurMinLod);
|
|
4882
|
+
}
|
|
4883
|
+
_getPMREMExtension(renderer) {
|
|
4884
|
+
const pmremGenerator = new PMREMGenerator(renderer);
|
|
4885
|
+
pmremGenerator._fromTextureExtension = function(texture) {
|
|
4886
|
+
this._setSize(texture.image.length === 0 ? 16 : texture.image[0].width || texture.image[0].image.width);
|
|
4887
|
+
const target = this._allocateTargets();
|
|
4888
|
+
this._mipBlurMaterial = _getMipBlurMaterial(this._lodMax, target.width, target.height);
|
|
4889
|
+
this._mipCopyMaterial = _getMipCopyMaterial(this._lodMax, target.width, target.height);
|
|
4890
|
+
this._lodMeshes = this._lodPlanes.map((v)=>new Mesh(v, this._mipBlurMaterial));
|
|
4891
|
+
return target;
|
|
4892
|
+
};
|
|
4893
|
+
pmremGenerator._applyMipBlur = function(sourceTarget, texture, blurMinLod, blurMaxLod, sigma, exposure) {
|
|
4894
|
+
const pingPongRenderTarget = this._pingPongRenderTarget;
|
|
4895
|
+
const uniforms = this._mipBlurMaterial.uniforms;
|
|
4896
|
+
uniforms.envMap.value = texture;
|
|
4897
|
+
uniforms.exposure.value = exposure;
|
|
4898
|
+
let lod = blurMaxLod;
|
|
4899
|
+
let targetOut = sourceTarget;
|
|
4900
|
+
let targetIn = pingPongRenderTarget;
|
|
4901
|
+
this._mipBlur(sourceTarget, pingPongRenderTarget, lod, 1);
|
|
4902
|
+
for(let i = 0; lod-- > blurMinLod; i++){
|
|
4903
|
+
targetOut = (i & 1) === 0 ? pingPongRenderTarget : sourceTarget;
|
|
4904
|
+
targetIn = (i & 1) === 1 ? pingPongRenderTarget : sourceTarget;
|
|
4905
|
+
this._mipBlur(targetOut, targetIn, lod, mipGaussianBlendWeight(sigma, lod));
|
|
4906
|
+
}
|
|
4907
|
+
sourceTarget.scissorTest = false;
|
|
4908
|
+
_setViewport(sourceTarget, 0, 0, sourceTarget.width, sourceTarget.height);
|
|
4909
|
+
return targetOut;
|
|
4910
|
+
};
|
|
4911
|
+
pmremGenerator._mipBlur = function(targetOut, targetIn, lodOut, weight) {
|
|
4912
|
+
const uniforms = this._mipBlurMaterial.uniforms;
|
|
4913
|
+
uniforms.cubeUVMap.value = targetIn.texture;
|
|
4914
|
+
uniforms.weight.value = weight;
|
|
4915
|
+
uniforms.lod.value = lodOut;
|
|
4916
|
+
this._blit(targetOut, lodOut, this._mipBlurMaterial);
|
|
4917
|
+
};
|
|
4918
|
+
pmremGenerator._mipCopy = function(targetOut, targetIn, lodOut, lodIn = lodOut) {
|
|
4919
|
+
const uniforms = this._mipCopyMaterial.uniforms;
|
|
4920
|
+
uniforms.cubeUVMap.value = targetIn.texture;
|
|
4921
|
+
uniforms.lod.value = lodIn;
|
|
4922
|
+
this._blit(targetOut, lodOut, this._mipCopyMaterial);
|
|
4923
|
+
targetOut.scissorTest = false;
|
|
4924
|
+
_setViewport(targetOut, 0, 0, targetOut.width, targetOut.height);
|
|
4925
|
+
};
|
|
4926
|
+
pmremGenerator._blit = function(targetOut, lodOut, material) {
|
|
4927
|
+
const renderer = this._renderer;
|
|
4928
|
+
const _lodMax = this._lodMax;
|
|
4929
|
+
const outputSize = this._sizeLods[lodOut];
|
|
4930
|
+
const x = 3 * outputSize * (lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0);
|
|
4931
|
+
const y = 4 * (this._cubeSize - outputSize);
|
|
4932
|
+
_setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
|
|
4933
|
+
const lodMesh = this._lodMeshes[lodOut];
|
|
4934
|
+
lodMesh.material = material;
|
|
4935
|
+
renderer.autoClear = false;
|
|
4936
|
+
renderer.setRenderTarget(targetOut);
|
|
4937
|
+
renderer.render(lodMesh, _flatCamera);
|
|
4938
|
+
};
|
|
4939
|
+
return pmremGenerator;
|
|
4940
|
+
}
|
|
4941
|
+
constructor({ viewer, reflectMap }){
|
|
4942
|
+
this._sigma = 2;
|
|
4943
|
+
this._blurMinLod = 0;
|
|
4944
|
+
this._blurMaxLod = MAX_LOD;
|
|
4945
|
+
this._blurIntensity = -1;
|
|
4946
|
+
this.exposure = 1;
|
|
4947
|
+
this._reflectMap = reflectMap;
|
|
4948
|
+
this._pmremGenerator = this._getPMREMExtension(viewer.renderer);
|
|
4949
|
+
this._envMapTarget = this._pmremGenerator._fromTextureExtension(reflectMap);
|
|
4950
|
+
}
|
|
4951
|
+
}
|
|
4952
|
+
|
|
4953
|
+
class EnvironmentPlugin extends Plugin {
|
|
4954
|
+
get debug() {
|
|
4955
|
+
return this._debug;
|
|
4956
|
+
}
|
|
4957
|
+
set debug(v) {
|
|
4958
|
+
if (this._debug !== v) {
|
|
4959
|
+
this._debug = v;
|
|
4960
|
+
if (v) {
|
|
4961
|
+
if (this._debugNode === null) {
|
|
4962
|
+
const viewer = this.viewer;
|
|
4963
|
+
const debugScene = DebugPlugin.Instance(viewer).scene;
|
|
4964
|
+
this._debugNode = viewer.addNode(Object3D, {
|
|
4965
|
+
parent: debugScene
|
|
4966
|
+
});
|
|
4967
|
+
viewer.addNode(Plane, {
|
|
4968
|
+
parent: this._debugNode,
|
|
4969
|
+
material: new MeshBasicMaterial({
|
|
4970
|
+
map: this._reflectPass.envMapTarget.texture
|
|
4971
|
+
}),
|
|
4972
|
+
position: new Vector3(1.1, 3, 0)
|
|
4973
|
+
});
|
|
4974
|
+
viewer.addNode(Plane, {
|
|
4975
|
+
parent: this._debugNode,
|
|
4976
|
+
material: new MeshBasicMaterial({
|
|
4977
|
+
map: this._mipBlurPass.envMapTarget.texture
|
|
4978
|
+
}),
|
|
4979
|
+
position: new Vector3(0, 3, 0)
|
|
4980
|
+
});
|
|
4981
|
+
}
|
|
4982
|
+
}
|
|
4983
|
+
if (this._debugNode) {
|
|
4984
|
+
this._debugNode.visible = v;
|
|
4985
|
+
}
|
|
4986
|
+
}
|
|
4987
|
+
}
|
|
4988
|
+
onRender() {
|
|
4989
|
+
const { renderer } = this.viewer;
|
|
4990
|
+
const autoClear = renderer.autoClear;
|
|
4991
|
+
const oldTarget = renderer.getRenderTarget();
|
|
4992
|
+
const oldActiveCubeFace = renderer.getActiveCubeFace();
|
|
4993
|
+
const oldActiveMipmapLevel = renderer.getActiveMipmapLevel();
|
|
4994
|
+
this._reflectPass.envMapIntensity = this.envMapIntensity;
|
|
4995
|
+
this._mipBlurPass.exposure = this.reflectExposure;
|
|
4996
|
+
this._mipBlurPass.blurIntensity = this.reflectBlurIntensity;
|
|
4997
|
+
this._cubeCamera.update(renderer, this._scene);
|
|
4998
|
+
this._reflectPass.mergeReflect(this._mergeInfo);
|
|
4999
|
+
this._mipBlurPass.mergeMipBlur(this._mergeInfo);
|
|
5000
|
+
renderer.autoClear = autoClear;
|
|
5001
|
+
renderer.setRenderTarget(oldTarget, oldActiveCubeFace, oldActiveMipmapLevel);
|
|
5002
|
+
}
|
|
5003
|
+
constructor({ envMap, scene, near, far, layer = 0, resolution = 256, floatType = HalfFloatType, position = new Vector3(0, 1, 0) } = {}){
|
|
5004
|
+
super();
|
|
5005
|
+
this._mergeInfo = {
|
|
5006
|
+
envMapTarget: null,
|
|
5007
|
+
lodMax: 0
|
|
5008
|
+
};
|
|
5009
|
+
this._debug = false;
|
|
5010
|
+
this._debugNode = null;
|
|
5011
|
+
this.envMapIntensity = 1;
|
|
5012
|
+
this.reflectExposure = 1;
|
|
5013
|
+
this.reflectBlurIntensity = 5;
|
|
5014
|
+
this.install = ()=>{
|
|
5015
|
+
const viewer = this.viewer;
|
|
5016
|
+
this._scene = scene || viewer.scene;
|
|
5017
|
+
const cubeRenderTarget = viewer.createCubeRenderTarget(resolution, false, floatType, 0, true);
|
|
5018
|
+
this._cubeCamera = new CubeCamera(near || viewer.camera.near, far || viewer.camera.far, cubeRenderTarget);
|
|
5019
|
+
this._cubeCamera.position.copy(position);
|
|
5020
|
+
this._cubeCamera.layers.set(layer);
|
|
5021
|
+
const reflectMap = cubeRenderTarget.texture;
|
|
5022
|
+
this._reflectPass = new MergeRefectPass({
|
|
5023
|
+
viewer,
|
|
5024
|
+
reflectMap,
|
|
5025
|
+
envMap
|
|
5026
|
+
});
|
|
5027
|
+
this._mipBlurPass = new MergeMipBlurPass({
|
|
5028
|
+
viewer,
|
|
5029
|
+
reflectMap
|
|
5030
|
+
});
|
|
5031
|
+
};
|
|
5032
|
+
this.uninstall = ()=>{
|
|
5033
|
+
this._reflectPass.dispose();
|
|
5034
|
+
this._mipBlurPass.dispose();
|
|
5035
|
+
};
|
|
5036
|
+
}
|
|
5037
|
+
}
|
|
5038
|
+
__decorate([
|
|
5039
|
+
property
|
|
5040
|
+
], EnvironmentPlugin.prototype, "debug", null);
|
|
5041
|
+
__decorate([
|
|
5042
|
+
property({
|
|
5043
|
+
min: 0,
|
|
5044
|
+
max: 1,
|
|
5045
|
+
step: 0.01
|
|
5046
|
+
})
|
|
5047
|
+
], EnvironmentPlugin.prototype, "envMapIntensity", void 0);
|
|
5048
|
+
__decorate([
|
|
5049
|
+
property({
|
|
5050
|
+
min: 0,
|
|
5051
|
+
max: 10,
|
|
5052
|
+
step: 0.01
|
|
5053
|
+
})
|
|
5054
|
+
], EnvironmentPlugin.prototype, "reflectExposure", void 0);
|
|
5055
|
+
__decorate([
|
|
5056
|
+
property({
|
|
5057
|
+
min: 0,
|
|
5058
|
+
max: 10,
|
|
5059
|
+
step: 0.1
|
|
5060
|
+
})
|
|
5061
|
+
], EnvironmentPlugin.prototype, "reflectBlurIntensity", void 0);
|
|
5062
|
+
|
|
5063
|
+
class BoxProjectionPlugin extends Plugin {
|
|
5064
|
+
get debug() {
|
|
5065
|
+
return this._debug;
|
|
5066
|
+
}
|
|
5067
|
+
set debug(v) {
|
|
5068
|
+
if (this._debug !== v) {
|
|
5069
|
+
this._debug = v;
|
|
5070
|
+
if (v) {
|
|
5071
|
+
if (this._helper === null) {
|
|
5072
|
+
this._helper = new Box3Helper(new Box3(this._boxMin, this._boxMax));
|
|
5073
|
+
DebugPlugin.Instance(this.viewer).add(this._helper);
|
|
5074
|
+
}
|
|
5075
|
+
}
|
|
5076
|
+
if (this._helper) {
|
|
5077
|
+
this._helper.visible = v;
|
|
5078
|
+
}
|
|
5079
|
+
}
|
|
5080
|
+
}
|
|
5081
|
+
get center() {
|
|
5082
|
+
return this._center;
|
|
5083
|
+
}
|
|
5084
|
+
set center(v) {
|
|
5085
|
+
this._center.copy(v);
|
|
5086
|
+
}
|
|
5087
|
+
get boxMin() {
|
|
5088
|
+
return this._boxMin;
|
|
5089
|
+
}
|
|
5090
|
+
set boxMin(v) {
|
|
5091
|
+
this._boxMin.copy(v);
|
|
5092
|
+
}
|
|
5093
|
+
get boxMax() {
|
|
5094
|
+
return this._boxMax;
|
|
5095
|
+
}
|
|
5096
|
+
set boxMax(v) {
|
|
5097
|
+
this._boxMax.copy(v);
|
|
5098
|
+
}
|
|
5099
|
+
onUpdate(dt) {
|
|
5100
|
+
if (this._debug) {
|
|
5101
|
+
this._helper.updateMatrixWorld();
|
|
5102
|
+
}
|
|
5103
|
+
}
|
|
5104
|
+
useBoxProjection(shader) {
|
|
5105
|
+
shader.defines.USE_BOX_PROJECTION = true;
|
|
5106
|
+
shader.uniforms.probePos = {
|
|
5107
|
+
value: this._center
|
|
5108
|
+
};
|
|
5109
|
+
shader.uniforms.probeBoxMin = {
|
|
5110
|
+
value: this._boxMin
|
|
5111
|
+
};
|
|
5112
|
+
shader.uniforms.probeBoxMax = {
|
|
5113
|
+
value: this._boxMax
|
|
5114
|
+
};
|
|
5115
|
+
}
|
|
5116
|
+
constructor(){
|
|
5117
|
+
super();
|
|
5118
|
+
this._center = new Vector4(0, 0.5, 0, 1);
|
|
5119
|
+
this._boxMin = new Vector3(0, 0, 0);
|
|
5120
|
+
this._boxMax = new Vector3(1, 1, 1);
|
|
5121
|
+
this._helper = null;
|
|
5122
|
+
this._debug = false;
|
|
5123
|
+
this.install = ()=>{
|
|
5124
|
+
ShaderLib.physical.vertexShader = ShaderLib.physical.vertexShader.replace(/#ifdef USE_TRANSMISSION/g, `
|
|
5125
|
+
#if defined(USE_TRANSMISSION) || defined(USE_BOX_PROJECTION)
|
|
5126
|
+
`);
|
|
5127
|
+
ShaderLib.physical.fragmentShader = ShaderLib.physical.fragmentShader.replace("varying vec3 vViewPosition;", `
|
|
5128
|
+
varying vec3 vViewPosition;
|
|
5129
|
+
#if defined(USE_BOX_PROJECTION)
|
|
5130
|
+
varying vec3 vWorldPosition;
|
|
5131
|
+
#endif
|
|
5132
|
+
`);
|
|
5133
|
+
ShaderChunk.worldpos_vertex = ShaderChunk.worldpos_vertex.replace("#if defined( USE_ENVMAP )", "#if defined( USE_ENVMAP ) || defined( USE_BOX_PROJECTION )");
|
|
5134
|
+
ShaderChunk.envmap_physical_pars_fragment = ShaderChunk.envmap_physical_pars_fragment.replace("#ifdef USE_ENVMAP", `
|
|
5135
|
+
#ifdef USE_ENVMAP
|
|
5136
|
+
|
|
5137
|
+
#if defined(USE_BOX_PROJECTION)
|
|
5138
|
+
uniform vec4 probePos;
|
|
5139
|
+
uniform vec3 probeBoxMin;
|
|
5140
|
+
uniform vec3 probeBoxMax;
|
|
5141
|
+
|
|
5142
|
+
vec3 boxProjection(vec3 nrdir, vec3 worldPos, vec3 probePos, vec3 boxMin, vec3 boxMax) {
|
|
5143
|
+
vec3 tbot = boxMin - worldPos;
|
|
5144
|
+
vec3 ttop = boxMax - worldPos;
|
|
5145
|
+
vec3 tmax = mix(tbot, ttop, step(vec3(0), nrdir));
|
|
5146
|
+
tmax /= nrdir;
|
|
5147
|
+
float t = min(min(tmax.x, tmax.y), tmax.z);
|
|
5148
|
+
return worldPos + nrdir * t - probePos;
|
|
5149
|
+
}
|
|
5150
|
+
#endif
|
|
5151
|
+
|
|
5152
|
+
`).replace("reflectVec = inverseTransformDirection( reflectVec, viewMatrix );", `
|
|
5153
|
+
reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
|
|
5154
|
+
|
|
5155
|
+
#if defined(USE_BOX_PROJECTION)
|
|
5156
|
+
if (probePos.w > 0.001) {
|
|
5157
|
+
reflectVec = boxProjection(reflectVec, vWorldPosition, probePos.xyz, probeBoxMin.xyz, probeBoxMax.xyz);
|
|
5158
|
+
}
|
|
5159
|
+
#endif
|
|
5160
|
+
|
|
5161
|
+
`).replace("vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );", `
|
|
5162
|
+
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
|
|
5163
|
+
|
|
5164
|
+
#if defined(USE_BOX_PROJECTION)
|
|
5165
|
+
if (probePos.w > 0.001) {
|
|
5166
|
+
worldNormal = boxProjection(worldNormal, vWorldPosition, probePos.xyz, probeBoxMin.xyz, probeBoxMax.xyz);
|
|
5167
|
+
}
|
|
5168
|
+
#endif
|
|
5169
|
+
|
|
5170
|
+
`);
|
|
5171
|
+
};
|
|
5172
|
+
this.uninstall = ()=>{
|
|
5173
|
+
DebugPlugin.Instance(this.viewer).remove(this._helper);
|
|
5174
|
+
};
|
|
4114
5175
|
}
|
|
4115
5176
|
}
|
|
5177
|
+
__decorate([
|
|
5178
|
+
property
|
|
5179
|
+
], BoxProjectionPlugin.prototype, "debug", null);
|
|
5180
|
+
__decorate([
|
|
5181
|
+
property
|
|
5182
|
+
], BoxProjectionPlugin.prototype, "center", null);
|
|
5183
|
+
__decorate([
|
|
5184
|
+
property
|
|
5185
|
+
], BoxProjectionPlugin.prototype, "boxMin", null);
|
|
5186
|
+
__decorate([
|
|
5187
|
+
property
|
|
5188
|
+
], BoxProjectionPlugin.prototype, "boxMax", null);
|
|
4116
5189
|
|
|
4117
|
-
export { AnimationCurve, Box, CinestationBlendDefinition, CinestationBrain, Component, DeviceInput, Easing, EventEmitter, FInterpConstantTo, FInterpTo, FreelookVirtualCamera, Logger, ObjectInstance, Perlin, Plane, Plugin, PropertyManager, QInterpConstantTo, QInterpTo, Quat_AngularDistance, Quat_Equals, Quat_exponentialDamp, Quat_quarticDamp, Quat_smoothDamp, Sphere, SystemInfo, Tween, TweenChain, TweenManager, VInterpConstantTo, VInterpTo, Vec3_smoothDamp, Vector3_NEG_ONE, Vector3_ONE, Vector3_RIGHT, Vector3_UNIT_X, Vector3_UNIT_Y, Vector3_UNIT_Z, Vector3_UP, Vector3_ZERO, Viewer, VirtualCamera, aEXRLoader, aFBXLoader, aGLTFLoader, aHDRLoader, aJSONLoader, aTextureLoader, exponentialDamp, getClassInstance, mixin, property, quarticDamp, smoothDamp };
|
|
5190
|
+
export { AnimationCurve, Box, BoxProjectionPlugin, CinestationBlendDefinition, CinestationBrain, Component, DebugPlugin, DeviceInput, Easing, EnvironmentPlugin, EventEmitter, FInterpConstantTo, FInterpTo, FreelookVirtualCamera, Logger, ObjectInstance, Perlin, Plane, Plugin, PropertyManager, QInterpConstantTo, QInterpTo, Quat_AngularDistance, Quat_Equals, Quat_exponentialDamp, Quat_quarticDamp, Quat_smoothDamp, Reflector, ReflectorMaterial, Sphere, SystemInfo, Tween, TweenChain, TweenManager, VInterpConstantTo, VInterpTo, Vec3_smoothDamp, Vector3_NEG_ONE, Vector3_ONE, Vector3_RIGHT, Vector3_UNIT_X, Vector3_UNIT_Y, Vector3_UNIT_Z, Vector3_UP, Vector3_ZERO, Viewer, VirtualCamera, aEXRLoader, aFBXLoader, aGLTFLoader, aHDRLoader, aJSONLoader, aLoader, aTextureLoader, exponentialDamp, frag_BoxfilterBlur, frag_cubeMapToPanorama, frag_panoramaToCubeMap, getClassInstance, getShaderMaterial, mixin, property, quarticDamp, smoothDamp, vert_fullscreen };
|
|
4118
5191
|
//# sourceMappingURL=module.js.map
|