@threenative/runtime-native 0.3.20 → 0.3.22

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threenative/runtime-native",
3
- "version": "0.3.20",
3
+ "version": "0.3.22",
4
4
  "description": "ThreeNative-owned native host for desktop and Android",
5
5
  "keywords": [
6
6
  "threenative",
@@ -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.20"
83
+ "@threenative/playtest": "0.3.22"
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/core": "0.3.20",
90
- "@threenative/assets": "0.3.21",
91
- "@threenative/three-native": "0.3.20"
89
+ "@threenative/core": "0.3.22",
90
+ "@threenative/assets": "0.3.23",
91
+ "@threenative/three-native": "0.3.22"
92
92
  },
93
93
  "scripts": {
94
94
  "deps:download": "node scripts/download-deps.mjs",
@@ -150,7 +150,7 @@ function unboundDiagnostic(specifier, name) {
150
150
  }
151
151
 
152
152
  /** Bundle the portable entry against native imports; publish nothing when a binding is absent. */
153
- export async function bundleNativeEngine({ entry, outfile, boot = true, define = {}, host = boot }) {
153
+ export async function bundleNativeEngine({ entry, outfile, boot = true, define = {}, host = boot, gameName, engine }) {
154
154
  // React and its reconciler branch on `process.env.NODE_ENV`; the player has no `process` (Vite defines it
155
155
  // on the desktop path, bundle.mjs). A caller's own define wins.
156
156
  define = { "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV ?? "production"), ...define };
@@ -244,6 +244,14 @@ export async function bundleNativeEngine({ entry, outfile, boot = true, define =
244
244
  return [facade, Object.values(result.metafile.outputs)[0].exports];
245
245
  })));
246
246
  const unresolved = new Map();
247
+ // PRD-905: the game's name and the engine drawing it, ahead of every module in the file, so a
248
+ // `TN_*` event reported from this bundle names the game instead of "unknown". Omitted when the
249
+ // caller has neither (the conformance and load-test bundles), and JSON.stringify escapes a name
250
+ // that carries a quote.
251
+ const brand = [
252
+ gameName === undefined ? undefined : `globalThis.__TN_GAME__ = ${JSON.stringify(gameName)};`,
253
+ engine === undefined ? undefined : `globalThis.__TN_ENGINE__ = ${JSON.stringify(engine)};`,
254
+ ].filter((line) => line !== undefined);
247
255
  const bundled = await build({
248
256
  stdin: { contents: boot
249
257
  ? `import ${JSON.stringify(resolve(player, "core-host.mjs"))}; import game from "tn:game"; globalThis.tn.__booting = true; void game.start().then(() => { globalThis.tn.__booting = false; game.ctx.renderer.render(game.ctx.scene, game.ctx.camera); }).catch(error => { globalThis.tn.__startupError = String(error.stack ?? error); });`
@@ -251,6 +259,7 @@ export async function bundleNativeEngine({ entry, outfile, boot = true, define =
251
259
  bundle: true, write: false, format: "iife", platform: "neutral", target: "es2022",
252
260
  conditions: ["threenative-native"], define: { "import.meta.env": "{}", ...define }, metafile: true,
253
261
  logLevel: "silent", outfile, sourcemap: "external", sourcesContent: true,
262
+ ...(brand.length > 0 && { banner: { js: brand.join("\n") } }),
254
263
  loader: { ".css": "empty" },
255
264
  plugins: [packageImports, { name: "native-engine", setup(builder) {
256
265
  builder.onResolve({ filter: /(?:^|\/)assets\.js$/ }, (args) => {
@@ -354,14 +363,15 @@ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.ur
354
363
  const args = process.argv.slice(2);
355
364
  const flags = new Map();
356
365
  for (let i = 0; i < args.length; i += 2) {
357
- if (!["--entry", "--out", "--engine", "--game-runtime", "--assets", "--asset-source"].includes(args[i]) || !args[i + 1] || flags.has(args[i]))
366
+ if (!["--entry", "--out", "--engine", "--engine-name", "--game-name", "--game-runtime", "--assets", "--asset-source"].includes(args[i]) || !args[i + 1] || flags.has(args[i]))
358
367
  throw new Error(`TN_NATIVE_ENGINE_ARGS: invalid or repeated option ${args[i]}`);
359
368
  flags.set(args[i], args[i + 1]);
360
369
  }
361
370
  if (flags.get("--engine") !== "native" || flags.get("--game-runtime") !== "v8" || !flags.get("--entry") || !flags.get("--out"))
362
- throw new Error("Usage: bundle-native-engine.mjs --engine native --game-runtime v8 --entry <src/game.ts> --out <game.js> [--assets <project dir> [--asset-source <dir>]]");
371
+ throw new Error("Usage: bundle-native-engine.mjs --engine native --game-runtime v8 --entry <src/game.ts> --out <game.js> [--assets <project dir> [--asset-source <dir>]] [--game-name <name> --engine-name <name>]");
363
372
  try {
364
- console.log(JSON.stringify(await bundleNativeEngine({ entry: flags.get("--entry"), outfile: flags.get("--out") })));
373
+ console.log(JSON.stringify(await bundleNativeEngine({ entry: flags.get("--entry"), outfile: flags.get("--out"),
374
+ gameName: flags.get("--game-name"), engine: flags.get("--engine-name") })));
365
375
  if (flags.has("--assets"))
366
376
  console.log(JSON.stringify({ assets: await cookNativeEngineAssets({ project: flags.get("--assets"), outfile: flags.get("--out"),
367
377
  source: flags.get("--asset-source") }) }));
@@ -235,7 +235,7 @@ function mobileDecoderStub(id, admitted) {
235
235
  /**
236
236
  * Main
237
237
  */
238
- async function bundleProject(project, entryPoint, outputPath, target, nativeBackend, decoders = []) {
238
+ async function bundleProject(project, entryPoint, outputPath, target, nativeBackend, decoders = [], brand = {}) {
239
239
  const absoluteProject = resolve(project);
240
240
  const absoluteEntry = resolve(absoluteProject, entryPoint);
241
241
  const absoluteOutput = resolve(outputPath);
@@ -252,6 +252,21 @@ async function bundleProject(project, entryPoint, outputPath, target, nativeBack
252
252
  throw new Error(`Cannot bundle '${absoluteProject}': its pinned Vite dependency is missing.`);
253
253
  }
254
254
  const { build } = await import(pathToFileURL(viteEntry).href);
255
+ // PRD-905: the game's name and the engine drawing it, as the web build's `withBootGlobals` writes
256
+ // them, so a `TN_*` event reported from this bundle names the game instead of "unknown". Written
257
+ // as the IIFE's first statements, ahead of every game module. `JSON.stringify` escapes whatever
258
+ // a name holds, and a native bundle is not HTML, so there is no tag for `<` to close.
259
+ const brandGlobals = [
260
+ brand.gameName === undefined
261
+ ? undefined
262
+ : `globalThis.__TN_GAME__ = ${JSON.stringify(brand.gameName)};`,
263
+ brand.engine === undefined
264
+ ? undefined
265
+ : `globalThis.__TN_ENGINE__ = ${JSON.stringify(brand.engine)};`,
266
+ ]
267
+ .filter((line) => line !== undefined)
268
+ .map((line) => `${line}\n`)
269
+ .join('');
255
270
  const nativePrelude = `
256
271
  const nativeElements = new Map();
257
272
  const nativeGetElementById = document.getElementById.bind(document);
@@ -375,7 +390,7 @@ void game.start().catch((error) => console.error(
375
390
  input: virtualEntry,
376
391
  output: {
377
392
  // `/*!` makes the scope marker a legal comment, the one class the minifier keeps.
378
- banner: `/*! TN_NATIVE_BUNDLE_SCOPE */\n(() => {\n${nativePrelude}`,
393
+ banner: `/*! TN_NATIVE_BUNDLE_SCOPE */\n(() => {\n${brandGlobals}${nativePrelude}`,
379
394
  codeSplitting: false,
380
395
  footer: '})();',
381
396
  // Vite's lib path defaults the minifier to `{ codegen: false }` for an ES lib, which
@@ -406,6 +421,8 @@ async function main() {
406
421
  let target = null;
407
422
  let nativeBackend = false;
408
423
  let decoders = [];
424
+ let gameName;
425
+ let engineName;
409
426
 
410
427
  for (let i = 0; i < args.length; i++) {
411
428
  if (args[i] === '--entry' && args[i + 1]) {
@@ -420,6 +437,10 @@ async function main() {
420
437
  target = args[++i];
421
438
  } else if (args[i] === '--native-backend') {
422
439
  nativeBackend = true;
440
+ } else if (args[i] === '--game-name' && args[i + 1]) {
441
+ gameName = args[++i];
442
+ } else if (args[i] === '--engine-name' && args[i + 1]) {
443
+ engineName = args[++i];
423
444
  } else if (args[i] === '--decoders' && args[i + 1] !== undefined) {
424
445
  decoders = args[++i].split(',').filter((codec) => codec.length > 0);
425
446
  const unknown = decoders.filter((codec) => !MOBILE_DECODER_STUBS.some((stub) => stub.codec === codec));
@@ -432,7 +453,10 @@ async function main() {
432
453
  if (!['android', 'desktop', 'ios'].includes(target)) {
433
454
  throw new Error('--project requires --target android|desktop|ios.');
434
455
  }
435
- await bundleProject(project, entryPoint, outputDir, target, nativeBackend, decoders);
456
+ await bundleProject(project, entryPoint, outputDir, target, nativeBackend, decoders, {
457
+ gameName,
458
+ engine: engineName,
459
+ });
436
460
  return;
437
461
  }
438
462
 
@@ -61,7 +61,7 @@ function samePath(left, right) {
61
61
  }
62
62
 
63
63
  export async function packageEngineDesktop(
64
- { project, entry, player, ui, output, buildReceipt, width = 1280, height = 720, title, priority = "game", fullscreen = true },
64
+ { project, entry, player, ui, output, buildReceipt, width = 1280, height = 720, title, priority = "game", fullscreen = true, gameName, engine },
65
65
  { bundle = bundleNativeEngine, cook = cookNativeEngineAssets } = {},
66
66
  ) {
67
67
  // An older CLI passes the canonical cache path without ever downloading it: this packager can
@@ -108,7 +108,7 @@ export async function packageEngineDesktop(
108
108
  rmSync(output, { force: true, recursive: true });
109
109
  mkdirSync(output, { recursive: true });
110
110
  const outfile = join(output, "game.js");
111
- const bundled = await bundle({ entry, outfile });
111
+ const bundled = await bundle({ entry, outfile, gameName, engine });
112
112
  await cook({ project, outfile });
113
113
  copyFileSync(player, join(output, PLAYER));
114
114
  chmodSync(join(output, PLAYER), 0o755);
@@ -180,7 +180,7 @@ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1]
180
180
  const args = process.argv.slice(2);
181
181
  const flags = new Map();
182
182
  for (let i = 0; i < args.length; i += 2) {
183
- if (!["--project", "--entry", "--player", "--ui", "--output", "--build-receipt", "--width", "--height", "--title", "--priority", "--fullscreen"].includes(args[i]) || !args[i + 1] || flags.has(args[i]))
183
+ if (!["--project", "--entry", "--player", "--ui", "--output", "--build-receipt", "--width", "--height", "--title", "--priority", "--fullscreen", "--game-name", "--engine-name"].includes(args[i]) || !args[i + 1] || flags.has(args[i]))
184
184
  throw new Error(`TN_ENGINE_PACKAGE_ARGS: invalid or repeated option ${args[i]}`);
185
185
  flags.set(args[i], args[i + 1]);
186
186
  }
@@ -195,6 +195,8 @@ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1]
195
195
  width: flags.has("--width") ? Number(flags.get("--width")) : undefined,
196
196
  height: flags.has("--height") ? Number(flags.get("--height")) : undefined,
197
197
  title: flags.get("--title"),
198
+ gameName: flags.get("--game-name"),
199
+ engine: flags.get("--engine-name"),
198
200
  priority: flags.get("--priority"),
199
201
  fullscreen: flags.has("--fullscreen") ? flags.get("--fullscreen") !== "false" : undefined,
200
202
  });
@@ -37,13 +37,13 @@ export const compute = (node, count, workgroupSize) =>
37
37
  // three's lights([...]) takes one array; each light crosses as its own engine object.
38
38
  export const lights = (list = []) => globalThis.tsl.lights(...list);
39
39
  export const {
40
- atomicAdd, atomicSub, atomicMax, atomicMin, atomicAnd, atomicOr, atomicXor, atomicStore, atomicLoad, Break, Continue, Return, Discard, log, lightShadowMatrix, attribute, uv, renderOutput, If, Loop, luminance, viewZToOrthographicDepth, viewZToPerspectiveDepth, logarithmicDepthToViewZ, vertexIndex,
40
+ atomicAdd, atomicSub, atomicMax, atomicMin, atomicAnd, atomicOr, atomicXor, atomicStore, atomicLoad, workgroupArray, workgroupBarrier, storageBarrier, textureBarrier, Break, Continue, Return, Discard, log, lightShadowMatrix, attribute, uv, renderOutput, If, Loop, luminance, viewZToOrthographicDepth, viewZToPerspectiveDepth, logarithmicDepthToViewZ, vertexIndex,
41
41
  add, sub, mul, div, negate, lessThan, greaterThan, equal, lessThanEqual, greaterThanEqual, and, or, not, all, any, abs, sin, cos,
42
42
  floor, fract, sqrt, exp, exp2, log2, normalize, length, min, max, pow, step, dot,
43
43
  distance, cross, mix, clamp, smoothstep, select, positionLocal, positionWorld, positionWorldDirection,
44
44
  normalViewGeometry, instanceIndex, cameraViewMatrix, modelWorldMatrix, ivec2, ivec3, ivec4, uvec2, uvec3, uvec4, nodeObject, reflect, textureLoad, textureSize,
45
45
  mx_noise_float, mx_worley_noise_float, mx_worley_noise_vec2, pmremTexture,
46
- convertToTexture, screenUV, materialColor, materialEmissive, materialMetalness, materialRoughness,
46
+ convertToTexture, screenUV, materialColor, materialEmissive, materialMetalness, materialRoughness, materialReferenceOpacity,
47
47
  cameraPosition, cameraProjectionMatrix, cameraWorldMatrix, positionGeometry, normalWorld, varying,
48
48
  cameraNear, cameraFar, screenSize, depth, viewportSharedTexture, viewportDepthTexture, linearDepth, viewportLinearDepth,
49
49
  } = globalThis.tsl;
@@ -79,9 +79,10 @@ export const { pass, PassNode, updateSecondaryPasses, mrt, output, normalView, m
79
79
 
80
80
  export const reflector = defineReflector(globalThis.tsl.reflector, { Object3D, PerspectiveCamera });
81
81
 
82
- // saturate, densityFogFactor, fog, context and velocity: plain JS over the engine's TSL functions,
82
+ // saturate, densityFogFactor, fog, context, velocity and materialReference: plain JS over the engine's TSL functions,
83
83
  // shared with the Wasm back end.
84
- export const { saturate, densityFogFactor, fog, context, velocity } = defineTslExtras({
84
+ export const { saturate, densityFogFactor, fog, context, velocity, materialReference } = defineTslExtras({
85
+ materialReferenceOpacity,
85
86
  get cameraNear() { return globalThis.tsl.cameraNear; },
86
87
  get cameraFar() { return globalThis.tsl.cameraFar; },
87
88
  clamp: (...args) => globalThis.tsl.clamp(...args),
@@ -1,4 +1,7 @@
1
1
  export * from "./core-three.mjs";
2
+ // three/webgpu's `TSL` is the three/tsl namespace, as upstream exports it.
3
+ // biome-ignore lint/style/useNamingConvention: three's export name.
4
+ export * as TSL from "./core-tsl.mjs";
2
5
  export { ShadowBaseNode } from "../../../../three-native/src/shadow-node.ts";
3
6
  import { detachVirtualShadow, shadowFilterOptions, virtualShadowOptions, syncVirtualShadowLods } from "../../../../three-native/src/shadow-node.ts";
4
7
  // Native VSM configuration crosses the same LightShadow registry setter as the Wasm facade.