@rings-webgpu/core 1.0.46 → 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.
@@ -24312,75 +24312,44 @@ struct InstanceData {
24312
24312
  }
24313
24313
 
24314
24314
  const _floatView$1 = new Float32Array(1);
24315
- const _int32View$1 = new Int32Array(_floatView$1.buffer);
24316
- function batchConvertToHalfFloat(src, dst, offset, length) {
24317
- for (let i = 0; i < length; i++) {
24318
- const val = src[offset + i];
24319
- _floatView$1[0] = val;
24320
- const x = _int32View$1[0];
24321
- let bits = x >> 16 & 32768;
24322
- let m = x >> 12 & 2047;
24323
- const e = x >> 23 & 255;
24324
- if (e < 103) {
24325
- dst[offset + i] = bits;
24326
- continue;
24327
- }
24328
- if (e > 142) {
24329
- bits |= 31744;
24330
- bits |= (e == 255 ? 1 : 0) && x & 8388607;
24331
- dst[offset + i] = bits;
24332
- continue;
24333
- }
24334
- if (e < 114) {
24335
- m |= 2048;
24336
- bits |= (m >> 114 - e) + (m >> 113 - e & 1);
24337
- dst[offset + i] = bits;
24338
- continue;
24339
- }
24340
- bits |= e - 112 << 10 | m >> 1;
24341
- bits += m & 1;
24342
- dst[offset + i] = bits;
24343
- }
24344
- }
24315
+ new Int32Array(_floatView$1.buffer);
24345
24316
  class Float16ArrayTexture extends Texture {
24346
24317
  uint16Array;
24347
- floatArray;
24348
24318
  _dataBuffer;
24349
24319
  /**
24350
- * 使用数字数组填充纹理,格式为[红0, 绿0, 蓝0, 透明度0, 红1, 绿1, 蓝1, 透明度1...]
24320
+ * 使用 Uint16Array 填充纹理(Float16 格式),格式为[红0, 绿0, 蓝0, 透明度0, 红1, 绿1, 蓝1, 透明度1...]
24351
24321
  * @param width 纹理宽度
24352
24322
  * @param height 纹理高度
24353
- * @param numbers 每个像素的颜色值数组
24323
+ * @param data Float16 数据数组(Uint16Array),每个元素是一个 Float16 值
24354
24324
  * @param useMipmap 是否生成Mipmap
24355
24325
  * @returns 返回纹理实例
24356
24326
  */
24357
- create(width, height, numbers = null, mipmap = true) {
24358
- if (numbers == null) {
24359
- numbers = [];
24360
- for (let i = 0, c = width * height * 4; i < c; i++) {
24361
- numbers[i] = 0;
24362
- }
24327
+ create(width, height, data = null, mipmap = true) {
24328
+ if (data == null) {
24329
+ const size = width * height * 4;
24330
+ data = new Uint16Array(size);
24331
+ data.fill(0);
24363
24332
  }
24364
- this.updateTexture(width, height, numbers, mipmap);
24333
+ this.updateTexture(width, height, data, mipmap);
24365
24334
  return this;
24366
24335
  }
24367
24336
  /**
24368
24337
  * 更新纹理内容
24369
24338
  * @param width 纹理宽度
24370
24339
  * @param height 纹理高度
24371
- * @param numbers 像素数据数组
24340
+ * @param data Float16 数据数组(Uint16Array),每个元素是一个 Float16 值
24372
24341
  * @param mipmap 是否生成Mipmap
24373
24342
  * @param startRow 起始行(部分更新)
24374
24343
  * @param rowCount 更新的行数(部分更新)
24375
24344
  */
24376
- updateTexture(width, height, numbers, mipmap = true, startRow, rowCount) {
24345
+ updateTexture(width, height, data, mipmap = true, startRow, rowCount) {
24377
24346
  if (width != this.width || height != this.height) {
24378
24347
  this._dataBuffer && this._dataBuffer.destroy();
24379
24348
  this._dataBuffer = null;
24380
24349
  this.gpuTexture && this.gpuTexture.destroy();
24381
24350
  this.gpuTexture = null;
24382
24351
  }
24383
- this.floatArray = numbers;
24352
+ this.uint16Array = data;
24384
24353
  let device = webGPUContext.device;
24385
24354
  const bytesPerRow = width * 4 * 2;
24386
24355
  this.format = GPUTextureFormat.rgba16float;
@@ -24390,14 +24359,7 @@ struct InstanceData {
24390
24359
  const updateHeight = rowCount;
24391
24360
  const updateOffset = startRow * width * 4;
24392
24361
  const updateLength = updateHeight * width * 4;
24393
- if (!this.uint16Array || this.uint16Array.length < updateOffset + updateLength) {
24394
- if (!this.uint16Array || this.uint16Array.length < numbers.length) {
24395
- this.uint16Array = new Uint16Array(numbers.length);
24396
- }
24397
- }
24398
- const uint16Array2 = this.uint16Array;
24399
- batchConvertToHalfFloat(numbers, uint16Array2, updateOffset, updateLength);
24400
- const updateData = uint16Array2.subarray(updateOffset, updateOffset + updateLength);
24362
+ const updateData = data.subarray(updateOffset, updateOffset + updateLength);
24401
24363
  const neededSize2 = updateData.byteLength;
24402
24364
  if (!this._dataBuffer || this._dataBuffer.size < neededSize2) {
24403
24365
  this._dataBuffer && this._dataBuffer.destroy();
@@ -24432,11 +24394,7 @@ struct InstanceData {
24432
24394
  GPUContext.endCommandEncoder(commandEncoder2);
24433
24395
  return;
24434
24396
  }
24435
- if (!this.uint16Array || this.uint16Array.length != numbers.length) {
24436
- this.uint16Array = new Uint16Array(numbers.length);
24437
- }
24438
- const uint16Array = this.uint16Array;
24439
- batchConvertToHalfFloat(numbers, uint16Array, 0, numbers.length);
24397
+ const uint16Array = data;
24440
24398
  const neededSize = uint16Array.byteLength;
24441
24399
  if (!this._dataBuffer || this._dataBuffer.size < neededSize) {
24442
24400
  this._dataBuffer && this._dataBuffer.destroy();
@@ -24825,7 +24783,8 @@ struct InstanceData {
24825
24783
  const h = this.size.y | 0;
24826
24784
  const count = asset.count;
24827
24785
  const tA = new Uint32Array(w * h * 4);
24828
- const tB = new Array(w * h * 4).fill(0);
24786
+ const tB = new Uint16Array(w * h * 4);
24787
+ tB.fill(0);
24829
24788
  const fb = new ArrayBuffer(4);
24830
24789
  const f32 = new Float32Array(fb);
24831
24790
  const u32 = new Uint32Array(fb);
@@ -24899,10 +24858,10 @@ struct InstanceData {
24899
24858
  const cBy = r01 * r02 + r11 * r12 + r21 * r22;
24900
24859
  const cBz = r02 * r02 + r12 * r12 + r22 * r22;
24901
24860
  const bidx = idx;
24902
- tB[bidx + 0] = cAx;
24903
- tB[bidx + 1] = cAy;
24904
- tB[bidx + 2] = cAz;
24905
- tB[bidx + 3] = cBz;
24861
+ tB[bidx + 0] = toHalfFloat(cAx) & 65535;
24862
+ tB[bidx + 1] = toHalfFloat(cAy) & 65535;
24863
+ tB[bidx + 2] = toHalfFloat(cAz) & 65535;
24864
+ tB[bidx + 3] = toHalfFloat(cBz) & 65535;
24906
24865
  const hx = toHalfFloat(cBx) & 65535;
24907
24866
  const hy = toHalfFloat(cBy) & 65535;
24908
24867
  tA[idx + 3] = hx | hy << 16;
@@ -42374,7 +42333,7 @@ else if (typeof exports === 'object')
42374
42333
  }
42375
42334
  }
42376
42335
 
42377
- const version = "1.0.45";
42336
+ const version = "1.0.48";
42378
42337
 
42379
42338
  class Engine3D {
42380
42339
  /**
@@ -54637,7 +54596,7 @@ fn frag(){
54637
54596
  _transformAData;
54638
54597
  // RGBA32U: count * 4
54639
54598
  _transformBData;
54640
- // RGBA16F: count * 4
54599
+ // RGBA16F: count * 4 (Float16 format)
54641
54600
  _orderData;
54642
54601
  // R32U: size.x * size.y
54643
54602
  _positions;
@@ -54695,7 +54654,8 @@ fn frag(){
54695
54654
  this._colorData.fill(0);
54696
54655
  this._transformAData = new Uint32Array(total * 4);
54697
54656
  this._transformAData.fill(0);
54698
- this._transformBData = new Array(total * 4).fill(0);
54657
+ this._transformBData = new Uint16Array(total * 4);
54658
+ this._transformBData.fill(0);
54699
54659
  this._orderData = new Uint32Array(total);
54700
54660
  for (let i = 0; i < total; i++) {
54701
54661
  this._orderData[i] = i < totalCount ? i : totalCount > 0 ? totalCount - 1 : 0;
@@ -54845,10 +54805,10 @@ fn frag(){
54845
54805
  const cBy = r01 * r02 + r11 * r12 + r21 * r22;
54846
54806
  const cBz = r02 * r02 + r12 * r12 + r22 * r22;
54847
54807
  const bidx = idx;
54848
- this._transformBData[bidx + 0] = cAx;
54849
- this._transformBData[bidx + 1] = cAy;
54850
- this._transformBData[bidx + 2] = cAz;
54851
- this._transformBData[bidx + 3] = cBz;
54808
+ this._transformBData[bidx + 0] = toHalfFloat(cAx) & 65535;
54809
+ this._transformBData[bidx + 1] = toHalfFloat(cAy) & 65535;
54810
+ this._transformBData[bidx + 2] = toHalfFloat(cAz) & 65535;
54811
+ this._transformBData[bidx + 3] = toHalfFloat(cBz) & 65535;
54852
54812
  const hx = toHalfFloat(cBx) & 65535;
54853
54813
  const hy = toHalfFloat(cBy) & 65535;
54854
54814
  this._transformAData[idx + 3] = hx | hy << 16;
@@ -62207,6 +62167,11 @@ fn frag(){
62207
62167
  _onSplatParsed = null;
62208
62168
  _batchSize = 1e3;
62209
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";
62210
62175
  constructor(onHeaderParsed, onSplatParsed, batchSize = 1e3) {
62211
62176
  this._onHeaderParsed = onHeaderParsed;
62212
62177
  this._onSplatParsed = onSplatParsed;
@@ -62229,6 +62194,14 @@ fn frag(){
62229
62194
  */
62230
62195
  cancel() {
62231
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
+ }
62232
62205
  }
62233
62206
  /**
62234
62207
  * Check if parsing is cancelled
@@ -62397,21 +62370,36 @@ fn frag(){
62397
62370
  }
62398
62371
  /**
62399
62372
  * Parse vertices from current data buffer
62373
+ * Entry point - checks if async processing is already scheduled
62400
62374
  */
62401
62375
  _parseVertices() {
62402
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
+ }
62403
62390
  const payload = new DataView(this._dataBuffer.buffer, this._dataBuffer.byteOffset, this._dataBuffer.byteLength);
62404
62391
  const vertexCount = this._header.vertexCount;
62405
62392
  const has = (n) => this._properties.find((p) => p.name === n) != null;
62406
62393
  const propIndex = (n) => this._properties.findIndex((p) => p.name === n);
62394
+ const startTime = performance.now();
62395
+ const maxProcessingTime = 5;
62396
+ let processedInThisChunk = 0;
62407
62397
  while (this._processedVertices < vertexCount && !this._cancelled) {
62408
62398
  const v = this._processedVertices;
62409
62399
  const vOffset = v * this._vertexStride;
62410
62400
  if (vOffset + this._vertexStride > this._dataOffset) {
62411
- break;
62412
- }
62413
- if (this._cancelled) {
62414
- break;
62401
+ this._parseTimeoutId = null;
62402
+ return;
62415
62403
  }
62416
62404
  const ix = propIndex("x");
62417
62405
  const iy = propIndex("y");
@@ -62477,12 +62465,47 @@ fn frag(){
62477
62465
  this._onSplatParsed(splatData, v);
62478
62466
  }
62479
62467
  this._processedVertices++;
62468
+ processedInThisChunk++;
62480
62469
  if (this._processedVertices % this._batchSize === 0) {
62481
- setTimeout(() => {
62482
- this._parseVertices();
62483
- }, 0);
62470
+ this._scheduleNextChunk();
62484
62471
  return;
62485
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);
62486
62509
  }
62487
62510
  }
62488
62511
  /**
@@ -71936,14 +71959,19 @@ fn frag(){
71936
71959
  this.color.b,
71937
71960
  this.color.a
71938
71961
  );
71939
- this._internalTexture.create(this._minSize, this._minSize, numbers, false);
71962
+ const float16Data = new Uint16Array(numbers.length);
71963
+ for (let i = 0; i < numbers.length; i++) {
71964
+ float16Data[i] = toHalfFloat(numbers[i]) & 65535;
71965
+ }
71966
+ this._internalTexture.create(this._minSize, this._minSize, float16Data, false);
71940
71967
  this.createFromTexture(this._minSize, this._internalTexture);
71941
71968
  return this;
71942
71969
  }
71943
71970
  changeColor(color) {
71944
71971
  this._skyColor = color;
71972
+ const numbers = [];
71945
71973
  Engine3D.res.fillColor(
71946
- this._internalTexture.floatArray,
71974
+ numbers,
71947
71975
  this._minSize,
71948
71976
  this._minSize,
71949
71977
  this.color.r,
@@ -71951,10 +71979,14 @@ fn frag(){
71951
71979
  this.color.b,
71952
71980
  this.color.a
71953
71981
  );
71982
+ const float16Data = new Uint16Array(numbers.length);
71983
+ for (let i = 0; i < numbers.length; i++) {
71984
+ float16Data[i] = toHalfFloat(numbers[i]) & 65535;
71985
+ }
71954
71986
  this._internalTexture.updateTexture(
71955
71987
  this._minSize,
71956
71988
  this._minSize,
71957
- this._internalTexture.floatArray,
71989
+ float16Data,
71958
71990
  false
71959
71991
  );
71960
71992
  this._faceData.uploadTexture(0, this._internalTexture);
@@ -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
  */
@@ -6,25 +6,24 @@ import { Texture } from "../gfx/graphics/webGpu/core/texture/Texture";
6
6
  */
7
7
  export declare class Float16ArrayTexture extends Texture {
8
8
  uint16Array: Uint16Array;
9
- floatArray: number[];
10
9
  private _dataBuffer;
11
10
  /**
12
- * 使用数字数组填充纹理,格式为[红0, 绿0, 蓝0, 透明度0, 红1, 绿1, 蓝1, 透明度1...]
11
+ * 使用 Uint16Array 填充纹理(Float16 格式),格式为[红0, 绿0, 蓝0, 透明度0, 红1, 绿1, 蓝1, 透明度1...]
13
12
  * @param width 纹理宽度
14
13
  * @param height 纹理高度
15
- * @param numbers 每个像素的颜色值数组
14
+ * @param data Float16 数据数组(Uint16Array),每个元素是一个 Float16 值
16
15
  * @param useMipmap 是否生成Mipmap
17
16
  * @returns 返回纹理实例
18
17
  */
19
- create(width: number, height: number, numbers?: number[], mipmap?: boolean): this;
18
+ create(width: number, height: number, data?: Uint16Array | null, mipmap?: boolean): this;
20
19
  /**
21
20
  * 更新纹理内容
22
21
  * @param width 纹理宽度
23
22
  * @param height 纹理高度
24
- * @param numbers 像素数据数组
23
+ * @param data Float16 数据数组(Uint16Array),每个元素是一个 Float16 值
25
24
  * @param mipmap 是否生成Mipmap
26
25
  * @param startRow 起始行(部分更新)
27
26
  * @param rowCount 更新的行数(部分更新)
28
27
  */
29
- updateTexture(width: number, height: number, numbers: number[], mipmap?: boolean, startRow?: number, rowCount?: number): void;
28
+ updateTexture(width: number, height: number, data: Uint16Array, mipmap?: boolean, startRow?: number, rowCount?: number): void;
30
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rings-webgpu/core",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "description": "Rings webgpu Engine",
5
5
  "main": "index.js",
6
6
  "exports": {