@babylonjs-toolkit/agent 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +3 -2
  2. package/package.json +1 -1
  3. package/skills/bt-atlas/SKILL.md +22 -5
  4. package/skills/bt-design/references/3d-hero-docs.md +10 -3
  5. package/skills/bt-design/references/3d-hero-scroll.md +30 -5
  6. package/skills/bt-gauntlet/SKILL.md +4 -4
  7. package/skills/bt-gauntlet/references/spec-composition.md +4 -2
  8. package/skills/bt-gauntlet/references/target-images.md +28 -4
  9. package/skills/bt-gauntlet/references/unity-pipeline.md +30 -8
  10. package/skills/bt-hero/SKILL.md +3 -3
  11. package/skills/bt-landing/SKILL.md +1 -1
  12. package/skills/bt-prototype/SKILL.md +3 -3
  13. package/skills/bt-unwrap/SKILL.md +396 -0
  14. package/skills/bt-unwrap/scripts/blender/__pycache__/bt_unwrap.cpython-313.pyc +0 -0
  15. package/skills/bt-unwrap/scripts/blender/__pycache__/image_utils.cpython-313.pyc +0 -0
  16. package/skills/bt-unwrap/scripts/blender/__pycache__/mesh_tools.cpython-313.pyc +0 -0
  17. package/skills/bt-unwrap/scripts/blender/__pycache__/model_io.cpython-313.pyc +0 -0
  18. package/skills/bt-unwrap/scripts/blender/__pycache__/previews.cpython-313.pyc +0 -0
  19. package/skills/bt-unwrap/scripts/blender/__pycache__/rasterizer.cpython-313.pyc +0 -0
  20. package/skills/bt-unwrap/scripts/blender/__pycache__/reference_views.cpython-313.pyc +0 -0
  21. package/skills/bt-unwrap/scripts/blender/__pycache__/reference_warp.cpython-313.pyc +0 -0
  22. package/skills/bt-unwrap/scripts/blender/__pycache__/texture_bake.cpython-313.pyc +0 -0
  23. package/skills/bt-unwrap/scripts/blender/__pycache__/texture_compose.cpython-313.pyc +0 -0
  24. package/skills/bt-unwrap/scripts/blender/__pycache__/uv_layout.cpython-313.pyc +0 -0
  25. package/skills/bt-unwrap/scripts/blender/bt_unwrap.py +678 -0
  26. package/skills/bt-unwrap/scripts/blender/image_utils.py +264 -0
  27. package/skills/bt-unwrap/scripts/blender/mesh_tools.py +508 -0
  28. package/skills/bt-unwrap/scripts/blender/model_io.py +135 -0
  29. package/skills/bt-unwrap/scripts/blender/previews.py +205 -0
  30. package/skills/bt-unwrap/scripts/blender/rasterizer.py +217 -0
  31. package/skills/bt-unwrap/scripts/blender/reference_views.py +945 -0
  32. package/skills/bt-unwrap/scripts/blender/reference_warp.py +571 -0
  33. package/skills/bt-unwrap/scripts/blender/texture_bake.py +390 -0
  34. package/skills/bt-unwrap/scripts/blender/texture_compose.py +596 -0
  35. package/skills/bt-unwrap/scripts/blender/uv_layout.py +605 -0
  36. package/skills/bt-unwrap/scripts/bt-unwrap.mjs +165 -0
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * bt-unwrap launcher: finds Blender on macOS, Windows or Linux and runs the bt-unwrap pipeline headless.
4
+ *
5
+ * node bt-unwrap.mjs <model> [options] run (see --help for every option)
6
+ * node bt-unwrap.mjs --help list every option
7
+ * node bt-unwrap.mjs --which-blender print the Blender it would use
8
+ *
9
+ * Launcher-only options (everything else goes to the pipeline):
10
+ * --blender <path> use this Blender executable (else $BLENDER, then PATH, then the usual install folders)
11
+ * --verbose show Blender's full log instead of only bt-unwrap lines and errors
12
+ *
13
+ * Exit code: the pipeline's — 0 done, 1 failed, 2 bad options.
14
+ */
15
+ import { spawn, spawnSync } from 'node:child_process';
16
+ import { existsSync, readdirSync } from 'node:fs';
17
+ import { homedir } from 'node:os';
18
+ import path from 'node:path';
19
+ import { fileURLToPath } from 'node:url';
20
+
21
+ /** Folder holding this launcher; the Blender pipeline lives in its `blender/` subfolder. */
22
+ const SCRIPT_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
23
+
24
+ /** The Python entry point Blender runs. */
25
+ const PIPELINE_SCRIPT = path.join(SCRIPT_DIRECTORY, 'blender', 'bt_unwrap.py');
26
+
27
+ /** Lines from Blender worth showing when not --verbose: our own progress plus anything that looks like a failure. */
28
+ const IMPORTANT_LINE = /^bt-unwrap:|Traceback|Error|error:|^\s+File "/;
29
+
30
+ /**
31
+ * Lists the places Blender is usually installed on this platform, newest version first.
32
+ * @returns {string[]} Candidate executable paths (may not exist).
33
+ */
34
+ function installedBlenderCandidates() {
35
+ if (process.platform === 'darwin') {
36
+ return ['/Applications/Blender.app/Contents/MacOS/Blender',
37
+ path.join(homedir(), 'Applications/Blender.app/Contents/MacOS/Blender')];
38
+ }
39
+ if (process.platform === 'win32') {
40
+ const roots = [process.env.ProgramFiles, process.env['ProgramFiles(x86)']].filter(Boolean)
41
+ .map((root) => path.join(root, 'Blender Foundation'));
42
+ const candidates = [];
43
+ for (const root of roots) {
44
+ if (!existsSync(root)) continue;
45
+ const versions = readdirSync(root).filter((name) => name.toLowerCase().startsWith('blender'))
46
+ .sort((first, second) => second.localeCompare(first, undefined, { numeric: true }));
47
+ candidates.push(...versions.map((name) => path.join(root, name, 'blender.exe')));
48
+ }
49
+ return candidates;
50
+ }
51
+ const optFolders = existsSync('/opt') ? readdirSync('/opt').filter((name) => name.startsWith('blender'))
52
+ .map((name) => path.join('/opt', name, 'blender')) : [];
53
+ return ['/usr/bin/blender', '/usr/local/bin/blender', '/snap/bin/blender', ...optFolders];
54
+ }
55
+
56
+ /**
57
+ * Checks whether a command resolves on PATH.
58
+ * @param {string} command - Command name.
59
+ * @returns {boolean} True when it runs.
60
+ */
61
+ function isOnPath(command) {
62
+ const probe = spawnSync(command, ['--version'], { stdio: 'ignore' });
63
+ return probe.status === 0;
64
+ }
65
+
66
+ /**
67
+ * Picks the Blender executable to use.
68
+ * @param {string | undefined} explicitPath - Path from --blender.
69
+ * @returns {string} The executable.
70
+ * @throws {Error} When no Blender can be found.
71
+ */
72
+ function findBlender(explicitPath) {
73
+ const configured = explicitPath || process.env.BLENDER;
74
+ if (configured) {
75
+ if (!existsSync(configured)) throw new Error(`Blender not found at ${configured}`);
76
+ return configured;
77
+ }
78
+ if (isOnPath('blender')) return 'blender';
79
+ const installed = installedBlenderCandidates().find((candidate) => existsSync(candidate));
80
+ if (installed) return installed;
81
+ throw new Error('Blender not found. Install Blender 4.2+ (5.x recommended), or pass --blender <path> / set BLENDER.');
82
+ }
83
+
84
+ /**
85
+ * Splits launcher-only options from the options meant for the pipeline.
86
+ * @param {string[]} argv - Command-line arguments after the script name.
87
+ * @returns {{ blenderPath: string | undefined, verbose: boolean, whichBlender: boolean, pipelineArguments: string[] }}
88
+ */
89
+ function parseLauncherArguments(argv) {
90
+ const pipelineArguments = [];
91
+ let blenderPath;
92
+ let verbose = false;
93
+ let whichBlender = false;
94
+ for (let index = 0; index < argv.length; index += 1) {
95
+ const argument = argv[index];
96
+ if (argument === '--blender') {
97
+ blenderPath = argv[index + 1];
98
+ index += 1;
99
+ } else if (argument === '--verbose') {
100
+ verbose = true;
101
+ } else if (argument === '--which-blender') {
102
+ whichBlender = true;
103
+ } else {
104
+ pipelineArguments.push(argument);
105
+ }
106
+ }
107
+ return { blenderPath, verbose, whichBlender, pipelineArguments };
108
+ }
109
+
110
+ /**
111
+ * Prints a child stream line by line, keeping only important lines unless verbose.
112
+ * @param {import('node:stream').Readable} stream - Blender's stdout or stderr.
113
+ * @param {NodeJS.WriteStream} destination - Where to print.
114
+ * @param {boolean} showEverything - Print every line.
115
+ */
116
+ function relayLines(stream, destination, showEverything) {
117
+ let pending = '';
118
+ stream.setEncoding('utf8');
119
+ stream.on('data', (chunk) => {
120
+ pending += chunk;
121
+ const lines = pending.split(/\r?\n/);
122
+ pending = lines.pop();
123
+ for (const line of lines) {
124
+ if (showEverything || IMPORTANT_LINE.test(line)) destination.write(`${line}\n`);
125
+ }
126
+ });
127
+ stream.on('end', () => {
128
+ if (pending && (showEverything || IMPORTANT_LINE.test(pending))) destination.write(`${pending}\n`);
129
+ });
130
+ }
131
+
132
+ /**
133
+ * Runs the pipeline and resolves with Blender's exit code.
134
+ * @returns {Promise<number>} Exit code.
135
+ */
136
+ async function main() {
137
+ const { blenderPath, verbose, whichBlender, pipelineArguments } = parseLauncherArguments(process.argv.slice(2));
138
+ let blender;
139
+ try {
140
+ blender = findBlender(blenderPath);
141
+ } catch (error) {
142
+ process.stderr.write(`bt-unwrap: ${error.message}\n`);
143
+ return 1;
144
+ }
145
+ if (whichBlender) {
146
+ process.stdout.write(`${blender}\n`);
147
+ return 0;
148
+ }
149
+ const wantsHelp = pipelineArguments.length === 0 || pipelineArguments.includes('--help') || pipelineArguments.includes('-h');
150
+ const blenderArguments = ['--background', '--factory-startup', '--python-exit-code', '1',
151
+ '--python', PIPELINE_SCRIPT, '--', ...(pipelineArguments.length ? pipelineArguments : ['--help'])];
152
+ const environment = verbose ? { ...process.env, BT_UNWRAP_TRACEBACK: '1' } : process.env;
153
+ const child = spawn(blender, blenderArguments, { stdio: ['ignore', 'pipe', 'pipe'], env: environment });
154
+ relayLines(child.stdout, process.stdout, verbose || wantsHelp);
155
+ relayLines(child.stderr, process.stderr, verbose || wantsHelp);
156
+ return new Promise((resolve) => {
157
+ child.on('close', (code) => resolve(code ?? 1));
158
+ child.on('error', (error) => {
159
+ process.stderr.write(`bt-unwrap: could not start Blender: ${error.message}\n`);
160
+ resolve(1);
161
+ });
162
+ });
163
+ }
164
+
165
+ process.exitCode = await main();