@rings-webgpu/core 1.0.45 → 1.0.47

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.
@@ -22850,13 +22850,15 @@ struct InstanceData {
22850
22850
  }
22851
22851
 
22852
22852
  // === calcSplatUV() - returns optional UV ===
22853
- fn calcSplatUV(orderId: u32, textureWidth: u32, numSplats: u32) -> vec2<i32> {
22853
+ fn getSplatId(orderId: u32, textureWidth: u32, numSplats: u32) -> u32 {
22854
22854
  let orderUV = vec2<i32>(
22855
22855
  i32(orderId % textureWidth),
22856
22856
  i32(orderId / textureWidth)
22857
22857
  );
22858
22858
 
22859
- let splatId = textureLoad(splatOrder, orderUV, 0).r;
22859
+ return u32(textureLoad(splatOrder, orderUV, 0).r);
22860
+ }
22861
+ fn calcSplatUV(splatId: u32, textureWidth: u32, numSplats: u32) -> vec2<i32> {
22860
22862
  return vec2<i32>(
22861
22863
  i32(splatId % textureWidth),
22862
22864
  i32(splatId / textureWidth)
@@ -22955,9 +22957,11 @@ struct InstanceData {
22955
22957
  if (orderId >= numSplats) {
22956
22958
  return discardSplat();
22957
22959
  }
22960
+
22961
+ let splatId = getSplatId(orderId, textureWidth, numSplats);
22958
22962
 
22959
22963
  // Calculate splat UV and load all data in one go
22960
- let splatUV = calcSplatUV(orderId, textureWidth, numSplats);
22964
+ let splatUV = calcSplatUV(splatId, textureWidth, numSplats);
22961
22965
  let splatData = getSplatData(splatUV);
22962
22966
 
22963
22967
  // Load color early for alpha test
@@ -24308,75 +24312,44 @@ struct InstanceData {
24308
24312
  }
24309
24313
 
24310
24314
  const _floatView$1 = new Float32Array(1);
24311
- const _int32View$1 = new Int32Array(_floatView$1.buffer);
24312
- function batchConvertToHalfFloat(src, dst, offset, length) {
24313
- for (let i = 0; i < length; i++) {
24314
- const val = src[offset + i];
24315
- _floatView$1[0] = val;
24316
- const x = _int32View$1[0];
24317
- let bits = x >> 16 & 32768;
24318
- let m = x >> 12 & 2047;
24319
- const e = x >> 23 & 255;
24320
- if (e < 103) {
24321
- dst[offset + i] = bits;
24322
- continue;
24323
- }
24324
- if (e > 142) {
24325
- bits |= 31744;
24326
- bits |= (e == 255 ? 1 : 0) && x & 8388607;
24327
- dst[offset + i] = bits;
24328
- continue;
24329
- }
24330
- if (e < 114) {
24331
- m |= 2048;
24332
- bits |= (m >> 114 - e) + (m >> 113 - e & 1);
24333
- dst[offset + i] = bits;
24334
- continue;
24335
- }
24336
- bits |= e - 112 << 10 | m >> 1;
24337
- bits += m & 1;
24338
- dst[offset + i] = bits;
24339
- }
24340
- }
24315
+ new Int32Array(_floatView$1.buffer);
24341
24316
  class Float16ArrayTexture extends Texture {
24342
24317
  uint16Array;
24343
- floatArray;
24344
24318
  _dataBuffer;
24345
24319
  /**
24346
- * 使用数字数组填充纹理,格式为[红0, 绿0, 蓝0, 透明度0, 红1, 绿1, 蓝1, 透明度1...]
24320
+ * 使用 Uint16Array 填充纹理(Float16 格式),格式为[红0, 绿0, 蓝0, 透明度0, 红1, 绿1, 蓝1, 透明度1...]
24347
24321
  * @param width 纹理宽度
24348
24322
  * @param height 纹理高度
24349
- * @param numbers 每个像素的颜色值数组
24323
+ * @param data Float16 数据数组(Uint16Array),每个元素是一个 Float16 值
24350
24324
  * @param useMipmap 是否生成Mipmap
24351
24325
  * @returns 返回纹理实例
24352
24326
  */
24353
- create(width, height, numbers = null, mipmap = true) {
24354
- if (numbers == null) {
24355
- numbers = [];
24356
- for (let i = 0, c = width * height * 4; i < c; i++) {
24357
- numbers[i] = 0;
24358
- }
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);
24359
24332
  }
24360
- this.updateTexture(width, height, numbers, mipmap);
24333
+ this.updateTexture(width, height, data, mipmap);
24361
24334
  return this;
24362
24335
  }
24363
24336
  /**
24364
24337
  * 更新纹理内容
24365
24338
  * @param width 纹理宽度
24366
24339
  * @param height 纹理高度
24367
- * @param numbers 像素数据数组
24340
+ * @param data Float16 数据数组(Uint16Array),每个元素是一个 Float16 值
24368
24341
  * @param mipmap 是否生成Mipmap
24369
24342
  * @param startRow 起始行(部分更新)
24370
24343
  * @param rowCount 更新的行数(部分更新)
24371
24344
  */
24372
- updateTexture(width, height, numbers, mipmap = true, startRow, rowCount) {
24345
+ updateTexture(width, height, data, mipmap = true, startRow, rowCount) {
24373
24346
  if (width != this.width || height != this.height) {
24374
24347
  this._dataBuffer && this._dataBuffer.destroy();
24375
24348
  this._dataBuffer = null;
24376
24349
  this.gpuTexture && this.gpuTexture.destroy();
24377
24350
  this.gpuTexture = null;
24378
24351
  }
24379
- this.floatArray = numbers;
24352
+ this.uint16Array = data;
24380
24353
  let device = webGPUContext.device;
24381
24354
  const bytesPerRow = width * 4 * 2;
24382
24355
  this.format = GPUTextureFormat.rgba16float;
@@ -24386,14 +24359,7 @@ struct InstanceData {
24386
24359
  const updateHeight = rowCount;
24387
24360
  const updateOffset = startRow * width * 4;
24388
24361
  const updateLength = updateHeight * width * 4;
24389
- if (!this.uint16Array || this.uint16Array.length < updateOffset + updateLength) {
24390
- if (!this.uint16Array || this.uint16Array.length < numbers.length) {
24391
- this.uint16Array = new Uint16Array(numbers.length);
24392
- }
24393
- }
24394
- const uint16Array2 = this.uint16Array;
24395
- batchConvertToHalfFloat(numbers, uint16Array2, updateOffset, updateLength);
24396
- const updateData = uint16Array2.subarray(updateOffset, updateOffset + updateLength);
24362
+ const updateData = data.subarray(updateOffset, updateOffset + updateLength);
24397
24363
  const neededSize2 = updateData.byteLength;
24398
24364
  if (!this._dataBuffer || this._dataBuffer.size < neededSize2) {
24399
24365
  this._dataBuffer && this._dataBuffer.destroy();
@@ -24428,11 +24394,7 @@ struct InstanceData {
24428
24394
  GPUContext.endCommandEncoder(commandEncoder2);
24429
24395
  return;
24430
24396
  }
24431
- if (!this.uint16Array || this.uint16Array.length != numbers.length) {
24432
- this.uint16Array = new Uint16Array(numbers.length);
24433
- }
24434
- const uint16Array = this.uint16Array;
24435
- batchConvertToHalfFloat(numbers, uint16Array, 0, numbers.length);
24397
+ const uint16Array = data;
24436
24398
  const neededSize = uint16Array.byteLength;
24437
24399
  if (!this._dataBuffer || this._dataBuffer.size < neededSize) {
24438
24400
  this._dataBuffer && this._dataBuffer.destroy();
@@ -24821,7 +24783,8 @@ struct InstanceData {
24821
24783
  const h = this.size.y | 0;
24822
24784
  const count = asset.count;
24823
24785
  const tA = new Uint32Array(w * h * 4);
24824
- const tB = new Array(w * h * 4).fill(0);
24786
+ const tB = new Uint16Array(w * h * 4);
24787
+ tB.fill(0);
24825
24788
  const fb = new ArrayBuffer(4);
24826
24789
  const f32 = new Float32Array(fb);
24827
24790
  const u32 = new Uint32Array(fb);
@@ -24895,10 +24858,10 @@ struct InstanceData {
24895
24858
  const cBy = r01 * r02 + r11 * r12 + r21 * r22;
24896
24859
  const cBz = r02 * r02 + r12 * r12 + r22 * r22;
24897
24860
  const bidx = idx;
24898
- tB[bidx + 0] = cAx;
24899
- tB[bidx + 1] = cAy;
24900
- tB[bidx + 2] = cAz;
24901
- 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;
24902
24865
  const hx = toHalfFloat(cBx) & 65535;
24903
24866
  const hy = toHalfFloat(cBy) & 65535;
24904
24867
  tA[idx + 3] = hx | hy << 16;
@@ -42370,7 +42333,7 @@ else if (typeof exports === 'object')
42370
42333
  }
42371
42334
  }
42372
42335
 
42373
- const version = "1.0.44";
42336
+ const version = "1.0.46";
42374
42337
 
42375
42338
  class Engine3D {
42376
42339
  /**
@@ -54633,7 +54596,7 @@ fn frag(){
54633
54596
  _transformAData;
54634
54597
  // RGBA32U: count * 4
54635
54598
  _transformBData;
54636
- // RGBA16F: count * 4
54599
+ // RGBA16F: count * 4 (Float16 format)
54637
54600
  _orderData;
54638
54601
  // R32U: size.x * size.y
54639
54602
  _positions;
@@ -54691,7 +54654,8 @@ fn frag(){
54691
54654
  this._colorData.fill(0);
54692
54655
  this._transformAData = new Uint32Array(total * 4);
54693
54656
  this._transformAData.fill(0);
54694
- this._transformBData = new Array(total * 4).fill(0);
54657
+ this._transformBData = new Uint16Array(total * 4);
54658
+ this._transformBData.fill(0);
54695
54659
  this._orderData = new Uint32Array(total);
54696
54660
  for (let i = 0; i < total; i++) {
54697
54661
  this._orderData[i] = i < totalCount ? i : totalCount > 0 ? totalCount - 1 : 0;
@@ -54841,10 +54805,10 @@ fn frag(){
54841
54805
  const cBy = r01 * r02 + r11 * r12 + r21 * r22;
54842
54806
  const cBz = r02 * r02 + r12 * r12 + r22 * r22;
54843
54807
  const bidx = idx;
54844
- this._transformBData[bidx + 0] = cAx;
54845
- this._transformBData[bidx + 1] = cAy;
54846
- this._transformBData[bidx + 2] = cAz;
54847
- 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;
54848
54812
  const hx = toHalfFloat(cBx) & 65535;
54849
54813
  const hy = toHalfFloat(cBy) & 65535;
54850
54814
  this._transformAData[idx + 3] = hx | hy << 16;
@@ -66409,6 +66373,7 @@ fn frag(){
66409
66373
  toggleTime: 0,
66410
66374
  queueProcessTime: 0
66411
66375
  };
66376
+ transCdnUrlFunc = null;
66412
66377
  constructor(url = null) {
66413
66378
  this.rootURL = url;
66414
66379
  this.lruCache = new LRUCache();
@@ -66857,7 +66822,7 @@ fn frag(){
66857
66822
  return parts.length > 1 ? parts[parts.length - 1] : "";
66858
66823
  };
66859
66824
  const extension = getUrlExtension(uri);
66860
- const fullUrl = url;
66825
+ const fullUrl = this.transCdnUrlFunc ? this.transCdnUrlFunc(url) : url;
66861
66826
  let scene = null;
66862
66827
  const loader = new FileLoader();
66863
66828
  switch (extension.toLowerCase()) {
@@ -71931,14 +71896,19 @@ fn frag(){
71931
71896
  this.color.b,
71932
71897
  this.color.a
71933
71898
  );
71934
- this._internalTexture.create(this._minSize, this._minSize, numbers, false);
71899
+ const float16Data = new Uint16Array(numbers.length);
71900
+ for (let i = 0; i < numbers.length; i++) {
71901
+ float16Data[i] = toHalfFloat(numbers[i]) & 65535;
71902
+ }
71903
+ this._internalTexture.create(this._minSize, this._minSize, float16Data, false);
71935
71904
  this.createFromTexture(this._minSize, this._internalTexture);
71936
71905
  return this;
71937
71906
  }
71938
71907
  changeColor(color) {
71939
71908
  this._skyColor = color;
71909
+ const numbers = [];
71940
71910
  Engine3D.res.fillColor(
71941
- this._internalTexture.floatArray,
71911
+ numbers,
71942
71912
  this._minSize,
71943
71913
  this._minSize,
71944
71914
  this.color.r,
@@ -71946,10 +71916,14 @@ fn frag(){
71946
71916
  this.color.b,
71947
71917
  this.color.a
71948
71918
  );
71919
+ const float16Data = new Uint16Array(numbers.length);
71920
+ for (let i = 0; i < numbers.length; i++) {
71921
+ float16Data[i] = toHalfFloat(numbers[i]) & 65535;
71922
+ }
71949
71923
  this._internalTexture.updateTexture(
71950
71924
  this._minSize,
71951
71925
  this._minSize,
71952
- this._internalTexture.floatArray,
71926
+ float16Data,
71953
71927
  false
71954
71928
  );
71955
71929
  this._faceData.uploadTexture(0, this._internalTexture);
@@ -136,6 +136,7 @@ export declare class TilesRenderer {
136
136
  private _bytesUsed;
137
137
  private _eventListeners;
138
138
  performanceStats: PerformanceStats;
139
+ transCdnUrlFunc: (oriUrl: string) => string;
139
140
  constructor(url?: string | null);
140
141
  /**
141
142
  * Get root tile
@@ -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.45",
3
+ "version": "1.0.47",
4
4
  "description": "Rings webgpu Engine",
5
5
  "main": "index.js",
6
6
  "exports": {