import { FlyData , City } from "../types/index" ; import { InitFlyLine } from "../tools/flyLine" ; import { lon2xyz } from "../tools/index" ; import { GlobalConfig } from "../config/index" ; import { Vector3 , CatmullRomCurve3 , Object3D } from "three" ; import pointPng from "../img/point.png" ; export const earthAddFlyLine = ( earth , flyLineData , cityList ) => { let flyManager = null ; if ( flyManager == null ) { flyManager = new InitFlyLine ( { texture : pointPng , } ) ; } for ( var i = 0 ; i < flyLineData . length ; i ++ ) { var flyLine = flyLineData [ i ] ; for ( var j = 0 ; j < flyLine . to . length ; j ++ ) { randomAddFlyLine ( earth , flyManager , cityList [ flyLine . from ] , cityList [ flyLine . to [ j ] ] , flyLine . color ) ; } } return flyManager ; } ; const randomAddFlyLine = ( earth , flyManager , fromCity , toCity , color ) => { setTimeout ( function ( ) { addFlyLine ( earth , flyManager , fromCity , toCity , color ) ; } , Math . ceil ( Math . random ( ) * 15000 ) ) ; } ; const addFlyLine = ( earth , flyManager , fromCity , toCity , color ) => { var coefficient = 1 ; var curvePoints = new Array ( ) ; var fromXyz = lon2xyz ( GlobalConfig . earthRadius , fromCity . longitude , fromCity . latitude ) ; var toXyz = lon2xyz ( GlobalConfig . earthRadius , toCity . longitude , toCity . latitude ) ; curvePoints . push ( new Vector3 ( fromXyz . x , fromXyz . y , fromXyz . z ) ) ; var distanceDivRadius = Math . sqrt ( ( fromXyz . x - toXyz . x ) * ( fromXyz . x - toXyz . x ) + ( fromXyz . y - toXyz . y ) * ( fromXyz . y - toXyz . y ) + ( fromXyz . z - toXyz . z ) * ( fromXyz . z - toXyz . z ) ) / GlobalConfig . earthRadius ; var partCount = 3 + Math . ceil ( distanceDivRadius * 3 ) ; for ( var i = 0 ; i < partCount ; i ++ ) { var partCoefficient = coefficient + ( partCount - Math . abs ( ( partCount - 1 ) / 2 - i ) ) * 0.01 ; var partTopXyz = getPartTopPoint ( { x : ( fromXyz . x * ( partCount - i ) ) / partCount + ( toXyz . x * ( i + 1 ) ) / partCount , y : ( fromXyz . y * ( partCount - i ) ) / partCount + ( toXyz . y * ( i + 1 ) ) / partCount , z : ( fromXyz . z * ( partCount - i ) ) / partCount + ( toXyz . z * ( i + 1 ) ) / partCount , } , GlobalConfig . earthRadius , partCoefficient ) ; curvePoints . push ( new Vector3 ( partTopXyz . x , partTopXyz . y , partTopXyz . z ) ) ; } curvePoints . push ( new Vector3 ( toXyz . x , toXyz . y , toXyz . z ) ) ; var curve = new CatmullRomCurve3 ( curvePoints , false ) ; var pointCount = Math . ceil ( 500 * partCount ) ; var allPoints = curve . getPoints ( pointCount ) ; var flyMesh = flyManager . addFly ( { curve : allPoints , color : color , width : 0.3 , length : Math . ceil ( ( allPoints . length * 3 ) / 5 ) , speed : partCount + 10 , repeat : Infinity , } ) ; earth . add ( flyMesh ) ; } ; const getPartTopPoint = ( innerPoint , earthRadius , partCoefficient ) => { var fromPartLen = Math . sqrt ( innerPoint . x * innerPoint . x + innerPoint . y * innerPoint . y + innerPoint . z * innerPoint . z ) ; return { x : ( innerPoint . x * partCoefficient * earthRadius ) / fromPartLen , y : ( innerPoint . y * partCoefficient * earthRadius ) / fromPartLen , z : ( innerPoint . z * partCoefficient * earthRadius ) / fromPartLen , } ; } ;