69 lines
1.9 KiB
C#
69 lines
1.9 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 SceneFoliageData:FoliageData
|
|
{
|
|
[Export]
|
|
public SceneReference sceneReference;
|
|
|
|
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 packedScene = sceneReference.LoadScene();
|
|
var sceneRoot = packedScene.Instantiate();
|
|
|
|
this.LogInfo( packedScene, sceneRoot );
|
|
|
|
var meshInstance = sceneRoot.GetSelfOrChildOf<MeshInstance3D>();
|
|
particles.DrawPasses = 1;
|
|
particles.DrawPass1 = meshInstance.Mesh;
|
|
|
|
}
|
|
}
|
|
} |