public void RemoveBricks(CellInfo cellInfo) { if (!m_BricksToVoxels.ContainsKey(cellInfo.cell)) { return; } var cellUpdateInfo = cellInfo.updateInfo; g_Cell = cellInfo.cell; BrickMeta bm = m_BricksToVoxels[cellInfo.cell]; foreach (var v in bm.voxels) { List <VoxelMeta> vm_list = m_VoxelToBricks[v]; int idx = vm_list.FindIndex((VoxelMeta lhs) => lhs.cell == g_Cell); if (idx >= 0) { m_VoxelMetaPool.Release(vm_list[idx]); vm_list.RemoveAt(idx); if (vm_list.Count > 0) { UpdateIndexForVoxel(v, cellUpdateInfo); } else { ClearVoxel(v, cellUpdateInfo); m_VoxelMetaListPool.Release(vm_list); m_VoxelToBricks.Remove(v); } } } m_BrickMetaPool.Release(bm); m_BricksToVoxels.Remove(cellInfo.cell); // Clear allocated chunks for (int i = cellUpdateInfo.firstChunkIndex; i < (cellUpdateInfo.firstChunkIndex + cellUpdateInfo.numberOfChunks); ++i) { m_IndexChunks[i] = false; } m_AvailableChunkCount += cellUpdateInfo.numberOfChunks; }
public void Clear() { cell = null; brickIndices.Clear(); }
public void AddBricks(Cell cell, NativeArray <Brick> bricks, List <Chunk> allocations, int allocationSize, int poolWidth, int poolHeight, CellIndexUpdateInfo cellInfo) { Debug.Assert(bricks.Length <= ushort.MaxValue, "Cannot add more than 65K bricks per RegId."); int largest_cell = ProbeReferenceVolume.CellSize(kMaxSubdivisionLevels); g_Cell = cell; // create a new copy BrickMeta bm = m_BrickMetaPool.Get(); m_BricksToVoxels.Add(cell, 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.Length - 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.subdivisionLevel); 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.subdivisionLevel); 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 = m_VoxelMetaListPool.Get(); m_VoxelToBricks.Add(v, vm_list); } VoxelMeta vm = null; int vm_idx = vm_list.FindIndex((VoxelMeta lhs) => lhs.cell == g_Cell); if (vm_idx == -1) // first time a brick from this id has touched this voxel { vm = m_VoxelMetaPool.Get(); vm.cell = cell; 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) { UpdateIndexForVoxel(voxel, cellInfo); } }