@threenative/runtime-native 0.3.11 → 0.3.12

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.11",
3
+ "version": "0.3.12",
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.11"
83
+ "@threenative/playtest": "0.3.12"
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.11",
90
- "@threenative/assets": "0.3.12",
91
- "@threenative/three-native": "0.3.11"
89
+ "@threenative/core": "0.3.12",
90
+ "@threenative/assets": "0.3.13",
91
+ "@threenative/three-native": "0.3.12"
92
92
  },
93
93
  "scripts": {
94
94
  "deps:download": "node scripts/download-deps.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, "../..");
@@ -21,7 +21,7 @@ const assetsEntry = resolve(dirname(require.resolve("@threenative/assets/package
21
21
  // Player facades share source with sibling packages; installed packages need their resolved roots.
22
22
  const packageImports = { name: "native-player-packages", setup(builder) {
23
23
  builder.onResolve({ filter: /^\.\.\/\.\.\/\.\.\/\.\.\/(?:three-native|core)\/src\// }, (args) => {
24
- if (!args.importer.startsWith(`${player}/`)) return;
24
+ if (!args.importer.startsWith(`${player}${sep}`)) return;
25
25
  const [, name, source] = /^\.\.\/\.\.\/\.\.\/\.\.\/(three-native|core)\/(.+)$/.exec(args.path);
26
26
  return { path: resolve(name === "core" ? core : threeNative, source) };
27
27
  });
@@ -208,9 +208,14 @@ export async function bundleNativeEngine({ entry, outfile, boot = true, define =
208
208
  logLevel: "silent", outfile, sourcemap: "external", sourcesContent: true,
209
209
  plugins: [packageImports, { name: "native-engine", setup(builder) {
210
210
  builder.onResolve({ filter: /(?:^|\/)assets\.js$/ }, (args) => {
211
- if (args.importer.startsWith(`${resolve(core, "src")}/`))
211
+ if (args.importer.startsWith(`${resolve(core, "src")}${sep}`))
212
212
  return { path: resolve(player, "core-assets.mjs") };
213
213
  });
214
+ // The browser WebGPU upload lane; the engine uploads compressed textures itself.
215
+ builder.onResolve({ filter: /(?:^|\/)compressed-texture-preparation\.js$/ }, (args) => {
216
+ if (args.importer.startsWith(`${resolve(core, "src")}/`))
217
+ return { path: resolve(player, "core-compressed-texture-preparation.mjs") };
218
+ });
214
219
  builder.onResolve({ filter: /^tn:game$/ }, () => ({ path: "game", namespace: "native-game" }));
215
220
  builder.onLoad({ filter: /.*/, namespace: "native-game" }, () => ({ contents: code, resolveDir: repo }));
216
221
  builder.onResolve({ filter: /^@threenative\/core$/ }, () => ({ path: "core", namespace: "native-core" }));
@@ -280,11 +285,18 @@ export async function cookNativeEngineAssets({ project, outfile, source }) {
280
285
  const module = await import(`data:text/javascript;base64,${Buffer.from(built.outputFiles[0].text).toString("base64")}`);
281
286
  assets = module.default?.assets ?? {};
282
287
  }
283
- const { compileAssets } = await import(assetsEntry);
288
+ // A file URL: on Windows, `import("D:\\...")` reads `d:` as a URL scheme and throws (engine#612).
289
+ const { compileAssets } = await import(pathToFileURL(assetsEntry).href);
284
290
  await compileAssets({ cwd: project, config: { ...assets, ...(source && { source: resolve(source) }), nativePackage: true }, platform: "desktop",
285
291
  runtimeDecoders: { ktx2: false, meshopt: false } });
286
292
  const output = resolve(project, assets.output ?? "public", "native/assets.tnpk");
287
293
  const target = resolve(dirname(resolve(outfile)), "native/assets.tnpk");
294
+ // A game with no asset files gets no pack (TN_ASSETS_NATIVE_PACKAGE_EMPTY), and the player opens
295
+ // `native/assets.tnpk` only when the game asks for an asset, so shipping none is correct.
296
+ if (!existsSync(output)) {
297
+ await rm(target, { force: true });
298
+ return undefined;
299
+ }
288
300
  await mkdir(dirname(target), { recursive: true });
289
301
  await writeFile(target, await readFile(output));
290
302
  return target;
@@ -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
- captureConsole: async () => output.split(/\r?\n/u).filter(Boolean).map((text) => ({ text, type: /\b(?:Error|FAILED|FATAL)\b/u.test(text) ? 'error' : 'log' })),
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);
@@ -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
+ }
@@ -2,6 +2,7 @@ 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,6 +10,7 @@ import { definePropertyBinding } from "../../../../three-native/src/property-bin
9
10
  import { audio } from "./core-audio.mjs";
10
11
  export const {
11
12
  ACESFilmicToneMapping,
13
+ AddEquation,
12
14
  AdditiveBlending,
13
15
  AgXToneMapping,
14
16
  AmbientLight,
@@ -29,11 +31,16 @@ export const {
29
31
  ClampToEdgeWrapping,
30
32
  Color,
31
33
  ConeGeometry,
34
+ ConstantAlphaFactor,
35
+ ConstantColorFactor,
36
+ CustomBlending,
32
37
  CylinderGeometry,
33
38
  DepthTexture,
34
39
  DirectionalLight,
35
40
  DodecahedronGeometry,
36
41
  DoubleSide,
42
+ DstAlphaFactor,
43
+ DstColorFactor,
37
44
  DynamicDrawUsage,
38
45
  EquirectangularReflectionMapping,
39
46
  Euler,
@@ -63,12 +70,15 @@ export const {
63
70
  LoopRepeat,
64
71
  Matrix3,
65
72
  Matrix4,
73
+ MaxEquation,
66
74
  Mesh,
67
75
  MeshBasicMaterial,
68
76
  MeshLambertMaterial,
69
77
  MeshPhongMaterial,
70
78
  MeshPhysicalMaterial,
71
79
  MeshStandardMaterial,
80
+ MinEquation,
81
+ MultiplyBlending,
72
82
  NearestFilter,
73
83
  NeutralToneMapping,
74
84
  NoBlending,
@@ -78,6 +88,13 @@ export const {
78
88
  NumberKeyframeTrack,
79
89
  Object3D,
80
90
  OctahedronGeometry,
91
+ OneFactor,
92
+ OneMinusConstantAlphaFactor,
93
+ OneMinusConstantColorFactor,
94
+ OneMinusDstAlphaFactor,
95
+ OneMinusDstColorFactor,
96
+ OneMinusSrcAlphaFactor,
97
+ OneMinusSrcColorFactor,
81
98
  OrthographicCamera,
82
99
  PCFShadowMap,
83
100
  PCFSoftShadowMap,
@@ -93,6 +110,7 @@ export const {
93
110
  Raycaster,
94
111
  RenderTarget,
95
112
  RepeatWrapping,
113
+ ReverseSubtractEquation,
96
114
  RingGeometry,
97
115
  RoundedBoxGeometry,
98
116
  SRGBColorSpace,
@@ -106,7 +124,12 @@ export const {
106
124
  SpotLight,
107
125
  Sprite,
108
126
  SpriteMaterial,
127
+ SrcAlphaFactor,
128
+ SrcAlphaSaturateFactor,
129
+ SrcColorFactor,
109
130
  StaticDrawUsage,
131
+ SubtractEquation,
132
+ SubtractiveBlending,
110
133
  TorusGeometry,
111
134
  TorusKnotGeometry,
112
135
  TubeGeometry,
@@ -115,6 +138,7 @@ export const {
115
138
  Vector3,
116
139
  Vector4,
117
140
  VectorKeyframeTrack,
141
+ ZeroFactor,
118
142
  } = globalThis;
119
143
  // three's PropertyBinding statics and console function over the engine class (shared with Wasm).
120
144
  export const { PropertyBinding, getConsoleFunction, setConsoleFunction } = definePropertyBinding(
@@ -142,9 +166,6 @@ export const clone = (root) => skeletonUtils.clone(root);
142
166
 
143
167
  // three's BatchedMesh: an engine class (PRD-552), each geometry's instances drawn as one instanced mesh.
144
168
  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
169
  // three's InstancedBufferGeometry: an engine class, drawn instanceCount times.
149
170
  export const { InstancedBufferGeometry } = globalThis;
150
171
  // three exports the engine does not provide: refused at use, by name, as on Wasm (unsupportedExport).
@@ -200,6 +221,7 @@ for (const name of [
200
221
  };
201
222
  }
202
223
  defineTypeFlags(globalThis);
224
+ defineReleaseNoops(globalThis);
203
225
  const geometries = [
204
226
  BoxGeometry,
205
227
  CircleGeometry,
@@ -25,8 +25,10 @@ export const syncUniforms = live.sync;
25
25
  export const { float, int, uint, vec2, vec3, color } = constants;
26
26
  export const vec4 = markNormalTarget(constants.vec4, globalThis.tsl.normalView);
27
27
  export const Fn = withFnBuilder(globalThis.tsl.Fn);
28
+ // three's lights([...]) takes one array; each light crosses as its own engine object.
29
+ export const lights = (list = []) => globalThis.tsl.lights(...list);
28
30
  export const {
29
- atomicAdd, atomicStore, atomicLoad, Break, Continue, Return, log, lightShadowMatrix, attribute, uv, renderOutput, If, Loop, luminance, viewZToOrthographicDepth, viewZToPerspectiveDepth, logarithmicDepthToViewZ, vertexIndex,
31
+ atomicAdd, atomicStore, atomicLoad, Break, Continue, Return, Discard, log, lightShadowMatrix, attribute, uv, renderOutput, If, Loop, luminance, viewZToOrthographicDepth, viewZToPerspectiveDepth, logarithmicDepthToViewZ, vertexIndex,
30
32
  add, sub, mul, div, negate, lessThan, greaterThan, equal, lessThanEqual, greaterThanEqual, and, or, not, all, any, abs, sin, cos,
31
33
  floor, fract, sqrt, exp, exp2, log2, normalize, length, min, max, pow, step, dot,
32
34
  distance, cross, mix, clamp, smoothstep, select, positionLocal, positionWorld, positionWorldDirection,
@@ -117,3 +119,8 @@ export const Stack = unsupportedExport("Stack");
117
119
  export const getShadowMaterial = unsupportedExport("getShadowMaterial");
118
120
  export const shadow = unsupportedExport("shadow");
119
121
  export const shadowPositionWorld = unsupportedExport("shadowPositionWorld");
122
+ // Core's rough diffuse lighting model reads these on three's renderer only; the engine shades roughDiffuse in C++.
123
+ // biome-ignore lint/style/useNamingConvention: the name is three/tsl's export, which core imports.
124
+ export const F_Schlick = unsupportedExport("F_Schlick");
125
+ export const specularColor = unsupportedExport("specularColor");
126
+ export const specularF90 = unsupportedExport("specularF90");
@@ -29,12 +29,13 @@ import { defineTempNode } from "../../../../three-native/src/temp-node.ts";
29
29
  import { defineRendererUtils } from "../../../../three-native/src/renderer-utils.ts";
30
30
  import { GPU_STAGES, SHADOW_STAGE } from "../../../../three-native/src/gpu-stages.ts";
31
31
 
32
- export const { StorageTexture, MeshBasicNodeMaterial, MeshStandardNodeMaterial, SpriteNodeMaterial } = globalThis;
32
+ export const { StorageTexture, MeshBasicNodeMaterial, MeshStandardNodeMaterial, MeshPhysicalNodeMaterial, SpriteNodeMaterial } = globalThis;
33
33
  Object.setPrototypeOf(StorageTexture.prototype, globalThis.Texture.prototype);
34
34
  Object.setPrototypeOf(MeshBasicNodeMaterial.prototype, globalThis.MeshBasicMaterial.prototype);
35
35
  Object.setPrototypeOf(MeshStandardNodeMaterial.prototype, globalThis.MeshStandardMaterial.prototype);
36
+ Object.setPrototypeOf(MeshPhysicalNodeMaterial.prototype, globalThis.MeshPhysicalMaterial.prototype);
36
37
  Object.setPrototypeOf(SpriteNodeMaterial.prototype, globalThis.SpriteMaterial.prototype);
37
- for (const material of [MeshBasicNodeMaterial, MeshStandardNodeMaterial, SpriteNodeMaterial]) {
38
+ for (const material of [MeshBasicNodeMaterial, MeshStandardNodeMaterial, MeshPhysicalNodeMaterial, SpriteNodeMaterial]) {
38
39
  material.prototype.isNodeMaterial = true;
39
40
  material.prototype[`is${material.name}`] = true;
40
41
  }
@@ -65,8 +66,7 @@ function drawTarget(renderer, target, root, camera, deferred) {
65
66
  syncUniforms();
66
67
  renderer.library.apply(renderer.toneMapping);
67
68
  globalThis.tn.setRendererState(renderer); // the target clears to the renderer's current clear colour
68
- if (deferred) globalThis.tn.renderTarget(target, root, camera, true);
69
- else globalThis.tn.renderTarget(target, root, camera);
69
+ globalThis.tn.renderTarget(target, root, camera, deferred === true, renderer.autoClear !== false);
70
70
  }
71
71
 
72
72
  // Every offscreen PassNode plans its draw into its own target; the player records it in this frame, after the post
@@ -80,6 +80,8 @@ export class WebGPURenderer {
80
80
  // The native scene pass draws to the player-owned surface, not a retained frame target.
81
81
  supportsRetainedTargetSubrect = false;
82
82
  renderScale = 1;
83
+ // three's autoClear: false draws into a render target over its contents (the player's own frame always clears).
84
+ autoClear = true;
83
85
  get temporalUpscale() { return globalThis.tn.renderInfo().temporalUpscale === true; }
84
86
  setRenderScale(scale) {
85
87
  if (!Number.isFinite(scale) || scale < 0.25 || scale > 1)
@@ -219,6 +221,10 @@ export class WebGPURenderer {
219
221
  // it at the call, and readRenderTargetPixelsAsync reads it back once the GPU copy lands.
220
222
  defineRenderTargets(WebGPURenderer.prototype, (renderer) => ({
221
223
  draw: (target, root, camera) => drawTarget(renderer, target, root, camera),
224
+ clear: (target, color, depth) => {
225
+ globalThis.tn.setRendererState(renderer); // the clear colour
226
+ globalThis.tn.clearTarget(target, color, depth);
227
+ },
222
228
  read: (target, x, y, width, height) => globalThis.tn.readTarget(target, x, y, width, height),
223
229
  }));
224
230
  // three's QuadMesh over the engine Mesh (shared with the Wasm back end).
@@ -280,7 +286,6 @@ export const MeshLambertNodeMaterial = unsupportedExport("MeshLambertNodeMateria
280
286
  export const MeshMatcapNodeMaterial = unsupportedExport("MeshMatcapNodeMaterial");
281
287
  export const MeshNormalNodeMaterial = unsupportedExport("MeshNormalNodeMaterial");
282
288
  export const MeshPhongNodeMaterial = unsupportedExport("MeshPhongNodeMaterial");
283
- export const MeshPhysicalNodeMaterial = unsupportedExport("MeshPhysicalNodeMaterial");
284
289
  export const MeshToonNodeMaterial = unsupportedExport("MeshToonNodeMaterial");
285
290
 
286
291
  // three's BlendMode (renderers/common/BlendMode.js): the blend state an MRT output names through