private void Destruct() { Batch batch = new Batch(PicaVoxelVolume); Vector3 posZero = PicaVoxelVolume.transform.position + (transform.rotation * (-PicaVoxelVolume.Pivot + (Vector3.one * (PicaVoxelVolume.VoxelSize * 0.5f)))); Vector3 oneX = PicaVoxelVolume.transform.rotation * (new Vector3(PicaVoxelVolume.VoxelSize, 0, 0)); Vector3 oneY = PicaVoxelVolume.transform.rotation * (new Vector3(0f, PicaVoxelVolume.VoxelSize, 0)); Vector3 oneZ = PicaVoxelVolume.transform.rotation * (new Vector3(0, 0, PicaVoxelVolume.VoxelSize)); Vector3 constructorPosition = transform.position; Frame frame = PicaVoxelVolume.GetCurrentFrame(); //int numVox = 0; Vector3 checkPos = posZero; for (int x = 0; x < PicaVoxelVolume.XSize; x++) { Vector3 xmult = oneX * x; for (int y = 0; y < PicaVoxelVolume.YSize; y++) { Vector3 ymult = oneY * y; for (int z = 0; z < PicaVoxelVolume.ZSize; z++) { Vector3 zmult = oneZ * z; checkPos.x = posZero.x + xmult.x + ymult.x + zmult.x; checkPos.y = posZero.y + xmult.y + ymult.y + zmult.y; checkPos.z = posZero.z + xmult.z + ymult.z + zmult.z; if (frame.Voxels[x + PicaVoxelVolume.XSize * (y + PicaVoxelVolume.YSize * z)].Active && Vector3.Distance(constructorPosition, checkPos) <= radius) { //numVox++; Voxel v = frame.Voxels[x + PicaVoxelVolume.XSize * (y + PicaVoxelVolume.YSize * z)]; v.Color *= PicaVoxelVolume.Material.GetColor("_Tint"); batch.Add(v, x, y, z, checkPos); frame.Voxels[x + PicaVoxelVolume.XSize * (y + PicaVoxelVolume.YSize * z)].State = VoxelState.Hidden; frame.SetChunkAtVoxelPositionDirty(x, y, z); } } } } if (CreateParticles && batch.Voxels.Count > 0 && VoxelParticleSystem.Instance != null) { VoxelParticleSystem.Instance.SpawnBatch(batch, pos => ((transform.position - (pos + Random.insideUnitSphere)) * 1f)); } batch.Dispose(); }
private void Construct() { Vector3 posZero = PicaVoxelVolume.transform.position + (transform.rotation * (-PicaVoxelVolume.Pivot + (Vector3.one * (PicaVoxelVolume.VoxelSize * 0.5f)))); Vector3 oneX = PicaVoxelVolume.transform.rotation * (new Vector3(PicaVoxelVolume.VoxelSize, 0, 0)); Vector3 oneY = PicaVoxelVolume.transform.rotation * (new Vector3(0f, PicaVoxelVolume.VoxelSize, 0)); Vector3 oneZ = PicaVoxelVolume.transform.rotation * (new Vector3(0, 0, PicaVoxelVolume.VoxelSize)); Vector3 constructorPosition = transform.position; Frame frame = PicaVoxelVolume.GetCurrentFrame(); Vector3 checkPos = posZero; for (int x = 0; x < PicaVoxelVolume.XSize; x++) { Vector3 xmult = oneX * x; for (int y = 0; y < PicaVoxelVolume.YSize; y++) { Vector3 ymult = oneY * y; for (int z = 0; z < PicaVoxelVolume.ZSize; z++) { Vector3 zmult = oneZ * z; checkPos.x = posZero.x + xmult.x + ymult.x + zmult.x; checkPos.y = posZero.y + xmult.y + ymult.y + zmult.y; checkPos.z = posZero.z + xmult.z + ymult.z + zmult.z; if (!frame.Voxels[x + PicaVoxelVolume.XSize * (y + PicaVoxelVolume.YSize * z)].Active && originalVoxels[x + PicaVoxelVolume.XSize * (y + PicaVoxelVolume.YSize * z)].Active && Vector3.Distance(constructorPosition, checkPos) <= radius) { frame.Voxels[x + PicaVoxelVolume.XSize * (y + PicaVoxelVolume.YSize * z)] = originalVoxels[x + PicaVoxelVolume.XSize * (y + PicaVoxelVolume.YSize * z)]; frame.SetChunkAtVoxelPositionDirty(x, y, z); //PicaVoxelVolume.SetVoxelAtArrayPosition(x, y, z, // originalVoxels[x + PicaVoxelVolume.XSize*(y + PicaVoxelVolume.YSize*z)]); } } } } frame.UpdateChunks(false); //frame.UpdateAllChunksNextFrame(); }