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:
@@ -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}).");
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ public sealed class EngineMcpTools
|
||||
string modelPath,
|
||||
[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 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
|
||||
{
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user