stpete2 commited on
Commit
703f6e6
·
verified ·
1 Parent(s): a703eac

Upload preprocess_manual.js

Browse files
Files changed (1) hide show
  1. preprocess_manual.js +57 -121
preprocess_manual.js CHANGED
@@ -1090,46 +1090,30 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1090
  // 2. 点群を分析
1091
  const pcaResult = computePCA(plyData.vertices);
1092
 
1093
- //////////////////////1095-1210 start
 
1094
 
1095
  // 3. 回転が必要な場合、ユーザーに通知
1096
  if (pcaResult.needsRotation) {
1097
  console.warn('[preprocessManual] ⚠️ PLY coordinate system is NOT aligned with world axes');
1098
  console.warn('[preprocessManual] This may cause visual mismatch between Box and filtering');
1099
 
1100
- // ⭐ 自動的に座標系を正規化
1101
- const shouldNormalize = confirm(
1102
- '⚠️ Warning: This PLY file has a tilted coordinate system.\n\n' +
1103
- 'This may cause the bounding box to appear tilted.\n\n' +
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
-
1127
  console.log('[DEBUG] First vertex BEFORE:', {
1128
  x: plyData.vertices[0].x.toFixed(3),
1129
  y: plyData.vertices[0].y.toFixed(3),
1130
  z: plyData.vertices[0].z.toFixed(3)
1131
  });
1132
-
1133
  plyData.vertices = plyData.vertices.map(v => {
1134
  const centered = {
1135
  x: v.x - center.x,
@@ -1145,13 +1129,13 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1145
 
1146
  return centered;
1147
  });
1148
-
1149
  console.log('[DEBUG] First vertex AFTER:', {
1150
  x: plyData.vertices[0].x.toFixed(3),
1151
  y: plyData.vertices[0].y.toFixed(3),
1152
  z: plyData.vertices[0].z.toFixed(3)
1153
  });
1154
-
1155
  let sumX = 0, sumY = 0, sumZ = 0;
1156
  plyData.vertices.forEach(v => {
1157
  sumX += v.x;
@@ -1161,29 +1145,28 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1161
  const avgX = sumX / plyData.vertices.length;
1162
  const avgY = sumY / plyData.vertices.length;
1163
  const avgZ = sumZ / plyData.vertices.length;
1164
-
1165
  console.log('[DEBUG] Average after centering:', {
1166
  x: avgX.toFixed(6),
1167
  y: avgY.toFixed(6),
1168
  z: avgZ.toFixed(6)
1169
  });
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
  }
1176
-
1177
  console.log('[preprocessManual] ✓ PLY centered at origin');
1178
-
1179
  // ========================================
1180
- // STEP 2: バウンディングボックスを再計算(常に実行)
1181
  // ========================================
1182
  console.log('[preprocessManual] Step 2: Recalculating bounding box...');
1183
-
1184
- minX = Infinity; minY = Infinity; minZ = Infinity;
1185
- maxX = -Infinity; maxY = -Infinity; maxZ = -Infinity;
1186
-
1187
  plyData.vertices.forEach(v => {
1188
  minX = Math.min(minX, v.x);
1189
  minY = Math.min(minY, v.y);
@@ -1192,28 +1175,28 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1192
  maxY = Math.max(maxY, v.y);
1193
  maxZ = Math.max(maxZ, v.z);
1194
  });
1195
-
1196
- sizeX = maxX - minX;
1197
- sizeY = maxY - minY;
1198
- sizeZ = maxZ - minZ;
1199
-
1200
  console.log('[preprocessManual] Centered sizes:', {
1201
  sizeX: sizeX.toFixed(2),
1202
  sizeY: sizeY.toFixed(2),
1203
  sizeZ: sizeZ.toFixed(2)
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);
@@ -1225,7 +1208,10 @@ parser.parsePLY(gsPath, true).then((plyData) => {
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
 
@@ -1245,44 +1231,6 @@ parser.parsePLY(gsPath, true).then((plyData) => {
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
- // ========================================
1253
- // STEP 4: 回転を適用(必要な場合のみ)
1254
- // ========================================
1255
- if (rotationApplied) {
1256
- console.log('[preprocessManual] Step 4: Applying rotation to all vertices...');
1257
-
1258
- plyData.vertices.forEach(v => {
1259
- const pos = new THREE.Vector3(v.x, v.y, v.z);
1260
- pos.applyMatrix4(rotationNeeded);
1261
- v.x = pos.x;
1262
- v.y = pos.y;
1263
- v.z = pos.z;
1264
- });
1265
-
1266
- console.log('[preprocessManual] ✓ PLY rotated to align with world axes');
1267
-
1268
- // ⭐ 重要: GSにも同じ変換を適用するためフラグを立てる
1269
- window.plyAlignmentApplied = true;
1270
- window.plyAlignmentMatrix = rotationNeeded.clone();
1271
-
1272
- console.log('[preprocessManual] ✓ Alignment matrix saved for GS display');
1273
- console.log('[preprocessManual] Matrix elements:', rotationNeeded.elements.slice(0, 4));
1274
-
1275
- } else {
1276
- console.log('[preprocessManual] Step 4: Skipped (no rotation needed)');
1277
- }
1278
-
1279
- // ========================================
1280
- // STEP 5: 最終確認(サイズの再計算) 不要なため削除された
1281
- // ========================================
1282
-
1283
- } else {
1284
- console.log('[preprocessManual] User chose to keep original orientation');
1285
- console.log('[preprocessManual] Box rotation sliders should be used to match PLY orientation');
1286
  }
1287
 
1288
  } else {
@@ -1290,13 +1238,7 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1290
  }
1291
 
1292
 
1293
-
1294
- ////////////////////1095-1210 end
1295
-
1296
-
1297
- // ========================================
1298
- // 元のコードを続ける
1299
- // ========================================
1300
 
1301
 
1302
  // ========================================
@@ -1372,26 +1314,39 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1372
  // ⭐ 4. カメラをPLYに合わせて調整(cameraControls初期化後)
1373
  // ========================================
1374
 
1375
- //////////////////////10:10
1376
 
1377
  console.log('[preprocessManual] Auto-aligning camera to PLY...');
1378
 
1379
- // ⭐⭐⭐ センタリング後の中心は常に 0,0,0 ⭐⭐⭐
1380
- const center = { x: 0, y: 0, z: 0 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1381
 
1382
- // Step 2 で計算したサイズを使用
1383
  const size = {
1384
- x: sizeX, // Step 2 で計算済み
1385
- y: sizeY,
1386
- z: sizeZ
1387
  };
1388
 
1389
  console.log('[preprocessManual] Camera alignment - PLY center:', center);
1390
  console.log('[preprocessManual] Camera alignment - PLY size:', size);
1391
 
1392
  const maxDim = Math.max(size.x, size.y, size.z);
1393
-
1394
- // カメラ位置を計算
1395
  const distance = maxDim * 2.0;
1396
 
1397
  camera.position.set(
@@ -1403,6 +1358,9 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1403
  camera.lookAt(center.x, center.y, center.z);
1404
  camera.updateProjectionMatrix();
1405
 
 
 
 
1406
  console.log('[preprocessManual] Camera positioned at:', {
1407
  x: camera.position.x.toFixed(2),
1408
  y: camera.position.y.toFixed(2),
@@ -1417,28 +1375,6 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1417
 
1418
  //////////////////////ここまで
1419
 
1420
-
1421
- camera.position.set(
1422
- center.x,
1423
- center.y + maxDim * 0.3,
1424
- center.z + distance
1425
- );
1426
-
1427
- camera.lookAt(center.x, center.y, center.z);
1428
- camera.updateProjectionMatrix();
1429
-
1430
- console.log('[preprocessManual] Camera positioned at:', {
1431
- x: camera.position.x.toFixed(2),
1432
- y: camera.position.y.toFixed(2),
1433
- z: camera.position.z.toFixed(2)
1434
- });
1435
- console.log('[preprocessManual] Looking at:', center);
1436
-
1437
- // ⭐ OrbitControlsのターゲットを設定(cameraControlsが存在することを確認済み)
1438
- cameraControls.controls.target.set(center.x, center.y, center.z);
1439
- cameraControls.controls.update();
1440
- console.log('[preprocessManual] OrbitControls target set to PLY center');
1441
-
1442
  // ========================================
1443
  // ⭐ 5. Scene bounds の計算と表示
1444
  // ========================================
 
1090
  // 2. 点群を分析
1091
  const pcaResult = computePCA(plyData.vertices);
1092
 
1093
+
1094
+ // 3. 回転が必要な場合、ユーザーに通知////1095-1290
1095
 
1096
  // 3. 回転が必要な場合、ユーザーに通知
1097
  if (pcaResult.needsRotation) {
1098
  console.warn('[preprocessManual] ⚠️ PLY coordinate system is NOT aligned with world axes');
1099
  console.warn('[preprocessManual] This may cause visual mismatch between Box and filtering');
1100
 
1101
+ // ⭐ ユーザー確認を削除し、自動的に正規化を実行
 
 
 
 
 
 
 
 
 
 
 
1102
  console.log('[preprocessManual] ===== STARTING AUTO-ALIGNMENT =====');
1103
+
1104
  const { center } = pcaResult;
1105
+
 
 
 
 
 
 
1106
  // ========================================
1107
+ // STEP 1: 中心化(1回だけ実行)
1108
  // ========================================
1109
  console.log('[preprocessManual] Step 1: Centering PLY...');
1110
+
1111
  console.log('[DEBUG] First vertex BEFORE:', {
1112
  x: plyData.vertices[0].x.toFixed(3),
1113
  y: plyData.vertices[0].y.toFixed(3),
1114
  z: plyData.vertices[0].z.toFixed(3)
1115
  });
1116
+
1117
  plyData.vertices = plyData.vertices.map(v => {
1118
  const centered = {
1119
  x: v.x - center.x,
 
1129
 
1130
  return centered;
1131
  });
1132
+
1133
  console.log('[DEBUG] First vertex AFTER:', {
1134
  x: plyData.vertices[0].x.toFixed(3),
1135
  y: plyData.vertices[0].y.toFixed(3),
1136
  z: plyData.vertices[0].z.toFixed(3)
1137
  });
1138
+
1139
  let sumX = 0, sumY = 0, sumZ = 0;
1140
  plyData.vertices.forEach(v => {
1141
  sumX += v.x;
 
1145
  const avgX = sumX / plyData.vertices.length;
1146
  const avgY = sumY / plyData.vertices.length;
1147
  const avgZ = sumZ / plyData.vertices.length;
1148
+
1149
  console.log('[DEBUG] Average after centering:', {
1150
  x: avgX.toFixed(6),
1151
  y: avgY.toFixed(6),
1152
  z: avgZ.toFixed(6)
1153
  });
1154
+
1155
  if (Math.abs(avgX) > 0.001 || Math.abs(avgY) > 0.001 || Math.abs(avgZ) > 0.001) {
1156
  console.error('[DEBUG] ❌ ERROR: Centering FAILED!');
1157
  } else {
1158
  console.log('[DEBUG] ✓ Centering SUCCESS! Average is ~0');
1159
  }
1160
+
1161
  console.log('[preprocessManual] ✓ PLY centered at origin');
1162
+
1163
  // ========================================
1164
+ // STEP 2: バウンディングボックスを再計算
1165
  // ========================================
1166
  console.log('[preprocessManual] Step 2: Recalculating bounding box...');
1167
+ let minX = Infinity, minY = Infinity, minZ = Infinity;
1168
+ let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
1169
+
 
1170
  plyData.vertices.forEach(v => {
1171
  minX = Math.min(minX, v.x);
1172
  minY = Math.min(minY, v.y);
 
1175
  maxY = Math.max(maxY, v.y);
1176
  maxZ = Math.max(maxZ, v.z);
1177
  });
1178
+
1179
+ const sizeX = maxX - minX;
1180
+ const sizeY = maxY - minY;
1181
+ const sizeZ = maxZ - minZ;
1182
+
1183
  console.log('[preprocessManual] Centered sizes:', {
1184
  sizeX: sizeX.toFixed(2),
1185
  sizeY: sizeY.toFixed(2),
1186
  sizeZ: sizeZ.toFixed(2)
1187
  });
1188
+
1189
  // ========================================
1190
+ // STEP 3: Y軸が最長になるように回転
1191
  // ========================================
1192
  console.log('[preprocessManual] Step 3: Checking if rotation is needed...');
1193
  console.log('[preprocessManual] Longest axis:',
1194
  sizeX > sizeY && sizeX > sizeZ ? 'X' :
1195
  sizeZ > sizeY ? 'Z' : 'Y');
1196
+
1197
  let rotationNeeded = new THREE.Matrix4();
1198
  let rotationApplied = false;
1199
+
1200
  if (sizeX > sizeY && sizeX > sizeZ) {
1201
  console.log('[preprocessManual] ⚙️ Rotating: X → Y (90° around Z axis)');
1202
  rotationNeeded.makeRotationZ(Math.PI / 2);
 
1208
  } else {
1209
  console.log('[preprocessManual] ✓ Y-axis is already the longest, no rotation needed');
1210
  }
1211
+
1212
+ // ========================================
1213
+ // STEP 4: 回転を適用(必要な場合のみ)
1214
+ // ========================================
1215
  if (rotationApplied) {
1216
  console.log('[preprocessManual] Step 4: Applying rotation to all vertices...');
1217
 
 
1231
  console.log('[preprocessManual] ✓ Alignment matrix saved for GS display');
1232
  } else {
1233
  console.log('[preprocessManual] Step 4: Skipped (no rotation needed)');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1234
  }
1235
 
1236
  } else {
 
1238
  }
1239
 
1240
 
1241
+ ////////////////////////1095-1290
 
 
 
 
 
 
1242
 
1243
 
1244
  // ========================================
 
1314
  // ⭐ 4. カメラをPLYに合わせて調整(cameraControls初期化後)
1315
  // ========================================
1316
 
1317
+ //////////////////////Line 1377-1391 (カメラ調整部分)
1318
 
1319
  console.log('[preprocessManual] Auto-aligning camera to PLY...');
1320
 
1321
+ // サイズを再計算(if ブロックの外なので)
1322
+ let minX = Infinity, minY = Infinity, minZ = Infinity;
1323
+ let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
1324
+
1325
+ plyData.vertices.forEach(vertex => {
1326
+ minX = Math.min(minX, vertex.x);
1327
+ minY = Math.min(minY, vertex.y);
1328
+ minZ = Math.min(minZ, vertex.z);
1329
+ maxX = Math.max(maxX, vertex.x);
1330
+ maxY = Math.max(maxY, vertex.y);
1331
+ maxZ = Math.max(maxZ, vertex.z);
1332
+ });
1333
+
1334
+ const center = {
1335
+ x: (maxX + minX) / 2,
1336
+ y: (maxY + minY) / 2,
1337
+ z: (maxZ + minZ) / 2
1338
+ };
1339
 
 
1340
  const size = {
1341
+ x: maxX - minX,
1342
+ y: maxY - minY,
1343
+ z: maxZ - minZ
1344
  };
1345
 
1346
  console.log('[preprocessManual] Camera alignment - PLY center:', center);
1347
  console.log('[preprocessManual] Camera alignment - PLY size:', size);
1348
 
1349
  const maxDim = Math.max(size.x, size.y, size.z);
 
 
1350
  const distance = maxDim * 2.0;
1351
 
1352
  camera.position.set(
 
1358
  camera.lookAt(center.x, center.y, center.z);
1359
  camera.updateProjectionMatrix();
1360
 
1361
+ ///////////////////////////Line 1377-1391 (カメラ調整部分)
1362
+
1363
+
1364
  console.log('[preprocessManual] Camera positioned at:', {
1365
  x: camera.position.x.toFixed(2),
1366
  y: camera.position.y.toFixed(2),
 
1375
 
1376
  //////////////////////ここまで
1377
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1378
  // ========================================
1379
  // ⭐ 5. Scene bounds の計算と表示
1380
  // ========================================