@maucwerk/glimmer 1.2.2 → 1.2.3

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 CHANGED
@@ -865,7 +865,7 @@ Access-Control-Allow-Methods: GET
865
865
  ## Package Structure
866
866
 
867
867
  ```
868
- @maucwerk/glimmer@1.2.2
868
+ @maucwerk/glimmer@1.2.3
869
869
  ├── dist/
870
870
  │ ├── index.d.ts # Main TypeScript declarations
871
871
  │ ├── vite/
@@ -880,7 +880,11 @@ The package supports both ESM and CommonJS with complete TypeScript declarations
880
880
 
881
881
  ## Version History
882
882
 
883
- ### v1.2.2 (Current)
883
+ ### v1.2.3 (Current)
884
+
885
+ - ✅ CSM cascade fading: no more visible transitions between cascades
886
+
887
+ ### v1.2.2
884
888
 
885
889
  - ✅ CSM actually renders: shadow maps enabled, materials registered, bias controls; bird edges tuned for readability
886
890
 
@@ -5645,7 +5645,7 @@ class Il {
5645
5645
  shadowBias: t.shadow_bias,
5646
5646
  lightDirection: s.clone(),
5647
5647
  lightIntensity: e.intensity
5648
- }), this.csm.lights.forEach((i) => {
5648
+ }), this.csm.fade = !0, this.csm.lights.forEach((i) => {
5649
5649
  i.color.set(e.color), i.intensity = e.intensity, i.shadow.normalBias = t.shadow_normal_bias;
5650
5650
  }), this.csm_callback = () => {
5651
5651
  var i;
@@ -443,7 +443,7 @@ uniform vec2 CSM_cascades[CSM_CASCADES];
443
443
  uniform float cameraNear;
444
444
  uniform float shadowFar;
445
445
  #endif
446
- `+h.ShaderChunk.lights_pars_begin},Li=new h.Matrix4,hs=new Pn({webGL:!0}),Je=new h.Vector3,an=new h.Box3,us=[],fs=[],ms=new h.Matrix4,Ti=new h.Matrix4,va=new h.Vector3(0,1,0);class xa{constructor(e){this.camera=e.camera,this.parent=e.parent,this.cascades=e.cascades||3,this.maxFar=e.maxFar||1e5,this.mode=e.mode||"practical",this.shadowMapSize=e.shadowMapSize||2048,this.shadowBias=e.shadowBias||1e-6,this.lightDirection=e.lightDirection||new h.Vector3(1,-1,1).normalize(),this.lightIntensity=e.lightIntensity||3,this.lightNear=e.lightNear||1,this.lightFar=e.lightFar||2e3,this.lightMargin=e.lightMargin||200,this.customSplitsCallback=e.customSplitsCallback,this.fade=!1,this.mainFrustum=new Pn({webGL:!0}),this.frustums=[],this.breaks=[],this.lights=[],this.shaders=new Map,this._createLights(),this.updateFrustums(),this._injectInclude()}_createLights(){for(let e=0;e<this.cascades;e++){const t=new h.DirectionalLight(16777215,this.lightIntensity);t.castShadow=!0,t.shadow.mapSize.width=this.shadowMapSize,t.shadow.mapSize.height=this.shadowMapSize,t.shadow.camera.near=this.lightNear,t.shadow.camera.far=this.lightFar,t.shadow.bias=this.shadowBias,this.parent.add(t),this.parent.add(t.target),this.lights.push(t)}}_initCascades(){const e=this.camera;e.updateProjectionMatrix(),this.mainFrustum.setFromProjectionMatrix(e.projectionMatrix,this.maxFar),this.mainFrustum.split(this.breaks,this.frustums)}_updateShadowBounds(){const e=this.frustums;for(let t=0;t<e.length;t++){const s=this.lights[t].shadow.camera,i=this.frustums[t],o=i.vertices.near,a=i.vertices.far,c=a[0];let l;c.distanceTo(a[2])>c.distanceTo(o[2])?l=a[2]:l=o[2];let d=c.distanceTo(l);if(this.fade){const u=this.camera,f=Math.max(u.far,this.maxFar),m=i.vertices.far[0].z/(f-u.near),y=.25*Math.pow(m,2)*(f-u.near);d+=y}s.left=-d/2,s.right=d/2,s.top=d/2,s.bottom=-d/2,s.updateProjectionMatrix()}}_getBreaks(){const e=this.camera,t=Math.min(e.far,this.maxFar);switch(this.breaks.length=0,this.mode){case"uniform":n(this.cascades,e.near,t,this.breaks);break;case"logarithmic":s(this.cascades,e.near,t,this.breaks);break;case"practical":i(this.cascades,e.near,t,.5,this.breaks);break;case"custom":this.customSplitsCallback===void 0&&console.error("CSM: Custom split scheme callback not defined."),this.customSplitsCallback(this.cascades,e.near,t,this.breaks);break}function n(o,a,c,l){for(let d=1;d<o;d++)l.push((a+(c-a)*d/o)/c);l.push(1)}function s(o,a,c,l){for(let d=1;d<o;d++)l.push(a*(c/a)**(d/o)/c);l.push(1)}function i(o,a,c,l,d){us.length=0,fs.length=0,s(o,a,c,fs),n(o,a,c,us);for(let u=1;u<o;u++)d.push(h.MathUtils.lerp(us[u-1],fs[u-1],l));d.push(1)}}update(){const e=this.camera,t=this.frustums;ms.lookAt(new h.Vector3,this.lightDirection,va),Ti.copy(ms).invert();for(let n=0;n<t.length;n++){const s=this.lights[n],i=s.shadow.camera,o=(i.right-i.left)/this.shadowMapSize,a=(i.top-i.bottom)/this.shadowMapSize;Li.multiplyMatrices(Ti,e.matrixWorld),t[n].toSpace(Li,hs);const c=hs.vertices.near,l=hs.vertices.far;an.makeEmpty();for(let d=0;d<4;d++)an.expandByPoint(c[d]),an.expandByPoint(l[d]);an.getCenter(Je),Je.z=an.max.z+this.lightMargin,Je.x=Math.floor(Je.x/o)*o,Je.y=Math.floor(Je.y/a)*a,Je.applyMatrix4(ms),s.position.copy(Je),s.target.position.copy(Je),s.target.position.x+=this.lightDirection.x,s.target.position.y+=this.lightDirection.y,s.target.position.z+=this.lightDirection.z}}_injectInclude(){h.ShaderChunk.lights_fragment_begin=Mi.lights_fragment_begin,h.ShaderChunk.lights_pars_begin=Mi.lights_pars_begin}setupMaterial(e){e.defines=e.defines||{},e.defines.USE_CSM=1,e.defines.CSM_CASCADES=this.cascades,this.fade&&(e.defines.CSM_FADE="");const t=[],n=this,s=this.shaders;e.onBeforeCompile=function(i){const o=Math.min(n.camera.far,n.maxFar);n._getExtendedBreaks(t),i.uniforms.CSM_cascades={value:t},i.uniforms.cameraNear={value:n.camera.near},i.uniforms.shadowFar={value:o},s.set(e,i)},s.set(e,null)}_updateUniforms(){const e=Math.min(this.camera.far,this.maxFar);this.shaders.forEach(function(n,s){if(n!==null){const i=n.uniforms;this._getExtendedBreaks(i.CSM_cascades.value),i.cameraNear.value=this.camera.near,i.shadowFar.value=e}!this.fade&&"CSM_FADE"in s.defines?(delete s.defines.CSM_FADE,s.needsUpdate=!0):this.fade&&!("CSM_FADE"in s.defines)&&(s.defines.CSM_FADE="",s.needsUpdate=!0)},this)}_getExtendedBreaks(e){for(;e.length<this.breaks.length;)e.push(new h.Vector2);e.length=this.breaks.length;for(let t=0;t<this.cascades;t++){const n=this.breaks[t],s=this.breaks[t-1]||0;e[t].x=s,e[t].y=n}}updateFrustums(){this._getBreaks(),this._initCascades(),this._updateShadowBounds(),this._updateUniforms()}remove(){for(let e=0;e<this.lights.length;e++)this.parent.remove(this.lights[e].target),this.parent.remove(this.lights[e])}dispose(){const e=this.shaders;e.forEach(function(t,n){delete n.onBeforeCompile,delete n.defines.USE_CSM,delete n.defines.CSM_CASCADES,delete n.defines.CSM_FADE,t!==null&&(delete t.uniforms.CSM_cascades,delete t.uniforms.cameraNear,delete t.uniforms.shadowFar),n.needsUpdate=!0}),e.clear()}}function Di(r){const t=new _.Box3().setFromObject(r).getSize(new _.Vector3);return Math.max(10,Math.max(t.x,t.y,t.z))}const ba=512,wa=100,Sa=30,Aa=-.001,Ma=3,La=16,{PI:Ta,sin:Qe,cos:et,tan:Ci,asin:Oi,atan2:Ii}=Math,Ne=Ta/180,Da=1e3*60*60*24,Ca=2440588,Oa=2451545;function Ia(r){return r.valueOf()/Da-.5+Ca-Oa}function ka(r){const e=2e3+r/365.2425;let t;return e<1920?(t=e-1900,-2.79+t*(1.494119+t*(-.0598939+t*(.0061966-t*197e-6)))):e<1941?(t=e-1920,21.2+t*(.84493+t*(-.0761+t*.0020936))):e<1961?(t=e-1950,29.07+t*(.407+t*(-1/233+t/2547))):e<1986?(t=e-1975,45.45+t*(1.067+t*(-1/260-t/718))):e<2005?(t=e-2e3,63.86+t*(.3345+t*(-.060374+t*(.0017275+t*(651814e-9+t*2373599e-11))))):e<2050?(t=e-2e3,62.92+t*(.32217+t*.005589)):(t=(e-1820)/100,-20+32*t*t-.5628*(2150-e))}function Na(r){return r+ka(r)/86400}function Ea(r,e,t){return(Ii(Qe(r),et(r)*Qe(e)-Ci(t)*et(e))/Ne+540)%360}function Pa(r,e,t){return Oi(Qe(e)*Qe(t)+et(e)*et(t)*et(r))}function Ra(r,e){return Ne*(280.46061837+360.98564736629*r)-e}function za(r){return r<0&&(r=0),2967e-7/Ci(r+.00312536/(r+.08901179))}function Ua(r){const e=r/36525,t=Ne*(280.46646+e*(36000.76983+e*3032e-7)),n=Ne*(357.52911+e*(35999.05029-e*1537e-7)),s=Qe(n),i=et(n),o=Ne*((1.914602-e*(.004817+e*14e-6))*s+(.019993-101e-6*e)*2*s*i+289e-6*s*(3-4*s*s)),a=Ne*(125.04-1934.136*e),c=t+o-Ne*(.00569+.00478*Qe(a)),l=Ne*(23.439291-e*(.0130042+e*(16e-8-e*504e-9)))+Ne*.00256*et(a);return{ra:Ii(et(l)*Qe(c),et(c)),dec:Oi(Qe(l)*Qe(c)),lon:c}}function Fa(r,e,t){const n=Ne*-t,s=Ne*e,i=Ia(r),o=Ua(Na(i)),a=Ra(i,n)-o.ra,c=Pa(a,s,o.dec);return{azimuth:Ea(a,s,o.dec),altitude:(c+za(c))/Ne}}const ps=Math.PI/180;function ja(r,e,t){const n=Fa(t,r,e),s=n.altitude,i=(n.azimuth%360+360)%360,o=s*ps,a=i*ps,c=new _.Vector3(Math.cos(o)*Math.sin(a),Math.sin(o),-Math.cos(o)*Math.cos(a));return{altitude_deg:s,azimuth_deg:i,direction:c}}const Ba=-6;function Va(r,e,t){const n=new _.Color(t);if(r<=Ba)return{intensity:0,color:new _.Color(0)};const s=Math.max(0,r),i=Math.sin(Math.min(s,90)*ps),o=e*(.12+.88*i),a=1-Math.min(s/30,1),l=new _.Color(16747586).lerp(n,1-a*.85);return{intensity:o,color:l}}class ki{constructor(e,t,n,s){g(this,"viewer");g(this,"scene");g(this,"settings");g(this,"sun_settings");g(this,"model_manager");g(this,"sun",null);g(this,"environment");g(this,"csm",null);g(this,"csm_key",null);g(this,"csm_callback",null);g(this,"models_watched",!1);this.viewer=e,this.scene=e.scene,this.settings=t,this.environment=n,this.model_manager=s,this.sun_settings=this.settings.get("environment").sun,this.settings.addEventListener("update",i=>{const o=i.detail;this.sun_settings=o.environment.sun,this.update()}),this.settings.addEventListener("environmentTextureLoaded",i=>{const o=i.detail.texture;if(this.environment.texture=o,this.sun&&this.sun_settings){const a=this._infer_sun_position_from_env_map();a&&(B.debug("Texture loaded event call; inferred Sun position from env map:",a),this.sun_settings.position=[a.x,a.y,a.z],this.update())}}),this.update()}update(){if(!this.sun_settings){this.sun&&(this.scene.remove(this.sun),this.sun=null);return}this.model_manager.ready.then(()=>{if(!this.sun_settings){this.teardown_csm();return}const e=this.apply_solar();if(!e){const n=this._infer_sun_position_from_env_map();n&&(B.debug("Inferred Sun position from env map:",n),this.sun_settings.position=[n.x,n.y,n.z])}const t=e??{position:this.sun_settings.position,intensity:this.sun_settings.intensity,color:this.sun_settings.color};this.sun_settings.csm?(this.remove_classic_sun(),this.sync_csm(t)):(this.teardown_csm(),this.sun_create(e??void 0)),this.sun_settings&&this.sync_sky(t.position)})}sync_sky(e){e&&this.environment.update_sky_environment(new _.Vector3(e[0],e[1],e[2]))}sun_fit_object(e=this.scene){const t=Di(e);let n=new _.Vector3(0,1,0).normalize();n=n.multiplyScalar(t*2),this.sun&&(n=this.sun.position.clone())}sun_fit_shadow(){const e=new _.Object3D;if(!this.model_manager){B.warn("No model manager found.");return}for(const o of this.model_manager.models.values())o.settings.shadow&&e.add(o.group.clone());e.children.length===0&&B.warn("No models with shadows found to fit shadow map."),B.debug("Models in fit_object:",e);const t=Di(e),n=ba,s=Math.ceil(t/wa),i=Math.min(Math.pow(2,Math.ceil(Math.log2(n*s))),this.viewer.renderer.capabilities.maxTextureSize);if(B.debug("Shadow map size:",i),this.sun){this.sun.shadow.mapSize.width=i,this.sun.shadow.mapSize.height=i;const o=Sa;this.sun.shadow.camera.left=-(t/2+o),this.sun.shadow.camera.right=t/2+o,this.sun.shadow.camera.top=t/2+o,this.sun.shadow.camera.bottom=-(t/2+o),this.sun.shadow.camera.near=.1,this.sun.shadow.camera.far=t*2,this.sun.shadow.bias=Aa,this.sun.shadow.radius=Ma,this.sun.shadow.blurSamples=La,B.info(`Recreated sun with shadow map size: ${i}x${i}`)}}resolve_solar(){const e=this.sun_settings.solar,t=ja(e.latitude,e.longitude,new Date(e.datetime)),n=Va(t.altitude_deg,this.sun_settings.intensity,this.sun_settings.color),s=t.direction.multiplyScalar(100);let i=0;return n.intensity>0&&(i=+`0x${n.color.getHexString()}`),B.debug(`Solar sun: lat ${e.latitude}, lon ${e.longitude}, alt ${t.altitude_deg.toFixed(1)}°, az ${t.azimuth_deg.toFixed(1)}°`),{position:[s.x,s.y,s.z],intensity:n.intensity,color:i}}apply_solar(){var e;if((e=this.sun_settings)!=null&&e.solar)try{return this.resolve_solar()}catch(t){B.warn("Failed to resolve solar sun, falling back to configured values:",t);return}}sun_create(e){if(!this.sun_settings)return;this.sun&&(this.scene.remove(this.sun),this.sun.dispose(),this.sun=null);const t=(e==null?void 0:e.color)??this.sun_settings.color,n=(e==null?void 0:e.intensity)??this.sun_settings.intensity;this.sun=new _.DirectionalLight(t,n),this.sun_settings.shadow&&(this.viewer.renderer.shadowMap.enabled=!0,this.sun.castShadow=!0,this.sun_fit_shadow()),this.sun.position.set(...(e==null?void 0:e.position)??this.sun_settings.position),this.scene.add(this.sun)}_infer_sun_position_from_env_map(){if(!this.environment)return B.warn("No environment map available."),null;const e=this.environment.texture,t=e==null?void 0:e.image;if(!t||!t.width||!t.height||!t.data)return B.warn("No environment map texture found."),null;const n=t.width,s=t.height,i=t.data;let o=0;const a=[];for(let m=0;m<i.length;m+=4){const y=i[m],v=i[m+1],b=i[m+2],S=.2126*y+.7152*v+.0722*b;if(S>o){o=S,a.length=0;const A=m/4;a.push({x:A%n,y:Math.floor(A/n)})}else if(S===o){const A=m/4;a.push({x:A%n,y:Math.floor(A/n)})}}let c=0,l=0;a.forEach(m=>{c+=m.x,l+=m.y}),c/=a.length,l/=a.length;let d=c/n*2*Math.PI;d=(d+Math.PI)%(2*Math.PI);const u=l/s*Math.PI,f=new _.Vector3(Math.sin(u)*Math.cos(d),Math.cos(u),Math.sin(u)*Math.sin(d));return f.normalize(),f.multiplyScalar(100)}remove_classic_sun(){var e,t;this.sun&&(this.scene.remove(this.sun),(t=(e=this.sun).dispose)==null||t.call(e),this.sun=null)}sync_csm(e){const t=this.sun_settings.csm,n=JSON.stringify(t),s=new _.Vector3(-e.position[0],-e.position[1],-e.position[2]).normalize();!this.csm||this.csm_key!==n?(this.teardown_csm(),this.viewer.renderer.shadowMap.enabled=!0,this.csm=new xa({camera:this.viewer.camera,parent:this.scene,cascades:t.cascades,maxFar:t.max_far,mode:"practical",shadowMapSize:t.shadow_map_size,shadowBias:t.shadow_bias,lightDirection:s.clone(),lightIntensity:e.intensity}),this.csm.lights.forEach(i=>{i.color.set(e.color),i.intensity=e.intensity,i.shadow.normalBias=t.shadow_normal_bias}),this.csm_callback=()=>{var i;(i=this.csm)==null||i.update()},this.viewer.register_animation_callback(this.csm_callback),this.csm_key=n,this.watch_model_loads()):(this.csm.lightDirection.copy(s),this.csm.lightIntensity=e.intensity,this.csm.lights.forEach(i=>{i.color.set(e.color),i.intensity=e.intensity,i.shadow.normalBias=t.shadow_normal_bias})),this.setup_csm_materials()}setup_csm_materials(){!this.csm||!this.csm_key||this.scene.traverse(e=>{const t=e;if(!t.isMesh)return;const n=Array.isArray(t.material)?t.material:[t.material];for(const s of n){if(!s)continue;const i=s;(i.isMeshStandardMaterial||i.isMeshLambertMaterial||i.isMeshPhongMaterial)&&i.userData.csm_setup_key!==this.csm_key&&(this.csm.setupMaterial(i),i.userData.csm_setup_key=this.csm_key,i.needsUpdate=!0)}})}watch_model_loads(){this.models_watched||(this.models_watched=!0,this.model_manager.addEventListener("loaded",()=>{this.setup_csm_materials()}))}teardown_csm(){this.csm_callback&&(this.viewer.unregister_animation_callback(this.csm_callback),this.csm_callback=null),this.csm&&(this.csm.remove(),this.csm.dispose(),this.csm=null),this.csm_key=null}dispose(){this.teardown_csm(),this.remove_classic_sun()}}const ue=[];for(let r=0;r<256;++r)ue.push((r+256).toString(16).slice(1));function Ga(r,e=0){return(ue[r[e+0]]+ue[r[e+1]]+ue[r[e+2]]+ue[r[e+3]]+"-"+ue[r[e+4]]+ue[r[e+5]]+"-"+ue[r[e+6]]+ue[r[e+7]]+"-"+ue[r[e+8]]+ue[r[e+9]]+"-"+ue[r[e+10]]+ue[r[e+11]]+ue[r[e+12]]+ue[r[e+13]]+ue[r[e+14]]+ue[r[e+15]]).toLowerCase()}let _s;const Za=new Uint8Array(16);function Wa(){if(!_s){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");_s=crypto.getRandomValues.bind(crypto)}return _s(Za)}const Ni={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Xa(r,e,t){var s;if(Ni.randomUUID&&!r)return Ni.randomUUID();r=r||{};const n=r.random??((s=r.rng)==null?void 0:s.call(r))??Wa();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Ga(n)}function $a(r,e=1e-4){e=Math.max(e,Number.EPSILON);const t={},n=r.getIndex(),s=r.getAttribute("position"),i=n?n.count:s.count;let o=0;const a=Object.keys(r.attributes),c={},l={},d=[],u=["getX","getY","getZ","getW"],f=["setX","setY","setZ","setW"];for(let A=0,L=a.length;A<L;A++){const x=a[A],z=r.attributes[x];c[x]=new z.constructor(new z.array.constructor(z.count*z.itemSize),z.itemSize,z.normalized);const Z=r.morphAttributes[x];Z&&(l[x]||(l[x]=[]),Z.forEach((j,O)=>{const D=new j.array.constructor(j.count*j.itemSize);l[x][O]=new j.constructor(D,j.itemSize,j.normalized)}))}const m=e*.5,y=Math.log10(1/e),v=Math.pow(10,y),b=m*v;for(let A=0;A<i;A++){const L=n?n.getX(A):A;let x="";for(let z=0,Z=a.length;z<Z;z++){const j=a[z],O=r.getAttribute(j),D=O.itemSize;for(let k=0;k<D;k++)x+=`${~~(O[u[k]](L)*v+b)},`}if(x in t)d.push(t[x]);else{for(let z=0,Z=a.length;z<Z;z++){const j=a[z],O=r.getAttribute(j),D=r.morphAttributes[j],k=O.itemSize,R=c[j],W=l[j];for(let $=0;$<k;$++){const N=u[$],ee=f[$];if(R[ee](o,O[N](L)),D)for(let Y=0,Me=D.length;Y<Me;Y++)W[Y][ee](o,D[Y][N](L))}}t[x]=o,d.push(o),o++}}const S=r.clone();for(const A in r.attributes){const L=c[A];if(S.setAttribute(A,new L.constructor(L.array.slice(0,o*L.itemSize),L.itemSize,L.normalized)),A in l)for(let x=0;x<l[A].length;x++){const z=l[A][x];S.morphAttributes[A][x]=new z.constructor(z.array.slice(0,o*z.itemSize),z.itemSize,z.normalized)}}return S.setIndex(d),S}function Ei(r,e){if(e===h.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),r;if(e===h.TriangleFanDrawMode||e===h.TriangleStripDrawMode){let t=r.getIndex();if(t===null){const o=[],a=r.getAttribute("position");if(a!==void 0){for(let c=0;c<a.count;c++)o.push(c);r.setIndex(o),t=r.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),r}const n=t.count-2,s=[];if(e===h.TriangleFanDrawMode)for(let o=1;o<=n;o++)s.push(t.getX(0)),s.push(t.getX(o)),s.push(t.getX(o+1));else for(let o=0;o<n;o++)o%2===0?(s.push(t.getX(o)),s.push(t.getX(o+1)),s.push(t.getX(o+2))):(s.push(t.getX(o+2)),s.push(t.getX(o+1)),s.push(t.getX(o)));s.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=r.clone();return i.setIndex(s),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),r}const Pi=new h.Box3,Rn=new h.Vector3;class gs extends h.InstancedBufferGeometry{constructor(){super(),this.isLineSegmentsGeometry=!0,this.type="LineSegmentsGeometry";const e=[-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0],t=[-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2],n=[0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5];this.setIndex(n),this.setAttribute("position",new h.Float32BufferAttribute(e,3)),this.setAttribute("uv",new h.Float32BufferAttribute(t,2))}applyMatrix4(e){const t=this.attributes.instanceStart,n=this.attributes.instanceEnd;return t!==void 0&&(t.applyMatrix4(e),n.applyMatrix4(e),t.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}setPositions(e){let t;e instanceof Float32Array?t=e:Array.isArray(e)&&(t=new Float32Array(e));const n=new h.InstancedInterleavedBuffer(t,6,1);return this.setAttribute("instanceStart",new h.InterleavedBufferAttribute(n,3,0)),this.setAttribute("instanceEnd",new h.InterleavedBufferAttribute(n,3,3)),this.instanceCount=this.attributes.instanceStart.count,this.computeBoundingBox(),this.computeBoundingSphere(),this}setColors(e){let t;e instanceof Float32Array?t=e:Array.isArray(e)&&(t=new Float32Array(e));const n=new h.InstancedInterleavedBuffer(t,6,1);return this.setAttribute("instanceColorStart",new h.InterleavedBufferAttribute(n,3,0)),this.setAttribute("instanceColorEnd",new h.InterleavedBufferAttribute(n,3,3)),this}fromWireframeGeometry(e){return this.setPositions(e.attributes.position.array),this}fromEdgesGeometry(e){return this.setPositions(e.attributes.position.array),this}fromMesh(e){return this.fromWireframeGeometry(new h.WireframeGeometry(e.geometry)),this}fromLineSegments(e){const t=e.geometry;return this.setPositions(t.attributes.position.array),this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new h.Box3);const e=this.attributes.instanceStart,t=this.attributes.instanceEnd;e!==void 0&&t!==void 0&&(this.boundingBox.setFromBufferAttribute(e),Pi.setFromBufferAttribute(t),this.boundingBox.union(Pi))}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new h.Sphere),this.boundingBox===null&&this.computeBoundingBox();const e=this.attributes.instanceStart,t=this.attributes.instanceEnd;if(e!==void 0&&t!==void 0){const n=this.boundingSphere.center;this.boundingBox.getCenter(n);let s=0;for(let i=0,o=e.count;i<o;i++)Rn.fromBufferAttribute(e,i),s=Math.max(s,n.distanceToSquared(Rn)),Rn.fromBufferAttribute(t,i),s=Math.max(s,n.distanceToSquared(Rn));this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&console.error("THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.",this)}}toJSON(){}}h.UniformsLib.line={worldUnits:{value:1},linewidth:{value:1},resolution:{value:new h.Vector2(1,1)},dashOffset:{value:0},dashScale:{value:1},dashSize:{value:1},gapSize:{value:1}},h.ShaderLib.line={uniforms:h.UniformsUtils.merge([h.UniformsLib.common,h.UniformsLib.fog,h.UniformsLib.line]),vertexShader:`
446
+ `+h.ShaderChunk.lights_pars_begin},Li=new h.Matrix4,hs=new Pn({webGL:!0}),Je=new h.Vector3,an=new h.Box3,us=[],fs=[],ms=new h.Matrix4,Ti=new h.Matrix4,va=new h.Vector3(0,1,0);class xa{constructor(e){this.camera=e.camera,this.parent=e.parent,this.cascades=e.cascades||3,this.maxFar=e.maxFar||1e5,this.mode=e.mode||"practical",this.shadowMapSize=e.shadowMapSize||2048,this.shadowBias=e.shadowBias||1e-6,this.lightDirection=e.lightDirection||new h.Vector3(1,-1,1).normalize(),this.lightIntensity=e.lightIntensity||3,this.lightNear=e.lightNear||1,this.lightFar=e.lightFar||2e3,this.lightMargin=e.lightMargin||200,this.customSplitsCallback=e.customSplitsCallback,this.fade=!1,this.mainFrustum=new Pn({webGL:!0}),this.frustums=[],this.breaks=[],this.lights=[],this.shaders=new Map,this._createLights(),this.updateFrustums(),this._injectInclude()}_createLights(){for(let e=0;e<this.cascades;e++){const t=new h.DirectionalLight(16777215,this.lightIntensity);t.castShadow=!0,t.shadow.mapSize.width=this.shadowMapSize,t.shadow.mapSize.height=this.shadowMapSize,t.shadow.camera.near=this.lightNear,t.shadow.camera.far=this.lightFar,t.shadow.bias=this.shadowBias,this.parent.add(t),this.parent.add(t.target),this.lights.push(t)}}_initCascades(){const e=this.camera;e.updateProjectionMatrix(),this.mainFrustum.setFromProjectionMatrix(e.projectionMatrix,this.maxFar),this.mainFrustum.split(this.breaks,this.frustums)}_updateShadowBounds(){const e=this.frustums;for(let t=0;t<e.length;t++){const s=this.lights[t].shadow.camera,i=this.frustums[t],o=i.vertices.near,a=i.vertices.far,c=a[0];let l;c.distanceTo(a[2])>c.distanceTo(o[2])?l=a[2]:l=o[2];let d=c.distanceTo(l);if(this.fade){const u=this.camera,f=Math.max(u.far,this.maxFar),m=i.vertices.far[0].z/(f-u.near),y=.25*Math.pow(m,2)*(f-u.near);d+=y}s.left=-d/2,s.right=d/2,s.top=d/2,s.bottom=-d/2,s.updateProjectionMatrix()}}_getBreaks(){const e=this.camera,t=Math.min(e.far,this.maxFar);switch(this.breaks.length=0,this.mode){case"uniform":n(this.cascades,e.near,t,this.breaks);break;case"logarithmic":s(this.cascades,e.near,t,this.breaks);break;case"practical":i(this.cascades,e.near,t,.5,this.breaks);break;case"custom":this.customSplitsCallback===void 0&&console.error("CSM: Custom split scheme callback not defined."),this.customSplitsCallback(this.cascades,e.near,t,this.breaks);break}function n(o,a,c,l){for(let d=1;d<o;d++)l.push((a+(c-a)*d/o)/c);l.push(1)}function s(o,a,c,l){for(let d=1;d<o;d++)l.push(a*(c/a)**(d/o)/c);l.push(1)}function i(o,a,c,l,d){us.length=0,fs.length=0,s(o,a,c,fs),n(o,a,c,us);for(let u=1;u<o;u++)d.push(h.MathUtils.lerp(us[u-1],fs[u-1],l));d.push(1)}}update(){const e=this.camera,t=this.frustums;ms.lookAt(new h.Vector3,this.lightDirection,va),Ti.copy(ms).invert();for(let n=0;n<t.length;n++){const s=this.lights[n],i=s.shadow.camera,o=(i.right-i.left)/this.shadowMapSize,a=(i.top-i.bottom)/this.shadowMapSize;Li.multiplyMatrices(Ti,e.matrixWorld),t[n].toSpace(Li,hs);const c=hs.vertices.near,l=hs.vertices.far;an.makeEmpty();for(let d=0;d<4;d++)an.expandByPoint(c[d]),an.expandByPoint(l[d]);an.getCenter(Je),Je.z=an.max.z+this.lightMargin,Je.x=Math.floor(Je.x/o)*o,Je.y=Math.floor(Je.y/a)*a,Je.applyMatrix4(ms),s.position.copy(Je),s.target.position.copy(Je),s.target.position.x+=this.lightDirection.x,s.target.position.y+=this.lightDirection.y,s.target.position.z+=this.lightDirection.z}}_injectInclude(){h.ShaderChunk.lights_fragment_begin=Mi.lights_fragment_begin,h.ShaderChunk.lights_pars_begin=Mi.lights_pars_begin}setupMaterial(e){e.defines=e.defines||{},e.defines.USE_CSM=1,e.defines.CSM_CASCADES=this.cascades,this.fade&&(e.defines.CSM_FADE="");const t=[],n=this,s=this.shaders;e.onBeforeCompile=function(i){const o=Math.min(n.camera.far,n.maxFar);n._getExtendedBreaks(t),i.uniforms.CSM_cascades={value:t},i.uniforms.cameraNear={value:n.camera.near},i.uniforms.shadowFar={value:o},s.set(e,i)},s.set(e,null)}_updateUniforms(){const e=Math.min(this.camera.far,this.maxFar);this.shaders.forEach(function(n,s){if(n!==null){const i=n.uniforms;this._getExtendedBreaks(i.CSM_cascades.value),i.cameraNear.value=this.camera.near,i.shadowFar.value=e}!this.fade&&"CSM_FADE"in s.defines?(delete s.defines.CSM_FADE,s.needsUpdate=!0):this.fade&&!("CSM_FADE"in s.defines)&&(s.defines.CSM_FADE="",s.needsUpdate=!0)},this)}_getExtendedBreaks(e){for(;e.length<this.breaks.length;)e.push(new h.Vector2);e.length=this.breaks.length;for(let t=0;t<this.cascades;t++){const n=this.breaks[t],s=this.breaks[t-1]||0;e[t].x=s,e[t].y=n}}updateFrustums(){this._getBreaks(),this._initCascades(),this._updateShadowBounds(),this._updateUniforms()}remove(){for(let e=0;e<this.lights.length;e++)this.parent.remove(this.lights[e].target),this.parent.remove(this.lights[e])}dispose(){const e=this.shaders;e.forEach(function(t,n){delete n.onBeforeCompile,delete n.defines.USE_CSM,delete n.defines.CSM_CASCADES,delete n.defines.CSM_FADE,t!==null&&(delete t.uniforms.CSM_cascades,delete t.uniforms.cameraNear,delete t.uniforms.shadowFar),n.needsUpdate=!0}),e.clear()}}function Di(r){const t=new _.Box3().setFromObject(r).getSize(new _.Vector3);return Math.max(10,Math.max(t.x,t.y,t.z))}const ba=512,wa=100,Sa=30,Aa=-.001,Ma=3,La=16,{PI:Ta,sin:Qe,cos:et,tan:Ci,asin:Oi,atan2:Ii}=Math,Ne=Ta/180,Da=1e3*60*60*24,Ca=2440588,Oa=2451545;function Ia(r){return r.valueOf()/Da-.5+Ca-Oa}function ka(r){const e=2e3+r/365.2425;let t;return e<1920?(t=e-1900,-2.79+t*(1.494119+t*(-.0598939+t*(.0061966-t*197e-6)))):e<1941?(t=e-1920,21.2+t*(.84493+t*(-.0761+t*.0020936))):e<1961?(t=e-1950,29.07+t*(.407+t*(-1/233+t/2547))):e<1986?(t=e-1975,45.45+t*(1.067+t*(-1/260-t/718))):e<2005?(t=e-2e3,63.86+t*(.3345+t*(-.060374+t*(.0017275+t*(651814e-9+t*2373599e-11))))):e<2050?(t=e-2e3,62.92+t*(.32217+t*.005589)):(t=(e-1820)/100,-20+32*t*t-.5628*(2150-e))}function Na(r){return r+ka(r)/86400}function Ea(r,e,t){return(Ii(Qe(r),et(r)*Qe(e)-Ci(t)*et(e))/Ne+540)%360}function Pa(r,e,t){return Oi(Qe(e)*Qe(t)+et(e)*et(t)*et(r))}function Ra(r,e){return Ne*(280.46061837+360.98564736629*r)-e}function za(r){return r<0&&(r=0),2967e-7/Ci(r+.00312536/(r+.08901179))}function Ua(r){const e=r/36525,t=Ne*(280.46646+e*(36000.76983+e*3032e-7)),n=Ne*(357.52911+e*(35999.05029-e*1537e-7)),s=Qe(n),i=et(n),o=Ne*((1.914602-e*(.004817+e*14e-6))*s+(.019993-101e-6*e)*2*s*i+289e-6*s*(3-4*s*s)),a=Ne*(125.04-1934.136*e),c=t+o-Ne*(.00569+.00478*Qe(a)),l=Ne*(23.439291-e*(.0130042+e*(16e-8-e*504e-9)))+Ne*.00256*et(a);return{ra:Ii(et(l)*Qe(c),et(c)),dec:Oi(Qe(l)*Qe(c)),lon:c}}function Fa(r,e,t){const n=Ne*-t,s=Ne*e,i=Ia(r),o=Ua(Na(i)),a=Ra(i,n)-o.ra,c=Pa(a,s,o.dec);return{azimuth:Ea(a,s,o.dec),altitude:(c+za(c))/Ne}}const ps=Math.PI/180;function ja(r,e,t){const n=Fa(t,r,e),s=n.altitude,i=(n.azimuth%360+360)%360,o=s*ps,a=i*ps,c=new _.Vector3(Math.cos(o)*Math.sin(a),Math.sin(o),-Math.cos(o)*Math.cos(a));return{altitude_deg:s,azimuth_deg:i,direction:c}}const Ba=-6;function Va(r,e,t){const n=new _.Color(t);if(r<=Ba)return{intensity:0,color:new _.Color(0)};const s=Math.max(0,r),i=Math.sin(Math.min(s,90)*ps),o=e*(.12+.88*i),a=1-Math.min(s/30,1),l=new _.Color(16747586).lerp(n,1-a*.85);return{intensity:o,color:l}}class ki{constructor(e,t,n,s){g(this,"viewer");g(this,"scene");g(this,"settings");g(this,"sun_settings");g(this,"model_manager");g(this,"sun",null);g(this,"environment");g(this,"csm",null);g(this,"csm_key",null);g(this,"csm_callback",null);g(this,"models_watched",!1);this.viewer=e,this.scene=e.scene,this.settings=t,this.environment=n,this.model_manager=s,this.sun_settings=this.settings.get("environment").sun,this.settings.addEventListener("update",i=>{const o=i.detail;this.sun_settings=o.environment.sun,this.update()}),this.settings.addEventListener("environmentTextureLoaded",i=>{const o=i.detail.texture;if(this.environment.texture=o,this.sun&&this.sun_settings){const a=this._infer_sun_position_from_env_map();a&&(B.debug("Texture loaded event call; inferred Sun position from env map:",a),this.sun_settings.position=[a.x,a.y,a.z],this.update())}}),this.update()}update(){if(!this.sun_settings){this.sun&&(this.scene.remove(this.sun),this.sun=null);return}this.model_manager.ready.then(()=>{if(!this.sun_settings){this.teardown_csm();return}const e=this.apply_solar();if(!e){const n=this._infer_sun_position_from_env_map();n&&(B.debug("Inferred Sun position from env map:",n),this.sun_settings.position=[n.x,n.y,n.z])}const t=e??{position:this.sun_settings.position,intensity:this.sun_settings.intensity,color:this.sun_settings.color};this.sun_settings.csm?(this.remove_classic_sun(),this.sync_csm(t)):(this.teardown_csm(),this.sun_create(e??void 0)),this.sun_settings&&this.sync_sky(t.position)})}sync_sky(e){e&&this.environment.update_sky_environment(new _.Vector3(e[0],e[1],e[2]))}sun_fit_object(e=this.scene){const t=Di(e);let n=new _.Vector3(0,1,0).normalize();n=n.multiplyScalar(t*2),this.sun&&(n=this.sun.position.clone())}sun_fit_shadow(){const e=new _.Object3D;if(!this.model_manager){B.warn("No model manager found.");return}for(const o of this.model_manager.models.values())o.settings.shadow&&e.add(o.group.clone());e.children.length===0&&B.warn("No models with shadows found to fit shadow map."),B.debug("Models in fit_object:",e);const t=Di(e),n=ba,s=Math.ceil(t/wa),i=Math.min(Math.pow(2,Math.ceil(Math.log2(n*s))),this.viewer.renderer.capabilities.maxTextureSize);if(B.debug("Shadow map size:",i),this.sun){this.sun.shadow.mapSize.width=i,this.sun.shadow.mapSize.height=i;const o=Sa;this.sun.shadow.camera.left=-(t/2+o),this.sun.shadow.camera.right=t/2+o,this.sun.shadow.camera.top=t/2+o,this.sun.shadow.camera.bottom=-(t/2+o),this.sun.shadow.camera.near=.1,this.sun.shadow.camera.far=t*2,this.sun.shadow.bias=Aa,this.sun.shadow.radius=Ma,this.sun.shadow.blurSamples=La,B.info(`Recreated sun with shadow map size: ${i}x${i}`)}}resolve_solar(){const e=this.sun_settings.solar,t=ja(e.latitude,e.longitude,new Date(e.datetime)),n=Va(t.altitude_deg,this.sun_settings.intensity,this.sun_settings.color),s=t.direction.multiplyScalar(100);let i=0;return n.intensity>0&&(i=+`0x${n.color.getHexString()}`),B.debug(`Solar sun: lat ${e.latitude}, lon ${e.longitude}, alt ${t.altitude_deg.toFixed(1)}°, az ${t.azimuth_deg.toFixed(1)}°`),{position:[s.x,s.y,s.z],intensity:n.intensity,color:i}}apply_solar(){var e;if((e=this.sun_settings)!=null&&e.solar)try{return this.resolve_solar()}catch(t){B.warn("Failed to resolve solar sun, falling back to configured values:",t);return}}sun_create(e){if(!this.sun_settings)return;this.sun&&(this.scene.remove(this.sun),this.sun.dispose(),this.sun=null);const t=(e==null?void 0:e.color)??this.sun_settings.color,n=(e==null?void 0:e.intensity)??this.sun_settings.intensity;this.sun=new _.DirectionalLight(t,n),this.sun_settings.shadow&&(this.viewer.renderer.shadowMap.enabled=!0,this.sun.castShadow=!0,this.sun_fit_shadow()),this.sun.position.set(...(e==null?void 0:e.position)??this.sun_settings.position),this.scene.add(this.sun)}_infer_sun_position_from_env_map(){if(!this.environment)return B.warn("No environment map available."),null;const e=this.environment.texture,t=e==null?void 0:e.image;if(!t||!t.width||!t.height||!t.data)return B.warn("No environment map texture found."),null;const n=t.width,s=t.height,i=t.data;let o=0;const a=[];for(let m=0;m<i.length;m+=4){const y=i[m],v=i[m+1],b=i[m+2],S=.2126*y+.7152*v+.0722*b;if(S>o){o=S,a.length=0;const A=m/4;a.push({x:A%n,y:Math.floor(A/n)})}else if(S===o){const A=m/4;a.push({x:A%n,y:Math.floor(A/n)})}}let c=0,l=0;a.forEach(m=>{c+=m.x,l+=m.y}),c/=a.length,l/=a.length;let d=c/n*2*Math.PI;d=(d+Math.PI)%(2*Math.PI);const u=l/s*Math.PI,f=new _.Vector3(Math.sin(u)*Math.cos(d),Math.cos(u),Math.sin(u)*Math.sin(d));return f.normalize(),f.multiplyScalar(100)}remove_classic_sun(){var e,t;this.sun&&(this.scene.remove(this.sun),(t=(e=this.sun).dispose)==null||t.call(e),this.sun=null)}sync_csm(e){const t=this.sun_settings.csm,n=JSON.stringify(t),s=new _.Vector3(-e.position[0],-e.position[1],-e.position[2]).normalize();!this.csm||this.csm_key!==n?(this.teardown_csm(),this.viewer.renderer.shadowMap.enabled=!0,this.csm=new xa({camera:this.viewer.camera,parent:this.scene,cascades:t.cascades,maxFar:t.max_far,mode:"practical",shadowMapSize:t.shadow_map_size,shadowBias:t.shadow_bias,lightDirection:s.clone(),lightIntensity:e.intensity}),this.csm.fade=!0,this.csm.lights.forEach(i=>{i.color.set(e.color),i.intensity=e.intensity,i.shadow.normalBias=t.shadow_normal_bias}),this.csm_callback=()=>{var i;(i=this.csm)==null||i.update()},this.viewer.register_animation_callback(this.csm_callback),this.csm_key=n,this.watch_model_loads()):(this.csm.lightDirection.copy(s),this.csm.lightIntensity=e.intensity,this.csm.lights.forEach(i=>{i.color.set(e.color),i.intensity=e.intensity,i.shadow.normalBias=t.shadow_normal_bias})),this.setup_csm_materials()}setup_csm_materials(){!this.csm||!this.csm_key||this.scene.traverse(e=>{const t=e;if(!t.isMesh)return;const n=Array.isArray(t.material)?t.material:[t.material];for(const s of n){if(!s)continue;const i=s;(i.isMeshStandardMaterial||i.isMeshLambertMaterial||i.isMeshPhongMaterial)&&i.userData.csm_setup_key!==this.csm_key&&(this.csm.setupMaterial(i),i.userData.csm_setup_key=this.csm_key,i.needsUpdate=!0)}})}watch_model_loads(){this.models_watched||(this.models_watched=!0,this.model_manager.addEventListener("loaded",()=>{this.setup_csm_materials()}))}teardown_csm(){this.csm_callback&&(this.viewer.unregister_animation_callback(this.csm_callback),this.csm_callback=null),this.csm&&(this.csm.remove(),this.csm.dispose(),this.csm=null),this.csm_key=null}dispose(){this.teardown_csm(),this.remove_classic_sun()}}const ue=[];for(let r=0;r<256;++r)ue.push((r+256).toString(16).slice(1));function Ga(r,e=0){return(ue[r[e+0]]+ue[r[e+1]]+ue[r[e+2]]+ue[r[e+3]]+"-"+ue[r[e+4]]+ue[r[e+5]]+"-"+ue[r[e+6]]+ue[r[e+7]]+"-"+ue[r[e+8]]+ue[r[e+9]]+"-"+ue[r[e+10]]+ue[r[e+11]]+ue[r[e+12]]+ue[r[e+13]]+ue[r[e+14]]+ue[r[e+15]]).toLowerCase()}let _s;const Za=new Uint8Array(16);function Wa(){if(!_s){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");_s=crypto.getRandomValues.bind(crypto)}return _s(Za)}const Ni={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Xa(r,e,t){var s;if(Ni.randomUUID&&!r)return Ni.randomUUID();r=r||{};const n=r.random??((s=r.rng)==null?void 0:s.call(r))??Wa();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Ga(n)}function $a(r,e=1e-4){e=Math.max(e,Number.EPSILON);const t={},n=r.getIndex(),s=r.getAttribute("position"),i=n?n.count:s.count;let o=0;const a=Object.keys(r.attributes),c={},l={},d=[],u=["getX","getY","getZ","getW"],f=["setX","setY","setZ","setW"];for(let A=0,L=a.length;A<L;A++){const x=a[A],z=r.attributes[x];c[x]=new z.constructor(new z.array.constructor(z.count*z.itemSize),z.itemSize,z.normalized);const Z=r.morphAttributes[x];Z&&(l[x]||(l[x]=[]),Z.forEach((j,O)=>{const D=new j.array.constructor(j.count*j.itemSize);l[x][O]=new j.constructor(D,j.itemSize,j.normalized)}))}const m=e*.5,y=Math.log10(1/e),v=Math.pow(10,y),b=m*v;for(let A=0;A<i;A++){const L=n?n.getX(A):A;let x="";for(let z=0,Z=a.length;z<Z;z++){const j=a[z],O=r.getAttribute(j),D=O.itemSize;for(let k=0;k<D;k++)x+=`${~~(O[u[k]](L)*v+b)},`}if(x in t)d.push(t[x]);else{for(let z=0,Z=a.length;z<Z;z++){const j=a[z],O=r.getAttribute(j),D=r.morphAttributes[j],k=O.itemSize,R=c[j],W=l[j];for(let $=0;$<k;$++){const N=u[$],ee=f[$];if(R[ee](o,O[N](L)),D)for(let Y=0,Me=D.length;Y<Me;Y++)W[Y][ee](o,D[Y][N](L))}}t[x]=o,d.push(o),o++}}const S=r.clone();for(const A in r.attributes){const L=c[A];if(S.setAttribute(A,new L.constructor(L.array.slice(0,o*L.itemSize),L.itemSize,L.normalized)),A in l)for(let x=0;x<l[A].length;x++){const z=l[A][x];S.morphAttributes[A][x]=new z.constructor(z.array.slice(0,o*z.itemSize),z.itemSize,z.normalized)}}return S.setIndex(d),S}function Ei(r,e){if(e===h.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),r;if(e===h.TriangleFanDrawMode||e===h.TriangleStripDrawMode){let t=r.getIndex();if(t===null){const o=[],a=r.getAttribute("position");if(a!==void 0){for(let c=0;c<a.count;c++)o.push(c);r.setIndex(o),t=r.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),r}const n=t.count-2,s=[];if(e===h.TriangleFanDrawMode)for(let o=1;o<=n;o++)s.push(t.getX(0)),s.push(t.getX(o)),s.push(t.getX(o+1));else for(let o=0;o<n;o++)o%2===0?(s.push(t.getX(o)),s.push(t.getX(o+1)),s.push(t.getX(o+2))):(s.push(t.getX(o+2)),s.push(t.getX(o+1)),s.push(t.getX(o)));s.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=r.clone();return i.setIndex(s),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),r}const Pi=new h.Box3,Rn=new h.Vector3;class gs extends h.InstancedBufferGeometry{constructor(){super(),this.isLineSegmentsGeometry=!0,this.type="LineSegmentsGeometry";const e=[-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0],t=[-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2],n=[0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5];this.setIndex(n),this.setAttribute("position",new h.Float32BufferAttribute(e,3)),this.setAttribute("uv",new h.Float32BufferAttribute(t,2))}applyMatrix4(e){const t=this.attributes.instanceStart,n=this.attributes.instanceEnd;return t!==void 0&&(t.applyMatrix4(e),n.applyMatrix4(e),t.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}setPositions(e){let t;e instanceof Float32Array?t=e:Array.isArray(e)&&(t=new Float32Array(e));const n=new h.InstancedInterleavedBuffer(t,6,1);return this.setAttribute("instanceStart",new h.InterleavedBufferAttribute(n,3,0)),this.setAttribute("instanceEnd",new h.InterleavedBufferAttribute(n,3,3)),this.instanceCount=this.attributes.instanceStart.count,this.computeBoundingBox(),this.computeBoundingSphere(),this}setColors(e){let t;e instanceof Float32Array?t=e:Array.isArray(e)&&(t=new Float32Array(e));const n=new h.InstancedInterleavedBuffer(t,6,1);return this.setAttribute("instanceColorStart",new h.InterleavedBufferAttribute(n,3,0)),this.setAttribute("instanceColorEnd",new h.InterleavedBufferAttribute(n,3,3)),this}fromWireframeGeometry(e){return this.setPositions(e.attributes.position.array),this}fromEdgesGeometry(e){return this.setPositions(e.attributes.position.array),this}fromMesh(e){return this.fromWireframeGeometry(new h.WireframeGeometry(e.geometry)),this}fromLineSegments(e){const t=e.geometry;return this.setPositions(t.attributes.position.array),this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new h.Box3);const e=this.attributes.instanceStart,t=this.attributes.instanceEnd;e!==void 0&&t!==void 0&&(this.boundingBox.setFromBufferAttribute(e),Pi.setFromBufferAttribute(t),this.boundingBox.union(Pi))}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new h.Sphere),this.boundingBox===null&&this.computeBoundingBox();const e=this.attributes.instanceStart,t=this.attributes.instanceEnd;if(e!==void 0&&t!==void 0){const n=this.boundingSphere.center;this.boundingBox.getCenter(n);let s=0;for(let i=0,o=e.count;i<o;i++)Rn.fromBufferAttribute(e,i),s=Math.max(s,n.distanceToSquared(Rn)),Rn.fromBufferAttribute(t,i),s=Math.max(s,n.distanceToSquared(Rn));this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&console.error("THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.",this)}}toJSON(){}}h.UniformsLib.line={worldUnits:{value:1},linewidth:{value:1},resolution:{value:new h.Vector2(1,1)},dashOffset:{value:0},dashScale:{value:1},dashSize:{value:1},gapSize:{value:1}},h.ShaderLib.line={uniforms:h.UniformsUtils.merge([h.UniformsLib.common,h.UniformsLib.fog,h.UniformsLib.line]),vertexShader:`
447
447
  #include <common>
448
448
  #include <color_pars_vertex>
449
449
  #include <fog_pars_vertex>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maucwerk/glimmer",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "A lightweight, interactive 3D model viewer for web applications built with Three.js",
5
5
  "main": "dist/vite/glimmer.umd.js",
6
6
  "module": "dist/vite/glimmer.mjs",