QuadTree/OcTree Updates
This commit is contained in:
parent
b776f76fad
commit
616a642a65
|
@ -29,6 +29,8 @@ namespace Rokojori
|
||||||
[Export]
|
[Export]
|
||||||
public Color colorBottom;
|
public Color colorBottom;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public string info = "";
|
||||||
|
|
||||||
protected override void OnConfigure()
|
protected override void OnConfigure()
|
||||||
{
|
{
|
||||||
|
@ -46,8 +48,17 @@ namespace Rokojori
|
||||||
offset,
|
offset,
|
||||||
(Vector2) context.internalSize
|
(Vector2) context.internalSize
|
||||||
);
|
);
|
||||||
|
|
||||||
|
info = "constants: " + constants.info;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ClearCaches()
|
||||||
|
{
|
||||||
|
base.ClearCaches();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void RenderView()
|
protected override void RenderView()
|
||||||
{
|
{
|
||||||
context.AssignScreenColorTexture();
|
context.AssignScreenColorTexture();
|
||||||
|
|
|
@ -8,6 +8,9 @@ namespace Rokojori
|
||||||
[GlobalClass]
|
[GlobalClass]
|
||||||
public abstract partial class RokojoriCompositorEffect:CompositorEffect
|
public abstract partial class RokojoriCompositorEffect:CompositorEffect
|
||||||
{
|
{
|
||||||
|
[ExportToolButton( "Clear Caches" )]
|
||||||
|
public Callable clearCachesButton => Callable.From( ()=> ClearCaches() );
|
||||||
|
|
||||||
public static readonly string effectsPath = "res://addons/rokojori_action_library/Runtime/Rendering/Compositor/CompositorEffects";
|
public static readonly string effectsPath = "res://addons/rokojori_action_library/Runtime/Rendering/Compositor/CompositorEffects";
|
||||||
public static string Path( string path )
|
public static string Path( string path )
|
||||||
{
|
{
|
||||||
|
@ -27,6 +30,11 @@ namespace Rokojori
|
||||||
RenderingServer.CallOnRenderThread( Callable.From( _InitializeCompositorEffect ) );
|
RenderingServer.CallOnRenderThread( Callable.From( _InitializeCompositorEffect ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void ClearCaches()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected void _InitializeCompositorEffect()
|
protected void _InitializeCompositorEffect()
|
||||||
{
|
{
|
||||||
OnConfigure();
|
OnConfigure();
|
||||||
|
@ -44,7 +52,8 @@ namespace Rokojori
|
||||||
{
|
{
|
||||||
if ( _hasError || context.HasError() )
|
if ( _hasError || context.HasError() )
|
||||||
{
|
{
|
||||||
this.LogInfo( context.messages );
|
var errors = context.messages.Filter( m => m.type == MessageType.Error );
|
||||||
|
this.LogInfo( "_hasError", _hasError, "context.HasError()", context.HasError(), errors.Join("\n") );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +105,7 @@ namespace Rokojori
|
||||||
{
|
{
|
||||||
this.LogError( e );
|
this.LogError( e );
|
||||||
_hasError = true;
|
_hasError = true;
|
||||||
|
context.Error( e );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( context.HasError() )
|
if ( context.HasError() )
|
||||||
|
|
|
@ -67,6 +67,11 @@ namespace Rokojori
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ClearCaches()
|
||||||
|
{
|
||||||
|
_constants.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,6 +25,21 @@ namespace Rokojori
|
||||||
|
|
||||||
public int internalSize => _floats.Count + _ints.Count;
|
public int internalSize => _floats.Count + _ints.Count;
|
||||||
|
|
||||||
|
public string info
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var bytesInfo = _bytes == null ? "null" : (_bytes.Length + "" );
|
||||||
|
return $"size:{size} internalSize:{internalSize} bytes:{bytesInfo} floats:{_floats.Count} ints:{_ints.Count}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
_floats.Clear();
|
||||||
|
_ints.Clear();
|
||||||
|
_bytes = null;
|
||||||
|
}
|
||||||
|
|
||||||
public void Set( params object[] objects )
|
public void Set( params object[] objects )
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,7 +8,7 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Rokojori
|
namespace Rokojori
|
||||||
{
|
{
|
||||||
public class OcTree<T>:OcTreeNode<T>
|
public class OcTree<T,D>:OcTreeNode<T,D>
|
||||||
{
|
{
|
||||||
protected Func<T,Vector3> _getPosition;
|
protected Func<T,Vector3> _getPosition;
|
||||||
protected Func<List<T>,List<T>> _combinePoints;
|
protected Func<List<T>,List<T>> _combinePoints;
|
||||||
|
@ -68,8 +68,8 @@ namespace Rokojori
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<OcTreeCell<T>> _rootCells = new List<OcTreeCell<T>>();
|
List<OcTreeCell<T,D>> _rootCells = new List<OcTreeCell<T,D>>();
|
||||||
public List<OcTreeCell<T>> rootCells => _rootCells;
|
public List<OcTreeCell<T,D>> rootCells => _rootCells;
|
||||||
|
|
||||||
public bool Insert( List<T> data )
|
public bool Insert( List<T> data )
|
||||||
{
|
{
|
||||||
|
@ -221,22 +221,22 @@ namespace Rokojori
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapList<int,OcTreeCell<T>> GetLevelMap()
|
public MapList<int,OcTreeCell<T,D>> GetLevelMap()
|
||||||
{
|
{
|
||||||
var walker = new OcTreeWalker<T>();
|
var walker = new OcTreeWalker<T,D>();
|
||||||
|
|
||||||
var levelMap = new MapList<int,OcTreeCell<T>>();
|
var levelMap = new MapList<int,OcTreeCell<T,D>>();
|
||||||
|
|
||||||
walker.Iterate(
|
walker.Iterate(
|
||||||
this,
|
this,
|
||||||
( n )=>
|
( n )=>
|
||||||
{
|
{
|
||||||
if ( n is OcTree<T> tree )
|
if ( n is OcTree<T,D> tree )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var c = n as OcTreeCell<T>;
|
var c = n as OcTreeCell<T,D>;
|
||||||
|
|
||||||
levelMap.Add( c.depth, c );
|
levelMap.Add( c.depth, c );
|
||||||
}
|
}
|
||||||
|
@ -262,13 +262,13 @@ namespace Rokojori
|
||||||
return _getPosition( data );
|
return _getPosition( data );
|
||||||
}
|
}
|
||||||
|
|
||||||
public OcTreeCell<T> GetRootCell( Vector3 position )
|
public OcTreeCell<T,D> GetRootCell( Vector3 position )
|
||||||
{
|
{
|
||||||
var rootIndex = PositionToRootIndex( position );
|
var rootIndex = PositionToRootIndex( position );
|
||||||
return GetRootCellByRootIndex( rootIndex );
|
return GetRootCellByRootIndex( rootIndex );
|
||||||
}
|
}
|
||||||
|
|
||||||
public OcTreeCell<T> GetRootCellByRootIndex( Vector3I rootCellIndex )
|
public OcTreeCell<T,D> GetRootCellByRootIndex( Vector3I rootCellIndex )
|
||||||
{
|
{
|
||||||
var rootCellFlatIndex = MathX.MultiIndexToFlatIndex( rootCellIndex, _rootCellDimensions );
|
var rootCellFlatIndex = MathX.MultiIndexToFlatIndex( rootCellIndex, _rootCellDimensions );
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ namespace Rokojori
|
||||||
var min = rootIndex * rootCellSize3 + start;
|
var min = rootIndex * rootCellSize3 + start;
|
||||||
var max = min + rootCellSize3;
|
var max = min + rootCellSize3;
|
||||||
|
|
||||||
var cell = OcTreeCell<T>.Create( this, min, max, _rootCells.Count );
|
var cell = OcTreeCell<T,D>.Create( this, min, max, _rootCells.Count );
|
||||||
|
|
||||||
_rootCells.Add( cell );
|
_rootCells.Add( cell );
|
||||||
|
|
|
@ -7,16 +7,16 @@ using System;
|
||||||
|
|
||||||
namespace Rokojori
|
namespace Rokojori
|
||||||
{
|
{
|
||||||
public class OcTreeCell<T>:OcTreeNode<T>
|
public class OcTreeCell<T,D>:OcTreeNode<T,D>
|
||||||
{
|
{
|
||||||
OcTreeCell<T> _parent;
|
OcTreeCell<T,D> _parent;
|
||||||
public OcTreeCell<T> parent => _parent;
|
public OcTreeCell<T,D> parent => _parent;
|
||||||
|
|
||||||
OcTree<T> _tree;
|
OcTree<T,D> _tree;
|
||||||
public OcTree<T> tree => _tree;
|
public OcTree<T,D> tree => _tree;
|
||||||
|
|
||||||
List<OcTreeCell<T>> _cells;
|
List<OcTreeCell<T,D>> _cells;
|
||||||
public List<OcTreeCell<T>> cells => _cells;
|
public List<OcTreeCell<T,D>> cells => _cells;
|
||||||
|
|
||||||
|
|
||||||
public int numCells => _cells == null ? 0 : cells.Count;
|
public int numCells => _cells == null ? 0 : cells.Count;
|
||||||
|
@ -70,9 +70,9 @@ namespace Rokojori
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OcTreeCell<T> Create( OcTree<T> tree, Vector3 min, Vector3 max, int rootIndex )
|
public static OcTreeCell<T,D> Create( OcTree<T,D> tree, Vector3 min, Vector3 max, int rootIndex )
|
||||||
{
|
{
|
||||||
var cell = new OcTreeCell<T>();
|
var cell = new OcTreeCell<T,D>();
|
||||||
cell._tree = tree;
|
cell._tree = tree;
|
||||||
cell._center = (max + min ) / 2f;
|
cell._center = (max + min ) / 2f;
|
||||||
cell._size = ( max - min );
|
cell._size = ( max - min );
|
||||||
|
@ -83,9 +83,9 @@ namespace Rokojori
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OcTreeCell<T> Create( OcTreeCell<T> parent, int depth, Vector3 min, Vector3 max )
|
public static OcTreeCell<T,D> Create( OcTreeCell<T,D> parent, int depth, Vector3 min, Vector3 max )
|
||||||
{
|
{
|
||||||
var cell = new OcTreeCell<T>();
|
var cell = new OcTreeCell<T,D>();
|
||||||
cell._parent = parent;
|
cell._parent = parent;
|
||||||
cell._tree = parent.tree;
|
cell._tree = parent.tree;
|
||||||
cell._center = (max + min ) / 2f;
|
cell._center = (max + min ) / 2f;
|
||||||
|
@ -207,7 +207,7 @@ namespace Rokojori
|
||||||
_isCombined = true;
|
_isCombined = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OcTreeCell<T> GetChildCellFor( Vector3 position )
|
public OcTreeCell<T,D> GetChildCellFor( Vector3 position )
|
||||||
{
|
{
|
||||||
return _cells.Find( c => c.box.ContainsPoint( position ) );
|
return _cells.Find( c => c.box.ContainsPoint( position ) );
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ namespace Rokojori
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_cells = new List<OcTreeCell<T>>();
|
_cells = new List<OcTreeCell<T,D>>();
|
||||||
|
|
||||||
for ( int x = -1; x < 1; x ++ )
|
for ( int x = -1; x < 1; x ++ )
|
||||||
{
|
{
|
|
@ -7,7 +7,7 @@ using System;
|
||||||
|
|
||||||
namespace Rokojori
|
namespace Rokojori
|
||||||
{
|
{
|
||||||
public class OcTreeNode<T>
|
public class OcTreeNode<T,D>
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,45 +7,45 @@ using System;
|
||||||
|
|
||||||
namespace Rokojori
|
namespace Rokojori
|
||||||
{
|
{
|
||||||
public class OcTreeWalker<T>:TreeWalker<OcTreeNode<T>>
|
public class OcTreeWalker<T,D>:TreeWalker<OcTreeNode<T,D>>
|
||||||
{
|
{
|
||||||
public override OcTreeNode<T> Parent( OcTreeNode<T> node )
|
public override OcTreeNode<T,D> Parent( OcTreeNode<T,D> node )
|
||||||
{
|
{
|
||||||
if ( node is OcTree<T> )
|
if ( node is OcTree<T,D> )
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cell = node as OcTreeCell<T>;
|
var cell = node as OcTreeCell<T,D>;
|
||||||
|
|
||||||
return cell.isRoot ? cell.tree : cell.parent;
|
return cell.isRoot ? cell.tree : cell.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int NumChildren( OcTreeNode<T> node )
|
public override int NumChildren( OcTreeNode<T,D> node )
|
||||||
{
|
{
|
||||||
if ( node is OcTree<T> tree )
|
if ( node is OcTree<T,D> tree )
|
||||||
{
|
{
|
||||||
return tree.rootCells.Count;
|
return tree.rootCells.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cell = node as OcTreeCell<T>;
|
var cell = node as OcTreeCell<T,D>;
|
||||||
|
|
||||||
return cell.numCells;
|
return cell.numCells;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OcTreeNode<T> ChildAt( OcTreeNode<T> node, int index )
|
public override OcTreeNode<T,D> ChildAt( OcTreeNode<T,D> node, int index )
|
||||||
{
|
{
|
||||||
if ( index < 0 || index >= NumChildren( node ) )
|
if ( index < 0 || index >= NumChildren( node ) )
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( node is OcTree<T> tree )
|
if ( node is OcTree<T,D> tree )
|
||||||
{
|
{
|
||||||
return tree.rootCells[ index ];
|
return tree.rootCells[ index ];
|
||||||
}
|
}
|
||||||
|
|
||||||
var cell = node as OcTreeCell<T>;
|
var cell = node as OcTreeCell<T,D>;
|
||||||
|
|
||||||
return cell.cells[ index ];
|
return cell.cells[ index ];
|
||||||
}
|
}
|
|
@ -7,16 +7,16 @@ using System;
|
||||||
|
|
||||||
namespace Rokojori
|
namespace Rokojori
|
||||||
{
|
{
|
||||||
public class QuadTreeCell<T>:QuadTreeNode<T>
|
public class QuadTreeCell<T,D>:QuadTreeNode<T,D>
|
||||||
{
|
{
|
||||||
QuadTreeCell<T> _parent;
|
QuadTreeCell<T,D> _parent;
|
||||||
public QuadTreeCell<T> parent => _parent;
|
public QuadTreeCell<T,D> parent => _parent;
|
||||||
|
|
||||||
QuadTree<T> _tree;
|
QuadTree<T,D> _tree;
|
||||||
public QuadTree<T> tree => _tree;
|
public QuadTree<T,D> tree => _tree;
|
||||||
|
|
||||||
List<QuadTreeCell<T>> _cells;
|
List<QuadTreeCell<T,D>> _cells;
|
||||||
public List<QuadTreeCell<T>> cells => _cells;
|
public List<QuadTreeCell<T,D>> cells => _cells;
|
||||||
|
|
||||||
|
|
||||||
public int numCells => _cells == null ? 0 : cells.Count;
|
public int numCells => _cells == null ? 0 : cells.Count;
|
||||||
|
@ -70,9 +70,9 @@ namespace Rokojori
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static QuadTreeCell<T> Create( QuadTree<T> tree, Vector2 min, Vector2 max, int rootIndex )
|
public static QuadTreeCell<T,D> Create( QuadTree<T,D> tree, Vector2 min, Vector2 max, int rootIndex )
|
||||||
{
|
{
|
||||||
var cell = new QuadTreeCell<T>();
|
var cell = new QuadTreeCell<T,D>();
|
||||||
cell._tree = tree;
|
cell._tree = tree;
|
||||||
cell._center = (max + min ) / 2f;
|
cell._center = (max + min ) / 2f;
|
||||||
cell._size = ( max - min );
|
cell._size = ( max - min );
|
||||||
|
@ -83,9 +83,9 @@ namespace Rokojori
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static QuadTreeCell<T> Create( QuadTreeCell<T> parent, int depth, Vector2 min, Vector2 max )
|
public static QuadTreeCell<T,D> Create( QuadTreeCell<T,D> parent, int depth, Vector2 min, Vector2 max )
|
||||||
{
|
{
|
||||||
var cell = new QuadTreeCell<T>();
|
var cell = new QuadTreeCell<T,D>();
|
||||||
cell._parent = parent;
|
cell._parent = parent;
|
||||||
cell._tree = parent.tree;
|
cell._tree = parent.tree;
|
||||||
cell._center = (max + min ) / 2f;
|
cell._center = (max + min ) / 2f;
|
||||||
|
@ -205,7 +205,7 @@ namespace Rokojori
|
||||||
_isCombined = true;
|
_isCombined = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QuadTreeCell<T> GetChildCellFor( Vector2 position )
|
public QuadTreeCell<T,D> GetChildCellFor( Vector2 position )
|
||||||
{
|
{
|
||||||
return _cells.Find( c => c.box.ContainsPoint( position ) );
|
return _cells.Find( c => c.box.ContainsPoint( position ) );
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ namespace Rokojori
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_cells = new List<QuadTreeCell<T>>();
|
_cells = new List<QuadTreeCell<T,D>>();
|
||||||
|
|
||||||
for ( int x = -1; x < 1; x ++ )
|
for ( int x = -1; x < 1; x ++ )
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,8 +7,8 @@ using System;
|
||||||
|
|
||||||
namespace Rokojori
|
namespace Rokojori
|
||||||
{
|
{
|
||||||
public class QuadTreeNode<T>
|
public class QuadTreeNode<T,D>
|
||||||
{
|
{
|
||||||
|
public D nodeData;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,45 +7,45 @@ using System;
|
||||||
|
|
||||||
namespace Rokojori
|
namespace Rokojori
|
||||||
{
|
{
|
||||||
public class QuadTreeWalker<T>:TreeWalker<QuadTreeNode<T>>
|
public class QuadTreeWalker<T,D>:TreeWalker<QuadTreeNode<T,D>>
|
||||||
{
|
{
|
||||||
public override QuadTreeNode<T> Parent( QuadTreeNode<T> node )
|
public override QuadTreeNode<T,D> Parent( QuadTreeNode<T,D> node )
|
||||||
{
|
{
|
||||||
if ( node is QuadTree<T> )
|
if ( node is QuadTree<T,D> )
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cell = node as QuadTreeCell<T>;
|
var cell = node as QuadTreeCell<T,D>;
|
||||||
|
|
||||||
return cell.isRoot ? cell.tree : cell.parent;
|
return cell.isRoot ? cell.tree : cell.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int NumChildren( QuadTreeNode<T> node )
|
public override int NumChildren( QuadTreeNode<T,D> node )
|
||||||
{
|
{
|
||||||
if ( node is QuadTree<T> tree )
|
if ( node is QuadTree<T,D> tree )
|
||||||
{
|
{
|
||||||
return tree.rootCells.Count;
|
return tree.rootCells.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cell = node as QuadTreeCell<T>;
|
var cell = node as QuadTreeCell<T,D>;
|
||||||
|
|
||||||
return cell.numCells;
|
return cell.numCells;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override QuadTreeNode<T> ChildAt( QuadTreeNode<T> node, int index )
|
public override QuadTreeNode<T,D> ChildAt( QuadTreeNode<T,D> node, int index )
|
||||||
{
|
{
|
||||||
if ( index < 0 || index >= NumChildren( node ) )
|
if ( index < 0 || index >= NumChildren( node ) )
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( node is QuadTree<T> tree )
|
if ( node is QuadTree<T,D> tree )
|
||||||
{
|
{
|
||||||
return tree.rootCells[ index ];
|
return tree.rootCells[ index ];
|
||||||
}
|
}
|
||||||
|
|
||||||
var cell = node as QuadTreeCell<T>;
|
var cell = node as QuadTreeCell<T,D>;
|
||||||
|
|
||||||
return cell.cells[ index ];
|
return cell.cells[ index ];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue