用途:针对含数千个部件的 Three.js 建造类游戏,做空间索引与大地图世界流式加载,以优化查询与渲染性能。
主要能力:提供 SpatialHashGrid(均匀分布下的 O(1) 查询)与 Octree(聚集对象的自适应查询),以及 chunk-manager.js 用于大型地图的世界流式加载、performance-profiler.js 用于基准测试。
用法:按需导入脚本并使用,例如:import { SpatialHashGrid } from './scripts/spatial-hash-grid.js'; import { Octree } from './scripts/octree.js'; 均匀分布用 const grid = new SpatialHashGrid(10); grid.insert(piece, piece.position); const nearby = grid.queryRadius(position, 15); 聚集基地用 const octree = new Octree(bounds, { maxDepth: 8 }); octree.insert(piece); const inBox = octree.queryBox(min, max);
选择建议:部件少于 1,000 时用数组;1–5k 且均匀分布用 SpatialHashGrid;1–5k 且聚集用 Octree;5k 以上用 ChunkManager 并按块配 Octree。
适用场景:建造类游戏的邻近查询、碰撞与渲染剔除、大地图分块加载。
限制:官方文本未提供,具体参数调优、内存与平台支持等细节暂未提供,详细说明见 references/performance-at-scale.md。