// TODO: We need to get rid of Handles.DrawWireCube to be able to have those at runtime as well. void OnDrawGizmos() { if (!enabled || !gameObject.activeSelf || !ProbeReferenceVolume.instance.isInitialized) { return; } var debugDisplay = ProbeReferenceVolume.instance.debugDisplay; if (debugDisplay.drawBricks) { var subdivColors = ProbeReferenceVolume.instance.subdivisionDebugColors; IEnumerable <ProbeBrickIndex.Brick> GetVisibleBricks() { if (debugDisplay.realtimeSubdivision) { // realtime subdiv cells are already culled foreach (var kp in realtimeSubdivisionInfo) { var cellVolume = kp.Key; foreach (var brick in kp.Value) { yield return(brick); } } } else { foreach (var cell in ProbeReferenceVolume.instance.cells.Values) { if (ShouldCullCell(cell.position, ProbeReferenceVolume.instance.GetTransform().posWS)) { continue; } if (cell.bricks == null) { continue; } foreach (var brick in cell.bricks) { yield return(brick); } } } } if (brickGizmos == null) { brickGizmos = new MeshGizmo((int)(Mathf.Pow(3, ProbeBrickIndex.kMaxSubdivisionLevels) * MeshGizmo.vertexCountPerCube)); } brickGizmos.Clear(); foreach (var brick in GetVisibleBricks()) { if (brick.subdivisionLevel < 0) { continue; } Vector3 scaledSize = Vector3.one * Mathf.Pow(3, brick.subdivisionLevel); Vector3 scaledPos = brick.position + scaledSize / 2; brickGizmos.AddWireCube(scaledPos, scaledSize, subdivColors[brick.subdivisionLevel]); } brickGizmos.RenderWireframe(ProbeReferenceVolume.instance.GetRefSpaceToWS(), gizmoName: "Brick Gizmo Rendering"); } if (debugDisplay.drawCells) { IEnumerable <Vector3> GetVisibleCellCenters() { if (debugDisplay.realtimeSubdivision) { foreach (var kp in realtimeSubdivisionInfo) { kp.Key.CalculateCenterAndSize(out var center, out var _); yield return(center); } } else { foreach (var cell in ProbeReferenceVolume.instance.cells.Values) { if (ShouldCullCell(cell.position, ProbeReferenceVolume.instance.GetTransform().posWS)) { continue; } var positionF = new Vector3(cell.position.x, cell.position.y, cell.position.z); var center = positionF * m_Profile.cellSizeInMeters + m_Profile.cellSizeInMeters * 0.5f * Vector3.one; yield return(center); } } } Matrix4x4 trs = Matrix4x4.TRS(ProbeReferenceVolume.instance.GetTransform().posWS, ProbeReferenceVolume.instance.GetTransform().rot, Vector3.one); // For realtime subdivision, the matrix from ProbeReferenceVolume.instance can be wrong if the profile changed since the last bake if (debugDisplay.realtimeSubdivision) { trs = Matrix4x4.TRS(transform.position, Quaternion.identity, Vector3.one); } // Fetching this from components instead of from the reference volume allows the user to // preview how cells will look before they commit to a bake. Gizmos.color = new Color(0, 1, 0.5f, 0.2f); Gizmos.matrix = trs; if (cellGizmo == null) { cellGizmo = new MeshGizmo(); } cellGizmo.Clear(); foreach (var center in GetVisibleCellCenters()) { Gizmos.DrawCube(center, Vector3.one * m_Profile.cellSizeInMeters); cellGizmo.AddWireCube(center, Vector3.one * m_Profile.cellSizeInMeters, new Color(0, 1, 0.5f, 1)); } cellGizmo.RenderWireframe(Gizmos.matrix, gizmoName: "Brick Gizmo Rendering"); } }
// TODO: We need to get rid of Handles.DrawWireCube to be able to have those at runtime as well. void OnDrawGizmos() { if (!enabled || !gameObject.activeSelf || !ProbeReferenceVolume.instance.isInitialized) { return; } var debugDisplay = ProbeReferenceVolume.instance.debugDisplay; if (debugDisplay.drawBricks) { var subdivColors = ProbeReferenceVolume.instance.subdivisionDebugColors; foreach (var cell in ProbeReferenceVolume.instance.cells.Values) { if (ShouldCullCell(cell.position, ProbeReferenceVolume.instance.GetTransform().posWS)) { continue; } if (cell.bricks == null) { continue; } if (!brickGizmos.TryGetValue(cell, out var meshGizmo)) { meshGizmo = AddBrickGizmo(cell); } meshGizmo.RenderWireframe(ProbeReferenceVolume.instance.GetRefSpaceToWS(), gizmoName: "Brick Gizmo Rendering"); MeshGizmo AddBrickGizmo(ProbeReferenceVolume.Cell cell) { var meshGizmo = new MeshGizmo((int)(Mathf.Pow(3, ProbeBrickIndex.kMaxSubdivisionLevels) * MeshGizmo.vertexCountPerCube)); meshGizmo.Clear(); foreach (var brick in cell.bricks) { Vector3 scaledSize = Vector3.one * Mathf.Pow(3, brick.subdivisionLevel); Vector3 scaledPos = brick.position + scaledSize / 2; meshGizmo.AddWireCube(scaledPos, scaledSize, subdivColors[brick.subdivisionLevel]); } brickGizmos[cell] = meshGizmo; return(meshGizmo); } } } if (debugDisplay.drawCells) { // Fetching this from components instead of from the reference volume allows the user to // preview how cells will look before they commit to a bake. Gizmos.color = new Color(0, 1, 0.5f, 0.2f); Gizmos.matrix = Matrix4x4.TRS(ProbeReferenceVolume.instance.GetTransform().posWS, ProbeReferenceVolume.instance.GetTransform().rot, Vector3.one); if (cellGizmo == null) { cellGizmo = new MeshGizmo(); } cellGizmo.Clear(); foreach (var cell in ProbeReferenceVolume.instance.cells.Values) { if (ShouldCullCell(cell.position, transform.position)) { continue; } var positionF = new Vector3(cell.position.x, cell.position.y, cell.position.z); var center = positionF * m_Profile.cellSize + m_Profile.cellSize * 0.5f * Vector3.one; Gizmos.DrawCube(center, Vector3.one * m_Profile.cellSize); cellGizmo.AddWireCube(center, Vector3.one * m_Profile.cellSize, new Color(0, 1, 0.5f, 1)); } cellGizmo.RenderWireframe(Gizmos.matrix, gizmoName: "Brick Gizmo Rendering"); } }