108 lines
2.1 KiB
C#
108 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Godot;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace Rokojori
|
|
{
|
|
/** <summary for="class FoliageRenderer">
|
|
|
|
<title>
|
|
A node to render foliage.
|
|
</title>
|
|
|
|
<description>
|
|
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.
|
|
|
|
|
|
</description>
|
|
|
|
</summary>
|
|
*/
|
|
|
|
[Tool]
|
|
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/Scatterer.svg") ]
|
|
public partial class FoliageRenderer:Node3D
|
|
{
|
|
[Export]
|
|
public FoliageData[] foliage = [];
|
|
|
|
List<FoliageRenderLayer> 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 || foliage == null || foliage.Length == 0 )
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
if ( updateLayers || foliage.Length != renderLayers.Count )
|
|
{
|
|
updateLayers = false;
|
|
this.DestroyChildren();
|
|
renderLayers = foliage.Map<FoliageData,FoliageRenderLayer>( 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 =>
|
|
{
|
|
if ( r == null )
|
|
{
|
|
return;
|
|
}
|
|
|
|
r.Update( delta );
|
|
}
|
|
);
|
|
}
|
|
|
|
}
|
|
} |