@threenative/runtime-native 0.3.11 → 0.3.13
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/android/app/src/main/java/com/mystral/engine/MystralActivity.java +4 -1
- package/build/web/tn-native-engine-web-threads.mjs +1 -1
- package/build/web/tn-native-engine-web-threads.wasm +0 -0
- package/build/web/tn-native-engine-web.mjs +1 -1
- package/build/web/tn-native-engine-web.wasm +0 -0
- package/package.json +7 -7
- package/scripts/bundle-native-engine.mjs +64 -12
- package/scripts/desktop-distribution.mjs +3 -0
- package/scripts/package-android.mjs +2 -0
- package/scripts/package-engine-desktop.mjs +12 -6
- package/scripts/profile-production.mjs +2 -1
- package/scripts/verify-starter-desktop-base.mjs +9 -2
- package/src/engine/player/core-assets.mjs +30 -0
- package/src/engine/player/core-compressed-texture-preparation.mjs +16 -0
- package/src/engine/player/core-host.mjs +21 -2
- package/src/engine/player/core-three.mjs +83 -11
- package/src/engine/player/core-tsl.mjs +37 -9
- package/src/engine/player/core-unused.mjs +4 -0
- package/src/engine/player/core-webgpu.mjs +37 -12
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threenative/runtime-native",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.13",
|
|
4
4
|
"description": "ThreeNative-owned native host for desktop and Android",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"threenative",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/ThreeNativeHQ/threenative.git",
|
|
21
|
+
"url": "git+https://github.com/ThreeNativeHQ/threenative-engine.git",
|
|
22
22
|
"directory": "packages/runtime-native"
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
@@ -80,15 +80,15 @@
|
|
|
80
80
|
"publint": "0.3.22",
|
|
81
81
|
"three": "0.187.0",
|
|
82
82
|
"vitest": "4.1.10",
|
|
83
|
-
"@threenative/playtest": "0.3.
|
|
83
|
+
"@threenative/playtest": "0.3.13"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
86
|
"pngjs": "7.0.0",
|
|
87
87
|
"esbuild": "0.27.0",
|
|
88
88
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
89
|
-
"@threenative/
|
|
90
|
-
"@threenative/
|
|
91
|
-
"@threenative/
|
|
89
|
+
"@threenative/assets": "0.3.14",
|
|
90
|
+
"@threenative/three-native": "0.3.13",
|
|
91
|
+
"@threenative/core": "0.3.13"
|
|
92
92
|
},
|
|
93
93
|
"scripts": {
|
|
94
94
|
"deps:download": "node scripts/download-deps.mjs",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"native:physics:parity": "pnpm --dir ../.. exec vitest run packages/physics/__tests__/parity.spec.ts && cargo test --manifest-path native/physics/Cargo.toml --lib --test parity -- --nocapture",
|
|
106
106
|
"native:physics:parity:device": "node scripts/verify-android-physics-parity.mjs",
|
|
107
107
|
"native:qualify:physical": "node scripts/qualify-physical-mobile.mjs",
|
|
108
|
-
"native:verify:desktop": "node scripts/verify-desktop-audio.mjs && node scripts/verify-desktop-stability.mjs && node scripts/verify-desktop-core.mjs && node scripts/verify-desktop-physics.mjs && sh ../../scripts/xvfb.sh node scripts/verify-native-contracts.mjs && pnpm --dir ../playtest build && sh ../../scripts/xvfb.sh node scripts/verify-desktop-loading.mjs && sh ../../scripts/xvfb.sh node scripts/verify-desktop-ui-frame.mjs && vitest run --config vitest.config.ts tests/external-bundle-discovery.test.mjs",
|
|
108
|
+
"native:verify:desktop": "node scripts/verify-desktop-audio.mjs && node scripts/verify-desktop-stability.mjs && node scripts/verify-desktop-core.mjs && node scripts/verify-desktop-physics.mjs && sh ../../scripts/xvfb.sh node scripts/verify-native-contracts.mjs && pnpm --dir ../playtest build && sh ../../scripts/xvfb.sh node scripts/verify-desktop-loading.mjs && sh ../../scripts/xvfb.sh node scripts/verify-desktop-ui-frame.mjs && vitest run --config vitest.config.ts tests/external-bundle-discovery.test.mjs tests/host-cli.test.mjs tests/host-window.test.mjs",
|
|
109
109
|
"native:verify:metahuman": "node scripts/verify-desktop-metahuman.mjs",
|
|
110
110
|
"native:verify:loading": "pnpm --dir ../playtest build && sh ../../scripts/xvfb.sh node scripts/verify-desktop-loading.mjs",
|
|
111
111
|
"native:verify:ui-frame": "pnpm --dir ../playtest build && sh ../../scripts/xvfb.sh node scripts/verify-desktop-ui-frame.mjs",
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { execFileSync } from "node:child_process";
|
|
5
5
|
import { existsSync, realpathSync, readFileSync } from "node:fs";
|
|
6
|
-
import { readFile, mkdir, writeFile, rename, unlink } from "node:fs/promises";
|
|
6
|
+
import { readFile, mkdir, rm, writeFile, rename, unlink } from "node:fs/promises";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
|
-
import { dirname, resolve } from "node:path";
|
|
9
|
-
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { dirname, resolve, sep } from "node:path";
|
|
9
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
10
10
|
|
|
11
11
|
const native = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
12
12
|
const repo = resolve(native, "../..");
|
|
@@ -15,20 +15,49 @@ const require = createRequire(resolve(native, "package.json"));
|
|
|
15
15
|
const { build } = require("esbuild");
|
|
16
16
|
const ts = require("typescript");
|
|
17
17
|
const core = dirname(require.resolve("@threenative/core/package.json"));
|
|
18
|
+
// A core subpath bundles from the source its package export names: "./spells" -> dist/spells/index.js
|
|
19
|
+
// -> src/spells/index.ts. Guessing src/<last segment>.ts missed the nested spells entries.
|
|
20
|
+
export function coreSubpathSource(coreDir, specifier) {
|
|
21
|
+
try {
|
|
22
|
+
return coreSourcePath(specifier, coreDir);
|
|
23
|
+
} catch (failure) {
|
|
24
|
+
// The mapping rule lives in `coreSourcePath`; this keeps the name and the code #621's test pins.
|
|
25
|
+
const reason = failure instanceof Error ? failure.message : String(failure);
|
|
26
|
+
throw new Error(`TN_NATIVE_ENGINE_UNBOUND: ${specifier} [${reason}]`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
18
29
|
const threeNative = dirname(require.resolve("@threenative/three-native/package.json"));
|
|
19
30
|
const assetsEntry = resolve(dirname(require.resolve("@threenative/assets/package.json")), "dist/index.js");
|
|
20
31
|
|
|
21
32
|
// Player facades share source with sibling packages; installed packages need their resolved roots.
|
|
22
33
|
const packageImports = { name: "native-player-packages", setup(builder) {
|
|
23
34
|
builder.onResolve({ filter: /^\.\.\/\.\.\/\.\.\/\.\.\/(?:three-native|core)\/src\// }, (args) => {
|
|
24
|
-
if (!args.importer.startsWith(`${player}
|
|
35
|
+
if (!args.importer.startsWith(`${player}${sep}`)) return;
|
|
25
36
|
const [, name, source] = /^\.\.\/\.\.\/\.\.\/\.\.\/(three-native|core)\/(.+)$/.exec(args.path);
|
|
26
37
|
return { path: resolve(name === "core" ? core : threeNative, source) };
|
|
27
38
|
});
|
|
28
39
|
} };
|
|
29
40
|
|
|
30
|
-
|
|
31
|
-
|
|
41
|
+
/**
|
|
42
|
+
* The source file behind one `@threenative/core/<subpath>` import.
|
|
43
|
+
*
|
|
44
|
+
* The native player bundles source, so the subpath maps through the package's own `exports`: the
|
|
45
|
+
* published target `./dist/render-environment.js` is written from `src/render-environment.ts`.
|
|
46
|
+
* Reading the last path segment as the file name is what broke every kit that imports
|
|
47
|
+
* `@threenative/core/render/environment` after PRD-833 moved the module: it asked for
|
|
48
|
+
* `src/environment.ts`, which does not exist, and the desktop build died on that read.
|
|
49
|
+
*/
|
|
50
|
+
export function coreSourcePath(specifier, root = core) {
|
|
51
|
+
const subpath = specifier.replace(/^@threenative\/core\//u, "");
|
|
52
|
+
const manifest = JSON.parse(readFileSync(resolve(root, "package.json"), "utf8"));
|
|
53
|
+
const exported = manifest.exports?.[`./${subpath}`];
|
|
54
|
+
const target = typeof exported === "string" ? exported : exported?.import;
|
|
55
|
+
if (typeof target !== "string")
|
|
56
|
+
throw new Error(`TN_NATIVE_ENGINE_CORE_SUBPATH: @threenative/core/${subpath} is not exported.`);
|
|
57
|
+
return resolve(root, "src", target.replace(/^\.\/dist\//u, "").replace(/\.js$/u, ".ts"));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function rejectUpstream(metafile) { const upstream = Object.keys(metafile.inputs).filter((file) => /(?:^|\/)node_modules\/three\//.test(file));
|
|
32
61
|
if (upstream.length) throw new Error(`TN_NATIVE_ENGINE_UPSTREAM: ${upstream.join(", ")}`);
|
|
33
62
|
}
|
|
34
63
|
|
|
@@ -114,6 +143,9 @@ function unboundDiagnostic(specifier, name) {
|
|
|
114
143
|
|
|
115
144
|
/** Bundle the portable entry against native imports; publish nothing when a binding is absent. */
|
|
116
145
|
export async function bundleNativeEngine({ entry, outfile, boot = true, define = {}, host = boot }) {
|
|
146
|
+
// React and its reconciler branch on `process.env.NODE_ENV`; the player has no `process` (Vite defines it
|
|
147
|
+
// on the desktop path, bundle.mjs). A caller's own define wins.
|
|
148
|
+
define = { "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV ?? "production"), ...define };
|
|
117
149
|
let engineCommit;
|
|
118
150
|
try {
|
|
119
151
|
const git = (args) => execFileSync("git", args, { cwd: repo, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
@@ -134,6 +166,9 @@ export async function bundleNativeEngine({ entry, outfile, boot = true, define =
|
|
|
134
166
|
external: ["three", "three/*", "three-mesh-bvh", "three-mesh-bvh/*",
|
|
135
167
|
"@threenative/core", "@threenative/core/*"],
|
|
136
168
|
logLevel: "silent", metafile: true, sourcemap: "inline", sourcesContent: true,
|
|
169
|
+
// A UI component imports its stylesheet; the native-css backend reads the extracted sheets from the
|
|
170
|
+
// ui dir, so in the JS realm the import is only a side effect (the desktop path is Vite's CSS split).
|
|
171
|
+
loader: { ".css": "empty" },
|
|
137
172
|
// A script entry that imports core's loader by relative path (the load test's Fox) would inline the
|
|
138
173
|
// browser loader and its GLTFLoader; it reads the cooked package like core's own imports do.
|
|
139
174
|
plugins: [packageImports, { name: "native-assets", setup(builder) {
|
|
@@ -189,8 +224,10 @@ export async function bundleNativeEngine({ entry, outfile, boot = true, define =
|
|
|
189
224
|
"three/addons/loaders/LUTCubeLoader.js": resolve(player, "core-lut.mjs"),
|
|
190
225
|
"three/addons/loaders/HDRLoader.js": resolve(player, "core-hdr.mjs"),
|
|
191
226
|
"three-mesh-bvh": resolve(threeNative, "src/addons/mesh-bvh.ts"),
|
|
227
|
+
"three-mesh-bvh/webgpu": resolve(player, "core-unused.mjs"),
|
|
192
228
|
"three/addons/utils/BufferGeometryUtils.js": resolve(threeNative, "src/addons/buffer-geometry-utils.ts"),
|
|
193
229
|
"three/addons/geometries/DecalGeometry.js": resolve(threeNative, "src/addons/decal-geometry.ts"),
|
|
230
|
+
"three/addons/animation/CCDIKSolver.js": resolve(threeNative, "src/addons/ccd-ik-solver.ts"),
|
|
194
231
|
};
|
|
195
232
|
const exports = new Map(await Promise.all(Object.values(modules).map(async (facade) => {
|
|
196
233
|
// A facade's own exports; `three` inside one (an addon over the engine) is the facade above.
|
|
@@ -206,17 +243,23 @@ export async function bundleNativeEngine({ entry, outfile, boot = true, define =
|
|
|
206
243
|
bundle: true, write: false, format: "iife", platform: "neutral", target: "es2022",
|
|
207
244
|
conditions: ["threenative-native"], define: { "import.meta.env": "{}", ...define }, metafile: true,
|
|
208
245
|
logLevel: "silent", outfile, sourcemap: "external", sourcesContent: true,
|
|
246
|
+
loader: { ".css": "empty" },
|
|
209
247
|
plugins: [packageImports, { name: "native-engine", setup(builder) {
|
|
210
248
|
builder.onResolve({ filter: /(?:^|\/)assets\.js$/ }, (args) => {
|
|
211
|
-
if (args.importer.startsWith(`${resolve(core, "src")}
|
|
249
|
+
if (args.importer.startsWith(`${resolve(core, "src")}${sep}`))
|
|
212
250
|
return { path: resolve(player, "core-assets.mjs") };
|
|
213
251
|
});
|
|
252
|
+
// The browser WebGPU upload lane; the engine uploads compressed textures itself.
|
|
253
|
+
builder.onResolve({ filter: /(?:^|\/)compressed-texture-preparation\.js$/ }, (args) => {
|
|
254
|
+
if (args.importer.startsWith(`${resolve(core, "src")}/`))
|
|
255
|
+
return { path: resolve(player, "core-compressed-texture-preparation.mjs") };
|
|
256
|
+
});
|
|
214
257
|
builder.onResolve({ filter: /^tn:game$/ }, () => ({ path: "game", namespace: "native-game" }));
|
|
215
258
|
builder.onLoad({ filter: /.*/, namespace: "native-game" }, () => ({ contents: code, resolveDir: repo }));
|
|
216
259
|
builder.onResolve({ filter: /^@threenative\/core$/ }, () => ({ path: "core", namespace: "native-core" }));
|
|
217
260
|
builder.onLoad({ filter: /.*/, namespace: "native-core" }, () => ({ contents: coreExports, resolveDir: repo }));
|
|
218
261
|
builder.onResolve({ filter: /^@threenative\/core\// }, (args) => ({
|
|
219
|
-
path:
|
|
262
|
+
path: coreSourcePath(args.path),
|
|
220
263
|
}));
|
|
221
264
|
builder.onResolve({ filter: /^(three(?:\/|$)|three-mesh-bvh(?:\/|$))/ }, async (args) => {
|
|
222
265
|
const source = args.namespace === "native-game" ? code : await readFile(args.importer, "utf8");
|
|
@@ -267,8 +310,10 @@ export async function bundleNativeEngine({ entry, outfile, boot = true, define =
|
|
|
267
310
|
|
|
268
311
|
/**
|
|
269
312
|
* Cooks a project's assets for the native engine beside the game bundle: its own `assets` config,
|
|
270
|
-
*
|
|
271
|
-
* the
|
|
313
|
+
* with the native package on, which the player reads from `<bundle dir>/native/assets.tnpk`.
|
|
314
|
+
* Meshopt stays on: the engine compiles the meshoptimizer decoders and its glTF loader decodes
|
|
315
|
+
* EXT/KHR_meshopt_compression (PRD-515). KTX2 is still refused (TN_NATIVE_KTX2_UNSUPPORTED), so its
|
|
316
|
+
* cook output is not kept. `source` overrides the config's source dir.
|
|
272
317
|
*/
|
|
273
318
|
export async function cookNativeEngineAssets({ project, outfile, source }) {
|
|
274
319
|
project = resolve(project);
|
|
@@ -280,11 +325,18 @@ export async function cookNativeEngineAssets({ project, outfile, source }) {
|
|
|
280
325
|
const module = await import(`data:text/javascript;base64,${Buffer.from(built.outputFiles[0].text).toString("base64")}`);
|
|
281
326
|
assets = module.default?.assets ?? {};
|
|
282
327
|
}
|
|
283
|
-
|
|
328
|
+
// A file URL: on Windows, `import("D:\\...")` reads `d:` as a URL scheme and throws (engine#612).
|
|
329
|
+
const { compileAssets } = await import(pathToFileURL(assetsEntry).href);
|
|
284
330
|
await compileAssets({ cwd: project, config: { ...assets, ...(source && { source: resolve(source) }), nativePackage: true }, platform: "desktop",
|
|
285
|
-
runtimeDecoders: { ktx2: false, meshopt:
|
|
331
|
+
runtimeDecoders: { ktx2: false, meshopt: true } });
|
|
286
332
|
const output = resolve(project, assets.output ?? "public", "native/assets.tnpk");
|
|
287
333
|
const target = resolve(dirname(resolve(outfile)), "native/assets.tnpk");
|
|
334
|
+
// A game with no asset files gets no pack (TN_ASSETS_NATIVE_PACKAGE_EMPTY), and the player opens
|
|
335
|
+
// `native/assets.tnpk` only when the game asks for an asset, so shipping none is correct.
|
|
336
|
+
if (!existsSync(output)) {
|
|
337
|
+
await rm(target, { force: true });
|
|
338
|
+
return undefined;
|
|
339
|
+
}
|
|
288
340
|
await mkdir(dirname(target), { recursive: true });
|
|
289
341
|
await writeFile(target, await readFile(output));
|
|
290
342
|
return target;
|
|
@@ -357,6 +357,9 @@ export function containerMetadata({ platform = process.platform, config }) {
|
|
|
357
357
|
` <key>CFBundleVersion</key><string>${xml(build)}</string>`,
|
|
358
358
|
` <key>CFBundleIconFile</key><string>${xml(slug)}</string>`,
|
|
359
359
|
' <key>LSMinimumSystemVersion</key><string>11.0</string>',
|
|
360
|
+
// PRD-859: macOS starts Game Mode for a fullscreen game (CPU and GPU priority, lower input latency).
|
|
361
|
+
' <key>LSApplicationCategoryType</key><string>public.app-category.games</string>',
|
|
362
|
+
' <key>LSSupportsGameMode</key><true/>',
|
|
360
363
|
' <key>NSHighResolutionCapable</key><true/>',
|
|
361
364
|
'</dict>',
|
|
362
365
|
'</plist>',
|
|
@@ -586,6 +586,8 @@ export function renderAndroidManifest(source, orientation = 'landscape') {
|
|
|
586
586
|
}
|
|
587
587
|
rendered = upsertApplicationMetadata(rendered, 'TN_KEEP_SCREEN_ON', String(config.display.keepScreenOn));
|
|
588
588
|
rendered = upsertApplicationMetadata(rendered, 'TN_MAX_FPS', String(config.display.maxFps));
|
|
589
|
+
// `display.priority` (PRD-859): the game thread's CPU priority; anything but "normal" ships the default.
|
|
590
|
+
rendered = upsertApplicationMetadata(rendered, 'TN_PRIORITY', config.display.priority === 'normal' ? 'normal' : 'game');
|
|
589
591
|
// `display.backgroundMode`. Carried as metadata beside the others so the activity can hand it to
|
|
590
592
|
// the native host, which decides whether the render loop parks when the player leaves. Fail
|
|
591
593
|
// closed on a value nobody defined: an unrecognized mode ships as 'pause'.
|
|
@@ -10,15 +10,20 @@ import { bundleNativeEngine, cookNativeEngineAssets } from "./bundle-native-engi
|
|
|
10
10
|
|
|
11
11
|
const PLAYER = "tn-native-engine-player-v8";
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The launcher: the window opens with the game's title and size, the player takes the game's CPU priority
|
|
15
|
+
* (`display.priority`, PRD-859), and every argument reaches the player.
|
|
16
|
+
*/
|
|
17
|
+
export function launcher(width, height, title, priority = "game") {
|
|
18
|
+
if (priority !== "game" && priority !== "normal") throw new Error(`TN_ENGINE_PACKAGE_ARGS: --priority must be game or normal, got ${priority}`);
|
|
15
19
|
return [
|
|
16
20
|
"#!/bin/sh",
|
|
17
21
|
'DIR=$(cd "$(dirname "$0")" && pwd)',
|
|
18
22
|
...(title ? [`TN_PLAYER_TITLE=\${TN_PLAYER_TITLE:-'${title.replaceAll("'", "'\\''")}'}`, "export TN_PLAYER_TITLE"] : []),
|
|
19
23
|
`: "\${TN_PLAYER_WIDTH:=${width}}"`,
|
|
20
24
|
`: "\${TN_PLAYER_HEIGHT:=${height}}"`,
|
|
21
|
-
|
|
25
|
+
`: "\${TN_PLAYER_PRIORITY:=${priority}}"`,
|
|
26
|
+
"export TN_PLAYER_WIDTH TN_PLAYER_HEIGHT TN_PLAYER_PRIORITY",
|
|
22
27
|
`exec "$DIR/${PLAYER}" "$DIR/game.js" "$@"`,
|
|
23
28
|
"",
|
|
24
29
|
].join("\n");
|
|
@@ -29,7 +34,7 @@ export function launcher(width, height, title) {
|
|
|
29
34
|
* and, for a web UI, `ui/`. `bundle` and `cook` are the engine bundler's, injectable for the unit test.
|
|
30
35
|
*/
|
|
31
36
|
export async function packageEngineDesktop(
|
|
32
|
-
{ project, entry, player, ui, output, buildReceipt, width = 1280, height = 720, title },
|
|
37
|
+
{ project, entry, player, ui, output, buildReceipt, width = 1280, height = 720, title, priority },
|
|
33
38
|
{ bundle = bundleNativeEngine, cook = cookNativeEngineAssets } = {},
|
|
34
39
|
) {
|
|
35
40
|
if (!player || !existsSync(player)) {
|
|
@@ -50,7 +55,7 @@ export async function packageEngineDesktop(
|
|
|
50
55
|
cpSync(ui, join(output, "ui"), { recursive: true });
|
|
51
56
|
}
|
|
52
57
|
const start = join(output, basename(output));
|
|
53
|
-
writeFileSync(start, launcher(width, height, title));
|
|
58
|
+
writeFileSync(start, launcher(width, height, title, priority));
|
|
54
59
|
chmodSync(start, 0o755);
|
|
55
60
|
if (buildReceipt) {
|
|
56
61
|
const receipt = JSON.parse(readFileSync(buildReceipt, "utf8"));
|
|
@@ -79,7 +84,7 @@ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1]
|
|
|
79
84
|
const args = process.argv.slice(2);
|
|
80
85
|
const flags = new Map();
|
|
81
86
|
for (let i = 0; i < args.length; i += 2) {
|
|
82
|
-
if (!["--project", "--entry", "--player", "--ui", "--output", "--build-receipt", "--width", "--height", "--title"].includes(args[i]) || !args[i + 1] || flags.has(args[i]))
|
|
87
|
+
if (!["--project", "--entry", "--player", "--ui", "--output", "--build-receipt", "--width", "--height", "--title", "--priority"].includes(args[i]) || !args[i + 1] || flags.has(args[i]))
|
|
83
88
|
throw new Error(`TN_ENGINE_PACKAGE_ARGS: invalid or repeated option ${args[i]}`);
|
|
84
89
|
flags.set(args[i], args[i + 1]);
|
|
85
90
|
}
|
|
@@ -94,6 +99,7 @@ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1]
|
|
|
94
99
|
width: flags.has("--width") ? Number(flags.get("--width")) : undefined,
|
|
95
100
|
height: flags.has("--height") ? Number(flags.get("--height")) : undefined,
|
|
96
101
|
title: flags.get("--title"),
|
|
102
|
+
priority: flags.get("--priority"),
|
|
97
103
|
});
|
|
98
104
|
} catch (error) {
|
|
99
105
|
console.error(error instanceof Error ? error.message : String(error));
|
|
@@ -970,7 +970,8 @@ function createDesktopDriver(artifactPath, project, options, mailboxRoot, mailbo
|
|
|
970
970
|
let stopping;
|
|
971
971
|
const screenshotRequestPath = join(mailboxRoot, 'tn-playtest-screenshot-request.txt');
|
|
972
972
|
return {
|
|
973
|
-
|
|
973
|
+
// GLib supplies severity before its message, which can itself contain the word Error.
|
|
974
|
+
captureConsole: async () => output.split(/\r?\n/u).filter(Boolean).map((text) => ({ text, type: /^\s*(?:\*\* \([^)]*\): WARNING \*\*:|\([^)]*\): dbind-WARNING \*\*:)/u.test(text) ? 'warning' : /\b(?:Error|FAILED|FATAL)\b/u.test(text) ? 'error' : 'log' })),
|
|
974
975
|
isAlive: async () => child !== undefined && child.exitCode === null,
|
|
975
976
|
launch: async () => {
|
|
976
977
|
child = spawnNative(artifactPath, project, options, mailboxRoot);
|
|
@@ -331,8 +331,15 @@ function verifyOwnedDesktop({ frames, project, artifact, artifactDirectory, logP
|
|
|
331
331
|
TN_PLAYTEST_COMPLETION_WINDOW_TIMEOUT_MS: String(Math.max(1, timeout - 10_000)) },
|
|
332
332
|
});
|
|
333
333
|
writeFileSync(logPath, `${result.stdout ?? ''}\n${result.stderr ?? ''}`);
|
|
334
|
-
if (result.error || result.signal || result.status !== 0)
|
|
335
|
-
|
|
334
|
+
if (result.error || result.signal || result.status !== 0) {
|
|
335
|
+
// An empty-but-present stderr is still a string, so `??` never reached the exit status: every
|
|
336
|
+
// failed runner read `runner failed: (empty stderr)`, which names neither the status nor the
|
|
337
|
+
// log the run just wrote. PRD-840's native capture stopped here twice with nothing to read.
|
|
338
|
+
const output = `${result.stderr ?? ''}${result.stdout ?? ''}`.trim();
|
|
339
|
+
const why = result.error?.message ?? (result.signal ? `signal ${result.signal}` :
|
|
340
|
+
output.length > 0 ? output : `exit ${result.status}`);
|
|
341
|
+
throw new Error(`TN_NATIVE_STARTER_SMOKE: runner failed: ${why} (log: ${logPath})`);
|
|
342
|
+
}
|
|
336
343
|
const report = JSON.parse(result.stdout);
|
|
337
344
|
if (report?.pass !== true || !report.assertionResults?.length
|
|
338
345
|
|| report.assertionResults.some((assertion) => assertion.pass !== true))
|
|
@@ -66,5 +66,35 @@ export function createAssetLoader(options = {}) {
|
|
|
66
66
|
},
|
|
67
67
|
prefetch: async () => ({ requested: 0, requestedBytes: 0, settled: 0, settledBytes: 0 }),
|
|
68
68
|
startBackgroundFill: async () => {},
|
|
69
|
+
// core's memo (PRD-860) stores on the web Cache API; a native host has none, so `build` runs every time.
|
|
70
|
+
memo: async (key, build) => {
|
|
71
|
+
if (typeof key !== "string" || key === "") throw new Error("TN_ASSET_MEMO_INVALID: key must be a non-empty string.");
|
|
72
|
+
return build();
|
|
73
|
+
},
|
|
69
74
|
};
|
|
70
75
|
}
|
|
76
|
+
|
|
77
|
+
// core's fetchAsset, verbatim in behaviour: the player's fetch (core-host.mjs) reads `tnpk:` urls.
|
|
78
|
+
export async function fetchAsset(assets, path) {
|
|
79
|
+
const candidates = await assets.resolve(path);
|
|
80
|
+
const failures = [];
|
|
81
|
+
let answered = false;
|
|
82
|
+
let lastError;
|
|
83
|
+
for (const url of candidates) {
|
|
84
|
+
let response;
|
|
85
|
+
try {
|
|
86
|
+
response = await fetch(url);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
lastError = error;
|
|
89
|
+
failures.push(`${url} (${error instanceof Error ? error.message : String(error)})`);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
answered = true;
|
|
93
|
+
if (response.ok) return response;
|
|
94
|
+
failures.push(`${url} (status ${String(response.status)})`);
|
|
95
|
+
}
|
|
96
|
+
throw new Error(
|
|
97
|
+
`TN_ASSET_NOT_SERVED: '${path}' is not served by any of ${String(candidates.length)} candidate url(s): ${failures.join("; ") || "none"}.`,
|
|
98
|
+
answered || candidates.length === 0 ? undefined : { cause: lastError },
|
|
99
|
+
);
|
|
100
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Core's compressed upload lane writes through a browser WebGPU device. The engine uploads its own
|
|
2
|
+
// textures and exposes no such device, so the lane behaves as core's does with none: it owns
|
|
3
|
+
// nothing, and a compressed texture is refused with the same message.
|
|
4
|
+
export class CompressedTextureUploads {
|
|
5
|
+
resolveOriginal(texture) {
|
|
6
|
+
return texture;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
upload() {
|
|
10
|
+
return Promise.reject(
|
|
11
|
+
new Error("WebGPU renderer lacks bounded compressed texture preparation."),
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
dispose() {}
|
|
16
|
+
}
|
|
@@ -26,6 +26,10 @@ const pointerLock = (on) => {
|
|
|
26
26
|
};
|
|
27
27
|
// The legacy host installs the drawing surface as a global too; a script entry (the load test) reads it there.
|
|
28
28
|
globalThis.canvas = canvas;
|
|
29
|
+
// A page's window is an event target too, and a game may read its input there (`inputTarget: globalThis`):
|
|
30
|
+
// the player's input reaches the window's listeners as it reaches the canvas's.
|
|
31
|
+
globalThis.addEventListener = canvas.addEventListener;
|
|
32
|
+
globalThis.removeEventListener = canvas.removeEventListener;
|
|
29
33
|
canvas.requestPointerLock = () => pointerLock(true);
|
|
30
34
|
canvas.exitPointerLock = () => pointerLock(false);
|
|
31
35
|
// A real monotonic clock, as a page has: ticks and timers keep their fixed-step time, but
|
|
@@ -69,7 +73,21 @@ globalThis.__tnDispatchInput = (event) => {
|
|
|
69
73
|
for (const callback of [...(listeners.get(event.type) ?? [])]) callback(dom);
|
|
70
74
|
};
|
|
71
75
|
|
|
72
|
-
//
|
|
76
|
+
// `assets.resolve()` answers `tnpk:<path>` on the player, and a game reads that URL with fetch (procedural-animals
|
|
77
|
+
// loads its `.animal` packs so). This fetch serves the installed package's Buffer entries and nothing else: a
|
|
78
|
+
// network URL is refused by name, so the player still makes no request.
|
|
79
|
+
globalThis.fetch = async (input, init) => {
|
|
80
|
+
const url = typeof input === "string" ? input : String(input?.url ?? input);
|
|
81
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(url))
|
|
82
|
+
throw new TypeError(`TN_NATIVE_FETCH_NETWORK_UNSUPPORTED: ${url} (the native player reads only its installed package)`);
|
|
83
|
+
init?.signal?.throwIfAborted?.();
|
|
84
|
+
// core-textures' logicalPath, inlined: that module reads engine globals at import, which this host precedes.
|
|
85
|
+
const hash = url.indexOf("#");
|
|
86
|
+
const path = url.startsWith("tnpk:") ? url.slice(5) : hash < 0 ? url : url.slice(hash + 1);
|
|
87
|
+
return new Response(globalThis.tn.loadAsset("buffer", path).value, { url });
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// The player makes no network request. The runner's desktop network check needs the
|
|
73
91
|
// `runtime.network` capability and a `network` observation from the bridge core installs: report the honest
|
|
74
92
|
// zero, as playtest/src/three/device.ts does for the legacy host's retained fetch failures.
|
|
75
93
|
{
|
|
@@ -124,7 +142,8 @@ globalThis.tn.onUpdate((dt) => {
|
|
|
124
142
|
|
|
125
143
|
const readSize = () => ({ width: canvas.width, height: canvas.height, aspect: canvas.width / canvas.height });
|
|
126
144
|
export const platform = {
|
|
127
|
-
|
|
145
|
+
// The player's navigator.getGamepads (v8_main.cpp: scePad on PS4, SDL3 on desktop) in the W3C standard mapping.
|
|
146
|
+
input: () => globalThis.navigator?.getGamepads?.() ?? [],
|
|
128
147
|
inputTarget: canvas,
|
|
129
148
|
renderer: { createCanvas: () => canvas, hasWebGPU: () => true, readSize: () => [1280, 720], observeResize: () => () => {} },
|
|
130
149
|
viewport: { readSize, observeResize: () => () => {} },
|
|
@@ -2,13 +2,21 @@ import { unsupportedExport } from "../../../../three-native/src/refused.ts";
|
|
|
2
2
|
import {
|
|
3
3
|
Material,
|
|
4
4
|
defineObjectSurface,
|
|
5
|
+
defineReleaseNoops,
|
|
5
6
|
defineTypeFlags,
|
|
6
7
|
} from "../../../../three-native/src/object-surface.ts";
|
|
7
8
|
import { definePropertyBinding } from "../../../../three-native/src/property-binding.ts";
|
|
9
|
+
import { defineGridHelper } from "../../../../three-native/src/grid-helper.ts";
|
|
10
|
+
import { AnimationUtils, defineCreateInterpolant } from "../../../../three-native/src/animation-utils.ts";
|
|
11
|
+
import { defineBox2 } from "../../../../three-native/src/box2.ts";
|
|
12
|
+
import { defineTypedBufferAttribute } from "../../../../three-native/src/buffer-attributes.ts";
|
|
13
|
+
import { defineEdgesGeometry } from "../../../../three-native/src/edges-geometry.ts";
|
|
14
|
+
import { defineLayeredTargets } from "../../../../three-native/src/render-target.ts";
|
|
8
15
|
// Identity-preserving imports over the V8 adapter, never upstream Three.js.
|
|
9
16
|
import { audio } from "./core-audio.mjs";
|
|
10
17
|
export const {
|
|
11
18
|
ACESFilmicToneMapping,
|
|
19
|
+
AddEquation,
|
|
12
20
|
AdditiveBlending,
|
|
13
21
|
AgXToneMapping,
|
|
14
22
|
AmbientLight,
|
|
@@ -29,11 +37,18 @@ export const {
|
|
|
29
37
|
ClampToEdgeWrapping,
|
|
30
38
|
Color,
|
|
31
39
|
ConeGeometry,
|
|
40
|
+
ConstantAlphaFactor,
|
|
41
|
+
ConstantColorFactor,
|
|
42
|
+
CubeTexture,
|
|
43
|
+
CustomBlending,
|
|
32
44
|
CylinderGeometry,
|
|
45
|
+
DataArrayTexture,
|
|
33
46
|
DepthTexture,
|
|
34
47
|
DirectionalLight,
|
|
35
48
|
DodecahedronGeometry,
|
|
36
49
|
DoubleSide,
|
|
50
|
+
DstAlphaFactor,
|
|
51
|
+
DstColorFactor,
|
|
37
52
|
DynamicDrawUsage,
|
|
38
53
|
EquirectangularReflectionMapping,
|
|
39
54
|
Euler,
|
|
@@ -63,12 +78,15 @@ export const {
|
|
|
63
78
|
LoopRepeat,
|
|
64
79
|
Matrix3,
|
|
65
80
|
Matrix4,
|
|
81
|
+
MaxEquation,
|
|
66
82
|
Mesh,
|
|
67
83
|
MeshBasicMaterial,
|
|
68
84
|
MeshLambertMaterial,
|
|
69
85
|
MeshPhongMaterial,
|
|
70
86
|
MeshPhysicalMaterial,
|
|
71
87
|
MeshStandardMaterial,
|
|
88
|
+
MinEquation,
|
|
89
|
+
MultiplyBlending,
|
|
72
90
|
NearestFilter,
|
|
73
91
|
NeutralToneMapping,
|
|
74
92
|
NoBlending,
|
|
@@ -78,6 +96,13 @@ export const {
|
|
|
78
96
|
NumberKeyframeTrack,
|
|
79
97
|
Object3D,
|
|
80
98
|
OctahedronGeometry,
|
|
99
|
+
OneFactor,
|
|
100
|
+
OneMinusConstantAlphaFactor,
|
|
101
|
+
OneMinusConstantColorFactor,
|
|
102
|
+
OneMinusDstAlphaFactor,
|
|
103
|
+
OneMinusDstColorFactor,
|
|
104
|
+
OneMinusSrcAlphaFactor,
|
|
105
|
+
OneMinusSrcColorFactor,
|
|
81
106
|
OrthographicCamera,
|
|
82
107
|
PCFShadowMap,
|
|
83
108
|
PCFSoftShadowMap,
|
|
@@ -93,7 +118,10 @@ export const {
|
|
|
93
118
|
Raycaster,
|
|
94
119
|
RenderTarget,
|
|
95
120
|
RepeatWrapping,
|
|
121
|
+
ReverseSubtractEquation,
|
|
96
122
|
RingGeometry,
|
|
123
|
+
Points,
|
|
124
|
+
PointsMaterial,
|
|
97
125
|
RoundedBoxGeometry,
|
|
98
126
|
SRGBColorSpace,
|
|
99
127
|
Scene,
|
|
@@ -106,7 +134,12 @@ export const {
|
|
|
106
134
|
SpotLight,
|
|
107
135
|
Sprite,
|
|
108
136
|
SpriteMaterial,
|
|
137
|
+
SrcAlphaFactor,
|
|
138
|
+
SrcAlphaSaturateFactor,
|
|
139
|
+
SrcColorFactor,
|
|
109
140
|
StaticDrawUsage,
|
|
141
|
+
SubtractEquation,
|
|
142
|
+
SubtractiveBlending,
|
|
110
143
|
TorusGeometry,
|
|
111
144
|
TorusKnotGeometry,
|
|
112
145
|
TubeGeometry,
|
|
@@ -115,6 +148,7 @@ export const {
|
|
|
115
148
|
Vector3,
|
|
116
149
|
Vector4,
|
|
117
150
|
VectorKeyframeTrack,
|
|
151
|
+
ZeroFactor,
|
|
118
152
|
} = globalThis;
|
|
119
153
|
// three's PropertyBinding statics and console function over the engine class (shared with Wasm).
|
|
120
154
|
export const { PropertyBinding, getConsoleFunction, setConsoleFunction } = definePropertyBinding(
|
|
@@ -142,19 +176,45 @@ export const clone = (root) => skeletonUtils.clone(root);
|
|
|
142
176
|
|
|
143
177
|
// three's BatchedMesh: an engine class (PRD-552), each geometry's instances drawn as one instanced mesh.
|
|
144
178
|
export const { BatchedMesh } = globalThis;
|
|
145
|
-
// three's BatchedMesh/InstancedMesh.dispose frees the instance textures; the engine frees its instance
|
|
146
|
-
// buffers with the object, so the call has nothing to release (core's projection mirror makes it).
|
|
147
|
-
for (const instanced of [BatchedMesh, InstancedMesh]) instanced.prototype.dispose ??= function dispose() {};
|
|
148
179
|
// three's InstancedBufferGeometry: an engine class, drawn instanceCount times.
|
|
149
180
|
export const { InstancedBufferGeometry } = globalThis;
|
|
181
|
+
// three's GridHelper: engine LineSegments with vertex colours (shared definer, ported from three).
|
|
182
|
+
export const GridHelper = defineGridHelper(globalThis);
|
|
183
|
+
// three's EdgesGeometry, Box2, typed BufferAttributes and AnimationUtils: JS ports over engine classes,
|
|
184
|
+
// shared with the Wasm entry (PRD-784 P5-9).
|
|
185
|
+
export const EdgesGeometry = defineEdgesGeometry(globalThis);
|
|
186
|
+
export const Box2 = defineBox2(globalThis);
|
|
187
|
+
export const Uint8BufferAttribute = defineTypedBufferAttribute(BufferAttribute, Uint8Array);
|
|
188
|
+
export const Uint16BufferAttribute = defineTypedBufferAttribute(BufferAttribute, Uint16Array);
|
|
189
|
+
export const Uint32BufferAttribute = defineTypedBufferAttribute(BufferAttribute, Uint32Array);
|
|
190
|
+
export { AnimationUtils };
|
|
191
|
+
// three's track.createInterpolant over the engine tracks (shared with the Wasm entry, PRD-854).
|
|
192
|
+
defineCreateInterpolant(globalThis);
|
|
193
|
+
// three's flags on the engine's layered texture, as the Wasm entry sets them (texture-sources.ts).
|
|
194
|
+
Object.assign(DataArrayTexture.prototype, { isArrayTexture: true, isDataArrayTexture: true });
|
|
150
195
|
// three exports the engine does not provide: refused at use, by name, as on Wasm (unsupportedExport).
|
|
151
196
|
export const LineLoop = unsupportedExport("LineLoop");
|
|
152
|
-
export const Points = unsupportedExport("Points");
|
|
153
197
|
export const WebGLRenderer = unsupportedExport("WebGLRenderer");
|
|
198
|
+
export const CompressedArrayTexture = unsupportedExport("CompressedArrayTexture");
|
|
199
|
+
export const InstancedInterleavedBuffer = unsupportedExport("InstancedInterleavedBuffer");
|
|
200
|
+
export const TextureUtils = unsupportedExport("TextureUtils");
|
|
201
|
+
// three's CubeRenderTarget, RenderTarget3D and CubeCamera (shared with the Wasm back end).
|
|
202
|
+
export const { CubeRenderTarget, RenderTarget3D, CubeCamera } = defineLayeredTargets(globalThis);
|
|
154
203
|
export const { AudioContext, AudioListener, Audio, PositionalAudio, AudioLoader } = audio;
|
|
155
204
|
|
|
156
205
|
// Native traversal and child enumeration are host callbacks, not a second JS scene graph.
|
|
157
206
|
const bags = new WeakMap();
|
|
207
|
+
// three's userData is the game's object, kept with the wrapper; a game may also replace it (`x.userData = {...}`).
|
|
208
|
+
const userData = {
|
|
209
|
+
configurable: true,
|
|
210
|
+
get() {
|
|
211
|
+
if (!bags.has(this)) bags.set(this, {});
|
|
212
|
+
return bags.get(this);
|
|
213
|
+
},
|
|
214
|
+
set(value) {
|
|
215
|
+
bags.set(this, value);
|
|
216
|
+
},
|
|
217
|
+
};
|
|
158
218
|
for (const name of [
|
|
159
219
|
"Object3D",
|
|
160
220
|
"Scene",
|
|
@@ -175,6 +235,7 @@ for (const name of [
|
|
|
175
235
|
"Sprite",
|
|
176
236
|
"Line",
|
|
177
237
|
"LineSegments",
|
|
238
|
+
"Points",
|
|
178
239
|
]) {
|
|
179
240
|
const prototype = globalThis[name].prototype;
|
|
180
241
|
const parent = Object.getOwnPropertyDescriptor(prototype, "parent").get;
|
|
@@ -184,12 +245,7 @@ for (const name of [
|
|
|
184
245
|
return parent.call(this) ?? null;
|
|
185
246
|
},
|
|
186
247
|
},
|
|
187
|
-
userData
|
|
188
|
-
get() {
|
|
189
|
-
if (!bags.has(this)) bags.set(this, {});
|
|
190
|
-
return bags.get(this);
|
|
191
|
-
},
|
|
192
|
-
},
|
|
248
|
+
userData,
|
|
193
249
|
});
|
|
194
250
|
// The engine's walk (`__walk`, shared with the Wasm back end): one call for the whole subtree.
|
|
195
251
|
prototype.traverse = function (callback) {
|
|
@@ -200,6 +256,14 @@ for (const name of [
|
|
|
200
256
|
};
|
|
201
257
|
}
|
|
202
258
|
defineTypeFlags(globalThis);
|
|
259
|
+
defineReleaseNoops(globalThis);
|
|
260
|
+
// three gives Material, Texture and BufferGeometry a userData too: as on Wasm (browser-backend.ts), every engine
|
|
261
|
+
// class with a dispose method (prd493's terrain splat writes material.userData.TN_TERRAIN_SPLAT).
|
|
262
|
+
for (const name of Object.getOwnPropertyNames(globalThis)) {
|
|
263
|
+
const prototype = typeof globalThis[name] === "function" ? globalThis[name].prototype : undefined;
|
|
264
|
+
if (typeof prototype?.dispose === "function" && !Object.hasOwn(prototype, "userData"))
|
|
265
|
+
Object.defineProperty(prototype, "userData", userData);
|
|
266
|
+
}
|
|
203
267
|
const geometries = [
|
|
204
268
|
BoxGeometry,
|
|
205
269
|
CircleGeometry,
|
|
@@ -246,7 +310,7 @@ for (const [base, names] of [
|
|
|
246
310
|
[Mesh, [SkinnedMesh, InstancedMesh]],
|
|
247
311
|
[BufferGeometry, geometries],
|
|
248
312
|
[BufferAttribute, [Float32BufferAttribute, InstancedBufferAttribute]],
|
|
249
|
-
[Texture, [DepthTexture, DataTexture, globalThis.CanvasTexture]],
|
|
313
|
+
[Texture, [DepthTexture, DataTexture, DataArrayTexture, globalThis.CanvasTexture]],
|
|
250
314
|
[Path, [Shape]],
|
|
251
315
|
]) {
|
|
252
316
|
for (const derived of names) Object.setPrototypeOf(derived.prototype, base.prototype);
|
|
@@ -285,6 +349,7 @@ defineObjectSurface({
|
|
|
285
349
|
MeshPhysicalMaterial,
|
|
286
350
|
MeshStandardMaterial,
|
|
287
351
|
SpriteMaterial,
|
|
352
|
+
PointsMaterial,
|
|
288
353
|
],
|
|
289
354
|
});
|
|
290
355
|
export { Material };
|
|
@@ -301,3 +366,10 @@ export const GreaterEqualCompare = 518;
|
|
|
301
366
|
export const CustomToneMapping = 5;
|
|
302
367
|
export const AlwaysDepth = 1;
|
|
303
368
|
export const VSMShadowMap = 3;
|
|
369
|
+
// three's interpolation and animation blend constants (constants.js); the engine's keyframe track and
|
|
370
|
+
// AnimationClip constructors accept exactly these values.
|
|
371
|
+
export const InterpolateDiscrete = 2300;
|
|
372
|
+
export const InterpolateLinear = 2301;
|
|
373
|
+
export const InterpolateSmooth = 2302;
|
|
374
|
+
export const NormalAnimationBlendMode = 2500;
|
|
375
|
+
export const AdditiveAnimationBlendMode = 2501;
|