rj-action-library/Runtime/Rendering/Assets/Foliage/MeshInstanceFoliageData.cs

65 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
using System.Threading.Tasks;
namespace Rokojori
{
/** <summary for="class PackedSceneFoliageData">
<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]
public partial class MeshInstanceFoliageData:FoliageData
{
[Export]
public NodePath meshInstanceReference;
public override void Initialize( FoliageRenderLayer renderLayer )
{
var particles = renderLayer.renderer.CreateChild<GpuParticles3D>();
renderLayer.gpuParticles3D = particles;
var processMaterial = new GPUFoliageShaderMaterial();
particles.ProcessMaterial = processMaterial;
particles.Lifetime = 0.01f;
particles.Explosiveness = 1f;
particles.FixedFps = 0;
particles.Interpolate = false;
particles.FractDelta = false;
particles.CustomAabb = Box3.WithSize( 10000 );
processMaterial.positionVariance.Set( renderLayer.renderer.noise );
processMaterial.rotationVariance.Set( renderLayer.renderer.noise );
processMaterial.scaleVariance.Set( renderLayer.renderer.noise );
processMaterial.occupancyVariance.Set( renderLayer.renderer.noise );
renderLayer.gpuFoliageShaderMaterial = processMaterial;
var meshInstance = renderLayer.renderer.GetNode( meshInstanceReference ) as MeshInstance3D;
particles.DrawPasses = 1;
particles.DrawPass1 = meshInstance.Mesh;
}
}
}