Files
Fishing/tools/mcp/npc-faces.js
T
2026-11-09 22:37:44 +05:00

60 lines
4.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Крупные планы голов NPC: node tools/mcp/npc-faces.js <suffix> "<Имя1>" "<Имя2>" …
// Play → каждый NPC выводится на открытое место → снимки: спереди, сбоку, голова повёрнута на 60° (как при взгляде на игрока).
// Сохраняет assets/reference/npc_check_<латиница>_<suffix>_{front,side,turn}.jpg
const fs = require('fs'), path = require('path'), os = require('os'), { execFileSync } = require('child_process');
const ROOT = path.join(__dirname, '..', '..');
const [suffix, ...names] = process.argv.slice(2);
const TR = { а:'a',б:'b',в:'v',г:'g',д:'d',е:'e',ё:'e',ж:'zh',з:'z',и:'i',й:'y',к:'k',л:'l',м:'m',н:'n',о:'o',п:'p',р:'r',с:'s',т:'t',у:'u',ф:'f',х:'h',ц:'c',ч:'ch',ш:'sh',щ:'sch',ъ:'',ы:'y',ь:'',э:'e',ю:'yu',я:'ya' };
const slug = n => n.toLowerCase().split('').map(c => TR[c] ?? (/[a-z0-9]/.test(c) ? c : '_')).join('').replace(/_+/g, '_');
const steps = [{ tool: 'start_stop_play', args: { is_start: true }, waitAfter: 20000 },
{ tool: 'execute_luau', args: { datamodel_type: 'Server', code: 'local c = game.Players:GetPlayers()[1].Character c:PivotTo(CFrame.new(0, 3, 2000)) c.HumanoidRootPart.Anchored = true return 1' } }];
const shots = [];
names.forEach((name, i) => {
// NPC на пустое место высоко над картой, на невидимую плиту (у каждого своя)
const X = 300 + i * 40;
steps.push({ tool: 'execute_luau', args: { datamodel_type: 'Server', code: `local rig = workspace.FishingMap:FindFirstChild(${JSON.stringify(name)})
if not rig then return "нет" end
local pad = Instance.new("Part") pad.Anchored = true pad.Size = Vector3.new(20, 1, 20) pad.CFrame = CFrame.new(${X}, 199.5, 0) pad.Color = Color3.fromRGB(120, 110, 100) pad.Parent = workspace
rig.HumanoidRootPart.Anchored = true
rig:PivotTo(CFrame.new(${X}, 200 + rig.Humanoid.HipHeight + rig.HumanoidRootPart.Size.Y / 2, 0))
-- персонаж рядом, за спиной у камеры (иначе стриминг не прогрузит NPC)
local pl = game.Players:GetPlayers()[1]
pl.Character:PivotTo(CFrame.new(${X} + 6, 203, 14))
pcall(function() pl:RequestStreamAroundAsync(Vector3.new(${X}, 200, 0), 10) end)
return "ok"` }, waitAfter: 4000 });
const cam = (dx, dz, turn) => `local RunService = game:GetService("RunService")
local rig = workspace.FishingMap:FindFirstChild(${JSON.stringify(name)})
local head = rig.Head
pcall(function() RunService:UnbindFromRenderStep("ToolShot") end)
local me = game.Players.LocalPlayer.Character
RunService:BindToRenderStep("ToolShot", Enum.RenderPriority.Last.Value, function()
for _, p in ipairs(me:GetDescendants()) do
if p:IsA("BasePart") or p:IsA("Decal") then p.LocalTransparencyModifier = 1 end
end
local root = rig.HumanoidRootPart.CFrame
local target = head.Position - Vector3.new(0, 0.6, 0)
workspace.CurrentCamera.CFrame = CFrame.lookAt(target + root:VectorToWorldSpace(Vector3.new(${dx}, 0.4, ${dz})), target)
workspace.CurrentCamera.FieldOfView = 40
end)
return "cam"`;
for (const [k, dx, dz, turn] of [['front', 0.8, -6.5, 0], ['side', -6.5, -0.4, 0], ['turn', 1.5, -6.5, 60]]) {
// поворот головы — на сервере (с клиента MCP не даёт менять суставы); 0 — вернуть прямо
steps.push({ tool: 'execute_luau', args: { datamodel_type: 'Server', code: `local rig = workspace.FishingMap:FindFirstChild(${JSON.stringify(name)})
local neck = rig.Head:FindFirstChild("Neck")
if neck and neck:IsA("Motor6D") then rig:SetAttribute("NeckC0", rig:GetAttribute("NeckC0") or neck.C0) neck.C0 = rig:GetAttribute("NeckC0") * CFrame.Angles(0, math.rad(${turn}), 0) end
return 1` } });
steps.push({ tool: 'execute_luau', args: { datamodel_type: 'Client', code: cam(dx, dz, turn) }, waitAfter: 1500 });
steps.push({ tool: 'screen_capture', args: { capture_id: 'Face' } });
shots.push(path.join(ROOT, 'assets', 'reference', `npc_check_${slug(name)}_${suffix}_${k}.jpg`));
}
});
steps.push({ tool: 'start_stop_play', args: { is_start: false } });
const tmp = path.join(os.tmpdir(), 'npcfaces.json');
fs.writeFileSync(tmp, JSON.stringify(steps));
const res = execFileSync('node', [path.join(__dirname, 'run.js'), tmp], { encoding: 'utf8', maxBuffer: 1 << 26 });
let i = 0;
for (const m of res.matchAll(/IMAGE (.+\.jpe?g)/g)) fs.renameSync(m[1].trim(), shots[i++]);
const lines = res.split('\n');
lines.forEach((l, k) => { if (/ERROR/.test(l)) console.log(l + ' → ' + (lines[k + 1] || '').slice(0, 300)); });
console.log(shots.slice(0, i).map(s => path.basename(s)).join('\n'));