diff --git a/public/audio/thunder-close.mp3 b/public/audio/thunder-close.mp3 new file mode 100644 index 0000000..201dc45 Binary files /dev/null and b/public/audio/thunder-close.mp3 differ diff --git a/src/OceanScene.js b/src/OceanScene.js index 0489b9a..26f56ee 100644 --- a/src/OceanScene.js +++ b/src/OceanScene.js @@ -13,7 +13,7 @@ import { DEFAULT_SCENE_PARAMS } from './weatherPresets.js'; import { OffshoreWindTurbineAsset } from './objects/OffshoreWindTurbineAsset.js'; const RAIN_AUDIO_URL = '/audio/rain-calming.mp3'; -const THUNDER_AUDIO_URL = '/audio/thunder-distant.mp3'; +const THUNDER_AUDIO_URL = '/audio/thunder-close.mp3'; export class OceanScene { constructor(container) { @@ -61,6 +61,7 @@ export class OceanScene { this.rainAudioCrossfadeDuration = 1.6; this.thunderAudioPool = []; this.thunderAudioIndex = 0; + this.thunderVolume = DEFAULT_SCENE_PARAMS.thunderVolume; this.scheduledThunder = []; this.params = { ...DEFAULT_SCENE_PARAMS }; @@ -1802,6 +1803,12 @@ export class OceanScene { this.params.lightningIntensity = value; } + setThunderVolume(value) { + const nextValue = THREE.MathUtils.clamp(value, 0, 1); + this.params.thunderVolume = nextValue; + this.thunderVolume = nextValue; + } + applyParams(nextParams = {}) { const mergedParams = { ...DEFAULT_SCENE_PARAMS, ...nextParams }; @@ -1831,6 +1838,7 @@ export class OceanScene { this.setStarIntensity(mergedParams.starIntensity); this.setStarEnabled(mergedParams.starEnabled); this.setLightningIntensity(mergedParams.lightningIntensity); + this.setThunderVolume(mergedParams.thunderVolume); this.setLightningEnabled(mergedParams.lightningEnabled); this.setRainEnabled(mergedParams.rainEnabled); } @@ -1904,7 +1912,7 @@ export class OceanScene { this.thunderAudioIndex += 1; audio.pause(); audio.currentTime = 0; - audio.volume = THREE.MathUtils.clamp(volume, 0, 1); + audio.volume = THREE.MathUtils.clamp(volume * this.thunderVolume, 0, 1); audio.playbackRate = playbackRate; const playPromise = audio.play(); if (playPromise?.catch) { diff --git a/src/main.js b/src/main.js index 04c808e..61d85a9 100644 --- a/src/main.js +++ b/src/main.js @@ -70,7 +70,8 @@ function setupControls(oceanScene) { 'starEnabled', 'starIntensity', 'lightningEnabled', - 'lightningIntensity' + 'lightningIntensity', + 'thunderVolume' ]; const presetComments = { elevation: '太阳高度角', @@ -100,7 +101,8 @@ function setupControls(oceanScene) { starEnabled: '是否启用星空', starIntensity: '星空强度', lightningEnabled: '是否启用雷闪', - lightningIntensity: '雷闪强度' + lightningIntensity: '雷闪强度', + thunderVolume: '雷声音量' }; const exportActions = { @@ -207,14 +209,10 @@ function setupControls(oceanScene) { const rainFolder = gui.addFolder('雨效'); bindController(rainFolder.add(params, 'rainEnabled').name('启用雨效'), (value) => oceanScene.setRainEnabled(value)); - bindController(rainFolder.add(params, 'rainScreenIntensity', 0, 1.5, 0.01).name('屏幕雨滴'), (value) => oceanScene.setRainScreenIntensity(value)); bindController(rainFolder.add(params, 'rainVeilIntensity', 0.5, 2.5, 0.01).name('雨线强度'), (value) => oceanScene.setRainVeilIntensity(value)); - bindController(rainFolder.add(params, 'rainDropSize', 0.4, 1.8, 0.01).name('雨滴尺寸'), (value) => oceanScene.setRainDropSize(value)); - bindController(rainFolder.add(params, 'rainSpeed', 0.2, 2.5, 0.01).name('速度'), (value) => oceanScene.setRainSpeed(value)); bindController(rainFolder.add(params, 'rainAudioEnabled').name('启用雨声'), (value) => oceanScene.setRainAudioEnabled(value)); bindController(rainFolder.add(params, 'rainAudioVolume', 0, 1, 0.01).name('雨声音量'), (value) => oceanScene.setRainAudioVolume(value)); bindController(rainFolder.add(params, 'lightningEnabled').name('启用雷闪'), (value) => oceanScene.setLightningEnabled(value)); - bindController(rainFolder.add(params, 'lightningIntensity', 0, 1.5, 0.01).name('雷闪强度'), (value) => oceanScene.setLightningIntensity(value)); const snowFolder = gui.addFolder('雪效'); bindController(snowFolder.add(params, 'snowEnabled').name('启用降雪'), (value) => oceanScene.setSnowEnabled(value)); diff --git a/src/weatherPresets.js b/src/weatherPresets.js index 208a8be..181e004 100644 --- a/src/weatherPresets.js +++ b/src/weatherPresets.js @@ -28,6 +28,7 @@ export const DEFAULT_SCENE_PARAMS = { starIntensity: 0.7, lightningEnabled: true, lightningIntensity: 0.75, + thunderVolume: 1.0, mieCoefficient: 0.005, mieDirectionalG: 0.8 };