//public string SceneName=>$"{Publisher} {Util.ToLocalDateTime(SubmitTime).ToString("d",CultureInfo.CreateSpecificCulture("en-GB"))}"; public JsonScene(VoxelGrid grid, List <Room> rooms) { var jsonVoxelGrid = new JsonVoxelGrid(grid); foreach (var voxel in grid.Voxels) { JsonVoxels.Add(new JsonVoxel(voxel)); } foreach (var room in rooms) { JsonRooms.Add(new JsonRoom(room, jsonVoxelGrid)); } }
void Start() { // Initialise the voxel grid Vector3Int gridSize = new Vector3Int(64, 10, 64); _voxelGrid = new VoxelGrid(gridSize, Vector3.zero, 1, parent: this.transform); // Set the random engine's seed Random.InitState(_randomSeed); // 46 Create the Pix2Pix inference object _pix2pix = new Pix2Pix(); }
public void ComponentStarted() { if (_displayGrid == null) { _displayGrid = new VoxelGrid(new VoxelGridData(1, 1, 1, 1), new Dictionary <Vector3i, GameObject>()); var gameObject = new GameObject($"{Name} Display Object"); gameObject.Transform.InheiritParentTransform = false; gameObject.AddComponent(_displayGrid); gameObject.AddComponent(new VoxelMeshRenderable(_types, _materialInstance)); GameObject.AddChild(_displayGrid.GameObject); } _displayGrid.GameObject.IsActive = true; }
static void FireBeam(int relXIndex, int relYIndex, Axis relativeX, Axis relativeY, Axis relativeZ, Octree <bool> voxelMap, Queue <Vector3Int> dirtyVoxels) { for (int i = 0; i < voxelMap.Dimensions.Get(relativeZ); i++) { Vector3Int pos = new Vector3Int(); pos = pos.Set(relativeX, relXIndex); pos = pos.Set(relativeY, relYIndex); pos = pos.Set(relativeZ, i); VoxelGrid.TryRemoveVoxel(pos, voxelMap, dirtyVoxels); } }
/// <summary> /// Creates a deep copy of this voxel in another grid /// </summary> /// <param name="other">The target <see cref="VoxelGrid"/></param> /// <returns>The copied <see cref="Voxel"/></returns> public Voxel DeepCopyToGrid(VoxelGrid other) { Voxel newVoxel = new Voxel(new Vector3Int(Index.x, Index.y, Index.z), other); newVoxel.IsOccupied = IsOccupied; newVoxel.IsActive = IsActive; newVoxel.Faces = Faces; newVoxel.Part = Part; newVoxel.InSpace = InSpace; newVoxel.ParentSpace = ParentSpace; return(newVoxel); }
private void CreateChunk(int index, int x, int y, int z) { VoxelGrid chunk = Instantiate(voxelGridPrefab) as VoxelGrid; chunk.name = "VoxelGrid" + index.ToString(); chunk.transform.parent = transform; chunk.transform.localPosition = new Vector3(x * chunkSize - chunkHalfSize * chunkResolution + voxelHalfSize, y * chunkSize - chunkHalfSize * chunkResolution + voxelHalfSize, z * chunkSize - chunkHalfSize * chunkResolution + voxelHalfSize); chunk.index = index; chunk.Initalize(voxelResolution, size); chunks.Add(chunk); }
/// <summary> /// Generates a texture from the grid, resized properly internally. /// </summary> /// <param name="grid">The source <see cref="VoxelGrid"/></param> /// <returns>The result <see cref="Texture2D"/></returns> public static Texture2D TextureFromGrid256(VoxelGrid grid) { //string folder = @"D:\GitRepo\PublicParts\PP_AI_Studies\temp_en"; var textureFormat = TextureFormat.RGB24; Vector2Int size = new Vector2Int(grid.Size.x, grid.Size.z); Texture2D gridImage = new Texture2D(size.x, size.y, textureFormat, true, true); for (int i = 0; i < gridImage.width; i++) { for (int j = 0; j < gridImage.height; j++) { var voxel = grid.Voxels[i, 0, j]; Color c = !voxel.IsActive || voxel.IsOccupied ? Color.black : Color.white; gridImage.SetPixel(i, j, c); } } gridImage.Apply(); //ImageReadWrite.SaveImage2Path(gridImage, folder + @"\helpers\firstOutput"); //Construct the resulting resized image //Scale image up, multiplying by 4 TextureScale.Point(gridImage, gridImage.width * 4, gridImage.height * 4); //Texture2D resultImage = new Texture2D(256, 256, textureFormat, true, true); Texture2D resultImage = new Texture2D(256, 256); //Set all pixels to gray Color[] grayPixels = new Color[256 * 256]; var gray = Color.gray; for (int i = 0; i < grayPixels.Length; i++) { grayPixels[i] = gray; } resultImage.SetPixels(grayPixels); resultImage.Apply(); //Write grid image on result image for (int i = 0; i < gridImage.width; i++) { for (int j = 0; j < gridImage.height; j++) { int x = i; int y = resultImage.height - gridImage.height + j; resultImage.SetPixel(x, y, gridImage.GetPixel(i, j)); } } resultImage.Apply(); return(resultImage); }
// //Unity Specific Methods // void Start() { _cam = Camera.main; if (!_testMode) { if (_bigGrid) { _gridSize = new Vector3Int(40, 1, 82); _grid = new VoxelGrid(_gridSize, _voxelSize, Vector3.zero); _slabFile = "Input Data/BigSlab"; _structureFile = "StructureParts_BigSlab"; } else { _gridSize = new Vector3Int(20, 1, 45); _grid = new VoxelGrid(_gridSize, _voxelSize, Vector3.zero); _slabFile = "Input Data/SmallSlab"; _structureFile = "Input Data/StructureParts_SmallSlab"; } } else { _gridSize = new Vector3Int(20, 1, 45); _grid = new VoxelGrid(_gridSize, _voxelSize, Vector3.zero); _slabFile = "Input Data/TestingData/SlabStates"; _structureFile = "Input Data/TestingData/Structure"; string configurablesFile = "Input Data/TestingData/Configurables"; string spacesFile = "Input Data/TestingData/Spaces"; //string knotsFile = "Input Data/TestingData/Knots"; ReadConfigurables(configurablesFile); ReadSpaces(spacesFile); //ReadKnots(knotsFile); } _tenants = JSONReader.ReadTenantsWithPreferences("Input Data/U_TenantPreferences", _grid); _spaceRequests = JSONReader.ReadSpaceRequests("Input Data/U_SpaceRequests", _tenants); _cameraPivot.position = new Vector3(_gridSize.x / 2, 0, _gridSize.z / 2) * _voxelSize; //Read CSV to create the floor CSVReader.SetGridState(_grid, _slabFile); //Read JSON to create structural parts ReadStructure(_structureFile); //Start the daily progression coroutine if (_testMode) { StartCoroutine(DailyProgression()); } }
public void InitializeNonUnityData() { World.market.initialize(); World.Create(mapTexture, !readMapFormFile); //Game.updateStatus("Making grid.."); grid = new VoxelGrid(mapTexture.getWidth(), mapTexture.getHeight(), Options.cellMultiplier * mapTexture.getWidth(), mapTexture, World.GetAllProvinces()); if (!devMode) { makeHelloMessage(); } updateStatus("Finishing generation.."); }
public void Setup() { _data = new VoxelGrid(32, 1); var chunkGenerator = new ChunkGenerator(null, 32, 1); var random = new Random(0); chunkGenerator.GenerateSpheres(_data, random); chunkGenerator.SplatterHoles(_data, random); _vertices = new List <VertexPositionTextureNormal>(_data.GridSize * _data.GridSize * _data.GridSize); _indices = new List <ushort>(_data.GridSize * _data.GridSize * _data.GridSize); _imageSize = new Vector2(32, 32); }
/// <summary> /// Creates a Face /// </summary> /// <param name="x">X Index</param> /// <param name="y">Y Index</param> /// <param name="z">Z Index</param> /// <param name="direction">Direction Axis</param> /// <param name="grid">Grid to create the Face in</param> public Face(int x, int y, int z, Axis direction, VoxelGrid grid) { _grid = grid; Index = new Vector3Int(x, y, z); Direction = direction; Voxels = GetVoxels(); foreach (var v in Voxels.Where(v => v != null)) { v.Faces.Add(this); } Center = GetCenter(); }
/// <summary> /// TestManual StarBlock /// </summary> /// <returns></returns> private bool ManualJumpStart() { //_tryCounter = 0; Debug.Log("Add Start Block Attempt"); VoxelGrid.SetRandomType();//RandomPattern bool blockAdded = VoxelGrid.TryAddBlockToGrid(StartRandomIndexXZ(), RandomRotation()); if (blockAdded) { return(true); } Debug.Log("Nope :'("); return(false); }
/// <summary> /// Creates a regular voxel on a voxel grid /// </summary> /// <param name="index">The index of the Voxel</param> /// <param name="voxelgrid">The <see cref="VoxelGrid"/> this <see cref="Voxel"/> is attached to</param> /// <param name="voxelGameObject">The <see cref="GameObject"/> used on the Voxel</param> public Voxel(Vector3Int index, VoxelGrid voxelGrid, GameObject voxelGameObject) { Index = index; _voxelGrid = voxelGrid; _size = _voxelGrid.VoxelSize; _voxelGO = GameObject.Instantiate(voxelGameObject, (_voxelGrid.Origin + Index) * _size, Quaternion.identity); _voxelGO.transform.position = (_voxelGrid.Origin + Index) * _size; _voxelGO.transform.localScale *= _voxelGrid.VoxelSize; _voxelGO.name = $"Voxel_{Index.x}_{Index.y}_{Index.z}"; _voxelGO.GetComponent <MeshRenderer>().material = Resources.Load <Material>("Materials/Basic"); _voxelGO.GetComponent <VoxelTrigger>().ConnectedVoxel = this; //Status = VoxelType.Disabled; Status = VoxelType.Empty; }
public GraphVoxel(Vector3Int index, VoxelGrid voxelGrid, float state, bool createCollider = false, Transform parent = null) { //Index = index; //_voxelGrid = voxelGrid; //_size = voxelGrid.VoxelSize; //_state = state; //_PlotVoxel = GameObject.CreatePrimitive(PrimitiveType.Cube); //_PlotVoxel.transform.position = (_voxelGrid.Origin + Index) * _size; //_PlotVoxel.transform.localScale *= _voxelGrid.VoxelSize * 1; //_PlotVoxel.name = $"Voxel_{Index.x}_{Index.y}_{Index.z}"; //_PlotVoxel.GetComponent<MeshRenderer>().material = Resources.Load<Material>("Materials/Plot"); Index = index; _voxelGrid = voxelGrid; _size = _voxelGrid.VoxelSize; _state = state; IsActive = true; FColor = FunctionColor.Empty; if (createCollider) { var colliderPrefab = Resources.Load <GameObject>("Prefabs/VoxelCollider"); VoxelCollider = GameObject.Instantiate(colliderPrefab, parent, true); VoxelCollider.transform.localPosition = new Vector3(Index.x, Index.y, Index.z) * _size; VoxelCollider.name = $"{Index.x}_{Index.y}_{Index.z}"; VoxelCollider.tag = "Voxel"; } //} //public GraphVoxel(Vector3Int index, VoxelGrid voxelGrid, float state, float sizeFactor) //{ // Index = index; // _voxelGrid = voxelGrid; // _size = _voxelGrid.VoxelSize; // FColor = FunctionColor.White; // _state = state; // _voxelGO = GameObject.CreatePrimitive(PrimitiveType.Cube); // _voxelGO.transform.position = (_voxelGrid.Origin + Index) * _size; // _voxelGO.transform.localScale *= _voxelGrid.VoxelSize * sizeFactor; // _voxelGO.name = $"Voxel_{Index.x}_{Index.y}_{Index.z}"; // _voxelGO.GetComponent<MeshRenderer>().material = Resources.Load<Material>("Materials/Plot"); //} }
/// <summary> /// Translates the current state of a grid into a RenderTexture /// </summary> /// <param name="grid">The <see cref="VoxelGrid"/> to translate</param> /// <returns>The resulting <see cref="RenderTexture"/></returns> public static RenderTexture RenderTextureFromGrid64(VoxelGrid grid) { var textureFormat = TextureFormat.RGB24; Vector2Int size = new Vector2Int(grid.Size.x, grid.Size.z); Texture2D gridImage = new Texture2D(size.x, size.y, textureFormat, true, true); for (int i = 0; i < gridImage.width; i++) { for (int j = 0; j < gridImage.height; j++) { var voxel = grid.Voxels[i, 0, j]; Color c = !voxel.IsActive || voxel.IsOccupied ? Color.black : Color.white; gridImage.SetPixel(i, j, c); } } gridImage.Apply(); Texture2D resultImage = new Texture2D(64, 64); //Set all pixels to gray Color[] grayPixels = new Color[64 * 64]; var gray = Color.gray; for (int i = 0; i < grayPixels.Length; i++) { grayPixels[i] = gray; } resultImage.SetPixels(grayPixels); resultImage.Apply(); //Write grid image on result image for (int i = 0; i < gridImage.width; i++) { for (int j = 0; j < gridImage.height; j++) { int x = i; int y = resultImage.height - gridImage.height + j; resultImage.SetPixel(x, y, gridImage.GetPixel(i, j)); } } resultImage.Apply(); RenderTexture destiny = new RenderTexture(64, 64, 0); Graphics.Blit(resultImage, destiny); return(destiny); }
public static void SetGridState(VoxelGrid grid, string filename) { string file = Resources.Load <TextAsset>(filename).text; var lines = file.Split('\n').ToArray(); foreach (var line in lines) { var comps = line.Split('_').ToArray(); var x = int.Parse(comps[0]); var y = int.Parse(comps[1]); var z = int.Parse(comps[2]); var b = bool.Parse(comps[3]); grid.Voxels[x, y, z].IsActive = b; } }
public JsonVoxelGrid(VoxelGrid grid) { GridSize = grid.GridSize; //Voxels = grid.Voxels; //Voxels = new JsonVoxel[GridSize.x, GridSize.y, GridSize.z]; foreach (var voxel in grid.Voxels) { Voxels.Add(new JsonVoxel(voxel)); } //Corners = grid.Corners; //Faces = grid.Faces; //Edges = grid.Edges; Origin = grid.Origin; Corner = grid.Corner; }
public static void RefreshConnectivityInBin(Bin[] bins, int binIndex, Vector3Int binGridDimensions) { Bin bin = bins[binIndex]; Bin binRight, binLeft, binUp, binDown, binFore, binBack; VoxelGrid.TryGetBin(bin.Coords + Vector3Int.right, bins, binGridDimensions, out binRight); VoxelGrid.TryGetBin(bin.Coords + Vector3Int.left, bins, binGridDimensions, out binLeft); VoxelGrid.TryGetBin(bin.Coords + Vector3Int.up, bins, binGridDimensions, out binUp); VoxelGrid.TryGetBin(bin.Coords + Vector3Int.down, bins, binGridDimensions, out binDown); VoxelGrid.TryGetBin(bin.Coords + Vector3Int.forward, bins, binGridDimensions, out binFore); VoxelGrid.TryGetBin(bin.Coords + Vector3Int.back, bins, binGridDimensions, out binBack); bins[binIndex] = RefreshConnectivityInBin(bin, binRight, binLeft, binUp, binDown, binFore, binBack); }
public static List <PPSpace> ReadSpacesAsList(VoxelGrid grid, string file) { List <PPSpace> outList = new List <PPSpace>(); string jsonString = Resources.Load <TextAsset>(file).text; PPSpaceCollection spaceList = JsonUtility.FromJson <PPSpaceCollection>(jsonString); int count = 0; foreach (var space in spaceList.Spaces) { PPSpace s = new PPSpace(); s.OCIndexes = space.OCIndexes; outList.Add(s.NewSpace(grid, $"Space_{count++}")); } return(outList); }
private void Start() { _cam = Camera.main; _gridSize = new Vector3Int(30, 1, 24); MainGrid = new VoxelGrid(_gridSize, _voxelSize, transform.position, true, true); _boundaries = MainGrid.Boundaries; _gridGO = MainGrid.GridGO; _gridGO.transform.SetParent(transform); //Load tenants and requests data _tenants = JSONReader.ReadTenantsWithPreferences("Input Data/U_TenantPreferences 01", MainGrid); _spaceRequests = JSONReader.ReadSpaceRequests("Input Data/U_SpaceRequests", _tenants); CreateBlankConfigurables(); }
public static void FindExposedSides(ref VoxelGrid grid, VoxelTypes types, T sideProcessor) { var space = grid.VoxelSpace; for (int x = 0; x < grid.GridSize; x++) { for (int y = 0; y < grid.GridSize; y++) { for (int z = 0; z < grid.GridSize; z++) { Voxel voxel = grid[x, y, z]; if (voxel.Exists) { if (ShouldRenderSide(ref grid, ref space, types, voxel.BlockType, x, y - 1, z)) { sideProcessor.Process(x, y, z, VoxelSide.BOTTOM); } if (ShouldRenderSide(ref grid, ref space, types, voxel.BlockType, x + 1, y, z)) { sideProcessor.Process(x, y, z, VoxelSide.EAST); } if (ShouldRenderSide(ref grid, ref space, types, voxel.BlockType, x - 1, y, z)) { sideProcessor.Process(x, y, z, VoxelSide.WEST); } if (ShouldRenderSide(ref grid, ref space, types, voxel.BlockType, x, y + 1, z)) { sideProcessor.Process(x, y, z, VoxelSide.TOP); } if (ShouldRenderSide(ref grid, ref space, types, voxel.BlockType, x, y, z - 1)) { sideProcessor.Process(x, y, z, VoxelSide.NORTH); } if (ShouldRenderSide(ref grid, ref space, types, voxel.BlockType, x, y, z + 1)) { sideProcessor.Process(x, y, z, VoxelSide.SOUTH); } } } } } }
/// <summary> /// Creates a regular voxel on a voxel grid /// </summary> /// <param name="index">The index of the Voxel</param> /// <param name="voxelgrid">The <see cref="VoxelGrid"/> this <see cref="Voxel"/> is attached to</param> /// <param name="voxelGameObject">The <see cref="GameObject"/> used on the Voxel</param> public Voxel(Vector3Int index, VoxelGrid voxelGrid, bool createCollider = false, Transform parent = null) { Index = index; _voxelGrid = voxelGrid; _size = _voxelGrid.VoxelSize; IsActive = true; FColor = FunctionColor.Empty; if (createCollider) { var colliderPrefab = Resources.Load <GameObject>("Prefabs/VoxelCollider"); VoxelCollider = GameObject.Instantiate(colliderPrefab, parent, true); VoxelCollider.transform.localPosition = new Vector3(Index.x, Index.y, Index.z) * _size; VoxelCollider.name = $"{Index.x}_{Index.y}_{Index.z}"; VoxelCollider.tag = "Voxel"; } }
public static void DrawSpaceBoundary(PPSpace space, VoxelGrid grid, Color color, Vector3 origin) { var voxelSize = grid.VoxelSize; _properties.SetColor("_BaseColor", color); var boundary = space.SortedBoundaryIndexes; for (int i = 0; i < boundary.Length; i++) { Vector3 start = boundary[i]; Vector3 end; if (i + 1 >= boundary.Length) end = boundary[0]; else end = boundary[i + 1]; start = ((start + new Vector3(0.5f, 1.5f, 0.5f)) * voxelSize) + origin; end = ((end + new Vector3(0.5f, 1.5f, 0.5f)) * voxelSize) + origin; DrawBar(start, end, 0.05f, color); } }
void Start() { // Initialise the voxel grid //Vector3Int gridSize = new Vector3Int(25, 10, 25); //_voxelGrid = new VoxelGrid(gridSize, Vector3.zero, 1, parent: this.transform); //Initialise the voxel grid from image _inputImage = Resources.Load <Texture2D>("Data/map1"); _voxelGrid = new VoxelGrid(_inputImage, Vector3.zero, 1, 1, parent: this.transform); // Set the random engine's seed Random.InitState(_randomSeed); }
//05 Create GraphVoxel constructor /// <summary> /// Creates a <see cref="GraphVoxel"/> /// </summary> /// <param name="index">Index on the <see cref="VoxelGrid"/></param> /// <param name="voxelGrid">Grid the voxel is to be created at</param> /// <param name="state">Initial state the voxel should be set to</param> /// <param name="sizeFactor">Factor to scale the GameObject over the voxel size</param> public GraphVoxel(Vector3Int index, VoxelGrid voxelGrid, float state, float sizeFactor) { Index = index; _voxelGrid = voxelGrid; _size = _voxelGrid.VoxelSize; _state = state; _voxelGO = GameObject.CreatePrimitive(PrimitiveType.Cube); _voxelGO.transform.position = (_voxelGrid.Origin + Index) * _size; _voxelGO.transform.localScale *= _voxelGrid.VoxelSize * sizeFactor; _voxelGO.name = $"Voxel_{Index.x}_{Index.y}_{Index.z}"; _voxelGO.tag = "Voxel"; _voxelGO.GetComponent <MeshRenderer>().material = Resources.Load <Material>("Materials/Basic"); IsActive = true; }
/// <summary> /// Separate method to call Unity API. WOULDN'T WORK IN MULTYTHREADING! /// Called after initialization of non-Unity data /// </summary> public static void setUnityAPI() { // Assigns a material named "Assets/Resources/..." to the object. //defaultCountryBorderMaterial = Resources.Load("materials/CountryBorder", typeof(Material)) as Material; //defaultCountryBorderMaterial = GameObject.Find("CountryBorderMaterial").GetComponent<MeshRenderer>().material; ////defaultProvinceBorderMaterial = Resources.Load("materials/ProvinceBorder", typeof(Material)) as Material; //defaultProvinceBorderMaterial = GameObject.Find("ProvinceBorderMaterial").GetComponent<MeshRenderer>().material; ////selectedProvinceBorderMaterial = Resources.Load("materials/SelectedProvinceBorder", typeof(Material)) as Material; //selectedProvinceBorderMaterial = GameObject.Find("SelectedProvinceBorderMaterial").GetComponent<MeshRenderer>().material; ////impassableBorder = Resources.Load("materials/ImpassableBorder", typeof(Material)) as Material; //impassableBorder = GameObject.Find("ImpassableBorderMaterial").GetComponent<MeshRenderer>().material; //r3dTextPrefab = (GameObject)Resources.Load("prefabs/3dProvinceNameText", typeof(GameObject)); //r3DProvinceTextPrefab = GameObject.Find("3DProvinceNameText"); //r3DCountryTextPrefab = GameObject.Find("3DCountryNameText"); World.GetAllLandProvinces().PerformAction(x => x.setUnityAPI(grid.getMesh(x), grid.getBorders())); World.AllSeaProvinces().PerformAction(x => x.setUnityAPI(grid.getMesh(x), grid.getBorders())); foreach (var item in World.GetAllLandProvinces()) { var node = item.GameObject.GetComponent <Node>(); node.Set(item, item.getAllNeighbors()); World.Get.graph.AddNode(node); } World.GetAllLandProvinces().PerformAction(x => x.SetBorderMaterials()); Country.setUnityAPI(); //seaProvinces = null; // todo clear resources grid = null; mapTexture = null; // Annex all countries to P)layer //foreach (var item in World.getAllExistingCountries().Where(x => x != Game.Player)) //{ // item.annexTo(Game.Player); //} //Quaternion.Ro(90f, Vector3.right); //World.Get.transform.Rotate(Vector3.right* 90f); //World.Get.transform.rotation.SetAxisAngle(Vector3.right, 90f); //del.x = 90f; //World.Get.transform.rotation = del; }
private static bool ShouldRenderSide(VoxelGrid grid, VoxelTypes types, ushort otherType, int x, int y, int z) { var voxelIndex = new Vector3i(x, y, z); if (grid.ContainsIndex(voxelIndex)) { var voxel = grid[x, y, z]; return(!voxel.Exists || (types[voxel.BlockType].Transparent && voxel.BlockType != otherType)); } else { var spaceIndex = grid.VoxelSpace.GetSpaceIndexFromVoxelIndex(grid.MemberIndex, voxelIndex); var voxel = grid.VoxelSpace.GetVoxel(spaceIndex); return(!voxel.HasValue || !voxel.Value.Exists || (types[voxel.Value.BlockType].Transparent && voxel.Value.BlockType != otherType)); } }
public static List <StructuralPart> ReadStructureAsList(VoxelGrid grid, string file) { List <StructuralPart> outList = new List <StructuralPart>(); string jsonString = Resources.Load <TextAsset>(file).text; SPartCollection partList = JsonUtility.FromJson <SPartCollection>(jsonString); foreach (var part in partList.Parts) { StructuralPart p = new StructuralPart(); p.OCIndexes = part.OCIndexes; p.OrientationName = part.OrientationName; p.OccupiedIndexes = part.OccupiedIndexes; p.Height = part.Height; outList.Add(p.NewPart(grid)); } return(outList); }
/// <summary> /// Methods using VoxelGrid operations, /// </summary> private bool AddStartBlock() { _tryCounter = 0; Debug.Log("Add Start Block Attempt"); while (_tryCounter < _triesPerIteration) { VoxelGrid.SetRandomType();//RandomPattern //_grid.AddBlock(StartRandomIndexXZ(), RandomRotation()); bool blockAdded = VoxelGrid.TryAddBlockToGrid(StartRandomIndexXZ(), RandomRotation()); if (blockAdded) { _tryCounter++; return(true); } } Debug.Log("Nope :'("); return(false); }
public static VoxelGrid MakeGridWithVoids(IEnumerable <MeshCollider> voids, float voxelSize = 1f) { var boundingBox = new Bounds(); foreach (var v in voids.Select(v => v.bounds)) { boundingBox.Encapsulate(v); } var grid = new VoxelGrid(boundingBox, voxelSize); foreach (var voxel in grid.Voxels) { voxel.There = !voxel.VoidVoxel(voids); } return(grid); }
internal Sector( PhysicsEngine pe, VoxelWorld world, VoxelSector sector ) { this.sector = sector; content = new VoxelShape[sector.Size_x * sector.Size_y * sector.Size_z]; shape = new VoxelGridShape( content, world.VoxelBlockSize ); grid = new VoxelGrid( shape, new Vector3( sector.Pos_x * sector.Size_x * world.VoxelBlockSize , sector.Pos_y * sector.Size_y * world.VoxelBlockSize , sector.Pos_z * sector.Size_z * world.VoxelBlockSize ) ); PhysicsSpace = pe.world; }