@threenative/runtime-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.
@@ -17,20 +17,21 @@ for (const name of ["DirectionalLightShadow", "PointLightShadow", "SpotLightShad
17
17
  }
18
18
  import { BufferAttribute, Color, DataTexture, Material, NormalBlending } from "./core-three.mjs";
19
19
  import { unsupportedExport } from "../../../../three-native/src/refused.ts";
20
- import { PassNode, StorageBufferAttribute, StorageInstancedBufferAttribute, syncUniforms, updateSecondaryPasses } from "./core-tsl.mjs";
20
+ import { IndirectStorageBufferAttribute, PassNode, StorageBufferAttribute, StorageInstancedBufferAttribute, syncUniforms, updateSecondaryPasses } from "./core-tsl.mjs";
21
21
  import { readStorageBytes } from "../../../../three-native/src/storage.ts";
22
22
  import { GAME_SPANS } from "../../../../core/src/profiling/Spans.ts";
23
23
  import { defineToneMappingLibrary } from "../../../../three-native/src/tone-mapping.ts";
24
24
  import { ShadowMap } from "../../../../three-native/src/shadow-map.ts";
25
25
  import { defineSphereReflectionCapture } from "../../../../three-native/src/sphere-reflection-capture.ts";
26
- import { defineRenderTargets } from "../../../../three-native/src/render-target.ts";
26
+ import { defineRenderTargets, textureCopyArguments } from "../../../../three-native/src/render-target.ts";
27
27
  import { defineQuadMesh } from "../../../../three-native/src/quad-mesh.ts";
28
28
  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, MeshPhysicalNodeMaterial, SpriteNodeMaterial } = globalThis;
32
+ export const { StorageTexture, Storage3DTexture, MeshBasicNodeMaterial, MeshStandardNodeMaterial, MeshPhysicalNodeMaterial, SpriteNodeMaterial } = globalThis;
33
33
  Object.setPrototypeOf(StorageTexture.prototype, globalThis.Texture.prototype);
34
+ Object.setPrototypeOf(Storage3DTexture.prototype, globalThis.Texture.prototype);
34
35
  Object.setPrototypeOf(MeshBasicNodeMaterial.prototype, globalThis.MeshBasicMaterial.prototype);
35
36
  Object.setPrototypeOf(MeshStandardNodeMaterial.prototype, globalThis.MeshStandardMaterial.prototype);
36
37
  Object.setPrototypeOf(MeshPhysicalNodeMaterial.prototype, globalThis.MeshPhysicalMaterial.prototype);
@@ -62,11 +63,11 @@ class NativeBackend {
62
63
  }
63
64
  }
64
65
 
65
- function drawTarget(renderer, target, root, camera, deferred) {
66
+ function drawTarget(renderer, target, root, camera, deferred, layer = 0) {
66
67
  syncUniforms();
67
68
  renderer.library.apply(renderer.toneMapping);
68
69
  globalThis.tn.setRendererState(renderer); // the target clears to the renderer's current clear colour
69
- globalThis.tn.renderTarget(target, root, camera, deferred === true, renderer.autoClear !== false);
70
+ globalThis.tn.renderTarget(target, root, camera, deferred === true, renderer.autoClear !== false, layer);
70
71
  }
71
72
 
72
73
  // Every offscreen PassNode plans its draw into its own target; the player records it in this frame, after the post
@@ -118,6 +119,13 @@ export class WebGPURenderer {
118
119
  if (segments[0] > 0) stages[SHADOW_STAGE] = segments[0];
119
120
  return stages;
120
121
  },
122
+ // The same sample split by pass, as the Wasm engine publishes it (PRD-871): the scene pass, every shadow map (sun
123
+ // and lamps), and the rest (other passes, output, gather). Core's `gpuFrameSample` hands it to TN_FRAME_BUDGET.
124
+ get gpuSplit() {
125
+ const { samples, source, segments } = globalThis.tn.renderInfo().gpuTiming;
126
+ if (!(samples > 0)) return undefined;
127
+ return { frame: source, main: segments[1], shadow: segments[0] + segments[5], other: segments[2] + segments[3] + segments[4] };
128
+ },
121
129
  },
122
130
  frame: 0,
123
131
  reset() {},
@@ -158,6 +166,9 @@ export class WebGPURenderer {
158
166
  const { width, height } = globalThis.tn.surfaceSize();
159
167
  return target.set(width, height);
160
168
  }
169
+ // render() publishes the frame, and the player draws it after the frame callback: the engine runs
170
+ // onBeforeRender then, so core's geometry capture keeps its hooks until the next frame.
171
+ drawsAfterFrame = true;
161
172
  render(scene, camera) {
162
173
  updateTempNodes(this, scene, camera);
163
174
  drawSecondaryPasses(this);
@@ -214,13 +225,19 @@ export class WebGPURenderer {
214
225
  }
215
226
  // Drops the attribute's GPU copy; the next use uploads its CPU contents again.
216
227
  deleteAttribute(attribute) { globalThis.tn.deleteStorage(attribute); return this; }
228
+ // three's initTexture and copyTextureToTexture (as the Wasm back end's): `source.dataReady = false` uploads nothing,
229
+ // because the copies write the texels. A call before the player opens its renderer runs when it opens.
230
+ initTexture(texture) { globalThis.tn.initTexture(texture, texture?.source?.dataReady === false); }
231
+ copyTextureToTexture(source, destination, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = 0) {
232
+ globalThis.tn.copyTexture(source, destination, ...textureCopyArguments(srcRegion, dstPosition, srcLevel, dstLevel));
233
+ }
217
234
  dispose() {}
218
235
  }
219
236
 
220
237
  // three's render targets (shared with the Wasm back end): render() while a target is set draws into
221
238
  // it at the call, and readRenderTargetPixelsAsync reads it back once the GPU copy lands.
222
239
  defineRenderTargets(WebGPURenderer.prototype, (renderer) => ({
223
- draw: (target, root, camera) => drawTarget(renderer, target, root, camera),
240
+ draw: (target, root, camera, layer) => drawTarget(renderer, target, root, camera, false, layer),
224
241
  clear: (target, color, depth) => {
225
242
  globalThis.tn.setRendererState(renderer); // the clear colour
226
243
  globalThis.tn.clearTarget(target, color, depth);
@@ -279,9 +296,10 @@ export class RenderPipeline {
279
296
  export { PassNode };
280
297
  // three's NodeUpdateType, the constants a node's update schedule names.
281
298
  export const NodeUpdateType = Object.freeze({ NONE: "none", FRAME: "frame", RENDER: "render", OBJECT: "object" });
282
- // three's StorageBufferAttribute and StorageInstancedBufferAttribute: BufferAttributes that TSL storage() binds
283
- // as storage buffers (defined with the storage nodes, in core-tsl.mjs).
284
- export { StorageBufferAttribute, StorageInstancedBufferAttribute };
299
+ // three's StorageBufferAttribute, StorageInstancedBufferAttribute and IndirectStorageBufferAttribute: BufferAttributes
300
+ // that TSL storage() binds as storage buffers, and that a geometry's setIndirect() takes (defined with the storage
301
+ // nodes, in core-tsl.mjs).
302
+ export { StorageBufferAttribute, StorageInstancedBufferAttribute, IndirectStorageBufferAttribute };
285
303
  export const MeshLambertNodeMaterial = unsupportedExport("MeshLambertNodeMaterial");
286
304
  export const MeshMatcapNodeMaterial = unsupportedExport("MeshMatcapNodeMaterial");
287
305
  export const MeshNormalNodeMaterial = unsupportedExport("MeshNormalNodeMaterial");
@@ -315,6 +333,8 @@ NodeMaterial.prototype.isNodeMaterial = true;
315
333
  export const RendererUtils = defineRendererUtils(Color);
316
334
  // Refused at use: only VirtualShadowNode.setup builds one, and the engine draws that map in C++.
317
335
  export const AssignNode = unsupportedExport("AssignNode");
336
+ export const BundleGroup = unsupportedExport("BundleGroup");
337
+ export const EventNode = unsupportedExport("EventNode");
318
338
 
319
339
  WebGPURenderer.prototype.SphereReflectionCapture = defineSphereReflectionCapture(
320
340
  async (scene, x, y, z, size, face, renderer) => {