oda-engine 0.0.0-stage → 0.1.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 (204) hide show
  1. package/README.md +151 -2
  2. package/bin/nowhere.mjs +352 -0
  3. package/lib/account.mjs +57 -0
  4. package/lib/agentModules.mjs +57 -0
  5. package/lib/devServer.mjs +351 -0
  6. package/lib/headless.mjs +231 -0
  7. package/lib/headlessPreview.mjs +212 -0
  8. package/lib/keys.mjs +517 -0
  9. package/lib/make.mjs +855 -0
  10. package/lib/mcp.mjs +537 -0
  11. package/lib/open.mjs +22 -0
  12. package/lib/preview.mjs +87 -0
  13. package/lib/previewRpc.mjs +134 -0
  14. package/lib/project.mjs +359 -0
  15. package/lib/publishFlow.mjs +131 -0
  16. package/lib/resources.mjs +50 -0
  17. package/lib/rules.mjs +60 -0
  18. package/lib/scaffold.mjs +42 -0
  19. package/lib/setup.mjs +59 -0
  20. package/lib/tools.mjs +668 -0
  21. package/package.json +51 -4
  22. package/template/game.config.json +9 -0
  23. package/template/scene.json +4 -0
  24. package/template/src/main.ts +11 -0
  25. package/vendor/DOCS.md +447 -0
  26. package/vendor/agent/appRun.mjs +520 -0
  27. package/vendor/agent/assets/brief.mjs +242 -0
  28. package/vendor/agent/assets/collider.mjs +531 -0
  29. package/vendor/agent/assets/environments/index.mjs +12 -0
  30. package/vendor/agent/assets/environments/worldlabs.mjs +161 -0
  31. package/vendor/agent/assets/fetch.mjs +168 -0
  32. package/vendor/agent/assets/footprint.mjs +13 -0
  33. package/vendor/agent/assets/gltf.mjs +547 -0
  34. package/vendor/agent/assets/hdr.mjs +269 -0
  35. package/vendor/agent/assets/imageOps.mjs +171 -0
  36. package/vendor/agent/assets/images/codex.mjs +307 -0
  37. package/vendor/agent/assets/images/fal.mjs +75 -0
  38. package/vendor/agent/assets/images/gemini.mjs +84 -0
  39. package/vendor/agent/assets/images/index.mjs +25 -0
  40. package/vendor/agent/assets/images/openai.mjs +75 -0
  41. package/vendor/agent/assets/images/stability.mjs +71 -0
  42. package/vendor/agent/assets/images/views.mjs +31 -0
  43. package/vendor/agent/assets/import.mjs +1352 -0
  44. package/vendor/agent/assets/inspect.mjs +465 -0
  45. package/vendor/agent/assets/jobs.mjs +196 -0
  46. package/vendor/agent/assets/ktx2.mjs +290 -0
  47. package/vendor/agent/assets/ledger.mjs +466 -0
  48. package/vendor/agent/assets/net.mjs +254 -0
  49. package/vendor/agent/assets/prices.json +39 -0
  50. package/vendor/agent/assets/providers/fal.mjs +115 -0
  51. package/vendor/agent/assets/providers/index.mjs +22 -0
  52. package/vendor/agent/assets/providers/meshy.mjs +119 -0
  53. package/vendor/agent/assets/providers/tripo.mjs +188 -0
  54. package/vendor/agent/assets/sources/ambientcg.mjs +129 -0
  55. package/vendor/agent/assets/sources/index.mjs +23 -0
  56. package/vendor/agent/assets/sources/polyhaven.mjs +237 -0
  57. package/vendor/agent/assets/sources/polypizza.mjs +121 -0
  58. package/vendor/agent/assets/splat.mjs +631 -0
  59. package/vendor/agent/assets/targets.mjs +122 -0
  60. package/vendor/agent/assets/tile.mjs +261 -0
  61. package/vendor/agent/assets/unzip.mjs +180 -0
  62. package/vendor/agent/blender/cleanup.py +360 -0
  63. package/vendor/agent/blender/convert.py +167 -0
  64. package/vendor/agent/blender/find.mjs +192 -0
  65. package/vendor/agent/blender/nw_export.py +104 -0
  66. package/vendor/agent/blender/nw_rubric.py +426 -0
  67. package/vendor/agent/blender/run.mjs +193 -0
  68. package/vendor/agent/blender/runner.py +252 -0
  69. package/vendor/agent/blender/sheet.py +743 -0
  70. package/vendor/agent/depth.mjs +134 -0
  71. package/vendor/agent/director/board.mjs +451 -0
  72. package/vendor/agent/director/contracts.mjs +663 -0
  73. package/vendor/agent/director/director.mjs +2365 -0
  74. package/vendor/agent/director/estimate.mjs +200 -0
  75. package/vendor/agent/director/gate.mjs +802 -0
  76. package/vendor/agent/director/limits.json +16 -0
  77. package/vendor/agent/director/methods.mjs +457 -0
  78. package/vendor/agent/director/policy.json +33 -0
  79. package/vendor/agent/director/prompts.mjs +244 -0
  80. package/vendor/agent/director/reading.mjs +341 -0
  81. package/vendor/agent/director/router.mjs +184 -0
  82. package/vendor/agent/director/seams.mjs +243 -0
  83. package/vendor/agent/director/session.mjs +643 -0
  84. package/vendor/agent/director/store.mjs +119 -0
  85. package/vendor/agent/director/taskGate.mjs +110 -0
  86. package/vendor/agent/director/teamLedger.mjs +118 -0
  87. package/vendor/agent/director/triage.mjs +63 -0
  88. package/vendor/agent/downloads.cjs +363 -0
  89. package/vendor/agent/flow.mjs +78 -0
  90. package/vendor/agent/guard.mjs +613 -0
  91. package/vendor/agent/host.mjs +1736 -0
  92. package/vendor/agent/language.mjs +58 -0
  93. package/vendor/agent/ledger.mjs +360 -0
  94. package/vendor/agent/locale.cjs +186 -0
  95. package/vendor/agent/loop/capacity.mjs +74 -0
  96. package/vendor/agent/loop/compose.mjs +127 -0
  97. package/vendor/agent/loop/gate.mjs +205 -0
  98. package/vendor/agent/loop/judge.mjs +189 -0
  99. package/vendor/agent/loop/levels.mjs +273 -0
  100. package/vendor/agent/loop/state.mjs +358 -0
  101. package/vendor/agent/notes.cjs +278 -0
  102. package/vendor/agent/pace.mjs +258 -0
  103. package/vendor/agent/panels.mjs +431 -0
  104. package/vendor/agent/prompt.mjs +342 -0
  105. package/vendor/agent/reference/board.mjs +410 -0
  106. package/vendor/agent/reference/compose.mjs +364 -0
  107. package/vendor/agent/reference/decode.mjs +56 -0
  108. package/vendor/agent/reference/facts.mjs +1874 -0
  109. package/vendor/agent/reference/png.mjs +107 -0
  110. package/vendor/agent/reference/records.mjs +63 -0
  111. package/vendor/agent/reference/web.mjs +252 -0
  112. package/vendor/agent/roles/artist.mjs +69 -0
  113. package/vendor/agent/roles/builder.mjs +79 -0
  114. package/vendor/agent/roles/checks.mjs +223 -0
  115. package/vendor/agent/roles/common.mjs +188 -0
  116. package/vendor/agent/roles/critic.mjs +171 -0
  117. package/vendor/agent/roles/index.mjs +39 -0
  118. package/vendor/agent/roles/modeller.mjs +142 -0
  119. package/vendor/agent/roles/qa.mjs +58 -0
  120. package/vendor/agent/roles/rubrics.mjs +79 -0
  121. package/vendor/agent/roles/sound.mjs +69 -0
  122. package/vendor/agent/rounds.cjs +333 -0
  123. package/vendor/agent/shared.mjs +284 -0
  124. package/vendor/agent/stopGate.mjs +574 -0
  125. package/vendor/agent/subagents.mjs +129 -0
  126. package/vendor/agent/tools/assets.mjs +499 -0
  127. package/vendor/agent/tools/blender.mjs +754 -0
  128. package/vendor/agent/tools/cards.mjs +479 -0
  129. package/vendor/agent/tools/choices.mjs +479 -0
  130. package/vendor/agent/tools/compose.mjs +74 -0
  131. package/vendor/agent/tools/environment.mjs +488 -0
  132. package/vendor/agent/tools/eyes.mjs +733 -0
  133. package/vendor/agent/tools/generate.mjs +338 -0
  134. package/vendor/agent/tools/guide.mjs +46 -0
  135. package/vendor/agent/tools/harness.mjs +193 -0
  136. package/vendor/agent/tools/image.mjs +643 -0
  137. package/vendor/agent/tools/index.mjs +162 -0
  138. package/vendor/agent/tools/look.mjs +578 -0
  139. package/vendor/agent/tools/loop.mjs +858 -0
  140. package/vendor/agent/tools/others.mjs +123 -0
  141. package/vendor/agent/tools/pictures.mjs +535 -0
  142. package/vendor/agent/tools/reference.mjs +366 -0
  143. package/vendor/agent/transcripts.mjs +118 -0
  144. package/vendor/agent-loop.mjs +602 -0
  145. package/vendor/agent-plugin/.claude-plugin/plugin.json +5 -0
  146. package/vendor/agent-plugin/skills/art-direction/SKILL.md +82 -0
  147. package/vendor/agent-plugin/skills/asset-legality/SKILL.md +101 -0
  148. package/vendor/agent-plugin/skills/asset-sources/SKILL.md +111 -0
  149. package/vendor/agent-plugin/skills/blender-modeling/SKILL.md +97 -0
  150. package/vendor/agent-plugin/skills/look-dev/SKILL.md +104 -0
  151. package/vendor/agent-plugin/skills/playtesting/SKILL.md +74 -0
  152. package/vendor/agent-plugin/skills/reference-loop/SKILL.md +102 -0
  153. package/vendor/agent-plugin/skills/sound-design/SKILL.md +60 -0
  154. package/vendor/agent-plugin/skills/style/SKILL.md +35 -0
  155. package/vendor/agent-plugin/skills/tsl-r185/SKILL.md +107 -0
  156. package/vendor/auth.cjs +570 -0
  157. package/vendor/build.cjs +953 -0
  158. package/vendor/catalog.json +455 -0
  159. package/vendor/connectors.cjs +688 -0
  160. package/vendor/eyes.mjs +733 -0
  161. package/vendor/gameExports.json +1390 -0
  162. package/vendor/git.cjs +222 -0
  163. package/vendor/models.json +57 -0
  164. package/vendor/publish.cjs +1018 -0
  165. package/vendor/refBoard.cjs +301 -0
  166. package/vendor/schema/dist/assets.d.ts +335 -0
  167. package/vendor/schema/dist/assets.js +439 -0
  168. package/vendor/schema/dist/brief.d.ts +357 -0
  169. package/vendor/schema/dist/brief.js +302 -0
  170. package/vendor/schema/dist/common.d.ts +9 -0
  171. package/vendor/schema/dist/common.js +13 -0
  172. package/vendor/schema/dist/config.d.ts +406 -0
  173. package/vendor/schema/dist/config.js +355 -0
  174. package/vendor/schema/dist/contract.d.ts +599 -0
  175. package/vendor/schema/dist/contract.js +1146 -0
  176. package/vendor/schema/dist/index.d.ts +14 -0
  177. package/vendor/schema/dist/index.js +21 -0
  178. package/vendor/schema/dist/look.d.ts +463 -0
  179. package/vendor/schema/dist/look.js +681 -0
  180. package/vendor/schema/dist/lookStats.d.ts +230 -0
  181. package/vendor/schema/dist/lookStats.js +768 -0
  182. package/vendor/schema/dist/pilot.d.ts +32 -0
  183. package/vendor/schema/dist/pilot.js +44 -0
  184. package/vendor/schema/dist/publish.d.ts +214 -0
  185. package/vendor/schema/dist/publish.js +291 -0
  186. package/vendor/schema/dist/scene.d.ts +75 -0
  187. package/vendor/schema/dist/scene.js +120 -0
  188. package/vendor/schema/dist/skyLight.d.ts +141 -0
  189. package/vendor/schema/dist/skyLight.js +436 -0
  190. package/vendor/schema/dist/style.d.ts +131 -0
  191. package/vendor/schema/dist/style.js +155 -0
  192. package/vendor/schema/package.json +1 -0
  193. package/vendor/selectionPrompt.mjs +51 -0
  194. package/vendor/useTools.mjs +195 -0
  195. package/vendor/userMessage.mjs +26 -0
  196. package/web-dist/assets/GaussianSplatUtils-CptQkDVX.js +1 -0
  197. package/web-dist/assets/KTX2Loader-C53LJqss.js +2 -0
  198. package/web-dist/assets/SPZLoader-BQ3tjaTv.js +1 -0
  199. package/web-dist/assets/gaussianSplat-_9tcWegB.js +1 -0
  200. package/web-dist/assets/index-Baka-ZO7.js +693 -0
  201. package/web-dist/assets/index-CcjyyQco.css +1 -0
  202. package/web-dist/assets/meshopt_decoder.module-BvwdjiD3.js +1 -0
  203. package/web-dist/assets/zstddec.module-CfFeQW7d.js +1 -0
  204. package/web-dist/index.html +34 -0
@@ -0,0 +1,192 @@
1
+ // Finds the creator's Blender for nw_blender and for the studio context line.
2
+ // The agent used to spend the first minutes of every Blender request hunting
3
+ // for the binary with ls and mdfind; the host does it once instead and hands
4
+ // the answer to both the tool and the prompt.
5
+ //
6
+ // Everything the search touches comes in through `deps`, so a check can play
7
+ // a Mac, a Windows tree or an empty machine without one.
8
+
9
+ import { execFile } from 'node:child_process'
10
+ import { existsSync, readdirSync } from 'node:fs'
11
+ import os from 'node:os'
12
+ import path from 'node:path'
13
+
14
+ /** The oldest Blender whose Python API and glTF exporter nw_blender's scripts are written for. */
15
+ export const MIN_VERSION = [4, 2]
16
+
17
+ const VERSION_RE = /Blender (\d+)\.(\d+)(?:\.(\d+))?/
18
+
19
+ export const realDeps = {
20
+ platform: process.platform,
21
+ env: process.env,
22
+ home: os.homedir(),
23
+ exists: (p) => existsSync(p),
24
+ list: (dir) => {
25
+ try {
26
+ return readdirSync(dir)
27
+ } catch {
28
+ return []
29
+ }
30
+ },
31
+ run: (cmd, args, timeoutMs) =>
32
+ new Promise((resolve) => {
33
+ execFile(cmd, args, { timeout: timeoutMs, windowsHide: true, maxBuffer: 1 << 20 }, (err, stdout) => {
34
+ resolve({ code: err ? (typeof err.code === 'number' ? err.code : 1) : 0, stdout: String(stdout ?? '') })
35
+ })
36
+ }),
37
+ }
38
+
39
+ // Found once, kept for the life of the process: the agent host asks at the
40
+ // start of every request. A miss is kept only briefly, so a creator who
41
+ // installs Blender after being told to is found on their next request.
42
+ const MISS_MS = 60_000
43
+ const cache = new WeakMap()
44
+
45
+ /**
46
+ * @returns {Promise<{ path: string, version: string, major: number, minor: number, patch: number, root: string }
47
+ * | { error: string, searched: string[] }>}
48
+ * root is the install folder (the .app on macOS, the executable's folder elsewhere),
49
+ * for a guard that lets the agent read what ships with Blender.
50
+ */
51
+ export async function findBlender(deps = realDeps) {
52
+ const hit = cache.get(deps)
53
+ // A Blender found earlier is asked about again only if it has gone (moved
54
+ // or uninstalled while the studio ran).
55
+ if (hit && ((hit.found && deps.exists(hit.found)) || (!hit.found && Date.now() - hit.at < MISS_MS))) return hit.promise
56
+ const promise = search(deps)
57
+ // In flight: a second caller (the studio context and a tool call at once) waits for this search.
58
+ cache.set(deps, { promise, at: Date.now(), found: null })
59
+ const result = await promise
60
+ cache.set(deps, { promise, at: Date.now(), found: result.error ? null : result.path })
61
+ return result
62
+ }
63
+
64
+ /** Major, minor and patch from `Blender 5.1.2` (or a folder name such as `Blender 4.2`). */
65
+ export function parseVersion(text) {
66
+ const m = VERSION_RE.exec(String(text ?? ''))
67
+ if (!m) return null
68
+ return { major: Number(m[1]), minor: Number(m[2]), patch: Number(m[3] ?? 0) }
69
+ }
70
+
71
+ const newer = (a, b) => a.major - b.major || a.minor - b.minor || a.patch - b.patch
72
+ const oldEnough = (v) => v.major > MIN_VERSION[0] || (v.major === MIN_VERSION[0] && v.minor >= MIN_VERSION[1])
73
+ const label = (v) => `${v.major}.${v.minor}.${v.patch}`
74
+
75
+ /** Case-insensitive, because Windows spells ProgramFiles as it likes. */
76
+ function envVar(env, name) {
77
+ if (env[name] !== undefined) return env[name]
78
+ const key = Object.keys(env).find((k) => k.toLowerCase() === name.toLowerCase())
79
+ return key ? env[key] : undefined
80
+ }
81
+
82
+ async function search(deps) {
83
+ const P = deps.platform === 'win32' ? path.win32 : path.posix
84
+ const searched = []
85
+ const tooOld = []
86
+ const probed = new Set()
87
+
88
+ // Runs each candidate that exists for its version and keeps the newest one
89
+ // that is recent enough. Several installs side by side are common (a
90
+ // "Blender 4.2.app" kept for an old file next to the current one).
91
+ async function best(candidates) {
92
+ let pick = null
93
+ for (const exe of candidates) {
94
+ if (!exe || probed.has(exe)) continue
95
+ probed.add(exe)
96
+ searched.push(exe)
97
+ if (!deps.exists(exe)) continue
98
+ const out = await deps.run(exe, ['-b', '--factory-startup', '--version'], 15_000)
99
+ const v = parseVersion(out.stdout)
100
+ if (!v) continue
101
+ if (!oldEnough(v)) {
102
+ tooOld.push({ path: exe, version: label(v) })
103
+ continue
104
+ }
105
+ if (!pick || newer(v, pick.v) > 0) pick = { exe, v }
106
+ }
107
+ return pick
108
+ }
109
+
110
+ const root = (exe) => {
111
+ if (deps.platform === 'darwin') {
112
+ const at = exe.toLowerCase().lastIndexOf('.app/')
113
+ if (at >= 0) return exe.slice(0, at + 4)
114
+ }
115
+ return P.dirname(exe)
116
+ }
117
+ const done = (pick) => ({ path: pick.exe, version: label(pick.v), ...pick.v, root: root(pick.exe) })
118
+
119
+ // The creator's own say comes first. On a Mac it may name the .app itself.
120
+ const own = envVar(deps.env, 'NOWHERE_BLENDER')
121
+ if (own) {
122
+ const exe = deps.platform === 'darwin' && /\.app\/?$/i.test(own) ? P.join(own, 'Contents', 'MacOS', 'Blender') : own
123
+ const pick = await best([exe])
124
+ if (pick) return done(pick)
125
+ }
126
+
127
+ if (deps.platform === 'darwin') {
128
+ const apps = [P.join('/Applications', 'Blender.app', 'Contents', 'MacOS', 'Blender')]
129
+ for (const dir of ['/Applications', P.join(deps.home, 'Applications')]) {
130
+ for (const name of deps.list(dir)) {
131
+ if (/^blender.*\.app$/i.test(name)) apps.push(P.join(dir, name, 'Contents', 'MacOS', 'Blender'))
132
+ }
133
+ }
134
+ let pick = await best(apps)
135
+ if (pick) return done(pick)
136
+ // Spotlight knows an app dragged anywhere else (a Downloads folder, an
137
+ // external disk).
138
+ searched.push('Spotlight (mdfind)')
139
+ const found = await deps.run('mdfind', ["kMDItemCFBundleIdentifier == 'org.blenderfoundation.blender'"], 3_000)
140
+ const lines = found.stdout.split('\n').map((l) => l.trim()).filter((l) => l.endsWith('.app'))
141
+ pick = await best(lines.map((app) => P.join(app, 'Contents', 'MacOS', 'Blender')))
142
+ if (pick) return done(pick)
143
+ } else if (deps.platform === 'win32') {
144
+ const programFiles = envVar(deps.env, 'ProgramFiles') ?? 'C:\\Program Files'
145
+ const localAppData = envVar(deps.env, 'LOCALAPPDATA')
146
+ const programFilesX86 = envVar(deps.env, 'ProgramFiles(x86)') ?? 'C:\\Program Files (x86)'
147
+ // The installer makes one "Blender 4.2" folder per version; the newest
148
+ // folder is tried first, and every one is probed anyway.
149
+ const folderVersion = (name) => parseVersion(name.replace(/^blender\s*/i, 'Blender ')) ?? { major: 0, minor: 0, patch: 0 }
150
+ const versioned = (base) => {
151
+ if (!base) return []
152
+ const folder = P.join(base, 'Blender Foundation')
153
+ return deps
154
+ .list(folder)
155
+ .filter((name) => /^blender/i.test(name))
156
+ .sort((a, b) => newer(folderVersion(b), folderVersion(a)))
157
+ .map((name) => P.join(folder, name, 'blender.exe'))
158
+ }
159
+ const candidates = [
160
+ ...versioned(programFiles),
161
+ ...versioned(localAppData && P.join(localAppData, 'Programs')),
162
+ P.join(programFilesX86, 'Steam', 'steamapps', 'common', 'Blender', 'blender.exe'),
163
+ ]
164
+ let pick = await best(candidates)
165
+ if (pick) return done(pick)
166
+ // Whatever opens a .blend file when the creator double-clicks one.
167
+ searched.push('the registry (HKCR\\blendfile)')
168
+ const reg = await deps.run('reg', ['query', 'HKCR\\blendfile\\shell\\open\\command', '/ve'], 3_000)
169
+ const quoted = /"([^"]+blender[^"]*\.exe)"/i.exec(reg.stdout)
170
+ pick = await best(quoted ? [quoted[1]] : [])
171
+ if (pick) return done(pick)
172
+ searched.push('where blender')
173
+ const where = await deps.run('where', ['blender'], 3_000)
174
+ pick = await best(where.stdout.split(/\r?\n/).map((l) => l.trim()).filter(Boolean))
175
+ if (pick) return done(pick)
176
+ } else {
177
+ searched.push('which blender')
178
+ const which = await deps.run('which', ['blender'], 3_000)
179
+ const first = which.stdout.split('\n').map((l) => l.trim()).find(Boolean)
180
+ const pick = await best([first, '/snap/bin/blender', '/usr/bin/blender'])
181
+ if (pick) return done(pick)
182
+ }
183
+
184
+ const old = tooOld.length
185
+ ? `Blender ${tooOld.map((t) => `${t.version} at ${t.path}`).join(' and ')} ${tooOld.length > 1 ? 'are' : 'is'} too old: Oda needs Blender ${MIN_VERSION.join('.')} or later. `
186
+ : 'Blender was not found. '
187
+ return {
188
+ error: `${old}Searched: ${searched.join(', ')}. The creator needs Blender ${MIN_VERSION.join('.')} or later from blender.org; set NOWHERE_BLENDER to its executable if it is somewhere else.`,
189
+ searched,
190
+ ...(tooOld.length ? { tooOld } : {}),
191
+ }
192
+ }
@@ -0,0 +1,104 @@
1
+ # What runner.py (the agent's model) and convert.py (a file from outside)
2
+ # share: the glTF export with the options the game is built around, and the
3
+ # list of material nodes that export drops. One module, so a model made in
4
+ # Blender and a model converted from an FBX leave as the same kind of GLB.
5
+ # Written for Blender 4.2 to 5.1.
6
+
7
+ import bpy
8
+
9
+ # What the glTF exporter translates. Anything else upstream of a material's
10
+ # output (procedural textures, math, ramps) is baked to nothing on export;
11
+ # the agent is told, and the sheets show what survived.
12
+ GLTF_NODES = {
13
+ 'ShaderNodeBsdfPrincipled', 'ShaderNodeOutputMaterial', 'ShaderNodeTexImage', 'ShaderNodeNormalMap',
14
+ 'ShaderNodeUVMap', 'ShaderNodeTexCoord', 'ShaderNodeMapping', 'ShaderNodeSeparateColor', 'ShaderNodeSeparateRGB',
15
+ 'ShaderNodeCombineColor', 'ShaderNodeCombineRGB', 'ShaderNodeEmission', 'ShaderNodeBsdfTransparent',
16
+ 'ShaderNodeMixShader', 'ShaderNodeVertexColor', 'ShaderNodeAttribute', 'ShaderNodeBsdfDiffuse', 'ShaderNodeGroup',
17
+ 'NodeReroute', 'NodeFrame', 'NodeGroupInput', 'NodeGroupOutput',
18
+ }
19
+
20
+ # A Mix node set to multiply a colour attribute into the base colour is how
21
+ # baked vertex colour (an AO bake, say) reaches the game; the exporter reads
22
+ # that one pattern.
23
+ GLTF_MIX = 'ShaderNodeMix'
24
+
25
+
26
+ def node_problems(tree, seen_trees):
27
+ """Node labels upstream of the tree's output that glTF does not translate."""
28
+ found = []
29
+ if tree is None or tree.name_full in seen_trees:
30
+ return found
31
+ seen_trees.add(tree.name_full)
32
+ outputs = [n for n in tree.nodes if n.bl_idname == 'ShaderNodeOutputMaterial' and getattr(n, 'is_active_output', False)]
33
+ outputs = outputs or [n for n in tree.nodes if n.bl_idname in ('ShaderNodeOutputMaterial', 'NodeGroupOutput')]
34
+ stack = list(outputs)
35
+ seen = set(n.name for n in stack)
36
+ while stack:
37
+ node = stack.pop()
38
+ if node.bl_idname not in GLTF_NODES and not vertex_colour_mix(node):
39
+ found.append(node.bl_label or node.bl_idname)
40
+ if node.bl_idname == 'ShaderNodeGroup' and getattr(node, 'node_tree', None) is not None:
41
+ found.extend(node_problems(node.node_tree, seen_trees))
42
+ for socket in node.inputs:
43
+ for link in socket.links:
44
+ if link.from_node.name not in seen:
45
+ seen.add(link.from_node.name)
46
+ stack.append(link.from_node)
47
+ return found
48
+
49
+
50
+ def vertex_colour_mix(node):
51
+ """A colour Mix that multiplies a Color Attribute in: the exporter keeps it as COLOR_0."""
52
+ if node.bl_idname != GLTF_MIX or getattr(node, 'data_type', '') != 'RGBA' or getattr(node, 'blend_type', '') != 'MULTIPLY':
53
+ return False
54
+ for socket in node.inputs:
55
+ for link in socket.links:
56
+ if link.from_node.bl_idname in ('ShaderNodeVertexColor', 'ShaderNodeAttribute'):
57
+ return True
58
+ return False
59
+
60
+
61
+ def dropped_nodes(objects):
62
+ report = []
63
+ seen = set()
64
+ for obj in objects:
65
+ for slot in getattr(obj, 'material_slots', []):
66
+ mat = slot.material
67
+ if mat is None or mat.name_full in seen:
68
+ continue
69
+ seen.add(mat.name_full)
70
+ if not getattr(mat, 'node_tree', None):
71
+ continue
72
+ nodes = sorted(set(node_problems(mat.node_tree, set())))
73
+ if nodes:
74
+ report.append({'material': mat.name, 'nodes': nodes})
75
+ return report
76
+
77
+
78
+ def export_options(filepath):
79
+ return dict(
80
+ filepath=filepath, export_format='GLB', use_selection=True, export_apply=True, export_yup=True,
81
+ export_texcoords=True, export_normals=True, export_materials='EXPORT', export_image_format='AUTO',
82
+ export_animations=True, export_cameras=False, export_lights=False, export_extras=False,
83
+ )
84
+
85
+
86
+ def export(out_tmp, selected, warnings):
87
+ opts = export_options(out_tmp)
88
+ for obj in bpy.context.view_layer.objects:
89
+ obj.select_set(False)
90
+ for obj in selected:
91
+ obj.select_set(True)
92
+ bpy.context.view_layer.objects.active = selected[0]
93
+ # An older 4.x exporter may not know an option; drop it and say so,
94
+ # rather than failing a model over a flag.
95
+ for _ in range(len(opts)):
96
+ try:
97
+ bpy.ops.export_scene.gltf(**opts)
98
+ return
99
+ except TypeError as e:
100
+ bad = next((k for k in opts if k != 'filepath' and f'"{k}"' in str(e)), None)
101
+ if bad is None:
102
+ raise
103
+ opts.pop(bad)
104
+ warnings.append(f'this Blender\'s glTF exporter has no option {bad}; exported without it')