/
RaskolnickOFF
/
3D
Обзор
Документация
Войти
/
RaskolnickOFF
/
3D
Код
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
js/source/systems/render/BiomeVisualSystem.js
84 строки
3 KB
RaskolnickOFF
Structure update
06 июн 2026, 03:18
06 июн 2026, 03:18
9bc1c25
Код
Авторство
О чём код?
// js/source/systems/render/BiomeVisualSystem.js — туман + цвет деревьев по биому // Раскраска террейна — только через levelColors в Ground.js, не трогаем. import { Components } from '../../core/Components.js'; export class BiomeVisualSystem { /** * @param {import('../core/RenderContext.js').RenderContext} ctx * @param {{ updateBiomePalette?: Function }} groundApi — больше не используется для палитры * @param {import('./TerrainSystem.js').TerrainSystem} terrainSystem */ constructor(ctx, groundApi, terrainSystem) { this.scene = ctx.scene; this.eventBus = ctx.eventBus; this.worldMapData = ctx.worldMapData; this.groundApi = groundApi; this.terrainSystem = terrainSystem; this.playerEntity = null; this._currentTreeBiome = null; this._treeBiomeCounter = 0; this._TREE_BIOME_DELAY = 80; } setPlayerEntity(entity) { this.playerEntity = entity; } update() { if (!this.playerEntity || !this.worldMapData) return; const transform = this.playerEntity.get(Components.TRANSFORM); if (!transform) return; const groundY = this.terrainSystem.getHeightAt(transform.x, transform.z); const biome = this.worldMapData.getBiomeAt(transform.x, transform.z, groundY); if (!biome) return; // Туман по биому if (this.scene.fog && biome.fog) { this.scene.fog.color.set(biome.fog); } // Цвет деревьев по биому this._updateTreeColor(biome.type); } _updateTreeColor(biomeType) { if (biomeType === this._currentTreeBiome) { this._treeBiomeCounter = 0; return; } this._treeBiomeCounter++; if (this._treeBiomeCounter >= this._TREE_BIOME_DELAY) { this._currentTreeBiome = biomeType; this._treeBiomeCounter = 0; this._applyTreeColor(biomeType === 'snow' ? 'snow' : 'standard'); } } _applyTreeColor(mode) { const treeConfigs = this.worldMapData?.settings?.trees; if (!treeConfigs) return; this.scene.traverse(child => { if (!child.name || !child.name.startsWith('tree_')) return; const type = child.name.replace('tree_', ''); const cfg = treeConfigs[type]; if (!cfg) return; const color = mode === 'snow' ? (cfg.snowColor || '#e8eef0') : (cfg.leavesColor || '#2d5a1e'); child.traverse(sub => { if (sub.isMesh && sub.material && sub.name === 'leaves') { sub.material.color.set(color); } }); }); } }