@threenative/runtime-native 0.3.4 → 0.3.5

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.
@@ -0,0 +1,294 @@
1
+ import { unsupportedExport } from "../../../../three-native/src/refused.ts";
2
+ import {
3
+ Material,
4
+ defineObjectSurface,
5
+ defineTypeFlags,
6
+ } from "../../../../three-native/src/object-surface.ts";
7
+ import { definePropertyBinding } from "../../../../three-native/src/property-binding.ts";
8
+ // Identity-preserving imports over the V8 adapter, never upstream Three.js.
9
+ import { audio } from "./core-audio.mjs";
10
+ export const {
11
+ ACESFilmicToneMapping,
12
+ AdditiveBlending,
13
+ AgXToneMapping,
14
+ AmbientLight,
15
+ AnimationAction,
16
+ AnimationClip,
17
+ AnimationMixer,
18
+ AttachedBindMode,
19
+ BackSide,
20
+ Bone,
21
+ Box3,
22
+ BoxGeometry,
23
+ BufferAttribute,
24
+ BufferGeometry,
25
+ Camera,
26
+ CapsuleGeometry,
27
+ CatmullRomCurve3,
28
+ CircleGeometry,
29
+ ClampToEdgeWrapping,
30
+ Color,
31
+ ConeGeometry,
32
+ CylinderGeometry,
33
+ DepthTexture,
34
+ DirectionalLight,
35
+ DodecahedronGeometry,
36
+ DoubleSide,
37
+ DynamicDrawUsage,
38
+ EquirectangularReflectionMapping,
39
+ Euler,
40
+ ExtrudeGeometry,
41
+ Float32BufferAttribute,
42
+ FloatType,
43
+ Fog,
44
+ FogExp2,
45
+ FrontSide,
46
+ Frustum,
47
+ Group,
48
+ HemisphereLight,
49
+ IcosahedronGeometry,
50
+ InstancedBufferAttribute,
51
+ InstancedMesh,
52
+ LOD,
53
+ LatheGeometry,
54
+ Layers,
55
+ Line,
56
+ LineBasicMaterial,
57
+ LineSegments,
58
+ LinearFilter,
59
+ LinearMipmapLinearFilter,
60
+ LinearSRGBColorSpace,
61
+ LoopOnce,
62
+ LoopPingPong,
63
+ LoopRepeat,
64
+ Matrix3,
65
+ Matrix4,
66
+ Mesh,
67
+ MeshBasicMaterial,
68
+ MeshLambertMaterial,
69
+ MeshPhongMaterial,
70
+ MeshPhysicalMaterial,
71
+ MeshStandardMaterial,
72
+ NearestFilter,
73
+ NeutralToneMapping,
74
+ NoBlending,
75
+ NoColorSpace,
76
+ NoToneMapping,
77
+ NormalBlending,
78
+ NumberKeyframeTrack,
79
+ Object3D,
80
+ OctahedronGeometry,
81
+ OrthographicCamera,
82
+ PCFShadowMap,
83
+ PCFSoftShadowMap,
84
+ Path,
85
+ PerspectiveCamera,
86
+ Plane,
87
+ PlaneGeometry,
88
+ PointLight,
89
+ Quaternion,
90
+ QuaternionKeyframeTrack,
91
+ RGBAFormat,
92
+ Ray,
93
+ Raycaster,
94
+ RenderTarget,
95
+ RepeatWrapping,
96
+ RingGeometry,
97
+ RoundedBoxGeometry,
98
+ SRGBColorSpace,
99
+ Scene,
100
+ Shape,
101
+ ShapeGeometry,
102
+ Skeleton,
103
+ SkinnedMesh,
104
+ Sphere,
105
+ SphereGeometry,
106
+ SpotLight,
107
+ Sprite,
108
+ SpriteMaterial,
109
+ StaticDrawUsage,
110
+ TorusGeometry,
111
+ TorusKnotGeometry,
112
+ TubeGeometry,
113
+ UnsignedByteType,
114
+ Vector2,
115
+ Vector3,
116
+ Vector4,
117
+ VectorKeyframeTrack,
118
+ } = globalThis;
119
+ // three's PropertyBinding statics and console function over the engine class (shared with Wasm).
120
+ export const { PropertyBinding, getConsoleFunction, setConsoleFunction } = definePropertyBinding(
121
+ globalThis.PropertyBinding,
122
+ );
123
+ // Texture sources (typed array, canvas, ImageBitmap) the engine copies; see core-textures.mjs.
124
+ import { DataTexture, Texture } from "./core-textures.mjs";
125
+ export {
126
+ CanvasTexture,
127
+ DataTexture,
128
+ Data3DTexture,
129
+ DataUtils,
130
+ HalfFloatType,
131
+ ImageBitmapLoader,
132
+ Texture,
133
+ TextureLoader,
134
+ } from "./core-textures.mjs";
135
+
136
+ // The binding registry represents the stateless namespaces as native objects.
137
+ // With JS math (the player's default) the global is three's own namespace object; otherwise a bound class.
138
+ export const MathUtils = typeof globalThis.MathUtils === "function" ? new globalThis.MathUtils() : globalThis.MathUtils;
139
+ const skeletonUtils = new globalThis.SkeletonUtils();
140
+ export const clone = (root) => skeletonUtils.clone(root);
141
+
142
+
143
+ // three's BatchedMesh: an engine class (PRD-552), each geometry's instances drawn as one instanced mesh.
144
+ 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
+ // three's InstancedBufferGeometry: an engine class, drawn instanceCount times.
149
+ export const { InstancedBufferGeometry } = globalThis;
150
+ // three exports the engine does not provide: refused at use, by name, as on Wasm (unsupportedExport).
151
+ export const LineLoop = unsupportedExport("LineLoop");
152
+ export const Points = unsupportedExport("Points");
153
+ export const WebGLRenderer = unsupportedExport("WebGLRenderer");
154
+ export const { AudioContext, AudioListener, Audio, PositionalAudio, AudioLoader } = audio;
155
+
156
+ // Native traversal and child enumeration are host callbacks, not a second JS scene graph.
157
+ const bags = new WeakMap();
158
+ for (const name of [
159
+ "Object3D",
160
+ "Scene",
161
+ "Mesh",
162
+ "Group",
163
+ "SkinnedMesh",
164
+ "InstancedMesh",
165
+ "Camera",
166
+ "PerspectiveCamera",
167
+ "OrthographicCamera",
168
+ "DirectionalLight",
169
+ "AmbientLight",
170
+ "HemisphereLight",
171
+ "PointLight",
172
+ "SpotLight",
173
+ "Bone",
174
+ "LOD",
175
+ "Sprite",
176
+ "Line",
177
+ "LineSegments",
178
+ ]) {
179
+ const prototype = globalThis[name].prototype;
180
+ const parent = Object.getOwnPropertyDescriptor(prototype, "parent").get;
181
+ Object.defineProperties(prototype, {
182
+ parent: {
183
+ get() {
184
+ return parent.call(this) ?? null;
185
+ },
186
+ },
187
+ userData: {
188
+ get() {
189
+ if (!bags.has(this)) bags.set(this, {});
190
+ return bags.get(this);
191
+ },
192
+ },
193
+ });
194
+ // The engine's walk (`__walk`, shared with the Wasm back end): one call for the whole subtree.
195
+ prototype.traverse = function (callback) {
196
+ for (const object of this.__walk(false)) callback(object);
197
+ };
198
+ prototype.traverseVisible = function (callback) {
199
+ for (const object of this.__walk(true)) callback(object);
200
+ };
201
+ }
202
+ defineTypeFlags(globalThis);
203
+ const geometries = [
204
+ BoxGeometry,
205
+ CircleGeometry,
206
+ ConeGeometry,
207
+ CylinderGeometry,
208
+ PlaneGeometry,
209
+ RingGeometry,
210
+ RoundedBoxGeometry,
211
+ SphereGeometry,
212
+ TorusGeometry,
213
+ LatheGeometry,
214
+ TubeGeometry,
215
+ ShapeGeometry,
216
+ ExtrudeGeometry,
217
+ IcosahedronGeometry,
218
+ CapsuleGeometry,
219
+ DodecahedronGeometry,
220
+ OctahedronGeometry,
221
+ TorusKnotGeometry,
222
+ InstancedBufferGeometry,
223
+ ];
224
+ // Adapt wrapper inheritance only; native classes continue to own every scene operation.
225
+ for (const [base, names] of [
226
+ [
227
+ Object3D,
228
+ [
229
+ Scene,
230
+ Mesh,
231
+ Group,
232
+ Camera,
233
+ Bone,
234
+ LOD,
235
+ Sprite,
236
+ AmbientLight,
237
+ DirectionalLight,
238
+ HemisphereLight,
239
+ PointLight,
240
+ SpotLight,
241
+ Line,
242
+ ],
243
+ ],
244
+ [Line, [LineSegments]],
245
+ [Camera, [PerspectiveCamera, OrthographicCamera]],
246
+ [Mesh, [SkinnedMesh, InstancedMesh]],
247
+ [BufferGeometry, geometries],
248
+ [BufferAttribute, [Float32BufferAttribute, InstancedBufferAttribute]],
249
+ [Texture, [DepthTexture, DataTexture, globalThis.CanvasTexture]],
250
+ [Path, [Shape]],
251
+ ]) {
252
+ for (const derived of names) Object.setPrototypeOf(derived.prototype, base.prototype);
253
+ }
254
+ // The type flags three defines on its value classes (`isColor`, `isVector3`, ...).
255
+ for (const value of [
256
+ Color,
257
+ Vector2,
258
+ Vector3,
259
+ Vector4,
260
+ Quaternion,
261
+ Euler,
262
+ Matrix3,
263
+ Matrix4,
264
+ Box3,
265
+ Plane,
266
+ Texture,
267
+ DepthTexture,
268
+ DataTexture,
269
+ BufferGeometry,
270
+ BufferAttribute,
271
+ InstancedBufferAttribute,
272
+ ])
273
+ value.prototype[`is${value.name}`] = true;
274
+ CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
275
+ // attributes/groups, shape.holes and the abstract Material: shared with the Wasm back end.
276
+ defineObjectSurface({
277
+ bufferGeometry: BufferGeometry,
278
+ geometries,
279
+ shape: Shape,
280
+ materials: [
281
+ LineBasicMaterial,
282
+ MeshBasicMaterial,
283
+ MeshLambertMaterial,
284
+ MeshPhongMaterial,
285
+ MeshPhysicalMaterial,
286
+ MeshStandardMaterial,
287
+ SpriteMaterial,
288
+ ],
289
+ });
290
+ export { Material };
291
+
292
+ // three's blending constant "use the material's own blending" (constants.js). It is a value in three,
293
+ // not an engine class, so it has no catalog entry; `new BlendMode(MaterialBlending)` names it.
294
+ export const MaterialBlending = 6;
@@ -0,0 +1,80 @@
1
+ // TSL authoring calls the native lazy graph; no upstream shader implementation enters the player.
2
+ import { liveUniforms, withConstValues } from "../../../../three-native/src/tsl-uniforms.ts";
3
+ import { defineReflector } from "../../../../three-native/src/reflector.ts";
4
+ import { definePass, markNormalTarget } from "../../../../three-native/src/pass-node.ts";
5
+ import { BufferAttribute, Color, Object3D, PerspectiveCamera, Vector2, Vector3, Vector4 } from "./core-three.mjs";
6
+ import { defineStorage } from "../../../../three-native/src/storage.ts";
7
+ import { defineStruct } from "../../../../three-native/src/tsl-struct.ts";
8
+ import { defineTslExtras } from "../../../../three-native/src/tsl-extras.ts";
9
+
10
+ // r185's ConstNode.value on float(), vec3(), color() and the other constants (shared with the Wasm back end).
11
+ const constants = { ...globalThis.tsl };
12
+ withConstValues(constants, { Vector2, Vector3, Vector4, Color });
13
+
14
+ // three's `uniform.value = x` (shared with the Wasm back end): a number goes through at once; an
15
+ // edited Color or VectorN goes through `syncUniforms`, which the renderer calls before each frame.
16
+ const live = liveUniforms(globalThis.tsl.uniform, (node, lanes) => globalThis.tsl.setUniform(node, ...lanes));
17
+ export const uniform = live.uniform;
18
+ export const uniformArray = live.uniformArray;
19
+ export const reference = live.reference;
20
+ export const syncUniforms = live.sync;
21
+
22
+ export const { float, int, uint, vec2, vec3, color } = constants;
23
+ export const vec4 = markNormalTarget(constants.vec4, globalThis.tsl.normalView);
24
+ export const {
25
+ atomicAdd, atomicStore, atomicLoad, Break, Continue, Return, log, lightShadowMatrix, attribute, uv, texture, renderOutput, Fn, If, Loop, luminance, viewZToOrthographicDepth, viewZToPerspectiveDepth, logarithmicDepthToViewZ, vertexIndex,
26
+ add, sub, mul, div, negate, lessThan, greaterThan, equal, lessThanEqual, greaterThanEqual, and, or, not, all, any, abs, sin, cos,
27
+ floor, fract, sqrt, exp, exp2, log2, normalize, length, min, max, pow, step, dot,
28
+ distance, cross, mix, clamp, smoothstep, select, positionLocal, positionWorld,
29
+ normalViewGeometry, instanceIndex, cameraViewMatrix, ivec2, nodeObject, reflect, textureLoad,
30
+ mx_noise_float, mx_worley_noise_vec2, pmremTexture, texture3D,
31
+ convertToTexture, screenUV, materialColor, materialEmissive, materialMetalness, materialRoughness,
32
+ cameraPosition, cameraProjectionMatrix, cameraWorldMatrix, positionGeometry, normalWorld, varying,
33
+ cameraNear, cameraFar, screenSize, depth, viewportSharedTexture, viewportDepthTexture, linearDepth, viewportLinearDepth,
34
+ } = globalThis.tsl;
35
+ export const {
36
+ oneMinus, screenCoordinate, normalGeometry, tangentGeometry, positionViewDirection, dFdx, dFdy, lengthSq,
37
+ normalLocal, tangentLocal, positionPrevious,
38
+ atan, mod, fwidth, saturation, mat2, hash, time, deltaTime, transformDirection, normalWorldGeometry,
39
+ getViewPosition, frameGroup, renderGroup, objectGroup, transformNormalToView, property,
40
+ } = globalThis.tsl;
41
+
42
+ // three's storage buffers over engine BufferAttributes (shared with the Wasm back end): `storage`,
43
+ // `instancedArray` and `attributeArray` build the engine's storage node, whose kernels `renderer.compute` runs.
44
+ export const { storage, instancedArray, attributeArray, StorageBufferAttribute, StorageInstancedBufferAttribute } =
45
+ defineStorage(globalThis.tsl, BufferAttribute);
46
+
47
+ // three's pass(), mrt() and MRT slots over the player's one scene pass (shared with the Wasm back
48
+ // end); the player draws the scene and camera a pass is pointed at.
49
+ // An offscreen `new PassNode(PassNode.COLOR, scene, camera)` owns a RenderTarget that the renderer draws before the
50
+ // frame (updateSecondaryPasses, called from core-webgpu.mjs); only pass() publishes the frame's scene and camera.
51
+ export const { pass, PassNode, updateSecondaryPasses, mrt, output, normalView, metalness, roughness } = definePass(
52
+ globalThis.tsl,
53
+ (scene, camera) => {
54
+ globalThis.tn.scene = scene;
55
+ globalThis.tn.camera = camera;
56
+ },
57
+ { RenderTarget: globalThis.RenderTarget, surface: () => globalThis.tn.surfaceSize() },
58
+ );
59
+
60
+ export const reflector = defineReflector(globalThis.tsl.reflector, { Object3D, PerspectiveCamera });
61
+
62
+ // saturate, densityFogFactor, fog, context and velocity: plain JS over the engine's TSL functions,
63
+ // shared with the Wasm back end.
64
+ export const { saturate, densityFogFactor, fog, context, velocity } = defineTslExtras({
65
+ get cameraNear() { return globalThis.tsl.cameraNear; },
66
+ get cameraFar() { return globalThis.tsl.cameraFar; },
67
+ clamp: (...args) => globalThis.tsl.clamp(...args),
68
+ float: (value) => globalThis.tsl.float(value),
69
+ linearDepth: () => globalThis.tsl.linearDepth(),
70
+ vec4: (...args) => vec4(...args),
71
+ });
72
+
73
+ export const struct = defineStruct(globalThis.tsl.struct);
74
+
75
+ import { defineRtt } from "../../../../three-native/src/rtt.ts";
76
+ import { defineQuadMesh } from "../../../../three-native/src/quad-mesh.ts";
77
+ export const rtt = defineRtt(globalThis.tsl.rtt, { NodeMaterial: globalThis.NodeMaterial, RenderTarget: globalThis.RenderTarget, QuadMesh: defineQuadMesh(globalThis) });
78
+
79
+ import { defineWgslFn } from "../../../../three-native/src/wgsl-fn.ts";
80
+ export const wgslFn = defineWgslFn(globalThis.tsl.wgslFunction);
@@ -0,0 +1,21 @@
1
+ import { unsupportedExport } from "../../../../three-native/src/refused.ts";
2
+
3
+ // Unused imports must never pull upstream rendering/loader code into this artifact.
4
+ export const MeshBVH = unsupportedExport("MeshBVH");
5
+ export const GLTFLoader = unsupportedExport("GLTFLoader");
6
+ export const DRACOLoader = unsupportedExport("DRACOLoader");
7
+ export const MeshoptDecoder = { ready: Promise.resolve(), decodeGltfBuffer: unsupportedExport("MeshoptDecoder.decodeGltfBuffer") };
8
+ export const mergeGeometries = unsupportedExport("mergeGeometries");
9
+ export const mergeAttributes = unsupportedExport("mergeAttributes");
10
+ export const clone = unsupportedExport("clone");
11
+ export class KTX2Loader {
12
+ setTranscoderPath() {}
13
+ setWorkerLimit() {}
14
+ detectSupport = unsupportedExport("KTX2Loader.detectSupport");
15
+ load = unsupportedExport("KTX2Loader.load");
16
+ }
17
+ export const {
18
+ Fn, attribute, instanceIndex, normalGeometry, normalLocal, positionGeometry,
19
+ positionPrevious, storage, tangentGeometry, tangentLocal, uint, vec4,
20
+ context, mrt, output, velocity,
21
+ } = globalThis;
@@ -0,0 +1,207 @@
1
+ export * from "./core-three.mjs";
2
+ import { BufferAttribute, Color, Material, NormalBlending } from "./core-three.mjs";
3
+ import { unsupportedExport } from "../../../../three-native/src/refused.ts";
4
+ import { PassNode, StorageBufferAttribute, StorageInstancedBufferAttribute, syncUniforms, updateSecondaryPasses } from "./core-tsl.mjs";
5
+ import { readStorageBytes } from "../../../../three-native/src/storage.ts";
6
+ import { GAME_SPANS } from "../../../../core/src/profiling/Spans.ts";
7
+ import { ShadowMap } from "../../../../three-native/src/shadow-map.ts";
8
+ import { defineRenderTargets } from "../../../../three-native/src/render-target.ts";
9
+ import { defineQuadMesh } from "../../../../three-native/src/quad-mesh.ts";
10
+
11
+ export const { MeshBasicNodeMaterial, MeshStandardNodeMaterial, SpriteNodeMaterial } = globalThis;
12
+ Object.setPrototypeOf(MeshBasicNodeMaterial.prototype, globalThis.MeshBasicMaterial.prototype);
13
+ Object.setPrototypeOf(MeshStandardNodeMaterial.prototype, globalThis.MeshStandardMaterial.prototype);
14
+ Object.setPrototypeOf(SpriteNodeMaterial.prototype, globalThis.SpriteMaterial.prototype);
15
+ for (const material of [MeshBasicNodeMaterial, MeshStandardNodeMaterial, SpriteNodeMaterial]) {
16
+ material.prototype.isNodeMaterial = true;
17
+ material.prototype[`is${material.name}`] = true;
18
+ }
19
+
20
+ // Core still owns createRenderer/wrapRenderer; the player owns the GPU and draws these handles.
21
+ // The facade's backend answers three's adapter request with the player's GPU adapter, so core reads
22
+ // the same `adapter.info` identity (and software-adapter verdict) it reads in a browser.
23
+ class NativeBackend {
24
+ gpu = { requestAdapter: () => globalThis.tn.requestAdapter() };
25
+ // Pipelines the player's renderer has compiled so far (three counts createRenderPipeline calls on its
26
+ // backend; the engine counts its own pipeline cache). A window's compiles are the difference of two reads.
27
+ pipelineCompiles = () => globalThis.tn.renderInfo().pipelineCompiles;
28
+ }
29
+
30
+ function drawTarget(renderer, target, root, camera, deferred) {
31
+ syncUniforms();
32
+ globalThis.tn.setRendererState(renderer); // the target clears to the renderer's current clear colour
33
+ if (deferred) globalThis.tn.renderTarget(target, root, camera, true);
34
+ else globalThis.tn.renderTarget(target, root, camera);
35
+ }
36
+
37
+ // Every offscreen PassNode plans its draw into its own target; the player records it in this frame, after the post
38
+ // render-to-texture passes when the post graph samples the target, else ahead of the scene pass.
39
+ function drawSecondaryPasses(renderer) {
40
+ updateSecondaryPasses(() => globalThis.tn.surfaceSize(), (target, root, camera) => drawTarget(renderer, target, root, camera, true));
41
+ }
42
+
43
+ export class WebGPURenderer {
44
+ // The native scene pass draws to the player-owned surface, not a retained frame target.
45
+ supportsRetainedTargetSubrect = false;
46
+ constructor({ canvas, antialias = false } = {}) {
47
+ this.domElement = canvas;
48
+ this.samples = antialias ? 4 : 0;
49
+ }
50
+ backend = new NativeBackend();
51
+ // three's `renderer.info`, read from the last frame the player drew (one frame behind the
52
+ // simulation, as a GPU-timed reading is). `reset` has nothing to clear: the player counts per frame.
53
+ info = {
54
+ render: {
55
+ get drawCalls() { return globalThis.tn.renderInfo().drawCalls; },
56
+ get calls() { return globalThis.tn.renderInfo().drawCalls; },
57
+ get triangles() { return globalThis.tn.renderInfo().triangles; },
58
+ },
59
+ compute: {},
60
+ frame: 0,
61
+ reset() {},
62
+ };
63
+ // WebGPURenderer's defaults; the player applies them before each frame it draws.
64
+ shadowMap = new ShadowMap();
65
+ toneMapping = 0;
66
+ toneMappingExposure = 1;
67
+ outputColorSpace = "srgb";
68
+ // three's clear colour and alpha (linear), black and opaque by default; the player clears each frame
69
+ // and each render target to them (`__clearColor`, read by tn.setRendererState).
70
+ __clearColor = [0, 0, 0, 1];
71
+ setClearColor(color, alpha = 1) {
72
+ const value = typeof color === "object" && color !== null ? color : new Color(color);
73
+ this.__clearColor = [value.r, value.g, value.b, alpha];
74
+ }
75
+ getClearColor(target) { return target.setRGB(this.__clearColor[0], this.__clearColor[1], this.__clearColor[2]); }
76
+ getClearAlpha() { return this.__clearColor[3]; }
77
+ setClearAlpha(alpha) { this.__clearColor[3] = alpha; }
78
+ setPixelRatio() {}
79
+ // three's `await renderer.init()`: the player owns the GPU and has opened it before any script runs.
80
+ async init() { return this; }
81
+ // WebGPUCapabilities.getMaxAnisotropy: WebGPU samplers clamp maxAnisotropy to 16.
82
+ getMaxAnisotropy() { return 16; }
83
+ setSize(width, height) {
84
+ this.domElement.width = width;
85
+ this.domElement.height = height;
86
+ }
87
+ // The player owns the window, so setSize cannot resize it: the drawing buffer is the surface the player opened.
88
+ getDrawingBufferSize(target) {
89
+ const { width, height } = globalThis.tn.surfaceSize();
90
+ return target.set(width, height);
91
+ }
92
+ render(scene, camera) {
93
+ drawSecondaryPasses(this);
94
+ globalThis.__tnGameSpan?.(GAME_SPANS.transport, 0);
95
+ try { syncUniforms(); } finally { globalThis.__tnGameSpan?.(GAME_SPANS.transport, 1); }
96
+ globalThis.__tnGameSpan?.(GAME_SPANS.publish, 0);
97
+ try {
98
+ globalThis.tn.scene = scene;
99
+ globalThis.tn.camera = camera;
100
+ globalThis.tn.setRendererState(this);
101
+ } finally { globalThis.__tnGameSpan?.(GAME_SPANS.publish, 1); }
102
+ }
103
+ compileAsync(root, camera, scene) {
104
+ syncUniforms();
105
+ globalThis.tn.setRendererState(this);
106
+ return globalThis.tn.compileAsync(root, camera, scene);
107
+ }
108
+ // PRD-620: three's compute(node | node[]) queues kernels in call order; the player runs them before the
109
+ // frame's passes (and before a render target or a read of one). A dispatch size override has no native form.
110
+ compute(computeNodes, dispatchSize = null) {
111
+ if (dispatchSize !== null) throw new Error("TN_COMPUTE_DISPATCH_SIZE: renderer.compute(nodes, dispatchSize) is not available on the native engine; give the node its count.");
112
+ syncUniforms();
113
+ globalThis.tn.compute(computeNodes);
114
+ }
115
+ async computeAsync(computeNodes, dispatchSize = null) { this.compute(computeNodes, dispatchSize); }
116
+ // The buffer's bytes after every kernel queued before this call.
117
+ getArrayBufferAsync(attribute, target = null, offset = 0, count = -1) {
118
+ return readStorageBytes((a) => globalThis.tn.readStorage(a), attribute, target, offset, count);
119
+ }
120
+ // Drops the attribute's GPU copy; the next use uploads its CPU contents again.
121
+ deleteAttribute(attribute) { globalThis.tn.deleteStorage(attribute); return this; }
122
+ dispose() {}
123
+ }
124
+
125
+ // three's render targets (shared with the Wasm back end): render() while a target is set draws into
126
+ // it at the call, and readRenderTargetPixelsAsync reads it back once the GPU copy lands.
127
+ defineRenderTargets(WebGPURenderer.prototype, (renderer) => ({
128
+ draw: (target, root, camera) => drawTarget(renderer, target, root, camera),
129
+ read: (target, x, y, width, height) => globalThis.tn.readTarget(target, x, y, width, height),
130
+ }));
131
+ // three's QuadMesh over the engine Mesh (shared with the Wasm back end).
132
+ export const QuadMesh = defineQuadMesh(globalThis);
133
+
134
+ // three's RenderPipeline(renderer, outputNode): the player installs the node graph as its post pass
135
+ // (once per graph) and draws it with the renderer's settings.
136
+ export class RenderPipeline {
137
+ context = {};
138
+ outputColorTransform = true;
139
+ _source = null;
140
+ _graph = null;
141
+ constructor(renderer, outputNode = null) {
142
+ this.renderer = renderer;
143
+ this.outputNode = outputNode;
144
+ }
145
+ render() {
146
+ this.context.onBeforeRenderPipeline?.();
147
+ try {
148
+ drawSecondaryPasses(this.renderer);
149
+ syncUniforms();
150
+ globalThis.tn.setRendererState(this.renderer);
151
+ if (this._source !== this.outputNode) {
152
+ this._source = this.outputNode;
153
+ this._graph = null;
154
+ }
155
+ if (!this.outputColorTransform && this.outputNode !== null)
156
+ this._graph ??= globalThis.tsl.pipelineOutput(this.outputNode, 0);
157
+ globalThis.tn.setPostGraph(this.outputColorTransform ? this.outputNode : this._graph);
158
+ } finally { this.context.onAfterRenderPipeline?.(); }
159
+ }
160
+ dispose() { globalThis.tn.setPostGraph(null); }
161
+ }
162
+ // three's PassNode: pass() is the frame's pass; `new PassNode(PassNode.COLOR, scene, camera)` is an offscreen one (pass-node.ts).
163
+ export { PassNode };
164
+ // three's NodeUpdateType, the constants a node's update schedule names.
165
+ export const NodeUpdateType = Object.freeze({ NONE: "none", FRAME: "frame", RENDER: "render", OBJECT: "object" });
166
+ // three's StorageBufferAttribute and StorageInstancedBufferAttribute: BufferAttributes that TSL storage() binds
167
+ // as storage buffers (defined with the storage nodes, in core-tsl.mjs).
168
+ export { StorageBufferAttribute, StorageInstancedBufferAttribute };
169
+ export const MeshLambertNodeMaterial = unsupportedExport("MeshLambertNodeMaterial");
170
+ export const MeshMatcapNodeMaterial = unsupportedExport("MeshMatcapNodeMaterial");
171
+ export const MeshNormalNodeMaterial = unsupportedExport("MeshNormalNodeMaterial");
172
+ export const MeshPhongNodeMaterial = unsupportedExport("MeshPhongNodeMaterial");
173
+ export const MeshPhysicalNodeMaterial = unsupportedExport("MeshPhysicalNodeMaterial");
174
+ export const MeshToonNodeMaterial = unsupportedExport("MeshToonNodeMaterial");
175
+
176
+ // three's BlendMode (renderers/common/BlendMode.js): the blend state an MRT output names through
177
+ // `mrt.setBlendMode(name, mode)`. The factor and equation values are three's own constants.
178
+ export class BlendMode {
179
+ constructor(blending = NormalBlending) {
180
+ this.blending = blending;
181
+ this.blendSrc = 204; // SrcAlphaFactor
182
+ this.blendDst = 205; // OneMinusSrcAlphaFactor
183
+ this.blendEquation = 100; // AddEquation
184
+ this.blendSrcAlpha = null;
185
+ this.blendDstAlpha = null;
186
+ this.blendEquationAlpha = null;
187
+ this.premultiplyAlpha = false;
188
+ }
189
+ copy(source) { return Object.assign(this, source); }
190
+ clone() { return new this.constructor().copy(this); }
191
+ }
192
+
193
+ // three's ReadbackBuffer (shared with the Wasm back end).
194
+ export { ReadbackBuffer } from "../../../../three-native/src/storage.ts";
195
+
196
+ // Game-authored node lifecycles and fullscreen node materials have no V8 renderer binding. They stay
197
+ // importable, so a game that defines a node class or imports them runs; one that constructs or calls
198
+ // them fails at that use, by name. TempNode is a real constructor so `class X extends TempNode` loads.
199
+ export class TempNode {
200
+ constructor() {
201
+ throw new Error("TN_NATIVE_UNSUPPORTED_TEMPNODE: TempNode is not available on the native engine.");
202
+ }
203
+ }
204
+ export const NodeMaterial = globalThis.NodeMaterial;
205
+ Object.setPrototypeOf(NodeMaterial.prototype, Material.prototype);
206
+ NodeMaterial.prototype.isNodeMaterial = true;
207
+ export const RendererUtils = unsupportedExport("RendererUtils");