text: "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var i=require("three"),t=require("../geometries/LightningStrike.cjs.js");require("../math/SimplexNoise.cjs.js"),require("@babel/runtime/helpers/defineProperty");class n extends i.Object3D{constructor(n={}){super(),this.stormParams=n,n.size=void 0!==n.size?n.size:1e3,n.minHeight=void 0!==n.minHeight?n.minHeight:80,n.maxHeight=void 0!==n.maxHeight?n.maxHeight:100,n.maxSlope=void 0!==n.maxSlope?n.maxSlope:1.1,n.maxLightnings=void 0!==n.maxLightnings?n.maxLightnings:3,n.lightningMinPeriod=void 0!==n.lightningMinPeriod?n.lightningMinPeriod:3,n.lightningMaxPeriod=void 0!==n.lightningMaxPeriod?n.lightningMaxPeriod:7,n.lightningMinDuration=void 0!==n.lightningMinDuration?n.lightningMinDuration:1,n.lightningMaxDuration=void 0!==n.lightningMaxDuration?n.lightningMaxDuration:2.5,this.lightningParameters=t.LightningStrike.copyParameters(n.lightningParameters,n.lightningParameters),this.lightningParameters.isEternal=!1,this.lightningMaterial=void 0!==n.lightningMaterial?n.lightningMaterial:new i.MeshBasicMaterial({color:11599871}),void 0!==n.onRayPosition?this.onRayPosition=n.onRayPosition:this.onRayPosition=function(t,s){s.set((Math.random()-.5)*n.size,0,(Math.random()-.5)*n.size);const e=i.MathUtils.lerp(n.minHeight,n.maxHeight,Math.random());t.set(n.maxSlope*(2*Math.random()-1),1,n.maxSlope*(2*Math.random()-1)).multiplyScalar(e).add(s)},this.onLightningDown=n.onLightningDown,this.inited=!1,this.nextLightningTime=0,this.lightningsMeshes=[],this.deadLightningsMeshes=[];for(let n=0;n<this.stormParams.maxLightnings;n++){const n=new t.LightningStrike(t.LightningStrike.copyParameters({},this.lightningParameters)),s=new i.Mesh(n,this.lightningMaterial);this.deadLightningsMeshes.push(s)}}update(n){if(this.inited||(this.nextLightningTime=this.getNextLightningTime(n)*Math.random(),this.inited=!0),n>=this.nextLightningTime){const s=this.deadLightningsMeshes.pop();if(s){const e=t.LightningStrike.copyParameters(s.geometry.rayParameters,this.lightningParameters);e.birthTime=n,e.deathTime=n+i.MathUtils.lerp(this.stormParams.lightningMinDuration,this.stormParams.lightningMaxDuration,Math.random()),this.onRayPosition(e.sourceOffset,e.destOffset),e.noiseSeed=Math.random(),this.add(s),this.lightningsMeshes.push(s)}this.nextLightningTime=this.getNextLightningTime(n)}let s=0,e=this.lightningsMeshes.length;for(;s<e;){const i=this.lightningsMeshes[s],a=i.geometry,h=a.state;a.update(n),h===t.LightningStrike.RAY_PROPAGATING&&a.state>h&&this.onLightningDown&&this.onLightningDown(a),a.state===t.LightningStrike.RAY_EXTINGUISHED?(this.lightningsMeshes.splice(this.lightningsMeshes.indexOf(i),1),this.deadLightningsMeshes.push(i),this.remove(i),e--):s++}}getNextLightningTime(t){return t+i.MathUtils.lerp(this.stormParams.lightningMinPeriod,this.stormParams.lightningMaxPeriod,Math.random())/(this.stormParams.maxLightnings+1)}copy(i){return super.copy(i),this.stormParams.size=i.stormParams.size,this.stormParams.minHeight=i.stormParams.minHeight,this.stormParams.maxHeight=i.stormParams.maxHeight,this.stormParams.maxSlope=i.stormParams.maxSlope,this.stormParams.maxLightnings=i.stormParams.maxLightnings,this.stormParams.lightningMinPeriod=i.stormParams.lightningMinPeriod,this.stormParams.lightningMaxPeriod=i.stormParams.lightningMaxPeriod,this.stormParams.lightningMinDuration=i.stormParams.lightningMinDuration,this.stormParams.lightningMaxDuration=i.stormParams.lightningMaxDuration,this.lightningParameters=t.LightningStrike.copyParameters({},i.lightningParameters),this.lightningMaterial=i.stormParams.lightningMaterial,this.onLightningDown=i.onLightningDown,this}clone(){return new this.constructor(this.stormParams).copy(this)}}n.prototype.isLightningStorm=!0,exports.LightningStorm=n;
  