@threenative/three-native 0.3.12 → 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/package.json +1 -1
- package/src/addons/ccd-ik-solver.ts +170 -0
- package/src/addons/gltf-loader-web.ts +104 -17
- package/src/addons/screen-space.ts +20 -19
- package/src/animation-utils.ts +366 -0
- package/src/box2.ts +172 -0
- package/src/bridge-meter.ts +23 -9
- package/src/browser-abi-types.ts +232 -38
- package/src/browser-attribute-sync.ts +69 -0
- package/src/browser-backend.ts +71 -5
- package/src/browser-entry.ts +51 -12
- package/src/browser-loaders.ts +12 -0
- package/src/browser-renderer.ts +179 -112
- package/src/browser-tsl.ts +93 -16
- package/src/browser-value-views.ts +16 -0
- package/src/browser-wasm-runtime.ts +38 -13
- package/src/buffer-attributes.ts +19 -0
- package/src/compressed-texture.ts +116 -0
- package/src/debug-telemetry.ts +20 -6
- package/src/edges-geometry.ts +111 -0
- package/src/generated/console-markers.ts +13 -0
- package/src/generated/web-frame-fields.ts +84 -0
- package/src/gpu-stages.ts +17 -16
- package/src/grid-helper.ts +49 -0
- package/src/object-surface.ts +30 -6
- package/src/pass-node.ts +26 -6
- package/src/render-target.ts +478 -12
- package/src/shadow-node.ts +24 -1
- package/src/storage.ts +16 -5
- package/src/texture-sources.ts +12 -6
- package/src/tsl-uniforms.ts +146 -57
- package/src/update-ranges.ts +27 -1
package/src/browser-entry.ts
CHANGED
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
import catalogJson from "../api/catalog.json" with { type: "json" };
|
|
11
11
|
import registry from "../api/native-registry.json" with { type: "json" };
|
|
12
12
|
import { DataUtils } from "./addons/data-utils.js";
|
|
13
|
+
import { AnimationUtils, defineCreateInterpolant } from "./animation-utils.js";
|
|
13
14
|
import { type IAudioEngine, defineAudioClasses } from "./audio.js";
|
|
14
15
|
import { BlendMode } from "./blend-mode.js";
|
|
16
|
+
import { defineBox2 } from "./box2.js";
|
|
15
17
|
import {
|
|
16
18
|
type IBrowserRuntime,
|
|
17
19
|
type IRegistryDump,
|
|
@@ -20,6 +22,7 @@ import {
|
|
|
20
22
|
createWasmRuntime,
|
|
21
23
|
defineBrowserClasses,
|
|
22
24
|
} from "./browser-backend.js";
|
|
25
|
+
import { LOADERS } from "./browser-loaders.js";
|
|
23
26
|
import { ColorManagement } from "./browser-math.js";
|
|
24
27
|
import {
|
|
25
28
|
PIPELINE_POST,
|
|
@@ -29,8 +32,12 @@ import {
|
|
|
29
32
|
isWebHostModule,
|
|
30
33
|
} from "./browser-renderer.js";
|
|
31
34
|
import { type ITslRuntime, defineTsl, isTslNode } from "./browser-tsl.js";
|
|
35
|
+
import { defineTypedBufferAttribute } from "./buffer-attributes.js";
|
|
32
36
|
import type { CatalogEntry, ICatalog } from "./catalog.js";
|
|
37
|
+
import { defineEdgesGeometry } from "./edges-geometry.js";
|
|
38
|
+
import { WEB_FRAME_FIELD } from "./generated/web-frame-fields.js";
|
|
33
39
|
import { CPU_STAGE_FIELDS } from "./gpu-stages.js";
|
|
40
|
+
import { defineGridHelper } from "./grid-helper.js";
|
|
34
41
|
import { withMathUtilsExtras } from "./math-utils.js";
|
|
35
42
|
import {
|
|
36
43
|
Material,
|
|
@@ -42,6 +49,7 @@ import { type PassDraw, definePass } from "./pass-node.js";
|
|
|
42
49
|
import { definePropertyBinding } from "./property-binding.js";
|
|
43
50
|
import { defineQuadMesh } from "./quad-mesh.js";
|
|
44
51
|
import { defineReflector } from "./reflector.js";
|
|
52
|
+
import { defineLayeredTargets } from "./render-target.js";
|
|
45
53
|
import { defineRendererUtils } from "./renderer-utils.js";
|
|
46
54
|
import { ShadowBaseNode } from "./shadow-node.js";
|
|
47
55
|
import { ReadbackBuffer } from "./storage.js";
|
|
@@ -170,7 +178,7 @@ export async function bindWebEngine(
|
|
|
170
178
|
? () => {
|
|
171
179
|
const totals = { ...counters() };
|
|
172
180
|
// Off, the engine reads no clock and the totals stand at their last value: listing them would report a stale cost.
|
|
173
|
-
if (module._tnw_web_frame(
|
|
181
|
+
if (module._tnw_web_frame(WEB_FRAME_FIELD.cpuMetersActive) !== 0)
|
|
174
182
|
for (const [name, field] of Object.entries(CPU_STAGE_FIELDS))
|
|
175
183
|
totals[name] = module._tnw_web_frame(field);
|
|
176
184
|
return totals;
|
|
@@ -227,6 +235,22 @@ export async function bindWebEngine(
|
|
|
227
235
|
Object.assign(bound, { AudioContext, AudioListener, Audio, PositionalAudio, AudioLoader });
|
|
228
236
|
// three's QuadMesh over the engine Mesh (quad-mesh.ts), shared with the V8 player.
|
|
229
237
|
bound.QuadMesh = defineQuadMesh(classes as never);
|
|
238
|
+
// three's GridHelper over the engine LineSegments (grid-helper.ts), shared with the V8 player.
|
|
239
|
+
bound.GridHelper = defineGridHelper(classes as never);
|
|
240
|
+
// three's CubeRenderTarget, RenderTarget3D and CubeCamera (render-target.ts), shared with the V8 player.
|
|
241
|
+
Object.assign(bound, defineLayeredTargets(classes as never));
|
|
242
|
+
// three's EdgesGeometry, Box2, typed BufferAttributes and AnimationUtils: JS ports shared with V8.
|
|
243
|
+
bound.EdgesGeometry = defineEdgesGeometry(classes as never);
|
|
244
|
+
bound.Box2 = defineBox2(classes as never);
|
|
245
|
+
const attribute = classes.BufferAttribute as Parameters<typeof defineTypedBufferAttribute>[0];
|
|
246
|
+
bound.Uint8BufferAttribute = defineTypedBufferAttribute(attribute, Uint8Array);
|
|
247
|
+
bound.Uint16BufferAttribute = defineTypedBufferAttribute(attribute, Uint16Array);
|
|
248
|
+
bound.Uint32BufferAttribute = defineTypedBufferAttribute(attribute, Uint32Array);
|
|
249
|
+
bound.AnimationUtils = AnimationUtils;
|
|
250
|
+
// three's track.createInterpolant over the engine tracks, shared with V8 (PRD-854).
|
|
251
|
+
defineCreateInterpolant(classes);
|
|
252
|
+
// three's viewportCoordinate is screenCoordinate minus viewport.xy, which is (0, 0) on a full-target pass.
|
|
253
|
+
if (bound.screenCoordinate !== undefined) bound.viewportCoordinate = bound.screenCoordinate;
|
|
230
254
|
// three/webgpu's BlendMode, the record mrt().setBlendMode takes (data only, as on the engine's scene pass).
|
|
231
255
|
bound.BlendMode = BlendMode;
|
|
232
256
|
// The engine's four MathUtils functions, with the rest of three's number-only ones beside them.
|
|
@@ -246,14 +270,16 @@ export async function bindWebEngine(
|
|
|
246
270
|
bound.WebGPURenderer = defineWebRenderer(
|
|
247
271
|
module,
|
|
248
272
|
classes.Color as never,
|
|
249
|
-
(frame) => {
|
|
273
|
+
(frame, kernels) => {
|
|
250
274
|
// Each renderer render runs the live frame passes' updateBefore, as three's node update does;
|
|
251
275
|
// a render that advances no frame (a standing frame the runner asks for) still hears them.
|
|
252
276
|
updatePasses(frame);
|
|
253
277
|
// A compute dispatch passes no frame: it belongs to the frame already collected.
|
|
254
278
|
const frameId = frame?.frameId ?? collectedFrame;
|
|
255
279
|
if (updating || (frameId !== undefined && frameId === collectedFrame)) {
|
|
256
|
-
|
|
280
|
+
// A dispatch's sync carries that frame, so the frame hooks that already ran do not run again for it,
|
|
281
|
+
// and its kernels, so it runs only the hooks they read (PRD-878).
|
|
282
|
+
tsl?.sync(frame ?? (frameId === undefined ? undefined : { frameId, kernels }));
|
|
257
283
|
return;
|
|
258
284
|
}
|
|
259
285
|
collectedFrame = frameId;
|
|
@@ -271,11 +297,18 @@ export async function bindWebEngine(
|
|
|
271
297
|
bound.DataTexture as never,
|
|
272
298
|
);
|
|
273
299
|
// A GLB through the engine's own glTF loader, for the web GLTFLoader (addons/gltf-loader-web.ts).
|
|
274
|
-
|
|
300
|
+
// Off the main thread when the engine has a loader thread (PRD-860), else in the call.
|
|
301
|
+
const { loadGltf, loadGltfAsync } = runtime;
|
|
275
302
|
if (loadGltf !== undefined)
|
|
276
|
-
bound.__tnLoadGltf = (bytes: Uint8Array, files?: ReadonlyMap<string, Uint8Array>) => {
|
|
277
|
-
const loaded =
|
|
278
|
-
|
|
303
|
+
bound.__tnLoadGltf = async (bytes: Uint8Array, files?: ReadonlyMap<string, Uint8Array>) => {
|
|
304
|
+
const loaded = await (loadGltfAsync !== undefined
|
|
305
|
+
? loadGltfAsync.call(runtime, bytes, files)
|
|
306
|
+
: loadGltf.call(runtime, bytes, files));
|
|
307
|
+
return {
|
|
308
|
+
scene: wrap(loaded.scene),
|
|
309
|
+
scenes: loaded.scenes.map(wrap),
|
|
310
|
+
animations: loaded.animations.map(wrap),
|
|
311
|
+
};
|
|
279
312
|
};
|
|
280
313
|
if (tsl !== undefined && runtime.tsl !== undefined) {
|
|
281
314
|
const native = tsl.exports.reflector as (...args: unknown[]) => object;
|
|
@@ -304,10 +337,10 @@ export async function bindWebEngine(
|
|
|
304
337
|
// The frame pass draws at the engine's input size, at the frame's sample count (tnw_web_frame's
|
|
305
338
|
// 35, 36 and 18), so a game reads the size and MSAA the engine actually drew.
|
|
306
339
|
surface: () => ({
|
|
307
|
-
width: hostFrame?.call(module,
|
|
308
|
-
height: hostFrame?.call(module,
|
|
340
|
+
width: hostFrame?.call(module, WEB_FRAME_FIELD.inputWidth) ?? 0,
|
|
341
|
+
height: hostFrame?.call(module, WEB_FRAME_FIELD.inputHeight) ?? 0,
|
|
309
342
|
}),
|
|
310
|
-
samples: () => hostFrame?.call(module,
|
|
343
|
+
samples: () => hostFrame?.call(module, WEB_FRAME_FIELD.sampleCount) ?? 0,
|
|
311
344
|
},
|
|
312
345
|
);
|
|
313
346
|
drawSecondaryPasses = passes.updateSecondaryPasses;
|
|
@@ -319,13 +352,19 @@ export async function bindWebEngine(
|
|
|
319
352
|
|
|
320
353
|
/**
|
|
321
354
|
* The engine classes plus what plain JS adds over them: three's texture sources (typed array,
|
|
322
|
-
* canvas, image, ImageBitmapLoader), `DataUtils`, and the `ColorManagement` singleton.
|
|
355
|
+
* canvas, image, ImageBitmapLoader), three's loader base classes, `DataUtils`, and the `ColorManagement` singleton.
|
|
323
356
|
*/
|
|
324
357
|
export function withTextureSources(
|
|
325
358
|
classes: Readonly<Record<string, unknown>>,
|
|
326
359
|
runtime: IBrowserRuntime,
|
|
327
360
|
): Record<string, unknown> {
|
|
328
|
-
return {
|
|
361
|
+
return {
|
|
362
|
+
...classes,
|
|
363
|
+
...defineTextureSources(classes, runtime),
|
|
364
|
+
...LOADERS,
|
|
365
|
+
DataUtils,
|
|
366
|
+
ColorManagement,
|
|
367
|
+
};
|
|
329
368
|
}
|
|
330
369
|
|
|
331
370
|
interface IPipelineRenderer {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* three's loader base classes in JavaScript (three's own modules, MIT), for the browser back end:
|
|
3
|
+
* `Loader`, `FileLoader`, `LoadingManager` and `Cache` only fetch and track requests, so they draw
|
|
4
|
+
* nothing and need no engine call. An upstream loader that extends them (KTX2Loader, PRD-867) runs
|
|
5
|
+
* over the engine's textures unchanged.
|
|
6
|
+
*/
|
|
7
|
+
import { Cache } from "three/src/loaders/Cache.js";
|
|
8
|
+
import { FileLoader } from "three/src/loaders/FileLoader.js";
|
|
9
|
+
import { Loader } from "three/src/loaders/Loader.js";
|
|
10
|
+
import { DefaultLoadingManager, LoadingManager } from "three/src/loaders/LoadingManager.js";
|
|
11
|
+
|
|
12
|
+
export const LOADERS = { Cache, DefaultLoadingManager, FileLoader, Loader, LoadingManager };
|