oda-engine 0.0.0-stage → 0.1.0
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.
- package/README.md +151 -2
- package/bin/nowhere.mjs +352 -0
- package/lib/account.mjs +57 -0
- package/lib/agentModules.mjs +57 -0
- package/lib/devServer.mjs +351 -0
- package/lib/headless.mjs +231 -0
- package/lib/headlessPreview.mjs +212 -0
- package/lib/keys.mjs +517 -0
- package/lib/make.mjs +855 -0
- package/lib/mcp.mjs +537 -0
- package/lib/open.mjs +22 -0
- package/lib/preview.mjs +87 -0
- package/lib/previewRpc.mjs +134 -0
- package/lib/project.mjs +359 -0
- package/lib/publishFlow.mjs +90 -0
- package/lib/resources.mjs +50 -0
- package/lib/rules.mjs +60 -0
- package/lib/scaffold.mjs +42 -0
- package/lib/setup.mjs +59 -0
- package/lib/tools.mjs +668 -0
- package/package.json +51 -4
- package/template/game.config.json +9 -0
- package/template/scene.json +4 -0
- package/template/src/main.ts +11 -0
- package/vendor/DOCS.md +447 -0
- package/vendor/agent/appRun.mjs +520 -0
- package/vendor/agent/assets/brief.mjs +242 -0
- package/vendor/agent/assets/collider.mjs +531 -0
- package/vendor/agent/assets/environments/index.mjs +12 -0
- package/vendor/agent/assets/environments/worldlabs.mjs +161 -0
- package/vendor/agent/assets/fetch.mjs +168 -0
- package/vendor/agent/assets/footprint.mjs +13 -0
- package/vendor/agent/assets/gltf.mjs +547 -0
- package/vendor/agent/assets/hdr.mjs +269 -0
- package/vendor/agent/assets/imageOps.mjs +171 -0
- package/vendor/agent/assets/images/codex.mjs +307 -0
- package/vendor/agent/assets/images/fal.mjs +75 -0
- package/vendor/agent/assets/images/gemini.mjs +84 -0
- package/vendor/agent/assets/images/index.mjs +25 -0
- package/vendor/agent/assets/images/openai.mjs +75 -0
- package/vendor/agent/assets/images/stability.mjs +71 -0
- package/vendor/agent/assets/images/views.mjs +31 -0
- package/vendor/agent/assets/import.mjs +1352 -0
- package/vendor/agent/assets/inspect.mjs +465 -0
- package/vendor/agent/assets/jobs.mjs +196 -0
- package/vendor/agent/assets/ktx2.mjs +290 -0
- package/vendor/agent/assets/ledger.mjs +466 -0
- package/vendor/agent/assets/net.mjs +254 -0
- package/vendor/agent/assets/prices.json +39 -0
- package/vendor/agent/assets/providers/fal.mjs +115 -0
- package/vendor/agent/assets/providers/index.mjs +22 -0
- package/vendor/agent/assets/providers/meshy.mjs +119 -0
- package/vendor/agent/assets/providers/tripo.mjs +188 -0
- package/vendor/agent/assets/sources/ambientcg.mjs +129 -0
- package/vendor/agent/assets/sources/index.mjs +23 -0
- package/vendor/agent/assets/sources/polyhaven.mjs +237 -0
- package/vendor/agent/assets/sources/polypizza.mjs +121 -0
- package/vendor/agent/assets/splat.mjs +631 -0
- package/vendor/agent/assets/targets.mjs +122 -0
- package/vendor/agent/assets/tile.mjs +261 -0
- package/vendor/agent/assets/unzip.mjs +180 -0
- package/vendor/agent/blender/cleanup.py +360 -0
- package/vendor/agent/blender/convert.py +167 -0
- package/vendor/agent/blender/find.mjs +192 -0
- package/vendor/agent/blender/nw_export.py +104 -0
- package/vendor/agent/blender/nw_rubric.py +426 -0
- package/vendor/agent/blender/run.mjs +193 -0
- package/vendor/agent/blender/runner.py +252 -0
- package/vendor/agent/blender/sheet.py +743 -0
- package/vendor/agent/depth.mjs +134 -0
- package/vendor/agent/director/board.mjs +451 -0
- package/vendor/agent/director/contracts.mjs +663 -0
- package/vendor/agent/director/director.mjs +2365 -0
- package/vendor/agent/director/estimate.mjs +200 -0
- package/vendor/agent/director/gate.mjs +802 -0
- package/vendor/agent/director/limits.json +16 -0
- package/vendor/agent/director/methods.mjs +457 -0
- package/vendor/agent/director/policy.json +33 -0
- package/vendor/agent/director/prompts.mjs +244 -0
- package/vendor/agent/director/reading.mjs +341 -0
- package/vendor/agent/director/router.mjs +184 -0
- package/vendor/agent/director/seams.mjs +243 -0
- package/vendor/agent/director/session.mjs +643 -0
- package/vendor/agent/director/store.mjs +119 -0
- package/vendor/agent/director/taskGate.mjs +110 -0
- package/vendor/agent/director/teamLedger.mjs +118 -0
- package/vendor/agent/director/triage.mjs +63 -0
- package/vendor/agent/downloads.cjs +363 -0
- package/vendor/agent/flow.mjs +78 -0
- package/vendor/agent/guard.mjs +613 -0
- package/vendor/agent/host.mjs +1736 -0
- package/vendor/agent/language.mjs +58 -0
- package/vendor/agent/ledger.mjs +360 -0
- package/vendor/agent/locale.cjs +186 -0
- package/vendor/agent/loop/capacity.mjs +74 -0
- package/vendor/agent/loop/compose.mjs +127 -0
- package/vendor/agent/loop/gate.mjs +205 -0
- package/vendor/agent/loop/judge.mjs +189 -0
- package/vendor/agent/loop/levels.mjs +273 -0
- package/vendor/agent/loop/state.mjs +358 -0
- package/vendor/agent/notes.cjs +278 -0
- package/vendor/agent/pace.mjs +258 -0
- package/vendor/agent/panels.mjs +431 -0
- package/vendor/agent/prompt.mjs +342 -0
- package/vendor/agent/reference/board.mjs +410 -0
- package/vendor/agent/reference/compose.mjs +364 -0
- package/vendor/agent/reference/decode.mjs +56 -0
- package/vendor/agent/reference/facts.mjs +1874 -0
- package/vendor/agent/reference/png.mjs +107 -0
- package/vendor/agent/reference/records.mjs +63 -0
- package/vendor/agent/reference/web.mjs +252 -0
- package/vendor/agent/roles/artist.mjs +69 -0
- package/vendor/agent/roles/builder.mjs +79 -0
- package/vendor/agent/roles/checks.mjs +223 -0
- package/vendor/agent/roles/common.mjs +188 -0
- package/vendor/agent/roles/critic.mjs +171 -0
- package/vendor/agent/roles/index.mjs +39 -0
- package/vendor/agent/roles/modeller.mjs +142 -0
- package/vendor/agent/roles/qa.mjs +58 -0
- package/vendor/agent/roles/rubrics.mjs +79 -0
- package/vendor/agent/roles/sound.mjs +69 -0
- package/vendor/agent/rounds.cjs +333 -0
- package/vendor/agent/shared.mjs +284 -0
- package/vendor/agent/stopGate.mjs +574 -0
- package/vendor/agent/subagents.mjs +129 -0
- package/vendor/agent/tools/assets.mjs +499 -0
- package/vendor/agent/tools/blender.mjs +754 -0
- package/vendor/agent/tools/cards.mjs +479 -0
- package/vendor/agent/tools/choices.mjs +479 -0
- package/vendor/agent/tools/compose.mjs +74 -0
- package/vendor/agent/tools/environment.mjs +488 -0
- package/vendor/agent/tools/eyes.mjs +733 -0
- package/vendor/agent/tools/generate.mjs +338 -0
- package/vendor/agent/tools/guide.mjs +46 -0
- package/vendor/agent/tools/harness.mjs +193 -0
- package/vendor/agent/tools/image.mjs +643 -0
- package/vendor/agent/tools/index.mjs +162 -0
- package/vendor/agent/tools/look.mjs +578 -0
- package/vendor/agent/tools/loop.mjs +858 -0
- package/vendor/agent/tools/others.mjs +123 -0
- package/vendor/agent/tools/pictures.mjs +535 -0
- package/vendor/agent/tools/reference.mjs +366 -0
- package/vendor/agent/transcripts.mjs +118 -0
- package/vendor/agent-loop.mjs +602 -0
- package/vendor/agent-plugin/.claude-plugin/plugin.json +5 -0
- package/vendor/agent-plugin/skills/art-direction/SKILL.md +82 -0
- package/vendor/agent-plugin/skills/asset-legality/SKILL.md +101 -0
- package/vendor/agent-plugin/skills/asset-sources/SKILL.md +111 -0
- package/vendor/agent-plugin/skills/blender-modeling/SKILL.md +97 -0
- package/vendor/agent-plugin/skills/look-dev/SKILL.md +104 -0
- package/vendor/agent-plugin/skills/playtesting/SKILL.md +74 -0
- package/vendor/agent-plugin/skills/reference-loop/SKILL.md +102 -0
- package/vendor/agent-plugin/skills/sound-design/SKILL.md +60 -0
- package/vendor/agent-plugin/skills/style/SKILL.md +35 -0
- package/vendor/agent-plugin/skills/tsl-r185/SKILL.md +107 -0
- package/vendor/auth.cjs +570 -0
- package/vendor/build.cjs +953 -0
- package/vendor/catalog.json +455 -0
- package/vendor/connectors.cjs +688 -0
- package/vendor/eyes.mjs +733 -0
- package/vendor/gameExports.json +1390 -0
- package/vendor/git.cjs +222 -0
- package/vendor/models.json +57 -0
- package/vendor/publish.cjs +1018 -0
- package/vendor/refBoard.cjs +301 -0
- package/vendor/schema/dist/assets.d.ts +335 -0
- package/vendor/schema/dist/assets.js +439 -0
- package/vendor/schema/dist/brief.d.ts +357 -0
- package/vendor/schema/dist/brief.js +302 -0
- package/vendor/schema/dist/common.d.ts +9 -0
- package/vendor/schema/dist/common.js +13 -0
- package/vendor/schema/dist/config.d.ts +406 -0
- package/vendor/schema/dist/config.js +355 -0
- package/vendor/schema/dist/contract.d.ts +599 -0
- package/vendor/schema/dist/contract.js +1146 -0
- package/vendor/schema/dist/index.d.ts +14 -0
- package/vendor/schema/dist/index.js +21 -0
- package/vendor/schema/dist/look.d.ts +463 -0
- package/vendor/schema/dist/look.js +681 -0
- package/vendor/schema/dist/lookStats.d.ts +230 -0
- package/vendor/schema/dist/lookStats.js +768 -0
- package/vendor/schema/dist/pilot.d.ts +32 -0
- package/vendor/schema/dist/pilot.js +44 -0
- package/vendor/schema/dist/publish.d.ts +214 -0
- package/vendor/schema/dist/publish.js +291 -0
- package/vendor/schema/dist/scene.d.ts +75 -0
- package/vendor/schema/dist/scene.js +120 -0
- package/vendor/schema/dist/skyLight.d.ts +141 -0
- package/vendor/schema/dist/skyLight.js +436 -0
- package/vendor/schema/dist/style.d.ts +131 -0
- package/vendor/schema/dist/style.js +155 -0
- package/vendor/schema/package.json +1 -0
- package/vendor/selectionPrompt.mjs +51 -0
- package/vendor/useTools.mjs +195 -0
- package/vendor/userMessage.mjs +26 -0
- package/web-dist/assets/GaussianSplatUtils-CB77cP9U.js +1 -0
- package/web-dist/assets/KTX2Loader-6OIWUF7s.js +2 -0
- package/web-dist/assets/SPZLoader-zYj0Alfv.js +1 -0
- package/web-dist/assets/gaussianSplat-CJTI1sEh.js +1 -0
- package/web-dist/assets/index-CcjyyQco.css +1 -0
- package/web-dist/assets/index-DMyJcoZJ.js +693 -0
- package/web-dist/assets/meshopt_decoder.module-BvwdjiD3.js +1 -0
- package/web-dist/assets/zstddec.module-CfFeQW7d.js +1 -0
- package/web-dist/index.html +34 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
# The rubric sheet.py scores every export with, so a blockout says it is one
|
|
2
|
+
# in numbers before anyone looks at the sheets. Four scores from 1 to 5 and
|
|
3
|
+
# a few checks that are reported but not scored:
|
|
4
|
+
#
|
|
5
|
+
# silhouette from alpha masks of the front, side and top views: how far
|
|
6
|
+
# the outline is from a plain box (fill, outline complexity,
|
|
7
|
+
# holes)
|
|
8
|
+
# bevel from the geometry: the share of hard edges that are razor
|
|
9
|
+
# sharp (dihedral 75 degrees or more against all at 25 or more)
|
|
10
|
+
# materials distinct base colours, textures, normal maps
|
|
11
|
+
# budget triangles against the class budget (and far under it for a
|
|
12
|
+
# hero, which reads as a blockout)
|
|
13
|
+
#
|
|
14
|
+
# fixFirst names the lowest score and what it measured. It never says what
|
|
15
|
+
# the model should be: that is the brief's and the agent's. Pure numpy and
|
|
16
|
+
# bmesh, no rendering here: sheet.py renders the masks.
|
|
17
|
+
|
|
18
|
+
import math
|
|
19
|
+
|
|
20
|
+
import bmesh
|
|
21
|
+
import numpy as np
|
|
22
|
+
|
|
23
|
+
# The schema's TRIANGLE_BUDGETS (packages/schema assets.ts); nw_blender
|
|
24
|
+
# passes the schema's own number as `budget`, and asset_import may not.
|
|
25
|
+
TRIANGLE_BUDGETS = {'small': 2000, 'prop': 5000, 'large': 20000, 'hero': 50000, 'character': 30000, 'building': 40000, 'terrain': 100000}
|
|
26
|
+
DETAILED = {'hero', 'character', 'building'}
|
|
27
|
+
|
|
28
|
+
SEGMENTS = {
|
|
29
|
+
0: (), 15: (),
|
|
30
|
+
1: (('left', 'bottom'),), 2: (('bottom', 'right'),), 3: (('left', 'right'),), 4: (('top', 'right'),),
|
|
31
|
+
5: (('left', 'bottom'), ('top', 'right')), 6: (('top', 'bottom'),), 7: (('left', 'top'),),
|
|
32
|
+
8: (('left', 'top'),), 9: (('top', 'bottom'),), 10: (('left', 'top'), ('bottom', 'right')),
|
|
33
|
+
11: (('top', 'right'),), 12: (('left', 'right'),), 13: (('bottom', 'right'),), 14: (('left', 'bottom'),),
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# ---------------------------------------------------------------- silhouette
|
|
38
|
+
|
|
39
|
+
def _crossing(p, q):
|
|
40
|
+
d = q - p
|
|
41
|
+
with np.errstate(divide='ignore', invalid='ignore'):
|
|
42
|
+
t = np.where(np.abs(d) > 1e-9, (0.5 - p) / d, 0.5)
|
|
43
|
+
return np.clip(t, 0.0, 1.0)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def contour_length(alpha, sx=1.0, sy=1.0):
|
|
47
|
+
"""The length of the 0.5 contour of an alpha image (marching squares, with
|
|
48
|
+
the crossing interpolated), x scaled by sx and y by sy."""
|
|
49
|
+
a = np.pad(alpha.astype(np.float64), 1)
|
|
50
|
+
tl, tr, bl, br = a[:-1, :-1], a[:-1, 1:], a[1:, :-1], a[1:, 1:]
|
|
51
|
+
case = (tl >= 0.5) * 8 + (tr >= 0.5) * 4 + (br >= 0.5) * 2 + (bl >= 0.5) * 1
|
|
52
|
+
points = {
|
|
53
|
+
'top': (_crossing(tl, tr), np.zeros_like(tl)),
|
|
54
|
+
'right': (np.ones_like(tl), _crossing(tr, br)),
|
|
55
|
+
'bottom': (_crossing(bl, br), np.ones_like(tl)),
|
|
56
|
+
'left': (np.zeros_like(tl), _crossing(tl, bl)),
|
|
57
|
+
}
|
|
58
|
+
total = 0.0
|
|
59
|
+
for c, segs in SEGMENTS.items():
|
|
60
|
+
if not segs:
|
|
61
|
+
continue
|
|
62
|
+
where = case == c
|
|
63
|
+
if not where.any():
|
|
64
|
+
continue
|
|
65
|
+
for e1, e2 in segs:
|
|
66
|
+
dx = (points[e1][0][where] - points[e2][0][where]) * sx
|
|
67
|
+
dy = (points[e1][1][where] - points[e2][1][where]) * sy
|
|
68
|
+
total += float(np.sqrt(dx * dx + dy * dy).sum())
|
|
69
|
+
return total
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def count_holes(inside, min_area):
|
|
73
|
+
"""Background regions the shape encloses (4-connected, not reaching the edge), at least min_area pixels."""
|
|
74
|
+
bg = np.pad(~inside, 1, constant_values=True)
|
|
75
|
+
h, w = bg.shape
|
|
76
|
+
seen = np.zeros_like(bg)
|
|
77
|
+
holes = 0
|
|
78
|
+
flat = bg.ravel()
|
|
79
|
+
seen_flat = seen.ravel()
|
|
80
|
+
for start in np.flatnonzero(flat):
|
|
81
|
+
if seen_flat[start]:
|
|
82
|
+
continue
|
|
83
|
+
stack = [start]
|
|
84
|
+
seen_flat[start] = True
|
|
85
|
+
size = 0
|
|
86
|
+
border = False
|
|
87
|
+
while stack:
|
|
88
|
+
i = stack.pop()
|
|
89
|
+
size += 1
|
|
90
|
+
y, x = divmod(i, w)
|
|
91
|
+
if y == 0 or x == 0 or y == h - 1 or x == w - 1:
|
|
92
|
+
border = True
|
|
93
|
+
for j in (i - 1, i + 1, i - w, i + w):
|
|
94
|
+
if 0 <= j < flat.size and flat[j] and not seen_flat[j]:
|
|
95
|
+
if (j == i - 1 and x == 0) or (j == i + 1 and x == w - 1):
|
|
96
|
+
continue
|
|
97
|
+
seen_flat[j] = True
|
|
98
|
+
stack.append(j)
|
|
99
|
+
if not border and size >= min_area:
|
|
100
|
+
holes += 1
|
|
101
|
+
return holes
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def mask_stats(alpha):
|
|
105
|
+
"""fill (area over its bounding box), complexity (perimeter squared over
|
|
106
|
+
4 pi area, measured with the bounding box made square, so a box of any
|
|
107
|
+
proportions is 1.27 and a disc 1.0) and holes; None for an empty mask."""
|
|
108
|
+
inside = alpha >= 0.5
|
|
109
|
+
if not inside.any():
|
|
110
|
+
return None
|
|
111
|
+
ys, xs = np.nonzero(inside)
|
|
112
|
+
w = int(xs.max() - xs.min() + 1)
|
|
113
|
+
h = int(ys.max() - ys.min() + 1)
|
|
114
|
+
area = int(inside.sum())
|
|
115
|
+
fill = area / float(w * h)
|
|
116
|
+
perimeter = contour_length(alpha, 1.0 / w, 1.0 / h)
|
|
117
|
+
complexity = perimeter * perimeter / (4 * math.pi * fill) if fill > 0 else 0.0
|
|
118
|
+
return {'fill': round(fill, 3), 'complexity': round(complexity, 3), 'holes': count_holes(inside, max(3, int(area * 0.002))), 'pixels': [w, h]}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def silhouette(views):
|
|
122
|
+
"""views: {'front': stats, 'side': stats, 'top': stats} (stats from mask_stats, None when empty)."""
|
|
123
|
+
stats = {k: v for k, v in views.items() if v is not None}
|
|
124
|
+
if not stats:
|
|
125
|
+
return {'score': None, 'note': 'no silhouette (the masks were empty)', 'views': views}
|
|
126
|
+
holes = {k for k, v in stats.items() if v['holes'] > 0}
|
|
127
|
+
c18 = {k for k, v in stats.items() if v['complexity'] > 1.8}
|
|
128
|
+
c25 = {k for k, v in stats.items() if v['complexity'] > 2.5}
|
|
129
|
+
f6 = {k for k, v in stats.items() if v['fill'] < 0.6}
|
|
130
|
+
boxy = all(v['complexity'] < 1.4 and v['holes'] == 0 and v['fill'] > 0.9 for v in stats.values())
|
|
131
|
+
if len(c25 | holes) >= 2 or len(f6) >= 2:
|
|
132
|
+
score = 5
|
|
133
|
+
elif len(c18 | holes) >= 2 or c25 or f6:
|
|
134
|
+
score = 4
|
|
135
|
+
elif c18 | holes:
|
|
136
|
+
score = 3
|
|
137
|
+
elif boxy:
|
|
138
|
+
score = 1
|
|
139
|
+
else:
|
|
140
|
+
score = 2
|
|
141
|
+
parts = [f'{k} {v["complexity"]:.2f}' for k, v in stats.items()]
|
|
142
|
+
hole_count = sum(v['holes'] for v in stats.values())
|
|
143
|
+
note = ', '.join(parts) + (f'; {hole_count} hole{"s" if hole_count != 1 else ""}' if hole_count else '; no holes')
|
|
144
|
+
if score == 1:
|
|
145
|
+
note = 'every view reads as a plain box: ' + note
|
|
146
|
+
return {'score': score, 'note': note, 'views': views}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
# ---------------------------------------------------------------- geometry
|
|
150
|
+
|
|
151
|
+
def _welded(obj, depsgraph):
|
|
152
|
+
ev = obj.evaluated_get(depsgraph)
|
|
153
|
+
mesh = ev.to_mesh()
|
|
154
|
+
try:
|
|
155
|
+
bm = bmesh.new()
|
|
156
|
+
bm.from_mesh(mesh)
|
|
157
|
+
bm.transform(ev.matrix_world)
|
|
158
|
+
finally:
|
|
159
|
+
ev.to_mesh_clear()
|
|
160
|
+
# glTF splits vertices at every UV seam and hard normal; welding by
|
|
161
|
+
# position puts the surface back together so edges have two faces.
|
|
162
|
+
bmesh.ops.remove_doubles(bm, verts=bm.verts[:], dist=1e-5)
|
|
163
|
+
return bm
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def geometry(objects, depsgraph):
|
|
167
|
+
"""Bevel numbers and the geometry checks, over the meshes in world space."""
|
|
168
|
+
hard = razor = 0.0
|
|
169
|
+
open_edges = non_manifold = flipped = inverted = shells = 0
|
|
170
|
+
for obj in objects:
|
|
171
|
+
if obj.type != 'MESH':
|
|
172
|
+
continue
|
|
173
|
+
bm = _welded(obj, depsgraph)
|
|
174
|
+
try:
|
|
175
|
+
for e in bm.edges:
|
|
176
|
+
faces = e.link_faces
|
|
177
|
+
n = len(faces)
|
|
178
|
+
if n == 1:
|
|
179
|
+
open_edges += 1
|
|
180
|
+
elif n > 2:
|
|
181
|
+
non_manifold += 1
|
|
182
|
+
elif n == 2:
|
|
183
|
+
la = next(l for l in e.link_loops if l.face == faces[0])
|
|
184
|
+
lb = next(l for l in e.link_loops if l.face == faces[1])
|
|
185
|
+
if la.vert == lb.vert:
|
|
186
|
+
flipped += 1
|
|
187
|
+
bmesh.ops.triangulate(bm, faces=bm.faces[:])
|
|
188
|
+
bm.normal_update()
|
|
189
|
+
for e in bm.edges:
|
|
190
|
+
if len(e.link_faces) != 2:
|
|
191
|
+
continue
|
|
192
|
+
angle = math.degrees(e.calc_face_angle(0.0))
|
|
193
|
+
if angle >= 25:
|
|
194
|
+
length = e.calc_length()
|
|
195
|
+
hard += length
|
|
196
|
+
if angle >= 75:
|
|
197
|
+
razor += length
|
|
198
|
+
# Closed shells with a negative volume are inside out.
|
|
199
|
+
bm.faces.ensure_lookup_table()
|
|
200
|
+
done = set()
|
|
201
|
+
for f in bm.faces:
|
|
202
|
+
if f.index in done:
|
|
203
|
+
continue
|
|
204
|
+
stack = [f]
|
|
205
|
+
done.add(f.index)
|
|
206
|
+
closed = True
|
|
207
|
+
volume = 0.0
|
|
208
|
+
while stack:
|
|
209
|
+
g = stack.pop()
|
|
210
|
+
a, b, c = (v.co for v in g.verts[:3])
|
|
211
|
+
volume += a.dot(b.cross(c)) / 6
|
|
212
|
+
for e in g.edges:
|
|
213
|
+
if len(e.link_faces) != 2:
|
|
214
|
+
closed = False
|
|
215
|
+
for h in e.link_faces:
|
|
216
|
+
if h.index not in done:
|
|
217
|
+
done.add(h.index)
|
|
218
|
+
stack.append(h)
|
|
219
|
+
if closed:
|
|
220
|
+
shells += 1
|
|
221
|
+
if volume < -1e-12:
|
|
222
|
+
inverted += 1
|
|
223
|
+
finally:
|
|
224
|
+
bm.free()
|
|
225
|
+
share = razor / hard if hard > 0 else 0.0
|
|
226
|
+
return {'hard_m': round(hard, 4), 'razor_m': round(razor, 4), 'share': round(share, 4), 'open': open_edges,
|
|
227
|
+
'non_manifold': non_manifold, 'flipped': flipped, 'inverted': inverted, 'shells': shells}
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def bevel(geo):
|
|
231
|
+
s = geo['share']
|
|
232
|
+
score = 5 if s <= 0.2 else 4 if s <= 0.4 else 3 if s <= 0.6 else 2 if s <= 0.8 else 1
|
|
233
|
+
if geo['hard_m'] <= 0:
|
|
234
|
+
return {'score': 5, 'note': 'no hard edges', 'share': 0.0}
|
|
235
|
+
return {'score': score, 'note': f'{round(s * 100)}% of hard edges razor-sharp', 'share': s}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
# ---------------------------------------------------------------- materials
|
|
239
|
+
|
|
240
|
+
def _lab(rgb):
|
|
241
|
+
"""CIE Lab (D65) from sRGB 0 to 1."""
|
|
242
|
+
lin = [c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4 for c in rgb]
|
|
243
|
+
x = (0.4124564 * lin[0] + 0.3575761 * lin[1] + 0.1804375 * lin[2]) / 0.95047
|
|
244
|
+
y = (0.2126729 * lin[0] + 0.7151522 * lin[1] + 0.0721750 * lin[2]) / 1.0
|
|
245
|
+
z = (0.0193339 * lin[0] + 0.1191920 * lin[1] + 0.9503041 * lin[2]) / 1.08883
|
|
246
|
+
|
|
247
|
+
def f(t):
|
|
248
|
+
return t ** (1 / 3) if t > 216 / 24389 else (24389 / 27 * t + 16) / 116
|
|
249
|
+
|
|
250
|
+
fx, fy, fz = f(x), f(y), f(z)
|
|
251
|
+
return (116 * fy - 16, 500 * (fx - fy), 200 * (fy - fz))
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def delta_e2000(lab1, lab2):
|
|
255
|
+
L1, a1, b1 = lab1
|
|
256
|
+
L2, a2, b2 = lab2
|
|
257
|
+
c1, c2 = math.hypot(a1, b1), math.hypot(a2, b2)
|
|
258
|
+
cm = (c1 + c2) / 2
|
|
259
|
+
g = 0.5 * (1 - math.sqrt(cm ** 7 / (cm ** 7 + 25 ** 7))) if cm > 0 else 0.5
|
|
260
|
+
a1p, a2p = a1 * (1 + g), a2 * (1 + g)
|
|
261
|
+
c1p, c2p = math.hypot(a1p, b1), math.hypot(a2p, b2)
|
|
262
|
+
h1p = math.degrees(math.atan2(b1, a1p)) % 360 if c1p else 0.0
|
|
263
|
+
h2p = math.degrees(math.atan2(b2, a2p)) % 360 if c2p else 0.0
|
|
264
|
+
dLp = L2 - L1
|
|
265
|
+
dCp = c2p - c1p
|
|
266
|
+
if c1p * c2p == 0:
|
|
267
|
+
dhp = 0.0
|
|
268
|
+
elif abs(h2p - h1p) <= 180:
|
|
269
|
+
dhp = h2p - h1p
|
|
270
|
+
elif h2p - h1p > 180:
|
|
271
|
+
dhp = h2p - h1p - 360
|
|
272
|
+
else:
|
|
273
|
+
dhp = h2p - h1p + 360
|
|
274
|
+
dHp = 2 * math.sqrt(c1p * c2p) * math.sin(math.radians(dhp / 2))
|
|
275
|
+
Lm = (L1 + L2) / 2
|
|
276
|
+
cmp_ = (c1p + c2p) / 2
|
|
277
|
+
if c1p * c2p == 0:
|
|
278
|
+
hm = h1p + h2p
|
|
279
|
+
elif abs(h1p - h2p) <= 180:
|
|
280
|
+
hm = (h1p + h2p) / 2
|
|
281
|
+
elif h1p + h2p < 360:
|
|
282
|
+
hm = (h1p + h2p + 360) / 2
|
|
283
|
+
else:
|
|
284
|
+
hm = (h1p + h2p - 360) / 2
|
|
285
|
+
t = 1 - 0.17 * math.cos(math.radians(hm - 30)) + 0.24 * math.cos(math.radians(2 * hm)) + 0.32 * math.cos(math.radians(3 * hm + 6)) - 0.20 * math.cos(math.radians(4 * hm - 63))
|
|
286
|
+
dtheta = 30 * math.exp(-(((hm - 275) / 25) ** 2))
|
|
287
|
+
rc = 2 * math.sqrt(cmp_ ** 7 / (cmp_ ** 7 + 25 ** 7)) if cmp_ > 0 else 0.0
|
|
288
|
+
sl = 1 + 0.015 * (Lm - 50) ** 2 / math.sqrt(20 + (Lm - 50) ** 2)
|
|
289
|
+
sc = 1 + 0.045 * cmp_
|
|
290
|
+
sh = 1 + 0.015 * cmp_ * t
|
|
291
|
+
rt = -math.sin(math.radians(2 * dtheta)) * rc
|
|
292
|
+
return math.sqrt((dLp / sl) ** 2 + (dCp / sc) ** 2 + (dHp / sh) ** 2 + rt * (dCp / sc) * (dHp / sh))
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def distinct_colours(colours, threshold=8.0):
|
|
296
|
+
kept = []
|
|
297
|
+
for rgb in colours:
|
|
298
|
+
lab = _lab(rgb)
|
|
299
|
+
if all(delta_e2000(lab, k) > threshold for k in kept):
|
|
300
|
+
kept.append(lab)
|
|
301
|
+
return len(kept)
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def materials(infos, klass):
|
|
305
|
+
"""infos: [{'name', 'rgb' (sRGB 0 to 1 or None), 'textured', 'normal', 'roughness', 'emission'}]."""
|
|
306
|
+
count = len(infos)
|
|
307
|
+
if not count:
|
|
308
|
+
return {'score': 1, 'note': 'no material', 'distinct': 0, 'count': 0, 'textured': False, 'normal': False}
|
|
309
|
+
distinct = distinct_colours([i['rgb'] for i in infos if i.get('rgb') is not None]) or 1
|
|
310
|
+
textured = any(i.get('textured') for i in infos)
|
|
311
|
+
normal = any(i.get('normal') for i in infos)
|
|
312
|
+
emission = any(i.get('emission') for i in infos)
|
|
313
|
+
rough = [i['roughness'] for i in infos if isinstance(i.get('roughness'), (int, float))]
|
|
314
|
+
spread = (max(rough) - min(rough)) if rough else 0.0
|
|
315
|
+
if distinct >= 3 and ((klass in DETAILED and (textured or normal)) or (textured and normal)):
|
|
316
|
+
score = 5
|
|
317
|
+
elif distinct >= 3 or (distinct >= 2 and (textured or normal)):
|
|
318
|
+
score = 4
|
|
319
|
+
elif distinct >= 2:
|
|
320
|
+
score = 3
|
|
321
|
+
elif textured or normal or spread >= 0.25 or emission:
|
|
322
|
+
score = 2
|
|
323
|
+
else:
|
|
324
|
+
score = 1
|
|
325
|
+
bits = [f'{distinct} distinct colour{"s" if distinct != 1 else ""} in {count} material{"s" if count != 1 else ""}']
|
|
326
|
+
bits.append('textures' if textured else 'no textures')
|
|
327
|
+
if normal:
|
|
328
|
+
bits.append('a normal map')
|
|
329
|
+
if emission:
|
|
330
|
+
bits.append('emission')
|
|
331
|
+
return {'score': score, 'note': ', '.join(bits), 'distinct': distinct, 'count': count, 'textured': textured,
|
|
332
|
+
'normal': normal, 'emission': emission, 'roughnessSpread': round(spread, 3)}
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
# ---------------------------------------------------------------- budget
|
|
336
|
+
|
|
337
|
+
def budget(triangles, klass, limit=None):
|
|
338
|
+
limit = int(limit or TRIANGLE_BUDGETS.get(klass, TRIANGLE_BUDGETS['prop']))
|
|
339
|
+
ratio = triangles / limit if limit else 0.0
|
|
340
|
+
tris = f'{triangles:,}'
|
|
341
|
+
if ratio <= 1.0:
|
|
342
|
+
score = 5
|
|
343
|
+
elif ratio <= 1.125:
|
|
344
|
+
score = 4
|
|
345
|
+
elif ratio <= 1.25:
|
|
346
|
+
score = 3
|
|
347
|
+
elif ratio <= 1.5:
|
|
348
|
+
score = 2
|
|
349
|
+
else:
|
|
350
|
+
score = 1
|
|
351
|
+
note = f'{tris} triangles, {klass} budget {limit:,}'
|
|
352
|
+
blockout = klass in DETAILED and ratio < 0.05
|
|
353
|
+
if blockout:
|
|
354
|
+
score = 2
|
|
355
|
+
note += ': this reads as a blockout'
|
|
356
|
+
elif ratio > 1:
|
|
357
|
+
note += f' ({ratio:.2f}x)'
|
|
358
|
+
return {'score': score, 'note': note, 'triangles': triangles, 'budget': limit, 'ratio': round(ratio, 4), 'blockout': blockout}
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
# ---------------------------------------------------------------- checks and the verdict
|
|
362
|
+
|
|
363
|
+
def checks(size, bounds, expect, geo, uv_problems, texel):
|
|
364
|
+
out = {}
|
|
365
|
+
if expect:
|
|
366
|
+
parts = []
|
|
367
|
+
ok = True
|
|
368
|
+
for key in ('height', 'width', 'depth'):
|
|
369
|
+
if key not in expect or not expect[key]:
|
|
370
|
+
continue
|
|
371
|
+
have = size[key]
|
|
372
|
+
want = float(expect[key])
|
|
373
|
+
off = have / want - 1 if want else 0.0
|
|
374
|
+
if abs(off) > 0.05:
|
|
375
|
+
ok = False
|
|
376
|
+
parts.append(f'{key} {have:.3g} m, expected {want:.3g} m ({abs(off) * 100:.0f}% {"over" if off > 0 else "under"})')
|
|
377
|
+
else:
|
|
378
|
+
parts.append(f'{key} {have:.3g} m as expected')
|
|
379
|
+
out['scale'] = {'ok': ok, 'note': '; '.join(parts) or 'nothing expected'}
|
|
380
|
+
else:
|
|
381
|
+
out['scale'] = {'ok': None, 'note': 'no expected size given'}
|
|
382
|
+
lo, hi = bounds['min'], bounds['max']
|
|
383
|
+
cx, cy = (lo[0] + hi[0]) / 2, (lo[1] + hi[1]) / 2
|
|
384
|
+
tol_x = max(0.001, 0.02 * (hi[0] - lo[0]))
|
|
385
|
+
tol_y = max(0.001, 0.02 * (hi[1] - lo[1]))
|
|
386
|
+
pivot_ok = abs(lo[2]) <= 0.01 and abs(cx) <= tol_x and abs(cy) <= tol_y
|
|
387
|
+
out['pivot'] = {'ok': pivot_ok, 'note': 'base centre at the origin' if pivot_ok else
|
|
388
|
+
f'lowest point at {lo[2]:.3f} m, footprint centre at ({cx:.3f}, {cy:.3f}) m; the studio stands models on their origin'}
|
|
389
|
+
out['manifold'] = {'ok': geo['open'] == 0 and geo['non_manifold'] == 0, 'open': geo['open'], 'nonManifold': geo['non_manifold']}
|
|
390
|
+
out['normals'] = {'ok': geo['flipped'] == 0 and geo['inverted'] == 0, 'flipped': geo['flipped'], 'inverted': geo['inverted']}
|
|
391
|
+
out['uvs'] = {'ok': not uv_problems, 'missing': uv_problems}
|
|
392
|
+
out['texel'] = texel
|
|
393
|
+
return out
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
def fix_first(parts, klass):
|
|
397
|
+
"""The lowest score, as 'name n/5: what it measured'."""
|
|
398
|
+
order = []
|
|
399
|
+
b = parts.get('budget')
|
|
400
|
+
if b and b['score'] is not None and not b.get('blockout') and b['score'] < 5:
|
|
401
|
+
order.append((b['score'], 0, 'budget'))
|
|
402
|
+
for i, name in enumerate(('bevel', 'silhouette', 'materials'), start=1):
|
|
403
|
+
p = parts.get(name)
|
|
404
|
+
if p and p.get('score') is not None:
|
|
405
|
+
order.append((p['score'], i, name))
|
|
406
|
+
if b and b.get('blockout'):
|
|
407
|
+
order.append((b['score'], 4, 'budget'))
|
|
408
|
+
if not order:
|
|
409
|
+
return 'unknown: nothing could be scored'
|
|
410
|
+
score, _, name = min(order)
|
|
411
|
+
if score >= 4:
|
|
412
|
+
return 'none: every score is 4/5 or more; look at the sheets for what the numbers cannot see'
|
|
413
|
+
p = parts[name]
|
|
414
|
+
if name == 'bevel':
|
|
415
|
+
return f'bevel {score}/5: {round(p["share"] * 100)}% of hard edges are razor-sharp (no bevel); round the edges the form has rounded'
|
|
416
|
+
if name == 'silhouette':
|
|
417
|
+
why = 'every view reads as a plain box' if score == 1 else f'the outline is simple ({p["note"]})'
|
|
418
|
+
return f'silhouette {score}/5: {why}; compare the outlines with the forms the brief and the reference give it'
|
|
419
|
+
if name == 'materials':
|
|
420
|
+
return f'materials {score}/5: {p["note"]}; compare each surface with the brief\'s materials'
|
|
421
|
+
target = int(b['budget'] * 0.9)
|
|
422
|
+
if b.get('blockout'):
|
|
423
|
+
return (f'budget {score}/5: {b["triangles"]:,} triangles is under 5% of the {klass} budget ({b["budget"]:,}), so this reads as a blockout; '
|
|
424
|
+
'compare its forms and detail with the brief\'s')
|
|
425
|
+
return (f'budget {score}/5: {b["triangles"]:,} triangles, {b["ratio"]:.2f}x the {klass} budget of {b["budget"]:,}; '
|
|
426
|
+
f'it needs to come down to about {target:,} (fewer segments and subdivision levels, or a Decimate modifier)')
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// Runs Blender without a window for nw_blender: one of our two Python
|
|
2
|
+
// programs (runner.py exports the agent's model, sheet.py renders it), with
|
|
3
|
+
// its arguments in a JSON file and its answer in another, never parsed from
|
|
4
|
+
// the output, which the agent's own prints and Blender's chatter share.
|
|
5
|
+
//
|
|
6
|
+
// Blender's Python can do anything the creator's account can, so it gets as
|
|
7
|
+
// little as possible: factory settings, no auto-run of scripts inside .blend
|
|
8
|
+
// files, no network access by add-ons, and an environment built from scratch,
|
|
9
|
+
// so no API key the studio holds reaches the agent's script.
|
|
10
|
+
|
|
11
|
+
import { spawn, execFile } from 'node:child_process'
|
|
12
|
+
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
13
|
+
import path from 'node:path'
|
|
14
|
+
|
|
15
|
+
export const BLENDER_FLAGS = ['-b', '--factory-startup', '--disable-autoexec', '--offline-mode', '--python-exit-code', '3']
|
|
16
|
+
|
|
17
|
+
/** The command line after the executable. */
|
|
18
|
+
export const blenderArgs = (script, argsFile) => [...BLENDER_FLAGS, '--python', script, '--', argsFile]
|
|
19
|
+
|
|
20
|
+
const KEEP_BYTES = 200 * 1024
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The only variables Blender sees. Windows needs a few of its own to start
|
|
24
|
+
* at all (SystemRoot above all), and a user folder for Blender's caches.
|
|
25
|
+
*/
|
|
26
|
+
export function blenderEnv(processEnv, cwd) {
|
|
27
|
+
const pick = (name) => {
|
|
28
|
+
if (processEnv[name] !== undefined) return processEnv[name]
|
|
29
|
+
const key = Object.keys(processEnv).find((k) => k.toLowerCase() === name.toLowerCase())
|
|
30
|
+
return key ? processEnv[key] : undefined
|
|
31
|
+
}
|
|
32
|
+
const env = {
|
|
33
|
+
PATH: pick('PATH') ?? '',
|
|
34
|
+
HOME: pick('HOME') ?? pick('USERPROFILE') ?? cwd,
|
|
35
|
+
TMPDIR: pick('TMPDIR') ?? pick('TEMP') ?? cwd,
|
|
36
|
+
LANG: 'en_US.UTF-8',
|
|
37
|
+
BLENDER_USER_CONFIG: path.join(cwd, 'config'),
|
|
38
|
+
BLENDER_USER_SCRIPTS: path.join(cwd, 'scripts'),
|
|
39
|
+
// The creator's own Python packages (~/.local/lib/python3.x) stay out of
|
|
40
|
+
// Blender's Python, as their add-ons and preferences do.
|
|
41
|
+
PYTHONNOUSERSITE: '1',
|
|
42
|
+
}
|
|
43
|
+
if (process.platform === 'win32') {
|
|
44
|
+
for (const name of ['SystemRoot', 'SystemDrive', 'TEMP', 'TMP', 'USERPROFILE', 'LOCALAPPDATA', 'APPDATA', 'PATHEXT', 'ComSpec']) {
|
|
45
|
+
const value = pick(name)
|
|
46
|
+
if (value !== undefined) env[name] = value
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return env
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Two at a time across the host: two blender-modeler helpers working side by
|
|
53
|
+
// side is the expected case, and a third run waits rather than slowing all of
|
|
54
|
+
// them down on a laptop.
|
|
55
|
+
const MAX_RUNNING = 2
|
|
56
|
+
let running = 0
|
|
57
|
+
const waiting = []
|
|
58
|
+
|
|
59
|
+
function acquire() {
|
|
60
|
+
if (running < MAX_RUNNING) {
|
|
61
|
+
running++
|
|
62
|
+
return Promise.resolve()
|
|
63
|
+
}
|
|
64
|
+
return new Promise((resolve) => waiting.push(resolve))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function release() {
|
|
68
|
+
const next = waiting.shift()
|
|
69
|
+
if (next) next()
|
|
70
|
+
else running--
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// The whole process tree goes: a script that started a process of its own
|
|
74
|
+
// would otherwise keep Blender's output open and the call waiting.
|
|
75
|
+
function kill(child) {
|
|
76
|
+
if (process.platform === 'win32') {
|
|
77
|
+
execFile('taskkill', ['/pid', String(child.pid), '/T', '/F'], { windowsHide: true }, () => {})
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
process.kill(-child.pid, 'SIGKILL')
|
|
82
|
+
} catch {
|
|
83
|
+
child.kill('SIGKILL')
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Blenders still running when the agent host goes (the creator stopped the
|
|
88
|
+
// request, the studio quit) would otherwise run on to their own timeout. A
|
|
89
|
+
// run that stopAll ended, or that was still waiting its turn, comes back
|
|
90
|
+
// stopped, so the caller does not take it for a crash and start another.
|
|
91
|
+
const live = new Set()
|
|
92
|
+
const stopped = new WeakSet()
|
|
93
|
+
let generation = 0
|
|
94
|
+
process.on('exit', () => stopAll())
|
|
95
|
+
|
|
96
|
+
/** Stops every Blender this process started that is still running. */
|
|
97
|
+
export function stopAll() {
|
|
98
|
+
generation++
|
|
99
|
+
for (const child of live) {
|
|
100
|
+
stopped.add(child)
|
|
101
|
+
kill(child)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Keeps the end of a stream: a traceback and the last warnings are at the end. */
|
|
106
|
+
function tail() {
|
|
107
|
+
let text = ''
|
|
108
|
+
let cut = false
|
|
109
|
+
return {
|
|
110
|
+
add(chunk) {
|
|
111
|
+
text += chunk
|
|
112
|
+
if (text.length > KEEP_BYTES) {
|
|
113
|
+
text = text.slice(-KEEP_BYTES)
|
|
114
|
+
cut = true
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
get: () => (cut ? `[earlier output cut]\n${text}` : text),
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @param {{ bin: string, script: string, args: object & { result: string }, cwd: string, timeoutMs?: number }} opts
|
|
123
|
+
* @returns {Promise<{ code: number | null, signal: string | null, stdout: string, stderr: string, result: object | null,
|
|
124
|
+
* ms: number, timedOut: boolean, argv: string[], error?: string, stopped?: true }>}
|
|
125
|
+
*/
|
|
126
|
+
export async function runBlender({ bin, script, args, cwd, timeoutMs = 240_000 }) {
|
|
127
|
+
const gen = generation
|
|
128
|
+
mkdirSync(cwd, { recursive: true })
|
|
129
|
+
const argsFile = path.join(cwd, `${path.basename(script, path.extname(script))}-args.json`)
|
|
130
|
+
writeFileSync(argsFile, JSON.stringify(args))
|
|
131
|
+
rmSync(args.result, { force: true })
|
|
132
|
+
const argv = blenderArgs(script, argsFile)
|
|
133
|
+
|
|
134
|
+
await acquire()
|
|
135
|
+
const started = Date.now()
|
|
136
|
+
try {
|
|
137
|
+
if (gen !== generation) {
|
|
138
|
+
return { code: null, signal: null, stdout: '', stderr: '', result: null, ms: 0, timedOut: false, argv, stopped: true }
|
|
139
|
+
}
|
|
140
|
+
const out = tail()
|
|
141
|
+
const err = tail()
|
|
142
|
+
const { code, signal, timedOut, error, wasStopped } = await new Promise((resolve) => {
|
|
143
|
+
let timedOut = false
|
|
144
|
+
let child
|
|
145
|
+
try {
|
|
146
|
+
// Its own process group on POSIX, so a timeout can stop all of it.
|
|
147
|
+
child = spawn(bin, argv, { cwd, env: blenderEnv(process.env, cwd), stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true, detached: process.platform !== 'win32' })
|
|
148
|
+
} catch (e) {
|
|
149
|
+
resolve({ code: null, signal: null, timedOut: false, error: e.message })
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
live.add(child)
|
|
153
|
+
child.stdout.setEncoding('utf8')
|
|
154
|
+
child.stderr.setEncoding('utf8')
|
|
155
|
+
child.stdout.on('data', out.add)
|
|
156
|
+
child.stderr.on('data', err.add)
|
|
157
|
+
const timer = setTimeout(() => {
|
|
158
|
+
timedOut = true
|
|
159
|
+
kill(child)
|
|
160
|
+
}, timeoutMs)
|
|
161
|
+
child.on('error', (e) => {
|
|
162
|
+
clearTimeout(timer)
|
|
163
|
+
live.delete(child)
|
|
164
|
+
resolve({ code: null, signal: null, timedOut, error: e.message })
|
|
165
|
+
})
|
|
166
|
+
child.on('close', (code, signal) => {
|
|
167
|
+
clearTimeout(timer)
|
|
168
|
+
live.delete(child)
|
|
169
|
+
resolve({ code, signal, timedOut, wasStopped: stopped.has(child) })
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
let result = null
|
|
173
|
+
try {
|
|
174
|
+
result = JSON.parse(readFileSync(args.result, 'utf8'))
|
|
175
|
+
} catch {
|
|
176
|
+
// Blender died before our Python wrote its answer; the caller reads the output.
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
code,
|
|
180
|
+
signal,
|
|
181
|
+
stdout: out.get(),
|
|
182
|
+
stderr: err.get(),
|
|
183
|
+
result,
|
|
184
|
+
ms: Date.now() - started,
|
|
185
|
+
timedOut,
|
|
186
|
+
argv,
|
|
187
|
+
...(error ? { error } : {}),
|
|
188
|
+
...(wasStopped ? { stopped: true } : {}),
|
|
189
|
+
}
|
|
190
|
+
} finally {
|
|
191
|
+
release()
|
|
192
|
+
}
|
|
193
|
+
}
|