feat: Step 5 AI agent command bridge
- Add new Engine.AI project referenced by the App. - Define JSON command model: spawn_model, set_transform, delete_entity, list_entities. - Implement AiCommandProcessor with System.Text.Json and custom Vector3/Quaternion converters. - Wire processor into Program.cs; demo commands spawn and move a second cube. - AI commands are executed against the live Flecs world and visible in the next frame.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Engine.Core\Engine.Core.csproj" />
|
||||
<ProjectReference Include="..\Engine.Graphics\Engine.Graphics.csproj" />
|
||||
<ProjectReference Include="..\Engine.AI\Engine.AI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using Engine.AI;
|
||||
using Engine.Core;
|
||||
using Engine.Core.Components;
|
||||
using Engine.Graphics;
|
||||
@@ -13,23 +14,22 @@ class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Cortex Engine Step 4 — Starting up...");
|
||||
Console.WriteLine("Cortex Engine Step 5 — Starting up...");
|
||||
|
||||
try
|
||||
{
|
||||
using var world = World.Create();
|
||||
using var window = new Sdl3Window("Cortex Engine — Step 4", 1280, 720);
|
||||
using var window = new Sdl3Window("Cortex Engine — Step 5", 1280, 720);
|
||||
var timing = new Timing();
|
||||
var input = new InputMapping();
|
||||
using var vulkan = new VulkanContext(window, enableValidation: false);
|
||||
using var swapchain = new Swapchain(vulkan);
|
||||
using var renderer = new MeshRenderer(vulkan, swapchain);
|
||||
|
||||
var ai = new AiCommandProcessor(world, LoadModel);
|
||||
|
||||
var modelPath = FindModelPath(args);
|
||||
var mesh = modelPath.EndsWith(".gltf", StringComparison.OrdinalIgnoreCase)
|
||||
|| modelPath.EndsWith(".glb", StringComparison.OrdinalIgnoreCase)
|
||||
? GltfLoader.Load(modelPath, new Vector3(0.7f, 0.6f, 0.5f))
|
||||
: ObjLoader.Load(modelPath, new Vector3(0.7f, 0.6f, 0.5f));
|
||||
var mesh = LoadModel(modelPath);
|
||||
|
||||
var model = world.Entity("Model")
|
||||
.Set(new Transform(new Vector3(0.0f, 0.0f, 0.0f), Quaternion.Identity, new Vector3(0.5f)))
|
||||
@@ -45,6 +45,13 @@ class Program
|
||||
0.1f,
|
||||
100.0f));
|
||||
|
||||
// Demo: AI agent commands.
|
||||
Console.WriteLine("AI demo commands:");
|
||||
Console.WriteLine(ai.Process("""{ "type": "list_entities" }""").Message);
|
||||
Console.WriteLine(ai.Process("""{ "type": "spawn_model", "name": "SecondCube", "modelPath": "Content/cube.obj", "position": [0.8, 0, 0], "scale": [0.3, 0.3, 0.3] }""").Message);
|
||||
Console.WriteLine(ai.Process("""{ "type": "list_entities" }""").Message);
|
||||
Console.WriteLine(ai.Process("""{ "type": "set_transform", "name": "SecondCube", "position": [0.8, 0.5, 0], "rotation": [0, 0, 0, 1], "scale": [0.3, 0.3, 0.3] }""").Message);
|
||||
|
||||
var frames = 0;
|
||||
var lastFpsTime = 0.0;
|
||||
var lastWidth = window.Width;
|
||||
@@ -90,6 +97,14 @@ class Program
|
||||
}
|
||||
}
|
||||
|
||||
private static Mesh LoadModel(string path)
|
||||
{
|
||||
return path.EndsWith(".gltf", StringComparison.OrdinalIgnoreCase)
|
||||
|| path.EndsWith(".glb", StringComparison.OrdinalIgnoreCase)
|
||||
? GltfLoader.Load(path, new Vector3(0.7f, 0.6f, 0.5f))
|
||||
: ObjLoader.Load(path, new Vector3(0.7f, 0.6f, 0.5f));
|
||||
}
|
||||
|
||||
private static string FindModelPath(string[] args)
|
||||
{
|
||||
if (args.Length > 0 && File.Exists(args[0]))
|
||||
|
||||
Reference in New Issue
Block a user