import { PlaneBufferGeometry , TextureLoader , MeshBasicMaterial , DoubleSide , Mesh , Vector3 , } from "three" ; import type { City } from "../types/index" ; import { lon2xyz } from "../tools/index" ; import { GlobalConfig } from "../config/index" ; import wavePng from "../img/wave.png" ; import pointPng from "../img/point.png" ; export const getCityMeshGroup = ( cityList ) => { let waveMeshArr = [ ] ; let pointMeshArr = [ ] ; for ( const cityName in cityList ) { var city = cityList [ cityName ] ; var cityXyz = lon2xyz ( GlobalConfig . earthRadius , city . longitude , city . latitude ) ; var cityGeometry = new PlaneBufferGeometry ( 1 , 1 ) ; var textureLoader = new TextureLoader ( ) ; var texture = textureLoader . load ( wavePng ) ; var cityWaveMaterial = new MeshBasicMaterial ( { color : 0x22ffcc , map : texture , transparent : true , opacity : 1.0 , side : DoubleSide , depthWrite : false , } ) ; var pointTexture = textureLoader . load ( pointPng ) ; var cityPointMaterial = new MeshBasicMaterial ( { color : 0xffc300 , map : pointTexture , transparent : true , depthWrite : false , } ) ; var cityWaveMesh = new Mesh ( cityGeometry , cityWaveMaterial ) ; var cityMesh = new Mesh ( cityGeometry , cityPointMaterial ) ; var size = GlobalConfig . earthRadius * 0.05 ; cityMesh . scale . set ( size , size , size ) ; var size = GlobalConfig . earthRadius * 0.12 ; ( cityWaveMesh as any ) . size = size ; cityWaveMesh . scale . set ( size , size , size ) ; ( cityWaveMesh as any ) . _s = Math . random ( ) * 1.0 + 1.0 ; cityWaveMesh . position . set ( cityXyz . x , cityXyz . y , cityXyz . z ) ; cityMesh . position . set ( cityXyz . x , cityXyz . y , cityXyz . z ) ; var coordVec3 = new Vector3 ( cityXyz . x , cityXyz . y , cityXyz . z ) . normalize ( ) ; var meshNormal = new Vector3 ( 0 , 0 , 1 ) ; cityWaveMesh . quaternion . setFromUnitVectors ( meshNormal , coordVec3 ) ; cityMesh . quaternion . setFromUnitVectors ( meshNormal , coordVec3 ) ; waveMeshArr . push ( cityWaveMesh ) ; pointMeshArr . push ( cityMesh ) ; } return { waveMeshArr , pointMeshArr } ; } ; export const cityWaveAnimate = ( WaveMeshArr ) => { WaveMeshArr . forEach ( function ( mesh ) { mesh . _s += 0.007 ; mesh . scale . set ( mesh . size * mesh . _s , mesh . size * mesh . _s , mesh . size * mesh . _s ) ; if ( mesh . _s <= 1.5 ) { mesh . material . opacity = ( mesh . _s - 1 ) * 2 ; } else if ( mesh . _s > 1.5 && mesh . _s <= 2 ) { mesh . material . opacity = 1 - ( mesh . _s - 1.5 ) * 2 ; } else { mesh . _s = 1.0 ; } } ) ; } ;