defstep(grid):h,w=grid.shapeout=grid.copy()foryinrange(1,h-1):forxinrange(1,w-1):n=grid[y-1:y+2,x-1:x+2].sum()-grid[y,x]out[y,x]=1ifn>4else0returnout# init random 45% wall, run 5 steps → cave
Pattern 3 — Wave Function Collapse (sketch)
# tiles: list of (id, neighbor constraint dict)defwfc(grid_size,tiles):grid=[[set(t.idfortintiles)for_inrange(grid_size)]for_inrange(grid_size)]whilenotall_collapsed(grid):c=lowest_entropy_cell(grid)grid[c.y][c.x]={random.choice(list(grid[c.y][c.x]))}propagate(grid,c,tiles)returngrid
Pattern 4 — BSP dungeon partition
defsplit(rect,depth=4):ifdepth==0ormin(rect.w,rect.h)<12:return[rect]ifrect.w>rect.h:x=random.randint(rect.x+4,rect.x+rect.w-4)returnsplit(Rect(rect.x,rect.y,x-rect.x,rect.h),depth-1)+ \
split(Rect(x,rect.y,rect.x+rect.w-x,rect.h),depth-1)# similar for vertical
Pattern 5 — Diffusion terrain (2026)
# Pseudo: Stable Diffusion XL fine-tuned on heightmap atlasheightmap=sd_terrain.generate(prompt="alpine valley with river, top-down heightmap, 16-bit grayscale")mesh=heightmap_to_mesh(heightmap,vertical_scale=200.0)
Pattern 6 — Satellite → OSM (SAM-2)
# Mask building footprints from satellite tile, convert to OSM polygonsmasks=sam2.predict(satellite_tile)polygons=[mask_to_polygon(m)forminmasksifm.score>0.8]osm_xml=polygons_to_osm(polygons,tag={"building":"yes"})
매 결정 기준
상황
Approach
Continuous terrain
Perlin / Simplex / fBm
Organic cave
Cellular automaton
Tile-based level (puzzle)
WFC
Dungeon rooms
BSP + corridor connect
Open-world AAA
Houdini + UE5 PCG
Prompted asset
Diffusion (SDXL terrain LoRA)
GIS extraction
SAM-2 + DETR + OSM tagging
기본값: Perlin for terrain, WFC for tile-based, BSP for dungeons.