Files
Fishing/tools/mcp/preview-model.js
T
2026-11-06 12:34:01 +05:00

35 lines
2.5 KiB
JavaScript

// Предпросмотр модели из .bbmodel в Studio (режим редактирования): ставит копию высоко над картой
// (Workspace._ModelPreview), снимает с 4 сторон и убирает. node tools/mcp/preview-model.js <name> <out-prefix>
// <name> — файл assets/props/<name>.bbmodel (+ _palette.png). Снимки: <out-prefix>_front/side/back/top.jpg
const fs = require('fs'), path = require('path'), os = require('os'), { execFileSync } = require('child_process');
const ROOT = path.join(__dirname, '..', '..');
const [name, prefix] = process.argv.slice(2);
const lua = path.join(ROOT, 'tools', 'lobby-models', name + '.lua');
execFileSync('node', [path.join(ROOT, 'tools', 'bbmodel-to-luau.js'), path.join(ROOT, 'assets', 'props', name + '.bbmodel'),
path.join(ROOT, 'assets', 'props', name + '_palette.png'), lua, name], { stdio: 'inherit' });
const build = `local old = workspace:FindFirstChild("_ModelPreview") if old then old:Destroy() end
local build = (function()\n${fs.readFileSync(lua, 'utf8')}\nend)()
local m = build(workspace)
m.Name = "_ModelPreview"
m:PivotTo(CFrame.new(0, 300, 0))
local cf, size = m:GetBoundingBox()
local unanchored = 0
for _, p in ipairs(m:GetDescendants()) do if p:IsA("BasePart") and not p.Anchored then unanchored += 1 end end
return ("size %.1f x %.1f x %.1f, деталей %d, незакреплённых %d"):format(size.X, size.Y, size.Z, #m:GetDescendants(), unanchored)`;
const C = [0, 307, 0]; // центр модели примерно
const at = (dx, dy, dz) => [C[0] + dx, C[1] + dy, C[2] + dz];
const views = { front: at(6, 3, -22), side: at(-22, 3, -4), back: at(-5, 4, 22), top: at(0, 26, -10) };
const steps = [{ tool: 'execute_luau', args: { datamodel_type: 'Edit', code: build } }];
for (const [k, eye] of Object.entries(views)) {
steps.push({ tool: 'screen_capture', args: { capture_id: 'Preview_' + k, camera_position: eye, look_at_position: C } });
}
steps.push({ tool: 'execute_luau', args: { datamodel_type: 'Edit', code: 'workspace._ModelPreview:Destroy() return "removed"' } });
const tmp = path.join(os.tmpdir(), 'fishing-preview-' + process.pid + '.json');
fs.writeFileSync(tmp, JSON.stringify(steps));
const res = execFileSync('node', [path.join(__dirname, 'run.js'), tmp], { encoding: 'utf8', maxBuffer: 1 << 26 });
fs.unlinkSync(tmp);
const keys = Object.keys(views);
let i = 0;
for (const m of res.matchAll(/IMAGE (.+\.jpe?g)/g)) fs.renameSync(m[1].trim(), `${prefix}_${keys[i++]}.jpg`);
console.log(res.split('\n').filter(l => !l.startsWith('IMAGE')).join('\n'));