//CONSIDER: we will want to define this class's relationship to Chunk at some point public void Init(IntVector3 chunkPos, uint[] voxels) { int depth = vGenConfig.hilbertBits; Vector3 center = vGenConfig.ChunkPosToPos(chunkPos) + vGenConfig.ChunkSize / 2f; var bounds = new Bounds(center, vGenConfig.ChunkSize); tree = new VoxelOctree <uint>(depth, bounds); foreach (uint vox in voxels) { IntVector3 pos = IntVector3.FromUint256(vox); tree.Set(vox, pos.ToVector3()); } // instantiate or just set up raycast display rayDisplay = Instantiate(raycastDisplayPrefab); rayDisplay.transform.SetParent(transform); rayDisplay.transform.localPosition = vGenConfig.ChunkPosToPos(chunkPos); //ComputeBuffer b = BufferUtil.CreateWith(voxels); rayDisplay.initialize(null); //ResetBufferData(voxels); //test StartCoroutine(Scan()); //want }
public void Execute(int index) { var voxel = chunkData[index]; IntVector3 v = IntVector3.FromUint256((int)voxel.voxel); int flatIndex = v.ToFlatXYZIndex(chunkSize); contents[flatIndex] = voxel; }
public static int[] FakeHeights(IntVector3 size, int startY) { var stairs = Stairs(size); var result = new FlatArray2D <int>(size.xz); foreach (var vox in stairs) { var pos = IntVector3.FromUint256(vox); result[pos.xz] = result[pos.xz] < pos.y + startY ? pos.y + startY : result[pos.xz]; } return(result.storage); }
public void Execute(int index) { var pos = IntVector3.FromUint256(displayVoxels[index].voxel); bool hidden = false; int div = (int)Mathf.Pow(2, lodIndex); var touchDirections = CubeNeighbors6.TouchFaces(pos / div, chunkSize / div).ToList(); foreach (var nd in touchDirections) { hidden = true; var oppDir = CubeNeighbors6.Opposite(nd); var opp = CubeNeighbors6.SnapToFace(pos / div, chunkSize / div, oppDir); uint voxel = GetVoxelFromGenDataArray(get(nd), opp); if (voxel == EmptyVoxel) { hidden = false; break; } } if (hidden) { foreach (var nd in CubeNeighbors6.Directions) { if (touchDirections.Contains(nd)) { continue; } var nudge = pos / div + CubeNeighbors6.Relative(nd); uint voxel = GetVoxelFromGenDataArray(center, nudge); if (voxel == EmptyVoxel) { hidden = false; break; } } } if (hidden) { var geomData = displayVoxels[index]; geomData.voxel = EmptyVoxel; displayVoxels[index] = geomData; } }
public static void CheckAllSamePositionOnAxis(ComputeBuffer buff, int axis, string msg = " same axis? ") { var data = CVoxelMapFormat.BufferCountArgs.GetData <int>(buff); var axCoords = new List <int>(data.Length); foreach (var vox in data) { axCoords.Add(IntVector3.FromUint256(vox)[axis]); } var unique = axCoords.Distinct().Count(); Debug.Log(string.Format("{0} unique axis {1}? {2} data: {3} unique {4}", msg, axis, data.Length == unique, data.Length, unique)); }
public void Execute(int index) { IntVector3 pos = IntVector3.FromUint256(display[index].voxel); lock (locks[index]) { foreach (var relative in CrossNeighbors12.members) { var neiPos = pos + relative; if (ExistsAt(neiPos) == 1) { //todo: perform update var Geom = display[index]; Geom.extras = CrossBits12.SetBit(relative, true, Geom.extras); display[index] = Geom; } } } }