protected override void PreviewInSceneInternal(WorldStampCreator parent) { var bounds = parent.Template.Bounds; int counter = 0; int res = 32; foreach (var kvp in SplatData) { int xStep = kvp.Data.Width / res; int zStep = kvp.Data.Height / res; Vector2 cellSize = new Vector2((xStep / (float)kvp.Data.Width) * bounds.size.x, (zStep / (float)kvp.Data.Height) * bounds.size.z); for (var u = 0; u < kvp.Data.Width; u += xStep) { var fU = u / (float)kvp.Data.Width; var wU = bounds.min.x + fU * bounds.size.x; for (var v = 0; v < kvp.Data.Height; v += zStep) { var fV = v / (float)kvp.Data.Height; var wV = bounds.min.z + fV * bounds.size.z; var val = kvp.Data[u, v] / 255f; HandleExtensions.DrawXZCell(new Vector3(wU, counter, wV), cellSize, Quaternion.identity, ColorUtils.GetIndexColor(counter).WithAlpha(val)); } } counter++; } }
private void OnSceneGUI() { // save position in local space DashedCurve.CurveType t = (DashedCurve.CurveType)type.enumValueIndex; switch (t) { case DashedCurve.CurveType.Quadratic: start.vector3Value = ShowPoint(start.vector3Value); handle1.vector3Value = ShowPoint(handle1.vector3Value); handle2.vector3Value = handle1.vector3Value; end.vector3Value = ShowPoint(end.vector3Value); break; case DashedCurve.CurveType.Cubic: start.vector3Value = ShowPoint(start.vector3Value); handle1.vector3Value = ShowPoint(handle1.vector3Value); handle2.vector3Value = ShowPoint(handle2.vector3Value); end.vector3Value = ShowPoint(end.vector3Value); break; } serializedObject.ApplyModifiedProperties(); // draw in world space Handles.color = Color.gray; Handles.DrawAAPolyLine(3, transform.TransformPoint(start.vector3Value), transform.TransformPoint(handle1.vector3Value)); Handles.DrawAAPolyLine(3, transform.TransformPoint(end.vector3Value), transform.TransformPoint(handle2.vector3Value)); switch (t) { case DashedCurve.CurveType.Quadratic: HandleExtensions.DrawBezier2(transform.TransformPoint(start.vector3Value), transform.TransformPoint(end.vector3Value), transform.TransformPoint(handle1.vector3Value), Color.cyan, null, 5); break; case DashedCurve.CurveType.Cubic: Handles.DrawBezier( transform.TransformPoint(start.vector3Value), transform.TransformPoint(end.vector3Value), transform.TransformPoint(handle1.vector3Value), transform.TransformPoint(handle2.vector3Value), Color.cyan, null, 5); break; } }
protected override void OnSceneGUI(SceneView sceneView) { if (Template.Terrain == null) { return; } if (!BoundsLocked && DoSetArea()) { foreach (var worldStampCreatorLayer in Template.Creators) { worldStampCreatorLayer.NeedsRecapture = true; } } if (!Template.Creators.Contains(SceneGUIOwner)) { SceneGUIOwner = null; } if (SceneGUIOwner != null) { SceneGUIOwner.PreviewInScene(this); } var heightmap = GetCreator <HeightmapDataCreator>(); if (heightmap != null && heightmap.Enabled) { HandleExtensions.DrawWireCube(Template.Bounds.center.xz().x0z(Template.Bounds.min.y + heightmap.ZeroLevel * Template.Bounds.size.y), Template.Bounds.size.xz().x0z() / 2, Quaternion.identity, Color.cyan); } Handles.color = Color.white; Handles.DrawWireCube(Template.Bounds.center, Template.Bounds.size); Handles.color = Color.white.WithAlpha(.5f); Handles.DrawWireCube(Template.Terrain.GetPosition() + Template.Terrain.terrainData.size / 2, Template.Terrain.terrainData.size); }
private void UpdateVisualisation() { if (Canvas == null) { Debug.LogWarning("Trying to draw Painter with null Canvas?"); return; } DrawSceneControls(); for (var i = 0; i < 5; ++i) { var scale = TRS.GetScale(); scale = new Vector3(scale.x * Rect.size.x, 0, scale.z * Rect.size.y); var rectPos = TRS.MultiplyPoint(Rect.min.x0z(PlaneOffset) + Vector3.up * i + Rect.size.x0z() / 2); HandleExtensions.DrawWireCube(rectPos, scale / 2, TRS.GetRotation(), Color.cyan.WithAlpha(1 - i / 5f)); } Handles.color = Color.white; if (CurrentBrush != null) { CurrentBrush.DrawGizmos(GridManager, _currentInputState, Rect, TRS); } var cellColor = Color.white; if (!_currentInputState.MouseBlocked && DoSceneGUIForHoverCell != null) { DoSceneGUIForHoverCell(GridManager.GetCell(_currentInputState.GridPosition)); } Handles.color = Color.magenta.WithAlpha(.2f); Handles.DrawDottedLine(_currentInputState.PlanePosition, _currentInputState.GridPosition, 1); _repaint |= Canvas.Dirty; EditorCellHelper.SetAlive(); // Tell the cell renderer that it should keep rendering EditorCellHelper.CellSize = GridManager.GetGridSize(); EditorCellHelper.TRS = TRS; if (_repaint) { EditorCellHelper.Clear(false); lock (Canvas) { Canvas.Dirty = false; var enumerator = Canvas.AllValues(); while (enumerator.MoveNext()) { cellColor = Ramp.Evaluate((enumerator.Current.Value - MinValue) / MaxValue); cellColor = cellColor.WithAlpha(cellColor.a * Opacity); if (TransmuteCellColor != null) { cellColor = TransmuteCellColor(enumerator.Current.Key, cellColor); } var cellPos = GridManager.GetCellCenter(enumerator.Current.Key).x0z(PlaneOffset); EditorCellHelper.AddCell(cellPos, cellColor); } } EditorCellHelper.Invalidate(); _repaint = false; } }