@rings-webgpu/core 1.0.27 → 1.0.29

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.
@@ -2120,7 +2120,7 @@
2120
2120
  }
2121
2121
 
2122
2122
  var __defProp$2 = Object.defineProperty;
2123
- var __decorateClass$m = (decorators, target, key, kind) => {
2123
+ var __decorateClass$o = (decorators, target, key, kind) => {
2124
2124
  var result = void 0 ;
2125
2125
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
2126
2126
  if (decorator = decorators[i])
@@ -2223,10 +2223,10 @@
2223
2223
  return struct.__size;
2224
2224
  }
2225
2225
  };
2226
- __decorateClass$m([
2226
+ __decorateClass$o([
2227
2227
  NonSerialize
2228
2228
  ], _Struct.prototype, "__refection");
2229
- __decorateClass$m([
2229
+ __decorateClass$o([
2230
2230
  NonSerialize
2231
2231
  ], _Struct.prototype, "__size");
2232
2232
  let Struct = _Struct;
@@ -20496,6 +20496,10 @@ struct InstanceData {
20496
20496
  this.vsEntryPoint = vsEntryPoint;
20497
20497
  this.fsEntryPoint = fsEntryPoint;
20498
20498
  }
20499
+ setUniformArray(name, value) {
20500
+ super.setUniformArray(name, value);
20501
+ this.materialDataUniformBuffer.onChange();
20502
+ }
20499
20503
  setUniform(name, value) {
20500
20504
  super.setUniform(name, value);
20501
20505
  this.materialDataUniformBuffer.onChange();
@@ -20764,16 +20768,21 @@ struct InstanceData {
20764
20768
  if (buffer) {
20765
20769
  if (buffer.bufferType == GPUBufferType.MaterialDataUniformGPUBuffer) {
20766
20770
  let uniforms = [];
20767
- for (let i = 0; i < refs.dataFields.length; i++) {
20768
- const field = refs.dataFields[i];
20769
- if (!this.uniforms[field.name]) {
20770
- console.error(
20771
- `shader-${this.vsName}:${this.fsName} ${field.name}is empty`
20772
- );
20771
+ if (refs.dataFields) {
20772
+ for (let i = 0; i < refs.dataFields.length; i++) {
20773
+ const field = refs.dataFields[i];
20774
+ if (!this.uniforms[field.name]) {
20775
+ console.error(
20776
+ `shader-${this.vsName}:${this.fsName} ${field.name}is empty`
20777
+ );
20778
+ } else {
20779
+ uniforms.push(this.uniforms[field.name]);
20780
+ }
20773
20781
  }
20774
- uniforms.push(this.uniforms[field.name]);
20775
20782
  }
20776
- this.materialDataUniformBuffer.initDataUniform(uniforms);
20783
+ if (uniforms.length > 0) {
20784
+ this.materialDataUniformBuffer.initDataUniform(uniforms);
20785
+ }
20777
20786
  }
20778
20787
  let entry = {
20779
20788
  binding: refs.binding,
@@ -21963,9 +21972,9 @@ struct InstanceData {
21963
21972
  }
21964
21973
 
21965
21974
  var __defProp$1 = Object.defineProperty;
21966
- var __getOwnPropDesc$l = Object.getOwnPropertyDescriptor;
21967
- var __decorateClass$l = (decorators, target, key, kind) => {
21968
- var result = __getOwnPropDesc$l(target, key) ;
21975
+ var __getOwnPropDesc$n = Object.getOwnPropertyDescriptor;
21976
+ var __decorateClass$n = (decorators, target, key, kind) => {
21977
+ var result = __getOwnPropDesc$n(target, key) ;
21969
21978
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
21970
21979
  if (decorator = decorators[i])
21971
21980
  result = (decorator(target, key, result) ) || result;
@@ -22563,13 +22572,13 @@ struct InstanceData {
22563
22572
  this._combineShaderRefection = void 0;
22564
22573
  }
22565
22574
  }
22566
- __decorateClass$l([
22575
+ __decorateClass$n([
22567
22576
  EditorInspector
22568
22577
  ], RenderNode.prototype, "materials");
22569
- __decorateClass$l([
22578
+ __decorateClass$n([
22570
22579
  EditorInspector
22571
22580
  ], RenderNode.prototype, "castShadow");
22572
- __decorateClass$l([
22581
+ __decorateClass$n([
22573
22582
  EditorInspector
22574
22583
  ], RenderNode.prototype, "castGI");
22575
22584
 
@@ -22790,7 +22799,7 @@ struct InstanceData {
22790
22799
  @location(1) vTexCoord: vec2<f32>,
22791
22800
  };
22792
22801
 
22793
- // Textures (like PlayCanvas)
22802
+ // Textures
22794
22803
  @group(1) @binding(1) var splatColor: texture_2d<f32>;
22795
22804
  @group(1) @binding(2) var transformA: texture_2d<u32>;
22796
22805
  @group(1) @binding(3) var transformB: texture_2d<f32>;
@@ -22887,7 +22896,7 @@ struct InstanceData {
22887
22896
  return vec4f(v1.x, -v1.y, v2.x, -v2.y);
22888
22897
  }
22889
22898
 
22890
- // ===== SPLAT MAIN VS (from PlayCanvas gsplat-material.js) =====
22899
+ // ===== SPLAT MAIN VS =====
22891
22900
 
22892
22901
  @vertex
22893
22902
  fn VertMain(
@@ -23236,9 +23245,9 @@ struct InstanceData {
23236
23245
  }
23237
23246
  }
23238
23247
 
23239
- var __getOwnPropDesc$k = Object.getOwnPropertyDescriptor;
23240
- var __decorateClass$k = (decorators, target, key, kind) => {
23241
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$k(target, key) : target;
23248
+ var __getOwnPropDesc$m = Object.getOwnPropertyDescriptor;
23249
+ var __decorateClass$m = (decorators, target, key, kind) => {
23250
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$m(target, key) : target;
23242
23251
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
23243
23252
  if (decorator = decorators[i])
23244
23253
  result = (decorator(result)) || result;
@@ -23270,7 +23279,7 @@ struct InstanceData {
23270
23279
  pass.setUniform("pixelCull", new Float32Array([2, 0, 0, 0]));
23271
23280
  }
23272
23281
  };
23273
- exports.GSplatShader = __decorateClass$k([
23282
+ exports.GSplatShader = __decorateClass$m([
23274
23283
  RegisterShader(exports.GSplatShader, "GSplatShader")
23275
23284
  ], exports.GSplatShader);
23276
23285
 
@@ -24053,7 +24062,7 @@ struct InstanceData {
24053
24062
  size: data.byteLength,
24054
24063
  usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC
24055
24064
  });
24056
- device.queue.writeBuffer(textureDataBuffer, 0, data);
24065
+ device.queue.writeBuffer(textureDataBuffer, 0, data.buffer);
24057
24066
  const commandEncoder = GPUContext.beginCommandEncoder();
24058
24067
  commandEncoder.copyBufferToTexture(
24059
24068
  {
@@ -24085,7 +24094,7 @@ struct InstanceData {
24085
24094
  size: data.byteLength,
24086
24095
  usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC
24087
24096
  });
24088
- device.queue.writeBuffer(textureDataBuffer, 0, data);
24097
+ device.queue.writeBuffer(textureDataBuffer, 0, data.buffer);
24089
24098
  const commandEncoder = GPUContext.beginCommandEncoder();
24090
24099
  commandEncoder.copyBufferToTexture(
24091
24100
  {
@@ -24287,9 +24296,9 @@ struct InstanceData {
24287
24296
  }
24288
24297
  }
24289
24298
 
24290
- var __getOwnPropDesc$j = Object.getOwnPropertyDescriptor;
24291
- var __decorateClass$j = (decorators, target, key, kind) => {
24292
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$j(target, key) : target;
24299
+ var __getOwnPropDesc$l = Object.getOwnPropertyDescriptor;
24300
+ var __decorateClass$l = (decorators, target, key, kind) => {
24301
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$l(target, key) : target;
24293
24302
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
24294
24303
  if (decorator = decorators[i])
24295
24304
  result = (decorator(result)) || result;
@@ -25088,10 +25097,689 @@ struct InstanceData {
25088
25097
  super.destroy(force);
25089
25098
  }
25090
25099
  };
25091
- exports.GSplatRenderer = __decorateClass$j([
25100
+ exports.GSplatRenderer = __decorateClass$l([
25092
25101
  RegisterComponent(exports.GSplatRenderer, "GSplatRenderer")
25093
25102
  ], exports.GSplatRenderer);
25094
25103
 
25104
+ const PointCloud_VS = (
25105
+ /* wgsl */
25106
+ `
25107
+ #include "GlobalUniform"
25108
+
25109
+ const ALPHA_THRESHOLD: f32 = 0.00392156863;
25110
+
25111
+ struct MaterialUniform {
25112
+ modelMatrix: mat4x4<f32>,
25113
+ tex_params: vec4<f32>,
25114
+ pointParams: vec4<f32>,
25115
+ };
25116
+ @group(1) @binding(0) var<uniform> materialUniform: MaterialUniform;
25117
+
25118
+ struct VSOut {
25119
+ @builtin(position) member: vec4<f32>,
25120
+ @location(0) vColor: vec4<f32>,
25121
+ @location(1) vTexCoord: vec2<f32>,
25122
+ };
25123
+
25124
+ @group(1) @binding(1) var pointColor: texture_2d<f32>;
25125
+ @group(1) @binding(2) var pointPosition: texture_2d<f32>;
25126
+ @group(1) @binding(3) var pointOrder: texture_2d<u32>;
25127
+
25128
+ fn discardPoint() -> VSOut {
25129
+ var o: VSOut;
25130
+ o.member = vec4f(0.0, 0.0, 2.0, 1.0);
25131
+ o.vColor = vec4f(0.0);
25132
+ o.vTexCoord = vec2f(0.0);
25133
+ return o;
25134
+ }
25135
+
25136
+ fn calcPointUV(orderId: u32, textureWidth: u32, numPoints: u32) -> vec2<i32> {
25137
+ let pointId = orderId;
25138
+ return vec2<i32>(
25139
+ i32(pointId % textureWidth),
25140
+ i32(pointId / textureWidth)
25141
+ );
25142
+ }
25143
+
25144
+ @vertex
25145
+ fn VertMain(
25146
+ @builtin(vertex_index) vid: u32,
25147
+ @builtin(instance_index) iid: u32,
25148
+ @location(0) position: vec3<f32>
25149
+ ) -> VSOut {
25150
+ let batchSize = max(1u, u32(materialUniform.pointParams.w));
25151
+ let orderId = iid * batchSize + u32(position.z);
25152
+
25153
+ let textureWidth = max(1u, u32(materialUniform.tex_params.y));
25154
+ let numPoints = max(1u, u32(materialUniform.tex_params.x));
25155
+ let safeOrderId = min(orderId, numPoints - 1u);
25156
+
25157
+ let pointUV = calcPointUV(safeOrderId, textureWidth, numPoints);
25158
+ let color = textureLoad(pointColor, pointUV, 0);
25159
+
25160
+ let posData = textureLoad(pointPosition, pointUV, 0);
25161
+ let pointPos = vec3f(
25162
+ posData.x,
25163
+ posData.y,
25164
+ posData.z
25165
+ );
25166
+
25167
+ let matrix_model = materialUniform.modelMatrix;
25168
+ let matrix_view = globalUniform.viewMat;
25169
+ let matrix_projection = globalUniform.projMat;
25170
+ let model_view = matrix_view * matrix_model;
25171
+
25172
+ let centerClip = matrix_projection * (model_view * vec4f(pointPos, 1.0));
25173
+
25174
+ let inv_w = 1.0 / centerClip.w;
25175
+ let ndc = centerClip.xyz * inv_w;
25176
+ if (ndc.x < -1.0 || ndc.x > 1.0 ||
25177
+ ndc.y < -1.0 || ndc.y > 1.0 ||
25178
+ ndc.z < 0.0 || ndc.z > 1.0) {
25179
+ return discardPoint();
25180
+ }
25181
+
25182
+ let viewPos = model_view * vec4f(pointPos, 1.0);
25183
+ if (viewPos.z <= 0.0) {
25184
+ return discardPoint();
25185
+ }
25186
+
25187
+ let pointSize = materialUniform.tex_params.w;
25188
+ let viewport = vec2f(globalUniform.windowWidth, globalUniform.windowHeight);
25189
+ let safeViewport = max(viewport, vec2f(1.0, 1.0));
25190
+ let inv_viewport = 2.0 / safeViewport;
25191
+ let offsetNDC = position.xy * pointSize * 0.5 * inv_viewport;
25192
+ let offsetClip = vec4f(offsetNDC * centerClip.w, 0.0, 0.0);
25193
+
25194
+ var o: VSOut;
25195
+ o.member = centerClip + offsetClip;
25196
+ o.vColor = color;
25197
+ o.vTexCoord = position.xy;
25198
+ return o;
25199
+ }
25200
+ `
25201
+ );
25202
+ const PointCloud_FS = (
25203
+ /* wgsl */
25204
+ `
25205
+ #include "FragmentOutput"
25206
+
25207
+ const ALPHA_THRESHOLD: f32 = 0.00392156863;
25208
+
25209
+ struct MaterialUniform {
25210
+ modelMatrix: mat4x4<f32>,
25211
+ tex_params: vec4<f32>,
25212
+ pointParams: vec4<f32>,
25213
+ };
25214
+ @group(1) @binding(0) var<uniform> materialUniform: MaterialUniform;
25215
+
25216
+ @fragment
25217
+ fn FragMain(
25218
+ @location(0) vColor: vec4<f32>,
25219
+ @location(1) vTexCoord: vec2<f32>
25220
+ ) -> FragmentOutput {
25221
+ var o: FragmentOutput;
25222
+
25223
+ let pointShape = materialUniform.pointParams.x;
25224
+ let distSq = dot(vTexCoord, vTexCoord);
25225
+ let isCircle = pointShape > 0.5;
25226
+ let discardPixel = isCircle && distSq > 1.0;
25227
+
25228
+ if (discardPixel) {
25229
+ discard;
25230
+ }
25231
+
25232
+ o.color = vColor;
25233
+ o.gBuffer = vec4f(0.0);
25234
+ return o;
25235
+ }
25236
+ `
25237
+ );
25238
+
25239
+ var __getOwnPropDesc$k = Object.getOwnPropertyDescriptor;
25240
+ var __decorateClass$k = (decorators, target, key, kind) => {
25241
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$k(target, key) : target;
25242
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
25243
+ if (decorator = decorators[i])
25244
+ result = (decorator(result)) || result;
25245
+ return result;
25246
+ };
25247
+ exports.PointCloudShader = class PointCloudShader extends Shader {
25248
+ constructor() {
25249
+ super();
25250
+ ShaderLib.register("pointcloud_vs_dc", PointCloud_VS);
25251
+ ShaderLib.register("pointcloud_fs_dc", PointCloud_FS);
25252
+ const pass = new RenderShaderPass("pointcloud_vs_dc", "pointcloud_fs_dc");
25253
+ pass.passType = PassType.COLOR;
25254
+ pass.setShaderEntry("VertMain", "FragMain");
25255
+ pass.topology = GPUPrimitiveTopology.triangle_list;
25256
+ pass.depthWriteEnabled = true;
25257
+ pass.cullMode = GPUCullMode.none;
25258
+ pass.shaderState.transparent = false;
25259
+ pass.shaderState.blendMode = BlendMode.NORMAL;
25260
+ pass.shaderState.writeMasks = [15, 15];
25261
+ pass.shaderState.castReflection = false;
25262
+ this.addRenderPass(pass);
25263
+ this.setDefault();
25264
+ }
25265
+ setDefault() {
25266
+ const pass = this.getDefaultColorShader();
25267
+ const identityMatrix = new Matrix4();
25268
+ pass.setUniform("modelMatrix", identityMatrix.rawData);
25269
+ pass.setUniformArray("tex_params", new Float32Array([0, 0, 0, 4]));
25270
+ pass.setUniformArray("pointParams", new Float32Array([0, 0, 0, 128]));
25271
+ }
25272
+ };
25273
+ exports.PointCloudShader = __decorateClass$k([
25274
+ RegisterShader(exports.PointCloudShader, "PointCloudShader")
25275
+ ], exports.PointCloudShader);
25276
+
25277
+ class PointCloudMaterial extends Material {
25278
+ _texParams = new Float32Array([0, 0, 0, 4]);
25279
+ _pointParamsArray = new Float32Array([0, 0, 0, 128]);
25280
+ constructor() {
25281
+ super();
25282
+ this.shader = new exports.PointCloudShader();
25283
+ }
25284
+ /**
25285
+ * Set point cloud textures
25286
+ * @param pointPosition Position texture (RGB = xyz)
25287
+ * @param pointColor Color texture (RGBA)
25288
+ * @param texParams Texture parameters [numPoints, texWidth, validCount, pointSize]
25289
+ * @param pointOrder Optional sorting texture (R32U format)
25290
+ */
25291
+ setPointTextures(pointPosition, pointColor, texParams, pointOrder) {
25292
+ const pass = this.shader.getDefaultColorShader();
25293
+ if (!pass.getUniform("modelMatrix")) {
25294
+ const identityMatrix = new Matrix4();
25295
+ pass.setUniform("modelMatrix", identityMatrix.rawData);
25296
+ }
25297
+ pass.setTexture("pointColor", pointColor);
25298
+ pass.setTexture("pointPosition", pointPosition);
25299
+ this._texParams[0] = texParams[0];
25300
+ this._texParams[1] = texParams[1];
25301
+ this._texParams[2] = texParams[2];
25302
+ this._texParams[3] = texParams[3];
25303
+ pass.setUniformArray("tex_params", this._texParams);
25304
+ pass.setUniformArray("pointParams", this._pointParamsArray);
25305
+ if (pointOrder) {
25306
+ pass.setTexture("pointOrder", pointOrder);
25307
+ }
25308
+ pass.shaderState.depthCompare = GPUCompareFunction.less;
25309
+ }
25310
+ /**
25311
+ * Set the model matrix for transforming points to world space
25312
+ * @param matrix Model transformation matrix
25313
+ */
25314
+ setTransformMatrix(matrix) {
25315
+ const pass = this.shader.getDefaultColorShader();
25316
+ pass.setUniform("modelMatrix", matrix.rawData);
25317
+ }
25318
+ /**
25319
+ * Set point size in pixels
25320
+ * @param size Point size in pixels (default: 4.0)
25321
+ */
25322
+ setPointSize(size) {
25323
+ this._texParams[3] = Math.max(0.1, size);
25324
+ const pass = this.shader.getDefaultColorShader();
25325
+ pass.setUniformArray("tex_params", this._texParams);
25326
+ }
25327
+ /**
25328
+ * Set point shape
25329
+ * @param shape Point shape: 'square' or 'circle'
25330
+ */
25331
+ setPointShape(shape) {
25332
+ this._pointParamsArray[0] = shape === "circle" ? 1 : 0;
25333
+ const pass = this.shader.getDefaultColorShader();
25334
+ pass.setUniformArray("pointParams", this._pointParamsArray);
25335
+ }
25336
+ enableDebugFullScreen(enabled) {
25337
+ this._pointParamsArray[1] = enabled ? 1 : 0;
25338
+ const pass = this.shader.getDefaultColorShader();
25339
+ pass.setUniformArray("pointParams", this._pointParamsArray);
25340
+ }
25341
+ /**
25342
+ * Set batch size for instanced rendering
25343
+ * @param batchSize Number of points per draw call (default: 128)
25344
+ */
25345
+ setBatchSize(batchSize) {
25346
+ this._pointParamsArray[3] = Math.max(1, batchSize | 0);
25347
+ const pass = this.shader.getDefaultColorShader();
25348
+ pass.setUniformArray("pointParams", this._pointParamsArray);
25349
+ }
25350
+ }
25351
+
25352
+ class PointCloudGeometry extends GeometryBase {
25353
+ batchSize;
25354
+ constructor(batchSize = 128) {
25355
+ super();
25356
+ this.batchSize = batchSize;
25357
+ const meshPositions = new Float32Array(12 * batchSize);
25358
+ for (let i = 0; i < batchSize; ++i) {
25359
+ const baseIdx = i * 12;
25360
+ meshPositions.set([
25361
+ -1,
25362
+ -1,
25363
+ i,
25364
+ 1,
25365
+ -1,
25366
+ i,
25367
+ 1,
25368
+ 1,
25369
+ i,
25370
+ -1,
25371
+ 1,
25372
+ i
25373
+ ], baseIdx);
25374
+ }
25375
+ const meshIndices = new Uint32Array(6 * batchSize);
25376
+ for (let i = 0; i < batchSize; ++i) {
25377
+ const baseVertex = i * 4;
25378
+ const baseIdx = i * 6;
25379
+ meshIndices.set([
25380
+ 0 + baseVertex,
25381
+ 1 + baseVertex,
25382
+ 2 + baseVertex,
25383
+ 0 + baseVertex,
25384
+ 2 + baseVertex,
25385
+ 3 + baseVertex
25386
+ ], baseIdx);
25387
+ }
25388
+ this.setAttribute(VertexAttributeName.position, meshPositions);
25389
+ this.setIndices(meshIndices);
25390
+ this.addSubGeometry({
25391
+ indexStart: 0,
25392
+ indexCount: meshIndices.length,
25393
+ vertexStart: 0,
25394
+ vertexCount: meshPositions.length / 3,
25395
+ firstStart: 0,
25396
+ index: 0,
25397
+ topology: 0
25398
+ });
25399
+ }
25400
+ }
25401
+
25402
+ class Float32ArrayTexture extends Texture {
25403
+ create(width, height, data, filtering = true) {
25404
+ let device = webGPUContext.device;
25405
+ const bytesPerRow = width * 4 * 4;
25406
+ this.format = GPUTextureFormat.rgba32float;
25407
+ let mipmapCount = 1;
25408
+ this.createTextureDescriptor(width, height, mipmapCount, this.format);
25409
+ const textureDataBuffer = device.createBuffer({
25410
+ size: data.byteLength,
25411
+ usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC
25412
+ });
25413
+ device.queue.writeBuffer(textureDataBuffer, 0, data.buffer);
25414
+ const commandEncoder = GPUContext.beginCommandEncoder();
25415
+ commandEncoder.copyBufferToTexture(
25416
+ {
25417
+ buffer: textureDataBuffer,
25418
+ bytesPerRow
25419
+ },
25420
+ {
25421
+ texture: this.getGPUTexture()
25422
+ },
25423
+ {
25424
+ width,
25425
+ height,
25426
+ depthOrArrayLayers: 1
25427
+ }
25428
+ );
25429
+ GPUContext.endCommandEncoder(commandEncoder);
25430
+ if (filtering) {
25431
+ this.samplerBindingLayout.type = `non-filtering`;
25432
+ this.textureBindingLayout.sampleType = `unfilterable-float`;
25433
+ }
25434
+ this.gpuSampler = device.createSampler({});
25435
+ return this;
25436
+ }
25437
+ fromBuffer(width, height, textureDataBuffer) {
25438
+ let device = webGPUContext.device;
25439
+ const bytesPerRow = width * 4 * 4;
25440
+ this.format = GPUTextureFormat.rgba32float;
25441
+ this.mipmapCount = 1;
25442
+ this.createTextureDescriptor(width, height, this.mipmapCount, this.format);
25443
+ const commandEncoder = GPUContext.beginCommandEncoder();
25444
+ commandEncoder.copyBufferToTexture(
25445
+ {
25446
+ buffer: textureDataBuffer,
25447
+ bytesPerRow
25448
+ },
25449
+ {
25450
+ texture: this.getGPUTexture()
25451
+ },
25452
+ {
25453
+ width,
25454
+ height,
25455
+ depthOrArrayLayers: 1
25456
+ }
25457
+ );
25458
+ GPUContext.endCommandEncoder(commandEncoder);
25459
+ this.samplerBindingLayout.type = `non-filtering`;
25460
+ this.textureBindingLayout.sampleType = `unfilterable-float`;
25461
+ this.gpuSampler = device.createSampler({});
25462
+ return this;
25463
+ }
25464
+ }
25465
+
25466
+ var __getOwnPropDesc$j = Object.getOwnPropertyDescriptor;
25467
+ var __decorateClass$j = (decorators, target, key, kind) => {
25468
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$j(target, key) : target;
25469
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
25470
+ if (decorator = decorators[i])
25471
+ result = (decorator(result)) || result;
25472
+ return result;
25473
+ };
25474
+ exports.PointCloudRenderer = class PointCloudRenderer extends RenderNode {
25475
+ count = 0;
25476
+ size = new Vector2();
25477
+ pointColor;
25478
+ pointPosition;
25479
+ pointOrder;
25480
+ texParams;
25481
+ // [numPoints, texWidth, validCount, pointSize]
25482
+ pointCloudMaterial;
25483
+ _positions;
25484
+ get positions() {
25485
+ return this._positions;
25486
+ }
25487
+ _colors;
25488
+ _orderData;
25489
+ _fullCount = 0;
25490
+ get fullCount() {
25491
+ return this._fullCount;
25492
+ }
25493
+ _batchSize = 128;
25494
+ instanceCount = 0;
25495
+ _texturesInitialized = false;
25496
+ _debugFullScreen = false;
25497
+ _centerOffset = new Vector3();
25498
+ get centerOffset() {
25499
+ return this._centerOffset;
25500
+ }
25501
+ constructor() {
25502
+ super();
25503
+ }
25504
+ /**
25505
+ * Initialize point cloud from raw data
25506
+ * @param positions Point positions (xyz per point, Float32Array)
25507
+ * @param colors Point colors (rgba per point, Uint8Array)
25508
+ * @param count Number of points
25509
+ */
25510
+ initFromData(positions, colors, count) {
25511
+ if (!positions || !colors || count <= 0) {
25512
+ console.error("PointCloudRenderer: Invalid input data");
25513
+ return;
25514
+ }
25515
+ if (positions.length < count * 3) {
25516
+ console.error("PointCloudRenderer: Positions array too small");
25517
+ return;
25518
+ }
25519
+ if (colors.length < count * 4) {
25520
+ console.error("PointCloudRenderer: Colors array too small");
25521
+ return;
25522
+ }
25523
+ this.count = count;
25524
+ this._fullCount = count;
25525
+ this.size = this.evalTextureSize(count);
25526
+ this._positions = positions;
25527
+ this._colors = colors;
25528
+ this.centerizePositions();
25529
+ this.buildPositionTexture();
25530
+ this.buildColorTexture();
25531
+ this.texParams = new Float32Array([
25532
+ this.count,
25533
+ this.size.x,
25534
+ this.count,
25535
+ 4
25536
+ ]);
25537
+ this.buildOrderTexture();
25538
+ this.pointCloudMaterial = new PointCloudMaterial();
25539
+ this.geometry = new PointCloudGeometry(this._batchSize);
25540
+ this.materials = [this.pointCloudMaterial];
25541
+ this.instanceCount = Math.ceil(this.count / this._batchSize);
25542
+ }
25543
+ /**
25544
+ * Calculate texture size for given point count
25545
+ * @param count Number of points
25546
+ * @returns Texture dimensions (width, height)
25547
+ */
25548
+ evalTextureSize(count) {
25549
+ let w = Math.ceil(Math.sqrt(count));
25550
+ const align = 64;
25551
+ w = Math.ceil(w / align) * align;
25552
+ const h = Math.ceil(count / w);
25553
+ return new Vector2(w, h);
25554
+ }
25555
+ /**
25556
+ * Centerize positions to improve precision for large values
25557
+ * Subtracts the center point from all positions to keep values near zero
25558
+ */
25559
+ centerizePositions() {
25560
+ if (this.count === 0) return;
25561
+ let sumX = 0, sumY = 0, sumZ = 0;
25562
+ for (let i = 0; i < this.count; i++) {
25563
+ const idx = i * 3;
25564
+ sumX += this._positions[idx + 0];
25565
+ sumY += this._positions[idx + 1];
25566
+ sumZ += this._positions[idx + 2];
25567
+ }
25568
+ const centerX = sumX / this.count;
25569
+ const centerY = sumY / this.count;
25570
+ const centerZ = sumZ / this.count;
25571
+ this._centerOffset.set(centerX, centerY, centerZ);
25572
+ for (let i = 0; i < this.count; i++) {
25573
+ const idx = i * 3;
25574
+ this._positions[idx + 0] -= centerX;
25575
+ this._positions[idx + 1] -= centerY;
25576
+ this._positions[idx + 2] -= centerZ;
25577
+ }
25578
+ this.object3D.localPosition = this._centerOffset;
25579
+ }
25580
+ buildPositionTexture() {
25581
+ const w = this.size.x | 0;
25582
+ const h = this.size.y | 0;
25583
+ const count = this.count;
25584
+ const data = new Float32Array(w * h * 4);
25585
+ for (let i = 0; i < count; i++) {
25586
+ const idx = i * 4;
25587
+ const posIdx = i * 3;
25588
+ data[idx + 0] = this._positions[posIdx + 0];
25589
+ data[idx + 1] = this._positions[posIdx + 1];
25590
+ data[idx + 2] = this._positions[posIdx + 2];
25591
+ data[idx + 3] = 0;
25592
+ }
25593
+ if (count < w * h) {
25594
+ const lastIdx = (count - 1) * 4;
25595
+ for (let i = count; i < w * h; i++) {
25596
+ const idx = i * 4;
25597
+ data[idx + 0] = data[lastIdx + 0];
25598
+ data[idx + 1] = data[lastIdx + 1];
25599
+ data[idx + 2] = data[lastIdx + 2];
25600
+ data[idx + 3] = 0;
25601
+ }
25602
+ }
25603
+ this.pointPosition = new Float32ArrayTexture().create(w, h, data);
25604
+ this.pointPosition.name = "pointPosition";
25605
+ this.pointPosition.minFilter = "nearest";
25606
+ this.pointPosition.magFilter = "nearest";
25607
+ this.pointPosition.addressModeU = "clamp-to-edge";
25608
+ this.pointPosition.addressModeV = "clamp-to-edge";
25609
+ }
25610
+ buildColorTexture() {
25611
+ const w = this.size.x | 0;
25612
+ const h = this.size.y | 0;
25613
+ const count = this.count;
25614
+ const data = new Uint8Array(w * h * 4);
25615
+ for (let i = 0; i < count; i++) {
25616
+ const idx = i * 4;
25617
+ const colorIdx = i * 4;
25618
+ data[idx + 0] = this._colors[colorIdx + 0];
25619
+ data[idx + 1] = this._colors[colorIdx + 1];
25620
+ data[idx + 2] = this._colors[colorIdx + 2];
25621
+ data[idx + 3] = this._colors[colorIdx + 3];
25622
+ }
25623
+ if (count < w * h) {
25624
+ const lastIdx = (count - 1) * 4;
25625
+ for (let i = count; i < w * h; i++) {
25626
+ const idx = i * 4;
25627
+ data[idx + 0] = data[lastIdx + 0];
25628
+ data[idx + 1] = data[lastIdx + 1];
25629
+ data[idx + 2] = data[lastIdx + 2];
25630
+ data[idx + 3] = data[lastIdx + 3];
25631
+ }
25632
+ }
25633
+ this.pointColor = new Uint8ArrayTexture().create(w, h, data, false);
25634
+ this.pointColor.name = "pointColor";
25635
+ this.pointColor.minFilter = "nearest";
25636
+ this.pointColor.magFilter = "nearest";
25637
+ this.pointColor.mipmapFilter = "nearest";
25638
+ this.pointColor.addressModeU = "clamp-to-edge";
25639
+ this.pointColor.addressModeV = "clamp-to-edge";
25640
+ }
25641
+ buildOrderTexture() {
25642
+ const total = this.size.x * this.size.y;
25643
+ this._orderData = new Uint32Array(total);
25644
+ for (let i = 0; i < total; i++) {
25645
+ this._orderData[i] = i < this.count ? i : this.count > 0 ? this.count - 1 : 0;
25646
+ }
25647
+ this.pointOrder = new R32UintTexture().create(this.size.x, this.size.y, this._orderData);
25648
+ this.pointOrder.name = "pointOrder";
25649
+ this.pointOrder.minFilter = "nearest";
25650
+ this.pointOrder.magFilter = "nearest";
25651
+ this.pointOrder.addressModeU = "clamp-to-edge";
25652
+ this.pointOrder.addressModeV = "clamp-to-edge";
25653
+ }
25654
+ /**
25655
+ * Update node before rendering
25656
+ */
25657
+ nodeUpdate(view, passType, renderPassState, clusterLightingBuffer) {
25658
+ const worldMatrix = this.object3D.transform.worldMatrix;
25659
+ this.pointCloudMaterial.setTransformMatrix(worldMatrix);
25660
+ if (!this._texturesInitialized) {
25661
+ this.pointCloudMaterial.setPointTextures(
25662
+ this.pointPosition,
25663
+ this.pointColor,
25664
+ this.texParams,
25665
+ this.pointOrder
25666
+ );
25667
+ this.pointCloudMaterial.setBatchSize(this._batchSize);
25668
+ this.pointCloudMaterial.setPointSize(this.texParams[3]);
25669
+ this.pointCloudMaterial.enableDebugFullScreen(this._debugFullScreen);
25670
+ this._texturesInitialized = true;
25671
+ }
25672
+ super.nodeUpdate(view, passType, renderPassState, clusterLightingBuffer);
25673
+ }
25674
+ /**
25675
+ * Render pass
25676
+ */
25677
+ renderPass(view, passType, renderContext) {
25678
+ const encoder = renderContext.encoder;
25679
+ for (let mat of this.materials) {
25680
+ const passes = mat.getPass(passType);
25681
+ if (!passes || passes.length === 0) continue;
25682
+ for (const pass of passes) {
25683
+ if (!pass.pipeline) continue;
25684
+ pass.apply(this.geometry, renderContext.rendererPassState || renderContext);
25685
+ GPUContext.bindPipeline(encoder, pass);
25686
+ GPUContext.bindGeometryBuffer(encoder, this.geometry);
25687
+ const subGeometry = this.geometry.subGeometries[0];
25688
+ const lodInfo = subGeometry.lodLevels[0];
25689
+ if (this.instanceCount > 0) {
25690
+ GPUContext.drawIndexed(
25691
+ encoder,
25692
+ lodInfo.indexCount,
25693
+ this.instanceCount,
25694
+ lodInfo.indexStart,
25695
+ 0,
25696
+ 0
25697
+ );
25698
+ } else {
25699
+ GPUContext.drawIndexed(
25700
+ encoder,
25701
+ lodInfo.indexCount,
25702
+ 1,
25703
+ lodInfo.indexStart,
25704
+ 0,
25705
+ 0
25706
+ );
25707
+ }
25708
+ }
25709
+ }
25710
+ }
25711
+ /**
25712
+ * Set point size in pixels
25713
+ * @param size Point size in pixels
25714
+ */
25715
+ setPointSize(size) {
25716
+ this.texParams[3] = Math.max(0.1, size);
25717
+ if (this.pointCloudMaterial) {
25718
+ this.pointCloudMaterial.setPointSize(size);
25719
+ }
25720
+ }
25721
+ /**
25722
+ * Set point shape
25723
+ * @param shape 'square' or 'circle'
25724
+ */
25725
+ setPointShape(shape) {
25726
+ if (this.pointCloudMaterial) {
25727
+ this.pointCloudMaterial.setPointShape(shape);
25728
+ }
25729
+ }
25730
+ /**
25731
+ * Enable a fullscreen debug quad to validate the render pipeline.
25732
+ */
25733
+ enableDebugFullScreen(enabled) {
25734
+ this._debugFullScreen = enabled;
25735
+ if (this.pointCloudMaterial) {
25736
+ this.pointCloudMaterial.enableDebugFullScreen(enabled);
25737
+ }
25738
+ }
25739
+ /**
25740
+ * Set batch size for instanced rendering
25741
+ * @param batchSize Number of points per draw call
25742
+ */
25743
+ setBatchSize(batchSize) {
25744
+ this._batchSize = Math.max(1, batchSize | 0);
25745
+ if (this.geometry) {
25746
+ const oldGeometry = this.geometry;
25747
+ Reference.getInstance().detached(oldGeometry, this);
25748
+ if (!Reference.getInstance().hasReference(oldGeometry)) {
25749
+ oldGeometry.destroy();
25750
+ }
25751
+ this.geometry = new PointCloudGeometry(this._batchSize);
25752
+ }
25753
+ if (this.pointCloudMaterial) {
25754
+ this.pointCloudMaterial.setBatchSize(this._batchSize);
25755
+ this.pointCloudMaterial.enableDebugFullScreen(this._debugFullScreen);
25756
+ }
25757
+ this.instanceCount = Math.ceil(this.count / this._batchSize);
25758
+ }
25759
+ destroy(force) {
25760
+ if (this.pointColor) {
25761
+ this.pointColor.destroy(force);
25762
+ this.pointColor = null;
25763
+ }
25764
+ if (this.pointPosition) {
25765
+ this.pointPosition.destroy(force);
25766
+ this.pointPosition = null;
25767
+ }
25768
+ if (this.pointOrder) {
25769
+ this.pointOrder.destroy(force);
25770
+ this.pointOrder = null;
25771
+ }
25772
+ this._positions = null;
25773
+ this._colors = null;
25774
+ this._orderData = null;
25775
+ this.texParams = null;
25776
+ super.destroy(force);
25777
+ }
25778
+ };
25779
+ exports.PointCloudRenderer = __decorateClass$j([
25780
+ RegisterComponent(exports.PointCloudRenderer, "PointCloudRenderer")
25781
+ ], exports.PointCloudRenderer);
25782
+
25095
25783
  class BoundUtil {
25096
25784
  static maxVector = new Vector3(
25097
25785
  Number.MAX_VALUE * 0.1,
@@ -25111,6 +25799,36 @@ struct InstanceData {
25111
25799
  new Vector3(),
25112
25800
  new Vector3()
25113
25801
  ];
25802
+ static genPointCloudBounds(obj, bound) {
25803
+ bound ||= new BoundingBox(Vector3.ZERO, Vector3.ZERO);
25804
+ bound.setFromMinMax(this.maxVector, this.minVector);
25805
+ let pointCloudRenderers = obj.getComponents(exports.PointCloudRenderer);
25806
+ if (!pointCloudRenderers) {
25807
+ console.warn("genPointCloudBounds: No PointCloudRenderer found on object");
25808
+ return bound;
25809
+ }
25810
+ for (const pointCloudRenderer of pointCloudRenderers) {
25811
+ const positions = pointCloudRenderer.positions;
25812
+ const count = pointCloudRenderer.fullCount;
25813
+ if (!positions || count === 0) {
25814
+ console.warn("genPointCloudBounds: No position data available");
25815
+ continue;
25816
+ }
25817
+ const matrix = pointCloudRenderer.object3D.transform.worldMatrix;
25818
+ const point = new Vector3();
25819
+ for (let i = 0; i < count; i++) {
25820
+ const idx = i * 3;
25821
+ point.set(
25822
+ positions[idx + 0],
25823
+ positions[idx + 1],
25824
+ positions[idx + 2]
25825
+ );
25826
+ matrix.transformPoint(point, point);
25827
+ bound.expandByPoint(point);
25828
+ }
25829
+ }
25830
+ return bound;
25831
+ }
25114
25832
  static genGSplatBounds(obj, bound) {
25115
25833
  bound ||= new BoundingBox(Vector3.ZERO, Vector3.ZERO);
25116
25834
  bound.setFromMinMax(this.maxVector, this.minVector);
@@ -39088,7 +39806,10 @@ else if (typeof exports === 'object')
39088
39806
  buffer;
39089
39807
  binOffset;
39090
39808
  binLength;
39091
- header;
39809
+ _header;
39810
+ get header() {
39811
+ return this._header;
39812
+ }
39092
39813
  constructor(buffer, start, headerLength, binLength) {
39093
39814
  this.buffer = buffer;
39094
39815
  this.binOffset = start + headerLength;
@@ -39100,13 +39821,13 @@ else if (typeof exports === 'object')
39100
39821
  } else {
39101
39822
  header = {};
39102
39823
  }
39103
- this.header = header;
39824
+ this._header = header;
39104
39825
  }
39105
39826
  getKeys() {
39106
- return Object.keys(this.header);
39827
+ return Object.keys(this._header);
39107
39828
  }
39108
39829
  getData(key, count, defaultComponentType = null, defaultType = null) {
39109
- const header = this.header;
39830
+ const header = this._header;
39110
39831
  if (!(key in header)) {
39111
39832
  return null;
39112
39833
  }
@@ -39188,7 +39909,7 @@ else if (typeof exports === 'object')
39188
39909
  }
39189
39910
  destroy() {
39190
39911
  this.buffer = null;
39191
- this.header = null;
39912
+ this._header = null;
39192
39913
  this.binOffset = null;
39193
39914
  this.binLength = null;
39194
39915
  }
@@ -41432,7 +42153,7 @@ else if (typeof exports === 'object')
41432
42153
  }
41433
42154
  }
41434
42155
 
41435
- const version = "1.0.26";
42156
+ const version = "1.0.28";
41436
42157
 
41437
42158
  class Engine3D {
41438
42159
  /**
@@ -60165,6 +60886,166 @@ fn frag(){
60165
60886
  triangleTexnumbers: triangleTexnumbers.length > 0 ? triangleTexnumbers : void 0
60166
60887
  };
60167
60888
  }
60889
+ function parsePlyPointCloud(buffer) {
60890
+ const header = parsePlyHeader(buffer);
60891
+ const { format } = header;
60892
+ if (format === "ascii") {
60893
+ return parsePlyPointCloudASCII(buffer, header);
60894
+ } else {
60895
+ return parsePlyPointCloudBinary(buffer, header);
60896
+ }
60897
+ }
60898
+ function parsePlyPointCloudBinary(buffer, header) {
60899
+ const { vertexCount, properties, headerByteLength } = header;
60900
+ const payload = new DataView(buffer, headerByteLength);
60901
+ const has = (n) => properties.find((p) => p.name === n) != null;
60902
+ const propIndex = (n) => properties.findIndex((p) => p.name === n);
60903
+ const position = new Float32Array(vertexCount * 3);
60904
+ const hasColor = (has("red") || has("r")) && (has("green") || has("g")) && (has("blue") || has("b"));
60905
+ const hasAlpha = has("alpha") || has("a");
60906
+ const color = hasColor ? new Uint8Array(vertexCount * 4) : void 0;
60907
+ const propOffsets = [];
60908
+ let stride = 0;
60909
+ for (const p of properties) {
60910
+ propOffsets.push(stride);
60911
+ stride += byteSizeOfType(p.type);
60912
+ }
60913
+ let base = 0;
60914
+ for (let v = 0; v < vertexCount; v++) {
60915
+ const vOffset = base;
60916
+ const ix = propIndex("x");
60917
+ const iy = propIndex("y");
60918
+ const iz = propIndex("z");
60919
+ if (ix < 0 || iy < 0 || iz < 0) {
60920
+ throw new Error("PLY: Missing x/y/z for vertex");
60921
+ }
60922
+ position[v * 3 + 0] = readByType(payload, vOffset + propOffsets[ix], properties[ix].type);
60923
+ position[v * 3 + 1] = readByType(payload, vOffset + propOffsets[iy], properties[iy].type);
60924
+ position[v * 3 + 2] = readByType(payload, vOffset + propOffsets[iz], properties[iz].type);
60925
+ if (color) {
60926
+ const rIdx = propIndex("red") >= 0 ? propIndex("red") : propIndex("r");
60927
+ const gIdx = propIndex("green") >= 0 ? propIndex("green") : propIndex("g");
60928
+ const bIdx = propIndex("blue") >= 0 ? propIndex("blue") : propIndex("b");
60929
+ const aIdx = hasAlpha ? propIndex("alpha") >= 0 ? propIndex("alpha") : propIndex("a") : -1;
60930
+ if (rIdx >= 0 && gIdx >= 0 && bIdx >= 0) {
60931
+ let r = readByType(payload, vOffset + propOffsets[rIdx], properties[rIdx].type);
60932
+ let g = readByType(payload, vOffset + propOffsets[gIdx], properties[gIdx].type);
60933
+ let b = readByType(payload, vOffset + propOffsets[bIdx], properties[bIdx].type);
60934
+ let a = 255;
60935
+ if (properties[rIdx].type === "float" || properties[rIdx].type === "float32" || properties[rIdx].type === "double" || properties[rIdx].type === "float64") {
60936
+ r = Math.round(r * 255);
60937
+ g = Math.round(g * 255);
60938
+ b = Math.round(b * 255);
60939
+ }
60940
+ if (aIdx >= 0) {
60941
+ a = readByType(payload, vOffset + propOffsets[aIdx], properties[aIdx].type);
60942
+ if (properties[aIdx].type === "float" || properties[aIdx].type === "float32" || properties[aIdx].type === "double" || properties[aIdx].type === "float64") {
60943
+ a = Math.round(a * 255);
60944
+ }
60945
+ }
60946
+ color[v * 4 + 0] = Math.max(0, Math.min(255, r));
60947
+ color[v * 4 + 1] = Math.max(0, Math.min(255, g));
60948
+ color[v * 4 + 2] = Math.max(0, Math.min(255, b));
60949
+ color[v * 4 + 3] = Math.max(0, Math.min(255, a));
60950
+ }
60951
+ }
60952
+ base += stride;
60953
+ }
60954
+ return {
60955
+ vertexCount,
60956
+ position,
60957
+ color
60958
+ };
60959
+ }
60960
+ function parsePlyPointCloudASCII(buffer, header) {
60961
+ const { vertexCount, properties } = header;
60962
+ const text = new TextDecoder("utf-8").decode(buffer);
60963
+ const headerEnd = text.indexOf("end_header");
60964
+ if (headerEnd < 0) {
60965
+ throw new Error("PLY: Invalid PLY header");
60966
+ }
60967
+ let bodyStart = headerEnd + "end_header".length;
60968
+ while (bodyStart < text.length && (text[bodyStart] === " " || text[bodyStart] === "\n" || text[bodyStart] === "\r")) {
60969
+ bodyStart++;
60970
+ }
60971
+ const bodyText = text.substring(bodyStart);
60972
+ const tokens = bodyText.split(/\s+/).filter((token) => token.length > 0);
60973
+ let tokenIndex = 0;
60974
+ const has = (n) => properties.find((p) => p.name === n) != null;
60975
+ const parseASCIINumber = (type) => {
60976
+ if (tokenIndex >= tokens.length) {
60977
+ throw new Error("PLY: Unexpected end of file");
60978
+ }
60979
+ const value = tokens[tokenIndex++];
60980
+ switch (type) {
60981
+ case "char":
60982
+ case "uchar":
60983
+ case "short":
60984
+ case "ushort":
60985
+ case "int":
60986
+ case "uint":
60987
+ case "int8":
60988
+ case "uint8":
60989
+ case "int16":
60990
+ case "uint16":
60991
+ case "int32":
60992
+ case "uint32":
60993
+ return parseInt(value);
60994
+ case "float":
60995
+ case "double":
60996
+ case "float32":
60997
+ case "float64":
60998
+ return parseFloat(value);
60999
+ default:
61000
+ return parseFloat(value);
61001
+ }
61002
+ };
61003
+ const position = new Float32Array(vertexCount * 3);
61004
+ const hasColor = (has("red") || has("r")) && (has("green") || has("g")) && (has("blue") || has("b"));
61005
+ const hasAlpha = has("alpha") || has("a");
61006
+ const color = hasColor ? new Uint8Array(vertexCount * 4) : void 0;
61007
+ const propIndex = (n) => properties.findIndex((p) => p.name === n);
61008
+ const xIdx = propIndex("x");
61009
+ const yIdx = propIndex("y");
61010
+ const zIdx = propIndex("z");
61011
+ const rIdx = hasColor ? propIndex("red") >= 0 ? propIndex("red") : propIndex("r") : -1;
61012
+ const gIdx = hasColor ? propIndex("green") >= 0 ? propIndex("green") : propIndex("g") : -1;
61013
+ const bIdx = hasColor ? propIndex("blue") >= 0 ? propIndex("blue") : propIndex("b") : -1;
61014
+ const aIdx = hasAlpha ? propIndex("alpha") >= 0 ? propIndex("alpha") : propIndex("a") : -1;
61015
+ for (let v = 0; v < vertexCount; v++) {
61016
+ for (let pIdx = 0; pIdx < properties.length; pIdx++) {
61017
+ const prop = properties[pIdx];
61018
+ const value = parseASCIINumber(prop.type);
61019
+ if (pIdx === xIdx) {
61020
+ position[v * 3 + 0] = value;
61021
+ } else if (pIdx === yIdx) {
61022
+ position[v * 3 + 1] = value;
61023
+ } else if (pIdx === zIdx) {
61024
+ position[v * 3 + 2] = value;
61025
+ } else if (pIdx === rIdx && color) {
61026
+ const r = prop.type === "uchar" || prop.type === "uint8" ? value : Math.round(value * 255);
61027
+ color[v * 4 + 0] = Math.max(0, Math.min(255, r));
61028
+ } else if (pIdx === gIdx && color) {
61029
+ const g = prop.type === "uchar" || prop.type === "uint8" ? value : Math.round(value * 255);
61030
+ color[v * 4 + 1] = Math.max(0, Math.min(255, g));
61031
+ } else if (pIdx === bIdx && color) {
61032
+ const b = prop.type === "uchar" || prop.type === "uint8" ? value : Math.round(value * 255);
61033
+ color[v * 4 + 2] = Math.max(0, Math.min(255, b));
61034
+ } else if (pIdx === aIdx && color) {
61035
+ const a = prop.type === "uchar" || prop.type === "uint8" ? value : Math.round(value * 255);
61036
+ color[v * 4 + 3] = Math.max(0, Math.min(255, a));
61037
+ }
61038
+ }
61039
+ if (color && aIdx < 0) {
61040
+ color[v * 4 + 3] = 255;
61041
+ }
61042
+ }
61043
+ return {
61044
+ vertexCount,
61045
+ position,
61046
+ color
61047
+ };
61048
+ }
60168
61049
 
60169
61050
  class GaussianSplatParser extends ParserBase {
60170
61051
  static format = ParserFormat.BIN;
@@ -60297,6 +61178,23 @@ fn frag(){
60297
61178
  break;
60298
61179
  }
60299
61180
  case PlyMode.PointCloud: {
61181
+ const plyData = parsePlyPointCloud(buffer);
61182
+ const pointCloudObj = new exports.Object3D();
61183
+ pointCloudObj.name = "PLYPointCloud";
61184
+ const pointCloudObjRoot = new exports.Object3D();
61185
+ pointCloudObjRoot.name = "PLYPointCloudRoot";
61186
+ pointCloudObj.addChild(pointCloudObjRoot);
61187
+ const renderer = pointCloudObjRoot.addComponent(exports.PointCloudRenderer);
61188
+ if (plyData.color) {
61189
+ renderer.initFromData(plyData.position, plyData.color, plyData.vertexCount);
61190
+ } else {
61191
+ const defaultColors = new Uint8Array(plyData.vertexCount * 4);
61192
+ defaultColors.fill(255);
61193
+ renderer.initFromData(plyData.position, defaultColors, plyData.vertexCount);
61194
+ }
61195
+ renderer.setPointShape("circle");
61196
+ renderer.setPointSize(4);
61197
+ this.data = pointCloudObj;
60300
61198
  break;
60301
61199
  }
60302
61200
  case PlyMode.Mesh: {
@@ -60400,6 +61298,274 @@ fn frag(){
60400
61298
  }
60401
61299
  }
60402
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
+ const rtcCenter = featureTable.getData("RTC_CENTER", 1, "FLOAT", "VEC3");
61368
+ if (rtcCenter) {
61369
+ pointCloudObj.transform.localPosition.set(
61370
+ rtcCenter[0],
61371
+ rtcCenter[1],
61372
+ rtcCenter[2]
61373
+ );
61374
+ }
61375
+ pointCloudObj["batchTable"] = batchTable;
61376
+ pointCloudObj["featureTable"] = featureTable;
61377
+ return pointCloudObj;
61378
+ }
61379
+ parsePositions(featureTable, pointsLength) {
61380
+ let positions = featureTable.getData(
61381
+ "POSITION",
61382
+ pointsLength,
61383
+ "FLOAT",
61384
+ "VEC3"
61385
+ );
61386
+ if (positions) {
61387
+ return positions;
61388
+ }
61389
+ const quantized = featureTable.getData(
61390
+ "POSITION_QUANTIZED",
61391
+ pointsLength,
61392
+ "UNSIGNED_SHORT",
61393
+ "VEC3"
61394
+ );
61395
+ if (!quantized) {
61396
+ throw new Error(
61397
+ "PNTSLoader: Either POSITION or POSITION_QUANTIZED must be defined"
61398
+ );
61399
+ }
61400
+ const scale = featureTable.getData(
61401
+ "QUANTIZED_VOLUME_SCALE",
61402
+ 1,
61403
+ "FLOAT",
61404
+ "VEC3"
61405
+ );
61406
+ const offset = featureTable.getData(
61407
+ "QUANTIZED_VOLUME_OFFSET",
61408
+ 1,
61409
+ "FLOAT",
61410
+ "VEC3"
61411
+ );
61412
+ if (!scale || !offset) {
61413
+ throw new Error(
61414
+ "PNTSLoader: QUANTIZED_VOLUME_SCALE and QUANTIZED_VOLUME_OFFSET must be defined for quantized positions"
61415
+ );
61416
+ }
61417
+ const decoded = new Float32Array(pointsLength * 3);
61418
+ const quantizedRange = 65535;
61419
+ for (let i = 0; i < pointsLength; i++) {
61420
+ const idx = i * 3;
61421
+ decoded[idx + 0] = quantized[idx + 0] / quantizedRange * scale[0] + offset[0];
61422
+ decoded[idx + 1] = quantized[idx + 1] / quantizedRange * scale[1] + offset[1];
61423
+ decoded[idx + 2] = quantized[idx + 2] / quantizedRange * scale[2] + offset[2];
61424
+ }
61425
+ return decoded;
61426
+ }
61427
+ parseColors(featureTable, pointsLength) {
61428
+ let colors = featureTable.getData(
61429
+ "RGBA",
61430
+ pointsLength,
61431
+ "UNSIGNED_BYTE",
61432
+ "VEC4"
61433
+ );
61434
+ if (colors) {
61435
+ return colors;
61436
+ }
61437
+ const rgb = featureTable.getData(
61438
+ "RGB",
61439
+ pointsLength,
61440
+ "UNSIGNED_BYTE",
61441
+ "VEC3"
61442
+ );
61443
+ if (rgb) {
61444
+ const rgba2 = new Uint8Array(pointsLength * 4);
61445
+ for (let i = 0; i < pointsLength; i++) {
61446
+ const rgbIdx = i * 3;
61447
+ const rgbaIdx = i * 4;
61448
+ rgba2[rgbaIdx + 0] = rgb[rgbIdx + 0];
61449
+ rgba2[rgbaIdx + 1] = rgb[rgbIdx + 1];
61450
+ rgba2[rgbaIdx + 2] = rgb[rgbIdx + 2];
61451
+ rgba2[rgbaIdx + 3] = 255;
61452
+ }
61453
+ return rgba2;
61454
+ }
61455
+ const rgb565 = featureTable.getData(
61456
+ "RGB565",
61457
+ pointsLength,
61458
+ "UNSIGNED_SHORT",
61459
+ "SCALAR"
61460
+ );
61461
+ if (rgb565) {
61462
+ const rgba2 = new Uint8Array(pointsLength * 4);
61463
+ for (let i = 0; i < pointsLength; i++) {
61464
+ const decoded = this.decodeRGB565(rgb565[i]);
61465
+ const idx = i * 4;
61466
+ rgba2[idx + 0] = decoded[0];
61467
+ rgba2[idx + 1] = decoded[1];
61468
+ rgba2[idx + 2] = decoded[2];
61469
+ rgba2[idx + 3] = 255;
61470
+ }
61471
+ return rgba2;
61472
+ }
61473
+ const constantRGBA = featureTable.getData(
61474
+ "CONSTANT_RGBA",
61475
+ 1,
61476
+ "UNSIGNED_BYTE",
61477
+ "VEC4"
61478
+ );
61479
+ if (constantRGBA) {
61480
+ const rgba2 = new Uint8Array(pointsLength * 4);
61481
+ for (let i = 0; i < pointsLength; i++) {
61482
+ const idx = i * 4;
61483
+ rgba2[idx + 0] = constantRGBA[0];
61484
+ rgba2[idx + 1] = constantRGBA[1];
61485
+ rgba2[idx + 2] = constantRGBA[2];
61486
+ rgba2[idx + 3] = constantRGBA[3];
61487
+ }
61488
+ return rgba2;
61489
+ }
61490
+ const rgba = new Uint8Array(pointsLength * 4);
61491
+ rgba.fill(255);
61492
+ return rgba;
61493
+ }
61494
+ parseNormals(featureTable, pointsLength) {
61495
+ let normals = featureTable.getData(
61496
+ "NORMAL",
61497
+ pointsLength,
61498
+ "FLOAT",
61499
+ "VEC3"
61500
+ );
61501
+ if (normals) {
61502
+ return normals;
61503
+ }
61504
+ const octNormals = featureTable.getData(
61505
+ "NORMAL_OCT16P",
61506
+ pointsLength,
61507
+ "UNSIGNED_BYTE",
61508
+ "VEC2"
61509
+ );
61510
+ if (octNormals) {
61511
+ return this.decodeOctNormals(octNormals, pointsLength);
61512
+ }
61513
+ return null;
61514
+ }
61515
+ decodeRGB565(value) {
61516
+ const r = (value >> 11 & 31) << 3;
61517
+ const g = (value >> 5 & 63) << 2;
61518
+ const b = (value & 31) << 3;
61519
+ return [r, g, b];
61520
+ }
61521
+ decodeOctNormals(octNormals, pointsLength) {
61522
+ const normals = new Float32Array(pointsLength * 3);
61523
+ for (let i = 0; i < pointsLength; i++) {
61524
+ const idx = i * 2;
61525
+ const x = octNormals[idx] / 255;
61526
+ const y = octNormals[idx + 1] / 255;
61527
+ const nx = x * 2 - 1;
61528
+ const ny = y * 2 - 1;
61529
+ const nz = 1 - Math.abs(nx) - Math.abs(ny);
61530
+ let tx, ty;
61531
+ if (nz < 0) {
61532
+ tx = (nx >= 0 ? 1 : -1) * (1 - Math.abs(ny));
61533
+ ty = (ny >= 0 ? 1 : -1) * (1 - Math.abs(nx));
61534
+ } else {
61535
+ tx = nx;
61536
+ ty = ny;
61537
+ }
61538
+ const length = Math.sqrt(tx * tx + ty * ty + nz * nz);
61539
+ const nidx = i * 3;
61540
+ normals[nidx + 0] = tx / length;
61541
+ normals[nidx + 1] = ty / length;
61542
+ normals[nidx + 2] = nz / length;
61543
+ }
61544
+ return normals;
61545
+ }
61546
+ async parseDraco(featureTable, dracoExtension, pointsLength) {
61547
+ throw new Error("Draco compression not yet implemented");
61548
+ }
61549
+ }
61550
+
61551
+ class PNTSParser extends ParserBase {
61552
+ static format = ParserFormat.BIN;
61553
+ async parseBuffer(buffer) {
61554
+ const loader = new PNTSLoader();
61555
+ const pntsRoot = await loader.parse(buffer);
61556
+ const pntsObj = new exports.Object3D();
61557
+ pntsObj.name = "PNTS";
61558
+ pntsObj.addChild(pntsRoot);
61559
+ this.data = pntsObj;
61560
+ }
61561
+ verification() {
61562
+ if (this.data) {
61563
+ return true;
61564
+ }
61565
+ throw new Error("PNTSParser: Parse failed");
61566
+ }
61567
+ }
61568
+
60403
61569
  class PrefabBoneData {
60404
61570
  boneName;
60405
61571
  bonePath;
@@ -63506,9 +64672,9 @@ fn frag(){
63506
64672
  const extension = getUrlExtension(uri);
63507
64673
  const fullUrl = url;
63508
64674
  let scene = null;
64675
+ const loader = new FileLoader();
63509
64676
  switch (extension.toLowerCase()) {
63510
- case "b3dm":
63511
- const loader = new FileLoader();
64677
+ case "b3dm": {
63512
64678
  const parser = await loader.load(fullUrl, B3DMParser, {
63513
64679
  onProgress: (e) => {
63514
64680
  },
@@ -63517,29 +64683,38 @@ fn frag(){
63517
64683
  });
63518
64684
  scene = parser.data;
63519
64685
  break;
63520
- case "i3dm":
63521
- scene = await Engine3D.res.loadI3DM(
63522
- fullUrl,
63523
- {
63524
- onProgress: (e) => {
63525
- },
63526
- onComplete: (e) => {
63527
- }
64686
+ }
64687
+ case "i3dm": {
64688
+ const parser = await loader.load(fullUrl, I3DMParser, {
64689
+ onProgress: (e) => {
64690
+ },
64691
+ onComplete: (e) => {
63528
64692
  }
63529
- );
64693
+ });
64694
+ scene = parser.data;
63530
64695
  break;
64696
+ }
63531
64697
  case "glb":
63532
- case "gltf":
63533
- scene = await Engine3D.res.loadGltf(fullUrl, {
64698
+ case "gltf": {
64699
+ const parser = await loader.load(fullUrl, GLTFParser, {
63534
64700
  onProgress: (e) => {
63535
64701
  },
63536
64702
  onComplete: (e) => {
63537
64703
  }
63538
64704
  });
64705
+ scene = parser.data;
63539
64706
  break;
63540
- case "pnts":
63541
- console.warn("PNTS format not yet supported");
64707
+ }
64708
+ case "pnts": {
64709
+ const parser = await loader.load(fullUrl, PNTSParser, {
64710
+ onProgress: (e) => {
64711
+ },
64712
+ onComplete: (e) => {
64713
+ }
64714
+ });
64715
+ scene = parser.data;
63542
64716
  break;
64717
+ }
63543
64718
  case "json":
63544
64719
  {
63545
64720
  try {
@@ -68536,69 +69711,6 @@ fn frag(){
68536
69711
  }
68537
69712
  }
68538
69713
 
68539
- class Float32ArrayTexture extends Texture {
68540
- create(width, height, data, filtering = true) {
68541
- let device = webGPUContext.device;
68542
- const bytesPerRow = width * 4 * 4;
68543
- this.format = GPUTextureFormat.rgba32float;
68544
- let mipmapCount = 1;
68545
- this.createTextureDescriptor(width, height, mipmapCount, this.format);
68546
- const textureDataBuffer = device.createBuffer({
68547
- size: data.byteLength,
68548
- usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC
68549
- });
68550
- device.queue.writeBuffer(textureDataBuffer, 0, data);
68551
- const commandEncoder = GPUContext.beginCommandEncoder();
68552
- commandEncoder.copyBufferToTexture(
68553
- {
68554
- buffer: textureDataBuffer,
68555
- bytesPerRow
68556
- },
68557
- {
68558
- texture: this.getGPUTexture()
68559
- },
68560
- {
68561
- width,
68562
- height,
68563
- depthOrArrayLayers: 1
68564
- }
68565
- );
68566
- GPUContext.endCommandEncoder(commandEncoder);
68567
- if (filtering) {
68568
- this.samplerBindingLayout.type = `non-filtering`;
68569
- this.textureBindingLayout.sampleType = `unfilterable-float`;
68570
- }
68571
- this.gpuSampler = device.createSampler({});
68572
- }
68573
- fromBuffer(width, height, textureDataBuffer) {
68574
- let device = webGPUContext.device;
68575
- const bytesPerRow = width * 4 * 4;
68576
- this.format = GPUTextureFormat.rgba32float;
68577
- this.mipmapCount = 1;
68578
- this.createTextureDescriptor(width, height, this.mipmapCount, this.format);
68579
- const commandEncoder = GPUContext.beginCommandEncoder();
68580
- commandEncoder.copyBufferToTexture(
68581
- {
68582
- buffer: textureDataBuffer,
68583
- bytesPerRow
68584
- },
68585
- {
68586
- texture: this.getGPUTexture()
68587
- },
68588
- {
68589
- width,
68590
- height,
68591
- depthOrArrayLayers: 1
68592
- }
68593
- );
68594
- GPUContext.endCommandEncoder(commandEncoder);
68595
- this.samplerBindingLayout.type = `non-filtering`;
68596
- this.textureBindingLayout.sampleType = `unfilterable-float`;
68597
- this.gpuSampler = device.createSampler({});
68598
- return this;
68599
- }
68600
- }
68601
-
68602
69714
  class SolidColorSky extends LDRTextureCube {
68603
69715
  _internalTexture;
68604
69716
  _minSize = 32;
@@ -70365,6 +71477,9 @@ fn frag(){
70365
71477
  exports.PBRLItShader = PBRLItShader;
70366
71478
  exports.PBRLitSSSShader = PBRLitSSSShader;
70367
71479
  exports.PLUGIN_REGISTERED = PLUGIN_REGISTERED;
71480
+ exports.PNTSLoader = PNTSLoader;
71481
+ exports.PNTSLoaderBase = PNTSLoaderBase;
71482
+ exports.PNTSParser = PNTSParser;
70368
71483
  exports.ParserBase = ParserBase;
70369
71484
  exports.ParserFormat = ParserFormat;
70370
71485
  exports.ParticleSystemCurveEvalMode = ParticleSystemCurveEvalMode;
@@ -70386,6 +71501,10 @@ fn frag(){
70386
71501
  exports.PlyMode = PlyMode;
70387
71502
  exports.PlyParser = PlyParser;
70388
71503
  exports.PointClassification = PointClassification;
71504
+ exports.PointCloudGeometry = PointCloudGeometry;
71505
+ exports.PointCloudMaterial = PointCloudMaterial;
71506
+ exports.PointCloud_FS = PointCloud_FS;
71507
+ exports.PointCloud_VS = PointCloud_VS;
70389
71508
  exports.PointLightShadowRenderer = PointLightShadowRenderer;
70390
71509
  exports.PointShadowCubeCamera = PointShadowCubeCamera;
70391
71510
  exports.PointerEvent3D = PointerEvent3D;
@@ -70726,6 +71845,7 @@ fn frag(){
70726
71845
  exports.parsePlyGaussianSplat = parsePlyGaussianSplat;
70727
71846
  exports.parsePlyHeader = parsePlyHeader;
70728
71847
  exports.parsePlyMesh = parsePlyMesh;
71848
+ exports.parsePlyPointCloud = parsePlyPointCloud;
70729
71849
  exports.perm = perm;
70730
71850
  exports.post = post;
70731
71851
  exports.priorityCallback = priorityCallback;