@rings-webgpu/core 1.0.28 → 1.0.30

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.
@@ -25253,9 +25253,9 @@ struct InstanceData {
25253
25253
  pass.passType = PassType.COLOR;
25254
25254
  pass.setShaderEntry("VertMain", "FragMain");
25255
25255
  pass.topology = GPUPrimitiveTopology.triangle_list;
25256
- pass.depthWriteEnabled = false;
25256
+ pass.depthWriteEnabled = true;
25257
25257
  pass.cullMode = GPUCullMode.none;
25258
- pass.shaderState.transparent = true;
25258
+ pass.shaderState.transparent = false;
25259
25259
  pass.shaderState.blendMode = BlendMode.NORMAL;
25260
25260
  pass.shaderState.writeMasks = [15, 15];
25261
25261
  pass.shaderState.castReflection = false;
@@ -39806,7 +39806,10 @@ else if (typeof exports === 'object')
39806
39806
  buffer;
39807
39807
  binOffset;
39808
39808
  binLength;
39809
- header;
39809
+ _header;
39810
+ get header() {
39811
+ return this._header;
39812
+ }
39810
39813
  constructor(buffer, start, headerLength, binLength) {
39811
39814
  this.buffer = buffer;
39812
39815
  this.binOffset = start + headerLength;
@@ -39818,13 +39821,13 @@ else if (typeof exports === 'object')
39818
39821
  } else {
39819
39822
  header = {};
39820
39823
  }
39821
- this.header = header;
39824
+ this._header = header;
39822
39825
  }
39823
39826
  getKeys() {
39824
- return Object.keys(this.header);
39827
+ return Object.keys(this._header);
39825
39828
  }
39826
39829
  getData(key, count, defaultComponentType = null, defaultType = null) {
39827
- const header = this.header;
39830
+ const header = this._header;
39828
39831
  if (!(key in header)) {
39829
39832
  return null;
39830
39833
  }
@@ -39906,7 +39909,7 @@ else if (typeof exports === 'object')
39906
39909
  }
39907
39910
  destroy() {
39908
39911
  this.buffer = null;
39909
- this.header = null;
39912
+ this._header = null;
39910
39913
  this.binOffset = null;
39911
39914
  this.binLength = null;
39912
39915
  }
@@ -42150,7 +42153,7 @@ else if (typeof exports === 'object')
42150
42153
  }
42151
42154
  }
42152
42155
 
42153
- const version = "1.0.27";
42156
+ const version = "1.0.29";
42154
42157
 
42155
42158
  class Engine3D {
42156
42159
  /**
@@ -61295,6 +61298,276 @@ fn frag(){
61295
61298
  }
61296
61299
  }
61297
61300
 
61301
+ class PNTSLoaderBase {
61302
+ async parse(buffer) {
61303
+ const dataView = new DataView(buffer);
61304
+ const magic = readMagicBytes(dataView);
61305
+ console.assert(magic === "pnts");
61306
+ const version = dataView.getUint32(4, true);
61307
+ console.assert(version === 1);
61308
+ const byteLength = dataView.getUint32(8, true);
61309
+ console.assert(byteLength === buffer.byteLength);
61310
+ const featureTableJSONByteLength = dataView.getUint32(12, true);
61311
+ const featureTableBinaryByteLength = dataView.getUint32(16, true);
61312
+ const batchTableJSONByteLength = dataView.getUint32(20, true);
61313
+ const batchTableBinaryByteLength = dataView.getUint32(24, true);
61314
+ const featureTableStart = 28;
61315
+ const featureTable = new FeatureTable(
61316
+ buffer,
61317
+ featureTableStart,
61318
+ featureTableJSONByteLength,
61319
+ featureTableBinaryByteLength
61320
+ );
61321
+ const batchTableStart = featureTableStart + featureTableJSONByteLength + featureTableBinaryByteLength;
61322
+ const pointsLength = featureTable.header.POINTS_LENGTH || 0;
61323
+ const batchTable = new BatchTable(
61324
+ buffer,
61325
+ pointsLength,
61326
+ batchTableStart,
61327
+ batchTableJSONByteLength,
61328
+ batchTableBinaryByteLength
61329
+ );
61330
+ return {
61331
+ version,
61332
+ featureTable,
61333
+ batchTable
61334
+ };
61335
+ }
61336
+ }
61337
+
61338
+ class PNTSLoader extends PNTSLoaderBase {
61339
+ async parse(buffer) {
61340
+ const pnts = await super.parse(buffer);
61341
+ const { featureTable, batchTable } = pnts;
61342
+ const pointsLength = featureTable.header.POINTS_LENGTH;
61343
+ if (!pointsLength || pointsLength <= 0) {
61344
+ throw new Error("PNTSLoader: POINTS_LENGTH must be defined and greater than zero");
61345
+ }
61346
+ const extensions = featureTable.header.extensions;
61347
+ const dracoExtension = extensions?.["3DTILES_draco_point_compression"];
61348
+ let positions;
61349
+ let colors;
61350
+ if (dracoExtension) {
61351
+ const dracoData = await this.parseDraco(
61352
+ featureTable,
61353
+ dracoExtension,
61354
+ pointsLength
61355
+ );
61356
+ positions = dracoData.positions;
61357
+ colors = dracoData.colors;
61358
+ dracoData.normals;
61359
+ } else {
61360
+ positions = this.parsePositions(featureTable, pointsLength);
61361
+ colors = this.parseColors(featureTable, pointsLength);
61362
+ this.parseNormals(featureTable, pointsLength);
61363
+ }
61364
+ const pointCloudObj = new exports.Object3D();
61365
+ const renderer = pointCloudObj.addComponent(exports.PointCloudRenderer);
61366
+ renderer.initFromData(positions, colors, pointsLength);
61367
+ renderer.setPointShape("circle");
61368
+ renderer.setPointSize(4);
61369
+ const rtcCenter = featureTable.getData("RTC_CENTER", 1, "FLOAT", "VEC3");
61370
+ if (rtcCenter) {
61371
+ pointCloudObj.transform.localPosition.set(
61372
+ rtcCenter[0],
61373
+ rtcCenter[1],
61374
+ rtcCenter[2]
61375
+ );
61376
+ }
61377
+ pointCloudObj["batchTable"] = batchTable;
61378
+ pointCloudObj["featureTable"] = featureTable;
61379
+ return pointCloudObj;
61380
+ }
61381
+ parsePositions(featureTable, pointsLength) {
61382
+ let positions = featureTable.getData(
61383
+ "POSITION",
61384
+ pointsLength,
61385
+ "FLOAT",
61386
+ "VEC3"
61387
+ );
61388
+ if (positions) {
61389
+ return positions;
61390
+ }
61391
+ const quantized = featureTable.getData(
61392
+ "POSITION_QUANTIZED",
61393
+ pointsLength,
61394
+ "UNSIGNED_SHORT",
61395
+ "VEC3"
61396
+ );
61397
+ if (!quantized) {
61398
+ throw new Error(
61399
+ "PNTSLoader: Either POSITION or POSITION_QUANTIZED must be defined"
61400
+ );
61401
+ }
61402
+ const scale = featureTable.getData(
61403
+ "QUANTIZED_VOLUME_SCALE",
61404
+ 1,
61405
+ "FLOAT",
61406
+ "VEC3"
61407
+ );
61408
+ const offset = featureTable.getData(
61409
+ "QUANTIZED_VOLUME_OFFSET",
61410
+ 1,
61411
+ "FLOAT",
61412
+ "VEC3"
61413
+ );
61414
+ if (!scale || !offset) {
61415
+ throw new Error(
61416
+ "PNTSLoader: QUANTIZED_VOLUME_SCALE and QUANTIZED_VOLUME_OFFSET must be defined for quantized positions"
61417
+ );
61418
+ }
61419
+ const decoded = new Float32Array(pointsLength * 3);
61420
+ const quantizedRange = 65535;
61421
+ for (let i = 0; i < pointsLength; i++) {
61422
+ const idx = i * 3;
61423
+ decoded[idx + 0] = quantized[idx + 0] / quantizedRange * scale[0] + offset[0];
61424
+ decoded[idx + 1] = quantized[idx + 1] / quantizedRange * scale[1] + offset[1];
61425
+ decoded[idx + 2] = quantized[idx + 2] / quantizedRange * scale[2] + offset[2];
61426
+ }
61427
+ return decoded;
61428
+ }
61429
+ parseColors(featureTable, pointsLength) {
61430
+ let colors = featureTable.getData(
61431
+ "RGBA",
61432
+ pointsLength,
61433
+ "UNSIGNED_BYTE",
61434
+ "VEC4"
61435
+ );
61436
+ if (colors) {
61437
+ return colors;
61438
+ }
61439
+ const rgb = featureTable.getData(
61440
+ "RGB",
61441
+ pointsLength,
61442
+ "UNSIGNED_BYTE",
61443
+ "VEC3"
61444
+ );
61445
+ if (rgb) {
61446
+ const rgba2 = new Uint8Array(pointsLength * 4);
61447
+ for (let i = 0; i < pointsLength; i++) {
61448
+ const rgbIdx = i * 3;
61449
+ const rgbaIdx = i * 4;
61450
+ rgba2[rgbaIdx + 0] = rgb[rgbIdx + 0];
61451
+ rgba2[rgbaIdx + 1] = rgb[rgbIdx + 1];
61452
+ rgba2[rgbaIdx + 2] = rgb[rgbIdx + 2];
61453
+ rgba2[rgbaIdx + 3] = 255;
61454
+ }
61455
+ return rgba2;
61456
+ }
61457
+ const rgb565 = featureTable.getData(
61458
+ "RGB565",
61459
+ pointsLength,
61460
+ "UNSIGNED_SHORT",
61461
+ "SCALAR"
61462
+ );
61463
+ if (rgb565) {
61464
+ const rgba2 = new Uint8Array(pointsLength * 4);
61465
+ for (let i = 0; i < pointsLength; i++) {
61466
+ const decoded = this.decodeRGB565(rgb565[i]);
61467
+ const idx = i * 4;
61468
+ rgba2[idx + 0] = decoded[0];
61469
+ rgba2[idx + 1] = decoded[1];
61470
+ rgba2[idx + 2] = decoded[2];
61471
+ rgba2[idx + 3] = 255;
61472
+ }
61473
+ return rgba2;
61474
+ }
61475
+ const constantRGBA = featureTable.getData(
61476
+ "CONSTANT_RGBA",
61477
+ 1,
61478
+ "UNSIGNED_BYTE",
61479
+ "VEC4"
61480
+ );
61481
+ if (constantRGBA) {
61482
+ const rgba2 = new Uint8Array(pointsLength * 4);
61483
+ for (let i = 0; i < pointsLength; i++) {
61484
+ const idx = i * 4;
61485
+ rgba2[idx + 0] = constantRGBA[0];
61486
+ rgba2[idx + 1] = constantRGBA[1];
61487
+ rgba2[idx + 2] = constantRGBA[2];
61488
+ rgba2[idx + 3] = constantRGBA[3];
61489
+ }
61490
+ return rgba2;
61491
+ }
61492
+ const rgba = new Uint8Array(pointsLength * 4);
61493
+ rgba.fill(255);
61494
+ return rgba;
61495
+ }
61496
+ parseNormals(featureTable, pointsLength) {
61497
+ let normals = featureTable.getData(
61498
+ "NORMAL",
61499
+ pointsLength,
61500
+ "FLOAT",
61501
+ "VEC3"
61502
+ );
61503
+ if (normals) {
61504
+ return normals;
61505
+ }
61506
+ const octNormals = featureTable.getData(
61507
+ "NORMAL_OCT16P",
61508
+ pointsLength,
61509
+ "UNSIGNED_BYTE",
61510
+ "VEC2"
61511
+ );
61512
+ if (octNormals) {
61513
+ return this.decodeOctNormals(octNormals, pointsLength);
61514
+ }
61515
+ return null;
61516
+ }
61517
+ decodeRGB565(value) {
61518
+ const r = (value >> 11 & 31) << 3;
61519
+ const g = (value >> 5 & 63) << 2;
61520
+ const b = (value & 31) << 3;
61521
+ return [r, g, b];
61522
+ }
61523
+ decodeOctNormals(octNormals, pointsLength) {
61524
+ const normals = new Float32Array(pointsLength * 3);
61525
+ for (let i = 0; i < pointsLength; i++) {
61526
+ const idx = i * 2;
61527
+ const x = octNormals[idx] / 255;
61528
+ const y = octNormals[idx + 1] / 255;
61529
+ const nx = x * 2 - 1;
61530
+ const ny = y * 2 - 1;
61531
+ const nz = 1 - Math.abs(nx) - Math.abs(ny);
61532
+ let tx, ty;
61533
+ if (nz < 0) {
61534
+ tx = (nx >= 0 ? 1 : -1) * (1 - Math.abs(ny));
61535
+ ty = (ny >= 0 ? 1 : -1) * (1 - Math.abs(nx));
61536
+ } else {
61537
+ tx = nx;
61538
+ ty = ny;
61539
+ }
61540
+ const length = Math.sqrt(tx * tx + ty * ty + nz * nz);
61541
+ const nidx = i * 3;
61542
+ normals[nidx + 0] = tx / length;
61543
+ normals[nidx + 1] = ty / length;
61544
+ normals[nidx + 2] = nz / length;
61545
+ }
61546
+ return normals;
61547
+ }
61548
+ async parseDraco(featureTable, dracoExtension, pointsLength) {
61549
+ throw new Error("Draco compression not yet implemented");
61550
+ }
61551
+ }
61552
+
61553
+ class PNTSParser extends ParserBase {
61554
+ static format = ParserFormat.BIN;
61555
+ async parseBuffer(buffer) {
61556
+ const loader = new PNTSLoader();
61557
+ const pntsRoot = await loader.parse(buffer);
61558
+ const pntsObj = new exports.Object3D();
61559
+ pntsObj.name = "PNTS";
61560
+ pntsObj.addChild(pntsRoot);
61561
+ this.data = pntsObj;
61562
+ }
61563
+ verification() {
61564
+ if (this.data) {
61565
+ return true;
61566
+ }
61567
+ throw new Error("PNTSParser: Parse failed");
61568
+ }
61569
+ }
61570
+
61298
61571
  class PrefabBoneData {
61299
61572
  boneName;
61300
61573
  bonePath;
@@ -64401,9 +64674,9 @@ fn frag(){
64401
64674
  const extension = getUrlExtension(uri);
64402
64675
  const fullUrl = url;
64403
64676
  let scene = null;
64677
+ const loader = new FileLoader();
64404
64678
  switch (extension.toLowerCase()) {
64405
- case "b3dm":
64406
- const loader = new FileLoader();
64679
+ case "b3dm": {
64407
64680
  const parser = await loader.load(fullUrl, B3DMParser, {
64408
64681
  onProgress: (e) => {
64409
64682
  },
@@ -64412,29 +64685,38 @@ fn frag(){
64412
64685
  });
64413
64686
  scene = parser.data;
64414
64687
  break;
64415
- case "i3dm":
64416
- scene = await Engine3D.res.loadI3DM(
64417
- fullUrl,
64418
- {
64419
- onProgress: (e) => {
64420
- },
64421
- onComplete: (e) => {
64422
- }
64688
+ }
64689
+ case "i3dm": {
64690
+ const parser = await loader.load(fullUrl, I3DMParser, {
64691
+ onProgress: (e) => {
64692
+ },
64693
+ onComplete: (e) => {
64423
64694
  }
64424
- );
64695
+ });
64696
+ scene = parser.data;
64425
64697
  break;
64698
+ }
64426
64699
  case "glb":
64427
- case "gltf":
64428
- scene = await Engine3D.res.loadGltf(fullUrl, {
64700
+ case "gltf": {
64701
+ const parser = await loader.load(fullUrl, GLTFParser, {
64429
64702
  onProgress: (e) => {
64430
64703
  },
64431
64704
  onComplete: (e) => {
64432
64705
  }
64433
64706
  });
64707
+ scene = parser.data;
64434
64708
  break;
64435
- case "pnts":
64436
- console.warn("PNTS format not yet supported");
64709
+ }
64710
+ case "pnts": {
64711
+ const parser = await loader.load(fullUrl, PNTSParser, {
64712
+ onProgress: (e) => {
64713
+ },
64714
+ onComplete: (e) => {
64715
+ }
64716
+ });
64717
+ scene = parser.data;
64437
64718
  break;
64719
+ }
64438
64720
  case "json":
64439
64721
  {
64440
64722
  try {
@@ -71197,6 +71479,9 @@ fn frag(){
71197
71479
  exports.PBRLItShader = PBRLItShader;
71198
71480
  exports.PBRLitSSSShader = PBRLitSSSShader;
71199
71481
  exports.PLUGIN_REGISTERED = PLUGIN_REGISTERED;
71482
+ exports.PNTSLoader = PNTSLoader;
71483
+ exports.PNTSLoaderBase = PNTSLoaderBase;
71484
+ exports.PNTSParser = PNTSParser;
71200
71485
  exports.ParserBase = ParserBase;
71201
71486
  exports.ParserFormat = ParserFormat;
71202
71487
  exports.ParticleSystemCurveEvalMode = ParticleSystemCurveEvalMode;
@@ -432,6 +432,9 @@ export * from "./loader/parser/ply/PlyLoader";
432
432
  export * from "./loader/parser/ply/PlyParser";
433
433
  export * from "./loader/parser/ply/PlyTypes";
434
434
  export * from "./loader/parser/ply/PlyUtils";
435
+ export * from "./loader/parser/pnts/PNTSLoader";
436
+ export * from "./loader/parser/pnts/PNTSLoaderBase";
437
+ export * from "./loader/parser/pnts/PNTSParser";
435
438
  export * from "./loader/parser/prefab/PrefabAvatarParser";
436
439
  export * from "./loader/parser/prefab/PrefabMaterialParser";
437
440
  export * from "./loader/parser/prefab/PrefabMeshParser";
@@ -2,7 +2,8 @@ export declare class FeatureTable {
2
2
  private buffer;
3
3
  private binOffset;
4
4
  private binLength;
5
- private header;
5
+ private _header;
6
+ get header(): any;
6
7
  constructor(buffer: any, start: any, headerLength: any, binLength: any);
7
8
  getKeys(): string[];
8
9
  getData(key: any, count?: any, defaultComponentType?: any, defaultType?: any): any;
@@ -0,0 +1,10 @@
1
+ import { PNTSLoaderBase } from "./PNTSLoaderBase";
2
+ export declare class PNTSLoader extends PNTSLoaderBase {
3
+ parse(buffer: ArrayBuffer): Promise<any>;
4
+ private parsePositions;
5
+ private parseColors;
6
+ private parseNormals;
7
+ private decodeRGB565;
8
+ private decodeOctNormals;
9
+ private parseDraco;
10
+ }
@@ -0,0 +1,8 @@
1
+ import { FeatureTable, BatchTable } from "../b3dm/FeatureTable";
2
+ export declare class PNTSLoaderBase {
3
+ parse(buffer: ArrayBuffer): Promise<{
4
+ version: number;
5
+ featureTable: FeatureTable;
6
+ batchTable: BatchTable;
7
+ }>;
8
+ }
@@ -0,0 +1,7 @@
1
+ import { ParserBase } from "../ParserBase";
2
+ import { ParserFormat } from "../ParserFormat";
3
+ export declare class PNTSParser extends ParserBase {
4
+ static format: ParserFormat;
5
+ parseBuffer(buffer: ArrayBuffer): Promise<void>;
6
+ verification(): boolean;
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rings-webgpu/core",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "description": "Rings webgpu Engine",
5
5
  "main": "index.js",
6
6
  "exports": {