//Voxel methods public VoxelController GetVoxel() { //Get a voxel from pool VoxelController voxel = voxelPool.GetObject(); if (voxel != null) { voxel.GetComponent <Renderer>().sharedMaterial = currentVoxelMat; } return(voxel); }
public void SpawnVoxels(VoxelizationInfo info) { List <VoxelizationServer.AABCGrid> aABCGrids = info.aABCGrids; //int total = 0; if (aABCGrids != null) { foreach (VoxelizationServer.AABCGrid aABCGrid in aABCGrids) { Vector3 preCalc = aABCGrid.GetOrigin(); for (short x = 0; x < aABCGrid.GetWidth(); ++x) { for (short y = 0; y < aABCGrid.GetHeight(); ++y) { for (short z = 0; z < aABCGrid.GetDepth(); ++z) { if (aABCGrid.IsAABCActiveUnsafe(x, y, z)) { Vector3 cubeCenter = aABCGrid.GetAABCCenterUnsafe(x, y, z) + preCalc; voxelController = voxelPool.GetObject(); if (voxelController != null) { //++total; Transform voxelTrans = voxelController.gameObject.transform; voxelTrans.position = cubeCenter; voxelTrans.rotation = Quaternion.identity; //voxelTrans.rotation = Random.rotation; voxelTrans.localScale = info.voxelScale; if (!info.randomMaterial) { voxelController.GetComponent <Renderer>().sharedMaterial = info.mat; } else { voxelController.GetComponent <Renderer>().sharedMaterial = colorObjMng.GetVoxelRandomMaterial(); } voxelController.spawnLevels = 1; } } } } } //Set a collider in place to make voxels "explode" if (info.spawnCollider) { GameObject voxelCollider = voxelColliderPool.GetObject(); if (voxelCollider != null) { voxelCollider.transform.localScale = info.voxelColliderScale; voxelCollider.transform.position = aABCGrid.GetCenter(); } } } } //Debug.Log("Spider spawned: " + total); }