Upload preprocess_manual.js
Browse files- preprocess_manual.js +177 -225
preprocess_manual.js
CHANGED
|
@@ -1103,20 +1103,35 @@ parser.parsePLY(gsPath, true).then((plyData) => {
|
|
| 1103 |
// 完全修正版: PLY中心化(Line 1100-1290を置き換え)
|
| 1104 |
// イミュータブルなオブジェクト生成で確実に中心化
|
| 1105 |
// ========================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1106 |
|
| 1107 |
console.log('[preprocessManual] ===== STARTING AUTO-ALIGNMENT =====');
|
| 1108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1109 |
// ========================================
|
| 1110 |
// STEP 1: 重心計算
|
| 1111 |
// ========================================
|
| 1112 |
console.log('[preprocessManual] Step 1: Calculating center of mass...');
|
| 1113 |
|
| 1114 |
let sumX = 0, sumY = 0, sumZ = 0;
|
| 1115 |
-
plyData.vertices.
|
| 1116 |
-
sumX +=
|
| 1117 |
-
sumY +=
|
| 1118 |
-
sumZ +=
|
| 1119 |
-
}
|
| 1120 |
|
| 1121 |
const center = {
|
| 1122 |
x: sumX / plyData.vertices.length,
|
|
@@ -1137,42 +1152,27 @@ console.log('[DEBUG] First vertex BEFORE centering:', {
|
|
| 1137 |
});
|
| 1138 |
|
| 1139 |
// ========================================
|
| 1140 |
-
// STEP 2:
|
| 1141 |
// ========================================
|
| 1142 |
-
console.log('[preprocessManual] Step 2: Centering PLY (
|
| 1143 |
-
|
| 1144 |
-
const centeredVertices = [];
|
| 1145 |
|
|
|
|
| 1146 |
for (let i = 0; i < plyData.vertices.length; i++) {
|
| 1147 |
-
|
| 1148 |
-
|
| 1149 |
-
|
| 1150 |
-
const newVertex = {};
|
| 1151 |
-
|
| 1152 |
-
// 座標を中心化
|
| 1153 |
-
newVertex.x = v.x - center.x;
|
| 1154 |
-
newVertex.y = v.y - center.y;
|
| 1155 |
-
newVertex.z = v.z - center.z;
|
| 1156 |
-
|
| 1157 |
-
// 他のプロパティをコピー(座標以外)
|
| 1158 |
-
for (const key in v) {
|
| 1159 |
-
if (key !== 'x' && key !== 'y' && key !== 'z') {
|
| 1160 |
-
newVertex[key] = v[key];
|
| 1161 |
-
}
|
| 1162 |
-
}
|
| 1163 |
-
|
| 1164 |
-
centeredVertices.push(newVertex);
|
| 1165 |
}
|
| 1166 |
|
| 1167 |
-
// ⭐ 配列を完全に置き換え
|
| 1168 |
-
plyData.vertices = centeredVertices;
|
| 1169 |
-
|
| 1170 |
console.log('[DEBUG] First vertex AFTER centering:', {
|
| 1171 |
x: plyData.vertices[0].x.toFixed(6),
|
| 1172 |
y: plyData.vertices[0].y.toFixed(6),
|
| 1173 |
z: plyData.vertices[0].z.toFixed(6)
|
| 1174 |
});
|
| 1175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1176 |
// ========================================
|
| 1177 |
// STEP 3: 検証(平均を再計算)
|
| 1178 |
// ========================================
|
|
@@ -1202,12 +1202,6 @@ if (Math.abs(avgX) > 1e-6 || Math.abs(avgY) > 1e-6 || Math.abs(avgZ) > 1e-6) {
|
|
| 1202 |
avgY: avgY.toFixed(9),
|
| 1203 |
avgZ: avgZ.toFixed(9)
|
| 1204 |
});
|
| 1205 |
-
alert('❌ PLY Centering Failed!\n\n' +
|
| 1206 |
-
'Average is not zero:\n' +
|
| 1207 |
-
'X: ' + avgX.toFixed(9) + '\n' +
|
| 1208 |
-
'Y: ' + avgY.toFixed(9) + '\n' +
|
| 1209 |
-
'Z: ' + avgZ.toFixed(9) + '\n\n' +
|
| 1210 |
-
'Please reload and try again.');
|
| 1211 |
return;
|
| 1212 |
}
|
| 1213 |
|
|
@@ -1215,10 +1209,20 @@ console.log('[DEBUG] ✓ Centering SUCCESS! Average is effectively zero');
|
|
| 1215 |
console.log('[preprocessManual] ✓ PLY centered at origin');
|
| 1216 |
|
| 1217 |
// ========================================
|
| 1218 |
-
// STEP 4:
|
| 1219 |
// ========================================
|
| 1220 |
console.log('[preprocessManual] Step 4: Calculating bounding box...');
|
| 1221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1222 |
let minX = Infinity, minY = Infinity, minZ = Infinity;
|
| 1223 |
let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
| 1224 |
|
|
@@ -1232,103 +1236,67 @@ for (let i = 0; i < plyData.vertices.length; i++) {
|
|
| 1232 |
maxZ = Math.max(maxZ, v.z);
|
| 1233 |
}
|
| 1234 |
|
| 1235 |
-
const
|
| 1236 |
-
|
| 1237 |
-
|
|
|
|
|
|
|
| 1238 |
|
| 1239 |
-
console.log('[preprocessManual]
|
| 1240 |
min: { x: minX.toFixed(3), y: minY.toFixed(3), z: minZ.toFixed(3) },
|
| 1241 |
max: { x: maxX.toFixed(3), y: maxY.toFixed(3), z: maxZ.toFixed(3) },
|
| 1242 |
-
|
| 1243 |
});
|
| 1244 |
|
| 1245 |
-
//
|
| 1246 |
-
|
| 1247 |
-
|
| 1248 |
-
console.
|
| 1249 |
-
console.
|
| 1250 |
-
sizeX > sizeY && sizeX > sizeZ ? 'X (' + sizeX.toFixed(2) + 'm)' :
|
| 1251 |
-
sizeZ > sizeY ? 'Z (' + sizeZ.toFixed(2) + 'm)' :
|
| 1252 |
-
'Y (' + sizeY.toFixed(2) + 'm)');
|
| 1253 |
-
|
| 1254 |
-
let rotationNeeded = new THREE.Matrix4();
|
| 1255 |
-
let rotationApplied = false;
|
| 1256 |
-
|
| 1257 |
-
if (sizeX > sizeY && sizeX > sizeZ) {
|
| 1258 |
-
console.log('[preprocessManual] ⚙️ Rotating: X → Y (90° around Z axis)');
|
| 1259 |
-
rotationNeeded.makeRotationZ(Math.PI / 2);
|
| 1260 |
-
rotationApplied = true;
|
| 1261 |
-
} else if (sizeZ > sizeY && sizeZ > sizeX) {
|
| 1262 |
-
console.log('[preprocessManual] ⚙️ Rotating: Z → Y (90° around X axis)');
|
| 1263 |
-
rotationNeeded.makeRotationX(Math.PI / 2);
|
| 1264 |
-
rotationApplied = true;
|
| 1265 |
-
} else {
|
| 1266 |
-
console.log('[preprocessManual] ✓ Y-axis is already the longest, no rotation needed');
|
| 1267 |
-
}
|
| 1268 |
-
|
| 1269 |
-
// ========================================
|
| 1270 |
-
// STEP 6: 回転を適用(必要な場合のみ)
|
| 1271 |
-
// ========================================
|
| 1272 |
-
if (rotationApplied) {
|
| 1273 |
-
console.log('[preprocessManual] Step 6: Applying rotation...');
|
| 1274 |
-
|
| 1275 |
-
for (let i = 0; i < plyData.vertices.length; i++) {
|
| 1276 |
-
const v = plyData.vertices[i];
|
| 1277 |
-
const pos = new THREE.Vector3(v.x, v.y, v.z);
|
| 1278 |
-
pos.applyMatrix4(rotationNeeded);
|
| 1279 |
-
|
| 1280 |
-
v.x = pos.x;
|
| 1281 |
-
v.y = pos.y;
|
| 1282 |
-
v.z = pos.z;
|
| 1283 |
-
}
|
| 1284 |
-
|
| 1285 |
-
console.log('[preprocessManual] ✓ Rotation applied');
|
| 1286 |
|
| 1287 |
-
|
| 1288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1289 |
|
| 1290 |
-
|
| 1291 |
-
|
| 1292 |
-
|
| 1293 |
-
|
|
|
|
|
|
|
| 1294 |
}
|
| 1295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1296 |
// ========================================
|
| 1297 |
-
// STEP 7:
|
| 1298 |
// ========================================
|
| 1299 |
-
console.log('[preprocessManual]
|
| 1300 |
|
| 1301 |
-
|
| 1302 |
-
maxX = -Infinity; maxY = -Infinity; maxZ = -Infinity;
|
| 1303 |
|
| 1304 |
-
|
| 1305 |
-
const v = plyData.vertices[i];
|
| 1306 |
-
minX = Math.min(minX, v.x);
|
| 1307 |
-
minY = Math.min(minY, v.y);
|
| 1308 |
-
minZ = Math.min(minZ, v.z);
|
| 1309 |
-
maxX = Math.max(maxX, v.x);
|
| 1310 |
-
maxY = Math.max(maxY, v.y);
|
| 1311 |
-
maxZ = Math.max(maxZ, v.z);
|
| 1312 |
-
}
|
| 1313 |
|
| 1314 |
-
const finalCenter = {
|
| 1315 |
-
x: (minX + maxX) / 2,
|
| 1316 |
-
y: (minY + maxY) / 2,
|
| 1317 |
-
z: (minZ + maxZ) / 2
|
| 1318 |
-
};
|
| 1319 |
-
|
| 1320 |
-
console.log('[preprocessManual] Final PLY state:', {
|
| 1321 |
-
bounds: {
|
| 1322 |
-
min: { x: minX.toFixed(3), y: minY.toFixed(3), z: minZ.toFixed(3) },
|
| 1323 |
-
max: { x: maxX.toFixed(3), y: maxY.toFixed(3), z: maxZ.toFixed(3) }
|
| 1324 |
-
},
|
| 1325 |
-
center: {
|
| 1326 |
-
x: finalCenter.x.toFixed(6),
|
| 1327 |
-
y: finalCenter.y.toFixed(6),
|
| 1328 |
-
z: finalCenter.z.toFixed(6)
|
| 1329 |
-
}
|
| 1330 |
-
});
|
| 1331 |
|
|
|
|
| 1332 |
// ⭐ より厳密な検証(1mm以内)
|
| 1333 |
const tolerance = 0.001; // 1mm
|
| 1334 |
if (Math.abs(finalCenter.x) > tolerance ||
|
|
@@ -1444,102 +1412,110 @@ window.plyAlignmentMatrix = rotationNeeded.clone();
|
|
| 1444 |
// ========================================
|
| 1445 |
|
| 1446 |
|
| 1447 |
-
|
| 1448 |
-
|
| 1449 |
-
// ========================================
|
| 1450 |
-
// 修正版: カメラ配置部分(Line 1319-1430付近)
|
| 1451 |
-
// 2回目の中心化を削除し、検証のみに変更
|
| 1452 |
-
// ========================================
|
| 1453 |
|
| 1454 |
-
console.log('[preprocessManual] Auto-aligning camera to PLY...');
|
| 1455 |
|
| 1456 |
-
|
| 1457 |
-
|
| 1458 |
-
|
| 1459 |
-
|
| 1460 |
-
let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
| 1461 |
-
|
| 1462 |
-
plyData.vertices.forEach(vertex => {
|
| 1463 |
-
minX = Math.min(minX, vertex.x);
|
| 1464 |
-
minY = Math.min(minY, vertex.y);
|
| 1465 |
-
minZ = Math.min(minZ, vertex.z);
|
| 1466 |
-
maxX = Math.max(maxX, vertex.x);
|
| 1467 |
-
maxY = Math.max(maxY, vertex.y);
|
| 1468 |
-
maxZ = Math.max(maxZ, vertex.z);
|
| 1469 |
-
});
|
| 1470 |
-
|
| 1471 |
-
const calculatedCenter = {
|
| 1472 |
-
x: (maxX + minX) / 2,
|
| 1473 |
-
y: (maxY + minY) / 2,
|
| 1474 |
-
z: (maxZ + minZ) / 2
|
| 1475 |
-
};
|
| 1476 |
|
| 1477 |
-
|
| 1478 |
-
|
| 1479 |
-
console.log(' Max:', { x: maxX.toFixed(3), y: maxY.toFixed(3), z: maxZ.toFixed(3) });
|
| 1480 |
-
console.log(' Calculated center:', {
|
| 1481 |
-
x: calculatedCenter.x.toFixed(3),
|
| 1482 |
-
y: calculatedCenter.y.toFixed(3),
|
| 1483 |
-
z: calculatedCenter.z.toFixed(3)
|
| 1484 |
-
});
|
| 1485 |
|
| 1486 |
-
|
| 1487 |
-
|
| 1488 |
-
|
| 1489 |
-
|
| 1490 |
-
|
| 1491 |
-
|
| 1492 |
-
|
| 1493 |
-
|
| 1494 |
-
// ⭐ エラーメッセージのみ表示(中心化は実行しない)
|
| 1495 |
-
alert('⚠️ PLY Centering Error!\n\n' +
|
| 1496 |
-
'The PLY data is not centered at origin.\n' +
|
| 1497 |
-
'Expected: ~(0, 0, 0)\n' +
|
| 1498 |
-
'Got: (' + calculatedCenter.x.toFixed(2) + ', ' +
|
| 1499 |
-
calculatedCenter.y.toFixed(2) + ', ' +
|
| 1500 |
-
calculatedCenter.z.toFixed(2) + ')\n\n' +
|
| 1501 |
-
'Please reload the page and try again.');
|
| 1502 |
-
return; // 処理を中断
|
| 1503 |
-
}
|
| 1504 |
|
| 1505 |
-
|
| 1506 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1507 |
|
| 1508 |
-
|
| 1509 |
-
|
| 1510 |
-
|
| 1511 |
-
|
| 1512 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1513 |
|
| 1514 |
-
|
| 1515 |
-
console.log('[preprocessManual] Camera alignment - PLY size:', size);
|
| 1516 |
|
| 1517 |
-
|
| 1518 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1519 |
|
| 1520 |
-
|
| 1521 |
-
|
| 1522 |
-
|
| 1523 |
-
|
| 1524 |
-
);
|
| 1525 |
|
| 1526 |
-
|
| 1527 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1528 |
|
| 1529 |
-
|
| 1530 |
-
|
| 1531 |
-
|
| 1532 |
-
z: camera.position.z.toFixed(2)
|
| 1533 |
-
});
|
| 1534 |
-
console.log('[preprocessManual] Looking at:', center);
|
| 1535 |
|
| 1536 |
-
|
| 1537 |
-
|
| 1538 |
-
|
| 1539 |
-
console.log('[preprocessManual] OrbitControls target set to origin');
|
| 1540 |
|
| 1541 |
-
///////////////////////////////////////修正1: Line 1319-1375 を完全に書き換え
|
| 1542 |
|
|
|
|
| 1543 |
const sceneCenter = {
|
| 1544 |
x: (maxX + minX) / 2,
|
| 1545 |
y: (maxY + minY) / 2,
|
|
@@ -1547,8 +1523,6 @@ window.plyAlignmentMatrix = rotationNeeded.clone();
|
|
| 1547 |
};
|
| 1548 |
|
| 1549 |
|
| 1550 |
-
// 修正版: カメラ配置部分(Line 1319-1430付近)
|
| 1551 |
-
|
| 1552 |
// Display scene info in UI
|
| 1553 |
const sceneSizeEl = document.getElementById('scene-size');
|
| 1554 |
const sceneCenterEl = document.getElementById('scene-center');
|
|
@@ -1559,28 +1533,6 @@ window.plyAlignmentMatrix = rotationNeeded.clone();
|
|
| 1559 |
sceneCenterEl.textContent = `(${sceneCenter.x.toFixed(1)}, ${sceneCenter.y.toFixed(1)}, ${sceneCenter.z.toFixed(1)})`;
|
| 1560 |
}
|
| 1561 |
|
| 1562 |
-
// ========================================
|
| 1563 |
-
// ⭐ 6. 初期Box設定(中心化後のPLYに合わせる)
|
| 1564 |
-
// ========================================
|
| 1565 |
-
let boxSize = {
|
| 1566 |
-
x: size.x * 1.2, // 120% (余裕を持たせる)
|
| 1567 |
-
y: size.y * 1.2,
|
| 1568 |
-
z: size.z * 1.2
|
| 1569 |
-
};
|
| 1570 |
-
|
| 1571 |
-
let boxPosition = {
|
| 1572 |
-
x: 0, // ⭐ 明示的に 0,0,0
|
| 1573 |
-
y: 0,
|
| 1574 |
-
z: 0
|
| 1575 |
-
};
|
| 1576 |
-
|
| 1577 |
-
let boxRotation = { x: 0, y: 0, z: 0 };
|
| 1578 |
-
let plyOffset = { x: 0, y: 0, z: 0 };
|
| 1579 |
-
|
| 1580 |
-
console.log('[preprocessManual] Initial Box setup:');
|
| 1581 |
-
console.log(' boxSize:', boxSize);
|
| 1582 |
-
console.log(' boxPosition:', boxPosition);
|
| 1583 |
-
|
| 1584 |
const gsScene = gs.viewer.splatMesh.scenes[0];
|
| 1585 |
|
| 1586 |
// Create initial bounding box
|
|
|
|
| 1103 |
// 完全修正版: PLY中心化(Line 1100-1290を置き換え)
|
| 1104 |
// イミュータブルなオブジェクト生成で確実に中心化
|
| 1105 |
// ========================================
|
| 1106 |
+
// デバッグ版: PLY中心化(Line 1107-1330を置き換え)
|
| 1107 |
+
|
| 1108 |
+
// ========================================
|
| 1109 |
+
// デバッグ版: PLY中心化(Line 1107-1330を置き換え)
|
| 1110 |
+
// 各ステップで配列の参照を確認
|
| 1111 |
+
// ========================================
|
| 1112 |
|
| 1113 |
console.log('[preprocessManual] ===== STARTING AUTO-ALIGNMENT =====');
|
| 1114 |
|
| 1115 |
+
// ⭐ デバッグ: 元の配列の参照を記録
|
| 1116 |
+
const originalVerticesRef = plyData.vertices;
|
| 1117 |
+
console.log('[DEBUG] Original vertices reference:', originalVerticesRef);
|
| 1118 |
+
console.log('[DEBUG] Original first vertex:', {
|
| 1119 |
+
x: originalVerticesRef[0].x.toFixed(6),
|
| 1120 |
+
y: originalVerticesRef[0].y.toFixed(6),
|
| 1121 |
+
z: originalVerticesRef[0].z.toFixed(6)
|
| 1122 |
+
});
|
| 1123 |
+
|
| 1124 |
// ========================================
|
| 1125 |
// STEP 1: 重心計算
|
| 1126 |
// ========================================
|
| 1127 |
console.log('[preprocessManual] Step 1: Calculating center of mass...');
|
| 1128 |
|
| 1129 |
let sumX = 0, sumY = 0, sumZ = 0;
|
| 1130 |
+
for (let i = 0; i < plyData.vertices.length; i++) {
|
| 1131 |
+
sumX += plyData.vertices[i].x;
|
| 1132 |
+
sumY += plyData.vertices[i].y;
|
| 1133 |
+
sumZ += plyData.vertices[i].z;
|
| 1134 |
+
}
|
| 1135 |
|
| 1136 |
const center = {
|
| 1137 |
x: sumX / plyData.vertices.length,
|
|
|
|
| 1152 |
});
|
| 1153 |
|
| 1154 |
// ========================================
|
| 1155 |
+
// STEP 2: 中心化(in-place修正版)
|
| 1156 |
// ========================================
|
| 1157 |
+
console.log('[preprocessManual] Step 2: Centering PLY (in-place modification)...');
|
|
|
|
|
|
|
| 1158 |
|
| 1159 |
+
// ⭐ 元の配列を直接書き換える
|
| 1160 |
for (let i = 0; i < plyData.vertices.length; i++) {
|
| 1161 |
+
plyData.vertices[i].x -= center.x;
|
| 1162 |
+
plyData.vertices[i].y -= center.y;
|
| 1163 |
+
plyData.vertices[i].z -= center.z;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1164 |
}
|
| 1165 |
|
|
|
|
|
|
|
|
|
|
| 1166 |
console.log('[DEBUG] First vertex AFTER centering:', {
|
| 1167 |
x: plyData.vertices[0].x.toFixed(6),
|
| 1168 |
y: plyData.vertices[0].y.toFixed(6),
|
| 1169 |
z: plyData.vertices[0].z.toFixed(6)
|
| 1170 |
});
|
| 1171 |
|
| 1172 |
+
// ⭐ デバッグ: 配列の参照が変わっていないか確認
|
| 1173 |
+
console.log('[DEBUG] Vertices reference after centering:', plyData.vertices);
|
| 1174 |
+
console.log('[DEBUG] Is same reference?', plyData.vertices === originalVerticesRef);
|
| 1175 |
+
|
| 1176 |
// ========================================
|
| 1177 |
// STEP 3: 検証(平均を再計算)
|
| 1178 |
// ========================================
|
|
|
|
| 1202 |
avgY: avgY.toFixed(9),
|
| 1203 |
avgZ: avgZ.toFixed(9)
|
| 1204 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1205 |
return;
|
| 1206 |
}
|
| 1207 |
|
|
|
|
| 1209 |
console.log('[preprocessManual] ✓ PLY centered at origin');
|
| 1210 |
|
| 1211 |
// ========================================
|
| 1212 |
+
// STEP 4: バウンディングボックスを計算(デバッグ付き)
|
| 1213 |
// ========================================
|
| 1214 |
console.log('[preprocessManual] Step 4: Calculating bounding box...');
|
| 1215 |
|
| 1216 |
+
// ⭐ デバッグ: この時点での頂点を確認
|
| 1217 |
+
console.log('[DEBUG] First 3 vertices before bbox calculation:');
|
| 1218 |
+
for (let i = 0; i < Math.min(3, plyData.vertices.length); i++) {
|
| 1219 |
+
console.log(` V${i}:`, {
|
| 1220 |
+
x: plyData.vertices[i].x.toFixed(6),
|
| 1221 |
+
y: plyData.vertices[i].y.toFixed(6),
|
| 1222 |
+
z: plyData.vertices[i].z.toFixed(6)
|
| 1223 |
+
});
|
| 1224 |
+
}
|
| 1225 |
+
|
| 1226 |
let minX = Infinity, minY = Infinity, minZ = Infinity;
|
| 1227 |
let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
| 1228 |
|
|
|
|
| 1236 |
maxZ = Math.max(maxZ, v.z);
|
| 1237 |
}
|
| 1238 |
|
| 1239 |
+
const bboxCenter = {
|
| 1240 |
+
x: (minX + maxX) / 2,
|
| 1241 |
+
y: (minY + maxY) / 2,
|
| 1242 |
+
z: (minZ + maxZ) / 2
|
| 1243 |
+
};
|
| 1244 |
|
| 1245 |
+
console.log('[preprocessManual] Bounding box:', {
|
| 1246 |
min: { x: minX.toFixed(3), y: minY.toFixed(3), z: minZ.toFixed(3) },
|
| 1247 |
max: { x: maxX.toFixed(3), y: maxY.toFixed(3), z: maxZ.toFixed(3) },
|
| 1248 |
+
center: { x: bboxCenter.x.toFixed(6), y: bboxCenter.y.toFixed(6), z: bboxCenter.z.toFixed(6) }
|
| 1249 |
});
|
| 1250 |
|
| 1251 |
+
// ⭐ デバッグ: ここで中心がずれている場合は異常
|
| 1252 |
+
if (Math.abs(bboxCenter.x) > 0.01 || Math.abs(bboxCenter.y) > 0.01 || Math.abs(bboxCenter.z) > 0.01) {
|
| 1253 |
+
console.error('[DEBUG] ❌ CRITICAL ERROR: Bounding box center is not at origin!');
|
| 1254 |
+
console.error('[DEBUG] This means vertices were modified between Step 3 and Step 4!');
|
| 1255 |
+
console.error('[DEBUG] Bbox center:', bboxCenter);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1256 |
|
| 1257 |
+
// さらにデバッグ: 頂点を再チェック
|
| 1258 |
+
console.error('[DEBUG] Re-checking first vertex:');
|
| 1259 |
+
console.error(' Current:', {
|
| 1260 |
+
x: plyData.vertices[0].x.toFixed(6),
|
| 1261 |
+
y: plyData.vertices[0].y.toFixed(6),
|
| 1262 |
+
z: plyData.vertices[0].z.toFixed(6)
|
| 1263 |
+
});
|
| 1264 |
+
console.error(' Original (from reference):', {
|
| 1265 |
+
x: originalVerticesRef[0].x.toFixed(6),
|
| 1266 |
+
y: originalVerticesRef[0].y.toFixed(6),
|
| 1267 |
+
z: originalVerticesRef[0].z.toFixed(6)
|
| 1268 |
+
});
|
| 1269 |
|
| 1270 |
+
alert('❌ CRITICAL ERROR in Step 4!\n\n' +
|
| 1271 |
+
'Bounding box center is not at origin:\n' +
|
| 1272 |
+
'Center: (' + bboxCenter.x.toFixed(3) + ', ' + bboxCenter.y.toFixed(3) + ', ' + bboxCenter.z.toFixed(3) + ')\n\n' +
|
| 1273 |
+
'This indicates a serious bug.\n' +
|
| 1274 |
+
'Please check the browser console for details.');
|
| 1275 |
+
return;
|
| 1276 |
}
|
| 1277 |
|
| 1278 |
+
const sizeX = maxX - minX;
|
| 1279 |
+
const sizeY = maxY - minY;
|
| 1280 |
+
const sizeZ = maxZ - minZ;
|
| 1281 |
+
|
| 1282 |
+
console.log('[preprocessManual] ✓ Bounding box center is at origin');
|
| 1283 |
+
console.log('[preprocessManual] Size:', {
|
| 1284 |
+
x: sizeX.toFixed(3),
|
| 1285 |
+
y: sizeY.toFixed(3),
|
| 1286 |
+
z: sizeZ.toFixed(3)
|
| 1287 |
+
});
|
| 1288 |
+
|
| 1289 |
// ========================================
|
| 1290 |
+
// STEP 5-7: 残りのステップ(省略可能)
|
| 1291 |
// ========================================
|
| 1292 |
+
console.log('[preprocessManual] ✓ PLY is properly centered');
|
| 1293 |
|
| 1294 |
+
// 回転チェックは省略(必要なら追加)
|
|
|
|
| 1295 |
|
| 1296 |
+
console.log('[preprocessManual] ===== AUTO-ALIGNMENT COMPLETE =====');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1298 |
|
| 1299 |
+
// デバッグ版: PLY中心化(Line 1107-1330を置き換え)
|
| 1300 |
// ⭐ より厳密な検証(1mm以内)
|
| 1301 |
const tolerance = 0.001; // 1mm
|
| 1302 |
if (Math.abs(finalCenter.x) > tolerance ||
|
|
|
|
| 1412 |
// ========================================
|
| 1413 |
|
| 1414 |
|
| 1415 |
+
///////////////START1137
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1416 |
|
|
|
|
| 1417 |
|
| 1418 |
+
// ========================================
|
| 1419 |
+
// VERIFICATION ONLY - Do not re-center!
|
| 1420 |
+
// ========================================
|
| 1421 |
+
console.log('[preprocessManual] Verifying PLY is centered at origin...');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1422 |
|
| 1423 |
+
let minX = Infinity, minY = Infinity, minZ = Infinity;
|
| 1424 |
+
let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1425 |
|
| 1426 |
+
plyData.vertices.forEach(vertex => {
|
| 1427 |
+
minX = Math.min(minX, vertex.x);
|
| 1428 |
+
minY = Math.min(minY, vertex.y);
|
| 1429 |
+
minZ = Math.min(minZ, vertex.z);
|
| 1430 |
+
maxX = Math.max(maxX, vertex.x);
|
| 1431 |
+
maxY = Math.max(maxY, vertex.y);
|
| 1432 |
+
maxZ = Math.max(maxZ, vertex.z);
|
| 1433 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1434 |
|
| 1435 |
+
const verifiedCenter = {
|
| 1436 |
+
x: (maxX + minX) / 2,
|
| 1437 |
+
y: (maxY + minY) / 2,
|
| 1438 |
+
z: (maxZ + minZ) / 2
|
| 1439 |
+
};
|
| 1440 |
+
|
| 1441 |
+
console.log('[preprocessManual] Verified bounds:');
|
| 1442 |
+
console.log(' Min:', { x: minX.toFixed(3), y: minY.toFixed(3), z: minZ.toFixed(3) });
|
| 1443 |
+
console.log(' Max:', { x: maxX.toFixed(3), y: maxY.toFixed(3), z: maxZ.toFixed(3) });
|
| 1444 |
+
console.log(' Center:', {
|
| 1445 |
+
x: verifiedCenter.x.toFixed(6),
|
| 1446 |
+
y: verifiedCenter.y.toFixed(6),
|
| 1447 |
+
z: verifiedCenter.z.toFixed(6)
|
| 1448 |
+
});
|
| 1449 |
|
| 1450 |
+
// STRICT VERIFICATION - Must be within 1mm tolerance
|
| 1451 |
+
const tolerance = 0.001; // 1mm
|
| 1452 |
+
if (Math.abs(verifiedCenter.x) > tolerance ||
|
| 1453 |
+
Math.abs(verifiedCenter.y) > tolerance ||
|
| 1454 |
+
Math.abs(verifiedCenter.z) > tolerance) {
|
| 1455 |
+
console.error('[preprocessManual] ❌ CRITICAL ERROR: PLY centering verification FAILED!');
|
| 1456 |
+
console.error('[preprocessManual] Center is NOT at origin:', verifiedCenter);
|
| 1457 |
+
console.error('[preprocessManual] This means Step 2 centering did not work!');
|
| 1458 |
+
|
| 1459 |
+
alert('❌ CRITICAL ERROR: PLY Centering Failed!\n\n' +
|
| 1460 |
+
'Expected: (0, 0, 0)\n' +
|
| 1461 |
+
'Got: (' + verifiedCenter.x.toFixed(6) + ', ' +
|
| 1462 |
+
verifiedCenter.y.toFixed(6) + ', ' +
|
| 1463 |
+
verifiedCenter.z.toFixed(6) + ')\n\n' +
|
| 1464 |
+
'The vertices were modified between Step 2 and now.\n' +
|
| 1465 |
+
'Please reload the page and do NOT modify the code between steps.');
|
| 1466 |
+
return; // STOP execution
|
| 1467 |
+
}
|
| 1468 |
|
| 1469 |
+
console.log('[preprocessManual] ✓ Verification PASSED - Center is at origin');
|
|
|
|
| 1470 |
|
| 1471 |
+
// ========================================
|
| 1472 |
+
// Camera Setup (using verified bounds)
|
| 1473 |
+
// ========================================
|
| 1474 |
+
const size = {
|
| 1475 |
+
x: maxX - minX,
|
| 1476 |
+
y: maxY - minY,
|
| 1477 |
+
z: maxZ - minZ
|
| 1478 |
+
};
|
| 1479 |
+
|
| 1480 |
+
const maxDim = Math.max(size.x, size.y, size.z);
|
| 1481 |
+
const distance = maxDim * 2.0;
|
| 1482 |
+
|
| 1483 |
+
// Camera always looks at 0,0,0 (the guaranteed center)
|
| 1484 |
+
camera.position.set(0, maxDim * 0.3, distance);
|
| 1485 |
+
camera.lookAt(0, 0, 0);
|
| 1486 |
+
camera.updateProjectionMatrix();
|
| 1487 |
+
|
| 1488 |
+
console.log('[preprocessManual] Camera positioned at:', {
|
| 1489 |
+
x: camera.position.x.toFixed(2),
|
| 1490 |
+
y: camera.position.y.toFixed(2),
|
| 1491 |
+
z: camera.position.z.toFixed(2)
|
| 1492 |
+
});
|
| 1493 |
+
console.log('[preprocessManual] Looking at: (0, 0, 0)');
|
| 1494 |
|
| 1495 |
+
// ⭐ OrbitControls target
|
| 1496 |
+
cameraControls.controls.target.set(0, 0, 0);
|
| 1497 |
+
cameraControls.controls.update();
|
| 1498 |
+
console.log('[preprocessManual] OrbitControls target set to (0, 0, 0)');
|
|
|
|
| 1499 |
|
| 1500 |
+
// ========================================
|
| 1501 |
+
// Box Setup (centered at origin)
|
| 1502 |
+
// ========================================
|
| 1503 |
+
let boxSize = {
|
| 1504 |
+
x: size.x * 1.2, // 120% of PLY size
|
| 1505 |
+
y: size.y * 1.2,
|
| 1506 |
+
z: size.z * 1.2
|
| 1507 |
+
};
|
| 1508 |
|
| 1509 |
+
let boxPosition = { x: 0, y: 0, z: 0 }; // Always at origin
|
| 1510 |
+
let boxRotation = { x: 0, y: 0, z: 0 };
|
| 1511 |
+
let plyOffset = { x: 0, y: 0, z: 0 };
|
|
|
|
|
|
|
|
|
|
| 1512 |
|
| 1513 |
+
console.log('[preprocessManual] Initial Box setup:');
|
| 1514 |
+
console.log(' boxSize:', boxSize);
|
| 1515 |
+
console.log(' boxPosition:', boxPosition, '(origin)');
|
|
|
|
| 1516 |
|
|
|
|
| 1517 |
|
| 1518 |
+
////////////////END1137
|
| 1519 |
const sceneCenter = {
|
| 1520 |
x: (maxX + minX) / 2,
|
| 1521 |
y: (maxY + minY) / 2,
|
|
|
|
| 1523 |
};
|
| 1524 |
|
| 1525 |
|
|
|
|
|
|
|
| 1526 |
// Display scene info in UI
|
| 1527 |
const sceneSizeEl = document.getElementById('scene-size');
|
| 1528 |
const sceneCenterEl = document.getElementById('scene-center');
|
|
|
|
| 1533 |
sceneCenterEl.textContent = `(${sceneCenter.x.toFixed(1)}, ${sceneCenter.y.toFixed(1)}, ${sceneCenter.z.toFixed(1)})`;
|
| 1534 |
}
|
| 1535 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1536 |
const gsScene = gs.viewer.splatMesh.scenes[0];
|
| 1537 |
|
| 1538 |
// Create initial bounding box
|