@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/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 {
|
|
@@ -1006,7 +1006,43 @@ class TweenManager {
|
|
|
1006
1006
|
}
|
|
1007
1007
|
}
|
|
1008
1008
|
|
|
1009
|
-
|
|
1009
|
+
class aLoader {
|
|
1010
|
+
static _setMeshData(node) {
|
|
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
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
object.children.forEach((v)=>queue.push(v));
|
|
1033
|
+
}
|
|
1034
|
+
node.userData.meshData = {
|
|
1035
|
+
meshes,
|
|
1036
|
+
materials,
|
|
1037
|
+
textures
|
|
1038
|
+
};
|
|
1039
|
+
return node;
|
|
1040
|
+
}
|
|
1041
|
+
constructor(manager){
|
|
1042
|
+
this.manager = manager;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
aLoader._texKeys = [
|
|
1010
1046
|
"alphaMap",
|
|
1011
1047
|
"aoMap",
|
|
1012
1048
|
"bumpMap",
|
|
@@ -1019,35 +1055,6 @@ const materialMapKeys = [
|
|
|
1019
1055
|
"roughnessMap",
|
|
1020
1056
|
"specularMap"
|
|
1021
1057
|
];
|
|
1022
|
-
class aLoader {
|
|
1023
|
-
static _setMeshData(node) {
|
|
1024
|
-
const meshData = {
|
|
1025
|
-
meshes: [],
|
|
1026
|
-
materials: {},
|
|
1027
|
-
textures: {}
|
|
1028
|
-
};
|
|
1029
|
-
const callback = (node)=>{
|
|
1030
|
-
const materials = Array.isArray(node.material) ? node.material : [
|
|
1031
|
-
node.material
|
|
1032
|
-
];
|
|
1033
|
-
for (let mat of materials){
|
|
1034
|
-
meshData.meshes.push(node);
|
|
1035
|
-
meshData.materials[mat.name] = mat;
|
|
1036
|
-
let tex = null;
|
|
1037
|
-
for (let v of materialMapKeys){
|
|
1038
|
-
tex = mat[v];
|
|
1039
|
-
tex && (meshData.textures[tex.uuid] = tex);
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
};
|
|
1043
|
-
node.traverse((v)=>v instanceof three.Mesh && callback(v));
|
|
1044
|
-
node.userData.meshData = meshData;
|
|
1045
|
-
return node;
|
|
1046
|
-
}
|
|
1047
|
-
constructor(manager){
|
|
1048
|
-
this.manager = manager;
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
1058
|
|
|
1052
1059
|
class aEXRLoader extends aLoader {
|
|
1053
1060
|
load({ url, onLoad, onProgress, onError, texSettings }) {
|
|
@@ -2891,51 +2898,704 @@ class Plane extends three.Mesh {
|
|
|
2891
2898
|
}
|
|
2892
2899
|
}
|
|
2893
2900
|
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
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;
|
|
2908
2917
|
|
|
2909
|
-
|
|
2910
|
-
|
|
2918
|
+
#include <common>
|
|
2919
|
+
#include <logdepthbuf_pars_vertex>
|
|
2911
2920
|
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
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;
|
|
2915
2930
|
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
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 );
|
|
2919
2946
|
|
|
2920
|
-
|
|
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
|
|
2921
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
|
+
}
|
|
2922
3177
|
};
|
|
3178
|
+
return material;
|
|
2923
3179
|
}
|
|
2924
3180
|
|
|
2925
|
-
|
|
2926
|
-
|
|
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;
|
|
2927
3221
|
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
3222
|
+
varying vec4 vUv4;
|
|
3223
|
+
varying vec2 vUv;
|
|
3224
|
+
varying vec2 vUv1;
|
|
3225
|
+
varying vec3 vViewPosition;
|
|
3226
|
+
varying vec3 vNormal;
|
|
2931
3227
|
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
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";
|
|
2936
3378
|
}
|
|
3379
|
+
}
|
|
2937
3380
|
|
|
2938
|
-
|
|
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
|
+
});
|
|
2939
3599
|
}
|
|
2940
3600
|
|
|
2941
3601
|
class Caller {
|
|
@@ -3442,12 +4102,7 @@ class ResourceManager {
|
|
|
3442
4102
|
this._loaders.set(ext, loader);
|
|
3443
4103
|
}
|
|
3444
4104
|
}
|
|
3445
|
-
loadAsset(
|
|
3446
|
-
var { url, ext, onProgress } = _param, props = _object_without_properties_loose(_param, [
|
|
3447
|
-
"url",
|
|
3448
|
-
"ext",
|
|
3449
|
-
"onProgress"
|
|
3450
|
-
]);
|
|
4105
|
+
loadAsset({ url, ext, onProgress, ...props }) {
|
|
3451
4106
|
return new Promise((resolve, reject)=>{
|
|
3452
4107
|
const info = ResourceManager._parseURL(url);
|
|
3453
4108
|
const texSettings = ResourceManager._splitTextureSettings(props);
|
|
@@ -3497,8 +4152,9 @@ ResourceManager._texSettingKeys = [
|
|
|
3497
4152
|
"minFilter",
|
|
3498
4153
|
"format",
|
|
3499
4154
|
"anisotropy",
|
|
4155
|
+
"repeat",
|
|
3500
4156
|
"colorSpace",
|
|
3501
|
-
"
|
|
4157
|
+
"channel"
|
|
3502
4158
|
];
|
|
3503
4159
|
|
|
3504
4160
|
function applyProps(target, props) {
|
|
@@ -3613,7 +4269,7 @@ class Viewer extends EventEmitter {
|
|
|
3613
4269
|
renderer.render(Viewer.fullscreenMesh, Viewer.fullscreenCamera);
|
|
3614
4270
|
renderer.setRenderTarget(RT);
|
|
3615
4271
|
}
|
|
3616
|
-
static
|
|
4272
|
+
static CreateFullscreenTriangle() {
|
|
3617
4273
|
let geometry = new three.BufferGeometry();
|
|
3618
4274
|
geometry.setAttribute('position', new three.Float32BufferAttribute([
|
|
3619
4275
|
-1,
|
|
@@ -3636,6 +4292,37 @@ class Viewer extends EventEmitter {
|
|
|
3636
4292
|
], 2));
|
|
3637
4293
|
return geometry;
|
|
3638
4294
|
}
|
|
4295
|
+
static GetChildByName(node, name) {
|
|
4296
|
+
return Viewer.GetObject(node, (v)=>v.name === name && v);
|
|
4297
|
+
}
|
|
4298
|
+
static GetObject(node, filter) {
|
|
4299
|
+
const queue = [
|
|
4300
|
+
node
|
|
4301
|
+
];
|
|
4302
|
+
while(queue.length !== 0){
|
|
4303
|
+
let object = queue.shift();
|
|
4304
|
+
let target = filter(object);
|
|
4305
|
+
if (target) {
|
|
4306
|
+
return target;
|
|
4307
|
+
}
|
|
4308
|
+
object.children.forEach((v)=>queue.push(v));
|
|
4309
|
+
}
|
|
4310
|
+
}
|
|
4311
|
+
static GetObjects(node, filter) {
|
|
4312
|
+
const queue = [
|
|
4313
|
+
node
|
|
4314
|
+
];
|
|
4315
|
+
const objects = [];
|
|
4316
|
+
while(queue.length !== 0){
|
|
4317
|
+
let object = queue.shift();
|
|
4318
|
+
let target = filter(object);
|
|
4319
|
+
if (target) {
|
|
4320
|
+
objects.push(object);
|
|
4321
|
+
}
|
|
4322
|
+
object.children.forEach((v)=>queue.push(v));
|
|
4323
|
+
}
|
|
4324
|
+
return objects;
|
|
4325
|
+
}
|
|
3639
4326
|
get root() {
|
|
3640
4327
|
return this._root;
|
|
3641
4328
|
}
|
|
@@ -3805,30 +4492,20 @@ class Viewer extends EventEmitter {
|
|
|
3805
4492
|
addLoader(Loader) {
|
|
3806
4493
|
this._resourceManager.addLoader(Loader);
|
|
3807
4494
|
}
|
|
3808
|
-
load(
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
const node = yield _this.loadAsset({
|
|
3819
|
-
url,
|
|
3820
|
-
ext,
|
|
3821
|
-
onProgress
|
|
4495
|
+
async load({ url, ext, onProgress, castShadow = false, receiveShadow = false, ...props }) {
|
|
4496
|
+
const node = await this.loadAsset({
|
|
4497
|
+
url,
|
|
4498
|
+
ext,
|
|
4499
|
+
onProgress
|
|
4500
|
+
});
|
|
4501
|
+
if (castShadow || receiveShadow) {
|
|
4502
|
+
node.userData.meshData.meshes.forEach((v)=>{
|
|
4503
|
+
v.castShadow = castShadow;
|
|
4504
|
+
v.receiveShadow = receiveShadow;
|
|
3822
4505
|
});
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
v.receiveShadow = receiveShadow;
|
|
3827
|
-
});
|
|
3828
|
-
}
|
|
3829
|
-
_this.addNode(node, props);
|
|
3830
|
-
return node;
|
|
3831
|
-
})();
|
|
4506
|
+
}
|
|
4507
|
+
this.addNode(node, props);
|
|
4508
|
+
return node;
|
|
3832
4509
|
}
|
|
3833
4510
|
tween(target) {
|
|
3834
4511
|
return this._tweenManager.tween(target);
|
|
@@ -3840,16 +4517,12 @@ class Viewer extends EventEmitter {
|
|
|
3840
4517
|
this._tweenManager.killTweensOf(target);
|
|
3841
4518
|
}
|
|
3842
4519
|
traverseMaterials(callback) {
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
if (item.material) {
|
|
4520
|
+
Viewer.GetObjects(this._scene, (item)=>{
|
|
4521
|
+
if (item.isMesh) {
|
|
3846
4522
|
if (Array.isArray(item.material)) item.material.forEach(callback);
|
|
3847
4523
|
else callback(item.material);
|
|
3848
4524
|
}
|
|
3849
|
-
};
|
|
3850
|
-
renderList.opaque.forEach(setMaterial);
|
|
3851
|
-
renderList.transparent.forEach(setMaterial);
|
|
3852
|
-
renderList.transmissive.forEach(setMaterial);
|
|
4525
|
+
});
|
|
3853
4526
|
}
|
|
3854
4527
|
traversePlugins(callback) {
|
|
3855
4528
|
return this._pluginManager.traversePlugins(callback);
|
|
@@ -3877,18 +4550,7 @@ class Viewer extends EventEmitter {
|
|
|
3877
4550
|
removeComponent(node, component) {
|
|
3878
4551
|
return this._componentManager.removeComponent(node, component);
|
|
3879
4552
|
}
|
|
3880
|
-
addNode(object,
|
|
3881
|
-
var { args, debug, scale, position, rotation, shadowArgs, makeDefault, component, parent = this._scene } = _param, props = _object_without_properties_loose(_param, [
|
|
3882
|
-
"args",
|
|
3883
|
-
"debug",
|
|
3884
|
-
"scale",
|
|
3885
|
-
"position",
|
|
3886
|
-
"rotation",
|
|
3887
|
-
"shadowArgs",
|
|
3888
|
-
"makeDefault",
|
|
3889
|
-
"component",
|
|
3890
|
-
"parent"
|
|
3891
|
-
]);
|
|
4553
|
+
addNode(object, { args, debug, scale, position, rotation, shadowArgs, makeDefault, component, parent = this._scene, ...props } = {}) {
|
|
3892
4554
|
let node = null;
|
|
3893
4555
|
let ins = getClassInstance(object, args);
|
|
3894
4556
|
if (ins.isObject3D) {
|
|
@@ -3945,7 +4607,7 @@ class Viewer extends EventEmitter {
|
|
|
3945
4607
|
minFilter: nearest ? three.NearestFilter : mipmap ? three.LinearMipMapLinearFilter : three.LinearFilter,
|
|
3946
4608
|
type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : three.UnsignedByteType : floatType,
|
|
3947
4609
|
anisotropy: 0,
|
|
3948
|
-
colorSpace: three.
|
|
4610
|
+
colorSpace: three.LinearSRGBColorSpace,
|
|
3949
4611
|
depthBuffer: false,
|
|
3950
4612
|
stencilBuffer: false,
|
|
3951
4613
|
samples: SystemInfo.isSupportMSAA ? msaa : 0,
|
|
@@ -3960,7 +4622,7 @@ class Viewer extends EventEmitter {
|
|
|
3960
4622
|
minFilter: nearest ? three.NearestFilter : mipmap ? three.LinearMipMapLinearFilter : three.LinearFilter,
|
|
3961
4623
|
type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : three.UnsignedByteType : floatType,
|
|
3962
4624
|
anisotropy: 0,
|
|
3963
|
-
colorSpace: three.
|
|
4625
|
+
colorSpace: three.LinearSRGBColorSpace,
|
|
3964
4626
|
depthBuffer: false,
|
|
3965
4627
|
stencilBuffer: false,
|
|
3966
4628
|
samples: SystemInfo.isSupportMSAA ? msaa : 0,
|
|
@@ -4013,30 +4675,12 @@ class Viewer extends EventEmitter {
|
|
|
4013
4675
|
Viewer.CompileObject3D(this._renderer, this._scene, this._camera, this._scene);
|
|
4014
4676
|
}
|
|
4015
4677
|
}
|
|
4016
|
-
constructor(
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
}, 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 = {} } = _param, webglOpts = _object_without_properties_loose(_param, [
|
|
4023
|
-
"root",
|
|
4024
|
-
"canvas",
|
|
4025
|
-
"autoStart",
|
|
4026
|
-
"autoResize",
|
|
4027
|
-
"shadows",
|
|
4028
|
-
"camera",
|
|
4029
|
-
"targetFrameRate",
|
|
4030
|
-
"colorSpace",
|
|
4031
|
-
"toneMapping",
|
|
4032
|
-
"toneMappingExposure",
|
|
4033
|
-
"maxDPR",
|
|
4034
|
-
"path",
|
|
4035
|
-
"resourcePath",
|
|
4036
|
-
"dracoPath",
|
|
4037
|
-
"loader",
|
|
4038
|
-
"tasker"
|
|
4039
|
-
]);
|
|
4678
|
+
constructor({ root, canvas, autoStart = true, autoResize = true, shadows = false, camera = {
|
|
4679
|
+
fov: 45,
|
|
4680
|
+
near: 0.1,
|
|
4681
|
+
far: 1000,
|
|
4682
|
+
position: new three.Vector3(0, 0, 4)
|
|
4683
|
+
}, 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 } = {}){
|
|
4040
4684
|
super();
|
|
4041
4685
|
this._dpr = 1;
|
|
4042
4686
|
this._width = 1;
|
|
@@ -4065,7 +4709,7 @@ class Viewer extends EventEmitter {
|
|
|
4065
4709
|
this._DATA_FLOAT_TYPE = webgl.DATA_FLOAT_TYPE;
|
|
4066
4710
|
this._dpr = Math.min(maxDPR, window.devicePixelRatio);
|
|
4067
4711
|
this._scene = new three.Scene();
|
|
4068
|
-
this._camera = new three.PerspectiveCamera();
|
|
4712
|
+
this._camera = applyProps(new three.PerspectiveCamera(), camera);
|
|
4069
4713
|
this._renderer = new three.WebGLRenderer({
|
|
4070
4714
|
canvas: el,
|
|
4071
4715
|
context: webgl.gl
|
|
@@ -4106,23 +4750,455 @@ Viewer._shadowCameraKeys = [
|
|
|
4106
4750
|
"near",
|
|
4107
4751
|
"far"
|
|
4108
4752
|
];
|
|
4109
|
-
Viewer.fullscreenMesh = new three.Mesh(Viewer.
|
|
4753
|
+
Viewer.fullscreenMesh = new three.Mesh(Viewer.CreateFullscreenTriangle());
|
|
4110
4754
|
Viewer.fullscreenCamera = new three.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
4111
4755
|
|
|
4112
|
-
class
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4756
|
+
class MergeRefectPass {
|
|
4757
|
+
get envMapTarget() {
|
|
4758
|
+
return this._envMapTarget;
|
|
4759
|
+
}
|
|
4760
|
+
dispose() {
|
|
4761
|
+
this._envMapTarget.dispose();
|
|
4762
|
+
this._pmremGenerator.dispose();
|
|
4763
|
+
}
|
|
4764
|
+
mergeReflect(info) {
|
|
4765
|
+
this._pmremGenerator._clearTexture(this._envMapTarget, this.envMapIntensity);
|
|
4766
|
+
this._pmremGenerator._mergeReflect(this._envMapTarget, this._reflectMap);
|
|
4767
|
+
info.envMapTarget = this._envMapTarget;
|
|
4768
|
+
info.lodMax = this._pmremGenerator._lodMeshes.length - 1;
|
|
4769
|
+
}
|
|
4770
|
+
_getPMREMExtension(renderer) {
|
|
4771
|
+
const pmremGenerator = new three.PMREMGenerator(renderer);
|
|
4772
|
+
pmremGenerator._fromTextureExtension = function(reflectMap, envMap) {
|
|
4773
|
+
const target = envMap ? this._fromTexture(envMap) : this._fromCubeTexture(reflectMap);
|
|
4774
|
+
this._cubeMapMaterial = _getCubeMapMaterial();
|
|
4775
|
+
this._copyTexMaterial = _getClearMaterial();
|
|
4776
|
+
this._copyMesh = new three.Mesh(Viewer.fullscreenMesh.geometry, this._copyTexMaterial);
|
|
4777
|
+
this._lodMeshes = this._lodPlanes.map((v)=>new three.Mesh(v, this._cubeMapMaterial));
|
|
4778
|
+
this._sourceInit = false;
|
|
4779
|
+
return target;
|
|
4780
|
+
};
|
|
4781
|
+
pmremGenerator._fromCubeTexture = function(texture) {
|
|
4782
|
+
this._setSize(texture.image.length === 0 ? 16 : texture.image[0].width || texture.image[0].image.width);
|
|
4783
|
+
return this._allocateTargets();
|
|
4784
|
+
};
|
|
4785
|
+
pmremGenerator._copyTexture = function(targetOut, texture, intensity = 1) {
|
|
4786
|
+
const uniforms = this._copyTexMaterial.uniforms;
|
|
4787
|
+
uniforms.map.value = texture;
|
|
4788
|
+
uniforms.intensity.value = intensity;
|
|
4789
|
+
const renderer = this._renderer;
|
|
4790
|
+
renderer.autoClear = true;
|
|
4791
|
+
renderer.setRenderTarget(targetOut);
|
|
4792
|
+
renderer.render(this._copyMesh, _flatCamera);
|
|
4793
|
+
renderer.setRenderTarget(null);
|
|
4794
|
+
};
|
|
4795
|
+
pmremGenerator._clearTexture = function(targetOut, intensity) {
|
|
4796
|
+
const source = this._pingPongRenderTarget;
|
|
4797
|
+
if (this._sourceInit === false) {
|
|
4798
|
+
this._sourceInit = true;
|
|
4799
|
+
source.scissorTest = false;
|
|
4800
|
+
_setViewport(source, 0, 0, source.width, source.height);
|
|
4801
|
+
this._copyTexture(source, targetOut.texture);
|
|
4802
|
+
} else {
|
|
4803
|
+
this._copyTexture(targetOut, source.texture, intensity);
|
|
4804
|
+
}
|
|
4805
|
+
};
|
|
4806
|
+
pmremGenerator._mergeReflect = function(sourceTarget, reflectMap, clear = false) {
|
|
4807
|
+
const renderer = this._renderer;
|
|
4808
|
+
const autoClear = renderer.autoClear;
|
|
4809
|
+
const cubeMapMaterial = this._cubeMapMaterial;
|
|
4810
|
+
const uniforms = this._cubeMapMaterial.uniforms;
|
|
4811
|
+
uniforms.envMap.value = reflectMap;
|
|
4812
|
+
renderer.autoClear = clear;
|
|
4813
|
+
for(let i = 0; i < this._lodMeshes.length - 1; i++){
|
|
4814
|
+
uniforms.lod.value = i < 5 ? 0 : i;
|
|
4815
|
+
this._blit(sourceTarget, i, cubeMapMaterial);
|
|
4816
|
+
}
|
|
4817
|
+
sourceTarget.scissorTest = false;
|
|
4818
|
+
_setViewport(sourceTarget, 0, 0, sourceTarget.width, sourceTarget.height);
|
|
4819
|
+
renderer.autoClear = autoClear;
|
|
4820
|
+
};
|
|
4821
|
+
pmremGenerator._blit = function(targetOut, lodOut, material) {
|
|
4822
|
+
const renderer = this._renderer;
|
|
4823
|
+
const _lodMax = this._lodMax;
|
|
4824
|
+
const outputSize = this._sizeLods[lodOut];
|
|
4825
|
+
const x = 3 * outputSize * (lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0);
|
|
4826
|
+
const y = 4 * (this._cubeSize - outputSize);
|
|
4827
|
+
_setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
|
|
4828
|
+
const lodMesh = this._lodMeshes[lodOut];
|
|
4829
|
+
lodMesh.material = material;
|
|
4830
|
+
renderer.autoClear = false;
|
|
4831
|
+
renderer.setRenderTarget(targetOut);
|
|
4832
|
+
renderer.render(lodMesh, _flatCamera);
|
|
4833
|
+
};
|
|
4834
|
+
return pmremGenerator;
|
|
4835
|
+
}
|
|
4836
|
+
constructor({ envMap, reflectMap, viewer }){
|
|
4837
|
+
this.envMapIntensity = 1;
|
|
4838
|
+
this._reflectMap = reflectMap;
|
|
4839
|
+
this._pmremGenerator = this._getPMREMExtension(viewer.renderer);
|
|
4840
|
+
this._envMapTarget = this._pmremGenerator._fromTextureExtension(reflectMap, envMap);
|
|
4841
|
+
viewer.scene.environment = this._envMapTarget.texture;
|
|
4116
4842
|
}
|
|
4117
4843
|
}
|
|
4118
4844
|
|
|
4845
|
+
function mipGaussianBlendWeight(sigma, lod) {
|
|
4846
|
+
let sigma2 = sigma * sigma;
|
|
4847
|
+
let c = 2.0 * Math.PI * sigma2;
|
|
4848
|
+
let numerator = Math.pow(16, lod) * 1.386294361; //log(4)
|
|
4849
|
+
let denorminator = c * (Math.pow(4, lod) + c);
|
|
4850
|
+
return three.MathUtils.clamp(numerator / denorminator, 0, 1);
|
|
4851
|
+
}
|
|
4852
|
+
|
|
4853
|
+
const MAX_LOD = 10;
|
|
4854
|
+
class MergeMipBlurPass {
|
|
4855
|
+
get blurIntensity() {
|
|
4856
|
+
return this._blurIntensity;
|
|
4857
|
+
}
|
|
4858
|
+
set blurIntensity(v) {
|
|
4859
|
+
if (this._blurIntensity !== v) {
|
|
4860
|
+
this._blurIntensity = v;
|
|
4861
|
+
this._sigma = three.MathUtils.lerp(1, 40, this._blurIntensity / 10);
|
|
4862
|
+
for(let lod = 0; lod <= MAX_LOD; lod++){
|
|
4863
|
+
let w = mipGaussianBlendWeight(this._sigma, lod);
|
|
4864
|
+
if (w < 0.002) {
|
|
4865
|
+
this._blurMinLod = lod;
|
|
4866
|
+
}
|
|
4867
|
+
if (w >= 1) {
|
|
4868
|
+
this._blurMaxLod = lod;
|
|
4869
|
+
break;
|
|
4870
|
+
}
|
|
4871
|
+
}
|
|
4872
|
+
}
|
|
4873
|
+
}
|
|
4874
|
+
get envMapTarget() {
|
|
4875
|
+
return this._envMapTarget;
|
|
4876
|
+
}
|
|
4877
|
+
dispose() {
|
|
4878
|
+
this._envMapTarget.dispose();
|
|
4879
|
+
this._pmremGenerator.dispose();
|
|
4880
|
+
}
|
|
4881
|
+
mergeMipBlur(info) {
|
|
4882
|
+
const targetIn = this._pmremGenerator._applyMipBlur(this._envMapTarget, this._reflectMap, this._blurMinLod, this._blurMaxLod, this._sigma, this.exposure);
|
|
4883
|
+
this._pmremGenerator._mipCopy(info.envMapTarget, targetIn, info.lodMax, this._blurMinLod);
|
|
4884
|
+
}
|
|
4885
|
+
_getPMREMExtension(renderer) {
|
|
4886
|
+
const pmremGenerator = new three.PMREMGenerator(renderer);
|
|
4887
|
+
pmremGenerator._fromTextureExtension = function(texture) {
|
|
4888
|
+
this._setSize(texture.image.length === 0 ? 16 : texture.image[0].width || texture.image[0].image.width);
|
|
4889
|
+
const target = this._allocateTargets();
|
|
4890
|
+
this._mipBlurMaterial = _getMipBlurMaterial(this._lodMax, target.width, target.height);
|
|
4891
|
+
this._mipCopyMaterial = _getMipCopyMaterial(this._lodMax, target.width, target.height);
|
|
4892
|
+
this._lodMeshes = this._lodPlanes.map((v)=>new three.Mesh(v, this._mipBlurMaterial));
|
|
4893
|
+
return target;
|
|
4894
|
+
};
|
|
4895
|
+
pmremGenerator._applyMipBlur = function(sourceTarget, texture, blurMinLod, blurMaxLod, sigma, exposure) {
|
|
4896
|
+
const pingPongRenderTarget = this._pingPongRenderTarget;
|
|
4897
|
+
const uniforms = this._mipBlurMaterial.uniforms;
|
|
4898
|
+
uniforms.envMap.value = texture;
|
|
4899
|
+
uniforms.exposure.value = exposure;
|
|
4900
|
+
let lod = blurMaxLod;
|
|
4901
|
+
let targetOut = sourceTarget;
|
|
4902
|
+
let targetIn = pingPongRenderTarget;
|
|
4903
|
+
this._mipBlur(sourceTarget, pingPongRenderTarget, lod, 1);
|
|
4904
|
+
for(let i = 0; lod-- > blurMinLod; i++){
|
|
4905
|
+
targetOut = (i & 1) === 0 ? pingPongRenderTarget : sourceTarget;
|
|
4906
|
+
targetIn = (i & 1) === 1 ? pingPongRenderTarget : sourceTarget;
|
|
4907
|
+
this._mipBlur(targetOut, targetIn, lod, mipGaussianBlendWeight(sigma, lod));
|
|
4908
|
+
}
|
|
4909
|
+
sourceTarget.scissorTest = false;
|
|
4910
|
+
_setViewport(sourceTarget, 0, 0, sourceTarget.width, sourceTarget.height);
|
|
4911
|
+
return targetOut;
|
|
4912
|
+
};
|
|
4913
|
+
pmremGenerator._mipBlur = function(targetOut, targetIn, lodOut, weight) {
|
|
4914
|
+
const uniforms = this._mipBlurMaterial.uniforms;
|
|
4915
|
+
uniforms.cubeUVMap.value = targetIn.texture;
|
|
4916
|
+
uniforms.weight.value = weight;
|
|
4917
|
+
uniforms.lod.value = lodOut;
|
|
4918
|
+
this._blit(targetOut, lodOut, this._mipBlurMaterial);
|
|
4919
|
+
};
|
|
4920
|
+
pmremGenerator._mipCopy = function(targetOut, targetIn, lodOut, lodIn = lodOut) {
|
|
4921
|
+
const uniforms = this._mipCopyMaterial.uniforms;
|
|
4922
|
+
uniforms.cubeUVMap.value = targetIn.texture;
|
|
4923
|
+
uniforms.lod.value = lodIn;
|
|
4924
|
+
this._blit(targetOut, lodOut, this._mipCopyMaterial);
|
|
4925
|
+
targetOut.scissorTest = false;
|
|
4926
|
+
_setViewport(targetOut, 0, 0, targetOut.width, targetOut.height);
|
|
4927
|
+
};
|
|
4928
|
+
pmremGenerator._blit = function(targetOut, lodOut, material) {
|
|
4929
|
+
const renderer = this._renderer;
|
|
4930
|
+
const _lodMax = this._lodMax;
|
|
4931
|
+
const outputSize = this._sizeLods[lodOut];
|
|
4932
|
+
const x = 3 * outputSize * (lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0);
|
|
4933
|
+
const y = 4 * (this._cubeSize - outputSize);
|
|
4934
|
+
_setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
|
|
4935
|
+
const lodMesh = this._lodMeshes[lodOut];
|
|
4936
|
+
lodMesh.material = material;
|
|
4937
|
+
renderer.autoClear = false;
|
|
4938
|
+
renderer.setRenderTarget(targetOut);
|
|
4939
|
+
renderer.render(lodMesh, _flatCamera);
|
|
4940
|
+
};
|
|
4941
|
+
return pmremGenerator;
|
|
4942
|
+
}
|
|
4943
|
+
constructor({ viewer, reflectMap }){
|
|
4944
|
+
this._sigma = 2;
|
|
4945
|
+
this._blurMinLod = 0;
|
|
4946
|
+
this._blurMaxLod = MAX_LOD;
|
|
4947
|
+
this._blurIntensity = -1;
|
|
4948
|
+
this.exposure = 1;
|
|
4949
|
+
this._reflectMap = reflectMap;
|
|
4950
|
+
this._pmremGenerator = this._getPMREMExtension(viewer.renderer);
|
|
4951
|
+
this._envMapTarget = this._pmremGenerator._fromTextureExtension(reflectMap);
|
|
4952
|
+
}
|
|
4953
|
+
}
|
|
4954
|
+
|
|
4955
|
+
class EnvironmentPlugin extends Plugin {
|
|
4956
|
+
get debug() {
|
|
4957
|
+
return this._debug;
|
|
4958
|
+
}
|
|
4959
|
+
set debug(v) {
|
|
4960
|
+
if (this._debug !== v) {
|
|
4961
|
+
this._debug = v;
|
|
4962
|
+
if (v) {
|
|
4963
|
+
if (this._debugNode === null) {
|
|
4964
|
+
const viewer = this.viewer;
|
|
4965
|
+
const debugScene = DebugPlugin.Instance(viewer).scene;
|
|
4966
|
+
this._debugNode = viewer.addNode(three.Object3D, {
|
|
4967
|
+
parent: debugScene
|
|
4968
|
+
});
|
|
4969
|
+
viewer.addNode(Plane, {
|
|
4970
|
+
parent: this._debugNode,
|
|
4971
|
+
material: new three.MeshBasicMaterial({
|
|
4972
|
+
map: this._reflectPass.envMapTarget.texture
|
|
4973
|
+
}),
|
|
4974
|
+
position: new three.Vector3(1.1, 3, 0)
|
|
4975
|
+
});
|
|
4976
|
+
viewer.addNode(Plane, {
|
|
4977
|
+
parent: this._debugNode,
|
|
4978
|
+
material: new three.MeshBasicMaterial({
|
|
4979
|
+
map: this._mipBlurPass.envMapTarget.texture
|
|
4980
|
+
}),
|
|
4981
|
+
position: new three.Vector3(0, 3, 0)
|
|
4982
|
+
});
|
|
4983
|
+
}
|
|
4984
|
+
}
|
|
4985
|
+
if (this._debugNode) {
|
|
4986
|
+
this._debugNode.visible = v;
|
|
4987
|
+
}
|
|
4988
|
+
}
|
|
4989
|
+
}
|
|
4990
|
+
onRender() {
|
|
4991
|
+
const { renderer } = this.viewer;
|
|
4992
|
+
const autoClear = renderer.autoClear;
|
|
4993
|
+
const oldTarget = renderer.getRenderTarget();
|
|
4994
|
+
const oldActiveCubeFace = renderer.getActiveCubeFace();
|
|
4995
|
+
const oldActiveMipmapLevel = renderer.getActiveMipmapLevel();
|
|
4996
|
+
this._reflectPass.envMapIntensity = this.envMapIntensity;
|
|
4997
|
+
this._mipBlurPass.exposure = this.reflectExposure;
|
|
4998
|
+
this._mipBlurPass.blurIntensity = this.reflectBlurIntensity;
|
|
4999
|
+
this._cubeCamera.update(renderer, this._scene);
|
|
5000
|
+
this._reflectPass.mergeReflect(this._mergeInfo);
|
|
5001
|
+
this._mipBlurPass.mergeMipBlur(this._mergeInfo);
|
|
5002
|
+
renderer.autoClear = autoClear;
|
|
5003
|
+
renderer.setRenderTarget(oldTarget, oldActiveCubeFace, oldActiveMipmapLevel);
|
|
5004
|
+
}
|
|
5005
|
+
constructor({ envMap, scene, near, far, layer = 0, resolution = 256, floatType = three.HalfFloatType, position = new three.Vector3(0, 1, 0) } = {}){
|
|
5006
|
+
super();
|
|
5007
|
+
this._mergeInfo = {
|
|
5008
|
+
envMapTarget: null,
|
|
5009
|
+
lodMax: 0
|
|
5010
|
+
};
|
|
5011
|
+
this._debug = false;
|
|
5012
|
+
this._debugNode = null;
|
|
5013
|
+
this.envMapIntensity = 1;
|
|
5014
|
+
this.reflectExposure = 1;
|
|
5015
|
+
this.reflectBlurIntensity = 5;
|
|
5016
|
+
this.install = ()=>{
|
|
5017
|
+
const viewer = this.viewer;
|
|
5018
|
+
this._scene = scene || viewer.scene;
|
|
5019
|
+
const cubeRenderTarget = viewer.createCubeRenderTarget(resolution, false, floatType, 0, true);
|
|
5020
|
+
this._cubeCamera = new three.CubeCamera(near || viewer.camera.near, far || viewer.camera.far, cubeRenderTarget);
|
|
5021
|
+
this._cubeCamera.position.copy(position);
|
|
5022
|
+
this._cubeCamera.layers.set(layer);
|
|
5023
|
+
const reflectMap = cubeRenderTarget.texture;
|
|
5024
|
+
this._reflectPass = new MergeRefectPass({
|
|
5025
|
+
viewer,
|
|
5026
|
+
reflectMap,
|
|
5027
|
+
envMap
|
|
5028
|
+
});
|
|
5029
|
+
this._mipBlurPass = new MergeMipBlurPass({
|
|
5030
|
+
viewer,
|
|
5031
|
+
reflectMap
|
|
5032
|
+
});
|
|
5033
|
+
};
|
|
5034
|
+
this.uninstall = ()=>{
|
|
5035
|
+
this._reflectPass.dispose();
|
|
5036
|
+
this._mipBlurPass.dispose();
|
|
5037
|
+
};
|
|
5038
|
+
}
|
|
5039
|
+
}
|
|
5040
|
+
__decorate([
|
|
5041
|
+
property
|
|
5042
|
+
], EnvironmentPlugin.prototype, "debug", null);
|
|
5043
|
+
__decorate([
|
|
5044
|
+
property({
|
|
5045
|
+
min: 0,
|
|
5046
|
+
max: 1,
|
|
5047
|
+
step: 0.01
|
|
5048
|
+
})
|
|
5049
|
+
], EnvironmentPlugin.prototype, "envMapIntensity", void 0);
|
|
5050
|
+
__decorate([
|
|
5051
|
+
property({
|
|
5052
|
+
min: 0,
|
|
5053
|
+
max: 10,
|
|
5054
|
+
step: 0.01
|
|
5055
|
+
})
|
|
5056
|
+
], EnvironmentPlugin.prototype, "reflectExposure", void 0);
|
|
5057
|
+
__decorate([
|
|
5058
|
+
property({
|
|
5059
|
+
min: 0,
|
|
5060
|
+
max: 10,
|
|
5061
|
+
step: 0.1
|
|
5062
|
+
})
|
|
5063
|
+
], EnvironmentPlugin.prototype, "reflectBlurIntensity", void 0);
|
|
5064
|
+
|
|
5065
|
+
class BoxProjectionPlugin extends Plugin {
|
|
5066
|
+
get debug() {
|
|
5067
|
+
return this._debug;
|
|
5068
|
+
}
|
|
5069
|
+
set debug(v) {
|
|
5070
|
+
if (this._debug !== v) {
|
|
5071
|
+
this._debug = v;
|
|
5072
|
+
if (v) {
|
|
5073
|
+
if (this._helper === null) {
|
|
5074
|
+
this._helper = new three.Box3Helper(new three.Box3(this._boxMin, this._boxMax));
|
|
5075
|
+
DebugPlugin.Instance(this.viewer).add(this._helper);
|
|
5076
|
+
}
|
|
5077
|
+
}
|
|
5078
|
+
if (this._helper) {
|
|
5079
|
+
this._helper.visible = v;
|
|
5080
|
+
}
|
|
5081
|
+
}
|
|
5082
|
+
}
|
|
5083
|
+
get center() {
|
|
5084
|
+
return this._center;
|
|
5085
|
+
}
|
|
5086
|
+
set center(v) {
|
|
5087
|
+
this._center.copy(v);
|
|
5088
|
+
}
|
|
5089
|
+
get boxMin() {
|
|
5090
|
+
return this._boxMin;
|
|
5091
|
+
}
|
|
5092
|
+
set boxMin(v) {
|
|
5093
|
+
this._boxMin.copy(v);
|
|
5094
|
+
}
|
|
5095
|
+
get boxMax() {
|
|
5096
|
+
return this._boxMax;
|
|
5097
|
+
}
|
|
5098
|
+
set boxMax(v) {
|
|
5099
|
+
this._boxMax.copy(v);
|
|
5100
|
+
}
|
|
5101
|
+
onUpdate(dt) {
|
|
5102
|
+
if (this._debug) {
|
|
5103
|
+
this._helper.updateMatrixWorld();
|
|
5104
|
+
}
|
|
5105
|
+
}
|
|
5106
|
+
useBoxProjection(shader) {
|
|
5107
|
+
shader.defines.USE_BOX_PROJECTION = true;
|
|
5108
|
+
shader.uniforms.probePos = {
|
|
5109
|
+
value: this._center
|
|
5110
|
+
};
|
|
5111
|
+
shader.uniforms.probeBoxMin = {
|
|
5112
|
+
value: this._boxMin
|
|
5113
|
+
};
|
|
5114
|
+
shader.uniforms.probeBoxMax = {
|
|
5115
|
+
value: this._boxMax
|
|
5116
|
+
};
|
|
5117
|
+
}
|
|
5118
|
+
constructor(){
|
|
5119
|
+
super();
|
|
5120
|
+
this._center = new three.Vector4(0, 0.5, 0, 1);
|
|
5121
|
+
this._boxMin = new three.Vector3(0, 0, 0);
|
|
5122
|
+
this._boxMax = new three.Vector3(1, 1, 1);
|
|
5123
|
+
this._helper = null;
|
|
5124
|
+
this._debug = false;
|
|
5125
|
+
this.install = ()=>{
|
|
5126
|
+
three.ShaderLib.physical.vertexShader = three.ShaderLib.physical.vertexShader.replace(/#ifdef USE_TRANSMISSION/g, `
|
|
5127
|
+
#if defined(USE_TRANSMISSION) || defined(USE_BOX_PROJECTION)
|
|
5128
|
+
`);
|
|
5129
|
+
three.ShaderLib.physical.fragmentShader = three.ShaderLib.physical.fragmentShader.replace("varying vec3 vViewPosition;", `
|
|
5130
|
+
varying vec3 vViewPosition;
|
|
5131
|
+
#if defined(USE_BOX_PROJECTION)
|
|
5132
|
+
varying vec3 vWorldPosition;
|
|
5133
|
+
#endif
|
|
5134
|
+
`);
|
|
5135
|
+
three.ShaderChunk.worldpos_vertex = three.ShaderChunk.worldpos_vertex.replace("#if defined( USE_ENVMAP )", "#if defined( USE_ENVMAP ) || defined( USE_BOX_PROJECTION )");
|
|
5136
|
+
three.ShaderChunk.envmap_physical_pars_fragment = three.ShaderChunk.envmap_physical_pars_fragment.replace("#ifdef USE_ENVMAP", `
|
|
5137
|
+
#ifdef USE_ENVMAP
|
|
5138
|
+
|
|
5139
|
+
#if defined(USE_BOX_PROJECTION)
|
|
5140
|
+
uniform vec4 probePos;
|
|
5141
|
+
uniform vec3 probeBoxMin;
|
|
5142
|
+
uniform vec3 probeBoxMax;
|
|
5143
|
+
|
|
5144
|
+
vec3 boxProjection(vec3 nrdir, vec3 worldPos, vec3 probePos, vec3 boxMin, vec3 boxMax) {
|
|
5145
|
+
vec3 tbot = boxMin - worldPos;
|
|
5146
|
+
vec3 ttop = boxMax - worldPos;
|
|
5147
|
+
vec3 tmax = mix(tbot, ttop, step(vec3(0), nrdir));
|
|
5148
|
+
tmax /= nrdir;
|
|
5149
|
+
float t = min(min(tmax.x, tmax.y), tmax.z);
|
|
5150
|
+
return worldPos + nrdir * t - probePos;
|
|
5151
|
+
}
|
|
5152
|
+
#endif
|
|
5153
|
+
|
|
5154
|
+
`).replace("reflectVec = inverseTransformDirection( reflectVec, viewMatrix );", `
|
|
5155
|
+
reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
|
|
5156
|
+
|
|
5157
|
+
#if defined(USE_BOX_PROJECTION)
|
|
5158
|
+
if (probePos.w > 0.001) {
|
|
5159
|
+
reflectVec = boxProjection(reflectVec, vWorldPosition, probePos.xyz, probeBoxMin.xyz, probeBoxMax.xyz);
|
|
5160
|
+
}
|
|
5161
|
+
#endif
|
|
5162
|
+
|
|
5163
|
+
`).replace("vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );", `
|
|
5164
|
+
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
|
|
5165
|
+
|
|
5166
|
+
#if defined(USE_BOX_PROJECTION)
|
|
5167
|
+
if (probePos.w > 0.001) {
|
|
5168
|
+
worldNormal = boxProjection(worldNormal, vWorldPosition, probePos.xyz, probeBoxMin.xyz, probeBoxMax.xyz);
|
|
5169
|
+
}
|
|
5170
|
+
#endif
|
|
5171
|
+
|
|
5172
|
+
`);
|
|
5173
|
+
};
|
|
5174
|
+
this.uninstall = ()=>{
|
|
5175
|
+
DebugPlugin.Instance(this.viewer).remove(this._helper);
|
|
5176
|
+
};
|
|
5177
|
+
}
|
|
5178
|
+
}
|
|
5179
|
+
__decorate([
|
|
5180
|
+
property
|
|
5181
|
+
], BoxProjectionPlugin.prototype, "debug", null);
|
|
5182
|
+
__decorate([
|
|
5183
|
+
property
|
|
5184
|
+
], BoxProjectionPlugin.prototype, "center", null);
|
|
5185
|
+
__decorate([
|
|
5186
|
+
property
|
|
5187
|
+
], BoxProjectionPlugin.prototype, "boxMin", null);
|
|
5188
|
+
__decorate([
|
|
5189
|
+
property
|
|
5190
|
+
], BoxProjectionPlugin.prototype, "boxMax", null);
|
|
5191
|
+
|
|
4119
5192
|
exports.AnimationCurve = AnimationCurve;
|
|
4120
5193
|
exports.Box = Box;
|
|
5194
|
+
exports.BoxProjectionPlugin = BoxProjectionPlugin;
|
|
4121
5195
|
exports.CinestationBlendDefinition = CinestationBlendDefinition;
|
|
4122
5196
|
exports.CinestationBrain = CinestationBrain;
|
|
4123
5197
|
exports.Component = Component;
|
|
5198
|
+
exports.DebugPlugin = DebugPlugin;
|
|
4124
5199
|
exports.DeviceInput = DeviceInput;
|
|
4125
5200
|
exports.Easing = Easing;
|
|
5201
|
+
exports.EnvironmentPlugin = EnvironmentPlugin;
|
|
4126
5202
|
exports.EventEmitter = EventEmitter;
|
|
4127
5203
|
exports.FInterpConstantTo = FInterpConstantTo;
|
|
4128
5204
|
exports.FInterpTo = FInterpTo;
|
|
@@ -4140,6 +5216,8 @@ exports.Quat_Equals = Quat_Equals;
|
|
|
4140
5216
|
exports.Quat_exponentialDamp = Quat_exponentialDamp;
|
|
4141
5217
|
exports.Quat_quarticDamp = Quat_quarticDamp;
|
|
4142
5218
|
exports.Quat_smoothDamp = Quat_smoothDamp;
|
|
5219
|
+
exports.Reflector = Reflector;
|
|
5220
|
+
exports.ReflectorMaterial = ReflectorMaterial;
|
|
4143
5221
|
exports.Sphere = Sphere;
|
|
4144
5222
|
exports.SystemInfo = SystemInfo;
|
|
4145
5223
|
exports.Tween = Tween;
|
|
@@ -4163,11 +5241,17 @@ exports.aFBXLoader = aFBXLoader;
|
|
|
4163
5241
|
exports.aGLTFLoader = aGLTFLoader;
|
|
4164
5242
|
exports.aHDRLoader = aHDRLoader;
|
|
4165
5243
|
exports.aJSONLoader = aJSONLoader;
|
|
5244
|
+
exports.aLoader = aLoader;
|
|
4166
5245
|
exports.aTextureLoader = aTextureLoader;
|
|
4167
5246
|
exports.exponentialDamp = exponentialDamp;
|
|
5247
|
+
exports.frag_BoxfilterBlur = frag_BoxfilterBlur;
|
|
5248
|
+
exports.frag_cubeMapToPanorama = frag_cubeMapToPanorama;
|
|
5249
|
+
exports.frag_panoramaToCubeMap = frag_panoramaToCubeMap;
|
|
4168
5250
|
exports.getClassInstance = getClassInstance;
|
|
5251
|
+
exports.getShaderMaterial = getShaderMaterial;
|
|
4169
5252
|
exports.mixin = mixin;
|
|
4170
5253
|
exports.property = property;
|
|
4171
5254
|
exports.quarticDamp = quarticDamp;
|
|
4172
5255
|
exports.smoothDamp = smoothDamp;
|
|
5256
|
+
exports.vert_fullscreen = vert_fullscreen;
|
|
4173
5257
|
//# sourceMappingURL=main.js.map
|