// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using FlaxEngine;
namespace FlaxEditor.Tools.Terrain.Brushes
{
///
/// Terrain sculpture or paint brush logic descriptor.
///
[HideInEditor]
public abstract class Brush
{
///
/// The cached material instance for the brush usage.
///
protected MaterialInstance _material;
///
/// The brush size (in world units). Within this area, the brush will have at least some effect.
///
[EditorOrder(0), Limit(0.0f, 1000000.0f, 10.0f), Tooltip("The brush size (in world units). Within this area, the brush will have at least some effect.")]
public float Size = 4000.0f;
///
/// Gets the brush material for the terrain chunk rendering. It must have domain set to Terrain. Setup material parameters within this call.
///
/// The rendering context.
/// The world-space brush position.
/// The brush position.
/// The ready to render material for terrain chunks overlay on top of the terrain.
public abstract MaterialInstance GetBrushMaterial(ref RenderContext renderContext, ref Vector3 position, ref Color color);
///
/// Loads the brush material from the internal location. It's later cached by the object and reused.
///
/// The brush material path (for in-build editor brushes).
/// The brush material instance or null if cannot load or missing.
protected MaterialInstance CacheMaterial(string internalPath)
{
if (!_material)
{
var material = FlaxEngine.Content.LoadAsyncInternal(internalPath);
material.WaitForLoaded();
_material = material.CreateVirtualInstance();
}
return _material;
}
///
/// Samples the brush intensity at the specified position.
///
/// The brush center position (world-space).
/// The sample position (world-space).
/// The sampled value. Normalized to range 0-1 as an intensity to apply.
public abstract float Sample(ref Vector3 brushPosition, ref Vector3 samplePosition);
}
}