stpete2 commited on
Commit
619ed31
·
verified ·
1 Parent(s): a7ac364

Upload preprocess_manual.js

Browse files
Files changed (1) hide show
  1. preprocess_manual.js +46 -62
preprocess_manual.js CHANGED
@@ -1104,23 +1104,23 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1104
  'Do you want to automatically align the PLY to world axes?\n\n' +
1105
  '(Recommended: Yes)'
1106
  );
1107
-
1108
- if (shouldNormalize) {
1109
- console.log('[preprocessManual] ===== STARTING AUTO-ALIGNMENT =====');
1110
  ///////////////10:32 start
1111
-
 
 
1112
  console.log('[preprocessManual] ===== STARTING AUTO-ALIGNMENT =====');
1113
 
1114
  const { center } = pcaResult;
1115
 
1116
  // ========================================
1117
- // ⭐⭐⭐ 変数を最初に宣言(ifブロックの外側) ⭐⭐⭐
1118
  // ========================================
1119
  let sizeX, sizeY, sizeZ;
1120
  let minX, maxX, minY, maxY, minZ, maxZ;
1121
 
1122
  // ========================================
1123
- // STEP 1: 中心化(1回だけ実行)
1124
  // ========================================
1125
  console.log('[preprocessManual] Step 1: Centering PLY...');
1126
 
@@ -1170,7 +1170,6 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1170
 
1171
  if (Math.abs(avgX) > 0.001 || Math.abs(avgY) > 0.001 || Math.abs(avgZ) > 0.001) {
1172
  console.error('[DEBUG] ❌ ERROR: Centering FAILED!');
1173
- console.error('[DEBUG] Average is not zero:', { avgX, avgY, avgZ });
1174
  } else {
1175
  console.log('[DEBUG] ✓ Centering SUCCESS! Average is ~0');
1176
  }
@@ -1178,7 +1177,7 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1178
  console.log('[preprocessManual] ✓ PLY centered at origin');
1179
 
1180
  // ========================================
1181
- // STEP 2: バウンディングボックスを再計算
1182
  // ========================================
1183
  console.log('[preprocessManual] Step 2: Recalculating bounding box...');
1184
 
@@ -1205,64 +1204,49 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1205
  });
1206
 
1207
  // ========================================
1208
- // STEP 3: Y軸が最長になるように回転(条件付き)
1209
  // ========================================
1210
- if (pcaResult.needsRotation) {
1211
- const shouldNormalize = confirm(
1212
- '⚠️ Warning: This PLY file has a tilted coordinate system.\n\n' +
1213
- 'This may cause the bounding box to appear tilted.\n\n' +
1214
- 'Do you want to automatically align the PLY to world axes?\n\n' +
1215
- '(Recommended: Yes)'
1216
- );
1217
-
1218
- if (shouldNormalize) {
1219
- console.log('[preprocessManual] Step 3: Checking if rotation is needed...');
1220
- console.log('[preprocessManual] Longest axis:',
1221
- sizeX > sizeY && sizeX > sizeZ ? 'X' :
1222
- sizeZ > sizeY ? 'Z' : 'Y');
1223
-
1224
- let rotationNeeded = new THREE.Matrix4();
1225
- let rotationApplied = false;
1226
-
1227
- if (sizeX > sizeY && sizeX > sizeZ) {
1228
- console.log('[preprocessManual] ⚙️ Rotating: X → Y (90° around Z axis)');
1229
- rotationNeeded.makeRotationZ(Math.PI / 2);
1230
- rotationApplied = true;
1231
- } else if (sizeZ > sizeY && sizeZ > sizeX) {
1232
- console.log('[preprocessManual] ⚙️ Rotating: Z → Y (90° around X axis)');
1233
- rotationNeeded.makeRotationX(Math.PI / 2);
1234
- rotationApplied = true;
1235
- } else {
1236
- console.log('[preprocessManual] ✓ Y-axis is already the longest, no rotation needed');
1237
- }
1238
-
1239
- if (rotationApplied) {
1240
- console.log('[preprocessManual] Step 4: Applying rotation to all vertices...');
1241
-
1242
- plyData.vertices.forEach(v => {
1243
- const pos = new THREE.Vector3(v.x, v.y, v.z);
1244
- pos.applyMatrix4(rotationNeeded);
1245
- v.x = pos.x;
1246
- v.y = pos.y;
1247
- v.z = pos.z;
1248
- });
1249
-
1250
- console.log('[preprocessManual] ✓ PLY rotated to align with world axes');
1251
-
1252
- window.plyAlignmentApplied = true;
1253
- window.plyAlignmentMatrix = rotationNeeded.clone();
1254
-
1255
- console.log('[preprocessManual] ✓ Alignment matrix saved for GS display');
1256
- } else {
1257
- console.log('[preprocessManual] Step 4: Skipped (no rotation needed)');
1258
- }
1259
- } else {
1260
- console.log('[preprocessManual] User chose to keep original orientation');
1261
- }
1262
  } else {
1263
- console.log('[preprocessManual] ✓ PLY coordinate system is already aligned');
1264
  }
1265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1266
  //////////////////// 10:32 end
1267
 
1268
  // ========================================
 
1104
  'Do you want to automatically align the PLY to world axes?\n\n' +
1105
  '(Recommended: Yes)'
1106
  );
1107
+
 
 
1108
  ///////////////10:32 start
1109
+
1110
+ if (shouldNormalize) {
1111
+
1112
  console.log('[preprocessManual] ===== STARTING AUTO-ALIGNMENT =====');
1113
 
1114
  const { center } = pcaResult;
1115
 
1116
  // ========================================
1117
+ // 変数を最初に宣言(常に定義される)
1118
  // ========================================
1119
  let sizeX, sizeY, sizeZ;
1120
  let minX, maxX, minY, maxY, minZ, maxZ;
1121
 
1122
  // ========================================
1123
+ // STEP 1: 中心化(常に実行)
1124
  // ========================================
1125
  console.log('[preprocessManual] Step 1: Centering PLY...');
1126
 
 
1170
 
1171
  if (Math.abs(avgX) > 0.001 || Math.abs(avgY) > 0.001 || Math.abs(avgZ) > 0.001) {
1172
  console.error('[DEBUG] ❌ ERROR: Centering FAILED!');
 
1173
  } else {
1174
  console.log('[DEBUG] ✓ Centering SUCCESS! Average is ~0');
1175
  }
 
1177
  console.log('[preprocessManual] ✓ PLY centered at origin');
1178
 
1179
  // ========================================
1180
+ // STEP 2: バウンディングボックスを再計算(常に実行)
1181
  // ========================================
1182
  console.log('[preprocessManual] Step 2: Recalculating bounding box...');
1183
 
 
1204
  });
1205
 
1206
  // ========================================
1207
+ // STEP 3 & 4: 回転処理(条件付き)
1208
  // ========================================
1209
+ console.log('[preprocessManual] Step 3: Checking if rotation is needed...');
1210
+ console.log('[preprocessManual] Longest axis:',
1211
+ sizeX > sizeY && sizeX > sizeZ ? 'X' :
1212
+ sizeZ > sizeY ? 'Z' : 'Y');
1213
+
1214
+ let rotationNeeded = new THREE.Matrix4();
1215
+ let rotationApplied = false;
1216
+
1217
+ if (sizeX > sizeY && sizeX > sizeZ) {
1218
+ console.log('[preprocessManual] ⚙️ Rotating: X Y (90° around Z axis)');
1219
+ rotationNeeded.makeRotationZ(Math.PI / 2);
1220
+ rotationApplied = true;
1221
+ } else if (sizeZ > sizeY && sizeZ > sizeX) {
1222
+ console.log('[preprocessManual] ⚙️ Rotating: Z → Y (90° around X axis)');
1223
+ rotationNeeded.makeRotationX(Math.PI / 2);
1224
+ rotationApplied = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1225
  } else {
1226
+ console.log('[preprocessManual] ✓ Y-axis is already the longest, no rotation needed');
1227
  }
1228
 
1229
+ if (rotationApplied) {
1230
+ console.log('[preprocessManual] Step 4: Applying rotation to all vertices...');
1231
+
1232
+ plyData.vertices.forEach(v => {
1233
+ const pos = new THREE.Vector3(v.x, v.y, v.z);
1234
+ pos.applyMatrix4(rotationNeeded);
1235
+ v.x = pos.x;
1236
+ v.y = pos.y;
1237
+ v.z = pos.z;
1238
+ });
1239
+
1240
+ console.log('[preprocessManual] ✓ PLY rotated to align with world axes');
1241
+
1242
+ window.plyAlignmentApplied = true;
1243
+ window.plyAlignmentMatrix = rotationNeeded.clone();
1244
+
1245
+ console.log('[preprocessManual] ✓ Alignment matrix saved for GS display');
1246
+ } else {
1247
+ console.log('[preprocessManual] Step 4: Skipped (no rotation needed)');
1248
+ }
1249
+
1250
  //////////////////// 10:32 end
1251
 
1252
  // ========================================