stpete2 commited on
Commit
595bb43
·
verified ·
1 Parent(s): 4d1750e

Upload preprocess_manual.js

Browse files
Files changed (1) hide show
  1. preprocess_manual.js +108 -130
preprocess_manual.js CHANGED
@@ -1647,31 +1647,57 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1647
  console.log(' boxRotation:', boxRotation);
1648
  console.log(' plyOffset:', plyOffset);
1649
 
1650
- // 元のPLYデータの範囲を表示
1651
- console.log('[STEP 2] Original PLY Data:');
 
1652
  console.log(' Total vertices:', plyData.vertices.length);
1653
-
1654
- let origMinX = Infinity, origMinY = Infinity, origMinZ = Infinity;
1655
- let origMaxX = -Infinity, origMaxY = -Infinity, origMaxZ = -Infinity;
1656
-
1657
  plyData.vertices.forEach(v => {
1658
- origMinX = Math.min(origMinX, v.x);
1659
- origMinY = Math.min(origMinY, v.y);
1660
- origMinZ = Math.min(origMinZ, v.z);
1661
- origMaxX = Math.max(origMaxX, v.x);
1662
- origMaxY = Math.max(origMaxY, v.y);
1663
- origMaxZ = Math.max(origMaxZ, v.z);
1664
  });
1665
-
1666
- console.log(' Original bounds:');
1667
- console.log(' X:', origMinX.toFixed(3), 'to', origMaxX.toFixed(3));
1668
- console.log(' Y:', origMinY.toFixed(3), 'to', origMaxY.toFixed(3));
1669
- console.log(' Z:', origMinZ.toFixed(3), 'to', origMaxZ.toFixed(3));
1670
- console.log(' Original center:', {
1671
- x: ((origMinX + origMaxX) / 2).toFixed(3),
1672
- y: ((origMinY + origMaxY) / 2).toFixed(3),
1673
- z: ((origMinZ + origMaxZ) / 2).toFixed(3)
 
 
 
 
 
 
 
1674
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1675
 
1676
  cleanupAnimation();
1677
 
@@ -1735,130 +1761,82 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1735
  ui.setStatus('Filtering splats with bounding box...');
1736
 
1737
 
1738
- ///////////////////////////////13:47
1739
 
1740
- // ⭐⭐⭐ 重要: gs.centers0 を使用してフィルタリング ⭐⭐⭐
1741
- // plyData.vertices ではなく、実際に表示されている座標を使う
1742
 
1743
- console.log('[STEP 4] Using gs.centers0 (displayed coordinates) for filtering');
 
 
1744
 
1745
- // gs.centers0 から vertices 配列を作成
1746
- const displayedVertices = [];
1747
- for (let i = 0; i < gs.splatCount; i++) {
1748
- displayedVertices.push({
1749
- x: gs.centers0[i * 3 + 0],
1750
- y: gs.centers0[i * 3 + 1],
1751
- z: gs.centers0[i * 3 + 2],
1752
- // 元のインデックスを保持(後で元のデータを参照するため)
1753
- originalIndex: i
1754
- });
1755
- }
1756
-
1757
- console.log('[STEP 4] Created displayedVertices array:', displayedVertices.length, 'vertices');
1758
-
1759
- // ⭐ GS Scene の変換を考慮
1760
- const gsScene = gs.viewer.splatMesh.scenes[0];
1761
- gsScene.updateMatrixWorld(true);
1762
-
1763
- console.log('[STEP 4] GS Scene transform:');
1764
- console.log(' Position:', gsScene.position);
1765
- console.log(' Rotation:', gsScene.rotation);
1766
- console.log(' Scale:', gsScene.scale);
1767
-
1768
- // ワールド座標に変換されたBox設定を使用
1769
- const boxWorldPosition = new THREE.Vector3(
1770
- currentBoxPosition.x,
1771
- currentBoxPosition.y,
1772
- currentBoxPosition.z
1773
- );
1774
-
1775
- // GS Scene の逆変換を適用(BoxをGSのローカル空間に変換)
1776
- const gsInverseMatrix = new THREE.Matrix4().copy(gsScene.matrixWorld).invert();
1777
- boxWorldPosition.applyMatrix4(gsInverseMatrix);
1778
 
1779
- console.log('[STEP 4] Box position in GS local space:', {
1780
- x: boxWorldPosition.x.toFixed(3),
1781
- y: boxWorldPosition.y.toFixed(3),
1782
- z: boxWorldPosition.z.toFixed(3)
1783
- });
1784
 
1785
- // ⭐⭐⭐ 修正版フィルタリング関数を呼び出し ⭐⭐⭐
1786
- function filterDisplayedSplats(vertices, boxSize, boxPosition, boxRotation) {
1787
- console.log('[filterDisplayedSplats] Filtering', vertices.length, 'vertices');
1788
- console.log('[filterDisplayedSplats] Box settings:', {
1789
- size: boxSize,
1790
- position: boxPosition,
1791
- rotation: {
1792
- x: (boxRotation.x * 180 / Math.PI).toFixed(1) + '°',
1793
- y: (boxRotation.y * 180 / Math.PI).toFixed(1) + '°',
1794
- z: (boxRotation.z * 180 / Math.PI).toFixed(1) + '°'
1795
- }
1796
- });
1797
-
1798
- const halfX = boxSize.x / 2;
1799
- const halfY = boxSize.y / 2;
1800
- const halfZ = boxSize.z / 2;
1801
- const epsilon = 0.01;
1802
-
1803
- // 回転行列
1804
- const rotationMatrix = new THREE.Matrix4();
1805
- rotationMatrix.makeRotationFromEuler(new THREE.Euler(boxRotation.x, boxRotation.y, boxRotation.z));
1806
- const inverseRotationMatrix = new THREE.Matrix4().copy(rotationMatrix).invert();
1807
-
1808
- // フィルタリング
1809
- const filtered = vertices.filter((vertex) => {
1810
- const localPos = new THREE.Vector3(
1811
- vertex.x - boxPosition.x,
1812
- vertex.y - boxPosition.y,
1813
- vertex.z - boxPosition.z
1814
- );
1815
-
1816
- localPos.applyMatrix4(inverseRotationMatrix);
1817
-
1818
- const inside = (
1819
- localPos.x >= -(halfX + epsilon) && localPos.x <= (halfX + epsilon) &&
1820
- localPos.y >= -(halfY + epsilon) && localPos.y <= (halfY + epsilon) &&
1821
- localPos.z >= -(halfZ + epsilon) && localPos.z <= (halfZ + epsilon)
1822
- );
1823
-
1824
- return inside;
1825
- });
1826
-
1827
- console.log('[filterDisplayedSplats] Filtered:', filtered.length, '/', vertices.length);
1828
- console.log('[filterDisplayedSplats] Retention rate:', (filtered.length / vertices.length * 100).toFixed(1), '%');
1829
-
1830
- return filtered;
1831
- }
1832
 
1833
- // GS local space でフィルタリング
1834
- const filteredDisplayed = filterDisplayedSplats(
1835
- displayedVertices,
1836
- currentBoxSize,
1837
- boxWorldPosition, // ← GS local space に変換済み
1838
- currentBoxRotation
1839
- );
1840
 
1841
- if (filteredDisplayed.length === 0) {
1842
- console.error('[STEP 4] No splats found in the box!');
1843
- alert('⚠️ No splats found in the box!\n\nPlease adjust the box size/position and try again.');
1844
- ui.showPositionAdjustment();
1845
- return;
1846
- }
1847
 
1848
- console.log('[STEP 4] Filtering complete:', filteredDisplayed.length, 'splats kept');
 
 
 
 
1849
 
 
1850
 
1851
- /////////////////////////////////////13:47
 
 
 
 
 
 
 
 
 
 
1852
 
1853
- // ⭐⭐⭐ 修正: currentBoxSize, currentBoxPosition, currentBoxRotation を使用 ⭐⭐⭐
1854
- console.log('[STEP 4] ⭐ Calling filterSplatsByBox with CURRENT values from UI');
1855
  const filteredVertices = filterSplatsByBox(
1856
  plyData,
1857
- currentBoxSize, // ← UI から取得した値
1858
- currentBoxPosition, // ← UI から取得した値
1859
- currentBoxRotation // ← UI から取得した値
 
 
 
 
 
 
 
 
1860
  );
1861
 
 
 
1862
  if (filteredVertices.length === 0) {
1863
  console.error('[STEP 4] ❌ No splats found in the box!');
1864
  alert('⚠️ No splats found in the box!\n\nPlease adjust the box size/position and try again.\n\nCheck the browser console for detailed debug information.');
 
1647
  console.log(' boxRotation:', boxRotation);
1648
  console.log(' plyOffset:', plyOffset);
1649
 
1650
+ ////////////////////////////////////////////////////0123 start
1651
+ // 修正: 中心化後のPLYデータの範囲を確認
1652
+ console.log('[STEP 2] Centered PLY Data (should be ~0,0,0):');
1653
  console.log(' Total vertices:', plyData.vertices.length);
1654
+
1655
+ let centeredMinX = Infinity, centeredMinY = Infinity, centeredMinZ = Infinity;
1656
+ let centeredMaxX = -Infinity, centeredMaxY = -Infinity, centeredMaxZ = -Infinity;
1657
+
1658
  plyData.vertices.forEach(v => {
1659
+ centeredMinX = Math.min(centeredMinX, v.x);
1660
+ centeredMinY = Math.min(centeredMinY, v.y);
1661
+ centeredMinZ = Math.min(centeredMinZ, v.z);
1662
+ centeredMaxX = Math.max(centeredMaxX, v.x);
1663
+ centeredMaxY = Math.max(centeredMaxY, v.y);
1664
+ centeredMaxZ = Math.max(centeredMaxZ, v.z);
1665
  });
1666
+
1667
+ console.log(' Centered bounds:');
1668
+ console.log(' X:', centeredMinX.toFixed(3), 'to', centeredMaxX.toFixed(3));
1669
+ console.log(' Y:', centeredMinY.toFixed(3), 'to', centeredMaxY.toFixed(3));
1670
+ console.log(' Z:', centeredMinZ.toFixed(3), 'to', centeredMaxZ.toFixed(3));
1671
+
1672
+ const centeredCenter = {
1673
+ x: (centeredMinX + centeredMaxX) / 2,
1674
+ y: (centeredMinY + centeredMaxY) / 2,
1675
+ z: (centeredMinZ + centeredMaxZ) / 2
1676
+ };
1677
+
1678
+ console.log(' Centered center:', {
1679
+ x: centeredCenter.x.toFixed(3),
1680
+ y: centeredCenter.y.toFixed(3),
1681
+ z: centeredCenter.z.toFixed(3)
1682
  });
1683
+
1684
+ // ⭐ 検証: 中心が 0,0,0 から離れすぎている場合は警告
1685
+ if (Math.abs(centeredCenter.x) > 0.1 ||
1686
+ Math.abs(centeredCenter.y) > 0.1 ||
1687
+ Math.abs(centeredCenter.z) > 0.1) {
1688
+ console.error('[STEP 2] ❌ ERROR: PLY is NOT properly centered!');
1689
+ console.error('[STEP 2] Expected ~(0,0,0) but got:', centeredCenter);
1690
+ console.error('[STEP 2] This will cause Box filtering to fail!');
1691
+
1692
+ // ⭐ 緊急修正: もう一度中心化
1693
+ console.log('[STEP 2] Emergency re-centering...');
1694
+ plyData.vertices.forEach(v => {
1695
+ v.x -= centeredCenter.x;
1696
+ v.y -= centeredCenter.y;
1697
+ v.z -= centeredCenter.z;
1698
+ });
1699
+ console.log('[STEP 2] ✓ PLY force-centered to origin');
1700
+ }
1701
 
1702
  cleanupAnimation();
1703
 
 
1761
  ui.setStatus('Filtering splats with bounding box...');
1762
 
1763
 
1764
+ ///////////////////////////////////////13:47 start
1765
 
1766
+ console.log('[STEP 4] Transforming Box coordinates to GS local space');
 
1767
 
1768
+ // GS Scene の変換行列を取得
1769
+ const gsScene = gs.viewer.splatMesh.scenes[0];
1770
+ gsScene.updateMatrixWorld(true);
1771
 
1772
+ // Box Position を Three.js Vector3 に変換
1773
+ const boxWorldPosition = new THREE.Vector3(
1774
+ currentBoxPosition.x,
1775
+ currentBoxPosition.y,
1776
+ currentBoxPosition.z
1777
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1778
 
1779
+ // GS の逆行列を適用してローカル空間に変換
1780
+ const gsInverseMatrix = new THREE.Matrix4().copy(gsScene.matrixWorld).invert();
1781
+ const boxLocalPosition = boxWorldPosition.applyMatrix4(gsInverseMatrix);
 
 
1782
 
1783
+ console.log('[STEP 4] Box position transformation:');
1784
+ console.log(' World space:', currentBoxPosition);
1785
+ console.log(' GS local space:', {
1786
+ x: boxLocalPosition.x.toFixed(3),
1787
+ y: boxLocalPosition.y.toFixed(3),
1788
+ z: boxLocalPosition.z.toFixed(3)
1789
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1790
 
1791
+ // Box Rotation も変換
1792
+ const boxRotationEuler = new THREE.Euler(
1793
+ currentBoxRotation.x,
1794
+ currentBoxRotation.y,
1795
+ currentBoxRotation.z
1796
+ );
1797
+ const boxRotationMatrix = new THREE.Matrix4().makeRotationFromEuler(boxRotationEuler);
1798
 
1799
+ // GS の回転を抽出
1800
+ const gsRotationMatrix = new THREE.Matrix4().extractRotation(gsScene.matrixWorld);
 
 
 
 
1801
 
1802
+ // 合成: GS^-1 * Box
1803
+ const combinedRotationMatrix = new THREE.Matrix4()
1804
+ .copy(gsRotationMatrix)
1805
+ .invert()
1806
+ .multiply(boxRotationMatrix);
1807
 
1808
+ const combinedRotationEuler = new THREE.Euler().setFromRotationMatrix(combinedRotationMatrix);
1809
 
1810
+ console.log('[STEP 4] Box rotation transformation:');
1811
+ console.log(' World space (deg):', {
1812
+ x: (currentBoxRotation.x * 180 / Math.PI).toFixed(1) + '°',
1813
+ y: (currentBoxRotation.y * 180 / Math.PI).toFixed(1) + '°',
1814
+ z: (currentBoxRotation.z * 180 / Math.PI).toFixed(1) + '°'
1815
+ });
1816
+ console.log(' GS local space (deg):', {
1817
+ x: (combinedRotationEuler.x * 180 / Math.PI).toFixed(1) + '°',
1818
+ y: (combinedRotationEuler.y * 180 / Math.PI).toFixed(1) + '°',
1819
+ z: (combinedRotationEuler.z * 180 / Math.PI).toFixed(1) + '°'
1820
+ });
1821
 
1822
+ // ⭐⭐⭐ 変換後の座標で filterSplatsByBox を呼ぶ
 
1823
  const filteredVertices = filterSplatsByBox(
1824
  plyData,
1825
+ currentBoxSize,
1826
+ {
1827
+ x: boxLocalPosition.x,
1828
+ y: boxLocalPosition.y,
1829
+ z: boxLocalPosition.z
1830
+ },
1831
+ {
1832
+ x: combinedRotationEuler.x,
1833
+ y: combinedRotationEuler.y,
1834
+ z: combinedRotationEuler.z
1835
+ }
1836
  );
1837
 
1838
+ /////////////////////////////////////13:47 end
1839
+
1840
  if (filteredVertices.length === 0) {
1841
  console.error('[STEP 4] ❌ No splats found in the box!');
1842
  alert('⚠️ No splats found in the box!\n\nPlease adjust the box size/position and try again.\n\nCheck the browser console for detailed debug information.');