stpete2 commited on
Commit
8a56d8e
·
verified ·
1 Parent(s): 60b8edc

Upload preprocess_manual.js

Browse files
Files changed (1) hide show
  1. preprocess_manual.js +102 -0
preprocess_manual.js CHANGED
@@ -1123,6 +1123,79 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1123
 
1124
  console.log('[preprocessManual] ✓ PLY centered at origin');
1125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1126
  // 注: 完全な整列には固有値分解が必要
1127
  // ここでは中心化のみ実施
1128
  } else {
@@ -1625,6 +1698,35 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1625
 
1626
  // ⭐ 外側の変数も更新(念のため)
1627
  plyOffset = { x: 0, y: 0, z: 0 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1628
  } else {
1629
  console.log('[STEP 3] No PLY offset to apply');
1630
  }
 
1123
 
1124
  console.log('[preprocessManual] ✓ PLY centered at origin');
1125
 
1126
+ ////////////////// add 12/16 18:30
1127
+
1128
+ // ========================================
1129
+ // ⭐ 完全な座標系正規化
1130
+ // Line 1124 の後に追加
1131
+ // ========================================
1132
+
1133
+ if (shouldNormalize) {
1134
+ console.log('[preprocessManual] Auto-aligning PLY to world axes...');
1135
+
1136
+ const { center, covarianceMatrix } = pcaResult;
1137
+
1138
+ // 1. 中心化
1139
+ plyData.vertices.forEach(v => {
1140
+ v.x -= center.x;
1141
+ v.y -= center.y;
1142
+ v.z -= center.z;
1143
+ });
1144
+
1145
+ console.log('[preprocessManual] ✓ PLY centered at origin');
1146
+
1147
+ // 2. バウンディングボックスの主軸を取得
1148
+ let minX = Infinity, minY = Infinity, minZ = Infinity;
1149
+ let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
1150
+
1151
+ plyData.vertices.forEach(v => {
1152
+ minX = Math.min(minX, v.x);
1153
+ minY = Math.min(minY, v.y);
1154
+ minZ = Math.min(minZ, v.z);
1155
+ maxX = Math.max(maxX, v.x);
1156
+ maxY = Math.max(maxY, v.y);
1157
+ maxZ = Math.max(maxZ, v.z);
1158
+ });
1159
+
1160
+ // 3. Y軸が最も長い軸になるように回転(人体の場合)
1161
+ const sizeX = maxX - minX;
1162
+ const sizeY = maxY - minY;
1163
+ const sizeZ = maxZ - minZ;
1164
+
1165
+ console.log('[preprocessManual] Original sizes:', { sizeX, sizeY, sizeZ });
1166
+
1167
+ let rotationNeeded = new THREE.Matrix4();
1168
+
1169
+ if (sizeX > sizeY && sizeX > sizeZ) {
1170
+ // X軸が最長 → Y軸に回転
1171
+ rotationNeeded.makeRotationZ(Math.PI / 2);
1172
+ console.log('[preprocessManual] Rotating X→Y (90° around Z)');
1173
+ } else if (sizeZ > sizeY) {
1174
+ // Z軸が最長 → Y軸に回転
1175
+ rotationNeeded.makeRotationX(Math.PI / 2);
1176
+ console.log('[preprocessManual] Rotating Z→Y (90° around X)');
1177
+ }
1178
+
1179
+ // 4. 回転を適用
1180
+ if (!rotationNeeded.equals(new THREE.Matrix4())) {
1181
+ plyData.vertices.forEach(v => {
1182
+ const pos = new THREE.Vector3(v.x, v.y, v.z);
1183
+ pos.applyMatrix4(rotationNeeded);
1184
+ v.x = pos.x;
1185
+ v.y = pos.y;
1186
+ v.z = pos.z;
1187
+ });
1188
+
1189
+ console.log('[preprocessManual] ✓ PLY rotated to align with world axes');
1190
+
1191
+ // ⭐ 重要: GSにも同じ変換を適用するためフラグを立てる
1192
+ window.plyAlignmentApplied = true;
1193
+ window.plyAlignmentMatrix = rotationNeeded;
1194
+ }
1195
+ }
1196
+
1197
+ ///////////////// add end
1198
+
1199
  // 注: 完全な整列には固有値分解が必要
1200
  // ここでは中心化のみ実施
1201
  } else {
 
1698
 
1699
  // ⭐ 外側の変数も更新(念のため)
1700
  plyOffset = { x: 0, y: 0, z: 0 };
1701
+
1702
+
1703
+ // confirm-box-btn のイベントリスナー内に追加
1704
+
1705
+ // フィルタリング後、結果を視覚化
1706
+ if (filteredVertices.length > 0) {
1707
+ // 色を変えて表示
1708
+ filteredIndices.forEach(idx => {
1709
+ filteredGs.colors[idx * 4 + 0] = 0;
1710
+ filteredGs.colors[idx * 4 + 1] = 255;
1711
+ filteredGs.colors[idx * 4 + 2] = 0;
1712
+ });
1713
+
1714
+ filteredGs.splatMesh.updateDataTexturesFromBaseData(0, filteredGs.splatCount - 1);
1715
+
1716
+ const confirmResult = confirm(
1717
+ `Filtered ${filteredVertices.length} splats (shown in green).\n\n` +
1718
+ `Does the green area match the box?\n\n` +
1719
+ `OK = Continue | Cancel = Adjust box again`
1720
+ );
1721
+
1722
+ if (!confirmResult) {
1723
+ // Box設定に戻る
1724
+ ui.showPositionAdjustment();
1725
+ return;
1726
+ }
1727
+ }
1728
+
1729
+
1730
  } else {
1731
  console.log('[STEP 3] No PLY offset to apply');
1732
  }