gralobe 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gralobe.js +57 -7
- package/dist/gralobe.js.map +1 -1
- package/dist/gralobe.umd.cjs +44 -1
- package/dist/gralobe.umd.cjs.map +1 -1
- package/package.json +1 -1
package/dist/gralobe.umd.cjs
CHANGED
|
@@ -939,6 +939,49 @@ float fbm(vec2 p) {
|
|
|
939
939
|
return value;
|
|
940
940
|
}
|
|
941
941
|
|
|
942
|
+
// 3D hash for volumetric noise
|
|
943
|
+
float hash3(vec3 p) {
|
|
944
|
+
return fract(sin(dot(p, vec3(127.1, 311.7, 74.7))) * 43758.5453);
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// 3D noise for seamless spherical sampling
|
|
948
|
+
float noise3D(vec3 p) {
|
|
949
|
+
vec3 i = floor(p);
|
|
950
|
+
vec3 f = fract(p);
|
|
951
|
+
f = f * f * (3.0 - 2.0 * f);
|
|
952
|
+
|
|
953
|
+
float n000 = hash3(i);
|
|
954
|
+
float n100 = hash3(i + vec3(1.0, 0.0, 0.0));
|
|
955
|
+
float n010 = hash3(i + vec3(0.0, 1.0, 0.0));
|
|
956
|
+
float n110 = hash3(i + vec3(1.0, 1.0, 0.0));
|
|
957
|
+
float n001 = hash3(i + vec3(0.0, 0.0, 1.0));
|
|
958
|
+
float n101 = hash3(i + vec3(1.0, 0.0, 1.0));
|
|
959
|
+
float n011 = hash3(i + vec3(0.0, 1.0, 1.0));
|
|
960
|
+
float n111 = hash3(i + vec3(1.0, 1.0, 1.0));
|
|
961
|
+
|
|
962
|
+
float nx00 = mix(n000, n100, f.x);
|
|
963
|
+
float nx10 = mix(n010, n110, f.x);
|
|
964
|
+
float nx01 = mix(n001, n101, f.x);
|
|
965
|
+
float nx11 = mix(n011, n111, f.x);
|
|
966
|
+
|
|
967
|
+
float nxy0 = mix(nx00, nx10, f.y);
|
|
968
|
+
float nxy1 = mix(nx01, nx11, f.y);
|
|
969
|
+
|
|
970
|
+
return mix(nxy0, nxy1, f.z);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
// FBM using 3D noise for seamless spherical clouds
|
|
974
|
+
float fbm3D(vec3 p) {
|
|
975
|
+
float value = 0.0;
|
|
976
|
+
float amplitude = 0.5;
|
|
977
|
+
for (int i = 0; i < 4; i++) {
|
|
978
|
+
value += amplitude * noise3D(p);
|
|
979
|
+
p *= 2.0;
|
|
980
|
+
amplitude *= 0.5;
|
|
981
|
+
}
|
|
982
|
+
return value;
|
|
983
|
+
}
|
|
984
|
+
|
|
942
985
|
void main() {
|
|
943
986
|
if (vDiscard > 0.5) {
|
|
944
987
|
discard;
|
|
@@ -1112,5 +1155,5 @@ void main() {
|
|
|
1112
1155
|
|
|
1113
1156
|
gl_FragColor = vec4(1.0, 1.0, 1.0, alpha * vOpacity * 0.9);
|
|
1114
1157
|
}
|
|
1115
|
-
`,Tr={satellite:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_atmos_2048.jpg",natural:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_day_4096.jpg",dark:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_lights_2048.png",light:"https://raw.githubusercontent.com/turban/webgl-earth/master/images/2_no_clouds_4k.jpg",night:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_lights_2048.png",topographic:"https://eoimages.gsfc.nasa.gov/images/imagerecords/74000/74117/world.topo.200407.3x5400x2700.jpg"},Dr={texture:"satellite",labels:"all",statistic:"lifeExpectancy",autoRotate:!1,initialView:"globe",showControls:!1,showLegend:!0,effects:{atmosphereIntensity:0,atmosphere:!1,clouds:!1,starTwinkle:!0},extrudeHeight:!1};class ao{container;config;scene;camera;renderer;controls;globe=null;material=null;atmosphere=null;stars=null;gui=null;choropleth=null;legend=null;exporter=null;countryLabels=null;textureLoader=new D.TextureLoader;dataTexture=null;morph=0;currentStatistic=null;animationId=null;isDestroyed=!1;ready;resolveReady;constructor(e,t={}){if(typeof e=="string"){const i=document.querySelector(e);if(!i)throw new Error(`Container not found: ${e}`);this.container=i}else this.container=e;this.config={...Dr,...t,effects:{...Dr.effects,...t.effects}},this.ready=new Promise(i=>{this.resolveReady=i}),this.init()}async init(){const e=this.config.width||this.container.clientWidth||800,t=this.config.height||this.container.clientHeight||600;this.scene=new D.Scene,this.scene.background=new D.Color(2066),this.camera=new D.PerspectiveCamera(50,e/t,1,1e3),this.camera.position.set(0,0,this.config.initialView==="flat"?350:150),this.renderer=new D.WebGLRenderer({antialias:!0}),this.renderer.setSize(e,t),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.container.appendChild(this.renderer.domElement),this.controls=new Ir(this.camera,this.renderer.domElement),this.controls.enableDamping=!0,this.controls.minDistance=80,this.controls.maxDistance=400,this.choropleth=new Ca,this.config.showLegend&&(this.legend=new Sa(this.container)),await this.createGlobe(),this.createStars(),this.config.effects.atmosphere&&this.createAtmosphere(),this.countryLabels=new Ja(this.container,Ze),this.scene.add(this.countryLabels.getGroup()),this.globe&&this.countryLabels.setGlobe(this.globe),this.countryLabels.setCamera(this.camera),this.countryLabels.setStyle(this.config.labels),this.exporter=new ja(this.renderer,this.scene,this.camera),this.config.showControls&&this.createGUI(),await this.choropleth.waitForLoad(),this.setStatistic(this.config.statistic),this.morph=this.config.initialView==="globe"?1:0,this.material&&(this.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph),window.addEventListener("resize",this.handleResize),document.addEventListener("fullscreenchange",this.handleFullscreenChange),window.addEventListener("keydown",this.handleKeydown),this.animate(),this.resolveReady()}async createGlobe(){const e=await this.textureLoader.loadAsync(Tr[this.config.texture]);e.anisotropy=this.renderer.capabilities.getMaxAnisotropy(),e.minFilter=D.LinearMipmapLinearFilter,e.magFilter=D.LinearFilter;const t=document.createElement("canvas");t.width=2048,t.height=1024,this.dataTexture=new D.CanvasTexture(t);const i=new D.PlaneGeometry(Math.PI*2*Ze,Math.PI*Ze,256,128);this.material=new D.ShaderMaterial({vertexShader:eo,fragmentShader:to,uniforms:{uMorph:{value:0},uTime:{value:0},uParchment:{value:0},uExtremeParchment:{value:0},uTransitionEffect:{value:0},uTexture:{value:e},uDataTexture:{value:this.dataTexture},uCloudTexture:{value:null},uNightTexture:{value:null},uDataOpacity:{value:0},uDataOverlay:{value:0},uExtrudeHeight:{value:this.config.extrudeHeight?1:0},uSunDir:{value:new D.Vector3(1,.5,1).normalize()},uClouds:{value:this.config.effects.clouds?1:0},uCloudSpeed:{value:this.config.effects.cloudSpeed||1},uCloudOpacity:{value:this.config.effects.cloudOpacity||.6},uAtmosphereIntensity:{value:this.config.effects.atmosphereIntensity||0},uAurora:{value:this.config.effects.aurora?1:0},uAuroraIntensity:{value:1},uCityLights:{value:this.config.effects.cityLights?1:0},uCityLightsIntensity:{value:1},uOceanSpecular:{value:this.config.effects.oceanSpecular?1:0},uSpecularIntensity:{value:1},uSunGlow:{value:0},uGridLines:{value:this.config.effects.gridLines?1:0},uGridOpacity:{value:this.config.effects.gridOpacity||.5},uScanEffect:{value:0},uScanSpeed:{value:1},uHologram:{value:this.config.effects.hologramMode?1:0},uHologramColor:{value:new D.Color(65535)},uVintage:{value:this.config.effects.vintageMode?1:0},uThermal:{value:this.config.effects.thermalMode?1:0},uBlueprint:{value:this.config.effects.blueprintMode?1:0},uGlowPulse:{value:this.config.effects.glowPulse?1:0},uGlowColor:{value:new D.Color(4491519)}},side:D.DoubleSide}),this.globe=new D.Mesh(i,this.material),this.scene.add(this.globe)}createAtmosphere(){const e=new D.PlaneGeometry(Math.PI*2*Ze*1.15,Math.PI*Ze*1.15,128,64),t=new D.ShaderMaterial({vertexShader:io,fragmentShader:no,uniforms:{uMorph:{value:0}},side:D.BackSide,transparent:!0,blending:D.AdditiveBlending,depthWrite:!1});this.atmosphere=new D.Mesh(e,t),this.scene.add(this.atmosphere)}createStars(){const t=new D.BufferGeometry,i=new Float32Array(3e3*3),n=new Float32Array(3e3),r=new Float32Array(3e3);for(let o=0;o<3e3;o++){const l=300+Math.random()*300,c=Math.random()*Math.PI*2,h=Math.acos(2*Math.random()-1);i[o*3]=l*Math.sin(h)*Math.cos(c),i[o*3+1]=l*Math.sin(h)*Math.sin(c),i[o*3+2]=l*Math.cos(h),n[o]=.5+Math.random()*1.5,r[o]=Math.random()*Math.PI*2}t.setAttribute("position",new D.BufferAttribute(i,3)),t.setAttribute("aSize",new D.BufferAttribute(n,1)),t.setAttribute("aPhase",new D.BufferAttribute(r,1));const s=new D.ShaderMaterial({vertexShader:ro,fragmentShader:so,uniforms:{uTime:{value:0},uTwinkle:{value:this.config.effects.starTwinkle?1:0}},transparent:!0,blending:D.AdditiveBlending,depthWrite:!1});this.stars=new D.Points(t,s),this.scene.add(this.stars)}createGUI(){this.gui=new Ni({title:"Globe Controls",width:300});const e=this.gui.addFolder("View");e.add({toGlobe:()=>this.toGlobe()},"toGlobe").name("→ Globe"),e.add({toFlat:()=>this.toFlat()},"toFlat").name("→ Flat Map"),e.add({morph:this.morph},"morph",0,1).name("Morph").onChange(r=>this.setMorph(r)),e.open();const t=this.gui.addFolder("Statistics"),i=Object.keys(Zt);t.add({stat:this.config.statistic},"stat",i).name("Statistic").onChange(r=>this.setStatistic(r)),t.open();const n=["none","minimal","major","all"];this.gui.add({labels:this.config.labels},"labels",n).name("Labels").onChange(r=>this.setLabels(r)),this.gui.add(this.config,"autoRotate").name("Auto Rotate")}handleResize=()=>{if(this.isDestroyed)return;const e=this.config.width||this.container.clientWidth,t=this.config.height||this.container.clientHeight;this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.renderer.setSize(e,t),this.countryLabels?.resize(e,t)};handleFullscreenChange=()=>{this.isDestroyed||setTimeout(()=>this.handleResize(),50)};handleKeydown=e=>{this.isDestroyed||((e.key==="g"||e.key==="G")&&(this.morph>.5?this.toFlat():this.toGlobe()),(e.key==="f"||e.key==="F")&&this.toggleFullscreen())};animate=()=>{if(this.isDestroyed)return;this.animationId=requestAnimationFrame(this.animate);const e=performance.now()*.001;this.material&&(this.material.uniforms.uTime.value=e),this.stars&&(this.stars.material.uniforms.uTime.value=e),this.controls.update(),this.config.autoRotate&&this.globe&&(this.globe.rotation.y+=.002*this.morph),this.countryLabels?.update(),this.renderer.render(this.scene,this.camera),this.countryLabels?.render(this.scene,this.camera)};toGlobe(){wt.to(this,{morph:1,duration:2.5,ease:"power2.inOut",onUpdate:()=>{this.material&&(this.material.uniforms.uMorph.value=this.morph),this.atmosphere&&(this.atmosphere.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph),this.config.onViewChange?.("globe",this.morph)}}),wt.to(this.camera.position,{z:150,duration:2.5,ease:"power2.inOut"})}toFlat(){wt.to(this,{morph:0,duration:2.5,ease:"power2.inOut",onUpdate:()=>{this.material&&(this.material.uniforms.uMorph.value=this.morph),this.atmosphere&&(this.atmosphere.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph),this.config.onViewChange?.("flat",this.morph)}}),wt.to(this.camera.position,{z:350,duration:2.5,ease:"power2.inOut"})}setMorph(e){this.morph=Math.max(0,Math.min(1,e)),this.material&&(this.material.uniforms.uMorph.value=this.morph),this.atmosphere&&(this.atmosphere.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph)}getMorph(){return this.morph}setStatistic(e){if(typeof e=="string"){if(!Zt[e]){console.warn(`Unknown statistic: ${e}`);return}this.currentStatistic=e;const i=va.find(n=>n.id===e);if(i&&this.choropleth){const n=this.choropleth.renderTexture(i);if(this.material&&n){const r=new D.CanvasTexture(n);r.needsUpdate=!0,this.material.uniforms.uDataTexture.value=r,this.material.uniforms.uDataOverlay.value=1,this.material.uniforms.uDataOpacity.value=.7}}this.legend&&i&&this.legend.show(i)}else{const t=e;if(this.currentStatistic=t.definition.id,this.choropleth){const i=this.choropleth.renderCustomTexture(t.values,t.definition.colorScale,t.definition.domain);if(this.material&&i){const n=new D.CanvasTexture(i);n.needsUpdate=!0,this.material.uniforms.uDataTexture.value=n,this.material.uniforms.uDataOverlay.value=1,this.material.uniforms.uDataOpacity.value=.7}}this.legend&&this.legend.show(t.definition)}}setLabels(e){this.countryLabels?.setStyle(e)}async setTexture(e){const t=Tr[e];if(!(!t||!this.material))try{const i=await this.textureLoader.loadAsync(t);i.anisotropy=this.renderer.capabilities.getMaxAnisotropy(),i.minFilter=D.LinearMipmapLinearFilter,i.magFilter=D.LinearFilter,this.material.uniforms.uTexture.value=i}catch(i){console.error("Failed to load texture:",e,i)}}setAutoRotate(e){this.config.autoRotate=e}screenshot(e){this.exporter?.screenshot(e)}async recordGif(e){if(!this.exporter)return;const t=e?.duration||5,i=e?.fps||20,n=t*i;this.exporter.startGifCapture(e);for(let r=0;r<n;r++)this.exporter.captureGifFrame(),await new Promise(s=>setTimeout(s,1e3/i));await this.exporter.stopGifCapture(e)}async recordVideo(e){if(!this.exporter)return;const t=e?.duration||5;await this.exporter.startVideoRecording(e),await new Promise(i=>setTimeout(i,t*1e3)),this.exporter.stopVideoRecording()}setEffects(e){Object.assign(this.config.effects,e),this.material&&(e.atmosphere!==void 0&&(e.atmosphere&&!this.atmosphere?this.createAtmosphere():!e.atmosphere&&this.atmosphere&&(this.scene.remove(this.atmosphere),this.atmosphere.geometry.dispose(),this.atmosphere.material.dispose(),this.atmosphere=null)),e.clouds!==void 0&&(this.material.uniforms.uClouds.value=e.clouds?1:0),e.cloudSpeed!==void 0&&(this.material.uniforms.uCloudSpeed.value=e.cloudSpeed),e.cloudOpacity!==void 0&&(this.material.uniforms.uCloudOpacity.value=e.cloudOpacity),e.atmosphereIntensity!==void 0&&(this.material.uniforms.uAtmosphereIntensity.value=e.atmosphereIntensity),e.gridLines!==void 0&&(this.material.uniforms.uGridLines.value=e.gridLines?1:0),e.gridOpacity!==void 0&&(this.material.uniforms.uGridOpacity.value=e.gridOpacity),e.glowPulse!==void 0&&(this.material.uniforms.uGlowPulse.value=e.glowPulse?1:0),e.starTwinkle!==void 0&&this.stars&&(this.stars.material.uniforms.uTwinkle.value=e.starTwinkle?1:0))}resize(e,t){this.config.width=e,this.config.height=t,this.handleResize()}async toggleFullscreen(){document.fullscreenElement?(await document.exitFullscreen(),setTimeout(()=>this.handleResize(),100)):(await this.container.requestFullscreen(),setTimeout(()=>this.handleResize(),100))}isFullscreen(){return document.fullscreenElement===this.container}destroy(){this.isDestroyed=!0,this.animationId&&cancelAnimationFrame(this.animationId),window.removeEventListener("resize",this.handleResize),window.removeEventListener("keydown",this.handleKeydown),document.removeEventListener("fullscreenchange",this.handleFullscreenChange),this.gui?.destroy(),this.legend?.dispose(),this.countryLabels?.dispose(),this.globe?.geometry.dispose(),this.globe?.material?.dispose(),this.atmosphere?.geometry.dispose(),this.atmosphere?.material?.dispose(),this.stars?.geometry.dispose(),this.stars?.material?.dispose(),this.renderer.dispose(),this.container.removeChild(this.renderer.domElement)}}ae.BUILT_IN_STATISTICS=Zt,ae.GlobeViz=ao,ae.WORLD_STATISTICS=$i,ae.createFormatter=Vi,ae.formatValue=Pa,ae.normalizeCountryValues=fr,ae.toNumericCode=Bi,Object.defineProperty(ae,Symbol.toStringTag,{value:"Module"})}));
|
|
1158
|
+
`,Tr={satellite:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_atmos_2048.jpg",natural:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_day_4096.jpg",dark:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_lights_2048.png",light:"https://raw.githubusercontent.com/turban/webgl-earth/master/images/2_no_clouds_4k.jpg",night:"https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/planets/earth_lights_2048.png",topographic:"https://eoimages.gsfc.nasa.gov/images/imagerecords/74000/74117/world.topo.200407.3x5400x2700.jpg"},Dr={texture:"satellite",labels:"all",statistic:"lifeExpectancy",autoRotate:!1,initialView:"globe",showControls:!1,showLegend:!0,effects:{atmosphereIntensity:0,atmosphere:!1,clouds:!1,starTwinkle:!0},extrudeHeight:!1};class ao{container;config;scene;camera;renderer;controls;globe=null;material=null;atmosphere=null;stars=null;gui=null;choropleth=null;legend=null;exporter=null;countryLabels=null;textureLoader=new D.TextureLoader;dataTexture=null;morph=0;currentStatistic=null;animationId=null;isDestroyed=!1;ready;resolveReady;constructor(e,t={}){if(typeof e=="string"){const i=document.querySelector(e);if(!i)throw new Error(`Container not found: ${e}`);this.container=i}else this.container=e;this.config={...Dr,...t,effects:{...Dr.effects,...t.effects}},this.ready=new Promise(i=>{this.resolveReady=i}),this.init()}async init(){const e=this.config.width||this.container.clientWidth||800,t=this.config.height||this.container.clientHeight||600;this.scene=new D.Scene,this.scene.background=new D.Color(2066),this.camera=new D.PerspectiveCamera(50,e/t,1,1e3),this.camera.position.set(0,0,this.config.initialView==="flat"?350:150),this.renderer=new D.WebGLRenderer({antialias:!0}),this.renderer.setSize(e,t),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.container.appendChild(this.renderer.domElement),this.controls=new Ir(this.camera,this.renderer.domElement),this.controls.enableDamping=!0,this.controls.minDistance=80,this.controls.maxDistance=400,this.choropleth=new Ca,this.config.showLegend&&(this.legend=new Sa(this.container)),await this.createGlobe(),this.createStars(),this.config.effects.atmosphere&&this.createAtmosphere(),this.countryLabels=new Ja(this.container,Ze),this.scene.add(this.countryLabels.getGroup()),this.globe&&this.countryLabels.setGlobe(this.globe),this.countryLabels.setCamera(this.camera),this.countryLabels.setStyle(this.config.labels),this.exporter=new ja(this.renderer,this.scene,this.camera),this.config.showControls&&this.createGUI(),await this.choropleth.waitForLoad(),this.setStatistic(this.config.statistic),this.morph=this.config.initialView==="globe"?1:0,this.material&&(this.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph),window.addEventListener("resize",this.handleResize),document.addEventListener("fullscreenchange",this.handleFullscreenChange),window.addEventListener("keydown",this.handleKeydown),this.animate(),this.resolveReady()}async createGlobe(){const e=await this.textureLoader.loadAsync(Tr[this.config.texture]);e.anisotropy=this.renderer.capabilities.getMaxAnisotropy(),e.minFilter=D.LinearMipmapLinearFilter,e.magFilter=D.LinearFilter;const t=document.createElement("canvas");t.width=2048,t.height=1024,this.dataTexture=new D.CanvasTexture(t);const i=new D.PlaneGeometry(Math.PI*2*Ze,Math.PI*Ze,256,128);this.material=new D.ShaderMaterial({vertexShader:eo,fragmentShader:to,uniforms:{uMorph:{value:0},uTime:{value:0},uParchment:{value:0},uExtremeParchment:{value:0},uTransitionEffect:{value:0},uTexture:{value:e},uDataTexture:{value:this.dataTexture},uCloudTexture:{value:null},uNightTexture:{value:null},uDataOpacity:{value:0},uDataOverlay:{value:0},uExtrudeHeight:{value:this.config.extrudeHeight?1:0},uSunDir:{value:new D.Vector3(1,.5,1).normalize()},uClouds:{value:this.config.effects.clouds?1:0},uCloudSpeed:{value:this.config.effects.cloudSpeed||1},uCloudOpacity:{value:this.config.effects.cloudOpacity||.6},uAtmosphereIntensity:{value:this.config.effects.atmosphereIntensity||0},uAurora:{value:this.config.effects.aurora?1:0},uAuroraIntensity:{value:1},uCityLights:{value:this.config.effects.cityLights?1:0},uCityLightsIntensity:{value:1},uOceanSpecular:{value:this.config.effects.oceanSpecular?1:0},uSpecularIntensity:{value:1},uSunGlow:{value:0},uGridLines:{value:this.config.effects.gridLines?1:0},uGridOpacity:{value:this.config.effects.gridOpacity||.5},uScanEffect:{value:0},uScanSpeed:{value:1},uHologram:{value:this.config.effects.hologramMode?1:0},uHologramColor:{value:new D.Color(65535)},uVintage:{value:this.config.effects.vintageMode?1:0},uThermal:{value:this.config.effects.thermalMode?1:0},uBlueprint:{value:this.config.effects.blueprintMode?1:0},uGlowPulse:{value:this.config.effects.glowPulse?1:0},uGlowColor:{value:new D.Color(4491519)}},side:D.DoubleSide}),this.globe=new D.Mesh(i,this.material),this.scene.add(this.globe)}createAtmosphere(){const e=new D.PlaneGeometry(Math.PI*2*Ze*1.15,Math.PI*Ze*1.15,128,64),t=new D.ShaderMaterial({vertexShader:io,fragmentShader:no,uniforms:{uMorph:{value:0}},side:D.BackSide,transparent:!0,blending:D.AdditiveBlending,depthWrite:!1});this.atmosphere=new D.Mesh(e,t),this.scene.add(this.atmosphere)}createStars(){const t=new D.BufferGeometry,i=new Float32Array(3e3*3),n=new Float32Array(3e3),r=new Float32Array(3e3);for(let o=0;o<3e3;o++){const l=300+Math.random()*300,c=Math.random()*Math.PI*2,h=Math.acos(2*Math.random()-1);i[o*3]=l*Math.sin(h)*Math.cos(c),i[o*3+1]=l*Math.sin(h)*Math.sin(c),i[o*3+2]=l*Math.cos(h),n[o]=.5+Math.random()*1.5,r[o]=Math.random()*Math.PI*2}t.setAttribute("position",new D.BufferAttribute(i,3)),t.setAttribute("aSize",new D.BufferAttribute(n,1)),t.setAttribute("aPhase",new D.BufferAttribute(r,1));const s=new D.ShaderMaterial({vertexShader:ro,fragmentShader:so,uniforms:{uTime:{value:0},uTwinkle:{value:this.config.effects.starTwinkle?1:0}},transparent:!0,blending:D.AdditiveBlending,depthWrite:!1});this.stars=new D.Points(t,s),this.scene.add(this.stars)}createGUI(){getComputedStyle(this.container).position==="static"&&(this.container.style.position="relative"),this.gui=new Ni({container:this.container,title:"⚙ Controls",width:220,closeFolders:!0});const t=this.gui.domElement;t.style.position="absolute",t.style.top="8px",t.style.right="8px",t.style.zIndex="100",this.gui.close();const i=this.gui.addFolder("View");i.add({toGlobe:()=>this.toGlobe()},"toGlobe").name("→ Globe"),i.add({toFlat:()=>this.toFlat()},"toFlat").name("→ Flat"),i.add({morph:this.morph},"morph",0,1).name("Morph").onChange(o=>this.setMorph(o));const n=this.gui.addFolder("Statistics"),r=Object.keys(Zt);n.add({stat:this.config.statistic},"stat",r).name("Statistic").onChange(o=>this.setStatistic(o));const s=["none","minimal","major","all"];this.gui.addFolder("Display").add({labels:this.config.labels},"labels",s).name("Labels").onChange(o=>this.setLabels(o)),this.gui.add(this.config,"autoRotate").name("Auto Rotate")}handleResize=()=>{if(this.isDestroyed)return;const e=this.config.width||this.container.clientWidth,t=this.config.height||this.container.clientHeight;this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.renderer.setSize(e,t),this.countryLabels?.resize(e,t)};handleFullscreenChange=()=>{this.isDestroyed||setTimeout(()=>this.handleResize(),50)};handleKeydown=e=>{this.isDestroyed||((e.key==="g"||e.key==="G")&&(this.morph>.5?this.toFlat():this.toGlobe()),(e.key==="f"||e.key==="F")&&this.toggleFullscreen())};animate=()=>{if(this.isDestroyed)return;this.animationId=requestAnimationFrame(this.animate);const e=performance.now()*.001;this.material&&(this.material.uniforms.uTime.value=e),this.stars&&(this.stars.material.uniforms.uTime.value=e),this.controls.update(),this.config.autoRotate&&this.globe&&(this.globe.rotation.y+=.002*this.morph),this.countryLabels?.update(),this.renderer.render(this.scene,this.camera),this.countryLabels?.render(this.scene,this.camera)};toGlobe(){wt.to(this,{morph:1,duration:2.5,ease:"power2.inOut",onUpdate:()=>{this.material&&(this.material.uniforms.uMorph.value=this.morph),this.atmosphere&&(this.atmosphere.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph),this.config.onViewChange?.("globe",this.morph)}}),wt.to(this.camera.position,{z:150,duration:2.5,ease:"power2.inOut"})}toFlat(){wt.to(this,{morph:0,duration:2.5,ease:"power2.inOut",onUpdate:()=>{this.material&&(this.material.uniforms.uMorph.value=this.morph),this.atmosphere&&(this.atmosphere.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph),this.config.onViewChange?.("flat",this.morph)}}),wt.to(this.camera.position,{z:350,duration:2.5,ease:"power2.inOut"})}setMorph(e){this.morph=Math.max(0,Math.min(1,e)),this.material&&(this.material.uniforms.uMorph.value=this.morph),this.atmosphere&&(this.atmosphere.material.uniforms.uMorph.value=this.morph),this.countryLabels?.setMorph(this.morph)}getMorph(){return this.morph}setStatistic(e){if(typeof e=="string"){if(!Zt[e]){console.warn(`Unknown statistic: ${e}`);return}this.currentStatistic=e;const i=va.find(n=>n.id===e);if(i&&this.choropleth){const n=this.choropleth.renderTexture(i);if(this.material&&n){const r=new D.CanvasTexture(n);r.needsUpdate=!0,this.material.uniforms.uDataTexture.value=r,this.material.uniforms.uDataOverlay.value=1,this.material.uniforms.uDataOpacity.value=.7}}this.legend&&i&&this.legend.show(i)}else{const t=e;if(this.currentStatistic=t.definition.id,this.choropleth){const i=this.choropleth.renderCustomTexture(t.values,t.definition.colorScale,t.definition.domain);if(this.material&&i){const n=new D.CanvasTexture(i);n.needsUpdate=!0,this.material.uniforms.uDataTexture.value=n,this.material.uniforms.uDataOverlay.value=1,this.material.uniforms.uDataOpacity.value=.7}}this.legend&&this.legend.show(t.definition)}}setLabels(e){this.countryLabels?.setStyle(e)}async setTexture(e){const t=Tr[e];if(!(!t||!this.material))try{const i=await this.textureLoader.loadAsync(t);i.anisotropy=this.renderer.capabilities.getMaxAnisotropy(),i.minFilter=D.LinearMipmapLinearFilter,i.magFilter=D.LinearFilter,this.material.uniforms.uTexture.value=i}catch(i){console.error("Failed to load texture:",e,i)}}setAutoRotate(e){this.config.autoRotate=e}screenshot(e){this.exporter?.screenshot(e)}async recordGif(e){if(!this.exporter)return;const t=e?.duration||5,i=e?.fps||20,n=t*i;this.exporter.startGifCapture(e);for(let r=0;r<n;r++)this.exporter.captureGifFrame(),await new Promise(s=>setTimeout(s,1e3/i));await this.exporter.stopGifCapture(e)}async recordVideo(e){if(!this.exporter)return;const t=e?.duration||5;await this.exporter.startVideoRecording(e),await new Promise(i=>setTimeout(i,t*1e3)),this.exporter.stopVideoRecording()}setEffects(e){Object.assign(this.config.effects,e),this.material&&(e.atmosphere!==void 0&&(e.atmosphere&&!this.atmosphere?this.createAtmosphere():!e.atmosphere&&this.atmosphere&&(this.scene.remove(this.atmosphere),this.atmosphere.geometry.dispose(),this.atmosphere.material.dispose(),this.atmosphere=null)),e.clouds!==void 0&&(this.material.uniforms.uClouds.value=e.clouds?1:0),e.cloudSpeed!==void 0&&(this.material.uniforms.uCloudSpeed.value=e.cloudSpeed),e.cloudOpacity!==void 0&&(this.material.uniforms.uCloudOpacity.value=e.cloudOpacity),e.atmosphereIntensity!==void 0&&(this.material.uniforms.uAtmosphereIntensity.value=e.atmosphereIntensity),e.gridLines!==void 0&&(this.material.uniforms.uGridLines.value=e.gridLines?1:0),e.gridOpacity!==void 0&&(this.material.uniforms.uGridOpacity.value=e.gridOpacity),e.glowPulse!==void 0&&(this.material.uniforms.uGlowPulse.value=e.glowPulse?1:0),e.starTwinkle!==void 0&&this.stars&&(this.stars.material.uniforms.uTwinkle.value=e.starTwinkle?1:0))}resize(e,t){this.config.width=e,this.config.height=t,this.handleResize()}async toggleFullscreen(){document.fullscreenElement?(await document.exitFullscreen(),setTimeout(()=>this.handleResize(),100)):(await this.container.requestFullscreen(),setTimeout(()=>this.handleResize(),100))}isFullscreen(){return document.fullscreenElement===this.container}destroy(){this.isDestroyed=!0,this.animationId&&cancelAnimationFrame(this.animationId),window.removeEventListener("resize",this.handleResize),window.removeEventListener("keydown",this.handleKeydown),document.removeEventListener("fullscreenchange",this.handleFullscreenChange),this.gui?.destroy(),this.legend?.dispose(),this.countryLabels?.dispose(),this.globe?.geometry.dispose(),this.globe?.material?.dispose(),this.atmosphere?.geometry.dispose(),this.atmosphere?.material?.dispose(),this.stars?.geometry.dispose(),this.stars?.material?.dispose(),this.renderer.dispose(),this.container.removeChild(this.renderer.domElement)}}ae.BUILT_IN_STATISTICS=Zt,ae.GlobeViz=ao,ae.WORLD_STATISTICS=$i,ae.createFormatter=Vi,ae.formatValue=Pa,ae.normalizeCountryValues=fr,ae.toNumericCode=Bi,Object.defineProperty(ae,Symbol.toStringTag,{value:"Module"})}));
|
|
1116
1159
|
//# sourceMappingURL=gralobe.umd.cjs.map
|