@threenative/three-native 0.3.18 → 0.3.20

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threenative/three-native",
3
- "version": "0.3.18",
3
+ "version": "0.3.20",
4
4
  "license": "MIT",
5
5
  "description": "The native engine's machine-readable compatibility catalog and the generators that adapt it to TypeScript declarations and the C binding ABI.",
6
6
  "keywords": [
package/src/audio.ts CHANGED
@@ -94,6 +94,7 @@ export function defineAudioClasses(engine: IAudioEngine) {
94
94
  filter: AudioNode | null = null;
95
95
  timeDelta = 0;
96
96
  #last: number | undefined;
97
+ #lastPose: Float64Array | undefined;
97
98
 
98
99
  constructor() {
99
100
  super();
@@ -151,6 +152,35 @@ export function defineAudioClasses(engine: IAudioEngine) {
151
152
  this.matrixWorld.decompose(position, quaternion, scale);
152
153
  forward.set(0, 0, -1).applyQuaternion(quaternion);
153
154
  up.set(0, 1, 0).applyQuaternion(quaternion);
155
+ const last = this.#lastPose;
156
+ if (
157
+ last !== undefined &&
158
+ last[0] === position.x &&
159
+ last[1] === position.y &&
160
+ last[2] === position.z &&
161
+ last[3] === forward.x &&
162
+ last[4] === forward.y &&
163
+ last[5] === forward.z &&
164
+ last[6] === up.x &&
165
+ last[7] === up.y &&
166
+ last[8] === up.z
167
+ ) {
168
+ return;
169
+ }
170
+ let next = last;
171
+ if (next === undefined) {
172
+ next = new Float64Array(9);
173
+ this.#lastPose = next;
174
+ }
175
+ next[0] = position.x;
176
+ next[1] = position.y;
177
+ next[2] = position.z;
178
+ next[3] = forward.x;
179
+ next[4] = forward.y;
180
+ next[5] = forward.z;
181
+ next[6] = up.x;
182
+ next[7] = up.y;
183
+ next[8] = up.z;
154
184
  if (listener.positionX) {
155
185
  const end = this.context.currentTime + this.timeDelta;
156
186
  const ramp = (name: string, value: number) =>
@@ -433,6 +463,7 @@ export function defineAudioClasses(engine: IAudioEngine) {
433
463
 
434
464
  class PositionalAudio extends Audio<PannerNode> {
435
465
  panner: PannerNode;
466
+ #lastPose: Float64Array | undefined;
436
467
 
437
468
  constructor(listener: AudioListener) {
438
469
  super(listener);
@@ -501,6 +532,29 @@ export function defineAudioClasses(engine: IAudioEngine) {
501
532
  if (refresh) this.updateWorldMatrix(true, false);
502
533
  this.matrixWorld.decompose(position, quaternion, scale);
503
534
  orientation.set(0, 0, 1).applyQuaternion(quaternion);
535
+ const last = this.#lastPose;
536
+ if (
537
+ last !== undefined &&
538
+ last[0] === position.x &&
539
+ last[1] === position.y &&
540
+ last[2] === position.z &&
541
+ last[3] === orientation.x &&
542
+ last[4] === orientation.y &&
543
+ last[5] === orientation.z
544
+ ) {
545
+ return;
546
+ }
547
+ let next = last;
548
+ if (next === undefined) {
549
+ next = new Float64Array(6);
550
+ this.#lastPose = next;
551
+ }
552
+ next[0] = position.x;
553
+ next[1] = position.y;
554
+ next[2] = position.z;
555
+ next[3] = orientation.x;
556
+ next[4] = orientation.y;
557
+ next[5] = orientation.z;
504
558
  const panner = this.panner as LegacyPanner;
505
559
  if (panner.positionX) {
506
560
  const end = this.context.currentTime + this.listener.timeDelta;
@@ -102,6 +102,17 @@ export interface IBrowserRuntime {
102
102
  * With `offset`/`count`, a copy of that scalar subrange only (a per-vertex setter syncs one item).
103
103
  */
104
104
  attributeArray?(self: IEngineRef, offset?: number, count?: number): TypedArray;
105
+ /**
106
+ * Copies the attribute's data (or subrange `[offset, offset + count)`) directly into `dest` at
107
+ * `destOffset` without intermediate allocations; returns the number of elements copied.
108
+ */
109
+ attributeReadInto?(
110
+ self: IEngineRef,
111
+ dest: TypedArray,
112
+ offset?: number,
113
+ count?: number,
114
+ destOffset?: number,
115
+ ): number;
105
116
  /**
106
117
  * Writes `array` into the attribute's data; present with attributeArray. With `offset`, writes that
107
118
  * subrange; without it, `array` must be the attribute's whole data.
@@ -49,6 +49,7 @@ export interface IAttributeSync {
49
49
  rangeOf(method: string, args: readonly unknown[], itemSize: number): readonly [number, number];
50
50
  syncRange(attribute: object, entry: { array: TypedArray }, offset: number, count: number): void;
51
51
  syncFull(attribute: object, entry: { array: TypedArray }): void;
52
+ syncRecords(attributes: readonly object[], ops: unknown): void;
52
53
  instanceItem(
53
54
  mesh: object,
54
55
  attribute: string,
@@ -63,6 +64,130 @@ export interface IAttributeSync {
63
64
  ): boolean;
64
65
  }
65
66
 
67
+ interface IRecordDirtyPlan {
68
+ readonly from: number[];
69
+ readonly to: number[];
70
+ readonly full: boolean[];
71
+ }
72
+
73
+ function addDirtySpan(plan: IRecordDirtyPlan, slot: number, start: number, end: number): boolean {
74
+ if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end < start)
75
+ return false;
76
+ if (end > start) {
77
+ if (start < (plan.from[slot] as number)) plan.from[slot] = start;
78
+ if (end > (plan.to[slot] as number)) plan.to[slot] = end;
79
+ }
80
+ return true;
81
+ }
82
+
83
+ function advanceGatherOp(
84
+ opList: ArrayLike<number>,
85
+ at: number,
86
+ slot: number,
87
+ plan: IRecordDirtyPlan,
88
+ ): number {
89
+ if (at + 4 > opList.length) return -1;
90
+ const stride = opList[at + 2] as number;
91
+ const blocks = opList[at + 3] as number;
92
+ if (
93
+ !Number.isSafeInteger(stride) ||
94
+ stride < 1 ||
95
+ !Number.isSafeInteger(blocks) ||
96
+ blocks < 0 ||
97
+ at + 4 + blocks * 2 > opList.length
98
+ )
99
+ return -1;
100
+ let total = 0;
101
+ for (let b = 0; b < blocks; b += 1) {
102
+ const count = opList[at + 5 + b * 2] as number;
103
+ if (!Number.isSafeInteger(count) || count < 0) return -1;
104
+ total += count;
105
+ }
106
+ return addDirtySpan(plan, slot, 0, total * stride) ? at + 4 + blocks * 2 : -1;
107
+ }
108
+
109
+ function advanceLanesOp(
110
+ opList: ArrayLike<number>,
111
+ at: number,
112
+ slot: number,
113
+ plan: IRecordDirtyPlan,
114
+ ): number {
115
+ if (at + 4 > opList.length) return -1;
116
+ const lanesCount = opList[at + 3] as number;
117
+ if (!Number.isSafeInteger(lanesCount) || lanesCount < 0 || at + 4 + lanesCount > opList.length)
118
+ return -1;
119
+ plan.full[slot] = true;
120
+ return at + 4 + lanesCount;
121
+ }
122
+
123
+ function stepRecordOp(
124
+ opList: ArrayLike<number>,
125
+ at: number,
126
+ slotCount: number,
127
+ plan: IRecordDirtyPlan,
128
+ ): number {
129
+ const code = opList[at];
130
+ const slot = opList[at + 1] as number;
131
+ if (!Number.isSafeInteger(slot) || slot < 0 || slot >= slotCount) return -1;
132
+ switch (code) {
133
+ case 1: {
134
+ if (at + 5 > opList.length) return -1;
135
+ const start = opList[at + 2] as number;
136
+ const count = opList[at + 3] as number;
137
+ return addDirtySpan(plan, slot, start, start + count) ? at + 5 : -1;
138
+ }
139
+ case 2: {
140
+ if (at + 4 > opList.length) return -1;
141
+ const start = opList[at + 2] as number;
142
+ const count = opList[at + 3] as number;
143
+ return addDirtySpan(plan, slot, start, start + count) ? at + 4 : -1;
144
+ }
145
+ case 3: {
146
+ if (at + 5 > opList.length) return -1;
147
+ const to = opList[at + 3] as number;
148
+ const count = opList[at + 4] as number;
149
+ return addDirtySpan(plan, slot, to, to + count) ? at + 5 : -1;
150
+ }
151
+ case 4: {
152
+ if (at + 4 > opList.length) return -1;
153
+ const count = opList[at + 3] as number;
154
+ return addDirtySpan(plan, slot, 0, count) ? at + 4 : -1;
155
+ }
156
+ case 5:
157
+ return advanceGatherOp(opList, at, slot, plan);
158
+ case 6:
159
+ return at + 4 <= opList.length ? at + 4 : -1;
160
+ case 7:
161
+ return at + 5 <= opList.length ? at + 5 : -1;
162
+ case 8:
163
+ return advanceLanesOp(opList, at, slot, plan);
164
+ default:
165
+ return -1;
166
+ }
167
+ }
168
+
169
+ function collectRecordDirty(ops: unknown, slotCount: number): IRecordDirtyPlan | undefined {
170
+ if (
171
+ ops === null ||
172
+ ops === undefined ||
173
+ typeof ops !== "object" ||
174
+ typeof (ops as ArrayLike<number>).length !== "number"
175
+ )
176
+ return undefined;
177
+ const opList = ops as ArrayLike<number>;
178
+ const plan: IRecordDirtyPlan = {
179
+ from: new Array<number>(slotCount).fill(Number.POSITIVE_INFINITY),
180
+ to: new Array<number>(slotCount).fill(0),
181
+ full: new Array<boolean>(slotCount).fill(false),
182
+ };
183
+ for (let at = 0; at < opList.length; ) {
184
+ const next = stepRecordOp(opList, at, slotCount, plan);
185
+ if (next <= at) return undefined;
186
+ at = next;
187
+ }
188
+ return plan;
189
+ }
190
+
66
191
  export function defineAttributeSync(host: IAttributeSyncHost): IAttributeSync {
67
192
  const { runtime, refOf } = host;
68
193
  // three's `attribute.array` is the attribute's own JS typed array (PRD-540): the array the
@@ -72,7 +197,7 @@ export function defineAttributeSync(host: IAttributeSyncHost): IAttributeSync {
72
197
  // later game edit to the array wins, and `needsUpdate` sends the array to the engine. A read hands
73
198
  // the game the array, so the attribute is `pending` until its array is written back before the next
74
199
  // engine call (a per-vertex setter reads no kept array and flushes nothing).
75
- const { attributeArray, attributeWrite } = runtime;
200
+ const { attributeArray, attributeReadInto, attributeWrite } = runtime;
76
201
  const arrays = new WeakMap<object, { array: TypedArray }>();
77
202
  const itemSizes = new WeakMap<object, number>();
78
203
  // Shape survives data uploads and transform calls; only copy/replacement changes it.
@@ -132,6 +257,21 @@ export function defineAttributeSync(host: IAttributeSyncHost): IAttributeSync {
132
257
  `TN_NATIVE_ATTRIBUTE_RANGE: [${String(offset)}, ${String(count)}) is not a valid element range`,
133
258
  );
134
259
  if (offset + count > entry.array.length) return;
260
+ if (attributeReadInto !== undefined) {
261
+ const copied = attributeReadInto.call(
262
+ runtime,
263
+ refOf(attribute),
264
+ entry.array,
265
+ offset,
266
+ count,
267
+ offset,
268
+ );
269
+ if (copied !== count)
270
+ throw new TypeError(
271
+ `TN_NATIVE_ATTRIBUTE_SYNC: attributeReadInto gave ${String(copied)} elements for [${String(offset)}, ${String(count)})`,
272
+ );
273
+ return;
274
+ }
135
275
  const fresh = attributeArray?.call(runtime, refOf(attribute), offset, count);
136
276
  if (fresh === undefined || fresh.length !== count)
137
277
  throw new TypeError(
@@ -140,11 +280,49 @@ export function defineAttributeSync(host: IAttributeSyncHost): IAttributeSync {
140
280
  entry.array.set(fresh, offset);
141
281
  };
142
282
  const syncFull = (attribute: object, entry: { array: TypedArray }): void => {
283
+ if (attributeReadInto !== undefined) {
284
+ try {
285
+ const copied = attributeReadInto.call(
286
+ runtime,
287
+ refOf(attribute),
288
+ entry.array,
289
+ 0,
290
+ undefined,
291
+ 0,
292
+ );
293
+ if (copied === entry.array.length) return;
294
+ } catch (error) {
295
+ if (!(error instanceof RangeError)) throw error;
296
+ }
297
+ }
143
298
  const fresh = attributeArray?.call(runtime, refOf(attribute));
144
299
  if (fresh === undefined) return;
145
300
  if (fresh.length === entry.array.length) entry.array.set(fresh);
146
301
  else entry.array = fresh;
147
302
  };
303
+ const syncRecords = (attributes: readonly object[], ops: unknown): void => {
304
+ const plan = collectRecordDirty(ops, attributes.length);
305
+ if (plan === undefined) {
306
+ for (const attribute of attributes) {
307
+ const entry = arrays.get(attribute);
308
+ if (entry !== undefined) syncFull(attribute, entry);
309
+ }
310
+ return;
311
+ }
312
+ for (let slot = 0; slot < attributes.length; slot += 1) {
313
+ const attribute = attributes[slot] as object;
314
+ const entry = arrays.get(attribute);
315
+ if (entry === undefined) continue;
316
+ if (plan.full[slot]) {
317
+ syncFull(attribute, entry);
318
+ continue;
319
+ }
320
+ const from = plan.from[slot] as number;
321
+ const to = plan.to[slot] as number;
322
+ if (from >= to || from >= entry.array.length) continue;
323
+ syncRange(attribute, entry, from, Math.min(to, entry.array.length) - from);
324
+ }
325
+ };
148
326
  // three's `InstancedMesh.setMatrixAt`/`setColorAt` write the mesh's own `instanceMatrix`/
149
327
  // `instanceColor` array item (`index * 16`, `index * 3`); the engine's mesh-level call writes only
150
328
  // its own store, so the shadow a game already holds (core's velocity capture reads one per mesh a
@@ -243,6 +421,7 @@ export function defineAttributeSync(host: IAttributeSyncHost): IAttributeSync {
243
421
  rangeOf,
244
422
  syncRange,
245
423
  syncFull,
424
+ syncRecords,
246
425
  instanceItem,
247
426
  writeItemAt,
248
427
  };
@@ -370,6 +370,17 @@ export function defineBrowserClasses(
370
370
  );
371
371
  return attributeArray(self, offset, count);
372
372
  };
373
+ const attributeReadInto = source.attributeReadInto;
374
+ if (attributeReadInto !== undefined)
375
+ runtime.attributeReadInto = (self, dest, offset, count, destOffset) => {
376
+ debug.crossing(
377
+ "attributeRead",
378
+ self,
379
+ "array",
380
+ typeNames.get(self.type) ?? String(self.type),
381
+ );
382
+ return attributeReadInto(self, dest, offset, count, destOffset);
383
+ };
373
384
  const attributeWrite = source.attributeWrite;
374
385
  if (attributeWrite !== undefined)
375
386
  runtime.attributeWrite = (self, value, offset) => {
@@ -519,7 +530,7 @@ export function defineBrowserClasses(
519
530
  let scheduling = new WeakMap<object, unknown>();
520
531
  // Object3D methods that move only the transform: the mirrored labels and numbers stay.
521
532
  const transformOnly =
522
- /^(updateMatrix|updateMatrixWorld|updateWorldMatrix|lookAt|rotate(X|Y|Z|OnAxis|OnWorldAxis)|translate(X|Y|Z|OnAxis)|apply(Matrix4|Quaternion)|setRotationFrom\w+|localToWorld|worldToLocal|updateProjectionMatrix)$/u;
533
+ /^(updateMatrix|updateMatrixWorld|updateWorldMatrix|lookAt|rotate(X|Y|Z|OnAxis|OnWorldAxis)|translate(X|Y|Z|OnAxis)|apply(Matrix4|Quaternion)|setRotationFrom\w+|localToWorld|worldToLocal|updateProjectionMatrix|__tnGroundSnapApply|__tnBillboardFace)$/u;
523
534
  // `__THREENATIVE_BRIDGE_CACHE__ = false` (a page global the worker host forwards) turns the mirror, the
524
535
  // hierarchy cache and the JS Layers test off at the next safe point: the paired A/B knob.
525
536
  const knob = "__THREENATIVE_BRIDGE_CACHE__";
@@ -703,6 +714,7 @@ export function defineBrowserClasses(
703
714
  rangeOf,
704
715
  syncRange,
705
716
  syncFull,
717
+ syncRecords,
706
718
  instanceItem,
707
719
  writeItemAt,
708
720
  } = defineAttributeSync({ runtime, refOf });
@@ -991,12 +1003,9 @@ export function defineBrowserClasses(
991
1003
  if (loans.length > mark) result = repay(mark, result);
992
1004
  if (drives) animated = new WeakMap();
993
1005
  // A native record batch writes other attributes through the receiver's method.
994
- // Keep their JS arrays current so a later read cannot upload pre-refilter data.
1006
+ // Sync only the scalar subranges the op stream wrote instead of reading whole buffers back.
995
1007
  if (method === "__tnRecords" && Array.isArray(args[0])) {
996
- for (const attribute of args[0] as object[]) {
997
- const entry = arrays.get(attribute);
998
- if (entry !== undefined) syncFull(attribute, entry);
999
- }
1008
+ syncRecords(args[0] as object[], args[1]);
1000
1009
  }
1001
1010
  }
1002
1011
  // The engine's clone and copy carry the material's graphs; the TSL nodes a slot reads back
@@ -883,7 +883,10 @@ export function defineTsl(
883
883
  };
884
884
  const setUniforms = runtime.setUniforms?.bind(runtime);
885
885
  const engineReads = runtime.reads?.bind(runtime);
886
- const hookIds: number[] = [];
886
+ const readsCache = new WeakMap<
887
+ readonly object[],
888
+ { ids: number[]; kernelCache?: Map<string, ArrayLike<number> | undefined> }
889
+ >();
887
890
  const live = liveUniforms(
888
891
  matrixUniform,
889
892
  (node, lanes) => runtime.setUniform(node[TSL_NODE], lanes),
@@ -895,17 +898,39 @@ export function defineTsl(
895
898
  lanes,
896
899
  )),
897
900
  // A scene's render runs every hook (its fog, background and lights read uniforms no mesh names); a draw of
898
- // a mesh (a post quad) or a dispatch runs the hooks its graphs read, which the engine answers (PRD-878).
901
+ // a mesh (a post quad) or a dispatch runs the hooks and scanned objects its graphs read, which the engine answers (PRD-878).
899
902
  engineReads &&
900
903
  ((frame, hooked) => {
901
904
  const root = frame.scene as { isScene?: unknown } | null | undefined;
902
905
  if (frame.kernels === undefined && (root == null || root.isScene === true))
903
906
  return undefined;
904
- for (let i = hookIds.length; i < hooked.length; i += 1)
905
- hookIds.push((hooked[i] as ITslNode)[TSL_NODE]);
906
907
  const ref = frame.kernels === undefined ? engineRef(root as object) : undefined;
907
908
  if (frame.kernels === undefined && ref === undefined) return undefined;
908
- return engineReads(ref, frame.kernels ?? [], hookIds);
909
+ let entry = readsCache.get(hooked);
910
+ if (entry === undefined) {
911
+ entry = { ids: [] };
912
+ readsCache.set(hooked, entry);
913
+ }
914
+ if (entry.ids.length < hooked.length) {
915
+ for (let i = entry.ids.length; i < hooked.length; i += 1)
916
+ entry.ids.push((hooked[i] as ITslNode)[TSL_NODE]);
917
+ // Newly registered uniforms in the same array invalidate prior kernel read selections.
918
+ entry.kernelCache?.clear();
919
+ }
920
+ const kernels = frame.kernels;
921
+ if (kernels !== undefined) {
922
+ const kernelKey = kernels.length === 1 ? String(kernels[0]) : kernels.join(",");
923
+ let cache = entry.kernelCache;
924
+ if (cache === undefined) {
925
+ cache = new Map();
926
+ entry.kernelCache = cache;
927
+ }
928
+ if (cache.has(kernelKey)) return cache.get(kernelKey);
929
+ const picked = engineReads(undefined, kernels, entry.ids);
930
+ cache.set(kernelKey, picked);
931
+ return picked;
932
+ }
933
+ return engineReads(ref, [], entry.ids);
909
934
  }),
910
935
  );
911
936
  exports.uniform = booleanUniforms(live.uniform, (scalar) =>
@@ -498,6 +498,27 @@ export function createWasmRuntime(abi: TnAbiModule): IBrowserRuntime {
498
498
  );
499
499
  return target.subarray(from, from + length).slice();
500
500
  }),
501
+ attributeReadInto: (self, dest, offset, count, destOffset) =>
502
+ withAttributeView(self, (target) => {
503
+ const from = offset === undefined ? 0 : offset;
504
+ const into = destOffset === undefined ? 0 : destOffset;
505
+ const length = count === undefined ? target.length - from : count;
506
+ if (
507
+ !Number.isSafeInteger(from) ||
508
+ !Number.isSafeInteger(length) ||
509
+ !Number.isSafeInteger(into) ||
510
+ from < 0 ||
511
+ length < 0 ||
512
+ into < 0 ||
513
+ from + length > target.length ||
514
+ into + length > dest.length
515
+ )
516
+ throw new RangeError(
517
+ `TN_NATIVE_ATTRIBUTE_RANGE: [${String(from)}, ${String(length)}) into [${String(into)}, ${String(dest.length)}) is outside ${String(target.length)} elements`,
518
+ );
519
+ dest.set(target.subarray(from, from + length) as never, into);
520
+ return length;
521
+ }),
501
522
  attributeWrite: (self, array, offset) =>
502
523
  withAttributeView(self, (target) => {
503
524
  // An omitted offset writes the whole attribute, so the array must be its exact data; an
@@ -204,6 +204,13 @@ export function liveUniforms<TNode extends object>(
204
204
  // every sync walks. ponytail: the value is the closest owner this module sees; the engine release of such a node
205
205
  // waits too.
206
206
  const objects = new Set<WeakRef<TNode>>();
207
+ let objectsVersion = 0;
208
+ let objectNodesVersion = -1;
209
+ let objectNodes: TNode[] = [];
210
+ const addObject = (node: TNode) => {
211
+ objects.add(new WeakRef(node));
212
+ objectsVersion += 1;
213
+ };
207
214
  const pinned = new WeakMap<object, TNode[]>();
208
215
  // The node lives exactly as long as `value` does, so a wrapper the game dropped is released with the object it
209
216
  // reads.
@@ -252,7 +259,7 @@ export function liveUniforms<TNode extends object>(
252
259
  const state = target === undefined ? undefined : states.get(target);
253
260
  if (target === undefined || state === undefined || state.scanned === true) continue;
254
261
  state.scanned = true;
255
- objects.add(new WeakRef(target));
262
+ addObject(target);
256
263
  own(target, value);
257
264
  }
258
265
  },
@@ -280,7 +287,7 @@ export function liveUniforms<TNode extends object>(
280
287
  dirty.add(new WeakRef(node)); // its first sync writes it, as a scan did
281
288
  if (state.scanned !== true && !watch(node, value)) {
282
289
  state.scanned = true;
283
- objects.add(new WeakRef(node));
290
+ addObject(node);
284
291
  own(node, value);
285
292
  }
286
293
  };
@@ -530,14 +537,53 @@ export function liveUniforms<TNode extends object>(
530
537
  }
531
538
  dirty.delete(ref);
532
539
  }
533
- for (const ref of objects) {
534
- const node = ref.deref();
535
- if (node === undefined) {
536
- objects.delete(ref);
537
- continue;
540
+ if (extra?.kernels !== undefined && reads !== undefined) {
541
+ if (objects.size > 0) {
542
+ if (objectNodesVersion !== objectsVersion) {
543
+ const fresh: TNode[] = [];
544
+ for (const ref of objects) {
545
+ const node = ref.deref();
546
+ if (node === undefined) {
547
+ objects.delete(ref);
548
+ continue;
549
+ }
550
+ fresh.push(node);
551
+ }
552
+ objectsVersion += 1;
553
+ objectNodesVersion = objectsVersion;
554
+ objectNodes = fresh;
555
+ }
556
+ if (objectNodes.length > 0) {
557
+ const pickedObjects = reads(extra, objectNodes);
558
+ if (pickedObjects !== undefined) {
559
+ for (let i = 0; i < pickedObjects.length; i += 1) {
560
+ const node = objectNodes[pickedObjects[i] as number];
561
+ if (node === undefined) continue;
562
+ const state = states.get(node);
563
+ if (state !== undefined)
564
+ write(node, state, uniformLanes(state.value, state.scratch));
565
+ }
566
+ } else {
567
+ for (let i = 0; i < objectNodes.length; i += 1) {
568
+ const node = objectNodes[i] as TNode;
569
+ const state = states.get(node);
570
+ if (state !== undefined)
571
+ write(node, state, uniformLanes(state.value, state.scratch));
572
+ }
573
+ }
574
+ }
575
+ }
576
+ } else {
577
+ for (const ref of objects) {
578
+ const node = ref.deref();
579
+ if (node === undefined) {
580
+ objects.delete(ref);
581
+ objectsVersion += 1;
582
+ continue;
583
+ }
584
+ const state = states.get(node);
585
+ if (state !== undefined) write(node, state, uniformLanes(state.value, state.scratch));
538
586
  }
539
- const state = states.get(node);
540
- if (state !== undefined) write(node, state, uniformLanes(state.value, state.scratch));
541
587
  }
542
588
  flush();
543
589
  } finally {