I'm creating a terrain generation script. It would be very helpful to see it in the editor so that I an adjust parameters, but currently it only displays when I run the game. I've marked the script at [Tool] but apparently this is not enough. Is there a way to make my terrain visible in the editor viewport?
using Godot;
using System;
[Tool]
public class TerrainMesh : MeshInstance
{
[Export] int randseed = 0;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
OpenSimplexNoise noise = new OpenSimplexNoise();
noise.Period = 80;
noise.Octaves = 6;
PlaneMesh planeMesh = new PlaneMesh();
planeMesh.Size = new Vector2(400, 400);
planeMesh.SubdivideWidth = 200;
planeMesh.SubdivideDepth = 200;
SurfaceTool surfTool = new SurfaceTool();
surfTool.CreateFrom(planeMesh, 0);
ArrayMesh arrayPlane = surfTool.Commit();
MeshDataTool meshDataTool = new MeshDataTool();
meshDataTool.CreateFromSurface(arrayPlane, 0);
for (int i = 0; i < meshDataTool.GetVertexCount(); ++i)
{
Vector3 v = meshDataTool.GetVertex(i);
v.y = noise.GetNoise2d(v.x, v.z) * 60;
meshDataTool.SetVertex(i, v);
}
for (int i = 0; i < arrayPlane.GetSurfaceCount(); ++i)
arrayPlane.SurfaceRemove(i);
meshDataTool.CommitToSurface(arrayPlane);
surfTool.Begin(Mesh.PrimitiveType.Triangles);
surfTool.CreateFrom(arrayPlane, 0);
surfTool.GenerateNormals();
Mesh = surfTool.Commit();
CreateTrimeshCollision();
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(float delta)
{
}
}