@d5techs/3dgs-lib 1.4.2 → 1.4.4

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.
package/dist/3dgs-lib.js CHANGED
@@ -4263,6 +4263,52 @@ class OBJLoader {
4263
4263
  }
4264
4264
  }
4265
4265
  }
4266
+ function transformSHCoeffsYZSwap$1(sh, base, perChannel) {
4267
+ const SQRT3_2 = Math.sqrt(3) / 2;
4268
+ if (perChannel >= 3) {
4269
+ for (let ch = 0; ch < 3; ch++) {
4270
+ const a = sh[base + ch];
4271
+ const b = sh[base + 3 + ch];
4272
+ sh[base + ch] = -b;
4273
+ sh[base + 3 + ch] = -a;
4274
+ }
4275
+ }
4276
+ if (perChannel >= 8) {
4277
+ for (let ch = 0; ch < 3; ch++) {
4278
+ const g0 = sh[base + 9 + ch];
4279
+ const g1 = sh[base + 12 + ch];
4280
+ const g2 = sh[base + 15 + ch];
4281
+ const g3 = sh[base + 18 + ch];
4282
+ const g4 = sh[base + 21 + ch];
4283
+ sh[base + 9 + ch] = -g3;
4284
+ sh[base + 12 + ch] = g1;
4285
+ sh[base + 15 + ch] = -0.5 * g2 - SQRT3_2 * g4;
4286
+ sh[base + 18 + ch] = -g0;
4287
+ sh[base + 21 + ch] = -SQRT3_2 * g2 + 0.5 * g4;
4288
+ }
4289
+ }
4290
+ if (perChannel >= 15) {
4291
+ const A = Math.sqrt(10) / 4;
4292
+ const B = Math.sqrt(6) / 4;
4293
+ const P = Math.sqrt(15) / 4;
4294
+ for (let ch = 0; ch < 3; ch++) {
4295
+ const g0 = sh[base + 24 + ch];
4296
+ const g1 = sh[base + 27 + ch];
4297
+ const g2 = sh[base + 30 + ch];
4298
+ const g3 = sh[base + 33 + ch];
4299
+ const g4 = sh[base + 36 + ch];
4300
+ const g5 = sh[base + 39 + ch];
4301
+ const g6 = sh[base + 42 + ch];
4302
+ sh[base + 24 + ch] = A * g3 - B * g5;
4303
+ sh[base + 27 + ch] = g1;
4304
+ sh[base + 30 + ch] = B * g3 + A * g5;
4305
+ sh[base + 33 + ch] = A * g0 + B * g2;
4306
+ sh[base + 36 + ch] = -0.25 * g4 - P * g6;
4307
+ sh[base + 39 + ch] = -B * g0 + A * g2;
4308
+ sh[base + 42 + ch] = -P * g4 + 0.25 * g6;
4309
+ }
4310
+ }
4311
+ }
4266
4312
  const TYPE_SIZES$1 = {
4267
4313
  char: 1,
4268
4314
  uchar: 1,
@@ -4489,6 +4535,9 @@ async function loadPLY(url, options = {}) {
4489
4535
  shRest[dstBase + 1] = srcG < shRestProps.length ? readProperty$1(dataView, base, shRestProps[srcG], littleEndian) : 0;
4490
4536
  shRest[dstBase + 2] = srcB < shRestProps.length ? readProperty$1(dataView, base, shRestProps[srcB], littleEndian) : 0;
4491
4537
  }
4538
+ if (swapYZ) {
4539
+ transformSHCoeffsYZSwap$1(shRestBuffer, shOffset, perChannel);
4540
+ }
4492
4541
  splats[i] = {
4493
4542
  mean: swapYZ ? [x, z, y] : [x, y, z],
4494
4543
  scale: swapYZ ? [scale_0, scale_2, scale_1] : [scale_0, scale_1, scale_2],
@@ -4528,6 +4577,52 @@ const TYPE_SIZES = {
4528
4577
  double: 8,
4529
4578
  float64: 8
4530
4579
  };
4580
+ function transformSHCoeffsYZSwap(sh, base, perChannel) {
4581
+ const SQRT3_2 = Math.sqrt(3) / 2;
4582
+ if (perChannel >= 3) {
4583
+ for (let ch = 0; ch < 3; ch++) {
4584
+ const a = sh[base + ch];
4585
+ const b = sh[base + 3 + ch];
4586
+ sh[base + ch] = -b;
4587
+ sh[base + 3 + ch] = -a;
4588
+ }
4589
+ }
4590
+ if (perChannel >= 8) {
4591
+ for (let ch = 0; ch < 3; ch++) {
4592
+ const g0 = sh[base + 9 + ch];
4593
+ const g1 = sh[base + 12 + ch];
4594
+ const g2 = sh[base + 15 + ch];
4595
+ const g3 = sh[base + 18 + ch];
4596
+ const g4 = sh[base + 21 + ch];
4597
+ sh[base + 9 + ch] = -g3;
4598
+ sh[base + 12 + ch] = g1;
4599
+ sh[base + 15 + ch] = -0.5 * g2 - SQRT3_2 * g4;
4600
+ sh[base + 18 + ch] = -g0;
4601
+ sh[base + 21 + ch] = -SQRT3_2 * g2 + 0.5 * g4;
4602
+ }
4603
+ }
4604
+ if (perChannel >= 15) {
4605
+ const A = Math.sqrt(10) / 4;
4606
+ const B = Math.sqrt(6) / 4;
4607
+ const P = Math.sqrt(15) / 4;
4608
+ for (let ch = 0; ch < 3; ch++) {
4609
+ const g0 = sh[base + 24 + ch];
4610
+ const g1 = sh[base + 27 + ch];
4611
+ const g2 = sh[base + 30 + ch];
4612
+ const g3 = sh[base + 33 + ch];
4613
+ const g4 = sh[base + 36 + ch];
4614
+ const g5 = sh[base + 39 + ch];
4615
+ const g6 = sh[base + 42 + ch];
4616
+ sh[base + 24 + ch] = A * g3 - B * g5;
4617
+ sh[base + 27 + ch] = g1;
4618
+ sh[base + 30 + ch] = B * g3 + A * g5;
4619
+ sh[base + 33 + ch] = A * g0 + B * g2;
4620
+ sh[base + 36 + ch] = -0.25 * g4 - P * g6;
4621
+ sh[base + 39 + ch] = -B * g0 + A * g2;
4622
+ sh[base + 42 + ch] = -P * g4 + 0.25 * g6;
4623
+ }
4624
+ }
4625
+ }
4531
4626
  function validatePLYMagic(buffer) {
4532
4627
  const bytes = new Uint8Array(buffer, 0, Math.min(buffer.byteLength, 10));
4533
4628
  const decoder = new TextDecoder("ascii");
@@ -4868,6 +4963,9 @@ async function parsePLYBuffer(buffer, options = {}) {
4868
4963
  shCoeffs[shBase + dstBase + 2] = readProperty(dataView, base + prop.byteOffset, prop.type, littleEndian);
4869
4964
  }
4870
4965
  }
4966
+ if (swapYZ) {
4967
+ transformSHCoeffsYZSwap(shCoeffs, shBase, perChannel);
4968
+ }
4871
4969
  }
4872
4970
  outputIdx++;
4873
4971
  if (onProgress) {
@@ -4952,7 +5050,8 @@ const PLYLoaderMobile = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.def
4952
5050
  __proto__: null,
4953
5051
  compactDataToGPUBuffer,
4954
5052
  loadPLYMobile,
4955
- parsePLYBuffer
5053
+ parsePLYBuffer,
5054
+ transformSHCoeffsYZSwap
4956
5055
  }, Symbol.toStringTag, { value: "Module" }));
4957
5056
  const SPLAT_SIZE = 32;
4958
5057
  const MIN_FILE_SIZE = SPLAT_SIZE;
@@ -14276,6 +14375,16 @@ class HotspotManager {
14276
14375
  getHotspotCount() {
14277
14376
  return this.hotspots.length;
14278
14377
  }
14378
+ /**
14379
+ * 更新热点的 placedScale,使 billboard 每帧重建矩阵时使用新值。
14380
+ * 解决编辑器侧通过 setHotspotScale 修改尺寸后,billboard 模式
14381
+ * 仍用旧 placedScale 覆盖的问题。
14382
+ */
14383
+ setHotspotPlacedScale(hotspotIndex, newPlacedScale) {
14384
+ if (hotspotIndex < 0 || hotspotIndex >= this.hotspots.length) return false;
14385
+ this.hotspots[hotspotIndex].placedScale = newPlacedScale;
14386
+ return true;
14387
+ }
14279
14388
  /**
14280
14389
  * 通过 overlay mesh 起始索引找到对应的热点索引
14281
14390
  */
@@ -16301,7 +16410,7 @@ class App {
16301
16410
  }
16302
16411
  });
16303
16412
  if (coordinateSystem === "blender") {
16304
- const { positions, scales, rotations, count } = compactData;
16413
+ const { positions, scales, rotations, count, shCoeffs } = compactData;
16305
16414
  for (let i = 0; i < count; i++) {
16306
16415
  const i3 = i * 3, i4 = i * 4;
16307
16416
  const py = positions[i3 + 1], pz = positions[i3 + 2];
@@ -16314,6 +16423,9 @@ class App {
16314
16423
  rotations[i4] = -rw;
16315
16424
  rotations[i4 + 2] = rz;
16316
16425
  rotations[i4 + 3] = ry;
16426
+ if (shCoeffs) {
16427
+ transformSHCoeffsYZSwap(shCoeffs, i * 45, 15);
16428
+ }
16317
16429
  }
16318
16430
  }
16319
16431
  if (onProgress) onProgress(90, "upload");
@@ -16622,6 +16734,9 @@ class App {
16622
16734
  getHotspotBillboard(hotspotIndex) {
16623
16735
  return this.hotspotManager.getHotspotBillboard(hotspotIndex);
16624
16736
  }
16737
+ setHotspotPlacedScale(hotspotIndex, newPlacedScale) {
16738
+ return this.hotspotManager.setHotspotPlacedScale(hotspotIndex, newPlacedScale);
16739
+ }
16625
16740
  getHotspotCount() {
16626
16741
  return this.hotspotManager.getHotspotCount();
16627
16742
  }