namespace Sandbox.Volumes;
///
/// A base GameObjectSystem for handling of IVolume components. You can use this to find volume components
/// by position.
///
public sealed class VolumeSystem : GameObjectSystem
{
public VolumeSystem( Scene scene ) : base( scene )
{
}
///
/// Find a volume of this type, at this point. Will return null if none.
///
public T FindSingle( Vector3 position ) where T : IVolume
{
return FindAll( position ).FirstOrDefault();
}
///
/// Find all volumes of this type, at this point
///
public IEnumerable FindAll( Vector3 position ) where T : IVolume
{
// TODO - this won't scale - some kind of spacial lookup in the future
// where we get a callback when a component is enabled
// and if it's a volume, keep track of it somehow
// and then be able to find all volumes in an oct tree or some shit
foreach ( var volume in Scene.GetAll() )
{
if ( !volume.Test( position ) )
continue;
yield return volume;
}
}
public interface IVolume
{
SceneVolume GetVolume();
bool Test( Vector3 worldPosition );
bool Test( BBox worldBBox );
bool Test( Sphere worldSphere );
}
}