using System.Collections; using System.Collections.Generic; using Godot; using System; using System.Threading.Tasks; using System.Linq; namespace Rokojori { /** A node to render foliage. The GrassPatch has various settings to create a different styles of grass. It allows to change the shapes of the blades, their number and distribution, their triangle count, rotation and scale, LOD levels and much more. */ [Tool] [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/Scatterer.svg") ] public partial class FoliageRenderer:Node { [Export] public FoliageData[] foliage; List renderLayers = []; [Export] public bool processLayers = true; [Export] public bool updateLayers = true; [Export] public Camera3D camera; Camera3D _assignedCamera; [Export] public Texture2D noise; public Camera3D GetAssignedCamera() { return _assignedCamera; } public override void _Process( double delta ) { _assignedCamera = null; if ( ! processLayers ) { return; } if ( updateLayers || foliage.Length != renderLayers.Count ) { updateLayers = false; this.DestroyChildren(); renderLayers = foliage.Map( f => FoliageRenderLayer.Create( this, f ) ).ToList(); renderLayers.ForEach( r => r.data.Initialize( r ) ); } if ( Engine.IsEditorHint() ) { _assignedCamera = EditorInterface.Singleton.GetEditorViewport3D().GetCamera3D(); } else { _assignedCamera = camera; } if ( _assignedCamera == null ) { return; } // this.LogInfo( "Processing", renderLayers.Count ); renderLayers.ForEach( r => r.Update( delta ) ); } } }