@konfigure/sdk 0.2.1 → 0.3.0
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/README.md +54 -1
- package/dist/chunk-4KQN5AVT.js +782 -0
- package/dist/chunk-EBEY7ID3.js +1 -0
- package/dist/chunk-HFOEVYNK.js +4 -0
- package/dist/chunk-XR6EHOK2.js +482 -0
- package/dist/client-B2yVMro3.d.ts +80 -0
- package/dist/{configurator-6ISAZiAx.d.ts → configurator-CnGR3YDW.d.ts} +1 -1
- package/dist/index.d.ts +5 -57
- package/dist/index.js +1 -4
- package/dist/showroom.d.ts +145 -0
- package/dist/showroom.js +171 -0
- package/dist/{src-GJ5RXX7G.js → src-SHLZZCVA.js} +6 -6
- package/dist/view.d.ts +1 -1
- package/dist/view.js +3 -785
- package/package.json +5 -1
- package/dist/chunk-ARGXORCF.js +0 -1
- package/dist/chunk-OOVVLYAY.js +0 -482
|
@@ -0,0 +1,782 @@
|
|
|
1
|
+
import {k,c,d,e as e$1,j,i,g,h}from'./chunk-EBEY7ID3.js';import {f,e,a as a$1}from'./chunk-XR6EHOK2.js';import {a}from'./chunk-XUSV3KOD.js';import {Vector3,Color,Scene,BoxGeometry,MeshStandardMaterial,BackSide,PointLight,Mesh,MeshBasicMaterial,Matrix4,Matrix3,Vector2,Vector4,Box3,TextureLoader,MeshDepthMaterial,ShaderMaterial,AmbientLight,DirectionalLight,CubeUVReflectionMapping,Euler,UniformsUtils,UniformsLib,PlaneGeometry,BufferGeometry,BufferAttribute,InstancedMesh,NeutralToneMapping,ACESFilmicToneMapping,ShaderChunk,PerspectiveCamera,WebGLRenderer,SRGBColorSpace,NoToneMapping,HalfFloatType,UnsignedByteType,WebGLRenderTarget,DoubleSide,FloatType,DataTexture,RGBAFormat,EquirectangularReflectionMapping,LinearFilter,ClampToEdgeWrapping,OrthographicCamera,CustomToneMapping,Group,AnimationMixer,Quaternion,QuaternionKeyframeTrack,Object3D,MeshPhysicalMaterial,RepeatWrapping,LinearMipmapLinearFilter,NoColorSpace,NearestFilter,Fog,PMREMGenerator,ShadowMaterial,SpotLight,RectAreaLight,WebGLCubeRenderTarget,CubeCamera,LinearToneMapping}from'three';import {FullScreenQuad}from'three/addons/postprocessing/Pass.js';import {OrbitControls}from'three/addons/controls/OrbitControls.js';import {RGBELoader}from'three/addons/loaders/RGBELoader.js';import {OutputPass}from'three/addons/postprocessing/OutputPass.js';import {GLTFLoader}from'three/addons/loaders/GLTFLoader.js';import {DRACOLoader}from'three/examples/jsm/loaders/DRACOLoader.js';import*as Ia from'three/examples/jsm/utils/BufferGeometryUtils.js';function mt(e){return e instanceof Mesh}a(mt,"isMesh");var Mr=.5;function Et(e){let o=Array.isArray(e)?e:[e];return o.length>0&&o.every(t=>t.transparent&&t.opacity<Mr||(t.transmission??0)>Mr)}a(Et,"isSeeThrough");var wi=new Set(["room","floor","moduleContactShadow","bakedFloorShadow","selectionIndicator"]);function lo(e){return e instanceof Mesh&&!wi.has(e.name)&&!e.name.startsWith("wall")&&!e.userData.isCollider}a(lo,"isModuleMesh");function Bt(e,o){e.traverse(t=>{lo(t)&&o(t);});}a(Bt,"forEachModuleMesh");function He(e,o=true,t=false){e.traverse(r=>{r instanceof Mesh&&(r.castShadow=o&&!Et(r.material),r.receiveShadow=t);});}a(He,"setShadows");var ye={blur:.5,blurPasses:[1,.75,.5,.25],blurResolution:256,darkness:1.2,falloff:2,opacity:.5,cameraHeight:.12,contactHeight:.05,contactOpacity:1,groundOffset:4e-4},po=1;function Te(e){po=Math.min(1,Math.max(0,e));}a(Te,"setContactShadowFade");function je(){return po}a(je,"getContactShadowFade");var fo=0;function xe(e){fo=Math.min(1,Math.max(0,e));}a(xe,"setContactShadowCoverage");function qe(){return fo}a(qe,"getContactShadowCoverage");var kt,Lt,Pe;function Ti(){return Pe||(Pe=new MeshDepthMaterial,Pe.userData.darkness={value:ye.darkness},Pe.userData.falloff={value:ye.falloff},Pe.userData.contactReach={value:ye.contactHeight/ye.cameraHeight},Pe.onBeforeCompile=function(e){Pe&&(e.uniforms.darkness=Pe.userData.darkness,e.uniforms.falloff=Pe.userData.falloff,e.uniforms.contactReach=Pe.userData.contactReach,e.fragmentShader=`
|
|
2
|
+
uniform float darkness;
|
|
3
|
+
uniform float falloff;
|
|
4
|
+
uniform float contactReach;
|
|
5
|
+
${e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );",`float shadow = pow(1.0 - fragCoordZ, falloff) * darkness;
|
|
6
|
+
float contact = pow(clamp(1.0 - fragCoordZ / contactReach, 0.0, 1.0), falloff) * darkness;
|
|
7
|
+
gl_FragColor = vec4(contact, 0.0, 0.0, shadow);`)}
|
|
8
|
+
`);},Pe.depthTest=true,Pe.depthWrite=true),Pe}a(Ti,"getDepthMaterial");function Di(){return kt||(kt=new ShaderMaterial({uniforms:{tDiffuse:{value:null},h:{value:1/ye.blurResolution}},vertexShader:`
|
|
9
|
+
varying vec2 vUv;
|
|
10
|
+
void main() {
|
|
11
|
+
vUv = uv;
|
|
12
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
13
|
+
}
|
|
14
|
+
`,fragmentShader:`
|
|
15
|
+
uniform sampler2D tDiffuse;
|
|
16
|
+
uniform float h;
|
|
17
|
+
varying vec2 vUv;
|
|
18
|
+
void main() {
|
|
19
|
+
float alphaSum = 0.0;
|
|
20
|
+
float contactSum = 0.0;
|
|
21
|
+
float weights[9];
|
|
22
|
+
weights[0] = 0.051; weights[1] = 0.0918; weights[2] = 0.12245;
|
|
23
|
+
weights[3] = 0.1531; weights[4] = 0.1633; weights[5] = 0.1531;
|
|
24
|
+
weights[6] = 0.12245; weights[7] = 0.0918; weights[8] = 0.051;
|
|
25
|
+
for (int i = -4; i <= 4; i++) {
|
|
26
|
+
vec4 s = texture2D(tDiffuse, vec2(vUv.x + float(i) * h, vUv.y));
|
|
27
|
+
alphaSum += s.a * weights[i + 4];
|
|
28
|
+
contactSum += s.r * weights[i + 4];
|
|
29
|
+
}
|
|
30
|
+
gl_FragColor = vec4(contactSum, 0.0, 0.0, alphaSum);
|
|
31
|
+
}
|
|
32
|
+
`}),kt.depthTest=false),Lt||(Lt=new ShaderMaterial({uniforms:{tDiffuse:{value:null},v:{value:1/ye.blurResolution}},vertexShader:`
|
|
33
|
+
varying vec2 vUv;
|
|
34
|
+
void main() {
|
|
35
|
+
vUv = uv;
|
|
36
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
37
|
+
}
|
|
38
|
+
`,fragmentShader:`
|
|
39
|
+
uniform sampler2D tDiffuse;
|
|
40
|
+
uniform float v;
|
|
41
|
+
varying vec2 vUv;
|
|
42
|
+
void main() {
|
|
43
|
+
float alphaSum = 0.0;
|
|
44
|
+
float contactSum = 0.0;
|
|
45
|
+
float weights[9];
|
|
46
|
+
weights[0] = 0.051; weights[1] = 0.0918; weights[2] = 0.12245;
|
|
47
|
+
weights[3] = 0.1531; weights[4] = 0.1633; weights[5] = 0.1531;
|
|
48
|
+
weights[6] = 0.12245; weights[7] = 0.0918; weights[8] = 0.051;
|
|
49
|
+
for (int i = -4; i <= 4; i++) {
|
|
50
|
+
vec4 s = texture2D(tDiffuse, vec2(vUv.x, vUv.y + float(i) * v));
|
|
51
|
+
alphaSum += s.a * weights[i + 4];
|
|
52
|
+
contactSum += s.r * weights[i + 4];
|
|
53
|
+
}
|
|
54
|
+
gl_FragColor = vec4(contactSum, 0.0, 0.0, alphaSum);
|
|
55
|
+
}
|
|
56
|
+
`}),Lt.depthTest=false),{horizontal:kt,vertical:Lt}}a(Di,"getBlurMaterials");var mo=new Map,ke=new Vector3,Ai=new Color;function Ri(e,o,t){let{horizontal:r,vertical:a}=Di();e.blurPlane.visible=true,e.blurPlane.material=r,r.uniforms.tDiffuse&&r.uniforms.h&&(r.uniforms.tDiffuse.value=e.renderTarget.texture,r.uniforms.h.value=o/ye.blurResolution),t.setRenderTarget(e.renderTargetBlur),t.render(e.blurPlane,e.shadowCamera),e.blurPlane.material=a,a.uniforms.tDiffuse&&a.uniforms.v&&(a.uniforms.tDiffuse.value=e.renderTargetBlur.texture,a.uniforms.v.value=o/ye.blurResolution),t.setRenderTarget(e.renderTarget),t.render(e.blurPlane,e.shadowCamera),e.blurPlane.visible=false;}a(Ri,"blurShadow");function Tr(e,o){e.moduleGroup.updateMatrixWorld(),e.moduleGroup.getWorldPosition(ke);let t=!ke.equals(e.lastPosition);t&&e.lastPosition.copy(ke);let r=null,a=e.moduleGroup.parent;for(;a;){if(a instanceof Scene){r=a;break}a=a.parent;}if(r&&!e.shadowPlane.parent&&(r.add(e.shadowPlane),r.add(e.blurPlane)),e.shadowPlane.position.set(ke.x,ye.groundOffset,ke.z),e.blurPlane.position.set(ke.x,ye.groundOffset,ke.z),!e.moduleGroup.visible){e.shadowPlane.visible=false;return}if(e.shadowPlane.visible=true,Dr(e),!e.needsUpdate&&!t)return;e.needsUpdate=false;let i=e.size/2;e.shadowCamera.position.set(ke.x,0,ke.z),e.shadowCamera.rotation.x=Math.PI/2,e.shadowCamera.left=-i,e.shadowCamera.right=i,e.shadowCamera.top=i,e.shadowCamera.bottom=-i,e.shadowCamera.updateProjectionMatrix(),e.shadowCamera.updateMatrixWorld(true),e.shadowPlane.visible=false;let s=Ti(),l=new Scene;e.moduleGroup.traverse(u=>{if(u instanceof Mesh&&u.name!=="moduleContactShadow"){let d=new Mesh(u.geometry,s);u.updateWorldMatrix(true,false),d.matrix.copy(u.matrixWorld),d.matrixAutoUpdate=false,l.add(d);}});let c=o.getClearColor(Ai),f=o.getClearAlpha();o.setClearColor(0,0),o.setRenderTarget(e.renderTarget),o.clear(true,true,true),o.render(l,e.shadowCamera);for(let u of ye.blurPasses)Ri(e,ye.blur*u,o);o.setRenderTarget(null),o.setClearColor(c,f),e.shadowPlane.visible=true;}a(Tr,"renderModuleContactShadow");function Dr(e){if(!(e.shadowPlane.material instanceof ShaderMaterial))return;let{opacity:o,contactOpacity:t,coverage:r}=e.shadowPlane.material.uniforms,a=po*(e.shadowPlane.userData.fade??1);o&&(o.value=ye.opacity*a),t&&(t.value=ye.contactOpacity*a),r&&(r.value=fo);}a(Dr,"applyFadeAndCoverage");function rt(){for(let e of mo.values())Dr(e);}a(rt,"refreshContactShadows");function Xe(e){for(let o of mo.values())Tr(o,e);}a(Xe,"renderAllModuleContactShadows");function ho(){for(let e of mo.values())e.needsUpdate=true;}a(ho,"markAllShadowsForUpdate");var Ar={topLight:{intensity:500,position:[.418,16.199,.3]},room:{position:[-0.757,13.219,.717],scale:[31.713,28.305,28.591]},boxes:[{position:[-10.906,2.009,1.846],rotation:-0.195,scale:[2.328,7.905,4.651]},{position:[-5.607,-0.754,-0.758],rotation:.994,scale:[1.97,1.534,3.955]},{position:[6.167,.857,7.803],rotation:.561,scale:[3.927,6.285,3.687]},{position:[-2.017,.018,6.124],rotation:.333,scale:[2.002,4.566,2.064]},{position:[2.291,-0.756,-2.621],rotation:-0.286,scale:[1.546,1.552,1.496]},{position:[-2.193,-0.369,-5.547],rotation:.516,scale:[3.875,3.487,2.986]}],lights:[{intensity:50,position:[-16.116,14.37,8.208],scale:[.1,2.428,2.739]},{intensity:50,position:[-16.109,18.021,-8.207],scale:[.1,2.425,2.751]},{intensity:17,position:[14.904,12.198,-1.832],scale:[.15,4.265,6.331]},{intensity:43,position:[-0.462,8.89,14.52],scale:[4.38,5.441,.088]},{intensity:20,position:[3.235,11.486,-12.541],scale:[2.5,2,.1]},{intensity:100,position:[0,20,0],scale:[1,.1,1]}]};var Rr={topLight:{intensity:400,position:[.5,14,.5]},room:{position:[0,13.2,0],scale:[31.5,28.5,31.5]},boxes:[{position:[-10.906,-1,1.846],rotation:-0.195,scale:[2.328,7.905,4.651]},{position:[-5.607,-0.754,-0.758],rotation:.994,scale:[1.97,1.534,3.955]},{position:[6.167,-0.16,7.803],rotation:.561,scale:[3.927,6.285,3.687]},{position:[-2.017,.018,6.124],rotation:.333,scale:[2.002,4.566,2.064]},{position:[2.291,-0.756,-2.621],rotation:-0.286,scale:[1.546,1.552,1.496]},{position:[-2.193,-0.369,-5.547],rotation:.516,scale:[3.875,3.487,2.986]}],lights:[{intensity:80,position:[-14,5,8],scale:[.1,2.5,2.5]},{intensity:80,position:[-14,7,-4],scale:[.1,2.5,2.5]},{intensity:23,position:[14,6,0],scale:[.1,5,5]},{intensity:16,position:[0,4.5,14],scale:[5,5,.1]},{intensity:80,position:[7,4,-14],scale:[2.5,2.5,.1]},{intensity:80,position:[-7,8,-14],scale:[2.5,2.5,.1]},{intensity:80,position:[0,7,0],scale:[.3,.3,.3]}]};var Or={hdri:"/hdri/potsdamer_platz_1k.hdr",topLight:{intensity:75.4,color:"#ffffff",position:[0,12.5,0]},room:{color:"#dcdde1",position:[0,13.2,0],scale:[31.5,28.5,31.5]},boxes:[{position:[-12.5,-1.5,-3],rotation:-0.35,scale:[3,6,4]},{position:[11.5,-1.5,-5],rotation:.42,scale:[3.5,5.5,3.5]}],lights:[{intensity:.9,position:[0,4,13.5],scale:[18,13,.1]},{intensity:8.1,position:[-7,7,12.5],scale:[12,10,.1]},{intensity:9.3,position:[-10.5,6.5,11.5],scale:[6,6,.1]},{intensity:6.4,position:[10.5,5,11.5],scale:[5.5,5,.1]},{intensity:7.5,position:[-14,5,0],scale:[.1,6,9]},{intensity:7.5,position:[14,5,0],scale:[.1,6,9]},{intensity:4.6,position:[0,-5,9],scale:[10,2.5,.1]}]};var Ir={topLight:{intensity:150,color:"#fff5e6",position:[.5,14,.5]},room:{color:"#f5ebe0",position:[0,13.2,0],scale:[31.5,28.5,31.5]},boxes:[{position:[-10.906,-1,1.846],rotation:-0.195,scale:[2.328,7.905,4.651]},{position:[6.167,-0.16,7.803],rotation:.561,scale:[3.927,6.285,3.687]}],lights:[{intensity:45,position:[0,6,14],scale:[8,7,.1]},{intensity:40,position:[-14,5,0],scale:[.1,6,8]},{intensity:40,position:[14,5,0],scale:[.1,6,8]},{intensity:30,position:[4,5,-14],scale:[4,5,.1]},{intensity:30,position:[-4,5,-14],scale:[4,5,.1]},{intensity:25,position:[0,8,0],scale:[.5,.3,.5]}]};var Oi={legacy:Ar,neutral:Rr,surround:Ir,studio:Or};function _t(e){return Oi[e]}a(_t,"getEnvironmentData");var $e=class extends Scene{static{a(this,"EnvironmentScene");}constructor(o){super(),this.position.y=-3.5;let t=new BoxGeometry;t.deleteAttribute("uv");let r=new MeshStandardMaterial({metalness:0,side:BackSide}),a=new MeshStandardMaterial({metalness:0}),i=_t(o);i.room.color&&(r.color=new Color(i.room.color),a.color=new Color(i.room.color));let s=i.topLight.color?new Color(i.topLight.color):new Color(16777215),l=new PointLight(s,i.topLight.intensity,28,2);l.position.set(...i.topLight.position),this.add(l);let c=new Mesh(t,r);c.position.set(...i.room.position),c.scale.set(...i.room.scale),this.add(c);for(let f of i.boxes){let u=new Mesh(t,a);u.position.set(...f.position),u.rotation.set(0,f.rotation,0),u.scale.set(...f.scale),this.add(u);}for(let f of i.lights){let u=new Mesh(t,_i(f.intensity));u.position.set(...f.position),u.scale.set(...f.scale),this.add(u);}}};function _i(e){let o=new MeshBasicMaterial;return o.color.setScalar(e),o}a(_i,"createAreaLightMaterial");var zi=/swiftshader|llvmpipe|softpipe|lavapipe|software|basic render/i;function Fi(e){return zi.test(e)}a(Fi,"isSoftwareRendererName");function Gi(e){let o=e.getContext(),t=o.getExtension("WEBGL_debug_renderer_info");return String(o.getParameter(t?t.UNMASKED_RENDERER_WEBGL:o.RENDERER)??"")}a(Gi,"rendererName");function Ft(e){return Fi(Gi(e))}a(Ft,"isSoftwareRenderer");var nt=4,xo=16,ji=.3,qi=.35,Xi=.8,ht=`
|
|
57
|
+
varying vec2 vUv;
|
|
58
|
+
void main() {
|
|
59
|
+
vUv = uv;
|
|
60
|
+
gl_Position = vec4(position.xy, 0.0, 1.0);
|
|
61
|
+
}
|
|
62
|
+
`;function Lr(){return {bvh:{value:new e},previous:{value:null},envMap:{value:null},envMapRotation:{value:new Matrix3},envIntensity:{value:0},ambient:{value:0},sampleOffset:{value:0},samples:{value:4},rowStart:{value:0},rowEnd:{value:0},lampCount:{value:0},lampA:{value:Array.from({length:nt},()=>new Vector4)},lampB:{value:Array.from({length:nt},()=>new Vector4)},productAlbedo:{value:qi},floorAlbedo:{value:Xi}}}a(Lr,"traceUniforms");var _r=`
|
|
63
|
+
#include <common>
|
|
64
|
+
#include <cube_uv_reflection_fragment>
|
|
65
|
+
${f.common_functions}
|
|
66
|
+
${f.bvh_struct_definitions}
|
|
67
|
+
${f.bvh_ray_functions}
|
|
68
|
+
|
|
69
|
+
uniform BVH bvh;
|
|
70
|
+
uniform sampler2D previous;
|
|
71
|
+
uniform sampler2D envMap;
|
|
72
|
+
uniform mat3 envMapRotation;
|
|
73
|
+
uniform float envIntensity;
|
|
74
|
+
uniform float ambient;
|
|
75
|
+
uniform int sampleOffset;
|
|
76
|
+
uniform int samples;
|
|
77
|
+
// The rows this pass traces; the rest are carried over as they were. A
|
|
78
|
+
// pass over everything can take longer than a frame on a large scene.
|
|
79
|
+
uniform int rowStart;
|
|
80
|
+
uniform int rowEnd;
|
|
81
|
+
uniform int lampCount;
|
|
82
|
+
// xyz: the lamp's position (point) or the direction towards it
|
|
83
|
+
// (directional); w: 0 point, 1 directional.
|
|
84
|
+
uniform vec4 lampA[${nt}];
|
|
85
|
+
// x: intensity, y: decay, z: disc radius (m) or cone half-angle (rad).
|
|
86
|
+
uniform vec4 lampB[${nt}];
|
|
87
|
+
uniform float productAlbedo;
|
|
88
|
+
uniform float floorAlbedo;
|
|
89
|
+
varying vec2 vUv;
|
|
90
|
+
|
|
91
|
+
uvec2 pcg2d(uvec2 v) {
|
|
92
|
+
v = v * 1664525u + 1013904223u;
|
|
93
|
+
v.x += v.y * 1664525u;
|
|
94
|
+
v.y += v.x * 1664525u;
|
|
95
|
+
v = v ^ (v >> 16u);
|
|
96
|
+
v.x += v.y * 1664525u;
|
|
97
|
+
v.y += v.x * 1664525u;
|
|
98
|
+
v = v ^ (v >> 16u);
|
|
99
|
+
return v;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
vec2 texelRandom(uint salt) {
|
|
103
|
+
return vec2(pcg2d(uvec2(gl_FragCoord.xy) + uvec2(salt, salt * 7u))) / 4294967295.0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Every point walks the same low-discrepancy sequence (R2) from its own
|
|
107
|
+
// random offset: evenly spread samples for each point, and no pattern
|
|
108
|
+
// shared between neighbours for the eye to pick up.
|
|
109
|
+
vec2 r2(vec2 offset, float n) {
|
|
110
|
+
return fract(offset + n * vec2(0.7548776662466927, 0.5698402909980532));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Any direction perpendicular to n, and the third one that completes the frame.
|
|
114
|
+
void basis(vec3 n, out vec3 t, out vec3 b) {
|
|
115
|
+
t = normalize(abs(n.y) < 0.99 ? cross(n, vec3(0.0, 1.0, 0.0)) : cross(n, vec3(1.0, 0.0, 0.0)));
|
|
116
|
+
b = cross(n, t);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
bool hit(vec3 origin, vec3 direction, float maxDistance, out vec3 normal) {
|
|
120
|
+
uvec4 faceIndices = uvec4(0u);
|
|
121
|
+
vec3 faceNormal = vec3(0.0, 1.0, 0.0);
|
|
122
|
+
vec3 barycoord = vec3(0.0);
|
|
123
|
+
float side = 1.0;
|
|
124
|
+
float dist = 0.0;
|
|
125
|
+
bool found = bvhIntersectFirstHit(
|
|
126
|
+
bvh, origin, direction, faceIndices, faceNormal, barycoord, side, dist
|
|
127
|
+
);
|
|
128
|
+
// Turned to face the ray's origin by the intersection itself.
|
|
129
|
+
normal = faceNormal;
|
|
130
|
+
return found && dist < maxDistance;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// The sky's radiance, as irradiance per cosine-weighted sample: the ambient
|
|
134
|
+
// light is uniform, the environment is read the way a fully rough material
|
|
135
|
+
// would read it.
|
|
136
|
+
float sky(vec3 direction) {
|
|
137
|
+
vec3 env = textureCubeUV(envMap, envMapRotation * direction, 1.0).rgb;
|
|
138
|
+
return ambient + envIntensity * PI * dot(env, vec3(0.2126, 0.7152, 0.0722));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// This pass's samples at one point: (sky arrived, sky open, lamp arrived, lamp open).
|
|
142
|
+
vec4 gather(vec3 origin, vec3 normal) {
|
|
143
|
+
vec3 t;
|
|
144
|
+
vec3 b;
|
|
145
|
+
basis(normal, t, b);
|
|
146
|
+
vec2 skyOffset = texelRandom(1u);
|
|
147
|
+
vec2 lampOffset = texelRandom(2u);
|
|
148
|
+
vec4 sums = vec4(0.0);
|
|
149
|
+
|
|
150
|
+
for (int i = 0; i < ${xo}; i++) {
|
|
151
|
+
if (i >= samples) break;
|
|
152
|
+
float n = float(sampleOffset + i);
|
|
153
|
+
|
|
154
|
+
vec2 u = r2(skyOffset, n);
|
|
155
|
+
float r = sqrt(u.x);
|
|
156
|
+
float phi = 2.0 * PI * u.y;
|
|
157
|
+
vec3 direction = normalize(
|
|
158
|
+
t * (r * cos(phi)) + normal * sqrt(max(0.0, 1.0 - u.x)) + b * (r * sin(phi))
|
|
159
|
+
);
|
|
160
|
+
float light = sky(direction);
|
|
161
|
+
sums.y += light;
|
|
162
|
+
vec3 surface;
|
|
163
|
+
if (hit(origin, direction, 1e20, surface)) {
|
|
164
|
+
// Light the product sends back: what its surface receives, which is
|
|
165
|
+
// the open sky on a face turned up and the floor's own bounce on a
|
|
166
|
+
// face turned down.
|
|
167
|
+
float up = 0.5 + 0.5 * surface.y;
|
|
168
|
+
sums.x += productAlbedo * light * mix(floorAlbedo, 1.0, up);
|
|
169
|
+
} else {
|
|
170
|
+
sums.x += light;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
vec2 v = r2(lampOffset, n);
|
|
174
|
+
for (int l = 0; l < ${nt}; l++) {
|
|
175
|
+
if (l >= lampCount) break;
|
|
176
|
+
vec4 a = lampA[l];
|
|
177
|
+
vec4 c = lampB[l];
|
|
178
|
+
vec3 toLamp;
|
|
179
|
+
float reach;
|
|
180
|
+
float irradiance;
|
|
181
|
+
vec3 lt;
|
|
182
|
+
vec3 lb;
|
|
183
|
+
if (a.w < 0.5) {
|
|
184
|
+
vec3 axis = normalize(a.xyz - origin);
|
|
185
|
+
basis(axis, lt, lb);
|
|
186
|
+
float radius = c.z * sqrt(v.x);
|
|
187
|
+
float angle = 2.0 * PI * v.y;
|
|
188
|
+
vec3 target = a.xyz + (lt * cos(angle) + lb * sin(angle)) * radius;
|
|
189
|
+
toLamp = target - origin;
|
|
190
|
+
reach = length(toLamp);
|
|
191
|
+
toLamp /= reach;
|
|
192
|
+
irradiance = c.x / max(pow(reach, c.y), 0.01);
|
|
193
|
+
} else {
|
|
194
|
+
vec3 axis = normalize(a.xyz);
|
|
195
|
+
basis(axis, lt, lb);
|
|
196
|
+
float cosTheta = 1.0 - v.x * (1.0 - cos(c.z));
|
|
197
|
+
float sinTheta = sqrt(max(0.0, 1.0 - cosTheta * cosTheta));
|
|
198
|
+
float angle = 2.0 * PI * v.y;
|
|
199
|
+
toLamp = axis * cosTheta + (lt * cos(angle) + lb * sin(angle)) * sinTheta;
|
|
200
|
+
reach = 1e20;
|
|
201
|
+
irradiance = c.x;
|
|
202
|
+
}
|
|
203
|
+
float incoming = irradiance * max(dot(normal, toLamp), 0.0);
|
|
204
|
+
if (incoming <= 0.0) continue;
|
|
205
|
+
sums.w += incoming;
|
|
206
|
+
if (!hit(origin, toLamp, reach, surface)) sums.z += incoming;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return sums;
|
|
210
|
+
}
|
|
211
|
+
`;function zr(){return new ShaderMaterial({defines:{ENVMAP_TYPE_CUBE_UV:""},uniforms:{...Lr(),rect:{value:new Vector4},floorY:{value:0}},vertexShader:ht,fragmentShader:`
|
|
212
|
+
${_r}
|
|
213
|
+
uniform vec4 rect;
|
|
214
|
+
uniform float floorY;
|
|
215
|
+
void main() {
|
|
216
|
+
int row = int(gl_FragCoord.y);
|
|
217
|
+
if (row < rowStart || row >= rowEnd) {
|
|
218
|
+
gl_FragColor = texture2D(previous, vUv);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
// A millimetre up, so a ray leaving the floor does not start inside a
|
|
222
|
+
// foot resting on it.
|
|
223
|
+
vec3 origin = vec3(rect.x + vUv.x * rect.z, floorY + 0.001, rect.y + vUv.y * rect.w);
|
|
224
|
+
gl_FragColor = texture2D(previous, vUv) + gather(origin, vec3(0.0, 1.0, 0.0));
|
|
225
|
+
}
|
|
226
|
+
`})}a(zr,"createFloorTraceMaterial");function Fr(){return new ShaderMaterial({defines:{ENVMAP_TYPE_CUBE_UV:""},uniforms:{...Lr(),vertexPositions:{value:null},vertexNormals:{value:null}},vertexShader:ht,fragmentShader:`
|
|
227
|
+
${_r}
|
|
228
|
+
uniform sampler2D vertexPositions;
|
|
229
|
+
uniform sampler2D vertexNormals;
|
|
230
|
+
void main() {
|
|
231
|
+
ivec2 texel = ivec2(gl_FragCoord.xy);
|
|
232
|
+
vec4 accumulated = texelFetch(previous, texel, 0);
|
|
233
|
+
if (texel.y < rowStart || texel.y >= rowEnd) {
|
|
234
|
+
gl_FragColor = accumulated;
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
vec3 normal = texelFetch(vertexNormals, texel, 0).xyz;
|
|
238
|
+
// Padding, or a part without normals: left fully lit.
|
|
239
|
+
if (dot(normal, normal) < 0.5) {
|
|
240
|
+
gl_FragColor = accumulated + vec4(float(samples));
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
// Two millimetres off the surface: past the curvature of the
|
|
244
|
+
// neighbouring triangles, still well inside any seam worth shading.
|
|
245
|
+
vec3 origin = texelFetch(vertexPositions, texel, 0).xyz + normal * 0.002;
|
|
246
|
+
gl_FragColor = accumulated + gather(origin, normal);
|
|
247
|
+
}
|
|
248
|
+
`})}a(Fr,"createVertexTraceMaterial");function Gr(){return new ShaderMaterial({uniforms:{accumulated:{value:null}},vertexShader:ht,fragmentShader:`
|
|
249
|
+
uniform sampler2D accumulated;
|
|
250
|
+
void main() {
|
|
251
|
+
vec4 sums = texelFetch(accumulated, ivec2(gl_FragCoord.xy), 0);
|
|
252
|
+
float sky = sums.y > 0.0 ? clamp(sums.x / sums.y, 0.0, 1.0) : 1.0;
|
|
253
|
+
float lamp = sums.w > 0.0 ? clamp(sums.z / sums.w, 0.0, 1.0) : 1.0;
|
|
254
|
+
gl_FragColor = vec4(1.0 - sky, 1.0 - lamp, 128.0 / 255.0, 0.0);
|
|
255
|
+
}
|
|
256
|
+
`})}a(Gr,"createVertexResolveMaterial");var Gt=new Color;function $i(e){return Gt.copy(e),.2126*Gt.r+.7152*Gt.g+.0722*Gt.b}a($i,"luminance");function Yi(e,o){let t=0,r=[];return e.traverseVisible(a=>{if(!(a instanceof AmbientLight||a instanceof PointLight||a instanceof DirectionalLight)||a.intensity<=0||!a.layers.isEnabled(0))return;let i=a.intensity*$i(a.color);if(a instanceof AmbientLight){t+=i;return}if(r.length>=nt)return;let s=a.getWorldPosition(new Vector3);if(a instanceof PointLight){let l=Math.max(s.y-o,.1);r.push({a:new Vector4(s.x,s.y,s.z,0),b:new Vector4(i,a.decay,l*ji,0)});}else {let l=a.target.getWorldPosition(new Vector3);r.push({a:new Vector4(s.x-l.x,s.y-l.y,s.z-l.z,1),b:new Vector4(i,0,.05,0)});}}),{ambient:t,lamps:r}}a(Yi,"gatherLights");function Wr(e){let o=[e.environment?.id??0,e.environmentIntensity];return e.traverseVisible(t=>{(t instanceof AmbientLight||t instanceof PointLight||t instanceof DirectionalLight)&&o.push(t.id,t.intensity,...t.position.toArray());}),o.join(",")}a(Wr,"lightingSignature");function So(e,o,t){let r=e.uniforms,a=o.environment,i=a?.mapping===CubeUVReflectionMapping?a:null,{ambient:s,lamps:l}=Yi(o,t);r.ambient.value=s,r.envMap.value=i,r.envIntensity.value=i?o.environmentIntensity:0;let c=i?i.image.height:256,f=Math.log2(c)-2,u=e.defines,d=String(1/(3*Math.max(2**f,112)));u.CUBEUV_TEXEL_WIDTH!==d&&(u.CUBEUV_TEXEL_WIDTH=d,u.CUBEUV_TEXEL_HEIGHT=String(1/c),u.CUBEUV_MAX_MIP=`${f}.0`,e.needsUpdate=true);let M=new Euler().copy(o.environmentRotation);M.x*=-1,M.y*=-1,M.z*=-1,r.envMapRotation.value.setFromMatrix4(new Matrix4().makeRotationFromEuler(M)),r.lampCount.value=l.length,l.forEach((v,m)=>{r.lampA.value[m].copy(v.a),r.lampB.value[m].copy(v.b);});}a(So,"setTraceLighting");var ts=96,os=1024;function Nr(e,o){let[t,,r,a,i,s]=e,l=Math.max(i-o,.1),c=Math.min(Math.max(.5+l*.8,.75),3),f=a-t+c*2,u=s-r+c*2,d=Math.min(ts,os/Math.max(f,u));return {rect:new Vector4(t-c,r-c,f,u),size:[Math.max(16,Math.round(f*d)),Math.max(16,Math.round(u*d))]}}a(Nr,"floorRect");function Vr(){return new ShaderMaterial({uniforms:{accumulated:{value:null},texel:{value:new Vector2}},vertexShader:ht,fragmentShader:`
|
|
257
|
+
uniform sampler2D accumulated;
|
|
258
|
+
uniform vec2 texel;
|
|
259
|
+
varying vec2 vUv;
|
|
260
|
+
|
|
261
|
+
// All the light that arrives over all that would: the floor is lit by
|
|
262
|
+
// the sky and the lamps together, and darkened by what is missing of both.
|
|
263
|
+
float ratio(vec2 uv) {
|
|
264
|
+
vec4 sums = texture2D(accumulated, uv);
|
|
265
|
+
float open = sums.y + sums.w;
|
|
266
|
+
return open > 0.0 ? clamp((sums.x + sums.z) / open, 0.0, 1.0) : 1.0;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// A 5x5 binomial blur: what noise is left after a full bake is per
|
|
270
|
+
// texel, and the shadow itself is soft at this scale everywhere but
|
|
271
|
+
// right at a foot, where a texel is under a centimetre anyway.
|
|
272
|
+
void main() {
|
|
273
|
+
float weights[5] = float[5](1.0, 4.0, 6.0, 4.0, 1.0);
|
|
274
|
+
float sum = 0.0;
|
|
275
|
+
for (int y = 0; y < 5; y++) {
|
|
276
|
+
for (int x = 0; x < 5; x++) {
|
|
277
|
+
sum += weights[x] * weights[y] * ratio(vUv + vec2(float(x - 2), float(y - 2)) * texel);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
gl_FragColor = vec4(sum / 256.0, 0.0, 0.0, 1.0);
|
|
281
|
+
}
|
|
282
|
+
`})}a(Vr,"createFloorResolveMaterial");function Hr(){let e=new ShaderMaterial({uniforms:{map:{value:null},rect:{value:new Vector4},opacity:{value:0},previousMap:{value:null},previousRect:{value:new Vector4},crossfade:{value:1},...UniformsUtils.clone(UniformsLib.fog)},vertexShader:`
|
|
283
|
+
varying vec2 vFloor;
|
|
284
|
+
varying float vFogDepth;
|
|
285
|
+
void main() {
|
|
286
|
+
vec4 world = modelMatrix * vec4(position, 1.0);
|
|
287
|
+
vFloor = world.xz;
|
|
288
|
+
vec4 view = viewMatrix * world;
|
|
289
|
+
vFogDepth = -view.z;
|
|
290
|
+
gl_Position = projectionMatrix * view;
|
|
291
|
+
}
|
|
292
|
+
`,fragmentShader:`
|
|
293
|
+
uniform sampler2D map;
|
|
294
|
+
uniform vec4 rect;
|
|
295
|
+
uniform sampler2D previousMap;
|
|
296
|
+
uniform vec4 previousRect;
|
|
297
|
+
uniform float crossfade;
|
|
298
|
+
uniform float opacity;
|
|
299
|
+
uniform float fogNear;
|
|
300
|
+
uniform float fogFar;
|
|
301
|
+
varying vec2 vFloor;
|
|
302
|
+
varying float vFogDepth;
|
|
303
|
+
|
|
304
|
+
float encode(float linear) {
|
|
305
|
+
return linear <= 0.0031308 ? linear * 12.92 : 1.055 * pow(linear, 1.0 / 2.4) - 0.055;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// The light one map leaves on this point of the floor, 1 = unshadowed.
|
|
309
|
+
float lightFrom(sampler2D m, vec4 r) {
|
|
310
|
+
if (r.z <= 0.0) return 1.0;
|
|
311
|
+
vec2 uv = (vFloor - r.xy) / r.zw;
|
|
312
|
+
// The map covers a finite patch; its last few percent ease out so the
|
|
313
|
+
// patch never shows an edge.
|
|
314
|
+
vec2 edge = smoothstep(0.0, 0.06, uv) * smoothstep(0.0, 0.06, 1.0 - uv);
|
|
315
|
+
return 1.0 - (1.0 - texture2D(m, uv).r) * edge.x * edge.y;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
void main() {
|
|
319
|
+
float light = crossfade >= 1.0
|
|
320
|
+
? lightFrom(map, rect)
|
|
321
|
+
: mix(lightFrom(previousMap, previousRect), lightFrom(map, rect), crossfade);
|
|
322
|
+
// Fogged like the floor it lies on. The plane draws darkness, not a
|
|
323
|
+
// colour, so fog takes the darkness away rather than tinting it \u2014 and
|
|
324
|
+
// without it a scene dissolving into fog left its shadows standing on
|
|
325
|
+
// a floor that had already gone.
|
|
326
|
+
float fogged = fogFar > fogNear ? smoothstep(fogNear, fogFar, vFogDepth) : 0.0;
|
|
327
|
+
float kept = 1.0 - (1.0 - light) * opacity * (1.0 - fogged);
|
|
328
|
+
// The canvas blends in sRGB, after encoding. Black at alpha a keeps
|
|
329
|
+
// (1 - a) of the ENCODED floor, so the alpha that keeps that share of
|
|
330
|
+
// its light is 1 - encode(kept), not 1 - kept, which would shadow
|
|
331
|
+
// about twice as dark as traced.
|
|
332
|
+
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0 - encode(kept));
|
|
333
|
+
}
|
|
334
|
+
`,transparent:true,fog:true,depthWrite:false,polygonOffset:true,polygonOffsetFactor:-1,polygonOffsetUnits:-1}),o=new Mesh(new PlaneGeometry(1,1).rotateX(-Math.PI/2),e);return o.name="bakedFloorShadow",o.renderOrder=1,o.visible=false,o.matrixAutoUpdate=false,{plane:o,material:e}}a(Hr,"createFloorPlane");var Le=1024;function $r(e,o){let t=0,r=0;for(let v of e.parts){let m=o.get(v.key);if(!m)continue;let w=v.matrices.length/16,h=m.positions.length/3;t+=h*w,r+=(m.index?.length??h)*w;}let a=new Float32Array(t*3),i=new Uint32Array(r),s=[1/0,1/0,1/0,-1/0,-1/0,-1/0],l=0,c=0;for(let v of e.parts){let m=o.get(v.key);if(!m)continue;let w=m.positions,h=w.length/3;for(let S=0;S<v.matrices.length/16;S++){let g=v.matrices.subarray(S*16,S*16+16);for(let D=0;D<h;D++){let O=w[D*3],L=w[D*3+1],y=w[D*3+2],A=g[0]*O+g[4]*L+g[8]*y+g[12],k=g[1]*O+g[5]*L+g[9]*y+g[13],I=g[2]*O+g[6]*L+g[10]*y+g[14],U=(l+D)*3;a[U]=A,a[U+1]=k,a[U+2]=I,A<s[0]&&(s[0]=A),k<s[1]&&(s[1]=k),I<s[2]&&(s[2]=I),A>s[3]&&(s[3]=A),k>s[4]&&(s[4]=k),I>s[5]&&(s[5]=I);}if(m.index){for(let D=0;D<m.index.length;D++)i[c+D]=m.index[D]+l;c+=m.index.length;}else {for(let D=0;D<h;D++)i[c+D]=l+D;c+=h;}l+=h;}}let f=is(e,o),u=new BufferGeometry;u.setAttribute("position",new BufferAttribute(a,3)),u.setIndex(new BufferAttribute(i,1));let d=new a$1(u,{strategy:0,maxLeafSize:8}),M=a$1.serialize(d,{cloneBuffers:false});return {id:e.id,positions:a,index:M.index,roots:M.roots,bounds:s,triangles:r/3,...f}}a($r,"buildOccluders");var jr=new Matrix4,qr=new Matrix3;function is(e,o){let t=0;for(let l of e.parts){let c=o.get(l.key);l.vertices&&c&&(t+=c.positions.length/3);}let r=Math.max(1,Math.ceil(t/Le)),a=new Float32Array(r*Le*4),i=new Float32Array(r*Le*4),s=0;for(let l of e.parts){let c=o.get(l.key);if(!l.vertices||!c)continue;let f=jr.fromArray(l.matrices).elements;qr.getNormalMatrix(jr);let u=qr.elements,{positions:d,normals:M}=c,v=d.length/3;for(let m=0;m<v;m++){let w=d[m*3],h=d[m*3+1],S=d[m*3+2],g=(s+m)*4;if(a[g]=f[0]*w+f[4]*h+f[8]*S+f[12],a[g+1]=f[1]*w+f[5]*h+f[9]*S+f[13],a[g+2]=f[2]*w+f[6]*h+f[10]*S+f[14],a[g+3]=1,!M)continue;let D=M[m*3],O=M[m*3+1],L=M[m*3+2],y=u[0]*D+u[3]*O+u[6]*L,A=u[1]*D+u[4]*O+u[7]*L,k=u[2]*D+u[5]*O+u[8]*L,I=Math.hypot(y,A,k)||1;i[g]=y/I,i[g+1]=A/I,i[g+2]=k/I;}s+=v;}return {vertexPositions:a,vertexNormals:i,vertexCount:t}}a(is,"bakedVertices");function Yr(e){let o=new BufferGeometry;o.setAttribute("position",new BufferAttribute(e.positions,3)),o.setIndex(new BufferAttribute(e.index,1));let t={version:1,roots:e.roots,index:e.index,indirectBuffer:null};return a$1.deserialize(t,o,{setIndex:false})}a(Yr,"occluderBVH");var Ge="bakedShade",Kr=128,Mo=new WeakMap,Ut=new WeakMap,Po=new Set;function Ze(e){return Mo.get(e)??e}a(Ze,"sourceGeometry");function Qr(e){let o=e.geometry;if(Mo.has(o)&&Ut.get(o)===e)return o;let t=Ze(o),r=t.attributes.position;if(!r)return o;let a$1=new BufferGeometry;a$1.name=t.name,a$1.index=t.index;for(let[s,l]of Object.entries(t.attributes))s!==Ge&&(a$1.attributes[s]=l);a$1.morphAttributes=t.morphAttributes,a$1.morphTargetsRelative=t.morphTargetsRelative,a$1.groups=t.groups,a$1.drawRange=t.drawRange,a$1.boundingBox=t.boundingBox,a$1.boundingSphere=t.boundingSphere,a$1.userData=t.userData,Object.defineProperty(a$1,"boundsTree",{configurable:true,get:a(()=>t.boundsTree,"get"),set:a(s=>{t.boundsTree=s;},"set")});let i=new Uint8Array(r.count*4);for(let s=0;s<r.count;s++)i[s*4+2]=Kr;return a$1.setAttribute(Ge,new BufferAttribute(i,4,true)),Mo.set(a$1,t),Ut.set(a$1,e),Po.add(a$1),e.geometry=a$1,a$1}a(Qr,"wrapGeometry");function en(e,o,t){let r=e.geometry.getAttribute(Ge);if(!(r instanceof BufferAttribute)||Ut.get(e.geometry)!==e)return;let a=r.array;a.set(o.subarray(t*4,t*4+a.length)),r.needsUpdate=true;}a(en,"writeShade");function cs(e,o){for(let t=e;t;t=t.parent)if(t===o)return true;return false}a(cs,"isAttached");function tn(e){for(let o of Po){let t=Ut.get(o);if(t&&t.geometry===o&&cs(t,e))continue;t&&t.geometry===o&&(t.geometry=Ze(o));let r=o.attributes[Ge];o.attributes=r?{[Ge]:r}:{},o.index=null,o.morphAttributes={},o.dispose(),Po.delete(o);}}a(tn,"releaseWrappers");var be={value:new Vector2(0,0)},us={value:1},Zr=new WeakSet;function on(e){if(Zr.has(e)||!("isMeshStandardMaterial"in e))return;Zr.add(e);let o=e.onBeforeCompile.bind(e),t=e.customProgramCacheKey.bind(e);e.onBeforeCompile=(r,a)=>{o(r,a),r.uniforms.bakedShadeStrength=be,r.uniforms.bakedShadeDirectScale=us,r.vertexShader=r.vertexShader.replace("#include <common>",`#include <common>
|
|
335
|
+
attribute vec4 ${Ge};
|
|
336
|
+
varying vec2 vBakedShade;`).replace("#include <begin_vertex>",`#include <begin_vertex>
|
|
337
|
+
vBakedShade = abs(${Ge}.z - ${Kr}.0 / 255.0) < 0.002
|
|
338
|
+
? ${Ge}.xy
|
|
339
|
+
: vec2(0.0);`),r.fragmentShader=r.fragmentShader.replace("#include <common>",`#include <common>
|
|
340
|
+
uniform vec2 bakedShadeStrength;
|
|
341
|
+
uniform float bakedShadeDirectScale;
|
|
342
|
+
varying vec2 vBakedShade;`).replace("#include <aomap_fragment>",`#include <aomap_fragment>
|
|
343
|
+
{
|
|
344
|
+
vec2 kept = 1.0 - vBakedShade * bakedShadeStrength * vec2(1.0, bakedShadeDirectScale);
|
|
345
|
+
reflectedLight.indirectDiffuse *= kept.x;
|
|
346
|
+
// Reflections are occluded too, but less: a glossy surface in a
|
|
347
|
+
// crease still shows a highlight from the open side.
|
|
348
|
+
reflectedLight.indirectSpecular *= mix(1.0, kept.x, 0.5);
|
|
349
|
+
reflectedLight.directDiffuse *= kept.y;
|
|
350
|
+
reflectedLight.directSpecular *= kept.y;
|
|
351
|
+
#ifdef USE_SHEEN
|
|
352
|
+
sheenSpecularIndirect *= kept.x;
|
|
353
|
+
sheenSpecularDirect *= kept.y;
|
|
354
|
+
#endif
|
|
355
|
+
#ifdef USE_CLEARCOAT
|
|
356
|
+
clearcoatSpecularIndirect *= mix(1.0, kept.x, 0.5);
|
|
357
|
+
clearcoatSpecularDirect *= kept.y;
|
|
358
|
+
#endif
|
|
359
|
+
}`);},e.customProgramCacheKey=()=>`${t()}|bakedShade`,e.needsUpdate=true;}a(on,"patchMaterial");function ps(e){return (Array.isArray(e)?e:[e]).some(t=>t.visible&&t.colorWrite)}a(ps,"drawsSomething");function Nt(e){let o=[];return e.traverseVisible(t=>{lo(t)&&ps(t.material)&&!Et(t.material)&&o.push(t);}),o}a(Nt,"visibleModuleMeshes");function sn(e){let o=2166136261;function t(r){o=Math.imul(o^(r|0),16777619);}a(t,"mix");for(let r of e){let a=Ze(r.geometry);t(r.id),t(a.id);let i=a.attributes.position;t(i&&"version"in i?i.version:0);for(let s of r.matrixWorld.elements)t(Math.round(s*1e4));r instanceof InstancedMesh&&(t(r.count),t(r.instanceMatrix.version));}return t(e.length),o>>>0}a(sn,"occluderSignature");function fs(e){let o=Ze(e.geometry),t=o.attributes.position,r=t&&"version"in t?t.version:0;return `${o.uuid}:${r}:${o.index?.version??-1}`}a(fs,"shapeKey");function rn(e){if(!e)return null;if(e instanceof BufferAttribute&&e.array instanceof Float32Array&&e.itemSize===3&&!e.normalized)return e.array;let o=new Float32Array(e.count*3);for(let t=0;t<e.count;t++)o[t*3]=e.getX(t),o[t*3+1]=e.getY(t),o[t*3+2]=e.getZ(t);return o}a(rn,"floats");function ms(e){let o=Ze(e.geometry),t=rn(o.attributes.position);if(!t)return null;let r=o.index?.array,a=!r||r instanceof Uint32Array||r instanceof Uint16Array?r??null:Uint32Array.from(r);return {positions:t,normals:rn(o.attributes.normal),index:a}}a(ms,"shapeOf");var nn=new Matrix4,hs=new Matrix4;function gs(e){if(!(e instanceof InstancedMesh))return new Float32Array(e.matrixWorld.elements);let o=new Float32Array(e.count*16);for(let t=0;t<e.count;t++)e.getMatrixAt(t,nn),hs.multiplyMatrices(e.matrixWorld,nn).toArray(o,t*16);return o}a(gs,"matricesOf");function ln(){let e=null,o=new Set,t=0,r=new Map,a$1=new Map;try{throw new Error("@konfigure/sdk builds occluders on the main thread")}catch{e=null;}function i(s){let l=++t,c=[],f={},u=new Set,d=[],M=0;for(let m of s){let w=fs(m);if(!u.has(w)){let S=e&&o.has(w),g=S?null:ms(m);if(!S&&!g)continue;u.add(w),g&&(f[w]=g);}let h=!(m instanceof InstancedMesh);if(c.push({key:w,matrices:gs(m),vertices:h}),h){let S=Ze(m.geometry).attributes.position.count;d.push({mesh:m,offset:M,count:S}),M+=S;}}if(!e){for(let[w,h]of Object.entries(f))a$1.set(w,h);for(let w of a$1.keys())u.has(w)||a$1.delete(w);let m=Promise.resolve($r({id:l,parts:c},a$1));return {id:l,ranges:d,result:m}}o=u;let v=new Promise(m=>r.set(l,m));return e.postMessage({id:l,shapes:f,parts:c}),{id:l,ranges:d,result:v}}return a(i,"build"),{build:i,dispose(){e?.terminate(),e=null;for(let s of r.values())s(null);r.clear();}}}a(ln,"createOccluderBuilder");var Ss=64,ws=192,Ms=48e6,Ps=48,fn=4e5,Cs=16e3,Ts=64e6,Ds=1.5,As=1.2,Rs=60,Os=.2,mn=250,Is=1500,Es=4e3,hn=12e3,Bs=120,ks=450,Ls=.55,_s=.85,zs=.85,gt=0,gn=new Vector4;function vn(e){let{scene:o,renderer:t,requestTick:r}=e,a$1=t.extensions.has("EXT_color_buffer_float"),i=a$1||t.extensions.has("EXT_color_buffer_half_float"),s=t.capabilities.isWebGL2&&i?Ft(t)?"software":null:"unsupported",l=a$1?FloatType:HalfFloatType,c=zr(),f=Vr(),u=Fr(),d=Gr(),{plane:M,material:v}=Hr(),m=new FullScreenQuad(c),w=ln(),h=false,S=null,g=null,D=null,O=new Vector4,L={amount:1,fromNothing:false},y=null,A=null,k=[],I=null,U=null,X=false,C=null,F=0,G,V={still:fn,moving:fn/4},N="still",B=0,p=null,R=0,b=[],P=null,x=null,W=null,z=null,$=null,Y=0,H=0,Q=null;function K(_,Z){let J=a(()=>new WebGLRenderTarget(_,Z,{type:l,format:RGBAFormat,minFilter:NearestFilter,magFilter:NearestFilter,depthBuffer:false,generateMipmaps:false}),"make");return [J(),J()]}a(K,"accumulationTargets");function ne(_,Z,J){return !!_&&_.width===Z&&_.height===J}a(ne,"sized");function ge(_){let Z=t.getRenderTarget(),J=t.getClearColor(new Color),ee=t.getClearAlpha();t.setRenderTarget(_),t.setClearColor(0,0),t.clear(true,false,false),t.setRenderTarget(Z),t.setClearColor(J,ee);}a(ge,"clear");function te(_,Z){m.material=_;let J=t.getRenderTarget();t.setRenderTarget(Z),m.render(t),t.setRenderTarget(J);}a(te,"draw");function wt(_){let Z=Nt(o);if(!Z.length){z={job:{signature:_,started:performance.now(),activeMs:0,traced:0,stillTraced:0,stillMs:0,rect:new Vector4,ranges:[],floor:null,vertices:null,stats:{triangles:0,vertices:0,floorWidth:0,floorHeight:0,mainThreadMs:0,buildMs:0,vertexSamples:0}},shade:null};return}let J=performance.now(),{id:ee,ranges:oe,result:le}=w.build(Z),pe=performance.now()-J;P={id:ee,signature:_},le.then(ce=>{P?.id===ee&&(P=null,ce&&_===U&&se(_,ce,oe,J,pe),r());});}a(wt,"prepare");function se(_,Z,J,ee,oe){let le=performance.now(),pe=Yr(Z);c.uniforms.bvh.value.updateFrom(pe),u.uniforms.bvh.value=c.uniforms.bvh.value;let{rect:ce,size:re}=Nr(Z.bounds,gt);So(c,o,gt),So(u,o,gt),c.uniforms.rect.value.copy(ce),c.uniforms.floorY.value=gt,ne(S?.[0]??null,...re)||(S?.forEach(ve=>ve.dispose()),S=K(...re)),ge(S[0]);let Ce=Z.vertexPositions.length/4/Le;for(let ve of k)ve.dispose();k=[Z.vertexPositions,Z.vertexNormals].map(ve=>{let Re=new DataTexture(ve,Le,Ce,RGBAFormat,FloatType);return Re.needsUpdate=true,Re}),u.uniforms.vertexPositions.value=k[0],u.uniforms.vertexNormals.value=k[1],ne(y?.[0]??null,Le,Ce)||(y?.forEach(ve=>ve.dispose()),A?.dispose(),y=K(Le,Ce),A=new WebGLRenderTarget(Le,Ce,{type:UnsignedByteType,minFilter:NearestFilter,magFilter:NearestFilter,depthBuffer:false,generateMipmaps:false})),ge(y[0]);let Ne=a((ve,Re,pt)=>({material:ve,targets:Re,goal:pt,done:0,row:0,round:1}),"accumulation"),Ve=Math.max(Ps,Math.min(ws,Math.floor(Ms/Z.vertexCount)));x={signature:_,started:ee,activeMs:0,traced:0,stillTraced:0,stillMs:0,rect:ce,ranges:J,floor:Ne(c,S,Ss),vertices:Z.vertexCount?Ne(u,y,Ve):null,stats:{triangles:Z.triangles,vertices:Z.vertexCount,floorWidth:re[0],floorHeight:re[1],mainThreadMs:oe+performance.now()-le,buildMs:performance.now()-ee,vertexSamples:Z.vertexCount?Ve:0}};}a(se,"begin");function Mt(_,Z){if(_.done>=_.goal||Z<=0)return 0;let[J,ee]=_.targets,{width:oe,height:le}=J;_.row===0&&(_.round=Math.max(1,Math.min(xo,_.goal-_.done,Math.floor(Z/(oe*le)))));let pe=Math.min(le-_.row,Math.max(1,Math.floor(Z/(oe*_.round)))),ce=_.material.uniforms;return ce.previous.value=J.texture,ce.sampleOffset.value=_.done,ce.samples.value=_.round,ce.rowStart.value=_.row,ce.rowEnd.value=_.row+pe,te(_.material,ee),_.targets=[ee,J],_.row+=pe,_.row>=le&&(_.row=0,_.done+=_.round),pe*oe*_.round}a(Mt,"advance");function no(_,Z,J){if(!x)return;x.activeMs+=_,J||(x.stillMs+=_);let ee=t.getContext();if(Z&&p&&(ee.deleteSync(p),p=null),p){if(ee.clientWaitSync(p,0,0)===ee.TIMEOUT_EXPIRED){R++;return}ee.deleteSync(p),p=null;let Ve=b.length?[...b].sort((pt,ft)=>pt-ft):[1e3/60],ve=Math.max(4,Ve[Math.floor(Ve.length*Os)]),Re=V[N];R>0||_>ve*Ds?V[N]=Math.max(Cs,Re*.7):_<ve*As&&B>=Re*.7&&(V[N]=Math.min(Ts,Re*1.25)),R=0;}N=J?"moving":"still";let oe=V[N],le=Mt(x.floor,oe);B=le+(x.vertices?Mt(x.vertices,oe-le):0),x.traced+=B,J||(x.stillTraced+=B),p=ee.fenceSync(ee.SYNC_GPU_COMMANDS_COMPLETE,0),ee.flush();let pe=x.floor.done>=x.floor.goal,ce=!x.vertices||x.vertices.done>=x.vertices.goal;if(!pe||!ce)return;let re=x;if(x=null,S=re.floor.targets,!re.vertices||!A){z={job:re,shade:null};return}y=re.vertices.targets,d.uniforms.accumulated.value=y[0].texture,te(d,A);let Ce=A,Ne=new Uint8Array(Ce.width*Ce.height*4);W={signature:re.signature},t.readRenderTargetPixelsAsync(Ce,0,0,Ce.width,Ce.height,Ne).then(()=>{W?.signature===re.signature&&(W=null,re.signature===U&&(z={job:re,shade:Ne}),r());}).catch(()=>{W=null;});}a(no,"step");function Pt(){let _=L.amount<1,Z=L.fromNothing?gn:O;return v.uniforms.crossfade.value=L.amount,v.uniforms.previousRect.value.copy(_?Z:gn),v.uniforms.rect.value.z>0||_&&Z.z>0}a(Pt,"applyCrossfade");function et({job:_,shade:Z}){$={..._.stats,bakeMs:performance.now()-_.started};let J=v.uniforms.rect.value,ee=D;if(D=g,O.copy(J),v.uniforms.previousMap.value=D?.texture??null,_.rect.z===0||!S)ee?.dispose(),g=null,J.set(0,0,0,0);else {let[oe,le]=[S[0].width,S[0].height];ee&&ne(ee,oe,le)?g=ee:(ee?.dispose(),g=new WebGLRenderTarget(oe,le,{type:UnsignedByteType,minFilter:LinearFilter,magFilter:LinearFilter,depthBuffer:false,generateMipmaps:false})),f.uniforms.accumulated.value=S[0].texture,f.uniforms.texel.value.set(1/g.width,1/g.height),te(f,g),v.uniforms.map.value=g.texture,J.copy(_.rect);let{rect:pe}=_;M.matrix.makeScale(pe.z,1,pe.w).setPosition(pe.x+pe.z/2,gt+4e-4,pe.y+pe.w/2),M.matrixWorldNeedsUpdate=true;}if(Z)for(let oe of _.ranges)en(oe.mesh,Z,oe.offset);}a(et,"show");function tt(_){let Z=a(oe=>oe?oe.goal*oe.targets[0].width*oe.targets[0].height:0,"total");if(_.stillMs<Is)return _.activeMs>hn*2?"too-complex":null;let J=_.stillTraced/_.stillMs;if(J<Es)return "too-slow";let ee=Z(_.floor)+Z(_.vertices)-_.traced;return _.activeMs+ee/J>hn?"too-complex":null}a(tt,"judge");function Ct(_){if(!(!h||s||!_)){for(let Z of Nt(o)){Qr(Z);let J=Array.isArray(Z.material)?Z.material:[Z.material];for(let ee of J)on(ee);}tn(o);}}a(Ct,"beforeRender");function ao(_,Z=false){let J=performance.now(),ee=H?J-H:1/0,oe=ee<50?ee:1e3/60;H=J,ee<50&&(b.push(ee),b.length>Rs&&b.shift());let le=!s&&x?tt(x):null;if(le==="too-slow"?s=le:le==="too-complex"&&(C=x.signature,x=null),!h||s)return x=null,P=null,W=null,z=null,M.parent&&M.removeFromParent(),Y&&(xe(0),be.value.set(0,0)),Y=0,null;M.parent||o.add(M);let pe=_&&!X||U===null?`${sn(Nt(o))}|${Wr(o)}`:U;pe!==U&&(U=pe,F=J,P=null,x=null,W=null,z=null,clearTimeout(G),G=setTimeout(r,mn));let ce=null;I!==U?(Y>0&&(Y=Math.max(0,Y-oe/Bs),ce="redraw"),x?(no(oe,Q===null||Q!==x,Z),Q=x,ce??="work"):!P&&!W&&!z&&C!==U&&J-F>=mn&&wt(U),z&&Y===0&&(et(z),I=z.job.signature,z=null,ce="redraw")):Y<1&&(Y=Math.min(1,Y+oe/ks),ce="redraw");let re=Pt();return M.visible=re&&Y>0,v.uniforms.opacity.value=Y*Ls*je(),xe(re?Y:0),be.value.set(_s*Y,zs*Y),ce}a(ao,"update");function dt(){return !h||s?"off":I===U?Y<1?"fading":"idle":x?"tracing":C===U?Y>0?"fading":"skipped":P?"building":W?"reading":z?"fading":"settling"}return a(dt,"phase"),{setEnabled(_){h=_;},setHeld(_){X=_;},setFloorCrossfade(_,Z=false){L.amount=Math.min(1,Math.max(0,_)),L.fromNothing=Z;let J=Pt();M.visible=J&&Y>0;},beforeRender:Ct,update:ao,get phase(){return dt()},get availability(){return s||(C!==null&&C===U?"too-complex":"available")},hide(){let _=M.visible,Z=be.value.clone(),J=qe();return M.visible=false,be.value.set(0,0),xe(0),rt(),()=>{M.visible=_,be.value.copy(Z),xe(J),rt();}},get stats(){return $},dispose(){clearTimeout(G),p&&t.getContext().deleteSync(p),w.dispose(),M.removeFromParent(),xe(0),be.value.set(0,0),M.geometry.dispose(),c.uniforms.bvh.value.dispose();for(let _ of [c,f,u,d,v])_.dispose();m.dispose(),S?.forEach(_=>_.dispose()),y?.forEach(_=>_.dispose()),g?.dispose(),D?.dispose(),A?.dispose();for(let _ of k)_.dispose();}}}a(vn,"createBakedLighting");var bn={showFloor:true,lighting:{environmentIntensity:.1,ambientLightIntensity:.3*Math.PI,pointLightIntensity:.6*Math.PI},initialCameraPosition:[0,2,4.5],initialTarget:[0,.5,0],minPolarAngle:0,maxPolarAngle:Math.PI/2};var Ht={showFloor:true,lighting:{environmentIntensity:.45,ambientLightIntensity:.35,pointLightIntensity:0,rig:[{intensity:.6,position:[-3,2.5,-3]}]},shadowLightIntensity:2.2,updateLighting(e,o,t){let r=new Vector3;t.getCenter(r);let a=new Vector3;t.getSize(a);let i=Math.max(a.x,a.y,a.z,1)*3;o.position.set(r.x+i*.55,r.y+i*.9,r.z+i*.65),o.target.position.set(r.x,r.y*.5,r.z),o.target.updateMatrixWorld(),o.intensity=0,e.position.set(r.x,r.y+9,r.z);},shadowPadding:.6,toneMapping:NeutralToneMapping,toneMappingExposure:1,initialCameraPosition:[-0.8,1.25,1.65],initialTarget:[0,.5,0],snapCameraOnApply:true,minPolarAngle:0,maxPolarAngle:Math.PI/2,minDistance:.6,maxDistance:10,cameraNear:.05,cameraFar:250};var xn={...Ht,shadowPadding:1.5,initialCameraPosition:[-2.6,2.3,5.2],initialTarget:[0,1.1,0],minDistance:1.2,maxDistance:18};var wn={showFloor:false,environmentName:"studio",sceneColor:"#dcdcdc",adaptiveBackground:false,shadowPadding:.12,shadowLightIntensity:4.5,castModuleShadows:true,softShadowSize:16,softShadowSamples:24,toneMapping:ACESFilmicToneMapping,toneMappingExposure:1.22,lighting:{environmentIntensity:2,ambientLightIntensity:.18,pointLightIntensity:0,rig:[{intensity:1.5,position:[5,6,10]},{intensity:.5,position:[-5,3,-4]},{intensity:1,position:[1,-1,2]},{intensity:.7,position:[0,4,-6]}]},updateLighting(e,o,t){let r=t.getCenter(new Vector3),a=t.getSize(new Vector3);o.shadow.mapSize.x!==2048&&(o.shadow.mapSize.set(2048,2048),o.shadow.map?.dispose(),o.shadow.map=null),o.shadow.bias=-15e-7,o.shadow.normalBias=8e-4;let i=Math.max(a.length(),.3);e.position.set(r.x+i*2.4,r.y+i*2,r.z+i*1.1),e.castShadow=false,o.intensity=0,o.castShadow=true,o.position.set(r.x,r.y+i*2.2,r.z+i*1.89),o.target.position.copy(r),o.target.updateMatrixWorld();let s=o.position.distanceTo(r),l=Math.max(a.length(),.05);o.shadow.camera.near=Math.max(s-l,.01),o.shadow.camera.far=s+l,o.shadow.camera.updateProjectionMatrix();},initialCameraPosition:[-0.236,1.587,.336],initialTarget:[0,1.5,0],minPolarAngle:0,maxPolarAngle:Math.PI,minDistance:.08,maxDistance:2,cameraNear:.01,cameraFar:50,snapCameraOnApply:true};var jt={showFloor:true,sceneColor:"#f0f0f0",adaptiveBackground:true,lighting:{environmentIntensity:.2,ambientLightIntensity:.2*Math.PI,pointLightIntensity:.6*Math.PI},updateLighting(e,o,t){let r=new Vector3;t.getCenter(r);let a=new Vector3;t.getSize(a);let i=Math.max(a.y*1.2,4);e.position.set(r.x,r.y+i,r.z+3),e.castShadow=false,o.intensity=0,o.castShadow=true,o.position.copy(e.position),o.target.position.set(r.x,0,r.z),o.target.updateMatrixWorld();},initialCameraPosition:[0,2,4.5],initialTarget:[0,.5,0],minPolarAngle:0,maxPolarAngle:Math.PI/2};function Ns(){let e=new MeshStandardMaterial({color:"#e0e0e0",roughness:.9}),o=new BoxGeometry(2,3,.2),t=new Mesh(o,e);return t.position.set(0,1.5,-0.5),t.castShadow=true,t.receiveShadow=true,t.name="wall",[t]}a(Ns,"createWallGeometry");function Vs(e,o,t){let r=e.find(u=>u.name==="wall");if(!r||o.isEmpty())return;let a=o.getSize(new Vector3),i=o.getCenter(new Vector3),s=a.x+1,l=o.max.y+.5,c=t?.wallThickness??.2,f=t?.wallPositionOffset??0;r.geometry.dispose(),r.geometry=new BoxGeometry(s,l,c),r.position.set(i.x,l/2,o.min.z-c/2+f);}a(Vs,"updateWallGeometry");var Je={showFloor:true,lighting:{environmentIntensity:.5,ambientLightIntensity:.1*Math.PI,pointLightIntensity:.4*Math.PI},createGeometry:Ns,updateGeometry:Vs,initialCameraPosition:[0,2,5],initialTarget:[0,1.5,0],minPolarAngle:Math.PI/6,maxPolarAngle:Math.PI/2};var Tn={...jt,createGeometry:Je.createGeometry,updateGeometry:Je.updateGeometry};function js(e,o,t){let r=e.find(u=>u.name==="wall");if(!r||o.isEmpty())return;let a=o.getSize(new Vector3),i=o.getCenter(new Vector3),s=t?.wallThickness??.2,l=t?.wallPositionOffset??0,c=Math.max(o.max.y+.6,2.4),f=Math.max(a.x+1.2,2);r.geometry.dispose(),r.geometry=new BoxGeometry(f,c,s),r.position.set(i.x,c/2,o.min.z-s/2+l);}a(js,"updateWallGeometryClose");var An={...Je,updateGeometry:js,initialCameraPosition:[0,1.6,.52],initialTarget:[0,1.5,0],snapCameraOnApply:true,minDistance:.12,maxDistance:4};var me={ROOM:"room",WALL:"wall",SURROUND_LIGHT:"surround_light",SURROUND_LIGHT_WALL:"surround_light_wall",WALL_CLOSE:"wall_close",STUDIO_CLOSE:"studio_close",ROOM_LIT:"room_lit",ROOM_LIT_WIDE:"room_lit_wide"};var qs={[me.ROOM]:bn,[me.WALL]:Je,[me.SURROUND_LIGHT]:jt,[me.SURROUND_LIGHT_WALL]:Tn,[me.WALL_CLOSE]:An,[me.STUDIO_CLOSE]:wn,[me.ROOM_LIT]:Ht,[me.ROOM_LIT_WIDE]:xn};function Ao(e){return qs[e??me.ROOM]}a(Ao,"getScenePreset");function Oo({size:e,samples:o}){let t=ShaderChunk.shadowmap_pars_fragment,a$1=`
|
|
360
|
+
// --- konfigure soft shadows -------------------------------------------------
|
|
361
|
+
#define SOFT_SHADOW_TAPS ${Math.max(1,Math.round(o))}
|
|
362
|
+
#define SOFT_SHADOW_SIZE ${e.toFixed(2)}
|
|
363
|
+
|
|
364
|
+
// Interleaved gradient noise: a rotation per pixel with no visible pattern.
|
|
365
|
+
float softShadowAngle( vec2 fragCoord ) {
|
|
366
|
+
return fract( 52.9829189 * fract( dot( fragCoord, vec2( 0.06711056, 0.00583715 ) ) ) ) * 6.2831853;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Tap i of a Vogel disc of unit radius, turned by angle.
|
|
370
|
+
vec2 softShadowTap( int i, float angle ) {
|
|
371
|
+
float r = sqrt( ( float( i ) + 0.5 ) / float( SOFT_SHADOW_TAPS ) );
|
|
372
|
+
float theta = float( i ) * 2.399963 + angle;
|
|
373
|
+
return vec2( cos( theta ), sin( theta ) ) * r;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// The compare at uv blended from its four texels: a hard edge comes out as a
|
|
377
|
+
// ramp a texel wide, never as the texel grid.
|
|
378
|
+
float softShadowCompare( sampler2D shadowMap, vec2 shadowMapSize, vec2 uv, float compare ) {
|
|
379
|
+
vec2 texel = 1.0 / shadowMapSize;
|
|
380
|
+
vec2 grid = uv * shadowMapSize - 0.5;
|
|
381
|
+
vec2 f = fract( grid );
|
|
382
|
+
vec2 base = ( floor( grid ) + 0.5 ) * texel;
|
|
383
|
+
float a = texture2DCompare( shadowMap, base, compare );
|
|
384
|
+
float b = texture2DCompare( shadowMap, base + vec2( texel.x, 0.0 ), compare );
|
|
385
|
+
float c = texture2DCompare( shadowMap, base + vec2( 0.0, texel.y ), compare );
|
|
386
|
+
float d = texture2DCompare( shadowMap, base + texel, compare );
|
|
387
|
+
return mix( mix( a, b, f.x ), mix( c, d, f.x ), f.y );
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
float softShadow( sampler2D shadowMap, vec2 shadowMapSize, float lightSize, vec4 shadowCoord ) {
|
|
391
|
+
vec2 texel = 1.0 / shadowMapSize;
|
|
392
|
+
float angle = softShadowAngle( gl_FragCoord.xy );
|
|
393
|
+
float reach = SOFT_SHADOW_SIZE * lightSize;
|
|
394
|
+
|
|
395
|
+
// Blocker search: the mean depth of what casts onto this point within reach.
|
|
396
|
+
float blockerSum = 0.0;
|
|
397
|
+
float blockers = 0.0;
|
|
398
|
+
for ( int i = 0; i < SOFT_SHADOW_TAPS; i ++ ) {
|
|
399
|
+
vec2 uv = shadowCoord.xy + softShadowTap( i, angle ) * texel * reach;
|
|
400
|
+
float depth = unpackRGBAToDepth( texture2D( shadowMap, uv ) );
|
|
401
|
+
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
402
|
+
bool blocked = depth > shadowCoord.z;
|
|
403
|
+
#else
|
|
404
|
+
bool blocked = depth < shadowCoord.z;
|
|
405
|
+
#endif
|
|
406
|
+
if ( blocked ) {
|
|
407
|
+
blockerSum += depth;
|
|
408
|
+
blockers += 1.0;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if ( blockers == 0.0 ) return 1.0;
|
|
412
|
+
|
|
413
|
+
// Parallel-plane estimate: the penumbra widens with how far behind its
|
|
414
|
+
// blocker the receiver is.
|
|
415
|
+
float blocker = blockerSum / blockers;
|
|
416
|
+
float penumbra = abs( shadowCoord.z - blocker ) / max( blocker, 1e-4 );
|
|
417
|
+
float radius = max( 1.5, ( 1.0 + 1.25 * penumbra * SOFT_SHADOW_SIZE ) * lightSize );
|
|
418
|
+
|
|
419
|
+
float lit = 0.0;
|
|
420
|
+
for ( int i = 0; i < SOFT_SHADOW_TAPS; i ++ ) {
|
|
421
|
+
vec2 uv = shadowCoord.xy + softShadowTap( i, angle ) * texel * radius;
|
|
422
|
+
lit += softShadowCompare( shadowMap, shadowMapSize, uv, shadowCoord.z );
|
|
423
|
+
}
|
|
424
|
+
return lit / float( SOFT_SHADOW_TAPS );
|
|
425
|
+
}
|
|
426
|
+
`,i="float getShadow( sampler2D shadowMap",s="#if defined( SHADOWMAP_TYPE_PCF )",l=t.indexOf(i),c=t.slice(0,l),f=t.slice(l),u=c+a$1+f.replace(s,`return mix( 1.0, softShadow( shadowMap, shadowMapSize, shadowRadius, shadowCoord ), shadowIntensity );
|
|
427
|
+
${s}`);return ShaderChunk.shadowmap_pars_fragment=u,a(function(M,v,m){ShaderChunk.shadowmap_pars_fragment=t,Xs(M,v,m);},"teardown")}a(Oo,"softShadows");function Xs(e,o,t){o.traverse(r=>{let a=r.material;if(a)for(let i of [a].flat())e.properties.remove(i),i.dispose();}),e.info.programs&&(e.info.programs.length=0),e.compile(o,t);}a(Xs,"recompile");var Bo=.9,al=.3,il=.2;function ko(e,o){let t=new Box3,r=false;return Bt(e,a=>{a.visible&&(r=true,!(o?.excludeWallPanels&&a.userData.excludeFromWallBounds)&&t.expandByObject(a));}),{box:t,hasModules:r}}a(ko,"getModuleBoundingBox");function sl(e,o){let t=o.existingScene??new Scene,r=new Mesh,a$1=new PerspectiveCamera(46,1,.1,500),i,s,l=-1,c=-1,f,u,d,M=0,v,m=[],w,h,S=true,g=[],D=true,O={side:.5,top:.3},L=false,y=null,A=false,k=false,I=0,U=o.colorMode,X=true,C=false,F=null,G=false,V=[],N=null,B=false,p=null,R=false,b=false,P=false;function x(){X=true;}a(x,"invalidate");function W(T){C=T,T&&x();}a(W,"setForceRender");function z(T){F=T,x();}a(z,"setCameraDriver");let $=[];function Y(){return x(),new Promise(T=>$.push(T))}a(Y,"nextRender");function H(){if(!$.length)return;let T=$;$=[];for(let E of T)E();}a(H,"flushRenderWaiters");let{onAnimate:Q,onFrame:K,onRender:ne}=o;v=Ao(o.scenePreset);function ge(){a$1.near=v.cameraNear??.1,a$1.far=v.cameraFar??500,a$1.updateProjectionMatrix();}a(ge,"applyCameraFrustum"),ge();let te=new WebGLRenderer({antialias:true,canvas:e,alpha:true});te.setPixelRatio(window.devicePixelRatio),te.setSize(o.width,o.height),te.shadowMap.enabled=true,te.outputColorSpace=SRGBColorSpace,te.toneMapping=v.toneMapping??NoToneMapping,te.toneMappingExposure=v.toneMappingExposure??1;function wt(){G||(t.environment?.dispose(),i?.dispose(),ft(v?.environmentName??"neutral"),ho(),te.shadowMap.needsUpdate=true,N&&(N.dispose(),N=null,B&&pr(true)),x());}a(wt,"onContextRestored"),e.addEventListener("webglcontextrestored",wt),a$1.position.set(...v.initialCameraPosition),a$1.aspect=o.width/o.height;let se=new OrbitControls(a$1,e);se.target.set(...v.initialTarget),se.enableDamping=true,se.minDistance=v.minDistance??2,se.maxDistance=v.maxDistance??15,se.minPolarAngle=v.minPolarAngle,se.maxPolarAngle=v.maxPolarAngle,se.maxTargetRadius=10,se.addEventListener("change",()=>{se.target.y<.1&&(se.target.y=.1),x();});let Mt=Scene.prototype.add,no=Scene.prototype.remove;t.add=function(...T){return x(),Mt.apply(t,T)},t.remove=function(...T){return x(),no.apply(t,T)};function Pt(T){return T==="dark"?{bg:"#555",floor:"#666"}:{bg:y??v?.sceneColor??"#c1c1c1",floor:"#fff"}}a(Pt,"getSceneColors");function et(){let{bg:T,floor:E}=Pt(U);t.fog=new Fog(T,30,40),t.background=new Color(T),r.parent&&!L&&(r.material=new MeshStandardMaterial({color:E,roughness:1})),J=-1;}a(et,"applySceneColors");let tt=new Color;function Ct(T){return T.getRGB(tt,SRGBColorSpace),.299*tt.r+.587*tt.g+.114*tt.b}a(Ct,"srgbLuminance");function ao(){let T=0,E=0;return Bt(t,j=>{if(!j.visible||!j.userData.hasConfigurableSurface)return;let q=Array.isArray(j.material)?j.material:[j.material];for(let ie of q){let ue=ie.color;ue&&(T+=Ct(ue),E++);}}),E>0?T/E:null}a(ao,"getModuleAverageLuminance");let dt=new Color,_=new Color,Z=new Color,J=-1;function ee(){let T=ao()??0,E=T<=Bo?0:(T-Bo)/(1-Bo);if(Math.abs(E-J)<.01)return;J=E,Z.set(y??v?.sceneColor??"#c1c1c1");let j=Ct(Z)-al*E;if(dt.setRGB(j,j,j,SRGBColorSpace),t.background=dt,t.fog instanceof Fog&&t.fog.color.copy(dt),r.parent&&!L&&r.material instanceof MeshStandardMaterial){let q=1-il*E;_.setRGB(q,q,q,SRGBColorSpace),r.material.color.copy(_);}}a(ee,"updateAdaptiveColors");let oe=0,le=new Color("#ffffff"),pe=new Color,ce=new Color,re=null,Ce=.75;function Ne(T,E){let j=Math.min(1,Math.max(0,T));E&&le.set(E),j!==oe&&(oe=j,x());}a(Ne,"setFogVeil");function Ve(){if(!(t.fog instanceof Fog))return;if(!oe){if(!re)return;t.fog.near=re.near,t.fog.far=re.far,t.fog.color.copy(re.color),t.background=re.background,Te(1),re=null;return}re??={near:t.fog.near,far:t.fog.far,color:t.fog.color.clone(),background:t.background};let T=Math.max(.1,a$1.position.distanceTo(se.target)),E=Math.max(re.far,T*2),j=Math.max(.05,T*.15),q=Math.pow(oe,Ce),ie=E*Math.pow(j/E,q);t.fog.far=ie,t.fog.near=ie*(re.far>0?re.near/re.far:.5),t.fog.color.copy(pe.copy(re.color).lerp(le,q));let ue=re.background instanceof Color?re.background:le;t.background=ce.copy(ue).lerp(le,q),Te(1-q);}a(Ve,"applyFogVeil");function ve(T){t.traverse(E=>{if(!(E instanceof Mesh))return;let j=Array.isArray(E.material)?E.material:[E.material];for(let q of j)"envMap"in q&&q.envMap&&(q.envMap=T,q.needsUpdate=true);});}a(ve,"updateEnvironmentMaps");function Re(T){let E=new PMREMGenerator(te),j=E.fromScene(new $e(T),.04).texture;return E.dispose(),j}a(Re,"buildRoomEnvironment");function pt(T,E){new RGBELoader().load(T,j=>{if(!((v?.environmentName??"neutral")===E)||G){j.dispose();return}j.mapping=EquirectangularReflectionMapping;let ie=new PMREMGenerator(te),ue=ie.fromEquirectangular(j).texture;ie.dispose(),j.dispose(),t.environment?.dispose(),i?.dispose(),i=ue,t.environment=ue,ve(ue),x();});}a(pt,"loadHdriEnvironment");function ft(T){i=Re(T),t.environment=i,ve(i);let{hdri:E}=_t(T);E&&pt(E,T);}a(ft,"applyEnvironment");function Ja(){let T=v?.environmentName??"neutral";ft(T);let E=v.lighting;t.environmentIntensity=E.environmentIntensity,f=new AmbientLight(16777215,E.ambientLightIntensity),t.add(f);for(let ue of E.rig??[]){let fe=new DirectionalLight(16777215,ue.intensity);fe.position.set(...ue.position),fe.castShadow=false,V.push(fe),t.add(fe);}u=new PointLight(16777215,E.pointLightIntensity,100,0),u.position.set(0,9,0);let j=new PlaneGeometry(1e3,1e3),q=new ShadowMaterial;q.side=BackSide,q.opacity=.15,q.depthWrite=false,q.polygonOffset=true,q.polygonOffsetFactor=-1,q.polygonOffsetUnits=-1;let ie=new Mesh(j,q);ie.receiveShadow=true,ie.position.y=.004,ie.rotateX(Math.PI/2),ie.name="floor",ie.visible=D,t.add(ie),d=new DirectionalLight(16777215,0),d.position.set(0,5,0),d.castShadow=true,d.shadow.bias=-2e-5,d.shadow.intensity=1,d.shadow.camera.left=-10,d.shadow.camera.right=10,d.shadow.camera.top=10,d.shadow.camera.bottom=-10,l=v?.softShadowSize??10,c=v?.softShadowSamples??10,s=Oo({size:l,samples:c}),t.add(u,d,d.target);}a(Ja,"setEnvironment");function sr(){if(!v?.showFloor)return;let T=new PlaneGeometry(1e3,1e3),E=new MeshStandardMaterial({color:U==="dark"?"#666":"#fff",...i&&{envMap:i}});E.roughness=1,E.envMapIntensity=0,r=new Mesh(T,E),r.receiveShadow=false,r.rotation.x=-Math.PI/2,r.position.y=0,r.name="room",r.visible=D,t.add(r);}a(sr,"createRoom"),sr(),v.createGeometry&&(m=v.createGeometry(),m.forEach(T=>t.add(T))),Ja(),et();function lr(){!oe&&X&&U!=="dark"&&v?.adaptiveBackground&&ee(),Ve(),Xe(te);let T=X;N?.beforeRender(T),p?Qa(p):te.render(t,a$1),X=false,ur(T),ne?.(),H();}a(lr,"drawFrame");let Ka=new Vector2;function Qa(T){let{x:E,y:j}=te.getSize(Ka),q=Math.round(E*Math.min(1,Math.max(0,T.at)));te.setScissorTest(true),cr(T.left,0,q,j),cr(T.right,q,E-q,j),te.setScissorTest(false);}a(Qa,"renderSplit");function cr(T,E,j,q){if(j<=0)return;let ie=T.apply?.(),ue=T.bakedLighting===false?N?.hide():void 0;ie&&N?.beforeRender(true),te.setScissor(E,0,j,q),te.render(t,a$1),ue?.(),ie?.();}a(cr,"renderSide");function ur(T){let E=N?.update(T,P)??null;R=E==="redraw",b=E==="work";}a(ur,"runBake");function ei(){if(A){H();return}F?F(0):se.update(),lr();}a(ei,"renderNow");function dr(){if(!k)return;let T=performance.now()/1e3,E=M>0?T-M:.016;M=T;let j;F?(F(E),j=true):j=se.update(E),K?.(E),P=j,!A&&(C||X||j||R)?lr():!A&&b?ur(false):A&&H(),Q?.(),I=requestAnimationFrame(dr);}a(dr,"animate");function ti(T,E){a$1.aspect=T/E,a$1.updateProjectionMatrix(),te.setSize(T,E),te.setPixelRatio(Math.min(window.devicePixelRatio,2)),x();}a(ti,"setSize");function oi(T){U=T,et(),x();}a(oi,"setColorMode");function ri(T){T!==y&&(y=T,et(),x());}a(ri,"setSceneColor");function ni(T){let E=Ao(T);if(E===v)return;let j=v?.environmentName??"neutral";m.forEach(ae=>{t.remove(ae),ae instanceof Mesh&&(ae.geometry.dispose(),ae.material instanceof MeshStandardMaterial&&ae.material.dispose());}),m=[];let q=t.getObjectByName("room");if(E.showFloor&&!q?(v=E,sr()):!E.showFloor&&q&&(t.remove(q),q instanceof Mesh&&(q.geometry.dispose(),q.material instanceof MeshStandardMaterial&&q.material.dispose())),v=E,se.minDistance=v.minDistance??2,se.maxDistance=v.maxDistance??15,ge(),v.snapCameraOnApply&&(a$1.position.set(...v.initialCameraPosition),se.target.set(...v.initialTarget),se.update()),v.createGeometry){m=v.createGeometry();let ae=!!w;m.forEach(de=>{ae&&(de.visible=false),t.add(de);});}let ie=E.environmentName??"neutral";j!==ie&&(i?.dispose(),t.environment?.dispose(),ft(ie));let ue=v.lighting;t.environmentIntensity=ue.environmentIntensity,f&&(f.intensity=ue.ambientLightIntensity),u&&(u.intensity=ue.pointLightIntensity);for(let ae of V.splice(0))t.remove(ae);for(let ae of ue.rig??[]){let de=new DirectionalLight(16777215,ae.intensity);de.position.set(...ae.position),de.castShadow=false,V.push(de),t.add(de);}let fe=v.softShadowSize??10,Ee=v.softShadowSamples??10;(fe!==l||Ee!==c)&&(s?.(te,t,a$1),l=fe,c=Ee,s=Oo({size:fe,samples:Ee})),et(),te.toneMapping=v.toneMapping??NoToneMapping,te.toneMappingExposure=v.toneMappingExposure??1,se.minPolarAngle=v.minPolarAngle,se.maxPolarAngle=v.maxPolarAngle,fr(),x();}a(ni,"setScenePreset");function ai(T){p=T,x();}a(ai,"setSplitView");function pr(T){B=T,T&&!N&&(N=vn({scene:t,renderer:te,requestTick:a(()=>{b=true;},"requestTick")})),N?.setEnabled(T),x();}a(pr,"setBakedLighting");function ii(T){A=T,T||x();}a(ii,"setPaused");function si(T){S=T,m.forEach(E=>{E.visible=T&&!w;}),g.forEach(E=>{E.visible=T;}),x();}a(si,"setWallVisible");function li(T){D=T;for(let E of ["room","floor"]){let j=t.getObjectByName(E);j&&(j.visible=T);}x();}a(li,"setFloorVisible");function ci(T){O={side:T.side??.5,top:T.top??.3};}a(ci,"setWallSurround");function ui(T){let E=w!==T;return w=T,E}a(ui,"setWallThickness");function di(T){let E=h!==T;return h=T,E}a(di,"setWallPositionOffset");function fr(){if(!u||!d)return;let{box:T,hasModules:E}=ko(t);if(!E||T.isEmpty()){u.position.set(0,9,0),d.position.set(0,5,0),d.shadow.camera.left=-10,d.shadow.camera.right=10,d.shadow.camera.top=10,d.shadow.camera.bottom=-10,d.shadow.camera.updateProjectionMatrix(),se.maxDistance=15,se.maxTargetRadius=10,t.fog instanceof Fog&&(t.fog.near=20,t.fog.far=40);return}let j=new Vector3;T.getCenter(j);let q=new Vector3;T.getSize(q);let ie=Math.max(q.x,q.y,q.z),ue=v?.shadowPadding??Math.max(ie*.2,2),fe=ie/2+ue;if(v?.updateLighting)v.updateLighting(u,d,T);else {let ae=Math.max(9,Math.max(q.x,q.y,q.z)*1.5);u.position.set(j.x,ae,j.z),d.intensity=0,d.position.set(j.x,5,j.z),d.target.position.set(j.x,0,j.z),d.target.updateMatrixWorld();}if(d.shadow.camera.left=-fe,d.shadow.camera.right=fe,d.shadow.camera.top=fe,d.shadow.camera.bottom=-fe,d.shadow.camera.updateProjectionMatrix(),v?.updateLighting&&d.intensity===0){d.intensity=v.shadowLightIntensity??1,d.layers.disableAll(),d.layers.enable(1),a$1.layers.enable(1);let ae=v?.castModuleShadows===true;Bt(t,de=>{de.layers.enable(1),ae&&(de.castShadow=true,de.receiveShadow=true);}),m.forEach(de=>{de.traverse(Oe=>{Oe instanceof Mesh&&Oe.layers.enable(1);});});}else d.layers.enableAll();te.shadowMap.needsUpdate=true,t.traverse(ae=>{ae instanceof Mesh&&ae.material&&(ae.material.needsUpdate=true);}),x();let Ee=Math.max(q.x,q.y,q.z);if(se.maxDistance=Math.max(15,Ee*3),se.maxTargetRadius=Math.max(10,fe),t.fog instanceof Fog){let ae=v?.fogFarMultiplier??1.5,de=v?.fogNearMultiplier??.5,Oe=Math.max(40,se.maxDistance*ae);t.fog.near=Oe*de,t.fog.far=Oe;}if(v?.updateGeometry)if(w)m.forEach(ae=>{ae.visible=false;});else {let{box:ae}=ko(t,{excludeWallPanels:true});v.updateGeometry(m,ae,{wallThickness:w,wallPositionOffset:h}),m.forEach(de=>{de.visible=S;});}}a(fr,"updateLighting");function pi(){for(let Be of g)t.remove(Be),Be.geometry.dispose(),Be.material instanceof MeshStandardMaterial&&Be.material.dispose();if(g=[],!w)return;let{box:T,hasModules:E}=ko(t,{excludeWallPanels:true});if(!E||T.isEmpty())return;let j=T.getSize(new Vector3),q=T.getCenter(new Vector3),ie=w,ue=h??0,fe=O.side,Ee=O.top,ae=T.max.y+Ee,de=q.z+ue,Oe=new MeshStandardMaterial({color:"#e0e0e0",roughness:.9}),yi=new BoxGeometry(fe,ae,ie),Tt=new Mesh(yi,Oe.clone());Tt.name="wall-left",Tt.position.set(T.min.x-fe/2,ae/2,de),Tt.receiveShadow=true;let xi=new BoxGeometry(fe,ae,ie),Dt=new Mesh(xi,Oe.clone());Dt.name="wall-right",Dt.position.set(T.max.x+fe/2,ae/2,de),Dt.receiveShadow=true;let hr=j.x,Si=new BoxGeometry(hr,Ee,ie),At=new Mesh(Si,Oe.clone());At.name="wall-top",At.position.set(q.x,T.max.y+Ee/2,de),At.receiveShadow=true,g=[Tt,Dt,At];let io=T.min.y;if(io>.01){let Be=new BoxGeometry(hr,io,ie),Rt=new Mesh(Be,Oe.clone());Rt.name="wall-bottom",Rt.position.set(q.x,io/2,de),Rt.receiveShadow=true,g.push(Rt);}for(let Be of g)Be.visible=S,t.add(Be);}a(pi,"updateWallMesh");function fi(T){let E=m.find(j=>j.name==="wall");E&&(E.material instanceof MeshStandardMaterial&&E.material.dispose(),E.material=T);for(let j of g)j.material instanceof MeshStandardMaterial&&j.material.dispose(),j.material=T.clone();x();}a(fi,"applyWallMaterial");function mi(){let T=[];for(let E of m)E instanceof Mesh&&E.visible&&T.push(E);for(let E of g)E.visible&&T.push(E);return T}a(mi,"getOcclusionColliders");function hi(T){if(!r.parent)return;r.material instanceof MeshStandardMaterial&&r.material.dispose();let E=T.clone();E instanceof MeshStandardMaterial&&E.map&&(E.map=E.map.clone(),E.map.repeat.set(1e3,1e3),E.map.needsUpdate=true),r.material=E,L=true,x();}a(hi,"applyFloorMaterial");function gi(){k=true,M=0,x(),I=requestAnimationFrame(dr);}a(gi,"start");function mr(){k=false,I&&(cancelAnimationFrame(I),I=0);}a(mr,"stop");function vi(){G=true,mr(),e.removeEventListener("webglcontextrestored",wt),oe=0,re=null,Te(1),s&&s(te,t,a$1),N?.dispose(),N=null,t.traverse(T=>{T instanceof Mesh&&(T.geometry.dispose(),T.material.dispose());}),t.environment?.dispose(),i?.dispose(),m=[],g=[],L=false,t.clear(),delete t.add,delete t.remove,se.dispose(),te.dispose(),te.forceContextLoss();}a(vi,"dispose");function bi(){return {cameraPosition:[...v.initialCameraPosition],target:[...v.initialTarget]}}return a(bi,"getInitialView"),{scene:t,camera:a$1,renderer:te,controls:se,setSize:ti,setColorMode:oi,setSceneColor:ri,setScenePreset:ni,getInitialView:bi,setPaused:ii,setWallVisible:si,setFloorVisible:li,setWallSurround:ci,setWallThickness:ui,setWallPositionOffset:di,updateLighting:fr,updateWallMesh:pi,applyWallMaterial:fi,applyFloorMaterial:hi,getOcclusionColliders:mi,invalidate:x,setForceRender:W,setCameraDriver:z,setFogVeil:Ne,setBakedLighting:pr,setSplitView:ai,get bakedLighting(){return N},nextRender:Y,renderNow:ei,start:gi,stop:mr,dispose:vi}}a(sl,"createScene");var cl=["configurator","catalogue","daylight","dramatic","dark"],De=a((e,o)=>({enabled:true,softness:.7,temperature:5600,...o,id:e}),"light"),ul={configurator:{id:"configurator",live:true,environment:"neutral",environmentIntensity:0,environmentRotation:0,exposure:0,backdrop:"",floorShadow:1,lights:[]},catalogue:{id:"catalogue",environment:"neutral",environmentIntensity:.4,environmentRotation:0,exposure:0,backdrop:"#f2f2f0",floorShadow:.55,lights:[De("key",{azimuth:-40,elevation:40,intensity:1.5,softness:.85}),De("fill",{azimuth:55,elevation:20,intensity:.5,softness:1}),De("rim",{azimuth:160,elevation:45,intensity:.9,softness:.5})]},daylight:{id:"daylight",environment:"neutral",environmentIntensity:.45,environmentRotation:0,exposure:0,backdrop:"#e9e4dc",floorShadow:.55,lights:[De("key",{azimuth:-75,elevation:25,intensity:1.1,softness:1,temperature:6300}),De("fill",{azimuth:60,elevation:15,intensity:.25,softness:1,temperature:4800}),De("rim",{enabled:false,azimuth:165,elevation:35,intensity:1,softness:.6})]},dramatic:{id:"dramatic",environment:"neutral",environmentIntensity:.15,environmentRotation:0,exposure:0,backdrop:"#5b5b5d",floorShadow:.85,lights:[De("key",{azimuth:-70,elevation:30,intensity:2.4,softness:.35,temperature:4900}),De("fill",{azimuth:60,elevation:15,intensity:.25,softness:1}),De("rim",{azimuth:150,elevation:35,intensity:2,softness:.3,temperature:6500})]},dark:{id:"dark",environment:"neutral",environmentIntensity:.08,environmentRotation:0,exposure:0,backdrop:"#1e1e20",floorShadow:.75,lights:[De("key",{azimuth:-25,elevation:55,intensity:2,softness:.8}),De("fill",{azimuth:70,elevation:20,intensity:.3,softness:1}),De("rim",{azimuth:180,elevation:40,intensity:1.8,softness:.5})]}};function dl(e){return {...e,lights:e.lights.map(o=>({...o}))}}a(dl,"clonePhotoSetup");var pl=5600;function En(e){let o=Math.min(4e4,Math.max(1e3,e))/100,t=a(s=>Math.min(255,Math.max(0,s))/255,"clamp"),r=o<=66?255:329.698727446*Math.pow(o-60,-0.1332047592),a$1=o<=66?99.4708025861*Math.log(o)-161.1195681661:288.1221695283*Math.pow(o-60,-0.0755148492),i=o>=66?255:o<=19?0:138.5177312231*Math.log(o-10)-305.0447927307;return [t(r),t(a$1),t(i)]}a(En,"blackBody");function Lo(e,o=new Color){let t=En(e),r=En(pl),a=t.map((s,l)=>s/r[l]),i=Math.max(...a);return o.setRGB(a[0]/i,a[1]/i,a[2]/i,"srgb")}a(Lo,"kelvinToColor");var Yt=Math.atan(.3)*180/Math.PI,ml=Math.asin(1/Math.sqrt(3))*180/Math.PI,Zt={front:{name:"front",azimuth:0,elevation:Yt},back:{name:"back",azimuth:180,elevation:Yt},left:{name:"left",azimuth:-90,elevation:Yt},right:{name:"right",azimuth:90,elevation:Yt},top:{name:"top",azimuth:0,elevation:89.4,zoom:1.2},isometric:{name:"isometric",azimuth:45,elevation:ml,zoom:1.1},threeQuarter:{name:"threeQuarter",azimuth:35,elevation:18},threeQuarterLeft:{name:"threeQuarterLeft",azimuth:-35,elevation:18},hero:{name:"hero",azimuth:30,elevation:7,fov:22},profile:{name:"profile",azimuth:90,elevation:4,fov:20},closeUp:{name:"closeUp",azimuth:25,elevation:14,fov:24,zoom:.55},overhead:{name:"overhead",azimuth:20,elevation:62,zoom:1.1}},hl=Object.keys(Zt);function kn(e){return Object.hasOwn(Zt,e)}a(kn,"isPhotoShotPreset");function _o(e){if(typeof e!="string")return e;if(!kn(e))throw new Error(`Unknown photo shot "${e}"`);return Zt[e]}a(_o,"resolvePhotoShot");var Bn=Math.PI/180;function zo(e,o=new Vector3){let t=e.azimuth*Bn,r=Math.min(89.9,Math.max(-20,e.elevation))*Bn;return o.set(Math.sin(t)*Math.cos(r),Math.sin(r),Math.cos(t)*Math.cos(r)).normalize()}a(zo,"photoShotDirection");function bt(e){return e.extensions.has("EXT_color_buffer_float")||e.extensions.has("EXT_color_buffer_half_float")}a(bt,"supportsFloatTargets");function Fo(e,o,t,r={}){let a$1=bt(e)?HalfFloatType:UnsignedByteType,i=new WebGLRenderTarget(o,t,{type:a$1,samples:r.samples??8}),s=new WebGLRenderTarget(o,t),l=new OutputPass,c=new Uint8Array(o*t*4);function f(u){l.render(e,s,{texture:u},0,false),e.setRenderTarget(null),e.readRenderTargetPixels(s,0,0,o,t,c);let d=new ImageData(o,t),M=o*4;for(let v=0;v<t;v++){let m=(t-1-v)*M;d.data.set(c.subarray(m,m+M),v*M);}return d}return a(f,"encode"),{width:o,height:t,render(u,d){return e.setRenderTarget(i),e.clear(),e.render(u,d),e.setRenderTarget(null),f(i.texture)},encode:f,dispose(){i.dispose(),s.dispose(),l.dispose();}}}a(Fo,"createCaptureRenderer");function _n(e,o="png",t){let r=document.createElement("canvas");return r.width=e.width,r.height=e.height,r.getContext("2d")?.putImageData(e,0,0),r.toDataURL(o==="jpeg"?"image/jpeg":"image/png",t)}a(_n,"imageDataToDataURL");[{name:"front",dir:new Vector3(0,.3,1).normalize()},{name:"back",dir:new Vector3(0,.3,-1).normalize()},{name:"left",dir:new Vector3(-1,.3,0).normalize()},{name:"right",dir:new Vector3(1,.3,0).normalize()},{name:"top",dir:new Vector3(0,1,.01),distanceMultiplier:1.4},{name:"isometric",dir:new Vector3(1,1,1).normalize(),distanceMultiplier:1.3}];function zn(e){if(e.length===0)return null;let o=new Box3;for(let t of e){let r=t.getBoundingBoxes(true);for(let a of r)o.union(a);}return o.isEmpty()?null:o}a(zn,"getCombinedBoundingBox");var xl=1.15;function Fn(e,o,t,r,a=xl){let i=e.getCenter(new Vector3),s=r.clone().normalize(),l=new Vector3(0,1,0),c=new Vector3().crossVectors(l,s);c.lengthSq()<1e-6&&c.set(1,0,0),c.normalize();let f=new Vector3().crossVectors(s,c).normalize(),u=Math.tan(o*Math.PI/360),d=u*t,M=[new Vector3(e.min.x,e.min.y,e.min.z),new Vector3(e.min.x,e.min.y,e.max.z),new Vector3(e.min.x,e.max.y,e.min.z),new Vector3(e.min.x,e.max.y,e.max.z),new Vector3(e.max.x,e.min.y,e.min.z),new Vector3(e.max.x,e.min.y,e.max.z),new Vector3(e.max.x,e.max.y,e.min.z),new Vector3(e.max.x,e.max.y,e.max.z)],v=0;for(let m of M){let w=m.sub(i),h=w.dot(s),S=Math.abs(w.dot(c)),g=Math.abs(w.dot(f)),D=a*S/d+h,O=a*g/u+h;v=Math.max(v,D,O);}return v}a(Fn,"calculateCameraDistance");var Gn=30;[{name:"front",dir:new Vector3(0,.3,1).normalize()},{name:"back",dir:new Vector3(0,.3,-1).normalize()},{name:"left",dir:new Vector3(-1,.3,0).normalize()},{name:"right",dir:new Vector3(1,.3,0).normalize()},{name:"top",dir:new Vector3(0,1,.01),distanceMultiplier:1.4},{name:"isometric",dir:new Vector3(1,1,1).normalize(),distanceMultiplier:1.3}];function Sl(e,o){let r=[new Vector3(e.min.x,e.min.y,e.min.z),new Vector3(e.min.x,e.min.y,e.max.z),new Vector3(e.min.x,e.max.y,e.min.z),new Vector3(e.min.x,e.max.y,e.max.z),new Vector3(e.max.x,e.min.y,e.min.z),new Vector3(e.max.x,e.min.y,e.max.z),new Vector3(e.max.x,e.max.y,e.min.z),new Vector3(e.max.x,e.max.y,e.max.z)].map(a=>a.clone().project(o).y);return {minY:Math.min(...r),maxY:Math.max(...r)}}a(Sl,"getBoundingBoxScreenYExtent");function Wn(e,o,t){let{minY:r,maxY:a}=Sl(e,o),i=(a+r)/2,s=o.position.distanceTo(t),l=o.fov*Math.PI/180,c=2*Math.tan(l/2)*s;return i/2*c}a(Wn,"calculateVerticalCenteringOffset");var Rl=[1,2,4,8],Ol=[1,2,4],We=`
|
|
428
|
+
varying vec2 vUv;
|
|
429
|
+
void main() {
|
|
430
|
+
vUv = uv;
|
|
431
|
+
gl_Position = vec4(position.xy, 0.0, 1.0);
|
|
432
|
+
}
|
|
433
|
+
`,Vn=`
|
|
434
|
+
varying vec2 vUv;
|
|
435
|
+
uniform vec2 projection; // tan(fov / 2) * aspect, tan(fov / 2)
|
|
436
|
+
// (three's own \`luminance()\` is already in every shader's prelude.)
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
// View-space position from a guide texel: depth is in w (0 = nothing there).
|
|
440
|
+
vec3 viewPosition(vec2 uv, float depth) {
|
|
441
|
+
return vec3((uv * 2.0 - 1.0) * projection * depth, -depth);
|
|
442
|
+
}
|
|
443
|
+
`;function Il(){return new ShaderMaterial({side:DoubleSide,vertexShader:`
|
|
444
|
+
varying vec3 vNormal;
|
|
445
|
+
varying float vDepth;
|
|
446
|
+
void main() {
|
|
447
|
+
vNormal = normalize(normalMatrix * normal);
|
|
448
|
+
vec4 mv = modelViewMatrix * vec4(position, 1.0);
|
|
449
|
+
vDepth = -mv.z;
|
|
450
|
+
gl_Position = projectionMatrix * mv;
|
|
451
|
+
}
|
|
452
|
+
`,fragmentShader:`
|
|
453
|
+
varying vec3 vNormal;
|
|
454
|
+
varying float vDepth;
|
|
455
|
+
void main() {
|
|
456
|
+
gl_FragColor = vec4(normalize(vNormal) * (gl_FrontFacing ? 1.0 : -1.0), vDepth);
|
|
457
|
+
}
|
|
458
|
+
`})}a(Il,"normalDepthMaterial");var Hn="0.03";function El(){return new ShaderMaterial({defines:{BASE_FLOOR:Hn},uniforms:{traced:{value:null},albedo:{value:null}},vertexShader:We,fragmentShader:`
|
|
459
|
+
uniform sampler2D traced;
|
|
460
|
+
uniform sampler2D albedo;
|
|
461
|
+
varying vec2 vUv;
|
|
462
|
+
void main() {
|
|
463
|
+
vec4 t = texture2D(traced, vUv);
|
|
464
|
+
vec4 a = texture2D(albedo, vUv);
|
|
465
|
+
// Floored so a near-black surface (a chair leg) does not turn its
|
|
466
|
+
// noise into fireflies. Compose multiplies by the same floored base.
|
|
467
|
+
vec3 base = max(a.rgb / max(a.a, 1e-4), vec3(BASE_FLOOR));
|
|
468
|
+
gl_FragColor = vec4(t.rgb / base, t.a);
|
|
469
|
+
}
|
|
470
|
+
`})}a(El,"demodulateMaterial");function Bl(){return new ShaderMaterial({uniforms:{source:{value:null},cover:{value:null},useCover:{value:false}},vertexShader:We,fragmentShader:`
|
|
471
|
+
uniform sampler2D source;
|
|
472
|
+
uniform sampler2D cover;
|
|
473
|
+
uniform bool useCover;
|
|
474
|
+
varying vec2 vUv;
|
|
475
|
+
void main() {
|
|
476
|
+
float valid = useCover ? 1.0 - texture2D(cover, vUv).a : 1.0;
|
|
477
|
+
gl_FragColor = vec4(texture2D(source, vUv).rgb, valid);
|
|
478
|
+
}
|
|
479
|
+
`})}a(Bl,"maskMaterial");function kl(){return new ShaderMaterial({uniforms:{image:{value:null},direction:{value:new Vector2}},vertexShader:We,fragmentShader:`
|
|
480
|
+
uniform sampler2D image;
|
|
481
|
+
uniform vec2 direction;
|
|
482
|
+
varying vec2 vUv;
|
|
483
|
+
void main() {
|
|
484
|
+
float weights[5];
|
|
485
|
+
weights[0] = 0.2270270270; weights[1] = 0.1945945946; weights[2] = 0.1216216216;
|
|
486
|
+
weights[3] = 0.0540540541; weights[4] = 0.0162162162;
|
|
487
|
+
vec3 sum = vec3(0.0);
|
|
488
|
+
float mass = 0.0;
|
|
489
|
+
float total = 0.0;
|
|
490
|
+
for (int i = -4; i <= 4; i++) {
|
|
491
|
+
float w = weights[i < 0 ? -i : i];
|
|
492
|
+
vec4 t = texture2D(image, vUv + direction * float(i));
|
|
493
|
+
sum += t.rgb * t.a * w;
|
|
494
|
+
mass += t.a * w;
|
|
495
|
+
total += w;
|
|
496
|
+
}
|
|
497
|
+
gl_FragColor = vec4(mass > 0.0 ? sum / mass : texture2D(image, vUv).rgb, mass / total);
|
|
498
|
+
}
|
|
499
|
+
`})}a(kl,"gaussianMaterial");function Ll(){return new ShaderMaterial({uniforms:{withProduct:{value:null},floorOnly:{value:null}},vertexShader:We,fragmentShader:`
|
|
500
|
+
uniform sampler2D withProduct;
|
|
501
|
+
uniform sampler2D floorOnly;
|
|
502
|
+
varying vec2 vUv;
|
|
503
|
+
void main() {
|
|
504
|
+
float lit = luminance(texture2D(withProduct, vUv).rgb);
|
|
505
|
+
float open = luminance(texture2D(floorOnly, vUv).rgb);
|
|
506
|
+
gl_FragColor = vec4(vec3(clamp(1.0 - lit / max(open, 1e-4), 0.0, 1.0)), 1.0);
|
|
507
|
+
}
|
|
508
|
+
`})}a(Ll,"shadowMaterial");function _l(){return new ShaderMaterial({uniforms:{source:{value:null}},vertexShader:We,fragmentShader:`
|
|
509
|
+
uniform sampler2D source;
|
|
510
|
+
varying vec2 vUv;
|
|
511
|
+
void main() { gl_FragColor = texture2D(source, vUv); }
|
|
512
|
+
`})}a(_l,"copyMaterial");function zl(){return new ShaderMaterial({uniforms:{lighting:{value:null},texel:{value:null}},vertexShader:We,fragmentShader:`
|
|
513
|
+
uniform sampler2D lighting;
|
|
514
|
+
uniform vec2 texel;
|
|
515
|
+
varying vec2 vUv;
|
|
516
|
+
void main() {
|
|
517
|
+
float sum = 0.0;
|
|
518
|
+
float sumSq = 0.0;
|
|
519
|
+
for (int y = -2; y <= 2; y++) {
|
|
520
|
+
for (int x = -2; x <= 2; x++) {
|
|
521
|
+
float l = luminance(texture2D(lighting, vUv + vec2(x, y) * texel).rgb);
|
|
522
|
+
sum += l;
|
|
523
|
+
sumSq += l * l;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
float mean = sum / 25.0;
|
|
527
|
+
gl_FragColor = vec4(max(sumSq / 25.0 - mean * mean, 0.0));
|
|
528
|
+
}
|
|
529
|
+
`})}a(zl,"varianceMaterial");function Fl(){return new ShaderMaterial({uniforms:{lighting:{value:null},guide:{value:null},variance:{value:null},texel:{value:null},stepSize:{value:1},projection:{value:null}},vertexShader:We,fragmentShader:`
|
|
530
|
+
${Vn}
|
|
531
|
+
uniform sampler2D lighting;
|
|
532
|
+
uniform sampler2D guide;
|
|
533
|
+
uniform sampler2D variance;
|
|
534
|
+
uniform vec2 texel;
|
|
535
|
+
uniform float stepSize;
|
|
536
|
+
void main() {
|
|
537
|
+
vec4 centre = texture2D(lighting, vUv);
|
|
538
|
+
vec4 g = texture2D(guide, vUv);
|
|
539
|
+
if (g.a <= 0.0) { gl_FragColor = centre; return; }
|
|
540
|
+
vec3 p = viewPosition(vUv, g.a);
|
|
541
|
+
float l = luminance(centre.rgb);
|
|
542
|
+
float sigmaL = 4.0 * sqrt(texture2D(variance, vUv).r) + 1e-3;
|
|
543
|
+
float kernel[3];
|
|
544
|
+
kernel[0] = 3.0 / 8.0; kernel[1] = 1.0 / 4.0; kernel[2] = 1.0 / 16.0;
|
|
545
|
+
vec4 sum = vec4(0.0);
|
|
546
|
+
float weights = 0.0;
|
|
547
|
+
for (int y = -2; y <= 2; y++) {
|
|
548
|
+
for (int x = -2; x <= 2; x++) {
|
|
549
|
+
vec2 uv = vUv + vec2(x, y) * stepSize * texel;
|
|
550
|
+
vec4 gq = texture2D(guide, uv);
|
|
551
|
+
if (gq.a <= 0.0) continue;
|
|
552
|
+
vec4 c = texture2D(lighting, uv);
|
|
553
|
+
// Same surface: facing the same way, and on the centre's plane
|
|
554
|
+
// (distance from it relative to how far away it is).
|
|
555
|
+
float wn = pow(max(dot(g.rgb, gq.rgb), 0.0), 32.0);
|
|
556
|
+
float plane = abs(dot(g.rgb, viewPosition(uv, gq.a) - p)) / (0.01 * g.a);
|
|
557
|
+
float wp = exp(-plane);
|
|
558
|
+
// Not across a shadow edge: a difference the noise cannot explain.
|
|
559
|
+
float wl = exp(-abs(l - luminance(c.rgb)) / sigmaL);
|
|
560
|
+
float w = kernel[x < 0 ? -x : x] * kernel[y < 0 ? -y : y] * wn * wp * wl;
|
|
561
|
+
sum += c * w;
|
|
562
|
+
weights += w;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
gl_FragColor = weights > 0.0 ? sum / weights : centre;
|
|
566
|
+
}
|
|
567
|
+
`})}a(Fl,"atrousMaterial");function Gl(){return new ShaderMaterial({defines:{BASE_FLOOR:Hn},uniforms:{lighting:{value:null},guideLow:{value:null},guideHigh:{value:null},albedo:{value:null},lowSize:{value:null},projection:{value:null},transparent:{value:false},shadowMatte:{value:null},useShadow:{value:false},coverage:{value:null},guideProduct:{value:null},highTexel:{value:new Vector2},contact:{value:null},useContact:{value:false},floorOnly:{value:null},floorStrength:{value:1},cameraWorld:{value:new Matrix4},footprint:{value:new Vector4},floorFade:{value:new Vector3}},vertexShader:We,fragmentShader:`
|
|
568
|
+
${Vn}
|
|
569
|
+
uniform sampler2D lighting;
|
|
570
|
+
uniform sampler2D guideLow;
|
|
571
|
+
uniform sampler2D guideHigh;
|
|
572
|
+
uniform sampler2D albedo;
|
|
573
|
+
uniform vec2 lowSize;
|
|
574
|
+
uniform bool transparent;
|
|
575
|
+
uniform sampler2D shadowMatte;
|
|
576
|
+
uniform bool useShadow;
|
|
577
|
+
uniform sampler2D coverage; // the product alone (a), without floor or sweep \u2014 antialiased
|
|
578
|
+
uniform sampler2D guideProduct; // normal and depth of the product alone
|
|
579
|
+
uniform vec2 highTexel;
|
|
580
|
+
uniform sampler2D contact; // the contact-shadow decals over white: how much light the floor keeps
|
|
581
|
+
uniform bool useContact;
|
|
582
|
+
uniform sampler2D floorOnly; // the floor, path traced without the product
|
|
583
|
+
uniform float floorStrength;
|
|
584
|
+
uniform mat4 cameraWorld;
|
|
585
|
+
uniform vec4 footprint; // the product on the floor: min x, min z, max x, max z
|
|
586
|
+
uniform vec3 floorFade; // floor y, distance the shadow starts and ends fading
|
|
587
|
+
|
|
588
|
+
// How far from the product this pixel's patch of floor is.
|
|
589
|
+
float fromProduct() {
|
|
590
|
+
vec3 direction = (cameraWorld * vec4(normalize(vec3((vUv * 2.0 - 1.0) * projection, -1.0)), 0.0)).xyz;
|
|
591
|
+
vec3 origin = cameraWorld[3].xyz;
|
|
592
|
+
float t = (floorFade.x - origin.y) / direction.y;
|
|
593
|
+
if (t <= 0.0) return 1e6;
|
|
594
|
+
vec3 hit = origin + direction * t;
|
|
595
|
+
vec2 outside = max(vec2(footprint.x - hit.x, footprint.y - hit.z), vec2(hit.x - footprint.z, hit.z - footprint.w));
|
|
596
|
+
return length(max(outside, 0.0));
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// The lighting at this pixel for a surface with guide \`g\`: the 4 \xD7 4
|
|
600
|
+
// low-res texels around it, weighted by distance (a tent two texels
|
|
601
|
+
// wide) and by whether they lie on that surface. Four would do for
|
|
602
|
+
// broad surfaces, but a seam between two panels is thinner than a
|
|
603
|
+
// low-res texel, and with only four candidates it often found none on
|
|
604
|
+
// its own side: the seams came out as dotted lines.
|
|
605
|
+
vec4 upsample(vec4 g) {
|
|
606
|
+
vec3 p = viewPosition(vUv, g.a);
|
|
607
|
+
vec2 st = vUv * lowSize - 0.5;
|
|
608
|
+
vec2 origin = floor(st) - 1.0;
|
|
609
|
+
vec4 sum = vec4(0.0);
|
|
610
|
+
float weights = 0.0;
|
|
611
|
+
// The neighbour nearest this pixel's surface, for when none is on it.
|
|
612
|
+
vec4 nearest = texture2D(lighting, vUv);
|
|
613
|
+
float nearestPlane = 1e9;
|
|
614
|
+
for (int y = 0; y < 4; y++) {
|
|
615
|
+
for (int x = 0; x < 4; x++) {
|
|
616
|
+
vec2 texelPos = origin + vec2(x, y);
|
|
617
|
+
vec2 uv = (texelPos + 0.5) / lowSize;
|
|
618
|
+
vec2 d = abs(texelPos - st);
|
|
619
|
+
float wb = max(0.0, 1.0 - d.x / 2.0) * max(0.0, 1.0 - d.y / 2.0);
|
|
620
|
+
vec4 gq = texture2D(guideLow, uv);
|
|
621
|
+
vec4 lq = texture2D(lighting, uv);
|
|
622
|
+
float wn = gq.a > 0.0 ? pow(max(dot(g.rgb, gq.rgb), 0.0), 16.0) : 0.0;
|
|
623
|
+
float plane = gq.a > 0.0
|
|
624
|
+
? abs(dot(g.rgb, viewPosition(uv, gq.a) - p)) / (0.02 * g.a)
|
|
625
|
+
: 1e3;
|
|
626
|
+
if (plane < nearestPlane && wn > 0.5) {
|
|
627
|
+
nearestPlane = plane;
|
|
628
|
+
nearest = lq;
|
|
629
|
+
}
|
|
630
|
+
float w = wb * wn * exp(-plane);
|
|
631
|
+
sum += lq * w;
|
|
632
|
+
weights += w;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
// A silhouette pixel can find no low-res texel on its own surface \u2014
|
|
636
|
+
// they all lie on the floor or a farther part. Blending them anyway
|
|
637
|
+
// bit bright notches out of the edges; the nearest one does not.
|
|
638
|
+
return weights > 1e-4 ? sum / weights : nearest;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// The product's surface at a pixel its antialiased coverage says it
|
|
642
|
+
// touches. The guide is point-sampled, so at a silhouette the centre
|
|
643
|
+
// sample often lands on what is behind; the ring of neighbours finds
|
|
644
|
+
// the product's own normal and depth instead.
|
|
645
|
+
vec4 productGuide() {
|
|
646
|
+
vec4 g = texture2D(guideProduct, vUv);
|
|
647
|
+
if (g.a > 0.0) return g;
|
|
648
|
+
for (int ring = 1; ring <= 2; ring++) {
|
|
649
|
+
for (int y = -ring; y <= ring; y++) {
|
|
650
|
+
for (int x = -ring; x <= ring; x++) {
|
|
651
|
+
if (abs(x) != ring && abs(y) != ring) continue;
|
|
652
|
+
vec4 gq = texture2D(guideProduct, vUv + vec2(x, y) * highTexel * float(1));
|
|
653
|
+
if (gq.a > 0.0) return gq;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
return g;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
void main() {
|
|
661
|
+
vec4 a = texture2D(albedo, vUv);
|
|
662
|
+
vec4 cov = texture2D(coverage, vUv);
|
|
663
|
+
float covered = cov.a;
|
|
664
|
+
vec3 base;
|
|
665
|
+
vec4 light;
|
|
666
|
+
if (covered > 0.0) {
|
|
667
|
+
// On the product, or on its antialiased edge: its own base colour
|
|
668
|
+
// and its own surface, so an edge pixel is lit like the product and
|
|
669
|
+
// not like the backdrop behind it \u2014 that is what drew a bright
|
|
670
|
+
// fringe and a staircase along every leg.
|
|
671
|
+
base = cov.rgb / covered;
|
|
672
|
+
vec4 g = productGuide();
|
|
673
|
+
light = g.a > 0.0 ? upsample(g) : texture2D(lighting, vUv);
|
|
674
|
+
} else {
|
|
675
|
+
base = a.rgb / max(a.a, 1e-4);
|
|
676
|
+
vec4 g = texture2D(guideHigh, vUv);
|
|
677
|
+
light = g.a > 0.0 ? upsample(g) : texture2D(lighting, vUv);
|
|
678
|
+
}
|
|
679
|
+
// \xD7 the base floored as demodulation floored it. Multiplied back by
|
|
680
|
+
// the bare base, every channel under the floor kept only base/floor of
|
|
681
|
+
// its light: the blue of a wood stain (~0.01 linear) came back at a
|
|
682
|
+
// third, and every stain turned gold.
|
|
683
|
+
vec3 colour = light.rgb * max(base, vec3(BASE_FLOOR));
|
|
684
|
+
if (useShadow) {
|
|
685
|
+
// The floor traced with and without the product never quite agrees
|
|
686
|
+
// far from it (noise, the product's own bounce light): left in, a
|
|
687
|
+
// percent or two of "shadow" veiled the whole background and drew
|
|
688
|
+
// the floor's far edge as a dotted line. Below a few percent it is
|
|
689
|
+
// not a shadow anyone could see on a floor, so it fades out.
|
|
690
|
+
float darkening = texture2D(shadowMatte, vUv).r;
|
|
691
|
+
darkening *= smoothstep(0.03, 0.1, darkening);
|
|
692
|
+
// The shadow stays AROUND the product. The studio's low, soft fill
|
|
693
|
+
// and rim lay long faint shadows across the whole floor, and at full
|
|
694
|
+
// strength they flooded it; so the shadow fades out with distance
|
|
695
|
+
// from the product's footprint, and the setup scales what is left.
|
|
696
|
+
darkening *= 1.0 - smoothstep(floorFade.y, floorFade.z, fromProduct());
|
|
697
|
+
darkening *= floorStrength;
|
|
698
|
+
// The contact decals on top: the dark spot where a foot meets the
|
|
699
|
+
// floor, which the traced shadow has at too few pixels to keep.
|
|
700
|
+
float kept = (1.0 - darkening) * (useContact ? luminance(texture2D(contact, vUv).rgb) : 1.0);
|
|
701
|
+
if (transparent) {
|
|
702
|
+
// The product over its shadow (black at the shadow's opacity),
|
|
703
|
+
// straight alpha, as a PNG wants it.
|
|
704
|
+
float opacity = covered + (1.0 - covered) * (1.0 - kept);
|
|
705
|
+
gl_FragColor = vec4(opacity > 0.0 ? colour * covered / opacity : vec3(0.0), opacity);
|
|
706
|
+
} else {
|
|
707
|
+
vec3 floorColour = texture2D(floorOnly, vUv).rgb * kept;
|
|
708
|
+
gl_FragColor = vec4(mix(floorColour, colour, covered), 1.0);
|
|
709
|
+
}
|
|
710
|
+
} else {
|
|
711
|
+
gl_FragColor = vec4(colour, transparent ? covered : 1.0);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
`})}a(Gl,"composeMaterial");function jn(e){let o=new FullScreenQuad,t={normalDepth:Il(),demodulate:El(),variance:zl(),atrous:Fl(),compose:Gl(),shadow:Ll(),copy:_l(),mask:Bl(),gaussian:kl()},r=new Map,a$1=new WeakMap,i=new Color;function s(h,S,g,D=0){let O=r.get(h);return (!O||O.width!==S||O.height!==g)&&(O?.dispose(),O=new WebGLRenderTarget(S,g,{type:HalfFloatType,samples:D}),r.set(h,O)),O}a(s,"target");function l(h,S){o.material=h,e.setRenderTarget(S),o.render(e);}a(l,"pass");function c(h){let S=a$1.get(h);S||(S=new MeshBasicMaterial,a$1.set(h,S));let g=h;return g.color?S.color.copy(g.color):S.color.setRGB(1,1,1),(S.map!==(g.map??null)||S.vertexColors!==(g.vertexColors??false))&&(S.needsUpdate=true),S.map=g.map??null,S.alphaMap=g.alphaMap??null,S.vertexColors=g.vertexColors??false,S.side=h.side,S.transparent=h.transparent,S.opacity=h.opacity,S.alphaTest=h.alphaTest,S}a(c,"albedoOf");function f(h,S,g,D,O,L=[]){let y=L.filter(F=>F.visible);for(let F of y)F.visible=false;let A=s(`albedo${O}`,g,D,4),k=s(`guide${O}`,g,D),I=h.background,U=e.getClearColor(i).clone(),X=e.getClearAlpha(),C=[];h.traverseVisible(F=>{let G=F;G.isMesh&&(C.push([G,G.material]),G.material=Array.isArray(G.material)?G.material.map(c):c(G.material));}),h.background=null,e.setClearColor(0,0),e.setRenderTarget(A),e.clear(),e.render(h,S);for(let[F,G]of C)F.material=G;h.overrideMaterial=t.normalDepth,e.setRenderTarget(k),e.clear(),e.render(h,S),h.overrideMaterial=null,h.background=I,e.setClearColor(U,X),e.setRenderTarget(null);for(let F of y)F.visible=true;return {albedo:A,guide:k}}a(f,"renderGuides");function u(h,S,g,D,O){let L=s("decals",g,D,4),y=h.children.filter(C=>C.visible);for(let C of y)C.visible=false;for(let C of O)C.visible=true;let A=je(),k=qe();Te(1),xe(0),rt();let I=h.background;h.background=null;let U=e.getClearColor(i).clone(),X=e.getClearAlpha();e.setClearColor(16777215,1),e.setRenderTarget(L),e.clear(),e.render(h,S),e.setClearColor(U,X),h.background=I,Te(A),xe(k),rt();for(let C of O)C.visible=false;for(let C of y)C.visible=true;return L}a(u,"renderDecals");function d(h,S,g,D,O,L){let y=s(`${h}A`,D,O),A=s(`${h}B`,D,O),k=t.mask.uniforms;k.source.value=S,k.cover.value=g,k.useCover.value=g!==null,l(t.mask,y);let I=t.gaussian.uniforms;for(let U of L)for(let X of [new Vector2(U/D,0),new Vector2(0,U/O)])I.image.value=y.texture,I.direction.value=X,l(t.gaussian,A),[y,A]=[A,y];return y}a(d,"smoothFloor");function M(h,S,g,D,O,L){t.variance.uniforms.lighting.value=h.texture,t.variance.uniforms.texel.value=O,l(t.variance,g);let y=h,A=S,k=t.atrous.uniforms;k.guide.value=D,k.variance.value=g.texture,k.texel.value=O,k.projection.value=L;for(let I of [1,2,4,8])k.lighting.value=y.texture,k.stepSize.value=I,l(t.atrous,A),[y,A]=[A,y];return y}a(M,"denoise");function v(h,S,g){let D=s("kept",S,g);return t.copy.uniforms.source.value=h,l(t.copy,D),e.setRenderTarget(null),D.texture}a(v,"keep");function m(h){let{scene:S,camera:g,traced:D,width:O,height:L,lowWidth:y,lowHeight:A}=h,k=Math.tan(g.fov*Math.PI/360),I={x:k*g.aspect,y:k},U=f(S,g,O,L,"High",h.hide),X=h.floor&&!h.transparent?f(S,g,O,L,"Coverage",[...h.hide??[],...h.hideForCoverage??[]]):U,C=X.albedo,F=f(S,g,y,A,"Low"),G={x:1/y,y:1/A},V=s("lightingA",y,A),N=s("lightingB",y,A),B=s("variance",y,A);t.demodulate.uniforms.traced.value=D,t.demodulate.uniforms.albedo.value=F.albedo.texture,l(t.demodulate,V);let p=M(V,N,B,F.guide.texture,G,I),R=null,b=null;if(h.floor){let z=f(S,g,y,A,"CoverageLow",[...h.hide??[],...h.hideForCoverage??[]]).albedo,$=s("matte",y,A);t.shadow.uniforms.withProduct.value=h.floor.withProduct,t.shadow.uniforms.floorOnly.value=h.floor.floorOnly,l(t.shadow,$),R=d("shadow",$.texture,z.texture,y,A,Ol),h.transparent||(b=d("floor",h.floor.floorOnly,null,y,A,Rl));}let P=s("output",O,L),x=t.compose.uniforms;x.lighting.value=p.texture,x.guideLow.value=F.guide.texture,x.guideHigh.value=U.guide.texture,x.albedo.value=U.albedo.texture,x.lowSize.value={x:y,y:A},x.projection.value=I,x.transparent.value=h.transparent,x.useShadow.value=R!==null,x.shadowMatte.value=R?.texture??null,x.coverage.value=C.texture,x.guideProduct.value=X.guide.texture;let W=h.floor&&h.decals?.length?h.decals:[];if(x.useContact.value=W.length>0,x.contact.value=W.length?u(S,g,O,L,W).texture:null,x.highTexel.value=new Vector2(1/O,1/L),x.floorOnly.value=b?.texture??null,h.floor){let{footprint:z,fade:$,strength:Y}=h.floor;x.floorStrength.value=Y,x.cameraWorld.value=g.matrixWorld,x.footprint.value=new Vector4(z.min.x,z.min.z,z.max.x,z.max.z),x.floorFade.value=new Vector3(z.min.y,$[0],$[1]);}return l(t.compose,P),e.setRenderTarget(null),P.texture}a(m,"reconstruct");function w(){o.dispose();for(let h of Object.values(t))h.dispose();for(let h of r.values())h.dispose();}return a(w,"dispose"),{reconstruct:m,keep:v,dispose:w}}a(jn,"createReconstructor");function $n(e,o,t=512){let r=t/2,a=new WebGLRenderTarget(t,r,{type:FloatType}),i=new ShaderMaterial({uniforms:{cube:{value:o}},vertexShader:`
|
|
715
|
+
varying vec2 vUv;
|
|
716
|
+
void main() {
|
|
717
|
+
vUv = uv;
|
|
718
|
+
gl_Position = vec4(position.xy, 0.0, 1.0);
|
|
719
|
+
}
|
|
720
|
+
`,fragmentShader:`
|
|
721
|
+
uniform samplerCube cube;
|
|
722
|
+
varying vec2 vUv;
|
|
723
|
+
#define PI 3.141592653589793
|
|
724
|
+
void main() {
|
|
725
|
+
// The inverse of equirectUv: u = atan(z, x) / 2\u03C0 + 0.5, v = asin(y) / \u03C0 + 0.5.
|
|
726
|
+
float phi = (vUv.x - 0.5) * 2.0 * PI;
|
|
727
|
+
float theta = (vUv.y - 0.5) * PI;
|
|
728
|
+
vec3 direction = vec3(cos(theta) * cos(phi), sin(theta), cos(theta) * sin(phi));
|
|
729
|
+
gl_FragColor = vec4(textureCube(cube, direction).rgb, 1.0);
|
|
730
|
+
}
|
|
731
|
+
`,depthTest:false,depthWrite:false}),s=new FullScreenQuad(i),l=e.getRenderTarget();e.setRenderTarget(a),s.render(e),e.setRenderTarget(l);let c=new Float32Array(t*r*4);e.readRenderTargetPixels(a,0,0,t,r,c),s.dispose(),i.dispose(),a.dispose();let f=new DataTexture(c,t,r,RGBAFormat,FloatType);return f.mapping=EquirectangularReflectionMapping,f.minFilter=LinearFilter,f.magFilter=LinearFilter,f.needsUpdate=true,f}a($n,"cubeToEquirect");var Jl=1024,Kl=.6;function oa(e){let{product:o,bounds:t,floorY:r}=e,a$1=e.resolution??Jl,i=t.getCenter(new Vector3),s=t.getSize(new Vector3),l=Math.max(s.x,s.z)/2+s.length()*Kl,c={minFilter:LinearFilter,magFilter:LinearFilter,wrapS:ClampToEdgeWrapping,wrapT:ClampToEdgeWrapping,depthBuffer:false,stencilBuffer:false},f=new WebGLRenderTarget(a$1,a$1,c),u=new WebGLRenderTarget(a$1,a$1,c),d=new OrthographicCamera(-l,l,l,-l,.1,20);d.position.set(i.x,r+10,i.z),d.rotation.x=-Math.PI/2,d.updateMatrixWorld();let M=new MeshBasicMaterial({color:16777215,depthTest:false,depthWrite:false}),v=new Scene,m=new ShaderMaterial({uniforms:{tDiffuse:{value:null},direction:{value:new Vector2}},depthTest:false,depthWrite:false,vertexShader:`
|
|
732
|
+
varying vec2 vUv;
|
|
733
|
+
void main() {
|
|
734
|
+
vUv = uv;
|
|
735
|
+
gl_Position = vec4(position.xy, 0.0, 1.0);
|
|
736
|
+
}
|
|
737
|
+
`,fragmentShader:`
|
|
738
|
+
uniform sampler2D tDiffuse;
|
|
739
|
+
uniform vec2 direction;
|
|
740
|
+
varying vec2 vUv;
|
|
741
|
+
void main() {
|
|
742
|
+
vec4 sum = texture2D(tDiffuse, vUv) * 0.2270270270;
|
|
743
|
+
sum += texture2D(tDiffuse, vUv + direction * 1.0) * 0.1945945946;
|
|
744
|
+
sum += texture2D(tDiffuse, vUv - direction * 1.0) * 0.1945945946;
|
|
745
|
+
sum += texture2D(tDiffuse, vUv + direction * 2.0) * 0.1216216216;
|
|
746
|
+
sum += texture2D(tDiffuse, vUv - direction * 2.0) * 0.1216216216;
|
|
747
|
+
sum += texture2D(tDiffuse, vUv + direction * 3.0) * 0.0540540541;
|
|
748
|
+
sum += texture2D(tDiffuse, vUv - direction * 3.0) * 0.0540540541;
|
|
749
|
+
sum += texture2D(tDiffuse, vUv + direction * 4.0) * 0.0162162162;
|
|
750
|
+
sum += texture2D(tDiffuse, vUv - direction * 4.0) * 0.0162162162;
|
|
751
|
+
gl_FragColor = sum;
|
|
752
|
+
}
|
|
753
|
+
`}),w=new Mesh(new PlaneGeometry(2,2),m),h=new Scene;h.add(w);let S=new OrthographicCamera(-1,1,1,-1,0,1);function g(y){let A=y.y-r;return new Matrix4().set(A,-y.x,0,y.x*r,0,A-y.y,0,y.y*r,0,-y.z,A,y.z*r,0,-1,0,A+r)}a(g,"projection");function D(y,A){let k=g(A);v.clear();for(let I of o)I.updateMatrixWorld(true),I.traverse(U=>{let X=U;if(!X.isMesh||!X.visible||X.name==="moduleContactShadow")return;let C=new Mesh(X.geometry,M);C.matrixAutoUpdate=false,C.matrix.multiplyMatrices(k,X.matrixWorld),C.frustumCulled=false,v.add(C);});y.setRenderTarget(f),y.setClearColor(0,0),y.clear(true,false,false),y.render(v,d),v.clear();}a(D,"drawSilhouette");function O(y,A){for(let k of [new Vector2(1,0),new Vector2(0,1)])m.uniforms.tDiffuse.value=f.texture,m.uniforms.direction.value.copy(k).multiplyScalar(A/a$1),y.setRenderTarget(u),y.clear(true,false,false),y.render(h,S),[f,u]=[u,f];}a(O,"blurPass");function L(y,A){let k=y.getRenderTarget(),I=y.autoClear,U=y.getClearColor(new Color),X=y.getClearAlpha();y.autoClear=false;try{D(y,A.light);let C=A.blurWorld/(2*l)*a$1,F=Math.max(C/4,.5);for(let G of [1,.75,.5,.25])O(y,F*G);}finally{y.setRenderTarget(k),y.setClearColor(U,X),y.autoClear=I;}}return a(L,"update"),{get texture(){return f.texture},halfSize:l,update:L,dispose(){f.dispose(),u.dispose(),M.dispose(),m.dispose(),w.geometry.dispose();}}}a(oa,"createFloorShadow");var ia="// konfigure: studio tone curve",aa="vec3 CustomToneMapping( vec3 color ) { return color; }",ec=`vec3 CustomToneMapping( vec3 color ) {
|
|
754
|
+
${ia}
|
|
755
|
+
const float StartCompression = 0.8 - 0.04;
|
|
756
|
+
const float Desaturation = 0.15;
|
|
757
|
+
color *= toneMappingExposure;
|
|
758
|
+
float peak = max( color.r, max( color.g, color.b ) );
|
|
759
|
+
if ( peak < StartCompression ) return color;
|
|
760
|
+
float d = 1. - StartCompression;
|
|
761
|
+
float newPeak = 1. - d * d / ( peak + d - StartCompression );
|
|
762
|
+
color *= newPeak / peak;
|
|
763
|
+
float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );
|
|
764
|
+
return mix( color, vec3( newPeak ), g );
|
|
765
|
+
}`;function sa(){let e=ShaderChunk.tonemapping_pars_fragment;return e.includes(ia)?CustomToneMapping:e.includes(aa)?(ShaderChunk.tonemapping_pars_fragment=e.replace(aa,ec),CustomToneMapping):NeutralToneMapping}a(sa,"studioToneMapping");var No=Math.PI/180,fc=.8;function mc(e){let o=e*16,t=e*8,r=e*4.5,a=e*1.5,i=e*10,s=[[-r,t]];for(let f=0;f<=24;f++){let u=f/24*(Math.PI/2);s.push([-(r-a)-Math.cos(u)*a,a-Math.sin(u)*a]);}s.push([i,0]);let l=new PlaneGeometry(o,1,1,s.length-1),c=l.attributes.position;for(let[f,[u,d]]of s.entries())for(let M of [0,1]){let v=f*2+M;c.setXYZ(v,c.getX(v),d,u);}return l.computeVertexNormals(),l}a(mc,"sweepGeometry");function hc(e,o){let t=new MeshBasicMaterial({color:0,transparent:true,depthWrite:false,opacity:.35}),r={footprint:{value:[e.min.x,e.min.z,e.max.x,e.max.z]},fadeRange:{value:o}};return t.onBeforeCompile=a=>{Object.assign(a.uniforms,r),a.vertexShader=a.vertexShader.replace("#include <common>",`#include <common>
|
|
766
|
+
varying vec3 vFadeWorld;`).replace("#include <project_vertex>",`#include <project_vertex>
|
|
767
|
+
vFadeWorld = (modelMatrix * vec4(transformed, 1.0)).xyz;`),a.fragmentShader=a.fragmentShader.replace("#include <common>",["#include <common>","varying vec3 vFadeWorld;","uniform vec4 footprint; // the product on the floor: min x, min z, max x, max z","uniform vec2 fadeRange; // distance from the footprint the shadow starts and ends fading","float fromFootprint() {"," vec2 outside = max(vec2(footprint.x - vFadeWorld.x, footprint.y - vFadeWorld.z),"," vec2(vFadeWorld.x - footprint.z, vFadeWorld.z - footprint.w));"," return length(max(outside, 0.0));","}"].join(`
|
|
768
|
+
`)).replace("#include <alphamap_fragment>",`#include <alphamap_fragment>
|
|
769
|
+
diffuseColor.a *= 1.0 - smoothstep(fadeRange.x, fadeRange.y, fromFootprint());`);},t}a(hc,"fadedFloorMaterial");function ca(e){let{scene:o,renderer:t,product:r}=e,a$1=e.bounds.clone(),i=a$1.getCenter(new Vector3),s=a$1.getSize(new Vector3),l=Math.max(s.length(),.5),c=a$1.min.y,f=new Map;for(let B of o.children)r.includes(B)||(f.set(B,B.visible),B.visible=false);function u(){return o.children.filter(B=>B.name==="moduleContactShadow")}a(u,"contactShadows");let d={contactShadowFade:je(),contactShadowCoverage:qe(),bakedShade:be.value.clone(),fog:o.fog,background:o.background,environment:o.environment,environmentIntensity:o.environmentIntensity,environmentRotation:o.environmentRotation.clone(),toneMapping:t.toneMapping,exposure:t.toneMappingExposure,shadowsEnabled:t.shadowMap.enabled};o.fog=null,t.shadowMap.enabled=true,xe(0),be.value.set(0,0);let M=new Group;M.name="photoStage",o.add(M);let v=new MeshStandardMaterial({roughness:.95,metalness:0,side:DoubleSide}),m=new Mesh(mc(l),v);m.position.set(i.x,c,i.z),m.receiveShadow=false,M.add(m);let w=oa({product:e.product,bounds:a$1,floorY:c}),h=hc(a$1,[s.length()*.1,s.length()*.35]);h.alphaMap=w.texture;let S=new Mesh(new PlaneGeometry(w.halfSize*2,w.halfSize*2),h);S.rotation.x=-Math.PI/2,S.position.set(i.x,c+.001,i.z),M.add(S);let g=new MeshStandardMaterial({color:16777215,roughness:1}),D=new Mesh(new PlaneGeometry(l*16,l*16),g);D.rotation.x=-Math.PI/2,D.position.set(i.x,c,i.z),M.add(D);let O=new Map;function L(B){let p=O.get(B);if(!p){let R=new SpotLight(16777215,1,0,Math.PI/3,.9,2);R.target.position.copy(i);let b=new RectAreaLight;M.add(R,R.target,b),p={raster:R,area:b},O.set(B,p);}return p}a(L,"rigFor");let y=new Map;function A(B){let p=y.get(B);if(!p){let R=new $e(B),b=new WebGLCubeRenderTarget(256,{type:HalfFloatType});new CubeCamera(.1,100,b).update(t,R);let P=bt(t)?$n(t,b.texture):null,x=new PMREMGenerator(t),W=(P?x.fromEquirectangular(P):x.fromCubemap(b.texture)).texture;x.dispose(),b.dispose(),R.traverse(z=>{let $=z;if($.isMesh){$.geometry.dispose();for(let Y of [$.material].flat())Y.dispose();}}),p={equirect:P,pmrem:W},y.set(B,p);}return p}a(A,"environmentFor");let k=l*4;function I(B,p){let R=p+B.azimuth*No,b=B.elevation*No;return new Vector3(Math.sin(R)*Math.cos(b),Math.sin(b),Math.cos(R)*Math.cos(b)).multiplyScalar(k).add(i)}a(I,"lightPosition");let U=s.length()*.25;function X(B,p,R){let b=a$1.clone();if(!R||B.live)return b;let P=new Vector3,x=Math.atan2(p.x,p.z),W=[new Vector3(a$1.min.x,a$1.min.y,a$1.min.z),new Vector3(a$1.min.x,a$1.min.y,a$1.max.z),new Vector3(a$1.min.x,a$1.max.y,a$1.min.z),new Vector3(a$1.min.x,a$1.max.y,a$1.max.z),new Vector3(a$1.max.x,a$1.min.y,a$1.min.z),new Vector3(a$1.max.x,a$1.min.y,a$1.max.z),new Vector3(a$1.max.x,a$1.max.y,a$1.min.z),new Vector3(a$1.max.x,a$1.max.y,a$1.max.z)],z=B.lights.find($=>$.id==="key"&&$.enabled);for(let $ of z?[z]:B.lights.filter(Y=>Y.enabled)){let Y=I($,x);for(let H of W){let Q=Y.y-H.y;if(Q<=0)continue;let K=new Vector3().lerpVectors(Y,H,(Y.y-c)/Q),ne=new Vector3(Math.max(a$1.min.x-K.x,K.x-a$1.max.x,0),0,Math.max(a$1.min.z-K.z,K.z-a$1.max.z,0)),ge=ne.length();ge>U&&ne.multiplyScalar(U/ge),P.x=Math.max(P.x,ne.x),P.z=Math.max(P.z,ne.z);}}return b.expandByVector(P)}a(X,"framing");let C=new Color;function F(B,p){let R=A(B.environment);o.environment=p.mode==="path"&&R.equirect?R.equirect:R.pmrem,o.environmentIntensity=B.environmentIntensity,o.environmentRotation=new Euler(0,B.environmentRotation*No,0),o.background=p.transparent?null:new Color(B.backdrop),t.toneMapping=sa(),t.toneMappingExposure=Math.pow(2,B.exposure);let b=Math.atan2(p.cameraDirection.x,p.cameraDirection.z);m.visible=!p.transparent,m.rotation.y=b,v.color.set(B.backdrop);let P=!p.transparent||p.shadow,x=B.lights.find(z=>z.id==="key"&&z.enabled);if(S.visible=p.mode==="raster"&&P&&!!x,S.visible&&x){let z=l*(.08+x.softness*1.4);w.update(t,{light:I(x,b),blurWorld:z*s.y/2/k}),h.opacity=B.floorShadow*(1-x.softness*.35)*.7;}D.visible=p.transparent&&p.shadow&&p.mode==="path";for(let z of u())z.visible=p.mode==="raster"&&P;Te(B.floorShadow);let W=k;for(let z of B.lights){let $=L(z.id),Y=I(z,b);Lo(z.temperature,C);let H=$.raster;if(H.visible=z.enabled&&p.mode==="raster",H.position.copy(Y),H.color.copy(C),H.intensity=z.intensity*W*W*fc,H.castShadow=z.id==="key",H.castShadow){let ne=H.shadow.camera;ne.near=W*.2,ne.far=W*3,H.shadow.focus=.5,H.shadow.mapSize.set(2048,2048),H.shadow.radius=1+z.softness*3,H.shadow.intensity=1-z.softness*.35,H.shadow.bias=-2e-4,H.shadow.normalBias=.01,H.shadow.needsUpdate=true,t.shadowMap.needsUpdate=true;}let Q=$.area,K=l*(.08+z.softness*1.4);Q.visible=z.enabled&&p.mode==="path",Q.width=K,Q.height=K,Q.position.copy(Y),Q.lookAt(i),Q.color.copy(C),Q.intensity=z.intensity*W*W/(K*K);}}a(F,"apply");function G(){o.remove(M),m.geometry.dispose(),v.dispose(),S.geometry.dispose(),h.dispose(),w.dispose(),D.geometry.dispose(),g.dispose();for(let{raster:B}of O.values())B.shadow.dispose();for(let B of y.values())B.equirect?.dispose(),B.pmrem.dispose();for(let B of r)B.visible=true;for(let[B,p]of f)B.visible=p;Te(d.contactShadowFade),xe(d.contactShadowCoverage),be.value.copy(d.bakedShade),o.fog=d.fog,o.background=d.background,o.environment=d.environment,o.environmentIntensity=d.environmentIntensity,o.environmentRotation=d.environmentRotation,t.toneMapping=d.toneMapping,t.toneMappingExposure=d.exposure,t.shadowMap.enabled=d.shadowsEnabled,t.shadowMap.needsUpdate=true;}a(G,"dispose");function V(B){for(let p of r)p.visible=B;}a(V,"setProductVisible");function N(B){let p={fade:je(),coverage:qe(),shade:be.value.clone()},R=[];function b(P){for(let x of o.children)x.name!==P||!x.visible||(x.visible=false,R.push(()=>x.visible=true));}a(b,"hide"),M.visible=false;for(let[P,x]of f)P.visible=x;if(V(true),Te(d.contactShadowFade),xe(d.contactShadowCoverage),be.value.copy(d.bakedShade),o.fog=d.fog,o.background=d.background,o.environment=d.environment,o.environmentIntensity=d.environmentIntensity,o.environmentRotation=d.environmentRotation,t.toneMapping=d.toneMapping,t.toneMappingExposure=d.exposure,B.transparent){if(o.background=null,o.fog=null,b("room"),!B.shadow)for(let P of ["bakedFloorShadow","moduleContactShadow","floor"])b(P);}else if(B.backdrop){let P=new Color(B.backdrop);if(o.background=P,d.fog instanceof Fog){let W=d.fog.color.clone();d.fog.color.copy(P),R.push(()=>d.fog instanceof Fog&&d.fog.color.copy(W));}let x=o.getObjectByName("room");if(x instanceof Mesh&&x.material instanceof MeshStandardMaterial){let W=x.material,z=W.color.clone();W.color.copy(P),R.push(()=>W.color.copy(z));}}return B.exposure&&(d.toneMapping===NoToneMapping&&(t.toneMapping=LinearToneMapping),t.toneMappingExposure=d.exposure*Math.pow(2,B.exposure)),()=>{for(let P of R.reverse())P();for(let P of f.keys())P.visible=false;M.visible=true,o.fog=null,Te(p.fade),xe(p.coverage),be.value.copy(p.shade);}}return a(N,"live"),{bounds:a$1,apply:F,framing:X,shadowFloor:D,backdrop:m,get contactShadows(){return u()},setProductVisible:V,live:N,dispose:G}}a(ca,"createPhotoStage");var bc=["front","isometric","left","right","back","top"];function yc(e){let{data:o}=e;for(let t=0;t<o.length;t+=4){let r=o[t+3];r===0||r===255||(o[t]=Math.min(255,Math.round(o[t]*255/r)),o[t+1]=Math.min(255,Math.round(o[t+1]*255/r)),o[t+2]=Math.min(255,Math.round(o[t+2]*255/r)));}}a(yc,"unpremultiply");function ua(e){let{data:o}=e,t=Math.max(4,Math.floor(o.length/4/4096))*4;for(let r=0;r<o.length;r+=t)if(o[r]||o[r+1]||o[r+2]||o[r+3])return false;return true}a(ua,"isBlank");var da=128,xc=2500,Sc=12,pa=.5,fa=64,jo=75e4,wc=jo/(2400*1600),Mc=3e6,Pc=12e4,Cc=450,Tc=6;function Dc(e){let{scene:o,renderer:t,modules:r,labels:a$1}=e,i=zn(r);if(!i)throw new Error("No modules available for capture");let s=ca({scene:o,renderer:t,product:e.product,bounds:i}),l=new Map,c=null,f=null,u=Promise.resolve();function d(C){let F=u.then(C,C);return u=F.catch(()=>{}),F}a(d,"exclusive");function M(C,F,G,V){let N=_o(C),B=N.fov??Gn,p=zo(N),R=s.framing(G,p,V),b=Fn(R,B,F,p)*(N.zoom??1),P=R.getCenter(new Vector3),x=new PerspectiveCamera(B,F,.05,1e3);x.layers.enable(1),x.position.copy(P).addScaledVector(p,b),x.lookAt(P),x.updateMatrixWorld();let W=P.clone();W.y+=Wn(R,x,P),x.lookAt(W),x.updateMatrixWorld();let z=N.name in a$1?a$1[N.name]:N.name;return {camera:x,label:z,name:N.name}}a(M,"cameraFor");function v(C){return C.position.clone().sub(s.bounds.getCenter(new Vector3)).normalize()}a(v,"directionOf");function m(C,F,G,V,N){s.apply(C,{cameraDirection:v(F),mode:G,transparent:V,shadow:N});}a(m,"stageFor");function w(C,F){return t.shadowMap.needsUpdate=true,Xe(t),C.render(o,F)}a(w,"rasterise");function h(C,F){let G=`${C}x${F}`,V=l.get(G);return V||(V=Fo(t,C,F,{samples:4}),l.set(G,V)),V}a(h,"previewTargetFor");function S(C,F,G,V,N,B){let p=s.live({transparent:N,shadow:B,backdrop:C.backdrop||null,exposure:C.exposure});try{return D(F,G,V)}finally{p();}}a(S,"renderLive");let g=new Vector2;function D(C,F,G){let V=t.getContext(),N=V.getParameter(V.MAX_VIEWPORT_DIMS),B=Math.min(2048,N[0],N[1]),p=t.getPixelRatio(),R=t.getSize(g).clone(),b=t.getRenderTarget(),P=new ImageData(F,G);Xe(t),t.setPixelRatio(1),t.setSize(Math.min(B,F),Math.min(B,G),false),t.setRenderTarget(null);let x=Math.min(B,F,V.drawingBufferWidth),W=Math.min(B,G,V.drawingBufferHeight),z=new Uint8Array(x*W*4);try{for(let $=0;$<G;$+=W)for(let Y=0;Y<F;Y+=x){let H=Math.min(x,F-Y),Q=Math.min(W,G-$);C.setViewOffset(F,G,Y,$,H,Q),t.setViewport(0,0,H,Q),t.render(o,C),V.readPixels(0,0,H,Q,V.RGBA,V.UNSIGNED_BYTE,z);for(let K=0;K<Q;K++){let ne=(Q-1-K)*H*4;P.data.set(z.subarray(ne,ne+H*4),(($+K)*F+Y)*4);}}}finally{C.clearViewOffset(),t.setPixelRatio(p),t.setSize(R.x,R.y,false),t.setRenderTarget(b);}return yc(P),P}a(D,"drawLikeViewport");function O(C,F,G){let{transparent:V,shadow:N,width:B,height:p}=G,R=h(B,p),b=M(F,B/p,C,!V||N);return b?C.live?S(C,b.camera,B,p,V,N):(s.setProductVisible(true),m(C,b.camera,"raster",V,N),w(R,b.camera)):null}a(O,"preview");async function L(C){let F=Math.min(1,Math.sqrt(C.pathPixels/(C.width*C.height))),G=Math.round(C.width*F),V=Math.round(C.height*F),N=!C.transparent||C.shadow,B=N?.75:1;c??=await Rc(t),f??=jn(t),ma(c,G,V),Xe(t),m(C.setup,C.camera,"path",C.transparent,C.shadow),c.setScene(o,C.camera),await ha(t,c,{samples:C.samples,minSamples:C.minSamples,timeLimit:C.timeLimit*B,signal:C.signal,onFraction:a(R=>C.onFraction?.(R*B),"onFraction")});let p;if(N){let R=f.keep(c.target.texture,G,V);m(C.setup,C.camera,"path",C.transparent,C.shadow),s.setProductVisible(false);try{ma(c,Math.max(64,Math.round(G*pa)),Math.max(64,Math.round(V*pa))),c.setScene(o,C.camera),await ha(t,c,{samples:Math.min(C.samples,fa),minSamples:Math.min(C.minSamples,fa),timeLimit:C.timeLimit*(1-B),signal:C.signal,onFraction:a(P=>C.onFraction?.(B+P*(1-B)),"onFraction")});}finally{s.setProductVisible(true);}let b=s.bounds.getSize(new Vector3).length();p={withProduct:R,floorOnly:c.target.texture,footprint:s.bounds,fade:[b*.1,b*.35],strength:C.setup.floorShadow};}return m(C.setup,C.camera,"path",C.transparent,C.shadow),f.reconstruct({scene:o,camera:C.camera,traced:p?.withProduct??c.target.texture,width:C.width,height:C.height,lowWidth:G,lowHeight:V,transparent:C.transparent,floor:p,decals:p?s.contactShadows:[],hide:[s.shadowFloor],hideForCoverage:[s.backdrop]})}a(L,"trace");function y(C,F,G){return d(async()=>{if(!I||U||C.live)return null;Xo(G.signal);let{width:V,height:N,transparent:B,shadow:p}=G,R=M(F,V/N,C,!B||p);if(!R)return null;let b=await L({setup:C,camera:R.camera,width:V,height:N,transparent:G.transparent,shadow:G.shadow,pathPixels:Pc,samples:da,minSamples:Tc,timeLimit:Cc,signal:G.signal}),P=h(V,N).encode(b);return ua(P)?(U=true,null):P})}a(y,"refine");function A(C){return d(()=>k(C))}a(A,"capture");async function k(C){let{setup:F,width:G,height:V,transparent:N,shadow:B,signal:p,onProgress:R}=C,b=C.quality==="best"&&(F.live||I&&!U)?"best":"fast",P=C.samples??da,x=Math.min(Mc,Math.max(jo,Math.round(G*V*wc))),W=(C.timeLimit??xc)*(x/jo),z=Fo(t,G,V),$=[];try{for(let[Y,H]of C.angles.entries()){let Q=M(H,G/V,F,!N||B);if(!Q)continue;let K=a(ge=>R?.({index:Y,count:C.angles.length,angle:Q.name,label:Q.label,fraction:ge}),"report");K(0),Xo(p);let ne=null;if(F.live)ne=S(F,Q.camera,G,V,N,B),await qo();else if(b==="best"&&!U){let ge=await L({setup:F,camera:Q.camera,width:G,height:V,transparent:N,shadow:B,pathPixels:x,samples:P,minSamples:Sc,timeLimit:W,signal:p,onFraction:K});ne=z.encode(ge),ua(ne)&&(U=!0,ne=null);}ne||(m(F,Q.camera,"raster",N,B),ne=w(z,Q.camera),await qo()),$.push({name:Q.name,label:Q.label,dataUrl:_n(ne)}),K(1);}return $}finally{z.dispose();}}a(k,"captureNow");let I=bt(t)&&!Ft(t),U=false;function X(){for(let C of l.values())C.dispose();c?.dispose(),f?.dispose(),s.dispose();}return a(X,"dispose"),{get canPathTrace(){return I&&!U},preview:O,refine:y,capture:A,dispose:X}}a(Dc,"createPhotoStudio");var Ac='MeshBVH: "maxLeafTris" option has been deprecated';async function Rc(e){let{WebGLPathTracer:o}=await import('./src-SHLZZCVA.js'),t=console.warn;console.warn=(...a)=>{typeof a[0]=="string"&&a[0].startsWith(Ac)||t(...a);};let r;try{r=new o(e);}finally{console.warn=t;}return r.renderToCanvas=false,r.rasterizeScene=false,r.synchronizeRenderSize=false,r.renderDelay=0,r.minSamples=0,r.fadeDuration=0,r.bounces=6,r.multipleImportanceSampling=true,r.filterGlossyFactor=.5,r.tiles.set(1,1),r._generator.bvhOptions={maxLeafTris:void 0,maxLeafSize:1},r}a(Rc,"createPathTracer");function ma(e,o,t){e._pathTracer.setSize(o,t);}a(ma,"setPathTracerSize");async function ha(e,o,t){let r=new Float32Array(4),a=performance.now(),i=1;for(;o.samples<t.samples;){Xo(t.signal);let s=performance.now();for(let f=0;f<i&&o.samples<t.samples;f++)o.renderSample();e.readRenderTargetPixels(o.target,0,0,1,1,r);let l=performance.now()-s;l<35?i=Math.min(64,i*2):l>70&&(i=Math.max(1,Math.floor(i/2)));let c=performance.now()-a;if(t.onFraction(Math.min(1,Math.max(o.samples/t.samples,c/t.timeLimit))),c>t.timeLimit&&o.samples>=t.minSamples)break;await qo();}}a(ha,"accumulate");function qo(){return new Promise(e=>requestAnimationFrame(()=>e()))}a(qo,"nextFrame");function Xo(e){if(e?.aborted)throw new DOMException("Photo capture cancelled","AbortError")}a(Xo,"throwIfAborted");var ga=new GLTFLoader,$o=new DRACOLoader;$o.setDecoderPath("/draco/");ga.setDRACOLoader($o);function Ec(e){$o.setDecoderPath(e);}a(Ec,"setDracoDecoderPath");async function Yo(e){let o=await ga.loadAsync(e);return o.scene.animations=o.animations,o.scene}a(Yo,"loadModel");var va=new WeakMap;function kc(e,o){let t=va.get(e);t||(t=[],va.set(e,t));let r=t.find(a=>a.clip===o);if(!r){let a=new AnimationMixer(e),i=a.clipAction(o);i.play(),r={clip:o,mixer:a,action:i},t.push(r);}return r}a(kc,"scrubberFor");function Zo(e,o){let t=false;return e.traverse(r=>{!t&&r.animations.some(a=>a.name===o)&&(t=true);}),t}a(Zo,"hasClip");function xt(e,o,t){let r=Math.min(1,Math.max(0,t)),a=false;return e.traverse(i=>{for(let s of i.animations){if(s.name!==o)continue;let{mixer:l,action:c}=kc(i,s);c.time=r*s.duration,l.update(0),a=true;}}),a}a(xt,"seekClip");var ya=[{clip:"unfold",seconds:3.6},{clip:"open",seconds:2.2},{clip:"tilt",seconds:1.8}],xa=.15;function _c(e){let o=e.poses??ya,t=e.requestFrame??(typeof requestAnimationFrame=="function"?y=>requestAnimationFrame(y):y=>setTimeout(()=>y(performance.now()),16)),r=null,a$1=0,i=null,s=false,l=0,c=0,f;function u(y){return e.roots().filter(A=>Zo(A,y))}a(u,"posable");function d(){return o.filter(y=>u(y.clip).length>0).map(y=>y.clip)}a(d,"available");function M(y,A){let k=u(y);for(let I of k)xt(I,y,A),I.updateMatrixWorld(true);e.onPose?.(y,A,k);}a(M,"pose");function v(y,A){let k=new Box3;for(let I of u(y))xt(I,y,A),I.updateMatrixWorld(true);for(let I of e.roots())k.expandByObject(I);for(let I of u(y))xt(I,y,r===y?a$1:0),I.updateMatrixWorld(true);return k}a(v,"boundsAt");function m(y,A){if(!e.onFrame)return;let k=v(y,A===1?0:1).getSize(new Vector3),I=v(y,A),U=I.getSize(new Vector3);Math.max(Math.abs(U.x-k.x),Math.abs(U.y-k.y),Math.abs(U.z-k.z))/Math.max(k.x,k.y,k.z,1e-6)<xa||e.onFrame(I);}a(m,"frame");function w(y,A){let k=r===y?a$1:0;r=y;let I=++c;return new Promise(U=>{let X=a(()=>{a$1=A,M(y,A),s=false,e.onSettle?.(y,u(y)),A===0&&(r=null),f=void 0,U(true);},"arrive"),C=o.find(N=>N.clip===y)?.seconds??2;if(e.reducedMotion?.()||k===A)return X();s=true,f=U;let F=C*Math.abs(A-k)*1e3,G,V=a(N=>{if(I!==c)return;G??=N;let B=Math.min(1,(N-G)/F);a$1=k+(A-k)*B,M(y,a$1),B<1?t(V):X();},"step");t(V);})}a(w,"run");function h(){c++,f?.(false),f=void 0;}a(h,"interrupt");async function S(y,A){if(u(y).length===0)return;let k=++l;i=A?y:null,e.onChange?.(),h(),!(r&&r!==y&&(await w(r,0),k!==l))&&(!A&&r!==y||(e.beforeTravel?.(y,u(y)),m(y,A?1:0),await w(y,A?1:0)));}a(S,"setPose");async function g(){i?await S(i,false):r&&await S(r,false);}a(g,"rest");function D(){let y=r;return y?u(y).length===0?false:(a$1===0||(e.beforeTravel?.(y,u(y)),M(y,a$1),s||e.onSettle?.(y,u(y))),true):true}a(D,"reapply");function O(){!s&&(a$1===1?r:null)===i||(l++,h(),s=false,r&&r!==i&&(M(r,0),e.onSettle?.(r,u(r))),i?(r!==i&&m(i,1),r=i,a$1=1,M(i,1),e.onSettle?.(i,u(i))):(r=null,a$1=0));}a(O,"settle");function L(){h(),r=null,i=null,a$1=0,s=false,e.onChange?.();}return a(L,"forget"),{available:d,setPose:S,rest:g,reapply:D,settle:O,forget:L,target:a(()=>i,"target"),current:a(()=>r,"current"),progress:a(()=>a$1,"progress"),moving:a(()=>s,"moving")}}a(_c,"createPoseController");var Fe=.15,Sa=20,zc=5;function Fc(e,o){return o==="mm"?`${Math.round(e*1e3)} mm`:`${Math.round(e*100)} cm`}a(Fc,"formatScaleLength");function Jo(e,o,t,r){let a=e.clone().project(o);return a.z>1?null:{x:(a.x*.5+.5)*t,y:(-a.y*.5+.5)*r,zIndex:Math.floor(1e4-a.z*1e4)}}a(Jo,"project");function Gc(e,o,t,r){let{min:a,max:i}=e,s=e.getCenter(new Vector3);if(o.position.distanceTo(s)>Sa)return null;let l=o.position.z>s.z,c=o.position.x>s.x,f=l?i.z+Fe:a.z-Fe,u=c?i.x+Fe:a.x-Fe,d=a.y-Fe,M={x:[new Vector3(a.x,d,f),new Vector3(i.x,d,f)],y:[new Vector3(u,a.y,f),new Vector3(u,i.y,f)],z:[new Vector3(u,d,a.z),new Vector3(u,d,i.z)]},v=[];for(let S of ["x","y","z"]){let g=Jo(M[S][0],o,t,r),D=Jo(M[S][1],o,t,r);g&&D&&v.push({axis:S,x1:g.x,y1:g.y,x2:D.x,y2:D.y});}let m=c?i.x+Fe*2:a.x-Fe*2,w=[["x",new Vector3((a.x+i.x)/2,a.y-Fe*2,f),i.x-a.x],["y",new Vector3(m,(a.y+i.y)/2,f),i.y-a.y],["z",new Vector3(m,d,(a.z+i.z)/2),i.z-a.z]],h=[];for(let[S,g,D]of w){let O=Jo(g,o,t,r);O&&h.push({axis:S,...O,scale:zc/o.position.distanceTo(g),meters:D});}return {lines:v,labels:h}}a(Gc,"computeScaleOverlay");var Pa=.08,Hc=.3,Ca=.005;function wa(e){e.sort();let o=[];for(let a of e){let i=o[o.length-1];i&&a-i.to<=Pa?i.to=Math.max(i.to,a):o.push({from:a,to:a});}let t=o.length?o[o.length-1].to-o[0].from:0,r=o.reduce((a,i)=>a+i.to-i.from,0);return {pieces:o,length:t,rigid:r}}a(wa,"measureAxis");function Ta(e){let o=[];return e.traverse(t=>{let r=t;r.isMesh&&r.geometry?.attributes.position&&o.push(r);}),o}a(Ta,"productMeshes");function Ko(e){e.updateMatrixWorld(true);let o=e.matrixWorld.clone().invert(),t=new Map;return e.traverse(r=>{r!==e&&t.set(r,o.clone().multiply(r.matrixWorld));}),t}a(Ko,"relativeMatrices");function Da(e){let o=Ko(e),t=Ta(e).filter(d=>!d.userData.isCollider),r=[],a$1=[],i=new Vector3,s=new Box3;for(let d of t){let M=o.get(d),v=d.geometry.attributes.position;s.makeEmpty();for(let w=0;w<v.count;w++)i.fromBufferAttribute(v,w).applyMatrix4(M),r.push(i.x),a$1.push(i.y),s.expandByPoint(i);if(s.isEmpty())continue;let m=a((w,h,S)=>{if(!(S-h>Hc))for(let g=h;g<S;g+=Pa/2)w.push(g);},"fill");m(r,s.min.x,s.max.x),m(a$1,s.min.y,s.max.y);}if(r.length===0)return null;let l=wa(Float32Array.from(r)),c=wa(Float32Array.from(a$1)),f=a(d=>Math.round(d*1e3),"mm"),u=a(d=>Math.max(0,d.pieces.length-1)*Ca,"runs");return {x:l,y:c,size:{width:f(l.length),height:f(c.length)},minimum:{width:f(l.rigid+u(l)),height:f(c.rigid+u(c))}}}a(Da,"measureModule");function Ma(e,o,t){let{pieces:r}=e,a=r.slice(1).map((M,v)=>M.from-r[v].to),i=a.reduce((M,v)=>M+v,0),s=o-e.length,l=a.map(M=>Math.max(Ca,i>0?M+s*M/i:M)),c=r[0]?.from??0,f=e.rigid+l.reduce((M,v)=>M+v,0),u=t==="start"?c:c+(e.length-f)/2,d=[];for(let[M,v]of r.entries())d.push(u-v.from),u+=v.to-v.from+(l[M]??0);return M=>{if(r.length===0)return M;if(M<=r[0].to)return M+d[0];for(let v=0;v<r.length;v++){let m=r[v];if(M<=m.to){if(M>=m.from)return M+d[v];let w=r[v-1],h=(M-w.to)/(m.from-w.to),S=w.to+d[v-1],g=m.from+d[v];return S+(g-S)*h}}return M+d[d.length-1]}}a(Ma,"axisMap");function jc(e,o,t,r){let a$1=e.index,i=a$1?a$1.count:o.length,s=new Uint8Array(o.length),l=r.clone(),c=t.map((m,w)=>m.clone().sub(o[w])),f=new Vector3,u=new Vector3,d=new Vector3,M=new Vector3,v=1e-7;for(let m=0;m+2<i;m+=3){let w=[0,1,2].map(I=>a$1?a$1.getX(m+I):m+I),[h,S,g]=w;if(!(c[h].distanceToSquared(c[S])>v||c[h].distanceToSquared(c[g])>v))continue;f.subVectors(o[S],o[h]),u.subVectors(o[g],o[h]);let O=f.dot(f),L=f.dot(u),y=u.dot(u),A=O*y-L*L;if(Math.abs(A)<1e-14)continue;let k=a((I,U)=>{let X=U(S)-U(h),C=U(g)-U(h),F=(X*y-C*L)/A,G=(C*O-X*L)/A;return I.copy(f).multiplyScalar(F).addScaledVector(u,G)},"gradient");k(d,I=>l.getX(I)),k(M,I=>l.getY(I));for(let I of w)s[I]||(s[I]=1,r.setXY(I,l.getX(I)+d.dot(c[I]),l.getY(I)+M.dot(c[I])));}r.needsUpdate=true;}a(jc,"respreadUvs");function qc(e,o){if(Math.abs(o-1)<1e-6)return;let t=new Quaternion,r=new Vector3;e.traverse(a=>{a.animations.length&&(a.animations=a.animations.map(i=>{if(i.name!=="tilt")return i;let s=i.clone();for(let l of s.tracks){if(!(l instanceof QuaternionKeyframeTrack))continue;let c=l.values;for(let f=0;f<c.length;f+=4){t.fromArray(c,f);let u=2*Math.acos(Math.min(1,Math.abs(t.w)));if(u<1e-6)continue;let d=Math.sqrt(1-t.w*t.w);if(r.set(t.x/d,t.y/d,t.z/d),Math.abs(r.x)<.9)continue;let M=t.w<0?-1:1,v=Math.asin(Math.min(1,Math.sin(u)*o));t.setFromAxisAngle(r.multiplyScalar(M),v),t.toArray(c,f);}}return s}));});}a(qc,"retuneTilt");var Qo="konfigureResized";function er(e,o){let t=Da(e);if(!t)return null;let r=Ma(t.x,o.width/1e3,"centre"),a$1=Ma(t.y,o.height/1e3,"start"),i=a(w=>w.set(r(w.x),a$1(w.y),w.z),"map"),s=Ko(e),l=Ta(e),c=new Vector3,f=e.matrixWorld.clone().invert(),u=new Matrix4;e.traverse(w=>{let h=w.parent;w===e||!h||(c.setFromMatrixPosition(s.get(w)),i(c),h.updateMatrixWorld(false),h===e?u.identity():u.copy(f).multiply(h.matrixWorld).invert(),w.position.copy(c.applyMatrix4(u)),w.updateMatrix());});let d=Ko(e);for(let w of l){let h=w.geometry,S=h.clone();S.userData={...h.userData,[Qo]:true};let g=S.attributes.position,D=s.get(w),O=d.get(w).clone().invert(),L=[],y=[],A=new Vector3;for(let I=0;I<g.count;I++)A.fromBufferAttribute(g,I).applyMatrix4(D),L.push(A.clone()),i(A),y.push(A.clone()),A.applyMatrix4(O),g.setXYZ(I,A.x,A.y,A.z);g.needsUpdate=true;let k=S.attributes.uv;k&&jc(S,L,y,k),S.computeBoundingBox(),S.computeBoundingSphere(),h.userData[Qo]&&h.dispose(),w.geometry=S;}let M=a((w,h)=>h(w.pieces.at(-1).to)-h(w.pieces[0].from),"drawn"),v=M(t.x,r),m=M(t.y,a$1);return qc(e,t.y.length/m),{width:Math.round(v*1e3),height:Math.round(m*1e3)}}a(er,"resizeModule");function Xc(e){e.traverse(o=>{let t=o;t.isMesh&&t.geometry?.userData[Qo]&&t.geometry.dispose();});}a(Xc,"disposeResizedGeometry");function Yc(e,o){let t=[];return e.traverse(r=>{if(mt(r)){r.updateWorldMatrix(true,false);let a=r.geometry;if(a.boundingBox===null&&a.computeBoundingBox(),a.boundingBox&&!a.boundingBox.isEmpty()){let i=a.boundingBox.clone();i.applyMatrix4(r.matrixWorld);let s=i.clone(),l=new Vector3(o,o,o);s.min.add(l),s.max.sub(l),t.push({box:s,trueBox:i,ignoreForPartCollision:r.userData?.ignoreCollision||false,isCollider:r.userData?.isCollider||false,collisionGroup:r.userData?.collisionGroup||void 0});}}}),t}a(Yc,"computePartBoundingBoxes");function Aa(e,o=.001){let t=[];function r(){return t=Yc(e,o),t}a(r,"updateBoundingBoxes");function a$1(l){return t.length===0&&r(),t.filter(c=>!c.isCollider&&(l||!c.ignoreForPartCollision)).map(c=>c.box)}a(a$1,"getBoundingBoxes");function i(l){return t.length===0&&r(),t.filter(c=>!c.isCollider&&!c.ignoreForPartCollision&&c.collisionGroup!==l).map(c=>c.box)}a(i,"getBoundingBoxesExcludingGroup");function s(l){return t.length===0&&r(),t.filter(c=>!c.isCollider&&(l||!c.ignoreForPartCollision)).map(c=>c.trueBox)}return a(s,"getTrueBoundingBoxes"),{updateBoundingBoxes:r,getBoundingBoxes:a$1,getBoundingBoxesExcludingGroup:i,getTrueBoundingBoxes:s}}a(Aa,"createBoundingBox");function Qc(){if(typeof localStorage>"u")return false;let e=localStorage.getItem("debug-show-colliders");return e?JSON.parse(e):false}a(Qc,"getCollidersVisible");function Ea(e){let o=null,t=null,r=false;function a$2(u){u&&(e.remove(u),u.geometry.dispose(),u.material.dispose());}a(a$2,"disposeMesh");function i(u){let d=[],M=new Matrix4().copy(e.matrixWorld).invert();if(e.traverse(w=>{if(w instanceof Mesh){if(w.userData.isCollider||!u&&w.userData.ignoreCollision||u&&!w.visible)return;let h=w.geometry.getAttribute("position");if(!h)return;let S=new BufferGeometry;if(S.setAttribute("position",h.clone()),w.geometry.index)S.setIndex(w.geometry.index.clone());else {let g=h.count,D=new Uint32Array(g);for(let O=0;O<g;O++)D[O]=O;S.setIndex(new BufferAttribute(D,1));}S.applyMatrix4(new Matrix4().multiplyMatrices(M,w.matrixWorld)),d.push(S);}}),d.length===0)return null;let v=Ia.mergeGeometries(d,false);v.boundsTree=new a$1(v);let m=new Mesh(v,new MeshStandardMaterial({wireframe:true}));return m.visible=Qc(),m.userData.isCollider=true,e.add(m),m}a(i,"mergeGeometries");function s(){return a$2(o),a$2(t),o=null,t=null,e.updateWorldMatrix(true,true),o=i(false),o||(t=i(true)),r=true,o}a(s,"updateCollider");function l(){return r||s(),o}a(l,"getCollider");function c(){return r||s(),o??t}a(c,"getOcclusionCollider");function f(){a$2(o),a$2(t),o=null,t=null,r=false;}return a(f,"removeCollider"),{getCollider:l,getOcclusionCollider:c,updateCollider:s,removeCollider:f}}a(Ea,"createCollider");var Kt={ADD:"add",CONFIG:"config"};var St=class extends Error{static{a(this,"ConfiguratorError");}constructor(o){super(o),this.name="ConfiguratorError";}},Qt=class extends St{static{a(this,"ModuleNotFoundError");}constructor(o){super(`Module with ID ${o} not found`),this.name="ModuleNotFoundError";}};var at=class extends St{static{a(this,"SlotNotFoundError");}constructor(o,t){let r=t?`Slot "${o}" not found in ${t}`:`Slot "${o}" not found`;super(r),this.name="SlotNotFoundError";}};var it=class extends St{static{a(this,"NotPreloadedError");}constructor(o,t){super(`${o} ${t} not preloaded. Call preloadModelsForModule first.`),this.name="NotPreloadedError";}};function Ba(e,o,t){let r=new Vector3;e.point.models.addToModel.getWorldPosition(r);let a=t.clone(),i=new Vector3;o.point.models.addToModel.getWorldPosition(i);let s=c(r,i,a),c$1=r.clone().sub(a).applyAxisAngle(new Vector3(0,1,0),s).add(a),f=c(i,c$1,a),u=a.clone(),d=new Vector3().subVectors(a,u),M=t.clone().add(d);return {alpha:s,beta:f,translationOffset:d,newPosition:M,pointAAfterRotation:c$1}}a(Ba,"calculateSwapTransformation");var ka="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var st=a((e=21)=>{let o="",t=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)o+=ka[t[e]&63];return o},"nanoid");function La({point:e,compatibleModules:o,label:t,slotGroup:r,row:a,hasBuiltInConnector:i,preferConnection:s,disabledBySlotParts:l,enabledBySlotParts:c,disabledByNeighborSlots:f,linkedPartSlotName:u,autoConfigureParts:d,accessoryParts:M,accessoryAnchorPosition:v}){return {id:st(),point:e,module:void 0,compatibleModules:o,label:t,slotGroup:r,row:a,hasBuiltInConnector:i,preferConnection:s,disabledBySlotParts:l,enabledBySlotParts:c,disabledByNeighborSlots:f,linkedPartSlotName:u,autoConfigureParts:d,accessoryParts:M,accessoryAnchorPosition:v}}a(La,"createModuleSlot");function _a({part:e,compatibleParts:o,label:t,point:r,slotGroupId:a,column:i,row:s,invertible:l,canRotate:c,order:f,disabledPartsByNeighborSlots:u,enabledPartsByNeighborSlots:d,disabledPartsByNeighborParts:M,backrestBlocksTables:v,hiddenBySlotParts:m,syncWithSlotName:w,defaultInverted:h,isVariantDiscriminator:S}){return {part:e,compatibleParts:o,label:t,point:r,slotGroupId:a,column:i,row:s,invertible:l,inverted:false,canRotate:c,rotated:false,order:f,disabledPartsByNeighborSlots:u,enabledPartsByNeighborSlots:d,disabledPartsByNeighborParts:M,backrestBlocksTables:v,hiddenBySlotParts:m,syncWithSlotName:w,defaultInverted:h,isVariantDiscriminator:S}}a(_a,"createBasePartSlot");var Ke=new Box3,za=new Vector3;function nu(e,o){let t=e;for(;t.parent;)t=t.parent;let r;return t.traverse(a=>{!a.visible||!a.name.startsWith("wall")||(Ke.setFromObject(a),!Ke.isEmpty()&&(o.x<Ke.min.x||o.x>Ke.max.x||Ke.max.z<o.z||(r===void 0||Ke.max.y>r)&&(r=Ke.max.y)));}),r}a(nu,"getOccludingWallTopY");function lt(e,o=[],t=[]){let r=e;return {withSlotAction:a(({targetSlot:a,name:i,action:s})=>{if(!r.moduleSlots[a])throw new at(String(a),"module");let c=[...o,{targetSlot:String(a),name:i,action:s}];return lt(r,c,t)},"withSlotAction"),withModule:a(({targetSlot:a,newModule:i,connectionSlot:s})=>{if(!r.moduleSlots[a])throw new at(String(a),"module");if(!i.moduleSlots[s])throw new at(String(s),"new module");let l=[...t,{targetSlot:String(a),newModule:i,connectionSlot:String(s)}];return lt(r,o,l)},"withModule"),withModuleSlots:a(({moduleSlotsData:a})=>{let i={};return Object.entries(a).forEach(([s,l])=>{let c=La({point:{models:l.models,parentModuleId:r.id,parentModuleSlotId:void 0,active:l.active,type:l.type},compatibleModules:l.compatibleModules,label:l.label,slotGroup:l.slotGroup,row:l.row,hasBuiltInConnector:l.hasBuiltInConnector,preferConnection:l.preferConnection,disabledBySlotParts:l.disabledBySlotParts,enabledBySlotParts:l.enabledBySlotParts,disabledByNeighborSlots:l.disabledByNeighborSlots,linkedPartSlotName:l.linkedPartSlotName,autoConfigureParts:l.autoConfigureParts,accessoryParts:l.accessoryParts,accessoryAnchorPosition:l.accessoryAnchorPosition});c.point.parentModuleSlotId=c.id,r.moduleGroup.add(c.point.models.pointModel),r.moduleGroup.add(c.point.models.addToModel),i[s]=c;}),r.moduleSlots=i,lt(r,o,t)},"withModuleSlots"),withBasePartSlots:a(({basePartSlotsData:a})=>{let i={};return Object.entries(a).forEach(([s,l])=>{let c=_a({point:{models:l.models,parentModuleId:r.id,parentModuleSlotId:void 0,active:l.active,type:l.type},compatibleParts:l.compatibleParts,label:l.label,part:l.part,slotGroupId:l.slotGroupId,column:l.column,row:l.row,invertible:l.invertible,canRotate:l.canRotate,order:l.order,disabledPartsByNeighborSlots:l.disabledPartsByNeighborSlots,enabledPartsByNeighborSlots:l.enabledPartsByNeighborSlots,disabledPartsByNeighborParts:l.disabledPartsByNeighborParts,backrestBlocksTables:l.backrestBlocksTables,hiddenBySlotParts:l.hiddenBySlotParts,syncWithSlotName:l.syncWithSlotName,defaultInverted:l.defaultInverted,isVariantDiscriminator:l.isVariantDiscriminator});c.point.parentModuleId=r.id,c.point.parentModuleSlotId=c.point.models.pointModel.uuid;let f=s.startsWith("cross_");if((c.part.ignoreCollision||f)&&c.part.partGroup.traverse(u=>{u.userData.ignoreCollision=true;}),c.part.collisionGroup){let u=c.part.collisionGroup;c.part.partGroup.traverse(d=>{d.userData.collisionGroup=u;});}r.moduleGroup.add(c.part.partGroup),r.moduleGroup.add(c.point.models.pointModel),r.moduleGroup.add(c.point.models.addToModel),i[s]=c;}),r.basePartSlots=i,lt(r,o,t)},"withBasePartSlots"),withRotatableModule:a(()=>lt({...r,canSwapModuleSlots:true},o,t),"withRotatableModule"),build:a(()=>{let{getCollider:a$1,getOcclusionCollider:i,updateCollider:s,removeCollider:l}=Ea(r.moduleGroup),{updateBoundingBoxes:c,getBoundingBoxes:f,getTrueBoundingBoxes:u}=Aa(r.moduleGroup);c(),r.moduleGroup.userData=r.moduleGroup.userData||{},r.moduleGroup.userData.updateCollider=s,r.moduleGroup.userData.updateBoundingBoxes=c,He(r.moduleGroup,true,true);function d$1(){let D=f(false);if(D.length===0)return;let O=D[0].clone();for(let k=1;k<D.length;k++)O.union(D[k]);let L=r.configPoint.models.pointModel;L.getWorldPosition(za);let y=O.max.y,A=nu(r.moduleGroup,za);A!==void 0&&A>y&&(y=A),L.position.y=y+.15;}a(d$1,"updateConfigPoint");function M(D){r.moduleGroup.position.set(D.x,D.y,D.z);}a(M,"updatePosition");function v(D){r.moduleGroup.rotation.y=D;}a(v,"updateRotation");function m(D,O,L){let y=L.point.models.addToModel,A=O.point.models.addToModel,k=new Vector3(-1,0,0);y.getWorldDirection(k);let I=new Vector3(1,0,0);A.getWorldDirection(I);let U=Math.atan2(k.x,k.z)-Math.atan2(I.x,I.z)+Math.PI;D.moduleGroup.rotation.y=U;let X=new Vector3;y.getWorldPosition(X);let C=O.point.models.addToModel.position.clone(),F=new Matrix4().makeRotationY(U),G=C.applyMatrix4(F),V=X.clone().sub(G);D.moduleGroup.position.set(V.x,V.y,V.z),D.moduleGroup.userData.updateBoundingBoxes?.();}a(m,"placeNewNeighborModule");function w(D,O,L){L.module=D,O.module=g,L.point.active=false,O.point.active=false,D.predecessorSlotId=L.id,m(D,O,L);}a(w,"addModuleToSlot");function h(){Object.values(r.moduleSlots).forEach(D=>{let O=D.module?.moduleSlots;O&&Object.values(O).forEach(L=>{L.module?.id===r.id&&(L.module=void 0,L.point.active=true);});}),l(),r.moduleGroup.clear();}a(h,"remove");function S(D,O){g.moduleGroup.updateMatrixWorld(true);let L=Object.values(r.moduleSlots),y=g.predecessorSlotId,A=!y,k,I;if(A?(k=0,I=L[0]??null):[k,I]=d(L,y),!I||k===-1)return;let U=O??(k+1)%L.length,X=L[U];if(!X||U===k)return;let{alpha:C,beta:F,translationOffset:G}=Ba(I,X,r.moduleGroup.position),V=r.moduleGroup.rotation.y;v(V+C),r.moduleGroup.updateMatrixWorld(true);let N=r.moduleGroup.position.clone().add(G);M(N);let B=e$1(r.moduleSlots,g,A?void 0:I.module);if(B.length){let p=new Object3D;p.position.copy(r.moduleGroup.position),D.add(p);for(let R of B)p.attach(R.moduleGroup);p.rotation.y+=A?C:F,p.position.add(G);for(let R of B)D.attach(R.moduleGroup),R.moduleGroup.userData.updateBoundingBoxes?.();D.remove(p);}if(!A){let p=X.module,R=I.module;I.module=p,I.point.active=!p,p&&p.predecessorSlotId===X.id&&(p.predecessorSlotId=I.id),X.module=R,X.point.active=!R;}r.moduleGroup.userData.updateBoundingBoxes?.(),g.moduleGroup.updateMatrixWorld(true);}a(S,"swapModuleSlots"),d$1();let g={...r,apiModuleId:r.apiModuleId,getCollider:a$1,getOcclusionCollider:i,getBoundingBoxes:f,getTrueBoundingBoxes:u,updateConfigPoint:d$1,updatePosition:M,updateRotation:v,placeNewNeighborModule:m,addModuleToSlot:w,swapModuleSlots:r.canSwapModuleSlots?S:void 0,remove:h,predecessorSlotId:void 0};return t.forEach(({targetSlot:D,newModule:O,connectionSlot:L})=>{let y=g.moduleSlots[D],A=O.moduleSlots[L];y&&A&&g.addModuleToSlot(O,A,y);}),o.forEach(({targetSlot:D,name:O,action:L})=>{let y=g.moduleSlots[D];y&&(y.point.options?y.point.options.push({name:O,action:a(()=>L(g),"action")}):y.point.options=[{name:O,action:a(()=>L(g),"action")}]);}),g},"build")}}a(lt,"moduleBuilder");function tr(e){let{moduleData:o,position:t}=e,r=st(),a=t||new Vector3(0,0,0),i=new Group;i.position.set(a.x,a.y,a.z);let s=new Vector3(o.configPointPosition.x,o.configPointPosition.y,o.configPointPosition.z),l=new Object3D;l.position.copy(s);let c={type:"config",active:true,models:{pointModel:l,addToModel:l},parentModuleId:r,parentModuleSlotId:void 0};i.add(l);let f={id:r,code:o.code||o.name,position:a,moduleSlots:{},moduleSlotsOptions:{},basePartSlots:{},sizes:{x:o.sizes?.x??0,z:o.sizes?.z??0},moduleGroup:i,configPoint:c,slotGroups:o.slotGroups,apiModuleId:o.id,remoteProductLineId:o.remoteProductLineId??null},u=lt(f);return o.rotatableModule?u.withRotatableModule():u}a(tr,"createModuleBuilderFromData");function Ga({part:e,compatibleParts:o,label:t,point:r,mandatory:a,showInPreview:i}){return {part:e,compatibleParts:o,label:t,point:r,mandatory:a,showInPreview:i}}a(Ga,"createPartSlot");var or=k("PartBuilder");function Wa(e,o){e.userData&&Object.keys(e.userData).length>0&&(o.userData={...o.userData,...e.userData}),e.children.forEach((t,r)=>{let a=o.children[r];a&&Wa(t,a);});}a(Wa,"deepCopyUserData");function rr(e){let o=e;return {withPartSlots:a(t=>{let r={};return Object.entries(t).forEach(([a,i])=>{let s;if(or.debug("Processing slot",{slotKey:a,mandatory:i.mandatory,defaultPartApiId:i.defaultPartApiId,compatiblePartsCount:i.compatibleParts?.length??0}),i.mandatory&&i.defaultPartApiId&&i.compatibleParts){let u=i.compatibleParts.find(d=>d.apiPartId===i.defaultPartApiId);or.debug("Mandatory slot lookup",{slotKey:a,apiPartId:i.defaultPartApiId,found:!!u}),u&&(or.debug("Creating mandatory part",{slotKey:a}),s=u.createPart(),u.hasConfigurableSurface!==void 0&&(s.hasConfigurableSurface=u.hasConfigurableSurface),u.defaultSurfaceId!==void 0&&(s.defaultSurfaceId=u.defaultSurfaceId,s.hasConfigurableSurface&&(s.surfaceId=u.defaultSurfaceId)),u.allowedSurfaceGroupIds!==void 0&&(s.allowedSurfaceGroupIds=u.allowedSurfaceGroupIds),u.allowedSurfaceIds!==void 0&&(s.allowedSurfaceIds=u.allowedSurfaceIds));}let l=i.models.pointModel.clone(),c=i.models.addToModel.clone(),f=Ga({point:{models:{pointModel:l,addToModel:c},parentModuleId:o.id,parentModuleSlotId:void 0,active:i.active,type:i.type},compatibleParts:i.compatibleParts,label:i.label,part:s,mandatory:i.mandatory,showInPreview:i.showInPreview});if(o.partGroup.add(f.point.models.pointModel),o.partGroup.add(f.point.models.addToModel),f.part){if(f.part.ignoreCollision&&f.part.partGroup.traverse(u=>{u.userData.ignoreCollision=true;}),f.part.collisionGroup){let u=f.part.collisionGroup;f.part.partGroup.traverse(d=>{d.userData.collisionGroup=u;});}o.partGroup.add(f.part.partGroup),He(f.part.partGroup,true,true);}r[a]=f;}),o.partSlots=r,rr(o)},"withPartSlots"),withCompatibleParts:a(t=>(Object.entries(t).forEach(([r,a])=>{let i=o.partSlots[r];i&&(i.compatibleParts=a);}),rr(o)),"withCompatibleParts"),build:a(()=>o,"build")}}a(rr,"partBuilder");function nr(e){let{partData:o,model:t,position:r}=e,a=st(),i=r||new Vector3(0,0,0),s=t.clone();Wa(t,s),o.rotation&&s.rotation.set(o.rotation.x*Math.PI/180,o.rotation.y*Math.PI/180,o.rotation.z*Math.PI/180);let l=o.mirror?.x?-1:1,c=o.mirror?.y?-1:1,f=o.mirror?.z?-1:1,u=o.scale??1;s.scale.set(l*u,c*u,f*u);let d=new Group;d.position.set(i.x,i.y,i.z),d.add(s);let M={id:a,code:o.code??o.name,position:i,model:s,material:void 0,partGroup:d,partSlots:{},ignoreCollision:o.ignoreCollision,collisionGroup:o.collisionGroup??void 0,apiPartId:o.id,partTypeId:o.partTypeId??null,hasConfigurableSurface:o.hasConfigurableSurface,allowedSurfaceGroupIds:o.allowedSurfaceGroupIds,allowedSurfaceIds:o.allowedSurfaceIds,defaultSurfaceId:o.defaultSurfaceId??void 0,wallThickness:o.wallThickness??void 0,wallPositionOffset:o.wallPositionOffset??void 0,surfaceId:o.hasConfigurableSurface?o.defaultSurfaceId??void 0:void 0,isModuleAccessoryPart:o.remoteProductAccessoryId!=null,hideFromConfigurator:o.hideFromConfigurator??false,priceMultiplier:o.priceMultiplier??1};return rr(M)}a(nr,"createPartBuilderFromData");var lu=k("CatalogAdapter");function Na(e){let o={};try{o=typeof e.textureJson=="string"?JSON.parse(e.textureJson):e.textureJson??{};}catch{o={};}let t=new MeshPhysicalMaterial({color:typeof o.color=="string"?o.color:"#b9bcc4",metalness:typeof o.metalness=="number"?o.metalness:0,roughness:typeof o.roughness=="number"?o.roughness:.8});return t.name=`surface-${e.id}`,t}a(Na,"createColourSurfaceMaterial");function ar(e){let{catalog:o}=e,t=e.invalidate??(()=>{}),r=e.createSurfaceMaterial??Na,a$1=new Map,i$1=new Map,s=new Map,l=new Map,c=new Map,f=new Map,u=new Map,d=new Map(o.parts.map(p=>[p.id,p])),M=new Map(o.modules.map(p=>[p.id,p])),v=new Map(o.surfaces.map(p=>[p.id,p]));function m(p){return d.get(p)}a(m,"getPartById");function w(p){return M.get(p)}a(w,"getModuleById");function h$1(p){let R=u.get(p);if(R)return R;let b=v.get(p);if(!b)return null;let P=r(b);return P&&u.set(p,P),P}a(h$1,"getSurface");async function S(p){let R=l.get(p);if(R)return R.clone();let b=c.get(p);if(b)return (await b).clone();let P=Yo(p).then(x=>(l.set(p,x.clone()),c.delete(p),x));return c.set(p,P),P}a(S,"loadModelByPath");async function g$1(p){if(!p.model3d)return null;let R=await S(p.model3d.filePath),b=p.fixedSurfaceId?h$1(p.fixedSurfaceId):null;return R.traverse(P=>{if(mt(P)){if(P.userData.fixedFinish){P.userData.hasConfigurableSurface=false;return}P.userData.hasConfigurableSurface=p.hasConfigurableSurface,b&&(P.material=b);}}),p.tag&&(R.userData.tag=p.tag),R}a(g$1,"loadAndTagPartModel");function D(p,R){return new Vector3(R?.x??p.x,R?.y??p.y,R?.z??p.z)}a(D,"resolveCompatiblePartPosition");function O(p,R=new Set){let b=new Set;if(R.has(p))return b;R.add(p);let P=m(p);if(!P)return b;b.add(p);for(let x of P.partSlots??[])for(let{partId:W}of x.compatibleParts??[])for(let z of O(W,R))b.add(z);return b}a(O,"collectNestedPartIds");function L(p,R){return b=>{let P=i$1.get(p.id);if(!P)throw new it("Part data",p.id);let x=s.get(p.id);if(!x)throw new it("Part model",p.id);let W=b?.position??R,z=W?new Vector3(W.x,W.y,W.z):new Vector3(0,0,0),$=nr({partData:P,model:x,position:z}),Y=f.get(p.id);return Y&&$.withPartSlots(Y),$.build()}}a(L,"createPartFactory");function y(p,R){return b=>{let P=b?.position??R,x=P?new Vector3(P.x,P.y,P.z):new Vector3(0,0,0);return nr({partData:p,model:new Group,position:x}).build()}}a(y,"createEmptyPartFactory");function A(p){if(!p.partSlots||p.partSlots.length===0)return;let R={},b=new Map;for(let P of p.partSlots)for(let x of P.requiredByPartIds??[])b.has(x)||b.set(x,[]),b.get(x)?.push(P.name);for(let P of p.partSlots){let x=new Object3D;x.position.set(P.pointPosition.x,P.pointPosition.y,P.pointPosition.z);let W=new Object3D;W.position.set(P.addPosition.x,P.addPosition.y,P.addPosition.z);let z=[];for(let{partId:$,addPosition:Y}of P.compatibleParts??[]){let H=m($);if(!H||!H.models||H.models.length===0)continue;let Q=D(P.addPosition,Y),K={name:H.name,description:H.description??void 0,image:H.image??void 0,createPart:L(H,Q),apiPartId:H.id,partTypeId:H.partTypeId??null,hasConfigurableSurface:H.hasConfigurableSurface,allowedSurfaceGroupIds:H.allowedSurfaceGroupIds,allowedSurfaceIds:H.allowedSurfaceIds,defaultSurfaceId:H.defaultSurfaceId??void 0,hideFromConfigurator:H.hideFromConfigurator},ne=b.get($);ne&&ne.length>0&&(K.dependencies=ne),z.push(K);}R[P.name]={models:{pointModel:x,addToModel:W},active:false,type:Kt.CONFIG,label:P.label??P.name,compatibleParts:z.length>0?z:void 0,slotGroupId:P.slotGroupId??void 0,mandatory:P.mandatory??false,showInPreview:P.showInPreview??false,defaultPartApiId:j(P)};}return Object.keys(R).length>0?R:void 0}a(A,"buildPartSlotsData");async function k(p){a$1.set(p.id,p);let R=new Set;for(let b of p.basePartSlots??[])for(let{partId:P}of b.compatibleParts??[])for(let x of O(P))R.add(x);for(let b of p.moduleSlots??[]){for(let P of b.accessoryPartIds??[])for(let x of O(P))R.add(x);for(let P of b.compatibleModuleIds??[]){let x=w(P);x&&a$1.set(P,x);}}await Promise.all([...R].map(async b=>{let P=m(b);if(P){if(i$1.set(b,P),P.models&&P.models.length>0)if(P.models.length===1){let x=await g$1(P.models[0]);x&&s.set(b,x);}else {let x=new Group;for(let W of P.models){let z=await g$1(W);z&&x.add(z);}s.set(b,x);}P.partSlots&&P.partSlots.length>0&&!f.has(b)&&f.set(b,A(P));}}));}a(k,"preloadModelsForModule");function I(p){if(!p.basePartSlots||p.basePartSlots.length===0)return;let R={};for(let b of p.basePartSlots){let P=new Object3D;P.position.set(b.pointPosition.x,b.pointPosition.y,b.pointPosition.z);let x=new Object3D;x.position.set(b.addPosition.x,b.addPosition.y,b.addPosition.z);let W=[];for(let{partId:H,addPosition:Q}of b.compatibleParts??[]){let K=m(H);if(!K)continue;let ne=D(b.addPosition,Q),ge=!K.models||K.models.length===0,te=ge?y(K,ne):L(K,ne);W.push({name:K.name,description:K.description??void 0,image:K.image??void 0,createPart:te,apiPartId:K.id,partTypeId:K.partTypeId??null,hasConfigurableSurface:K.hasConfigurableSurface,allowedSurfaceGroupIds:K.allowedSurfaceGroupIds,allowedSurfaceIds:K.allowedSurfaceIds,defaultSurfaceId:K.defaultSurfaceId??void 0,hideFromConfigurator:K.hideFromConfigurator,isEmpty:ge});}let z=i(b,W.flatMap(H=>H.apiPartId??[])),$=W.find(H=>H.apiPartId===z)?.createPart;if(!$){lu.warn("No valid parts found for slot",{slotName:b.name});continue}let Y=$();b.defaultInverted&&(Y.partGroup.scale.z=-1),R[b.name]={models:{pointModel:P,addToModel:x},active:false,type:Kt.CONFIG,label:b.label??b.name,part:Y,compatibleParts:W.length>0?W:void 0,slotGroupId:b.slotGroupId??void 0,column:b.column??void 0,row:b.row??void 0,invertible:b.invertible??false,canRotate:b.canRotate??false,order:b.order??0,disabledPartsByNeighborSlots:b.disabledPartsByNeighborSlots??[],enabledPartsByNeighborSlots:b.enabledPartsByNeighborSlots??[],disabledPartsByNeighborParts:b.disabledPartsByNeighborParts??[],backrestBlocksTables:b.backrestBlocksTables??void 0,hiddenBySlotParts:b.hiddenBySlotParts??[],syncWithSlotName:b.syncWithSlotName??void 0,defaultInverted:b.defaultInverted??false,isVariantDiscriminator:b.isVariantDiscriminator??false};}return Object.keys(R).length>0?R:void 0}a(I,"buildBasePartSlotsData");function U(p){if(!p.moduleSlots||p.moduleSlots.length===0)return;let R={};for(let b of p.moduleSlots){let P=new Object3D;P.position.set(b.floatingPointPosition.x,b.floatingPointPosition.y,b.floatingPointPosition.z);let x=new Object3D;if(x.position.set(b.moduleSlotPosition.x,b.moduleSlotPosition.y,b.moduleSlotPosition.z),b.direction)x.lookAt(new Vector3(b.moduleSlotPosition.x+b.direction.x,b.moduleSlotPosition.y+b.direction.y,b.moduleSlotPosition.z+b.direction.z));else {let $=new Vector3(b.moduleSlotPosition.x,0,b.moduleSlotPosition.z).normalize();$.length()>0&&x.lookAt($);}let W=[],z=b.compatibleModulesWithSlots&&b.compatibleModulesWithSlots.length>0?b.compatibleModulesWithSlots:(b.compatibleModuleIds??[]).map($=>({moduleId:$,allowedSlotNames:void 0}));for(let{moduleId:$,allowedSlotNames:Y}of z){let H=M.get($);if(!H)continue;let Q=a(()=>X(H.id),"createModuleFn");W.push({id:H.id,name:H.name,image:H.image??void 0,createModule:Q,allowedSlotNames:Y});}R[b.name]={models:{pointModel:P,addToModel:x},active:true,type:Kt.ADD,label:b.label??b.name,slotGroup:b.slotGroup??void 0,row:b.moduleSlotPosition.z>.05?"front":b.moduleSlotPosition.z<-0.05?"back":"middle",hasBuiltInConnector:b.hasBuiltInConnector,preferConnection:b.preferConnection,compatibleModules:W,disabledBySlotParts:b.disabledBySlotParts??[],enabledBySlotParts:b.enabledBySlotParts??[],disabledByNeighborSlots:b.disabledByNeighborSlots??[],linkedPartSlotName:b.linkedPartSlotName??void 0,autoConfigureParts:b.autoConfigureParts??[]};}return Object.keys(R).length>0?R:void 0}a(U,"buildModuleSlotsData");function X(p){let R=a$1.get(p);if(!R)throw new it("Module data",p);return tr({moduleData:R}).build()}a(X,"createModuleSync");async function C(p){await k(p);let R=I(p),b=U(p),P=tr({moduleData:p});return R&&P.withBasePartSlots({basePartSlotsData:R}),b&&P.withModuleSlots({moduleSlotsData:b}),P.build()}a(C,"createModuleFromApi");async function F(p){let R=w(p);if(!R)throw new Qt(p);return C(R)}a(F,"createModuleById");function G(){return o.surfaces.filter(p=>p.status!=="deleted")}a(G,"listSurfaces");function V(p){return v.get(p)}a(V,"getSurfaceRow");function N(p,R){return g(p,R,v.get(R)?.groupId)}a(N,"isSurfaceAllowed");function B(p){function R(b,P){let x=h(b,{inherited:P},W=>N(b,W));if(b.hasConfigurableSurface&&x){let W=h$1(x);W&&(b.model.traverse(z=>{mt(z)&&z.userData.hasConfigurableSurface&&(z.material=W);}),b.material=W,b.surfaceId=x);}for(let W of Object.values(b.partSlots??{}))W.part&&R(W.part,x);}a(R,"applyPartSurface");for(let b of Object.values(p.basePartSlots))R(b.part);t();}return a(B,"applyDefaultSurfaces"),{catalog:o,getModuleById:w,getPartById:m,getSurface:h$1,preloadModelsForModule:k,createModuleSync:X,createModuleFromApi:C,createModuleById:F,applyDefaultSurfaces:B,listSurfaces:G,getSurfaceRow:V,isSurfaceAllowed:N}}a(ar,"createCatalogAdapter");var bu=new TextureLoader;function yu(e,{repeat:o,anisotropy:t,colorSpace:r}){return new Promise((a,i)=>{bu.load(e,s=>{s.colorSpace=r,s.wrapS=s.wrapT=RepeatWrapping,s.minFilter=LinearMipmapLinearFilter,s.magFilter=LinearFilter,s.anisotropy=t,s.generateMipmaps=true,s.repeat.set(o,o),a(s);},void 0,s=>i(s));})}a(yu,"loadSurfaceTexture");var Va={map:SRGBColorSpace,normalMap:NoColorSpace,roughnessMap:NoColorSpace,metalnessMap:NoColorSpace,aoMap:NoColorSpace};async function ir(e,{repeat:o,anisotropy:t}){let r=await Promise.all(Object.keys(Va).map(async i=>{let s=e[i];if(!s)return [i,void 0];let l=Va[i];return [i,await yu(s,{repeat:o,anisotropy:t,colorSpace:l})]})),a=Object.fromEntries(r.filter(([,i])=>i));return a.aoMap&&(a.aoMap.channel=0),a}a(ir,"loadSurfaceMaps");function ro(e,{map:o,normalMap:t,roughnessMap:r,metalnessMap:a,aoMap:i},s){let{sheen:l,sheenColor:c,sheenRoughness:f,emissive:u,anisotropy:d,anisotropyRotation:M}=e,v=l!==void 0||c!==void 0||f!==void 0||u!==void 0||d!==void 0||M!==void 0,m={...o?{map:o,...e.tint&&{color:new Color(e.color??"#ffffff")},roughness:e.roughness??.8,metalness:e.metalness??.1}:{color:new Color(e.color??"#808080"),metalness:e.metalness??.1,roughness:e.roughness??.8},...e.envMapIntensity!==void 0&&{envMapIntensity:e.envMapIntensity,...s&&{envMap:s}},...t&&{normalMap:t,...e.normalScale!==void 0&&{normalScale:new Vector2(e.normalScale,e.normalScale)}},...r&&{roughnessMap:r},...a&&{metalnessMap:a},...i&&{aoMap:i,...e.aoIntensity!==void 0&&{aoMapIntensity:e.aoIntensity}},...e.doubleSided&&{side:DoubleSide}};return v?new MeshPhysicalMaterial({...m,...l!==void 0&&{sheen:l},...c!==void 0&&{sheenColor:new Color(c)},...f!==void 0&&{sheenRoughness:f},...u!==void 0&&{emissive:new Color(u)},...d!==void 0&&{anisotropy:d},...M!==void 0&&{anisotropyRotation:M}}):new MeshStandardMaterial(m)}a(ro,"createSurfaceMaterial");function Xa(e,o){let t=e.geometry.clone();if(t.applyMatrix4(o),o.determinant()<0){let r=t.getIndex();if(r){let a=r.array;for(let i=0;i<a.length;i+=3){let s=a[i+1];a[i+1]=a[i+2],a[i+2]=s;}r.needsUpdate=true;}else {let a=t.getAttribute("position"),i=a.array,s=a.itemSize*3;for(let l=0;l<i.length;l+=s)for(let c=0;c<a.itemSize;c++){let f=l+a.itemSize+c,u=l+2*a.itemSize+c,d=i[f];i[f]=i[u],i[u]=d;}a.needsUpdate=true;}}e.geometry=t;}a(Xa,"bakeMatrixIntoGeometry");function $a(e,o,t){e.model.updateWorldMatrix(true,false);let r=e.model.matrixWorld.clone(),a=t.clone().invert(),i=r.premultiply(a),s=e.model.clone(true),l=i;if(i.determinant()<0){let d=new Matrix4().makeScale(-1,1,1);l=i.clone().multiply(d),s.position.set(0,0,0),s.quaternion.identity(),s.scale.set(1,1,1),s.updateMatrixWorld(true),s.traverse(M=>{let v=M;if(!v.isMesh)return;let m=v.matrixWorld.clone(),w=m.clone().invert().multiply(d).multiply(m);Xa(v,w);});}let c=new Vector3,f=new Quaternion,u=new Vector3;l.decompose(c,f,u),s.position.copy(c),s.quaternion.copy(f),s.scale.copy(u),o.add(s);for(let d in e.partSlots){let M=e.partSlots[d];M?.part&&$a(M.part,o,t);}}a($a,"clonePartModel");function Su(e){if(e.length===0)throw new Error("No modules to export");let o=new Group;o.name="ConfiguratorExport";for(let t of e){let r=new Group;r.position.copy(t.moduleGroup.position),r.rotation.copy(t.moduleGroup.rotation),r.scale.copy(t.moduleGroup.scale);let a=new Matrix4;t.moduleGroup.updateWorldMatrix(true,false),a.copy(t.moduleGroup.matrixWorld);for(let i in t.basePartSlots){let s=t.basePartSlots[i];s?.part&&!s.hidden&&!s.cleared&&$a(s.part,r,a);}o.add(r);}return o.updateMatrixWorld(true),o}a(Su,"buildExportObject3D");var wu=35.714285714285715;function Ya(e){if(!(!e||e<=0))return wu/e}a(Ya,"textureRepeatForImageSize");function Mu(e){let o=e.textureJson;if(!o)return {};if(typeof o=="object")return o;try{return JSON.parse(o)}catch{return {}}}a(Mu,"textureOptions");function Za(e,o=new Set){function t(r){if(r){r.surfaceId!==void 0&&o.add(r.surfaceId);for(let a of Object.values(r.nestedSlots))t(a);}}a(t,"walk");for(let r of Object.values(e.basePartSlots))t(r);for(let r of Object.values(e.children))Za(r,o);return o}a(Za,"surfaceIdsOf");function kh({catalog:e,anisotropy:o,environment:t,invalidate:r}){let a$1=new Map(e.surfaces.map(m=>[m.id,m])),i=new Map,s=new Map,l=new Set;for(let m of e.parts)for(let w of m.models)w.fixedSurfaceId&&l.add(w.fixedSurfaceId);function c(m){let w=s.get(m);if(w)return w;let h=a$1.get(m),S=(async()=>{if(!h)return;let g=Mu(h),D=(typeof g.repeat=="number"?g.repeat:void 0)??Ya(h.imageSizeCm)??1,O=a(L=>typeof g[L]=="string"?g[L]:void 0,"path");try{let L=await ir({map:h.texturePath??void 0,normalMap:O("normalPath"),roughnessMap:O("roughnessPath"),metalnessMap:O("metalnessPath"),aoMap:O("aoPath")},{repeat:D,anisotropy:o});i.set(m,ro(g,L,t()));}catch(L){console.warn(`[konfigure] finish ${m} textures failed; drawing its colour`,L),i.set(m,ro(g,{},t()));}})();return s.set(m,S),S}a(c,"loadMaterial");let f=ar({catalog:e,createSurfaceMaterial:a(m=>i.get(m.id)??null,"createSurfaceMaterial"),invalidate:r});function u(m,w){if(!m.hasConfigurableSurface||w===void 0)return;let h=f.getSurface(w);h&&(m.model.traverse(S=>{let g=S;g.isMesh&&g.userData.hasConfigurableSurface&&(g.material=h);}),m.material=h,m.surfaceId=w);}a(u,"paint");function d(m,w){for(let[h,S]of Object.entries(w.nestedSlots)){let g=m.partSlots?.[h];if(g){if(!S){g.part&&m.partGroup.remove(g.part.partGroup),g.part=void 0;continue}if(g.part?.apiPartId!==S.apiPartId){let D=g.compatibleParts?.find(L=>L.apiPartId===S.apiPartId);if(!D)continue;g.part&&m.partGroup.remove(g.part.partGroup);let O=D.createPart();m.partGroup.add(O.partGroup),g.part=O;}u(g.part,S.surfaceId),d(g.part,S);}}}a(d,"applyNested");function M(m,w){for(let[h,S]of Object.entries(w.basePartSlots)){let g=m.basePartSlots[h];if(g){if(g.part?.apiPartId!==S.apiPartId){let D=g.compatibleParts?.find(L=>L.apiPartId===S.apiPartId);if(!D)continue;let O=D.createPart();g.part&&m.moduleGroup.remove(g.part.partGroup),m.moduleGroup.add(O.partGroup),g.part=O;}g.part.partGroup.scale.z=w.invertedSlots[h]?-1:1,g.part.partGroup.rotation.y=w.rotatedSlots[h]?Math.PI:0,u(g.part,S.surfaceId),d(g.part,S);}}He(m.moduleGroup,true,true),m.moduleGroup.userData.updateBoundingBoxes?.();}a(M,"applyState");async function v(m){await Promise.all([...Za(m),...l].map(h=>c(h)));let w=await f.createModuleById(m.apiModuleId);if(M(w,m),m.size){let h=er(w.moduleGroup,m.size);h&&(w.size=h,w.sizes={...w.sizes,x:h.width/1e3}),w.moduleGroup.userData.updateBoundingBoxes?.();}return w}return a(v,"build"),{adapter:f,build:v,dispose(){for(let m of i.values())m.dispose();i.clear(),s.clear();}}}a(kh,"createModuleBuilder");/* @license
|
|
770
|
+
* Original neutral environment data from Google's <model-viewer> project.
|
|
771
|
+
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
772
|
+
* Licensed under the Apache License, Version 2.0 (the 'License');
|
|
773
|
+
* you may obtain a copy of the License at
|
|
774
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
775
|
+
*/
|
|
776
|
+
/* @license
|
|
777
|
+
* Original neutral environment scene from Google's <model-viewer> project.
|
|
778
|
+
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
779
|
+
* Licensed under the Apache License, Version 2.0 (the 'License');
|
|
780
|
+
* you may obtain a copy of the License at
|
|
781
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
782
|
+
*/export{Fi as a,Gi as b,sl as c,cl as d,ul as e,dl as f,hl as g,oa as h,bc as i,Dc as j,Ec as k,xt as l,_c as m,Su as n,Fe as o,Fc as p,Gc as q,Xc as r,kh as s};
|