update map

This commit is contained in:
bridge
2025-12-11 22:28:29 +08:00
parent 1f45d13214
commit b6bce76c36
68 changed files with 27 additions and 18 deletions

View File

@@ -7,12 +7,20 @@ import { getClusteredTileVariant } from '@/utils/procedural'
TextureStyle.defaultOptions.scaleMode = 'nearest'
// 地形变体配置
const TILE_VARIANTS: Record<string, { prefix: string, count: number }> = {
'RAINFOREST': { prefix: 'rainforest', count: 9 },
'BAMBOO': { prefix: 'bamboo', count: 9 },
'GOBI': { prefix: 'gobi', count: 9 },
'ISLAND': { prefix: 'island', count: 9 },
'SWAMP': { prefix: 'swamp', count: 9 },
// startIndex: 变体索引起始值,默认为 0
const TILE_VARIANTS: Record<string, { prefix: string, count: number, startIndex?: number }> = {
// 从 0 开始的变体 (0-8)
'GLACIER': { prefix: 'glacier', count: 9, startIndex: 0 },
'MOUNTAIN': { prefix: 'mountain', count: 9, startIndex: 0 },
'DESERT': { prefix: 'desert', count: 9, startIndex: 0 },
'SNOW_MOUNTAIN': { prefix: 'snow_mountain', count: 9, startIndex: 0 },
'FOREST': { prefix: 'forest', count: 9, startIndex: 0 },
'GRASSLAND': { prefix: 'grassland', count: 9, startIndex: 0 },
'RAINFOREST': { prefix: 'rainforest', count: 9, startIndex: 0 },
'BAMBOO': { prefix: 'bamboo', count: 9, startIndex: 0 },
'GOBI': { prefix: 'gobi', count: 9, startIndex: 0 },
'ISLAND': { prefix: 'island', count: 9, startIndex: 0 },
'SWAMP': { prefix: 'swamp', count: 9, startIndex: 0 },
}
// 全局纹理缓存,避免重复加载
@@ -83,8 +91,8 @@ export function useTextures() {
// Load Tile Variants
const variantPromises: Promise<void>[] = []
Object.entries(TILE_VARIANTS).forEach(([key, { prefix, count }]) => {
for (let i = 1; i <= count; i++) {
Object.entries(TILE_VARIANTS).forEach(([key, { prefix, count, startIndex = 0 }]) => {
for (let i = startIndex; i < startIndex + count; i++) {
const variantKey = `${key}_${i}`
const url = `/assets/tiles/${prefix}_${i}.png`
variantPromises.push(

View File

@@ -19,20 +19,21 @@ function random(x: number, y: number): number {
* 算法逻辑:
* 1. 使用双重正弦波生成低频噪声Biomes/群落感),让相邻的格子倾向于选择索引相近的变体。
* 2. 叠加高频 Hash 扰动Jitter避免纹理过于死板或出现明显的人工波纹。
* 3. 最终效果:变体会在地图上呈现自然的斑块状分布,而非杂乱的噪点。
* 3. 最终效果:变体会在地图上呈现自然的"斑块状"分布,而非杂乱的噪点。
*
* @param x 地图 X 坐标
* @param y 地图 Y 坐标
* @param count 变体总数 (例如 9)
* @returns 1 到 count 之间的整数索引
* @param startIndex 变体索引起始值,默认为 0
* @returns startIndex 到 startIndex + count - 1 之间的整数索引
*/
export function getClusteredTileVariant(x: number, y: number, count: number): number {
if (count <= 1) return 1;
export function getClusteredTileVariant(x: number, y: number, count: number, startIndex: number = 0): number {
if (count <= 1) return startIndex;
// 1. 低频噪声 (Large Scale Noise)
// 决定区域的主色调。Scale 越小,斑块越大。
// 0.15 意味着大约 2PI / 0.15 ~= 40 格一个完整周期,
// 视觉上大约 10-20 格为一个明显的群落
// 视觉上大约 10-20 格为一个明显的"群落"
const scale = 0.15;
// 使用两个不同频率和方向的波叠加,打破完美的对角线感
@@ -55,13 +56,13 @@ export function getClusteredTileVariant(x: number, y: number, count: number): nu
// 钳制到 [0, 1]
finalValue = Math.max(0, Math.min(1, finalValue));
// 4. 映射到 [1, count]
// 使用 Math.floor(val * count) 得到 0..count-1再 +1
let index = Math.floor(finalValue * count) + 1;
// 4. 映射到 [startIndex, startIndex + count - 1]
let index = Math.floor(finalValue * count) + startIndex;
// 边界保护 (防止浮点误差导致溢出)
if (index > count) index = count;
if (index < 1) index = 1;
const maxIndex = startIndex + count - 1;
if (index > maxIndex) index = maxIndex;
if (index < startIndex) index = startIndex;
return index;
}