1
This commit is contained in:
63
BITKit/Scripts/CSG/CSGBoxSubdivision.cs
Normal file
63
BITKit/Scripts/CSG/CSGBoxSubdivision.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using BITKit;
|
||||
|
||||
namespace BITFactory.CSG
|
||||
{
|
||||
[Tool]
|
||||
public partial class CSGBoxSubdivision : Node3D
|
||||
{
|
||||
[Export]
|
||||
private Vector3 Size
|
||||
{
|
||||
get => _size;
|
||||
set
|
||||
{
|
||||
_size = value;
|
||||
Rebuild();
|
||||
}
|
||||
}
|
||||
[Export]
|
||||
public int Level
|
||||
{
|
||||
get => _level;
|
||||
set
|
||||
{
|
||||
Rebuild();
|
||||
_level = value;
|
||||
}
|
||||
}
|
||||
private int _level;
|
||||
private Vector3 _size;
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
private void Rebuild()
|
||||
{
|
||||
foreach (var child in GetChildren())
|
||||
{
|
||||
if (child is CsgBox3D box)
|
||||
{
|
||||
box.QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
var smallBoxSize = _size / _level;
|
||||
for (var x = 0; x < _level; x++)
|
||||
{
|
||||
for (var y = 0; y < _level; y++)
|
||||
{
|
||||
var box = new CsgBox3D();
|
||||
AddChild(box);
|
||||
box.Size = smallBoxSize;
|
||||
box.Position = new Vector3(x * smallBoxSize.X, y * smallBoxSize.Y, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user