From 616a642a653693202e5225d237c5b0899f567d47 Mon Sep 17 00:00:00 2001 From: Josef Date: Sun, 28 Sep 2025 10:42:28 +0200 Subject: [PATCH] QuadTree/OcTree Updates --- .../Vignette/VignetteEffect.cs | 13 +++++++++- .../Compositor/RokojoriCompositorEffect.cs | 12 ++++++++- .../SingleShaderCompositorEffect.cs | 5 ++++ Runtime/Rendering/Objects/RDPushConstants.cs | 15 +++++++++++ .../Structures/Spatial/{ => Grid2D}/Grid2D.cs | 0 .../Spatial/{ => Grid2D}/Grid2D.cs.uid | 0 .../Spatial}/OcTree/OcTree.cs | 22 ++++++++-------- .../Spatial}/OcTree/OcTree.cs.uid | 0 .../Spatial}/OcTree/OcTreeCell.cs | 26 +++++++++---------- .../Spatial}/OcTree/OcTreeCell.cs.uid | 0 .../Spatial}/OcTree/OcTreeNode.cs | 2 +- .../Spatial}/OcTree/OcTreeNode.cs.uid | 0 .../Spatial}/OcTree/OcTreeWalker.cs | 20 +++++++------- .../Spatial}/OcTree/OcTreeWalker.cs.uid | 0 .../Spatial/QuadTree/QuadTreeCell.cs | 26 +++++++++---------- .../Spatial/QuadTree/QuadTreeNode.cs | 4 +-- .../Spatial/QuadTree/QuadTreeWalker.cs | 20 +++++++------- 17 files changed, 103 insertions(+), 62 deletions(-) rename Runtime/Structures/Spatial/{ => Grid2D}/Grid2D.cs (100%) rename Runtime/Structures/Spatial/{ => Grid2D}/Grid2D.cs.uid (100%) rename Runtime/{LOD/NTree => Structures/Spatial}/OcTree/OcTree.cs (92%) rename Runtime/{LOD/NTree => Structures/Spatial}/OcTree/OcTree.cs.uid (100%) rename Runtime/{LOD/NTree => Structures/Spatial}/OcTree/OcTreeCell.cs (86%) rename Runtime/{LOD/NTree => Structures/Spatial}/OcTree/OcTreeCell.cs.uid (100%) rename Runtime/{LOD/NTree => Structures/Spatial}/OcTree/OcTreeNode.cs (79%) rename Runtime/{LOD/NTree => Structures/Spatial}/OcTree/OcTreeNode.cs.uid (100%) rename Runtime/{LOD/NTree => Structures/Spatial}/OcTree/OcTreeWalker.cs (50%) rename Runtime/{LOD/NTree => Structures/Spatial}/OcTree/OcTreeWalker.cs.uid (100%) diff --git a/Runtime/Rendering/Compositor/CompositorEffects/Vignette/VignetteEffect.cs b/Runtime/Rendering/Compositor/CompositorEffects/Vignette/VignetteEffect.cs index c3e190c..ad12e61 100644 --- a/Runtime/Rendering/Compositor/CompositorEffects/Vignette/VignetteEffect.cs +++ b/Runtime/Rendering/Compositor/CompositorEffects/Vignette/VignetteEffect.cs @@ -29,6 +29,8 @@ namespace Rokojori [Export] public Color colorBottom; + [Export] + public string info = ""; protected override void OnConfigure() { @@ -46,8 +48,17 @@ namespace Rokojori offset, (Vector2) context.internalSize ); + + info = "constants: " + constants.info; + + } - + + public override void ClearCaches() + { + base.ClearCaches(); + } + protected override void RenderView() { context.AssignScreenColorTexture(); diff --git a/Runtime/Rendering/Compositor/RokojoriCompositorEffect.cs b/Runtime/Rendering/Compositor/RokojoriCompositorEffect.cs index c31407e..b265ffa 100644 --- a/Runtime/Rendering/Compositor/RokojoriCompositorEffect.cs +++ b/Runtime/Rendering/Compositor/RokojoriCompositorEffect.cs @@ -8,6 +8,9 @@ namespace Rokojori [GlobalClass] 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 string Path( string path ) { @@ -27,6 +30,11 @@ namespace Rokojori RenderingServer.CallOnRenderThread( Callable.From( _InitializeCompositorEffect ) ); } + public virtual void ClearCaches() + { + + } + protected void _InitializeCompositorEffect() { OnConfigure(); @@ -44,7 +52,8 @@ namespace Rokojori { 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; } @@ -96,6 +105,7 @@ namespace Rokojori { this.LogError( e ); _hasError = true; + context.Error( e ); } if ( context.HasError() ) diff --git a/Runtime/Rendering/Compositor/SingleShaderCompositorEffect.cs b/Runtime/Rendering/Compositor/SingleShaderCompositorEffect.cs index 78eb454..b0bedeb 100644 --- a/Runtime/Rendering/Compositor/SingleShaderCompositorEffect.cs +++ b/Runtime/Rendering/Compositor/SingleShaderCompositorEffect.cs @@ -67,6 +67,11 @@ namespace Rokojori { } + + public override void ClearCaches() + { + _constants.Clear(); + } } } \ No newline at end of file diff --git a/Runtime/Rendering/Objects/RDPushConstants.cs b/Runtime/Rendering/Objects/RDPushConstants.cs index 83b5e1f..f2c93c9 100644 --- a/Runtime/Rendering/Objects/RDPushConstants.cs +++ b/Runtime/Rendering/Objects/RDPushConstants.cs @@ -25,6 +25,21 @@ namespace Rokojori 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 ) { diff --git a/Runtime/Structures/Spatial/Grid2D.cs b/Runtime/Structures/Spatial/Grid2D/Grid2D.cs similarity index 100% rename from Runtime/Structures/Spatial/Grid2D.cs rename to Runtime/Structures/Spatial/Grid2D/Grid2D.cs diff --git a/Runtime/Structures/Spatial/Grid2D.cs.uid b/Runtime/Structures/Spatial/Grid2D/Grid2D.cs.uid similarity index 100% rename from Runtime/Structures/Spatial/Grid2D.cs.uid rename to Runtime/Structures/Spatial/Grid2D/Grid2D.cs.uid diff --git a/Runtime/LOD/NTree/OcTree/OcTree.cs b/Runtime/Structures/Spatial/OcTree/OcTree.cs similarity index 92% rename from Runtime/LOD/NTree/OcTree/OcTree.cs rename to Runtime/Structures/Spatial/OcTree/OcTree.cs index 4292239..29ff35f 100644 --- a/Runtime/LOD/NTree/OcTree/OcTree.cs +++ b/Runtime/Structures/Spatial/OcTree/OcTree.cs @@ -8,7 +8,7 @@ using System.Linq; namespace Rokojori { - public class OcTree:OcTreeNode + public class OcTree:OcTreeNode { protected Func _getPosition; protected Func,List> _combinePoints; @@ -68,8 +68,8 @@ namespace Rokojori - List> _rootCells = new List>(); - public List> rootCells => _rootCells; + List> _rootCells = new List>(); + public List> rootCells => _rootCells; public bool Insert( List data ) { @@ -221,22 +221,22 @@ namespace Rokojori } } - public MapList> GetLevelMap() + public MapList> GetLevelMap() { - var walker = new OcTreeWalker(); + var walker = new OcTreeWalker(); - var levelMap = new MapList>(); + var levelMap = new MapList>(); walker.Iterate( this, ( n )=> { - if ( n is OcTree tree ) + if ( n is OcTree tree ) { return; } - var c = n as OcTreeCell; + var c = n as OcTreeCell; levelMap.Add( c.depth, c ); } @@ -262,13 +262,13 @@ namespace Rokojori return _getPosition( data ); } - public OcTreeCell GetRootCell( Vector3 position ) + public OcTreeCell GetRootCell( Vector3 position ) { var rootIndex = PositionToRootIndex( position ); return GetRootCellByRootIndex( rootIndex ); } - public OcTreeCell GetRootCellByRootIndex( Vector3I rootCellIndex ) + public OcTreeCell GetRootCellByRootIndex( Vector3I rootCellIndex ) { var rootCellFlatIndex = MathX.MultiIndexToFlatIndex( rootCellIndex, _rootCellDimensions ); @@ -302,7 +302,7 @@ namespace Rokojori var min = rootIndex * rootCellSize3 + start; var max = min + rootCellSize3; - var cell = OcTreeCell.Create( this, min, max, _rootCells.Count ); + var cell = OcTreeCell.Create( this, min, max, _rootCells.Count ); _rootCells.Add( cell ); diff --git a/Runtime/LOD/NTree/OcTree/OcTree.cs.uid b/Runtime/Structures/Spatial/OcTree/OcTree.cs.uid similarity index 100% rename from Runtime/LOD/NTree/OcTree/OcTree.cs.uid rename to Runtime/Structures/Spatial/OcTree/OcTree.cs.uid diff --git a/Runtime/LOD/NTree/OcTree/OcTreeCell.cs b/Runtime/Structures/Spatial/OcTree/OcTreeCell.cs similarity index 86% rename from Runtime/LOD/NTree/OcTree/OcTreeCell.cs rename to Runtime/Structures/Spatial/OcTree/OcTreeCell.cs index 879e5a0..e788916 100644 --- a/Runtime/LOD/NTree/OcTree/OcTreeCell.cs +++ b/Runtime/Structures/Spatial/OcTree/OcTreeCell.cs @@ -7,16 +7,16 @@ using System; namespace Rokojori { - public class OcTreeCell:OcTreeNode + public class OcTreeCell:OcTreeNode { - OcTreeCell _parent; - public OcTreeCell parent => _parent; + OcTreeCell _parent; + public OcTreeCell parent => _parent; - OcTree _tree; - public OcTree tree => _tree; + OcTree _tree; + public OcTree tree => _tree; - List> _cells; - public List> cells => _cells; + List> _cells; + public List> cells => _cells; public int numCells => _cells == null ? 0 : cells.Count; @@ -70,9 +70,9 @@ namespace Rokojori } - public static OcTreeCell Create( OcTree tree, Vector3 min, Vector3 max, int rootIndex ) + public static OcTreeCell Create( OcTree tree, Vector3 min, Vector3 max, int rootIndex ) { - var cell = new OcTreeCell(); + var cell = new OcTreeCell(); cell._tree = tree; cell._center = (max + min ) / 2f; cell._size = ( max - min ); @@ -83,9 +83,9 @@ namespace Rokojori return cell; } - public static OcTreeCell Create( OcTreeCell parent, int depth, Vector3 min, Vector3 max ) + public static OcTreeCell Create( OcTreeCell parent, int depth, Vector3 min, Vector3 max ) { - var cell = new OcTreeCell(); + var cell = new OcTreeCell(); cell._parent = parent; cell._tree = parent.tree; cell._center = (max + min ) / 2f; @@ -207,7 +207,7 @@ namespace Rokojori _isCombined = true; } - public OcTreeCell GetChildCellFor( Vector3 position ) + public OcTreeCell GetChildCellFor( Vector3 position ) { return _cells.Find( c => c.box.ContainsPoint( position ) ); } @@ -220,7 +220,7 @@ namespace Rokojori return; } - _cells = new List>(); + _cells = new List>(); for ( int x = -1; x < 1; x ++ ) { diff --git a/Runtime/LOD/NTree/OcTree/OcTreeCell.cs.uid b/Runtime/Structures/Spatial/OcTree/OcTreeCell.cs.uid similarity index 100% rename from Runtime/LOD/NTree/OcTree/OcTreeCell.cs.uid rename to Runtime/Structures/Spatial/OcTree/OcTreeCell.cs.uid diff --git a/Runtime/LOD/NTree/OcTree/OcTreeNode.cs b/Runtime/Structures/Spatial/OcTree/OcTreeNode.cs similarity index 79% rename from Runtime/LOD/NTree/OcTree/OcTreeNode.cs rename to Runtime/Structures/Spatial/OcTree/OcTreeNode.cs index fbd7db7..9158436 100644 --- a/Runtime/LOD/NTree/OcTree/OcTreeNode.cs +++ b/Runtime/Structures/Spatial/OcTree/OcTreeNode.cs @@ -7,7 +7,7 @@ using System; namespace Rokojori { - public class OcTreeNode + public class OcTreeNode { } diff --git a/Runtime/LOD/NTree/OcTree/OcTreeNode.cs.uid b/Runtime/Structures/Spatial/OcTree/OcTreeNode.cs.uid similarity index 100% rename from Runtime/LOD/NTree/OcTree/OcTreeNode.cs.uid rename to Runtime/Structures/Spatial/OcTree/OcTreeNode.cs.uid diff --git a/Runtime/LOD/NTree/OcTree/OcTreeWalker.cs b/Runtime/Structures/Spatial/OcTree/OcTreeWalker.cs similarity index 50% rename from Runtime/LOD/NTree/OcTree/OcTreeWalker.cs rename to Runtime/Structures/Spatial/OcTree/OcTreeWalker.cs index 35a176e..6370383 100644 --- a/Runtime/LOD/NTree/OcTree/OcTreeWalker.cs +++ b/Runtime/Structures/Spatial/OcTree/OcTreeWalker.cs @@ -7,45 +7,45 @@ using System; namespace Rokojori { - public class OcTreeWalker:TreeWalker> + public class OcTreeWalker:TreeWalker> { - public override OcTreeNode Parent( OcTreeNode node ) + public override OcTreeNode Parent( OcTreeNode node ) { - if ( node is OcTree ) + if ( node is OcTree ) { return null; } - var cell = node as OcTreeCell; + var cell = node as OcTreeCell; return cell.isRoot ? cell.tree : cell.parent; } - public override int NumChildren( OcTreeNode node ) + public override int NumChildren( OcTreeNode node ) { - if ( node is OcTree tree ) + if ( node is OcTree tree ) { return tree.rootCells.Count; } - var cell = node as OcTreeCell; + var cell = node as OcTreeCell; return cell.numCells; } - public override OcTreeNode ChildAt( OcTreeNode node, int index ) + public override OcTreeNode ChildAt( OcTreeNode node, int index ) { if ( index < 0 || index >= NumChildren( node ) ) { return null; } - if ( node is OcTree tree ) + if ( node is OcTree tree ) { return tree.rootCells[ index ]; } - var cell = node as OcTreeCell; + var cell = node as OcTreeCell; return cell.cells[ index ]; } diff --git a/Runtime/LOD/NTree/OcTree/OcTreeWalker.cs.uid b/Runtime/Structures/Spatial/OcTree/OcTreeWalker.cs.uid similarity index 100% rename from Runtime/LOD/NTree/OcTree/OcTreeWalker.cs.uid rename to Runtime/Structures/Spatial/OcTree/OcTreeWalker.cs.uid diff --git a/Runtime/Structures/Spatial/QuadTree/QuadTreeCell.cs b/Runtime/Structures/Spatial/QuadTree/QuadTreeCell.cs index 131e5e3..f6e2a0a 100644 --- a/Runtime/Structures/Spatial/QuadTree/QuadTreeCell.cs +++ b/Runtime/Structures/Spatial/QuadTree/QuadTreeCell.cs @@ -7,16 +7,16 @@ using System; namespace Rokojori { - public class QuadTreeCell:QuadTreeNode + public class QuadTreeCell:QuadTreeNode { - QuadTreeCell _parent; - public QuadTreeCell parent => _parent; + QuadTreeCell _parent; + public QuadTreeCell parent => _parent; - QuadTree _tree; - public QuadTree tree => _tree; + QuadTree _tree; + public QuadTree tree => _tree; - List> _cells; - public List> cells => _cells; + List> _cells; + public List> cells => _cells; public int numCells => _cells == null ? 0 : cells.Count; @@ -70,9 +70,9 @@ namespace Rokojori } - public static QuadTreeCell Create( QuadTree tree, Vector2 min, Vector2 max, int rootIndex ) + public static QuadTreeCell Create( QuadTree tree, Vector2 min, Vector2 max, int rootIndex ) { - var cell = new QuadTreeCell(); + var cell = new QuadTreeCell(); cell._tree = tree; cell._center = (max + min ) / 2f; cell._size = ( max - min ); @@ -83,9 +83,9 @@ namespace Rokojori return cell; } - public static QuadTreeCell Create( QuadTreeCell parent, int depth, Vector2 min, Vector2 max ) + public static QuadTreeCell Create( QuadTreeCell parent, int depth, Vector2 min, Vector2 max ) { - var cell = new QuadTreeCell(); + var cell = new QuadTreeCell(); cell._parent = parent; cell._tree = parent.tree; cell._center = (max + min ) / 2f; @@ -205,7 +205,7 @@ namespace Rokojori _isCombined = true; } - public QuadTreeCell GetChildCellFor( Vector2 position ) + public QuadTreeCell GetChildCellFor( Vector2 position ) { return _cells.Find( c => c.box.ContainsPoint( position ) ); } @@ -218,7 +218,7 @@ namespace Rokojori return; } - _cells = new List>(); + _cells = new List>(); for ( int x = -1; x < 1; x ++ ) { diff --git a/Runtime/Structures/Spatial/QuadTree/QuadTreeNode.cs b/Runtime/Structures/Spatial/QuadTree/QuadTreeNode.cs index aca2323..9548654 100644 --- a/Runtime/Structures/Spatial/QuadTree/QuadTreeNode.cs +++ b/Runtime/Structures/Spatial/QuadTree/QuadTreeNode.cs @@ -7,8 +7,8 @@ using System; namespace Rokojori { - public class QuadTreeNode + public class QuadTreeNode { - + public D nodeData; } } \ No newline at end of file diff --git a/Runtime/Structures/Spatial/QuadTree/QuadTreeWalker.cs b/Runtime/Structures/Spatial/QuadTree/QuadTreeWalker.cs index ac39dfa..3e4d349 100644 --- a/Runtime/Structures/Spatial/QuadTree/QuadTreeWalker.cs +++ b/Runtime/Structures/Spatial/QuadTree/QuadTreeWalker.cs @@ -7,45 +7,45 @@ using System; namespace Rokojori { - public class QuadTreeWalker:TreeWalker> + public class QuadTreeWalker:TreeWalker> { - public override QuadTreeNode Parent( QuadTreeNode node ) + public override QuadTreeNode Parent( QuadTreeNode node ) { - if ( node is QuadTree ) + if ( node is QuadTree ) { return null; } - var cell = node as QuadTreeCell; + var cell = node as QuadTreeCell; return cell.isRoot ? cell.tree : cell.parent; } - public override int NumChildren( QuadTreeNode node ) + public override int NumChildren( QuadTreeNode node ) { - if ( node is QuadTree tree ) + if ( node is QuadTree tree ) { return tree.rootCells.Count; } - var cell = node as QuadTreeCell; + var cell = node as QuadTreeCell; return cell.numCells; } - public override QuadTreeNode ChildAt( QuadTreeNode node, int index ) + public override QuadTreeNode ChildAt( QuadTreeNode node, int index ) { if ( index < 0 || index >= NumChildren( node ) ) { return null; } - if ( node is QuadTree tree ) + if ( node is QuadTree tree ) { return tree.rootCells[ index ]; } - var cell = node as QuadTreeCell; + var cell = node as QuadTreeCell; return cell.cells[ index ]; }