void Start() { playerEdit.SetActive(true); playerPlay.SetActive(false); _light.enabled = true; aimHelper.gameObject.SetActive(false); txtError.text = ""; txtHelp.text = "Click to create procedural level"; _iCount = 0; _aVoxelChunks = new List <VoxelUtils.VoxelChunk> (); // create the full chunk voxel VoxelUtils.VoxelVector3Int pos = VoxelUtils.convertVector3ToVoxelVector3Int(Vector3.zero); VoxelUtils.VoxelChunk vs = createVoxelChunk(pos, VoxelUtils.MAX_CHUNK_UNITS, VoxelUtils.MAX_CHUNK_UNITS, VoxelUtils.MAX_CHUNK_UNITS); _aVoxelChunks.Add(vs); setVoxelChunkMesh(_aVoxelChunks [0]); txtCount.text = _aVoxelChunks.Count.ToString() + " Voxel Chunk" + (_aVoxelChunks.Count > 1 ? "s" : ""); aimHelper.localScale = new Vector3(_curDigSize.x * VoxelUtils.CHUNK_SIZE * 1.01f, _curDigSize.y * VoxelUtils.CHUNK_SIZE * 1.01f, _curDigSize.z * VoxelUtils.CHUNK_SIZE * 1.01f); }
// --------------------------------------------------------------------------------------------- // Update shit // --------------------------------------------------------------------------------------------- void Update() { if (Input.GetMouseButtonDown(0)) { if (EventSystem.current.IsPointerOverGameObject()) { return; } if (!subtracted) { // cut out center section and separate voxels VoxelUtils.VoxelVector3Int pos = VoxelUtils.convertVector3ToVoxelVector3Int(cutHolesPos[cutHolesIndex]); vsSubtract = createCutGameObject(pos, (int)cutHolesSize[cutHolesIndex].x, (int)cutHolesSize[cutHolesIndex].y, (int)cutHolesSize[cutHolesIndex].z); subtracted = true; stillSplitting = true; txtHelp.text = "Click to split " + (_aVoxelChunks.Count > 1 ? "voxels" : "voxel") + " into smaller chunks..."; } else if (stillSplitting) { if (!subtractChunk(vsSubtract)) { txtHelp.text = ":("; stillSplitting = false; } else { if (++cutHolesIndex < cutHolesPos.Count) { txtHelp.text = "Click to place another chunk..."; subtracted = false; } else { txtHelp.text = "All done here!"; txtError.text = ""; } } Destroy(vsSubtract.go); vsSubtract.go = null; /*stillSplitting = splitVoxels (vsSubtract); * if (!stillSplitting) { * Destroy (vsSubtract.go); * vsSubtract.go = null; * * if (++cutHolesIndex < cutHolesPos.Count) { * txtHelp.text = "Click to cut another hole..."; * subtracted = false; * } else { * txtHelp.text = "No more holes to cut!"; * } * }*/ } txtCount.text = _aVoxelChunks.Count.ToString() + " Voxel Chunk" + (_aVoxelChunks.Count > 1 ? "s" : ""); } }
void Start() { _iCount = 0; _aVoxelChunks = new List <VoxelUtils.VoxelChunk> (); // create the full chunk voxel VoxelUtils.VoxelVector3Int pos = VoxelUtils.convertVector3ToVoxelVector3Int(Vector3.zero); VoxelUtils.VoxelChunk vs = createVoxelChunk(pos, VoxelUtils.MAX_CHUNK_UNITS, VoxelUtils.MAX_CHUNK_UNITS, VoxelUtils.MAX_CHUNK_UNITS); _aVoxelChunks.Add(vs); onMouseClick(); txtError.text = ""; }
void Start() { _iCount = 0; _aVoxelChunks = new List <VoxelUtils.VoxelChunk> (); // create the full chunk voxel VoxelUtils.VoxelVector3Int pos = VoxelUtils.convertVector3ToVoxelVector3Int(Vector3.zero); VoxelUtils.VoxelChunk vs = createVoxelChunk(pos, VoxelUtils.MAX_CHUNK_UNITS, VoxelUtils.MAX_CHUNK_UNITS, VoxelUtils.MAX_CHUNK_UNITS); _aVoxelChunks.Add(vs); txtHelp.text = "Click to place a chunk..."; txtCount.text = _aVoxelChunks.Count.ToString() + " Voxel Chunk" + (_aVoxelChunks.Count > 1 ? "s" : ""); txtError.text = ""; }
void Start() { txtError.text = ""; txtHelp.text = "Click anywhere to dig a 0.5m cube - Press 'P' to polygonize level!"; _iCount = 0; _aVoxelChunks = new List <VoxelUtils.VoxelChunk> (); // create the full chunk voxel VoxelUtils.VoxelVector3Int pos = VoxelUtils.convertVector3ToVoxelVector3Int(Vector3.zero); VoxelUtils.VoxelChunk vs = createVoxelChunk(pos, VoxelUtils.MAX_CHUNK_UNITS, VoxelUtils.MAX_CHUNK_UNITS, VoxelUtils.MAX_CHUNK_UNITS); _aVoxelChunks.Add(vs); subtractChunk(new Vector3(30, 30, 30), new Vector3(12, 12, 12)); aimHelper.localScale = new Vector3(_curDigSize.x * VoxelUtils.CHUNK_SIZE * 1.01f, _curDigSize.y * VoxelUtils.CHUNK_SIZE * 1.01f, _curDigSize.z * VoxelUtils.CHUNK_SIZE * 1.01f); }
// --------------------------------------------------------------------------------------------- // cut a hole! // --------------------------------------------------------------------------------------------- private bool subtractChunk(Vector3 v3Pos, Vector3 v3Size) { bool success = true; float timer = Time.realtimeSinceStartup; VoxelUtils.VoxelVector3Int pos = VoxelUtils.convertVector3ToVoxelVector3Int(v3Pos); VoxelUtils.VoxelChunk vsCut = createCutVoxelChunk(pos, (int)v3Size.x, (int)v3Size.y, (int)v3Size.z); // does the new voxel intersect with any existing voxels? bool splittage = splitVoxels(vsCut); int loops = 0; while (splittage && loops < 1000) { splittage = splitVoxels(vsCut); loops++; } if (loops >= 1000) { Debug.LogWarning("looks like we got ourselves an endless loop here!"); txtError.text = "Looks like we got ourselves an endless loop here!"; success = false; } else { int i, len = _aVoxelChunks.Count; for (i = 0; i < len; ++i) { setVoxelChunkMesh(_aVoxelChunks [i]); } } Debug.Log("Time to create chunk(s): " + (Time.realtimeSinceStartup - timer).ToString()); txtCount.text = _aVoxelChunks.Count.ToString() + " Voxel Chunk" + (_aVoxelChunks.Count > 1 ? "s" : ""); return(success); }
// --------------------------------------------------------------------------------------------- private void onMouseClick() { float timer = Time.realtimeSinceStartup; if (cutHolesIndex >= cutHolesPos.Count) { return; } VoxelUtils.VoxelVector3Int pos = VoxelUtils.convertVector3ToVoxelVector3Int(cutHolesPos[cutHolesIndex]); vsSubtract = createCutGameObject(pos, (int)cutHolesSize[cutHolesIndex].x, (int)cutHolesSize[cutHolesIndex].y, (int)cutHolesSize[cutHolesIndex].z); if (!subtractChunk(vsSubtract)) { txtHelp.text = ":("; } else { if (++cutHolesIndex < cutHolesPos.Count) { txtHelp.text = "Click to continue..."; } else { txtHelp.text = "All done here!"; txtError.text = ""; } } //Destroy (vsSubtract.go); //vsSubtract.go = null; Debug.Log("time to create chunks: " + (Time.realtimeSinceStartup - timer).ToString()); txtCount.text = _aVoxelChunks.Count.ToString() + " Voxel Chunk" + (_aVoxelChunks.Count > 1 ? "s" : ""); }