public void RemoveBricks(RegId id) { if (!m_BricksToVoxels.ContainsKey(id)) { return; } BrickMeta bm = m_BricksToVoxels[id]; foreach (var v in bm.voxels) { List <VoxelMeta> vm_list = m_VoxelToBricks[v]; int idx = vm_list.FindIndex((VoxelMeta lhs) => lhs.id == id); if (idx >= 0) { vm_list.RemoveAt(idx); if (vm_list.Count > 0) { UpdateIndex(v); } else { ClearVoxel(v); m_VoxelToBricks.Remove(v); } } } m_BricksToVoxels.Remove(id); }
public void AddBricks(RegId id, List <Brick> bricks, List <Chunk> allocations, int allocationSize, int poolWidth, int poolHeight) { Debug.Assert(bricks.Count <= ushort.MaxValue, "Cannot add more than 65K bricks per RegId."); int largest_cell = ProbeReferenceVolume.CellSize(15); // create a new copy BrickMeta bm = new BrickMeta(); bm.voxels = new HashSet <Vector3Int>(); bm.bricks = new List <ReservedBrick>(bricks.Count); m_BricksToVoxels.Add(id, bm); int brick_idx = 0; // find all voxels each brick will touch for (int i = 0; i < allocations.Count; i++) { Chunk alloc = allocations[i]; int cnt = Mathf.Min(allocationSize, bricks.Count - brick_idx); for (int j = 0; j < cnt; j++, brick_idx++, alloc.x += ProbeBrickPool.kBrickProbeCountPerDim) { Brick brick = bricks[brick_idx]; int cellSize = ProbeReferenceVolume.CellSize(brick.size); Debug.Assert(cellSize <= largest_cell, "Cell sizes are not correctly sorted."); largest_cell = Mathf.Min(largest_cell, cellSize); MapBrickToVoxels(brick, bm.voxels); ReservedBrick rbrick = new ReservedBrick(); rbrick.brick = brick; rbrick.flattenedIdx = MergeIndex(alloc.flattenIndex(poolWidth, poolHeight), brick.size); bm.bricks.Add(rbrick); foreach (var v in bm.voxels) { List <VoxelMeta> vm_list; if (!m_VoxelToBricks.TryGetValue(v, out vm_list)) // first time the voxel is touched { vm_list = new List <VoxelMeta>(1); m_VoxelToBricks.Add(v, vm_list); } VoxelMeta vm; int vm_idx = vm_list.FindIndex((VoxelMeta lhs) => lhs.id == id); if (vm_idx == -1) // first time a brick from this id has touched this voxel { vm.id = id; vm.brickIndices = new List <ushort>(4); vm_list.Add(vm); } else { vm = vm_list[vm_idx]; } // add this brick to the voxel under its regId vm.brickIndices.Add((ushort)brick_idx); } } } foreach (var voxel in bm.voxels) { UpdateIndex(voxel); } }