stpete2 commited on
Commit
7ecb07b
·
verified ·
1 Parent(s): 595bb43

Upload preprocess_manual.js

Browse files
Files changed (1) hide show
  1. preprocess_manual.js +77 -15
preprocess_manual.js CHANGED
@@ -1315,10 +1315,16 @@ parser.parsePLY(gsPath, true).then((plyData) => {
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
 
@@ -1331,12 +1337,64 @@ parser.parsePLY(gsPath, true).then((plyData) => {
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,
@@ -1358,9 +1416,6 @@ parser.parsePLY(gsPath, true).then((plyData) => {
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),
@@ -1371,9 +1426,10 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1371
  // ⭐ OrbitControlsのターゲットを設定
1372
  cameraControls.controls.target.set(center.x, center.y, center.z);
1373
  cameraControls.controls.update();
1374
- console.log('[preprocessManual] OrbitControls target set to PLY center');
1375
-
1376
- //////////////////////ここまで
 
1377
 
1378
  // ========================================
1379
  // ⭐ 5. Scene bounds の計算と表示
@@ -1405,21 +1461,27 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1405
  }
1406
 
1407
  // ========================================
1408
- // ⭐ 6. 初期Box���定(PLYの中心に配置)
1409
  // ========================================
1410
  let boxSize = {
1411
- x: size.x * 0.5,
1412
- y: size.y * 0.5,
1413
- z: size.z * 0.5
1414
  };
 
1415
  let boxPosition = {
1416
- x: center.x,
1417
- y: center.y,
1418
- z: center.z
1419
  };
 
1420
  let boxRotation = { x: 0, y: 0, z: 0 };
1421
  let plyOffset = { x: 0, y: 0, z: 0 };
1422
 
 
 
 
 
1423
  const gsScene = gs.viewer.splatMesh.scenes[0];
1424
 
1425
  // Create initial bounding box
 
1315
  // ========================================
1316
 
1317
  //////////////////////Line 1377-1391 (カメラ調整部分)
1318
+ ///////////////////////////////////////修正1: Line 1319-1375 を完全に書き換え
1319
 
1320
+ // ========================================
1321
+ // ⭐ 4. カメラをPLYに合わせて調整(cameraControls初期化後)
1322
+ // ========================================
1323
  console.log('[preprocessManual] Auto-aligning camera to PLY...');
1324
 
1325
+ // ⭐⭐⭐ 重要: plyData.vertices が中心化されているはずなので、中心は 0,0,0 付近
1326
+ console.log('[preprocessManual] Verifying PLY centering...');
1327
+
1328
  let minX = Infinity, minY = Infinity, minZ = Infinity;
1329
  let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
1330
 
 
1337
  maxZ = Math.max(maxZ, vertex.z);
1338
  });
1339
 
1340
+ const calculatedCenter = {
1341
  x: (maxX + minX) / 2,
1342
  y: (maxY + minY) / 2,
1343
  z: (maxZ + minZ) / 2
1344
  };
1345
 
1346
+ console.log('[preprocessManual] PLY bounds after centering:');
1347
+ console.log(' Min:', { x: minX.toFixed(3), y: minY.toFixed(3), z: minZ.toFixed(3) });
1348
+ console.log(' Max:', { x: maxX.toFixed(3), y: maxY.toFixed(3), z: maxZ.toFixed(3) });
1349
+ console.log(' Calculated center:', {
1350
+ x: calculatedCenter.x.toFixed(3),
1351
+ y: calculatedCenter.y.toFixed(3),
1352
+ z: calculatedCenter.z.toFixed(3)
1353
+ });
1354
+
1355
+ // ⭐⭐⭐ 検証: 中心が 0,0,0 から離れすぎている場合
1356
+ if (Math.abs(calculatedCenter.x) > 0.1 ||
1357
+ Math.abs(calculatedCenter.y) > 0.1 ||
1358
+ Math.abs(calculatedCenter.z) > 0.1) {
1359
+ console.error('[preprocessManual] ❌ ERROR: PLY centering failed!');
1360
+ console.error('[preprocessManual] Expected center ~(0,0,0) but got:', calculatedCenter);
1361
+ console.error('[preprocessManual] This indicates Step 1 did not work correctly!');
1362
+
1363
+ // ⭐ 緊急対策: ここで強制的に中心化
1364
+ console.log('[preprocessManual] Force re-centering PLY...');
1365
+ plyData.vertices.forEach(vertex => {
1366
+ vertex.x -= calculatedCenter.x;
1367
+ vertex.y -= calculatedCenter.y;
1368
+ vertex.z -= calculatedCenter.z;
1369
+ });
1370
+
1371
+ // 再計算
1372
+ minX = Infinity; minY = Infinity; minZ = Infinity;
1373
+ maxX = -Infinity; maxY = -Infinity; maxZ = -Infinity;
1374
+
1375
+ plyData.vertices.forEach(vertex => {
1376
+ minX = Math.min(minX, vertex.x);
1377
+ minY = Math.min(minY, vertex.y);
1378
+ minZ = Math.min(minZ, vertex.z);
1379
+ maxX = Math.max(maxX, vertex.x);
1380
+ maxY = Math.max(maxY, vertex.y);
1381
+ maxZ = Math.max(maxZ, vertex.z);
1382
+ });
1383
+
1384
+ calculatedCenter.x = (maxX + minX) / 2;
1385
+ calculatedCenter.y = (maxY + minY) / 2;
1386
+ calculatedCenter.z = (maxZ + minZ) / 2;
1387
+
1388
+ console.log('[preprocessManual] After force re-centering:', {
1389
+ x: calculatedCenter.x.toFixed(6),
1390
+ y: calculatedCenter.y.toFixed(6),
1391
+ z: calculatedCenter.z.toFixed(6)
1392
+ });
1393
+ }
1394
+
1395
+ // ⭐ カメラ配置は 0,0,0 を中心にする
1396
+ const center = { x: 0, y: 0, z: 0 };
1397
+
1398
  const size = {
1399
  x: maxX - minX,
1400
  y: maxY - minY,
 
1416
  camera.lookAt(center.x, center.y, center.z);
1417
  camera.updateProjectionMatrix();
1418
 
 
 
 
1419
  console.log('[preprocessManual] Camera positioned at:', {
1420
  x: camera.position.x.toFixed(2),
1421
  y: camera.position.y.toFixed(2),
 
1426
  // ⭐ OrbitControlsのターゲットを設定
1427
  cameraControls.controls.target.set(center.x, center.y, center.z);
1428
  cameraControls.controls.update();
1429
+ console.log('[preprocessManual] OrbitControls target set to origin');
1430
+
1431
+ ///////////////////////////////////////修正1: Line 1319-1375 を完全に書き換え
1432
+
1433
 
1434
  // ========================================
1435
  // ⭐ 5. Scene bounds の計算と表示
 
1461
  }
1462
 
1463
  // ========================================
1464
+ // ⭐ 6. 初期Box設定(中心化後のPLYに合わせる)
1465
  // ========================================
1466
  let boxSize = {
1467
+ x: size.x * 1.2, // 120% (余裕を持たせる)
1468
+ y: size.y * 1.2,
1469
+ z: size.z * 1.2
1470
  };
1471
+
1472
  let boxPosition = {
1473
+ x: 0, // ⭐ 明示的に 0,0,0
1474
+ y: 0,
1475
+ z: 0
1476
  };
1477
+
1478
  let boxRotation = { x: 0, y: 0, z: 0 };
1479
  let plyOffset = { x: 0, y: 0, z: 0 };
1480
 
1481
+ console.log('[preprocessManual] Initial Box setup:');
1482
+ console.log(' boxSize:', boxSize);
1483
+ console.log(' boxPosition:', boxPosition);
1484
+
1485
  const gsScene = gs.viewer.splatMesh.scenes[0];
1486
 
1487
  // Create initial bounding box