void PointEdit() { RaycastHit hit; if (Physics.Raycast(cameraTransform.position, cameraTransform.forward, out hit, 5)) { Chunk chunk = world.GetChunk(hit.point); HexCoord hexUnrounded = chunk.PosToHex(hit.point); HexCell hexCenter = hexUnrounded.ToHexCell(); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { for (int k = -1; k <= 1; k++) { HexCell hex = new HexCell(hexCenter.x + i, hexCenter.y + j, hexCenter.z + k); Vector3 point = chunk.HexToPos(hex); Vector3 c = 2 * point - hexUnrounded.ToVector3(); float distanceStrength = 10 / (Mathf.Pow(c.x, 2) + Mathf.Pow(c.y, 2) + Mathf.Pow(c.z, 2)); Vector3 changeNormal = 10 * new Vector3(-2 * c.x / (Mathf.Pow(Mathf.Pow(c.x, 2) + Mathf.Pow(c.y, 2) + Mathf.Pow(c.z, 2), 2)), -2 * c.y / (Mathf.Pow(Mathf.Pow(c.x, 2) + Mathf.Pow(c.y, 2) + Mathf.Pow(c.z, 2), 2)), -2 * c.z / (Mathf.Pow(Mathf.Pow(c.x, 2) + Mathf.Pow(c.y, 2) + Mathf.Pow(c.z, 2), 2))); chunk.EditPointValue(hex, distanceStrength); chunk.EditPointNormal(hex, changeNormal); gameObject.GetComponent <LoadChunks>().AddToUpdateList(chunk.chunkCoords); } } } } }
float GetNoise(HexCoord coord) { HexCell cell = coord.ToHexCell(); try { return(world.GetNoise(HexToWorldHex(coord)) + editedValues[cell.x, cell.y, cell.z]); } catch { return(world.GetNoise(HexToWorldHex(coord))); } }
Vector3 GetNormal(HexCoord coord) { HexCell cell = coord.ToHexCell(); try { return(world.GetNormal(HexToWorldHex(coord)) + editedNormals[cell.x, cell.y, cell.z]); } catch { return(world.GetNormal(HexToWorldHex(coord))); } }
/// <summary> /// Method called when object is selected /// </summary> void OnDrawGizmosSelected() { for (int i = 0; i < chunkSize; i++) { for (int j = 0; j < chunkSize; j++) { for (int k = 0; k < chunkSize - 1; k++) { if (vertexes[i, j, k]) { HexCoord vert = new HexCoord((byte)i, (byte)j, (byte)k); Gizmos.color = Color.gray; Gizmos.DrawSphere(HexToPos(vert.ToHexCell()), .2f); if (world.showNormals) { Vector3 dir = GetNormal(vert); Gizmos.color = Color.yellow; Gizmos.DrawRay(HexToPos(vert.ToHexCell()), dir); } } } } } }