stpete2 commited on
Commit
38b192e
·
verified ·
1 Parent(s): 7e0b659

Upload preprocess_manual.js

Browse files
Files changed (1) hide show
  1. preprocess_manual.js +353 -270
preprocess_manual.js CHANGED
@@ -773,7 +773,6 @@ function downloadPLY(plyData, filename) {
773
 
774
  //////////////////////////////////////////////12/14 13:40 end
775
 
776
- ///////////////////////////////////////////////////12/13 14:00
777
 
778
  // ========================================
779
  // Keyboard Controls - Global Variables and Helper Functions
@@ -1182,16 +1181,73 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1182
  console.log(' Center:', defaultBoxPosition);
1183
  console.log(' Raw size:', { x: sizeX, y: sizeY, z: sizeZ });
1184
 
1185
- // GSの初期表示, 1216 12:20
1186
- GVRM.initGS(gsPath, undefined, undefined, scene).then((gs) => {
1187
-
1188
- ///start
1189
 
 
 
 
 
 
1190
 
 
 
 
1191
  console.log('[preprocessManual] GS initialized');
1192
 
1193
  // ========================================
1194
- // ⭐ カメラをPLYに合わせて調整
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1195
  // ========================================
1196
  console.log('[preprocessManual] Auto-aligning camera to PLY...');
1197
 
@@ -1222,15 +1278,13 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1222
 
1223
  const maxDim = Math.max(size.x, size.y, size.z);
1224
 
1225
- // カメラ位置を計算(PLYの中心から適切な距離)
1226
- const distance = maxDim * 2.0; // 点群全体が見える距離
1227
 
1228
- // ⭐ 重要: カメラをPLYの「正面」に配置
1229
- // Y軸が上、Z軸が前方になるように配置
1230
  camera.position.set(
1231
- center.x, // X: 中心
1232
- center.y + maxDim * 0.3, // Y: 少し上から
1233
- center.z + distance // Z: 前方から
1234
  );
1235
 
1236
  camera.lookAt(center.x, center.y, center.z);
@@ -1243,20 +1297,45 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1243
  });
1244
  console.log('[preprocessManual] Looking at:', center);
1245
 
1246
- // OrbitControlsのターゲットも設定
1247
- if (cameraControls && cameraControls.controls) {
1248
- cameraControls.controls.target.set(center.x, center.y, center.z);
1249
- cameraControls.controls.update();
1250
- console.log('[preprocessManual] OrbitControls target set to PLY center');
1251
- }
1252
 
1253
  // ========================================
1254
- // ⭐ 初期Boxもこの向きに合わせる
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1255
  // ========================================
1256
-
1257
- // 初期Box設定(PLYの中心に配置)
1258
  let boxSize = {
1259
- x: size.x * 0.5, // 初期値: PLYの50%サイズ
1260
  y: size.y * 0.5,
1261
  z: size.z * 0.5
1262
  };
@@ -1265,9 +1344,17 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1265
  y: center.y,
1266
  z: center.z
1267
  };
 
1268
  let plyOffset = { x: 0, y: 0, z: 0 };
1269
-
1270
- // UIのスライダーの初期値も更新
 
 
 
 
 
 
 
1271
  if (document.getElementById('box-x-step0')) {
1272
  document.getElementById('box-x-step0').value = boxSize.x.toFixed(1);
1273
  document.getElementById('box-x-value-step0').textContent = boxSize.x.toFixed(1);
@@ -1290,251 +1377,150 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1290
  console.log('[preprocessManual] UI sliders initialized to PLY-aligned values');
1291
  }
1292
 
1293
- const gsScene = gs.viewer.splatMesh.scenes[0];
1294
-
1295
- // Create initial bounding box(PLYの中心に配置)
1296
- ui.createBoundingBox(boxSize, boxPosition);
1297
 
1298
  console.log('[preprocessManual] ✓ Camera and Box aligned to PLY');
1299
-
1300
-
1301
 
1302
-
1303
- // ★★★ ADD CAMERA CONTROLS HERE ★★★
1304
- const cameraControls = setupCameraControls(camera, renderer);
1305
-
1306
- // ⭐ Initialize keyboard controls 12/13 14:00
1307
- setupKeyboardControls();
1308
-
1309
- // Animation loop for smooth camera controls
1310
- let animationId = null;
1311
- function animateControls() {
1312
- animationId = requestAnimationFrame(animateControls);
1313
- updateCameraFromKeys(camera, cameraControls);
1314
- cameraControls.controls.update();
1315
- renderer.render(scene, camera);
1316
- }
1317
-
1318
- animateControls();
1319
 
1320
- // Cleanup function to stop animation
1321
- const cleanupAnimation = () => {
1322
- if (animationId) {
1323
- cancelAnimationFrame(animationId);
1324
- animationId = null;
 
 
 
 
 
 
 
1325
  }
1326
  };
1327
-
1328
- //////////////// handle key 12/13 13:30
1329
-
1330
-
1331
- // ========================================
1332
- // Step 0: Box and PLY Position Adjustment
1333
- // ========================================
1334
-
1335
- ui.setStatus('Step 0: Adjust bounding box to frame your object');
1336
- ui.showPositionAdjustment();
1337
 
1338
-
1339
-
1340
- plyData.vertices.forEach(vertex => {
1341
- minX = Math.min(minX, vertex.x);
1342
- minY = Math.min(minY, vertex.y);
1343
- minZ = Math.min(minZ, vertex.z);
1344
- maxX = Math.max(maxX, vertex.x);
1345
- maxY = Math.max(maxY, vertex.y);
1346
- maxZ = Math.max(maxZ, vertex.z);
 
 
1347
  });
 
 
1348
 
1349
- const sceneSize = {
1350
- x: maxX - minX,
1351
- y: maxY - minY,
1352
- z: maxZ - minZ
1353
- };
1354
- const sceneCenter = {
1355
- x: (maxX + minX) / 2,
1356
- y: (maxY + minY) / 2,
1357
- z: (maxZ + minZ) / 2
1358
- };
1359
-
1360
- console.log('[preprocessManual] Scene bounds:', {
1361
- size: sceneSize,
1362
- center: sceneCenter
1363
  });
 
 
1364
 
1365
- // Display scene info in UI
1366
- const sceneSizeEl = document.getElementById('scene-size');
1367
- const sceneCenterEl = document.getElementById('scene-center');
1368
- if (sceneSizeEl) {
1369
- sceneSizeEl.textContent = `${sceneSize.x.toFixed(1)}m × ${sceneSize.y.toFixed(1)}m × ${sceneSize.z.toFixed(1)}m`;
1370
- }
1371
- if (sceneCenterEl) {
1372
- sceneCenterEl.textContent = `(${sceneCenter.x.toFixed(1)}, ${sceneCenter.y.toFixed(1)}, ${sceneCenter.z.toFixed(1)})`;
1373
- }
1374
-
1375
-
1376
-
1377
- // Create initial bounding box
1378
- ui.createBoundingBox(boxSize, boxPosition);
1379
-
1380
-
1381
 
1382
- // Box size sliders
1383
- // Box size sliders
1384
- const setupBoxSizeSlider = (id, valueId, axis) => {
1385
- const slider = document.getElementById(id);
1386
- const valueDisplay = document.getElementById(valueId);
1387
-
1388
- if (slider && valueDisplay) {
1389
- slider.addEventListener('input', (e) => {
1390
- const value = parseFloat(e.target.value);
1391
- valueDisplay.textContent = value.toFixed(1);
1392
- boxSize[axis] = value;
1393
- ui.updateBoundingBox(boxSize, boxPosition, boxRotation); // ⭐ 回転を渡す
1394
- });
1395
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1396
  };
1397
-
1398
- // Box position sliders
1399
- const setupBoxPosSlider = (id, valueId, axis) => {
1400
- const slider = document.getElementById(id);
1401
- const valueDisplay = document.getElementById(valueId);
1402
-
1403
- if (slider && valueDisplay) {
1404
- slider.addEventListener('input', (e) => {
1405
- const value = parseFloat(e.target.value);
1406
- valueDisplay.textContent = value.toFixed(1);
1407
- boxPosition[axis] = value;
1408
- ui.updateBoundingBox(boxSize, boxPosition, boxRotation); // ⭐ 回転を渡す
1409
- });
1410
- }
1411
  };
1412
-
1413
- /////////////////////////12/13 17:15 start
1414
-
1415
- // この変数を追加 (line 1002付近):
1416
- let boxRotation = { x: 0, y: 0, z: 0 };
1417
-
1418
- // Box rotation sliders (setupPlyOffsetSlider の後に追加):
1419
- const setupBoxRotSlider = (id, valueId, axis) => {
1420
- const slider = document.getElementById(id);
1421
- const valueDisplay = document.getElementById(valueId);
1422
-
1423
- if (slider && valueDisplay) {
1424
- slider.addEventListener('input', (e) => {
1425
- const degrees = parseFloat(e.target.value);
1426
- valueDisplay.textContent = degrees.toFixed(0);
1427
- boxRotation[axis] = degrees * Math.PI / 180; // Convert to radians
 
 
 
 
 
 
 
 
 
 
 
1428
  ui.updateBoundingBox(boxSize, boxPosition, boxRotation);
1429
  });
1430
  }
1431
- };
1432
-
1433
- // Setup rotation sliders (setupPlyOffsetSlider の呼び出しの後に追加):
1434
- setupBoxRotSlider('box-rot-y-step0', 'box-rot-y-value-step0', 'y');
1435
- setupBoxRotSlider('box-rot-x-step0', 'box-rot-x-value-step0', 'x');
1436
- setupBoxRotSlider('box-rot-z-step0', 'box-rot-z-value-step0', 'z');
1437
-
1438
-
1439
- /////////////////////////12/13 17:15 end
1440
-
1441
- // PLY offset sliders
1442
- const setupPlyOffsetSlider = (id, valueId, axis) => {
1443
- const slider = document.getElementById(id);
1444
- const valueDisplay = document.getElementById(valueId);
1445
-
1446
- if (slider && valueDisplay) {
1447
- slider.addEventListener('input', (e) => {
1448
- const value = parseFloat(e.target.value);
1449
- valueDisplay.textContent = value.toFixed(1);
1450
- plyOffset[axis] = value;
1451
- gsScene.position[axis] = value;
1452
- gsScene.updateMatrixWorld();
1453
- });
1454
- }
1455
- };
1456
-
1457
- // Setup all sliders
1458
- setupBoxSizeSlider('box-x-step0', 'box-x-value-step0', 'x');
1459
- setupBoxSizeSlider('box-y-step0', 'box-y-value-step0', 'y');
1460
- setupBoxSizeSlider('box-z-step0', 'box-z-value-step0', 'z');
1461
-
1462
- setupBoxPosSlider('box-x-pos-step0', 'box-x-pos-value-step0', 'x');
1463
- setupBoxPosSlider('box-y-pos-step0', 'box-y-pos-value-step0', 'y');
1464
- setupBoxPosSlider('box-z-pos-step0', 'box-z-pos-value-step0', 'z');
1465
-
1466
- setupPlyOffsetSlider('ply-x', 'ply-x-value', 'x');
1467
- setupPlyOffsetSlider('ply-y', 'ply-y-value', 'y');
1468
- setupPlyOffsetSlider('ply-z', 'ply-z-value', 'z');
1469
-
1470
-
1471
- /////////////////////////12/13 17:15 start
1472
- // Reset button
1473
- const resetAllBtn = document.getElementById('reset-all-btn');
1474
- if (resetAllBtn) {
1475
- resetAllBtn.addEventListener('click', () => {
1476
-
1477
-
1478
- // Reset rotation addition ########
1479
- boxRotation = { x: 0, y: 0, z: 0 };
1480
- document.getElementById('box-rot-y-step0').value = 0;
1481
- document.getElementById('box-rot-x-step0').value = 0;
1482
- document.getElementById('box-rot-z-step0').value = 0;
1483
- document.getElementById('box-rot-y-value-step0').textContent = '0';
1484
- document.getElementById('box-rot-x-value-step0').textContent = '0';
1485
- document.getElementById('box-rot-z-value-step0').textContent = '0';
1486
-
1487
-
1488
- // Reset box
1489
- boxSize = { x: 3, y: 3, z: 3 };
1490
- boxPosition = { x: 0, y: 0, z: 0 }; // ← y: 1 から y: 0 に変更
1491
- document.getElementById('box-x-step0').value = 3;
1492
- document.getElementById('box-y-step0').value = 3;
1493
- document.getElementById('box-z-step0').value = 3;
1494
- document.getElementById('box-x-value-step0').textContent = '3.0';
1495
- document.getElementById('box-y-value-step0').textContent = '3.0';
1496
- document.getElementById('box-z-value-step0').textContent = '3.0';
1497
-
1498
- document.getElementById('box-x-pos-step0').value = 0;
1499
- document.getElementById('box-y-pos-step0').value = 0; // ← 1 から 0 に変更
1500
- document.getElementById('box-z-pos-step0').value = 0;
1501
- document.getElementById('box-x-pos-value-step0').textContent = '0.0';
1502
- document.getElementById('box-y-pos-value-step0').textContent = '0.0'; // ← '1.0' から '0.0' に変更
1503
- document.getElementById('box-z-pos-value-step0').textContent = '0.0';
1504
-
1505
- // Reset PLY offset
1506
- plyOffset = { x: 0, y: 0, z: 0 };
1507
- document.getElementById('ply-x').value = 0;
1508
- document.getElementById('ply-y').value = 0;
1509
- document.getElementById('ply-z').value = 0;
1510
- document.getElementById('ply-x-value').textContent = '0.0';
1511
- document.getElementById('ply-y-value').textContent = '0.0';
1512
- document.getElementById('ply-z-value').textContent = '0.0';
1513
-
1514
- gsScene.position.set(0, 0, 0);
1515
- gsScene.updateMatrixWorld();
1516
- ui.updateBoundingBox(boxSize, boxPosition, boxRotation); // ⭐ 最後の引数を追加
1517
- });
1518
- }
1519
- /////////////////////////12/13 17:15 end
1520
-
1521
- // Confirm button
1522
 
1523
- // ----------------------------------------
1524
- // 完全版: confirmBoxBtn のイベントリスナー
1525
- // Line 1107から約100行を以下に置き換え
1526
- // ----------------------------------------
1527
- /////////////////// 12/15 18:00 全面描き直し
1528
-
1529
- // ========================================
1530
- // 修正版 confirmBoxBtn(完全なデバッグ版)
1531
- // Line 1090-1220付近を置き換え
1532
- // ========================================
1533
 
1534
- // ========================================
1535
- // 修正版 confirmBoxBtn (変数スコープ修正)
1536
- // Line 1378付近 の confirmBoxBtn.addEventListener 全体を置き換え
1537
- // ========================================
1538
 
1539
  const confirmBoxBtn = document.getElementById('confirm-box-btn');
1540
  if (confirmBoxBtn) {
@@ -1646,27 +1632,121 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1646
  ui.hidePositionAdjustment();
1647
  ui.setStatus('Filtering splats with bounding box...');
1648
 
1649
- // フィルタリング実行
1650
- console.log('[STEP 4] Starting filtering...');
1651
- console.log('[STEP 4] Using plyData with', plyData.vertices.length, 'vertices');
1652
 
1653
- // デバッグ: フィルタリング前の座標範囲を確認
1654
- let preMinX = Infinity, preMinY = Infinity, preMinZ = Infinity;
1655
- let preMaxX = -Infinity, preMaxY = -Infinity, preMaxZ = -Infinity;
1656
 
1657
- plyData.vertices.forEach(v => {
1658
- preMinX = Math.min(preMinX, v.x);
1659
- preMinY = Math.min(preMinY, v.y);
1660
- preMinZ = Math.min(preMinZ, v.z);
1661
- preMaxX = Math.max(preMaxX, v.x);
1662
- preMaxY = Math.max(preMaxY, v.y);
1663
- preMaxZ = Math.max(preMaxZ, v.z);
1664
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1665
 
1666
- console.log('[STEP 4] Pre-filter bounds:');
1667
- console.log(' X:', preMinX.toFixed(3), 'to', preMaxX.toFixed(3));
1668
- console.log(' Y:', preMinY.toFixed(3), 'to', preMaxY.toFixed(3));
1669
- console.log(' Z:', preMinZ.toFixed(3), 'to', preMaxZ.toFixed(3));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1670
 
1671
  // ⭐⭐⭐ 修正: currentBoxSize, currentBoxPosition, currentBoxRotation を使用 ⭐⭐⭐
1672
  console.log('[STEP 4] ⭐ Calling filterSplatsByBox with CURRENT values from UI');
@@ -1820,7 +1900,10 @@ parser.parsePLY(gsPath, true).then((plyData) => {
1820
 
1821
  ////////////////// 12/15 18:00 全面描き直し
1822
 
1823
- }); // GVRM.initGS().then()閉じる
 
 
 
1824
  }); // parser.parsePLY().then()閉じる
1825
  }); // ui.initialize().then()閉じる
1826
 
 
773
 
774
  //////////////////////////////////////////////12/14 13:40 end
775
 
 
776
 
777
  // ========================================
778
  // Keyboard Controls - Global Variables and Helper Functions
 
1181
  console.log(' Center:', defaultBoxPosition);
1182
  console.log(' Raw size:', { x: sizeX, y: sizeY, z: sizeZ });
1183
 
 
 
 
 
1184
 
1185
+ // ========================================
1186
+ // 修正版 初期化順序
1187
+ // GVRM.initGS() 部分を置き換え 12/16 12:50
1188
+ // Line 1187付近
1189
+ // ========================================
1190
 
1191
+ /////////////////////////////////////////15:01
1192
+ // GSの初期表示
1193
+ GVRM.initGS(gsPath, undefined, undefined, scene).then((gs) => {
1194
  console.log('[preprocessManual] GS initialized');
1195
 
1196
  // ========================================
1197
+ // ⭐ PLY補正が適用されている場合、GSにも同じ変換を適用
1198
+ // ========================================
1199
+ if (window.plyAlignmentApplied && window.plyAlignmentMatrix) {
1200
+ console.log('[preprocessManual] Applying alignment transform to GS display...');
1201
+
1202
+ const gsScene = gs.viewer.splatMesh.scenes[0];
1203
+
1204
+ // 補正行列をGS Sceneに適用
1205
+ gsScene.matrixAutoUpdate = false;
1206
+ gsScene.matrix.copy(window.plyAlignmentMatrix);
1207
+ gsScene.matrixWorldNeedsUpdate = true;
1208
+ gsScene.updateMatrixWorld(true);
1209
+
1210
+ console.log('[preprocessManual] ✓ GS display aligned with PLY data');
1211
+ console.log('[preprocessManual] GS Scene matrix:', gsScene.matrix.elements.slice(0, 4));
1212
+ } else {
1213
+ console.log('[preprocessManual] No alignment transform needed for GS');
1214
+ }
1215
+
1216
+ // ========================================
1217
+ // ⭐ 1. まずカメラコントロールを初期化
1218
+ // ========================================
1219
+ const cameraControls = setupCameraControls(camera, renderer);
1220
+ console.log('[preprocessManual] Camera controls initialized');
1221
+
1222
+ // ========================================
1223
+ // ⭐ 2. キーボードコントロールを初期化
1224
+ // ========================================
1225
+ setupKeyboardControls();
1226
+ console.log('[preprocessManual] Keyboard controls initialized');
1227
+
1228
+ // ========================================
1229
+ // ⭐ 3. アニメーションループを開始
1230
+ // ========================================
1231
+ let animationId = null;
1232
+ function animateControls() {
1233
+ animationId = requestAnimationFrame(animateControls);
1234
+ updateCameraFromKeys(camera, cameraControls);
1235
+ cameraControls.controls.update();
1236
+ renderer.render(scene, camera);
1237
+ }
1238
+
1239
+ animateControls();
1240
+
1241
+ // Cleanup function to stop animation
1242
+ const cleanupAnimation = () => {
1243
+ if (animationId) {
1244
+ cancelAnimationFrame(animationId);
1245
+ animationId = null;
1246
+ }
1247
+ };
1248
+
1249
+ // ========================================
1250
+ // ⭐ 4. カメラをPLYに合わせて調整(cameraControls初期化後)
1251
  // ========================================
1252
  console.log('[preprocessManual] Auto-aligning camera to PLY...');
1253
 
 
1278
 
1279
  const maxDim = Math.max(size.x, size.y, size.z);
1280
 
1281
+ // カメラ位置を計算
1282
+ const distance = maxDim * 2.0;
1283
 
 
 
1284
  camera.position.set(
1285
+ center.x,
1286
+ center.y + maxDim * 0.3,
1287
+ center.z + distance
1288
  );
1289
 
1290
  camera.lookAt(center.x, center.y, center.z);
 
1297
  });
1298
  console.log('[preprocessManual] Looking at:', center);
1299
 
1300
+ // OrbitControlsのターゲットを設定(cameraControlsが存在することを確認済み)
1301
+ cameraControls.controls.target.set(center.x, center.y, center.z);
1302
+ cameraControls.controls.update();
1303
+ console.log('[preprocessManual] OrbitControls target set to PLY center');
 
 
1304
 
1305
  // ========================================
1306
+ // ⭐ 5. Scene bounds の計算と表示
1307
+ // ========================================
1308
+ const sceneSize = {
1309
+ x: maxX - minX,
1310
+ y: maxY - minY,
1311
+ z: maxZ - minZ
1312
+ };
1313
+ const sceneCenter = {
1314
+ x: (maxX + minX) / 2,
1315
+ y: (maxY + minY) / 2,
1316
+ z: (maxZ + minZ) / 2
1317
+ };
1318
+
1319
+ console.log('[preprocessManual] Scene bounds:', {
1320
+ size: sceneSize,
1321
+ center: sceneCenter
1322
+ });
1323
+
1324
+ // Display scene info in UI
1325
+ const sceneSizeEl = document.getElementById('scene-size');
1326
+ const sceneCenterEl = document.getElementById('scene-center');
1327
+ if (sceneSizeEl) {
1328
+ sceneSizeEl.textContent = `${sceneSize.x.toFixed(1)}m × ${sceneSize.y.toFixed(1)}m × ${sceneSize.z.toFixed(1)}m`;
1329
+ }
1330
+ if (sceneCenterEl) {
1331
+ sceneCenterEl.textContent = `(${sceneCenter.x.toFixed(1)}, ${sceneCenter.y.toFixed(1)}, ${sceneCenter.z.toFixed(1)})`;
1332
+ }
1333
+
1334
+ // ========================================
1335
+ // ⭐ 6. 初期Box設定(PLYの中心に配置)
1336
  // ========================================
 
 
1337
  let boxSize = {
1338
+ x: size.x * 0.5,
1339
  y: size.y * 0.5,
1340
  z: size.z * 0.5
1341
  };
 
1344
  y: center.y,
1345
  z: center.z
1346
  };
1347
+ let boxRotation = { x: 0, y: 0, z: 0 };
1348
  let plyOffset = { x: 0, y: 0, z: 0 };
1349
+
1350
+ const gsScene = gs.viewer.splatMesh.scenes[0];
1351
+
1352
+ // Create initial bounding box
1353
+ ui.createBoundingBox(boxSize, boxPosition, boxRotation);
1354
+
1355
+ // ========================================
1356
+ // ⭐ 7. UIスライダーの初期値を更新
1357
+ // ========================================
1358
  if (document.getElementById('box-x-step0')) {
1359
  document.getElementById('box-x-step0').value = boxSize.x.toFixed(1);
1360
  document.getElementById('box-x-value-step0').textContent = boxSize.x.toFixed(1);
 
1377
  console.log('[preprocessManual] UI sliders initialized to PLY-aligned values');
1378
  }
1379
 
1380
+ ui.setStatus('Step 0: Adjust bounding box to frame your object');
1381
+ ui.showPositionAdjustment();
 
 
1382
 
1383
  console.log('[preprocessManual] ✓ Camera and Box aligned to PLY');
 
 
1384
 
1385
+ // ========================================
1386
+ // 8. 以降は元のコード(スライダー設定など)
1387
+ // ========================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1388
 
1389
+ // Box size sliders
1390
+ const setupBoxSizeSlider = (id, valueId, axis) => {
1391
+ const slider = document.getElementById(id);
1392
+ const valueDisplay = document.getElementById(valueId);
1393
+
1394
+ if (slider && valueDisplay) {
1395
+ slider.addEventListener('input', (e) => {
1396
+ const value = parseFloat(e.target.value);
1397
+ valueDisplay.textContent = value.toFixed(1);
1398
+ boxSize[axis] = value;
1399
+ ui.updateBoundingBox(boxSize, boxPosition, boxRotation);
1400
+ });
1401
  }
1402
  };
 
 
 
 
 
 
 
 
 
 
1403
 
1404
+ // Box position sliders
1405
+ const setupBoxPosSlider = (id, valueId, axis) => {
1406
+ const slider = document.getElementById(id);
1407
+ const valueDisplay = document.getElementById(valueId);
1408
+
1409
+ if (slider && valueDisplay) {
1410
+ slider.addEventListener('input', (e) => {
1411
+ const value = parseFloat(e.target.value);
1412
+ valueDisplay.textContent = value.toFixed(1);
1413
+ boxPosition[axis] = value;
1414
+ ui.updateBoundingBox(boxSize, boxPosition, boxRotation);
1415
  });
1416
+ }
1417
+ };
1418
 
1419
+ // Box rotation sliders
1420
+ const setupBoxRotSlider = (id, valueId, axis) => {
1421
+ const slider = document.getElementById(id);
1422
+ const valueDisplay = document.getElementById(valueId);
1423
+
1424
+ if (slider && valueDisplay) {
1425
+ slider.addEventListener('input', (e) => {
1426
+ const degrees = parseFloat(e.target.value);
1427
+ valueDisplay.textContent = degrees.toFixed(0);
1428
+ boxRotation[axis] = degrees * Math.PI / 180;
1429
+ ui.updateBoundingBox(boxSize, boxPosition, boxRotation);
 
 
 
1430
  });
1431
+ }
1432
+ };
1433
 
1434
+ // PLY offset sliders
1435
+ const setupPlyOffsetSlider = (id, valueId, axis) => {
1436
+ const slider = document.getElementById(id);
1437
+ const valueDisplay = document.getElementById(valueId);
1438
+
1439
+ if (slider && valueDisplay) {
1440
+ slider.addEventListener('input', (e) => {
1441
+ const value = parseFloat(e.target.value);
1442
+ valueDisplay.textContent = value.toFixed(1);
1443
+ plyOffset[axis] = value;
1444
+ gsScene.position[axis] = value;
1445
+ gsScene.updateMatrixWorld();
1446
+ });
1447
+ }
1448
+ };
 
1449
 
1450
+ // Setup all sliders
1451
+ setupBoxSizeSlider('box-x-step0', 'box-x-value-step0', 'x');
1452
+ setupBoxSizeSlider('box-y-step0', 'box-y-value-step0', 'y');
1453
+ setupBoxSizeSlider('box-z-step0', 'box-z-value-step0', 'z');
1454
+
1455
+ setupBoxPosSlider('box-x-pos-step0', 'box-x-pos-value-step0', 'x');
1456
+ setupBoxPosSlider('box-y-pos-step0', 'box-y-pos-value-step0', 'y');
1457
+ setupBoxPosSlider('box-z-pos-step0', 'box-z-pos-value-step0', 'z');
1458
+
1459
+ setupBoxRotSlider('box-rot-y-step0', 'box-rot-y-value-step0', 'y');
1460
+ setupBoxRotSlider('box-rot-x-step0', 'box-rot-x-value-step0', 'x');
1461
+ setupBoxRotSlider('box-rot-z-step0', 'box-rot-z-value-step0', 'z');
1462
+
1463
+ setupPlyOffsetSlider('ply-x', 'ply-x-value', 'x');
1464
+ setupPlyOffsetSlider('ply-y', 'ply-y-value', 'y');
1465
+ setupPlyOffsetSlider('ply-z', 'ply-z-value', 'z');
1466
+
1467
+ // Reset button
1468
+ const resetAllBtn = document.getElementById('reset-all-btn');
1469
+ if (resetAllBtn) {
1470
+ resetAllBtn.addEventListener('click', () => {
1471
+ // Reset rotation
1472
+ boxRotation = { x: 0, y: 0, z: 0 };
1473
+ document.getElementById('box-rot-y-step0').value = 0;
1474
+ document.getElementById('box-rot-x-step0').value = 0;
1475
+ document.getElementById('box-rot-z-step0').value = 0;
1476
+ document.getElementById('box-rot-y-value-step0').textContent = '0';
1477
+ document.getElementById('box-rot-x-value-step0').textContent = '0';
1478
+ document.getElementById('box-rot-z-value-step0').textContent = '0';
1479
+
1480
+ // Reset box to PLY-aligned defaults
1481
+ boxSize = {
1482
+ x: size.x * 0.5,
1483
+ y: size.y * 0.5,
1484
+ z: size.z * 0.5
1485
  };
1486
+ boxPosition = {
1487
+ x: center.x,
1488
+ y: center.y,
1489
+ z: center.z
 
 
 
 
 
 
 
 
 
 
1490
  };
1491
+
1492
+ // Update UI
1493
+ document.getElementById('box-x-step0').value = boxSize.x.toFixed(1);
1494
+ document.getElementById('box-y-step0').value = boxSize.y.toFixed(1);
1495
+ document.getElementById('box-z-step0').value = boxSize.z.toFixed(1);
1496
+ document.getElementById('box-x-value-step0').textContent = boxSize.x.toFixed(1);
1497
+ document.getElementById('box-y-value-step0').textContent = boxSize.y.toFixed(1);
1498
+ document.getElementById('box-z-value-step0').textContent = boxSize.z.toFixed(1);
1499
+
1500
+ document.getElementById('box-x-pos-step0').value = boxPosition.x.toFixed(1);
1501
+ document.getElementById('box-y-pos-step0').value = boxPosition.y.toFixed(1);
1502
+ document.getElementById('box-z-pos-step0').value = boxPosition.z.toFixed(1);
1503
+ document.getElementById('box-x-pos-value-step0').textContent = boxPosition.x.toFixed(1);
1504
+ document.getElementById('box-y-pos-value-step0').textContent = boxPosition.y.toFixed(1);
1505
+ document.getElementById('box-z-pos-value-step0').textContent = boxPosition.z.toFixed(1);
1506
+
1507
+ // Reset PLY offset
1508
+ plyOffset = { x: 0, y: 0, z: 0 };
1509
+ document.getElementById('ply-x').value = 0;
1510
+ document.getElementById('ply-y').value = 0;
1511
+ document.getElementById('ply-z').value = 0;
1512
+ document.getElementById('ply-x-value').textContent = '0.0';
1513
+ document.getElementById('ply-y-value').textContent = '0.0';
1514
+ document.getElementById('ply-z-value').textContent = '0.0';
1515
+
1516
+ gsScene.position.set(0, 0, 0);
1517
+ gsScene.updateMatrixWorld();
1518
  ui.updateBoundingBox(boxSize, boxPosition, boxRotation);
1519
  });
1520
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1521
 
 
 
 
 
 
 
 
 
 
 
1522
 
1523
+ ////////////////////////////////////////////////これの上が書き換えられる
 
 
 
1524
 
1525
  const confirmBoxBtn = document.getElementById('confirm-box-btn');
1526
  if (confirmBoxBtn) {
 
1632
  ui.hidePositionAdjustment();
1633
  ui.setStatus('Filtering splats with bounding box...');
1634
 
 
 
 
1635
 
1636
+ ///////////////////////////////13:47
 
 
1637
 
1638
+ // ⭐⭐⭐ 重要: gs.centers0 を使用してフィルタリング ⭐⭐⭐
1639
+ // plyData.vertices ではなく、実際に表示されている座標を使う
1640
+
1641
+ console.log('[STEP 4] Using gs.centers0 (displayed coordinates) for filtering');
1642
+
1643
+ // gs.centers0 から vertices 配列を作成
1644
+ const displayedVertices = [];
1645
+ for (let i = 0; i < gs.splatCount; i++) {
1646
+ displayedVertices.push({
1647
+ x: gs.centers0[i * 3 + 0],
1648
+ y: gs.centers0[i * 3 + 1],
1649
+ z: gs.centers0[i * 3 + 2],
1650
+ // 元のインデックスを保持(後で元のデータを参照するため)
1651
+ originalIndex: i
1652
+ });
1653
+ }
1654
+
1655
+ console.log('[STEP 4] Created displayedVertices array:', displayedVertices.length, 'vertices');
1656
+
1657
+ // ⭐ GS Scene の変換を考慮
1658
+ const gsScene = gs.viewer.splatMesh.scenes[0];
1659
+ gsScene.updateMatrixWorld(true);
1660
+
1661
+ console.log('[STEP 4] GS Scene transform:');
1662
+ console.log(' Position:', gsScene.position);
1663
+ console.log(' Rotation:', gsScene.rotation);
1664
+ console.log(' Scale:', gsScene.scale);
1665
+
1666
+ // ワールド座標に変換されたBox設定を使用
1667
+ const boxWorldPosition = new THREE.Vector3(
1668
+ currentBoxPosition.x,
1669
+ currentBoxPosition.y,
1670
+ currentBoxPosition.z
1671
+ );
1672
+
1673
+ // GS Scene の逆変換を適用(BoxをGSのローカル空間に変換)
1674
+ const gsInverseMatrix = new THREE.Matrix4().copy(gsScene.matrixWorld).invert();
1675
+ boxWorldPosition.applyMatrix4(gsInverseMatrix);
1676
+
1677
+ console.log('[STEP 4] Box position in GS local space:', {
1678
+ x: boxWorldPosition.x.toFixed(3),
1679
+ y: boxWorldPosition.y.toFixed(3),
1680
+ z: boxWorldPosition.z.toFixed(3)
1681
+ });
1682
 
1683
+ // ⭐⭐⭐ 修正版フィルタリング関数を呼び出し ⭐⭐⭐
1684
+ function filterDisplayedSplats(vertices, boxSize, boxPosition, boxRotation) {
1685
+ console.log('[filterDisplayedSplats] Filtering', vertices.length, 'vertices');
1686
+ console.log('[filterDisplayedSplats] Box settings:', {
1687
+ size: boxSize,
1688
+ position: boxPosition,
1689
+ rotation: {
1690
+ x: (boxRotation.x * 180 / Math.PI).toFixed(1) + '°',
1691
+ y: (boxRotation.y * 180 / Math.PI).toFixed(1) + '°',
1692
+ z: (boxRotation.z * 180 / Math.PI).toFixed(1) + '°'
1693
+ }
1694
+ });
1695
+
1696
+ const halfX = boxSize.x / 2;
1697
+ const halfY = boxSize.y / 2;
1698
+ const halfZ = boxSize.z / 2;
1699
+ const epsilon = 0.01;
1700
+
1701
+ // 回転行列
1702
+ const rotationMatrix = new THREE.Matrix4();
1703
+ rotationMatrix.makeRotationFromEuler(new THREE.Euler(boxRotation.x, boxRotation.y, boxRotation.z));
1704
+ const inverseRotationMatrix = new THREE.Matrix4().copy(rotationMatrix).invert();
1705
+
1706
+ // フィルタリング
1707
+ const filtered = vertices.filter((vertex) => {
1708
+ const localPos = new THREE.Vector3(
1709
+ vertex.x - boxPosition.x,
1710
+ vertex.y - boxPosition.y,
1711
+ vertex.z - boxPosition.z
1712
+ );
1713
+
1714
+ localPos.applyMatrix4(inverseRotationMatrix);
1715
+
1716
+ const inside = (
1717
+ localPos.x >= -(halfX + epsilon) && localPos.x <= (halfX + epsilon) &&
1718
+ localPos.y >= -(halfY + epsilon) && localPos.y <= (halfY + epsilon) &&
1719
+ localPos.z >= -(halfZ + epsilon) && localPos.z <= (halfZ + epsilon)
1720
+ );
1721
+
1722
+ return inside;
1723
+ });
1724
+
1725
+ console.log('[filterDisplayedSplats] Filtered:', filtered.length, '/', vertices.length);
1726
+ console.log('[filterDisplayedSplats] Retention rate:', (filtered.length / vertices.length * 100).toFixed(1), '%');
1727
+
1728
+ return filtered;
1729
+ }
1730
+
1731
+ // ⭐ GS local space でフィルタリング
1732
+ const filteredDisplayed = filterDisplayedSplats(
1733
+ displayedVertices,
1734
+ currentBoxSize,
1735
+ boxWorldPosition, // ← GS local space に変換済み
1736
+ currentBoxRotation
1737
+ );
1738
+
1739
+ if (filteredDisplayed.length === 0) {
1740
+ console.error('[STEP 4] ❌ No splats found in the box!');
1741
+ alert('⚠️ No splats found in the box!\n\nPlease adjust the box size/position and try again.');
1742
+ ui.showPositionAdjustment();
1743
+ return;
1744
+ }
1745
+
1746
+ console.log('[STEP 4] ✓ Filtering complete:', filteredDisplayed.length, 'splats kept');
1747
+
1748
+
1749
+ /////////////////////////////////////13:47
1750
 
1751
  // ⭐⭐⭐ 修正: currentBoxSize, currentBoxPosition, currentBoxRotation を使用 ⭐⭐⭐
1752
  console.log('[STEP 4] ⭐ Calling filterSplatsByBox with CURRENT values from UI');
 
1900
 
1901
  ////////////////// 12/15 18:00 全面描き直し
1902
 
1903
+
1904
+
1905
+
1906
+ }); // GVRM.initGS().then()閉じる
1907
  }); // parser.parsePLY().then()閉じる
1908
  }); // ui.initialize().then()閉じる
1909