Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .github/workflows/ci-linux-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,6 @@ jobs:
bash ./tools/ci/clang_tidy.sh build
"

dotnet-reflection-generator:
name: Dotnet reflection_generator (${{ matrix.build_type }})
runs-on: [self-hosted, Linux, X64]
strategy:
matrix:
build_type: [Debug, Release]
fail-fast: false
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
fetch-depth: 1
submodules: true

- name: Install Nix
uses: cachix/install-nix-action@v31.10.6

- name: Dotnet build and test
run: nix develop --command bash -c 'dotnet build tools/reflection_generator/reflection_generator.csproj --configuration ${{ matrix.build_type }} && dotnet test tools/reflection_generator/tests/ReflectionGenerator.Tests --configuration ${{ matrix.build_type }}'

dotnet-editor:
name: Dotnet editor (${{ matrix.build_type }})
runs-on: [self-hosted, Linux, X64]
Expand Down
6 changes: 3 additions & 3 deletions editor/VoxelEditor/VoxelEditorActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ private static async Task BakeAsync(HierarchyElement node) {
// Every volume gets a model
void Walk(HierarchyElement parent) {
foreach (var child in parent.Children) {
if (child.Type is "toast::FillVolume" or "toast::VoxelMesh") {
if (child.Type is "toast::FillVolume" or "toast::VoxelMesh" or "toast::VoxelLine") {
var path = $"{folder}/{UniqueFileName(child.Name, taken)}.tvox";
CreateVoxelFile(path);
bake.Pieces.Add(new VoxelBakePiece { Uid = child.Uid, Path = path });
}
if (child.Type is "toast::VoxelGroup" or "toast::FillVolume" or "toast::VoxelMesh" or "toast::CarveVolume"
or "toast::PaintVolume") {
if (child.Type is "toast::VoxelGroup" or "toast::FillVolume" or "toast::VoxelMesh" or "toast::VoxelLine"
or "toast::CarveVolume" or "toast::PaintVolume") {
Walk(child);
}
}
Expand Down
19 changes: 17 additions & 2 deletions editor/VoxelEditor/VoxelEditorView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,21 @@
<LucideIcon Kind="Scissors" Size="16" StrokeWidth="2.5" />
</ToggleButton>
<ToggleButton Classes="tool orange compact-control compact-icon"
CornerRadius="0,6,6,0"
CornerRadius="0"
ToolTip.Tip="Slice (Shift+Y)"
Command="{Binding SetToolCommand}"
CommandParameter="Slice"
IsChecked="{Binding ActiveTool, Converter={StaticResource EnumEqualsConverter}, ConverterParameter=Slice, Mode=OneWay}">
<LucideIcon Kind="Slice" Size="16" StrokeWidth="2.5" />
</ToggleButton>
<ToggleButton Classes="tool green compact-control compact-icon"
CornerRadius="0,6,6,0"
ToolTip.Tip="Line: drag along X or Y to repeat the model (U)"
Command="{Binding SetToolCommand}"
CommandParameter="Line"
IsChecked="{Binding ActiveTool, Converter={StaticResource EnumEqualsConverter}, ConverterParameter=Line, Mode=OneWay}">
<LucideIcon Kind="BrickWall" Size="16" StrokeWidth="2.5" />
</ToggleButton>
</StackPanel>

<StackPanel Grid.Column="1"
Expand Down Expand Up @@ -228,12 +236,19 @@
<elements:AssetBox AssetType="Script"
Width="200"
Value="{Binding DefaultScript, Mode=TwoWay}" Classes="compact-field" />
<LucideIcon Kind="BrickWall" Size="16" StrokeWidth="2.5"
Foreground="{StaticResource TextMuted}"
VerticalAlignment="Center" />
<elements:AssetBox AssetType="voxel_model"
Width="200"
ToolTip.Tip="Model the Line tool repeats"
Value="{Binding DefaultModel, Mode=TwoWay}" Classes="compact-field" />
</StackPanel>

<StackPanel Grid.Column="7"
Orientation="Horizontal"
Spacing="4"
ToolTip.Tip="Fill mode new volumes get">
ToolTip.Tip="Fill mode new fills and lines get">
<LucideIcon Kind="Blend" Size="16" StrokeWidth="2.5"
Foreground="{StaticResource TextMuted}"
VerticalAlignment="Center" />
Expand Down
1 change: 1 addition & 0 deletions editor/VoxelEditor/VoxelEditorView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private void OnShortcut(object? sender, KeyEventArgs e) {
case Key.T when mods == KeyModifiers.Shift: vm.SetToolCommand.Execute("Bucket"); break;
case Key.Y when mods == KeyModifiers.None: vm.SetToolCommand.Execute("Split"); break;
case Key.Y when mods == KeyModifiers.Shift: vm.SetToolCommand.Execute("Slice"); break;
case Key.U when mods == KeyModifiers.None: vm.SetToolCommand.Execute("Line"); break;
case Key.G when mods == KeyModifiers.None: vm.ShowUnitGrid = !vm.ShowUnitGrid; break;
case Key.G when mods == KeyModifiers.Shift: vm.ShowVoxelGrid = !vm.ShowVoxelGrid; break;
case Key.G when mods == KeyModifiers.Alt: vm.ShowVoxelEdges = !vm.ShowVoxelEdges; break;
Expand Down
31 changes: 27 additions & 4 deletions editor/VoxelEditor/VoxelEditorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace editor.VoxelEditor;

public enum VoxelTool { Select, Move, Extrude, Buildup, Carve, Paint, Bucket, Split, Slice }
public enum VoxelTool { Select, Move, Extrude, Buildup, Carve, Paint, Bucket, Split, Slice, Line }

public enum VoxelViewMode { Lit, Albedo, MetallicRoughness, PaletteId, PhysicsMaterial, DdaSteps, Volumes }

Expand Down Expand Up @@ -72,6 +72,7 @@ public partial class VoxelEditorViewModel : ObservableObject, IDisposable {
[ObservableProperty] private bool m_snapToUnit;
[ObservableProperty] private int m_paletteId = 1;
[ObservableProperty] private string? m_defaultScript;
[ObservableProperty] private string? m_defaultModel;
[ObservableProperty] private string m_defaultFillModeName = "Replace";
public static IReadOnlyList<string> FillModes { get; } = ["Replace", "Empty Only", "Solid Only", "Match"];
private uint DefaultFillMode => (uint)Math.Max(0, FillModes.ToList().IndexOf(DefaultFillModeName));
Expand Down Expand Up @@ -138,6 +139,10 @@ public VoxelEditorViewModel(
new InspectorSection("Volume", green, "BoxOccluder", ["position", "size"]),
new InspectorSection("Script", "Magenta", "Circle", ["m_shape_script"])
],
"VoxelLine" => [
new InspectorSection("Line", green, "BoxMesh", ["position", "size", "axis", "tile_space", "tile_offset", "flip", "mode", "match_id"]),
new InspectorSection("Model", green, "MeshItem", ["m_model", "m_palette"])
],
"VoxelMesh" => [
new InspectorSection("Position", green, "Move3d", ["position"]),
new InspectorSection("Model", green, "MeshItem", ["m_model"]),
Expand Down Expand Up @@ -378,6 +383,17 @@ public void CreateVolume(VoxelTool tool, (int X, int Y, int Z) min, (int X, int
});
}

public void CreateLine((int X, int Y, int Z) min, (int X, int Y, int Z) max, int axis) {
if (string.IsNullOrEmpty(DefaultModel)) {
_ = App.Modals.ShowWarning("Line", "Pick a voxel model for the Line tool in the toolbar first");
return;
}
Events.Send(new VoxelCreatePiece {
Parent = CreationParent(), Type = "toast::VoxelLine", Min = Int3(min), Max = Int3(max), Model = DefaultModel,
Axis = (uint)axis, Mode = DefaultFillMode
});
}

[RelayCommand]
private void AddMesh() {
EnsureEngine();
Expand Down Expand Up @@ -482,7 +498,8 @@ private static bool IsVolume(HierarchyElement node) {
}

private static bool IsPiece(HierarchyElement node) {
return IsVolume(node) || node.Type.EndsWith("VoxelMesh", StringComparison.Ordinal);
return IsVolume(node) || node.Type.EndsWith("VoxelMesh", StringComparison.Ordinal) ||
node.Type.EndsWith("VoxelLine", StringComparison.Ordinal);
}

// Split and Slice only cut the selected shape
Expand All @@ -491,7 +508,9 @@ private List<string> CutTargets() {
}

private string CreationParent() {
if (Hierarchy.SelectedNode is { Type: "toast::VoxelGroup" } group) return group.Uid;
var selected = Hierarchy.SelectedNode;
if (selected is { Type: "toast::VoxelGroup" } group) return group.Uid;
if (selected?.Parent is { Type: "toast::VoxelGroup" } owner) return owner.Uid;
return Workspace.RootUid ?? "";
}

Expand Down Expand Up @@ -527,6 +546,10 @@ partial void OnDefaultScriptChanged(string? value) {
SendTool();
}

partial void OnDefaultModelChanged(string? value) {
SendTool();
}

partial void OnDefaultFillModeNameChanged(string value) {
SendTool();
}
Expand Down Expand Up @@ -603,7 +626,7 @@ private void SendTool() {
if (!OwnsEngine) return;
Events.Send(new SetVoxelTool {
Tool = (uint)ActiveTool, PaintId = (uint)Math.Clamp(PaletteId, 1, 255), DefaultScript = DefaultScript ?? "",
DefaultMode = DefaultFillMode
DefaultMode = DefaultFillMode, DefaultModel = DefaultModel ?? ""
});
var gizmo = ActiveTool == VoxelTool.Move ? GizmoTool.VolumeFaces : GizmoTool.Select;
Events.Send(new SetGizmoTool { Tool = (uint)gizmo });
Expand Down
43 changes: 41 additions & 2 deletions editor/VoxelEditor/VoxelOrthoView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public sealed class VoxelOrthoView : Control {
private bool m_awaitingSliceSide;
private bool m_boxClickMode; // a plain click started the box, it follows the mouse until the next click

private enum Drag { None, Pan, Move, EdgeMinH, EdgeMaxH, EdgeMinV, EdgeMaxV, Extrude, Box, Cut }
private enum Drag { None, Pan, Move, EdgeMinH, EdgeMaxH, EdgeMinV, EdgeMaxV, Extrude, Box, Cut, Line }

private bool m_lineAlongH = true;

static VoxelOrthoView() {
AffectsRender<VoxelOrthoView>(ProjectionProperty);
Expand Down Expand Up @@ -226,7 +228,7 @@ public override void Render(DrawingContext context) {
DrawPiece(context, piece, box, selected);
}

if (m_drag is Drag.Box or Drag.Extrude) DrawPreviewBox(context);
if (m_drag is Drag.Box or Drag.Extrude or Drag.Line) DrawPreviewBox(context);
if (m_cutLine is { } line) DrawCut(context, bounds, line.A, line.B);
DrawLabel(context, Projection.ToString(), new Point(8, 6), Brush("TextMuted", Brushes.Gray));
}
Expand Down Expand Up @@ -469,6 +471,11 @@ protected override void OnPointerPressed(PointerPressedEventArgs e) {
m_drag = Drag.Box;
m_dragBox = SnapBox(cell.Item1, cell.Item2, cell.Item1, cell.Item2);
break;
case VoxelTool.Line:
m_drag = Drag.Line;
m_lineAlongH = true;
m_dragBox = LineBox(cell.Item1, cell.Item2, cell.Item1, cell.Item2, true);
break;
case VoxelTool.Split or VoxelTool.Slice:
m_drag = Drag.Cut;
var cutStart = SnapPoint(point.Position);
Expand Down Expand Up @@ -569,6 +576,17 @@ protected override void OnPointerMoved(PointerEventArgs e) {
m_dragBox = SnapBox((int)Math.Floor(h0), (int)Math.Floor(v0), (int)Math.Floor(h), (int)Math.Floor(v));
break;
}
case Drag.Line: {
var (h, v) = ToVoxel(at);
var (h0, v0) = ToVoxel(m_pressed);
var (ch, cv) = ((int)Math.Floor(h0), (int)Math.Floor(v0));
var (dh, dv) = ((int)Math.Floor(h) - ch, (int)Math.Floor(v) - cv);
m_lineAlongH = VAxis > 1 || Math.Abs(dv) <= Math.Abs(dh);
m_dragBox = m_lineAlongH
? LineBox(Math.Min(ch, ch + dh), cv, Math.Max(ch, ch + dh), cv, true)
: LineBox(ch, Math.Min(cv, cv + dv), ch, Math.Max(cv, cv + dv), false);
break;
}
case Drag.Cut when m_cutLine is { } line:
var cutEnd = SnapPoint(at);
m_cutLine = (line.A, cutEnd);
Expand Down Expand Up @@ -633,6 +651,9 @@ protected override void OnPointerReleased(PointerReleasedEventArgs e) {
case Drag.Box:
CreateFromBox(editor);
break;
case Drag.Line:
CreateLine(editor);
break;
case Drag.Extrude when m_dragPiece is { } piece:
editor.Extrude(piece.Uid, ToShape(piece, m_dragBox, false), ToShape(piece, m_dragBox, true), false);
break;
Expand Down Expand Up @@ -688,6 +709,24 @@ private void CreateFromBox(VoxelEditorViewModel editor) {
editor.CreateVolume(editor.ActiveTool, (min[0], min[1], min[2]), (max[0], max[1], max[2]));
}

private (int H0, int V0, int H1, int V1) LineBox(int h0, int v0, int h1, int v1, bool alongH) {
var box = SnapBox(h0, v0, h1, v1);
return alongH ? (box.H0, box.V0, box.H1, box.V0) : (box.H0, box.V0, box.H0, box.V1);
}

private void CreateLine(VoxelEditorViewModel editor) {
var depth = editor.SelectedPiece is { } around ? around.Axis(DepthAxis, false) : 0;
int[] min = new int[3];
int[] max = new int[3];
min[HAxis] = m_dragBox.H0;
max[HAxis] = m_dragBox.H1;
min[VAxis] = m_dragBox.V0;
max[VAxis] = m_dragBox.V1;
min[DepthAxis] = depth;
max[DepthAxis] = depth;
editor.CreateLine((min[0], min[1], min[2]), (max[0], max[1], max[2]), m_lineAlongH ? HAxis : VAxis);
}

private void BucketAt(VoxelEditorViewModel editor, (int H, int V) cell) {
int[] voxel = new int[3];
voxel[HAxis] = cell.H;
Expand Down
21 changes: 20 additions & 1 deletion engine/assets/lua/voxel.d.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function VoxelNodeProxy:localBoundingSphere() end

-- Procedural voxel pieces
--
-- FillVolume, CarveVolume, PaintVolume and VoxelMesh are pieces of a ProceduralVoxel
-- FillVolume, CarveVolume, PaintVolume, VoxelMesh and VoxelLine are pieces of a ProceduralVoxel
-- Each one draws into its own grid with editShape and the ProceduralVoxel applies them top to bottom
-- Positions are in voxels from the piece corner and nothing can be drawn past getSize()
--
Expand Down Expand Up @@ -428,6 +428,25 @@ function VoxelMeshProxy:getPalette() end
---@param palette Asset
function VoxelMeshProxy:setPalette(palette) end

---@class VoxelLine: VoxelVolume
---@field flip boolean The model is mirrored across the line so the other side faces out
local VoxelLineProxy = {}

--- The voxel model the line repeats
---@return Asset
function VoxelLineProxy:getModel() end

--- Swaps the model and redraws the line
---@param model Asset
function VoxelLineProxy:setModel(model) end

--- The palette that replaces the model colors
---@return Asset
function VoxelLineProxy:getPalette() end

---@param palette Asset
function VoxelLineProxy:setPalette(palette) end

---@class VoxelBucket
local VoxelBucketProxy = {}

Expand Down
2 changes: 2 additions & 0 deletions engine/src/toast/voxel/nodes/procedural_voxel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ auto ProceduralVoxel::land(const std::vector<Collected>& pieces, bool wait) -> s
for (const Collected& entry : pieces) {
const auto [placement, exact] = snappedPlacement(entry.to_root);
entry.piece->setMisaligned(!exact);
entry.piece->landedAt(placement);
VoxelPiece::GridRef grid = wait ? entry.piece->gridRef() : entry.piece->readyGrid();
if (grid == nullptr) {
continue;
Expand Down Expand Up @@ -771,6 +772,7 @@ void ProceduralVoxel::tickAsyncBuild() {
std::vector<Collected> pieces;
collect(*this, glm::mat4(1.0f), pieces);
for (const Collected& entry : pieces) {
entry.piece->landedAt(snappedPlacement(entry.to_root).first);
entry.piece->collectGrid();
entry.piece->requestGrid();
}
Expand Down
Loading
Loading