From a90195c600b8ed12314d4b10b2e6b7f2688775e4 Mon Sep 17 00:00:00 2001 From: emil28092005 Date: Thu, 18 Jun 2026 22:16:13 +0300 Subject: [PATCH] feat: optional physics in spawn_model MCP command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SpawnModelCommand: added Physics bool property (default false) - AiCommandProcessor.SpawnModel: when Physics=true, adds RigidBody.DynamicBox with half-extent = max(scale) * 0.5, mass = max(scale) * 2 - EngineMcpTools.SpawnModel: added 'physics' parameter (default false) - Physics is optional — spawn without physics by default, enable when needed - Physics bodies are initialized by the existing per-frame IsInitialized check --- src/Engine.AI/AiCommandProcessor.cs | 7 +++++++ src/Engine.AI/Commands/SpawnModelCommand.cs | 1 + src/Engine.AI/Mcp/EngineMcpTools.cs | 6 ++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Engine.AI/AiCommandProcessor.cs b/src/Engine.AI/AiCommandProcessor.cs index 832430e..1ee1425 100644 --- a/src/Engine.AI/AiCommandProcessor.cs +++ b/src/Engine.AI/AiCommandProcessor.cs @@ -83,6 +83,13 @@ public sealed class AiCommandProcessor .Set(new Transform(command.Position, command.Rotation, command.Scale)) .Set(mesh); + if (command.Physics) + { + var maxScale = MathF.Max(MathF.Max(command.Scale.X, command.Scale.Y), command.Scale.Z); + var rb = RigidBody.DynamicBox(new Vector3(maxScale * 0.5f), mass: maxScale * 2f); + entity.Set(rb); + } + return AiCommandResult.Ok($"Spawned entity '{command.Name}' with model '{command.ModelPath}' (id {(ulong)entity.Id})."); } diff --git a/src/Engine.AI/Commands/SpawnModelCommand.cs b/src/Engine.AI/Commands/SpawnModelCommand.cs index 310d217..c7cc5f6 100644 --- a/src/Engine.AI/Commands/SpawnModelCommand.cs +++ b/src/Engine.AI/Commands/SpawnModelCommand.cs @@ -12,4 +12,5 @@ public sealed record SpawnModelCommand : AiCommand public Vector3 Position { get; init; } = Vector3.Zero; public Quaternion Rotation { get; init; } = Quaternion.Identity; public Vector3 Scale { get; init; } = Vector3.One; + public bool Physics { get; init; } = false; } diff --git a/src/Engine.AI/Mcp/EngineMcpTools.cs b/src/Engine.AI/Mcp/EngineMcpTools.cs index d979c34..c2c151d 100644 --- a/src/Engine.AI/Mcp/EngineMcpTools.cs +++ b/src/Engine.AI/Mcp/EngineMcpTools.cs @@ -24,7 +24,8 @@ public sealed class EngineMcpTools string modelPath, [Description("Optional position as [x, y, z] (default: 0,0,0)")] IReadOnlyList? position = null, [Description("Optional rotation as [x, y, z, w] quaternion (default: identity)")] IReadOnlyList? rotation = null, - [Description("Optional scale as [x, y, z] (default: 1,1,1)")] IReadOnlyList? scale = null) + [Description("Optional scale as [x, y, z] (default: 1,1,1)")] IReadOnlyList? scale = null, + [Description("Optional: enable physics (default: false)")] bool physics = false) { var cmd = new SpawnModelCommand { @@ -32,7 +33,8 @@ public sealed class EngineMcpTools ModelPath = modelPath, Position = ToVector3(position, Vector3.Zero), Rotation = ToQuaternion(rotation, Quaternion.Identity), - Scale = ToVector3(scale, Vector3.One) + Scale = ToVector3(scale, Vector3.One), + Physics = physics }; return EnqueueAndReturnMessage(cmd);