stpete2 commited on
Commit
d2eab41
·
verified ·
1 Parent(s): 3112874

Upload preprocess_manual.js

Browse files
Files changed (1) hide show
  1. preprocess_manual.js +43 -126
preprocess_manual.js CHANGED
@@ -525,161 +525,78 @@ function createManualUI(scene, camera, renderer) {
525
 
526
  function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0, y: 0, z: 0 }) {
527
  console.log('[filterSplatsByBox] ===== FILTERING START =====');
528
- console.log('[filterSplatsByBox] Input parameters:');
529
- console.log(' Box Size:', boxSize);
530
- console.log(' Box Position:', boxPosition);
531
- console.log(' Box Rotation (radians):', boxRotation);
532
- console.log(' Box Rotation (degrees):', {
533
- x: (boxRotation.x * 180 / Math.PI).toFixed(1),
534
- y: (boxRotation.y * 180 / Math.PI).toFixed(1),
535
- z: (boxRotation.z * 180 / Math.PI).toFixed(1)
536
- });
537
- console.log(' Total input vertices:', plyData.vertices.length);
538
 
539
  const halfX = boxSize.x / 2;
540
  const halfY = boxSize.y / 2;
541
  const halfZ = boxSize.z / 2;
542
 
543
- // ⭐ 浮動小数点誤差のための許容値
544
- const epsilon = 0.0001;
545
-
546
- console.log('[filterSplatsByBox] Box half-extents:', { halfX, halfY, halfZ });
547
- console.log('[filterSplatsByBox] Using epsilon:', epsilon);
548
-
549
- // Create rotation matrix
550
  const rotationMatrix = new THREE.Matrix4();
551
  rotationMatrix.makeRotationFromEuler(new THREE.Euler(boxRotation.x, boxRotation.y, boxRotation.z));
552
-
553
- // Inverse matrix for transforming points into box space
554
  const inverseRotationMatrix = new THREE.Matrix4().copy(rotationMatrix).invert();
555
 
556
- console.log('[filterSplatsByBox] Rotation matrix created');
 
 
557
 
558
- // デバッグ: 最初の10個の頂点を詳細にログ
559
- console.log('[filterSplatsByBox] Sample vertices (first 10):');
560
- for (let i = 0; i < Math.min(10, plyData.vertices.length); i++) {
561
- const v = plyData.vertices[i];
562
- const localPos = new THREE.Vector3(
563
- v.x - boxPosition.x,
564
- v.y - boxPosition.y,
565
- v.z - boxPosition.z
566
- );
567
- localPos.applyMatrix4(inverseRotationMatrix);
568
-
569
- // ⭐ 修正: epsilonを使った境界判定
570
- const inside = (
571
- localPos.x >= -(halfX + epsilon) && localPos.x <= (halfX + epsilon) &&
572
- localPos.y >= -(halfY + epsilon) && localPos.y <= (halfY + epsilon) &&
573
- localPos.z >= -(halfZ + epsilon) && localPos.z <= (halfZ + epsilon)
574
- );
575
-
576
- console.log(` Vertex ${i}:`, {
577
- world: { x: v.x.toFixed(3), y: v.y.toFixed(3), z: v.z.toFixed(3) },
578
- local: { x: localPos.x.toFixed(3), y: localPos.y.toFixed(3), z: localPos.z.toFixed(3) },
579
- inside: inside,
580
- distances: {
581
- x: `${(localPos.x + halfX).toFixed(3)} / ${(halfX - localPos.x).toFixed(3)}`,
582
- y: `${(localPos.y + halfY).toFixed(3)} / ${(halfY - localPos.y).toFixed(3)}`,
583
- z: `${(localPos.z + halfZ).toFixed(3)} / ${(halfZ - localPos.z).toFixed(3)}`
584
- }
585
- });
586
- }
587
-
588
- // 実際のフィルタリング
589
- const filteredVertices = plyData.vertices.filter((vertex, index) => {
590
  const localPos = new THREE.Vector3(
591
  vertex.x - boxPosition.x,
592
  vertex.y - boxPosition.y,
593
  vertex.z - boxPosition.z
594
  );
595
-
596
  localPos.applyMatrix4(inverseRotationMatrix);
597
 
598
- // ⭐⭐⭐ CRITICAL FIX: epsilon付き境界判定 ⭐⭐⭐
599
  const inside = (
600
- localPos.x >= -(halfX + epsilon) && localPos.x <= (halfX + epsilon) &&
601
- localPos.y >= -(halfY + epsilon) && localPos.y <= (halfY + epsilon) &&
602
- localPos.z >= -(halfZ + epsilon) && localPos.z <= (halfZ + epsilon)
603
  );
604
 
605
- return inside;
606
- });
607
-
608
- // フィルタリング結果の統計
609
- const retentionRate = (filteredVertices.length / plyData.vertices.length * 100).toFixed(1);
610
-
611
- console.log('[filterSplatsByBox] ===== FILTERING COMPLETE =====');
612
- console.log('[filterSplatsByBox] Results:');
613
- console.log(' Filtered:', filteredVertices.length, '/', plyData.vertices.length);
614
- console.log(' Retention rate:', retentionRate, '%');
615
-
616
- // フィルタリング後の範囲を計算
617
- if (filteredVertices.length > 0) {
618
- let minX = Infinity, minY = Infinity, minZ = Infinity;
619
- let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
620
-
621
- filteredVertices.forEach(v => {
622
- minX = Math.min(minX, v.x);
623
- minY = Math.min(minY, v.y);
624
- minZ = Math.min(minZ, v.z);
625
- maxX = Math.max(maxX, v.x);
626
- maxY = Math.max(maxY, v.y);
627
- maxZ = Math.max(maxZ, v.z);
628
- });
629
-
630
- console.log('[filterSplatsByBox] Filtered bounds (world space):');
631
- console.log(' X:', minX.toFixed(3), 'to', maxX.toFixed(3), '(size:', (maxX - minX).toFixed(3), ')');
632
- console.log(' Y:', minY.toFixed(3), 'to', maxY.toFixed(3), '(size:', (maxY - minY).toFixed(3), ')');
633
- console.log(' Z:', minZ.toFixed(3), 'to', maxZ.toFixed(3), '(size:', (maxZ - minZ).toFixed(3), ')');
634
- console.log(' Center:', {
635
- x: ((minX + maxX) / 2).toFixed(3),
636
- y: ((minY + maxY) / 2).toFixed(3),
637
- z: ((minZ + maxZ) / 2).toFixed(3)
638
- });
639
-
640
- // 期待されるBOXの範囲と比較
641
- const expectedMinX = boxPosition.x - halfX;
642
- const expectedMaxX = boxPosition.x + halfX;
643
- const expectedMinY = boxPosition.y - halfY;
644
- const expectedMaxY = boxPosition.y + halfY;
645
- const expectedMinZ = boxPosition.z - halfZ;
646
- const expectedMaxZ = boxPosition.z + halfZ;
647
-
648
- console.log('[filterSplatsByBox] Expected bounds (if rotation = 0):');
649
- console.log(' X:', expectedMinX.toFixed(3), 'to', expectedMaxX.toFixed(3));
650
- console.log(' Y:', expectedMinY.toFixed(3), 'to', expectedMaxY.toFixed(3));
651
- console.log(' Z:', expectedMinZ.toFixed(3), 'to', expectedMaxZ.toFixed(3));
652
-
653
- // ⭐ 誤差チェック
654
- const errorX = Math.max(Math.abs(minX - expectedMinX), Math.abs(maxX - expectedMaxX));
655
- const errorY = Math.max(Math.abs(minY - expectedMinY), Math.abs(maxY - expectedMaxY));
656
- const errorZ = Math.max(Math.abs(minZ - expectedMinZ), Math.abs(maxZ - expectedMaxZ));
657
 
658
- console.log('[filterSplatsByBox] Boundary errors:');
659
- console.log(' X error:', errorX.toFixed(3), 'm');
660
- console.log(' Y error:', errorY.toFixed(3), 'm');
661
- console.log(' Z error:', errorZ.toFixed(3), 'm');
 
662
 
663
- if (errorX > 0.1 || errorY > 0.1 || errorZ > 0.1) {
664
- console.warn('[filterSplatsByBox] ⚠️ Boundary error > 0.1m detected!');
 
 
 
 
 
 
665
  }
666
- }
667
 
668
- // 警告
669
- if (filteredVertices.length < plyData.vertices.length * 0.1) {
670
- console.warn('[filterSplatsByBox] ⚠️ WARNING: Less than 10% of splats kept!');
671
- console.warn('[filterSplatsByBox] Box may be too small or positioned incorrectly');
672
- }
673
 
674
- if (filteredVertices.length === 0) {
675
- console.error('[filterSplatsByBox] ERROR: No vertices passed the filter!');
676
- console.error('[filterSplatsByBox] Check box position and size');
 
 
 
 
677
  }
678
 
679
- return filteredVertices;
 
 
680
  }
681
 
682
-
683
  //////////////////////////////12/15 17:20 end
684
 
685
 
 
525
 
526
  function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0, y: 0, z: 0 }) {
527
  console.log('[filterSplatsByBox] ===== FILTERING START =====');
528
+
529
+ // ⭐⭐⭐ 追加: すべての頂点の詳細を出力 ⭐⭐⭐
530
+ console.log('[DEBUG] ALL VERTICES ANALYSIS:');
 
 
 
 
 
 
 
531
 
532
  const halfX = boxSize.x / 2;
533
  const halfY = boxSize.y / 2;
534
  const halfZ = boxSize.z / 2;
535
 
 
 
 
 
 
 
 
536
  const rotationMatrix = new THREE.Matrix4();
537
  rotationMatrix.makeRotationFromEuler(new THREE.Euler(boxRotation.x, boxRotation.y, boxRotation.z));
 
 
538
  const inverseRotationMatrix = new THREE.Matrix4().copy(rotationMatrix).invert();
539
 
540
+ let insideCount = 0;
541
+ let outsideCount = 0;
542
+ let boundaryVertices = []; // 境界付近の頂点
543
 
544
+ plyData.vertices.forEach((vertex, index) => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
545
  const localPos = new THREE.Vector3(
546
  vertex.x - boxPosition.x,
547
  vertex.y - boxPosition.y,
548
  vertex.z - boxPosition.z
549
  );
 
550
  localPos.applyMatrix4(inverseRotationMatrix);
551
 
 
552
  const inside = (
553
+ localPos.x >= -(halfX + 0.0001) && localPos.x <= (halfX + 0.0001) &&
554
+ localPos.y >= -(halfY + 0.0001) && localPos.y <= (halfY + 0.0001) &&
555
+ localPos.z >= -(halfZ + 0.0001) && localPos.z <= (halfZ + 0.0001)
556
  );
557
 
558
+ if (inside) {
559
+ insideCount++;
560
+ } else {
561
+ outsideCount++;
562
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
563
 
564
+ // 境界から0.5m以内の頂点を記録
565
+ const distToEdgeX = Math.min(Math.abs(localPos.x + halfX), Math.abs(localPos.x - halfX));
566
+ const distToEdgeY = Math.min(Math.abs(localPos.y + halfY), Math.abs(localPos.y - halfY));
567
+ const distToEdgeZ = Math.min(Math.abs(localPos.z + halfZ), Math.abs(localPos.z - halfZ));
568
+ const minDistToEdge = Math.min(distToEdgeX, distToEdgeY, distToEdgeZ);
569
 
570
+ if (minDistToEdge < 0.5) {
571
+ boundaryVertices.push({
572
+ index,
573
+ world: { x: vertex.x, y: vertex.y, z: vertex.z },
574
+ local: { x: localPos.x, y: localPos.y, z: localPos.z },
575
+ inside,
576
+ distToEdge: minDistToEdge
577
+ });
578
  }
579
+ });
580
 
581
+ console.log('[DEBUG] Summary:');
582
+ console.log(' Inside:', insideCount);
583
+ console.log(' Outside:', outsideCount);
584
+ console.log(' Boundary vertices (within 0.5m):', boundaryVertices.length);
 
585
 
586
+ if (boundaryVertices.length > 0) {
587
+ console.log('[DEBUG] Boundary vertices details:');
588
+ boundaryVertices.slice(0, 20).forEach(v => {
589
+ console.log(` V${v.index}: world(${v.world.x.toFixed(2)}, ${v.world.y.toFixed(2)}, ${v.world.z.toFixed(2)}) ` +
590
+ `→ local(${v.local.x.toFixed(2)}, ${v.local.y.toFixed(2)}, ${v.local.z.toFixed(2)}) ` +
591
+ `→ ${v.inside ? 'IN' : 'OUT'} (dist: ${v.distToEdge.toFixed(3)}m)`);
592
+ });
593
  }
594
 
595
+ // 元のコードを続ける...
596
+ console.log('[filterSplatsByBox] Input parameters:');
597
+ // ...
598
  }
599
 
 
600
  //////////////////////////////12/15 17:20 end
601
 
602