// Copyright (c) Wojciech Figat. All rights reserved. using FlaxEditor.Gizmo; using FlaxEditor.SceneGraph.Actors; using FlaxEditor.Viewport; using FlaxEditor.Viewport.Modes; using FlaxEngine; namespace FlaxEditor.Tools.Foliage { /// /// Foliage painting tool mode. /// /// public class PaintFoliageGizmoMode : EditorGizmoMode { /// /// The foliage painting gizmo. /// public PaintFoliageGizmo Gizmo; /// /// Gets the current brush. /// public readonly Brush CurrentBrush = new Brush(); /// /// The last valid cursor position of the brush (in world space). /// public Vector3 CursorPosition { get; private set; } /// /// The last valid cursor hit point normal vector of the brush (in world space). /// public Vector3 CursorNormal { get; private set; } /// /// Flag used to indicate whenever last cursor position of the brush is valid. /// public bool HasValidHit { get; private set; } /// /// Gets the selected foliage actor (see ). /// public FlaxEngine.Foliage SelectedFoliage { get { var sceneEditing = Editor.Instance.SceneEditing; var foliageNode = sceneEditing.SelectionCount == 1 ? sceneEditing.Selection[0] as FoliageNode : null; return (FlaxEngine.Foliage)foliageNode?.Actor; } } /// /// Gets the world bounds of the brush located at the current cursor position (defined by ). Valid only if is set to true. /// public BoundingBox CursorBrushBounds { get { float brushSizeHalf = CurrentBrush.Size * 0.5f; Vector3 center = CursorPosition; BoundingBox box; box.Minimum = new Vector3(center.X - brushSizeHalf, center.Y - brushSizeHalf - brushSizeHalf, center.Z - brushSizeHalf); box.Maximum = new Vector3(center.X + brushSizeHalf, center.Y + brushSizeHalf + brushSizeHalf, center.Z + brushSizeHalf); return box; } } /// public override void Init(IGizmoOwner owner) { base.Init(owner); Gizmo = new PaintFoliageGizmo(owner, this); } /// public override void OnActivated() { base.OnActivated(); Owner.Gizmos.Active = Gizmo; ClearCursor(); } /// /// Clears the cursor location information cached within the gizmo mode. /// public void ClearCursor() { HasValidHit = false; } /// /// Sets the cursor location in the world space. Updates the brush location and cached affected chunks. /// /// The cursor hit location on the selected foliage. /// The cursor hit location normal vector fot he surface. public void SetCursor(ref Vector3 hitPosition, ref Vector3 hitNormal) { HasValidHit = true; CursorPosition = hitPosition; CursorNormal = hitNormal; } } }