feat: optional physics in spawn_model MCP command

- 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
This commit is contained in:
emil28092005
2026-06-18 22:16:13 +03:00
parent f8504cd44c
commit a90195c600
3 changed files with 12 additions and 2 deletions
+7
View File
@@ -83,6 +83,13 @@ public sealed class AiCommandProcessor
.Set(new Transform(command.Position, command.Rotation, command.Scale)) .Set(new Transform(command.Position, command.Rotation, command.Scale))
.Set(mesh); .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})."); return AiCommandResult.Ok($"Spawned entity '{command.Name}' with model '{command.ModelPath}' (id {(ulong)entity.Id}).");
} }
@@ -12,4 +12,5 @@ public sealed record SpawnModelCommand : AiCommand
public Vector3 Position { get; init; } = Vector3.Zero; public Vector3 Position { get; init; } = Vector3.Zero;
public Quaternion Rotation { get; init; } = Quaternion.Identity; public Quaternion Rotation { get; init; } = Quaternion.Identity;
public Vector3 Scale { get; init; } = Vector3.One; public Vector3 Scale { get; init; } = Vector3.One;
public bool Physics { get; init; } = false;
} }
+4 -2
View File
@@ -24,7 +24,8 @@ public sealed class EngineMcpTools
string modelPath, string modelPath,
[Description("Optional position as [x, y, z] (default: 0,0,0)")] IReadOnlyList<double>? position = null, [Description("Optional position as [x, y, z] (default: 0,0,0)")] IReadOnlyList<double>? position = null,
[Description("Optional rotation as [x, y, z, w] quaternion (default: identity)")] IReadOnlyList<double>? rotation = null, [Description("Optional rotation as [x, y, z, w] quaternion (default: identity)")] IReadOnlyList<double>? rotation = null,
[Description("Optional scale as [x, y, z] (default: 1,1,1)")] IReadOnlyList<double>? scale = null) [Description("Optional scale as [x, y, z] (default: 1,1,1)")] IReadOnlyList<double>? scale = null,
[Description("Optional: enable physics (default: false)")] bool physics = false)
{ {
var cmd = new SpawnModelCommand var cmd = new SpawnModelCommand
{ {
@@ -32,7 +33,8 @@ public sealed class EngineMcpTools
ModelPath = modelPath, ModelPath = modelPath,
Position = ToVector3(position, Vector3.Zero), Position = ToVector3(position, Vector3.Zero),
Rotation = ToQuaternion(rotation, Quaternion.Identity), Rotation = ToQuaternion(rotation, Quaternion.Identity),
Scale = ToVector3(scale, Vector3.One) Scale = ToVector3(scale, Vector3.One),
Physics = physics
}; };
return EnqueueAndReturnMessage(cmd); return EnqueueAndReturnMessage(cmd);