rj-action-library/Runtime/Procedural/Parametric/Plane/Plane.cs

75 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using Godot;
using System;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class Plane:Node3D
{
[Export]
public float width { get => _width; set { _width = value; UpdateMesh(); } }
float _width = 200;
[Export]
public float height { get => _height; set { _height = value; UpdateMesh(); } }
float _height = 200;
[Export]
public __PlaneMeshType__ type { get => _type; set { _type = value; UpdateMesh(); } }
__PlaneMeshType__ _type;
[Export]
public Material material;
[Export]
public MeshInstance3D outputMesh;
[Export]
public bool initialized
{
get => _initialized;
set { if ( _initialized ) { return; } _initialized = true; UpdateMesh(); }
}
bool _initialized;
void UpdateMesh()
{
if ( ! _initialized )
{
return;
}
if ( _type == null )
{
return;
}
this.LogInfo( "Creating mesh" );
var mg = _type.GetMeshGeometry( width, height );
if ( outputMesh == null )
{
outputMesh = this.CreateChild<MeshInstance3D>();
}
outputMesh.Mesh = mg.GenerateMesh();
if ( material != null )
{
Materials.Set( outputMesh, material );
}
this.LogInfo( material, outputMesh, outputMesh.Mesh );
}
}
}