stpete2 commited on
Commit
1bdc3d6
·
verified ·
1 Parent(s): d97dda3

Upload preprocess_manual.js

Browse files
Files changed (1) hide show
  1. preprocess_manual.js +147 -4
preprocess_manual.js CHANGED
@@ -526,7 +526,7 @@ function createManualUI(scene, camera, renderer) {
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;
@@ -539,7 +539,7 @@ function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0,
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(
@@ -592,9 +592,152 @@ function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0,
592
  });
593
  }
594
 
595
- // 元のコードを続ける...
596
  console.log('[filterSplatsByBox] Input parameters:');
597
- // ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
598
  }
599
 
600
  //////////////////////////////12/15 17:20 end
 
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;
 
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(
 
592
  });
593
  }
594
 
595
+ // ⭐⭐⭐ ここから元のコードを続ける ⭐⭐⭐
596
  console.log('[filterSplatsByBox] Input parameters:');
597
+ console.log(' Box Size:', boxSize);
598
+ console.log(' Box Position:', boxPosition);
599
+ console.log(' Box Rotation (radians):', boxRotation);
600
+ console.log(' Box Rotation (degrees):', {
601
+ x: (boxRotation.x * 180 / Math.PI).toFixed(1),
602
+ y: (boxRotation.y * 180 / Math.PI).toFixed(1),
603
+ z: (boxRotation.z * 180 / Math.PI).toFixed(1)
604
+ });
605
+ console.log(' Total input vertices:', plyData.vertices.length);
606
+
607
+ console.log('[filterSplatsByBox] Box half-extents:', { halfX, halfY, halfZ });
608
+ console.log('[filterSplatsByBox] Using epsilon: 0.0001');
609
+
610
+ console.log('[filterSplatsByBox] Rotation matrix created');
611
+
612
+ // Sample vertices (最初の10個)
613
+ console.log('[filterSplatsByBox] Sample vertices (first 10):');
614
+ for (let i = 0; i < Math.min(10, plyData.vertices.length); i++) {
615
+ const v = plyData.vertices[i];
616
+ const localPos = new THREE.Vector3(
617
+ v.x - boxPosition.x,
618
+ v.y - boxPosition.y,
619
+ v.z - boxPosition.z
620
+ );
621
+ localPos.applyMatrix4(inverseRotationMatrix);
622
+
623
+ const inside = (
624
+ localPos.x >= -(halfX + 0.0001) && localPos.x <= (halfX + 0.0001) &&
625
+ localPos.y >= -(halfY + 0.0001) && localPos.y <= (halfY + 0.0001) &&
626
+ localPos.z >= -(halfZ + 0.0001) && localPos.z <= (halfZ + 0.0001)
627
+ );
628
+
629
+ console.log(` Vertex ${i}:`, {
630
+ world: { x: v.x.toFixed(3), y: v.y.toFixed(3), z: v.z.toFixed(3) },
631
+ local: { x: localPos.x.toFixed(3), y: localPos.y.toFixed(3), z: localPos.z.toFixed(3) },
632
+ inside: inside,
633
+ distances: {
634
+ x: `${(localPos.x + halfX).toFixed(3)} / ${(halfX - localPos.x).toFixed(3)}`,
635
+ y: `${(localPos.y + halfY).toFixed(3)} / ${(halfY - localPos.y).toFixed(3)}`,
636
+ z: `${(localPos.z + halfZ).toFixed(3)} / ${(halfZ - localPos.z).toFixed(3)}`
637
+ }
638
+ });
639
+ }
640
+
641
+ // ⭐⭐⭐ 実際のフィルタリング ⭐⭐⭐
642
+ const filteredVertices = plyData.vertices.filter((vertex, index) => {
643
+ const localPos = new THREE.Vector3(
644
+ vertex.x - boxPosition.x,
645
+ vertex.y - boxPosition.y,
646
+ vertex.z - boxPosition.z
647
+ );
648
+
649
+ localPos.applyMatrix4(inverseRotationMatrix);
650
+
651
+ const inside = (
652
+ localPos.x >= -(halfX + 0.0001) && localPos.x <= (halfX + 0.0001) &&
653
+ localPos.y >= -(halfY + 0.0001) && localPos.y <= (halfY + 0.0001) &&
654
+ localPos.z >= -(halfZ + 0.0001) && localPos.z <= (halfZ + 0.0001)
655
+ );
656
+
657
+ return inside;
658
+ });
659
+
660
+ // フィルタリング結果の統計
661
+ const retentionRate = (filteredVertices.length / plyData.vertices.length * 100).toFixed(1);
662
+
663
+ console.log('[filterSplatsByBox] ===== FILTERING COMPLETE =====');
664
+ console.log('[filterSplatsByBox] Results:');
665
+ console.log(' Filtered:', filteredVertices.length, '/', plyData.vertices.length);
666
+ console.log(' Retention rate:', retentionRate, '%');
667
+
668
+ // フィルタリング後の範囲を計算
669
+ if (filteredVertices.length > 0) {
670
+ let minX = Infinity, minY = Infinity, minZ = Infinity;
671
+ let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
672
+
673
+ filteredVertices.forEach(v => {
674
+ minX = Math.min(minX, v.x);
675
+ minY = Math.min(minY, v.y);
676
+ minZ = Math.min(minZ, v.z);
677
+ maxX = Math.max(maxX, v.x);
678
+ maxY = Math.max(maxY, v.y);
679
+ maxZ = Math.max(maxZ, v.z);
680
+ });
681
+
682
+ console.log('[filterSplatsByBox] Filtered bounds (world space):');
683
+ console.log(' X:', minX.toFixed(3), 'to', maxX.toFixed(3), '(size:', (maxX - minX).toFixed(3), ')');
684
+ console.log(' Y:', minY.toFixed(3), 'to', maxY.toFixed(3), '(size:', (maxY - minY).toFixed(3), ')');
685
+ console.log(' Z:', minZ.toFixed(3), 'to', maxZ.toFixed(3), '(size:', (maxZ - minZ).toFixed(3), ')');
686
+ console.log(' Center:', {
687
+ x: ((minX + maxX) / 2).toFixed(3),
688
+ y: ((minY + maxY) / 2).toFixed(3),
689
+ z: ((minZ + maxZ) / 2).toFixed(3)
690
+ });
691
+
692
+ // 回転がない場合のみ期待値を計算
693
+ const hasRotation = Math.abs(boxRotation.x) > 0.01 ||
694
+ Math.abs(boxRotation.y) > 0.01 ||
695
+ Math.abs(boxRotation.z) > 0.01;
696
+
697
+ if (!hasRotation) {
698
+ const expectedMinX = boxPosition.x - halfX;
699
+ const expectedMaxX = boxPosition.x + halfX;
700
+ const expectedMinY = boxPosition.y - halfY;
701
+ const expectedMaxY = boxPosition.y + halfY;
702
+ const expectedMinZ = boxPosition.z - halfZ;
703
+ const expectedMaxZ = boxPosition.z + halfZ;
704
+
705
+ console.log('[filterSplatsByBox] Expected bounds (no rotation):');
706
+ console.log(' X:', expectedMinX.toFixed(3), 'to', expectedMaxX.toFixed(3));
707
+ console.log(' Y:', expectedMinY.toFixed(3), 'to', expectedMaxY.toFixed(3));
708
+ console.log(' Z:', expectedMinZ.toFixed(3), 'to', expectedMaxZ.toFixed(3));
709
+
710
+ const errorX = Math.max(Math.abs(minX - expectedMinX), Math.abs(maxX - expectedMaxX));
711
+ const errorY = Math.max(Math.abs(minY - expectedMinY), Math.abs(maxY - expectedMaxY));
712
+ const errorZ = Math.max(Math.abs(minZ - expectedMinZ), Math.abs(maxZ - expectedMaxZ));
713
+
714
+ console.log('[filterSplatsByBox] Boundary errors:');
715
+ console.log(' X error:', errorX.toFixed(3), 'm');
716
+ console.log(' Y error:', errorY.toFixed(3), 'm');
717
+ console.log(' Z error:', errorZ.toFixed(3), 'm');
718
+
719
+ if (errorX > 0.1 || errorY > 0.1 || errorZ > 0.1) {
720
+ console.warn('[filterSplatsByBox] ⚠️ Boundary error > 0.1m detected!');
721
+ }
722
+ } else {
723
+ console.log('[filterSplatsByBox] ℹ️ Box is rotated - Expected bounds check skipped');
724
+ console.log('[filterSplatsByBox] Filtered bounds above show actual world-space result');
725
+ }
726
+ }
727
+
728
+ // 警告
729
+ if (filteredVertices.length < plyData.vertices.length * 0.1) {
730
+ console.warn('[filterSplatsByBox] ⚠️ WARNING: Less than 10% of splats kept!');
731
+ console.warn('[filterSplatsByBox] Box may be too small or positioned incorrectly');
732
+ }
733
+
734
+ if (filteredVertices.length === 0) {
735
+ console.error('[filterSplatsByBox] ❌ ERROR: No vertices passed the filter!');
736
+ console.error('[filterSplatsByBox] Check box position and size');
737
+ }
738
+
739
+ // ⭐⭐⭐ 必須: 結果を返す ⭐⭐⭐
740
+ return filteredVertices;
741
  }
742
 
743
  //////////////////////////////12/15 17:20 end