shmodot/scripts/Railway.cs

54 lines
1.2 KiB
C#
Raw Normal View History

2022-08-04 22:20:29 +02:00
using Godot;
using System;
[Tool]
public class Railway : Path
{
[Export]
private Color _color;
[Export]
private float _gauge = 1f;
private ImmediateGeometry _geo = null;
private Vector3[] _points = null;
public void OnPathCurveChanged()
{
Curve.Tessellate();
_points = Curve.GetBakedPoints();
}
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
base._Ready();
_geo = GetNode<ImmediateGeometry>("ImmediateGeometry");
var m = new SpatialMaterial();
m.VertexColorUseAsAlbedo = true;
m.FlagsUnshaded = true;
_geo.MaterialOverride = m;
OnPathCurveChanged();
}
public override void _Process(float delta)
{
base._Process(delta);
if (_geo == null) return;
if (_points == null || _points.Length == 0) return;
_geo.Clear();
_geo.Begin(Mesh.PrimitiveType.LineStrip);
_geo.SetColor(new Color(1, 0, 0));
for(int i = 0; i < _points.Length; i++)
{
_geo.AddVertex(_points[i]);
}
_geo.End();
}
}