44using System . Collections . Generic ;
55using System . Collections . ObjectModel ;
66using UnityEngine ;
7+ using UnityEngine . Experimental . Rendering ;
78using Verse ;
89
910namespace RW_NodeTree
1011{
1112 public class Graphic_ChildNode : Graphic
1213 {
13- public Graphic_ChildNode ( INodeProcesser proccesser , Action < RenderTexture > ? PostFX = null )
14+ public Graphic_ChildNode ( INodeProcesser proccesser , uint textureSizeFactor = RenderingTools . DefaultTextureSizeFactor , float exceedanceFactor = 1f , float exceedanceOffset = 1f , GraphicsFormat textureFormat = GraphicsFormat . R8G8B8A8_SRGB , FilterMode textureFilterMode = FilterMode . Bilinear , Action < RenderTexture > ? PostFX = null )
1415 {
1516 if ( proccesser == null ) throw new ArgumentNullException ( nameof ( proccesser ) ) ;
1617 if ( proccesser is not Thing ) throw new ArgumentException ( "Invalid processer type" , nameof ( proccesser ) ) ;
1718 currentProcesser = proccesser ;
1819 postFX = PostFX ;
20+ this . textureSizeFactor = textureSizeFactor ;
21+ this . exceedanceFactor = exceedanceFactor ;
22+ this . exceedanceOffset = exceedanceOffset ;
23+ this . textureFormat = textureFormat ;
24+ this . textureFilterMode = textureFilterMode ;
1925 //base.drawSize = _THING.DrawSize(_THING.parent.Rotation);
2026 //base.data = _GRAPHIC.data;
2127 }
@@ -48,10 +54,19 @@ public override Material MatAt(Rot4 rot, Thing? thing = null)
4854
4955 if ( needUpdate || material == null || texture == null || cachedRenderTarget == null )
5056 {
51- currentProcesser . ChildNodes . GetNodeRenderingResult ( rot , ref cachedRenderTarget , ref texture , this , postFX ) ;
57+ Dictionary < string , List < RenderInfo > > nodeRenderingInfos = currentProcesser . ChildNodes . GetNodeRenderingInfos ( rot , this ) ;
58+
59+ List < RenderInfo > final = new List < RenderInfo > ( ) ;
60+ foreach ( var infos in nodeRenderingInfos )
61+ {
62+ if ( ! infos . Value . NullOrEmpty ( ) ) final . AddRange ( infos . Value ) ;
63+ }
64+
65+ RenderingTools . RenderToTarget ( final , ref cachedRenderTarget , ref texture , textureFormat , default , textureSizeFactor , exceedanceFactor , exceedanceOffset , postFX ) ;
66+
5267 Shader shader = thing . DefaultGraphic . Shader ;
5368 texture ! . wrapMode = TextureWrapMode . Clamp ;
54- texture . filterMode = currentProcesser . TextureFilterMode ;
69+ texture . filterMode = textureFilterMode ;
5570
5671 if ( material == null )
5772 {
@@ -65,10 +80,16 @@ public override Material MatAt(Rot4 rot, Thing? thing = null)
6580 defaultRenderingCache [ rot ] = ( false , material , texture , cachedRenderTarget ) ;
6681 }
6782
68- drawSize = new Vector2 ( texture . width , texture . height ) / currentProcesser . TextureSizeFactor ;
83+ drawSize = new Vector2 ( texture . width , texture . height ) / textureSizeFactor ;
6984 return material ;
7085 }
7186
87+ public override Mesh MeshAt ( Rot4 rot )
88+ {
89+ MatAt ( rot ) ;
90+ return base . MeshAt ( rot ) ;
91+ }
92+
7293 public override void DrawWorker ( Vector3 loc , Rot4 rot , ThingDef ? thingDef , Thing ? thing , float extraRotation )
7394 {
7495 MatAt ( rot ) ;
@@ -174,8 +195,14 @@ private class OffScreenRenderingCache
174195 public RenderTexture ? cachedRenderTargetNorth , cachedRenderTargetEast , cachedRenderTargetSouth , cachedRenderTargetWest ;
175196 }
176197
177- private readonly INodeProcesser currentProcesser ;
178- private readonly Action < RenderTexture > ? postFX ;
198+
199+ public readonly uint textureSizeFactor ;
200+ public readonly float exceedanceFactor ;
201+ public readonly float exceedanceOffset ;
202+ public readonly GraphicsFormat textureFormat ;
203+ public readonly FilterMode textureFilterMode ;
204+ public readonly INodeProcesser currentProcesser ;
205+ public readonly Action < RenderTexture > ? postFX ;
179206 private readonly OffScreenRenderingCache defaultRenderingCache = new OffScreenRenderingCache ( ) ;
180207 }
181208}
0 commit comments