@rings-webgpu/core 1.0.47 → 1.0.48

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.
@@ -42333,7 +42333,7 @@ else if (typeof exports === 'object')
42333
42333
  }
42334
42334
  }
42335
42335
 
42336
- const version = "1.0.46";
42336
+ const version = "1.0.48";
42337
42337
 
42338
42338
  class Engine3D {
42339
42339
  /**
@@ -62167,6 +62167,11 @@ fn frag(){
62167
62167
  _onSplatParsed = null;
62168
62168
  _batchSize = 1e3;
62169
62169
  _cancelled = false;
62170
+ // Async processing state
62171
+ _parseTimeoutId = null;
62172
+ _verticesPerChunk = 1e7;
62173
+ // Number of vertices to process per chunk
62174
+ _useIdleCallback = typeof requestIdleCallback !== "undefined";
62170
62175
  constructor(onHeaderParsed, onSplatParsed, batchSize = 1e3) {
62171
62176
  this._onHeaderParsed = onHeaderParsed;
62172
62177
  this._onSplatParsed = onSplatParsed;
@@ -62189,6 +62194,14 @@ fn frag(){
62189
62194
  */
62190
62195
  cancel() {
62191
62196
  this._cancelled = true;
62197
+ if (this._parseTimeoutId !== null) {
62198
+ if (this._useIdleCallback) {
62199
+ cancelIdleCallback(this._parseTimeoutId);
62200
+ } else {
62201
+ clearTimeout(this._parseTimeoutId);
62202
+ }
62203
+ this._parseTimeoutId = null;
62204
+ }
62192
62205
  }
62193
62206
  /**
62194
62207
  * Check if parsing is cancelled
@@ -62357,21 +62370,36 @@ fn frag(){
62357
62370
  }
62358
62371
  /**
62359
62372
  * Parse vertices from current data buffer
62373
+ * Entry point - checks if async processing is already scheduled
62360
62374
  */
62361
62375
  _parseVertices() {
62362
62376
  if (!this._header || !this._dataBuffer) return;
62377
+ if (this._parseTimeoutId !== null) {
62378
+ return;
62379
+ }
62380
+ this._parseVerticesChunk();
62381
+ }
62382
+ /**
62383
+ * Parse a chunk of vertices with time and count limits
62384
+ */
62385
+ _parseVerticesChunk() {
62386
+ if (!this._header || !this._dataBuffer || this._cancelled) {
62387
+ this._parseTimeoutId = null;
62388
+ return;
62389
+ }
62363
62390
  const payload = new DataView(this._dataBuffer.buffer, this._dataBuffer.byteOffset, this._dataBuffer.byteLength);
62364
62391
  const vertexCount = this._header.vertexCount;
62365
62392
  const has = (n) => this._properties.find((p) => p.name === n) != null;
62366
62393
  const propIndex = (n) => this._properties.findIndex((p) => p.name === n);
62394
+ const startTime = performance.now();
62395
+ const maxProcessingTime = 5;
62396
+ let processedInThisChunk = 0;
62367
62397
  while (this._processedVertices < vertexCount && !this._cancelled) {
62368
62398
  const v = this._processedVertices;
62369
62399
  const vOffset = v * this._vertexStride;
62370
62400
  if (vOffset + this._vertexStride > this._dataOffset) {
62371
- break;
62372
- }
62373
- if (this._cancelled) {
62374
- break;
62401
+ this._parseTimeoutId = null;
62402
+ return;
62375
62403
  }
62376
62404
  const ix = propIndex("x");
62377
62405
  const iy = propIndex("y");
@@ -62437,12 +62465,47 @@ fn frag(){
62437
62465
  this._onSplatParsed(splatData, v);
62438
62466
  }
62439
62467
  this._processedVertices++;
62468
+ processedInThisChunk++;
62440
62469
  if (this._processedVertices % this._batchSize === 0) {
62441
- setTimeout(() => {
62442
- this._parseVertices();
62443
- }, 0);
62470
+ this._scheduleNextChunk();
62444
62471
  return;
62445
62472
  }
62473
+ if (processedInThisChunk >= this._verticesPerChunk) {
62474
+ const elapsed = performance.now() - startTime;
62475
+ if (elapsed > maxProcessingTime) {
62476
+ this._scheduleNextChunk();
62477
+ return;
62478
+ }
62479
+ processedInThisChunk = 0;
62480
+ }
62481
+ }
62482
+ this._parseTimeoutId = null;
62483
+ }
62484
+ /**
62485
+ * Schedule next chunk of vertex processing
62486
+ */
62487
+ _scheduleNextChunk() {
62488
+ if (this._cancelled) {
62489
+ this._parseTimeoutId = null;
62490
+ return;
62491
+ }
62492
+ if (this._useIdleCallback) {
62493
+ this._parseTimeoutId = requestIdleCallback((deadline) => {
62494
+ this._parseTimeoutId = null;
62495
+ if (!this._cancelled && deadline.timeRemaining() > 0) {
62496
+ this._parseVerticesChunk();
62497
+ } else if (!this._cancelled) {
62498
+ this._parseTimeoutId = setTimeout(() => {
62499
+ this._parseTimeoutId = null;
62500
+ this._parseVerticesChunk();
62501
+ }, 0);
62502
+ }
62503
+ }, { timeout: 100 });
62504
+ } else {
62505
+ this._parseTimeoutId = setTimeout(() => {
62506
+ this._parseTimeoutId = null;
62507
+ this._parseVerticesChunk();
62508
+ }, 0);
62446
62509
  }
62447
62510
  }
62448
62511
  /**
@@ -21,6 +21,9 @@ export declare class PlyStreamParser {
21
21
  private _onSplatParsed;
22
22
  private _batchSize;
23
23
  private _cancelled;
24
+ private _parseTimeoutId;
25
+ private _verticesPerChunk;
26
+ private _useIdleCallback;
24
27
  constructor(onHeaderParsed: (header: PlyHeader) => void, onSplatParsed: (splatData: SplatData, index: number) => void, batchSize?: number);
25
28
  /**
26
29
  * Process incoming data chunk
@@ -53,8 +56,17 @@ export declare class PlyStreamParser {
53
56
  private _processDataChunk;
54
57
  /**
55
58
  * Parse vertices from current data buffer
59
+ * Entry point - checks if async processing is already scheduled
56
60
  */
57
61
  private _parseVertices;
62
+ /**
63
+ * Parse a chunk of vertices with time and count limits
64
+ */
65
+ private _parseVerticesChunk;
66
+ /**
67
+ * Schedule next chunk of vertex processing
68
+ */
69
+ private _scheduleNextChunk;
58
70
  /**
59
71
  * Get current parsing progress
60
72
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rings-webgpu/core",
3
- "version": "1.0.47",
3
+ "version": "1.0.48",
4
4
  "description": "Rings webgpu Engine",
5
5
  "main": "index.js",
6
6
  "exports": {