stpete2 commited on
Commit
4507f29
·
verified ·
1 Parent(s): 1bdc3d6

Upload preprocess_manual.js

Browse files
Files changed (1) hide show
  1. preprocess_manual.js +77 -63
preprocess_manual.js CHANGED
@@ -523,24 +523,44 @@ function createManualUI(scene, camera, renderer) {
523
  // Line 594付近を置き換え
524
  // ======================================== 20251214 21:20 fix
525
 
 
 
 
 
 
526
  function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0, y: 0, z: 0 }) {
527
  console.log('[filterSplatsByBox] ===== FILTERING START =====');
 
 
 
 
 
 
 
 
 
 
528
 
529
- // ⭐ デバッグコード
530
- console.log('[DEBUG] ALL VERTICES ANALYSIS:');
531
-
532
  const halfX = boxSize.x / 2;
533
  const halfY = boxSize.y / 2;
534
  const halfZ = boxSize.z / 2;
535
 
 
 
 
536
  const rotationMatrix = new THREE.Matrix4();
537
  rotationMatrix.makeRotationFromEuler(new THREE.Euler(boxRotation.x, boxRotation.y, boxRotation.z));
538
  const inverseRotationMatrix = new THREE.Matrix4().copy(rotationMatrix).invert();
539
 
 
 
 
540
  let insideCount = 0;
541
  let outsideCount = 0;
542
- let boundaryVertices = [];
543
 
 
544
  plyData.vertices.forEach((vertex, index) => {
545
  const localPos = new THREE.Vector3(
546
  vertex.x - boxPosition.x,
@@ -578,13 +598,13 @@ function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0,
578
  }
579
  });
580
 
581
- console.log('[DEBUG] Summary:');
582
  console.log(' Inside:', insideCount);
583
  console.log(' Outside:', outsideCount);
584
  console.log(' Boundary vertices (within 0.5m):', boundaryVertices.length);
585
 
586
  if (boundaryVertices.length > 0) {
587
- console.log('[DEBUG] Boundary vertices details:');
588
  boundaryVertices.slice(0, 20).forEach(v => {
589
  console.log(` V${v.index}: world(${v.world.x.toFixed(2)}, ${v.world.y.toFixed(2)}, ${v.world.z.toFixed(2)}) ` +
590
  `→ local(${v.local.x.toFixed(2)}, ${v.local.y.toFixed(2)}, ${v.local.z.toFixed(2)}) ` +
@@ -592,24 +612,7 @@ function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0,
592
  });
593
  }
594
 
595
- // ⭐⭐⭐ ここから元のコードを続ける ⭐⭐⭐
596
- console.log('[filterSplatsByBox] Input parameters:');
597
- console.log(' Box Size:', boxSize);
598
- console.log(' Box Position:', boxPosition);
599
- console.log(' Box Rotation (radians):', boxRotation);
600
- console.log(' Box Rotation (degrees):', {
601
- x: (boxRotation.x * 180 / Math.PI).toFixed(1),
602
- y: (boxRotation.y * 180 / Math.PI).toFixed(1),
603
- z: (boxRotation.z * 180 / Math.PI).toFixed(1)
604
- });
605
- console.log(' Total input vertices:', plyData.vertices.length);
606
-
607
- console.log('[filterSplatsByBox] Box half-extents:', { halfX, halfY, halfZ });
608
- console.log('[filterSplatsByBox] Using epsilon: 0.0001');
609
-
610
- console.log('[filterSplatsByBox] Rotation matrix created');
611
-
612
- // Sample vertices (最初の10個)
613
  console.log('[filterSplatsByBox] Sample vertices (first 10):');
614
  for (let i = 0; i < Math.min(10, plyData.vertices.length); i++) {
615
  const v = plyData.vertices[i];
@@ -629,17 +632,12 @@ function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0,
629
  console.log(` Vertex ${i}:`, {
630
  world: { x: v.x.toFixed(3), y: v.y.toFixed(3), z: v.z.toFixed(3) },
631
  local: { x: localPos.x.toFixed(3), y: localPos.y.toFixed(3), z: localPos.z.toFixed(3) },
632
- inside: inside,
633
- distances: {
634
- x: `${(localPos.x + halfX).toFixed(3)} / ${(halfX - localPos.x).toFixed(3)}`,
635
- y: `${(localPos.y + halfY).toFixed(3)} / ${(halfY - localPos.y).toFixed(3)}`,
636
- z: `${(localPos.z + halfZ).toFixed(3)} / ${(halfZ - localPos.z).toFixed(3)}`
637
- }
638
  });
639
  }
640
 
641
  // ⭐⭐⭐ 実際のフィルタリング ⭐⭐⭐
642
- const filteredVertices = plyData.vertices.filter((vertex, index) => {
643
  const localPos = new THREE.Vector3(
644
  vertex.x - boxPosition.x,
645
  vertex.y - boxPosition.y,
@@ -694,32 +692,7 @@ function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0,
694
  Math.abs(boxRotation.y) > 0.01 ||
695
  Math.abs(boxRotation.z) > 0.01;
696
 
697
- if (!hasRotation) {
698
- const expectedMinX = boxPosition.x - halfX;
699
- const expectedMaxX = boxPosition.x + halfX;
700
- const expectedMinY = boxPosition.y - halfY;
701
- const expectedMaxY = boxPosition.y + halfY;
702
- const expectedMinZ = boxPosition.z - halfZ;
703
- const expectedMaxZ = boxPosition.z + halfZ;
704
-
705
- console.log('[filterSplatsByBox] Expected bounds (no rotation):');
706
- console.log(' X:', expectedMinX.toFixed(3), 'to', expectedMaxX.toFixed(3));
707
- console.log(' Y:', expectedMinY.toFixed(3), 'to', expectedMaxY.toFixed(3));
708
- console.log(' Z:', expectedMinZ.toFixed(3), 'to', expectedMaxZ.toFixed(3));
709
-
710
- const errorX = Math.max(Math.abs(minX - expectedMinX), Math.abs(maxX - expectedMaxX));
711
- const errorY = Math.max(Math.abs(minY - expectedMinY), Math.abs(maxY - expectedMaxY));
712
- const errorZ = Math.max(Math.abs(minZ - expectedMinZ), Math.abs(maxZ - expectedMaxZ));
713
-
714
- console.log('[filterSplatsByBox] Boundary errors:');
715
- console.log(' X error:', errorX.toFixed(3), 'm');
716
- console.log(' Y error:', errorY.toFixed(3), 'm');
717
- console.log(' Z error:', errorZ.toFixed(3), 'm');
718
-
719
- if (errorX > 0.1 || errorY > 0.1 || errorZ > 0.1) {
720
- console.warn('[filterSplatsByBox] ⚠️ Boundary error > 0.1m detected!');
721
- }
722
- } else {
723
  console.log('[filterSplatsByBox] ℹ️ Box is rotated - Expected bounds check skipped');
724
  console.log('[filterSplatsByBox] Filtered bounds above show actual world-space result');
725
  }
@@ -736,7 +709,7 @@ function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0,
736
  console.error('[filterSplatsByBox] Check box position and size');
737
  }
738
 
739
- // ⭐⭐⭐ 必須: 結果を返す ⭐⭐⭐
740
  return filteredVertices;
741
  }
742
 
@@ -1361,23 +1334,35 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1361
 
1362
  cleanupAnimation();
1363
 
 
 
 
 
 
 
 
 
 
1364
  // PLY Offsetの適用
1365
  if (plyOffset.x !== 0 || plyOffset.y !== 0 || plyOffset.z !== 0) {
1366
  console.log('[STEP 3] Applying PLY offset:', plyOffset);
1367
 
 
1368
  plyData.vertices.forEach(vertex => {
1369
  vertex.x += plyOffset.x;
1370
  vertex.y += plyOffset.y;
1371
  vertex.z += plyOffset.z;
1372
  });
1373
 
1374
- await gs.viewer.dispose();
1375
 
 
1376
  const newHeader = plyData.header;
1377
  const newPlyData = parser.createPLYFile(newHeader, plyData.vertices, plyData.vertexSize);
1378
  const blob = new Blob([newPlyData], { type: 'application/octet-stream' });
1379
  const adjustedPlyUrl = URL.createObjectURL(blob);
1380
 
 
1381
  gs = await GVRM.initGS(adjustedPlyUrl, undefined, undefined, scene);
1382
  console.log('[STEP 3] ✓ GS reloaded with adjusted position');
1383
 
@@ -1386,28 +1371,57 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1386
  } else {
1387
  console.log('[STEP 3] No PLY offset to apply');
1388
  }
1389
-
1390
  ui.hidePositionAdjustment();
1391
  ui.setStatus('Filtering splats with bounding box...');
1392
-
1393
  // フィルタリング実行
1394
  console.log('[STEP 4] Starting filtering...');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1395
  const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation);
1396
-
1397
  if (filteredVertices.length === 0) {
1398
  console.error('[STEP 4] ❌ No splats found in the box!');
1399
  alert('⚠️ No splats found in the box!\n\nPlease adjust the box size/position and try again.\n\nCheck the browser console for detailed debug information.');
1400
  ui.showPositionAdjustment();
1401
  return;
1402
  }
1403
-
1404
  if (filteredVertices.length < 10) {
1405
  console.warn('[STEP 4] ⚠️ Only', filteredVertices.length, 'splats found');
1406
  alert(`⚠️ Only ${filteredVertices.length} splats found!\n\nThis is too few. Please adjust the box.\n\nCheck the browser console for detailed debug information.`);
1407
  ui.showPositionAdjustment();
1408
  return;
1409
  }
 
 
 
 
 
1410
 
 
 
 
1411
  // スプラットを中心化
1412
  console.log('[STEP 5] Centering splats...');
1413
 
 
523
  // Line 594付近を置き換え
524
  // ======================================== 20251214 21:20 fix
525
 
526
+ // ========================================
527
+ // 修正版 filterSplatsByBox 関数
528
+ // Line 527-742 を置き換え
529
+ // ========================================
530
+
531
  function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0, y: 0, z: 0 }) {
532
  console.log('[filterSplatsByBox] ===== FILTERING START =====');
533
+ console.log('[filterSplatsByBox] Input parameters:');
534
+ console.log(' Box Size:', boxSize);
535
+ console.log(' Box Position:', boxPosition);
536
+ console.log(' Box Rotation (radians):', boxRotation);
537
+ console.log(' Box Rotation (degrees):', {
538
+ x: (boxRotation.x * 180 / Math.PI).toFixed(1) + '°',
539
+ y: (boxRotation.y * 180 / Math.PI).toFixed(1) + '°',
540
+ z: (boxRotation.z * 180 / Math.PI).toFixed(1) + '°'
541
+ });
542
+ console.log(' Total input vertices:', plyData.vertices.length);
543
 
544
+ // Box半径
 
 
545
  const halfX = boxSize.x / 2;
546
  const halfY = boxSize.y / 2;
547
  const halfZ = boxSize.z / 2;
548
 
549
+ console.log('[filterSplatsByBox] Box half-extents:', { halfX, halfY, halfZ });
550
+
551
+ // 回転行列の作成と逆行列
552
  const rotationMatrix = new THREE.Matrix4();
553
  rotationMatrix.makeRotationFromEuler(new THREE.Euler(boxRotation.x, boxRotation.y, boxRotation.z));
554
  const inverseRotationMatrix = new THREE.Matrix4().copy(rotationMatrix).invert();
555
 
556
+ console.log('[filterSplatsByBox] Rotation matrices created');
557
+
558
+ // デバッグ: 境界付近の頂点を記録
559
  let insideCount = 0;
560
  let outsideCount = 0;
561
+ const boundaryVertices = [];
562
 
563
+ // 最初のパス: 統計収集
564
  plyData.vertices.forEach((vertex, index) => {
565
  const localPos = new THREE.Vector3(
566
  vertex.x - boxPosition.x,
 
598
  }
599
  });
600
 
601
+ console.log('[DEBUG] Pre-filter summary:');
602
  console.log(' Inside:', insideCount);
603
  console.log(' Outside:', outsideCount);
604
  console.log(' Boundary vertices (within 0.5m):', boundaryVertices.length);
605
 
606
  if (boundaryVertices.length > 0) {
607
+ console.log('[DEBUG] Sample boundary vertices:');
608
  boundaryVertices.slice(0, 20).forEach(v => {
609
  console.log(` V${v.index}: world(${v.world.x.toFixed(2)}, ${v.world.y.toFixed(2)}, ${v.world.z.toFixed(2)}) ` +
610
  `→ local(${v.local.x.toFixed(2)}, ${v.local.y.toFixed(2)}, ${v.local.z.toFixed(2)}) ` +
 
612
  });
613
  }
614
 
615
+ // サンプル頂点表示(最初の10個)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
616
  console.log('[filterSplatsByBox] Sample vertices (first 10):');
617
  for (let i = 0; i < Math.min(10, plyData.vertices.length); i++) {
618
  const v = plyData.vertices[i];
 
632
  console.log(` Vertex ${i}:`, {
633
  world: { x: v.x.toFixed(3), y: v.y.toFixed(3), z: v.z.toFixed(3) },
634
  local: { x: localPos.x.toFixed(3), y: localPos.y.toFixed(3), z: localPos.z.toFixed(3) },
635
+ inside: inside
 
 
 
 
 
636
  });
637
  }
638
 
639
  // ⭐⭐⭐ 実際のフィルタリング ⭐⭐⭐
640
+ const filteredVertices = plyData.vertices.filter((vertex) => {
641
  const localPos = new THREE.Vector3(
642
  vertex.x - boxPosition.x,
643
  vertex.y - boxPosition.y,
 
692
  Math.abs(boxRotation.y) > 0.01 ||
693
  Math.abs(boxRotation.z) > 0.01;
694
 
695
+ if (hasRotation) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
696
  console.log('[filterSplatsByBox] ℹ️ Box is rotated - Expected bounds check skipped');
697
  console.log('[filterSplatsByBox] Filtered bounds above show actual world-space result');
698
  }
 
709
  console.error('[filterSplatsByBox] Check box position and size');
710
  }
711
 
712
+ // ⭐⭐⭐ 重要: 結果を返す ⭐⭐⭐
713
  return filteredVertices;
714
  }
715
 
 
1334
 
1335
  cleanupAnimation();
1336
 
1337
+
1338
+
1339
+ // PLY Offsetの適用///////////////////////////////////////1215
1340
+
1341
+ // ========================================
1342
+ // 修正版 confirmBoxBtn (STEP 3-4のみ)
1343
+ // Line 1366-1450 付近を置き換え
1344
+ // ========================================
1345
+
1346
  // PLY Offsetの適用
1347
  if (plyOffset.x !== 0 || plyOffset.y !== 0 || plyOffset.z !== 0) {
1348
  console.log('[STEP 3] Applying PLY offset:', plyOffset);
1349
 
1350
+ // ⭐ 重要: plyData.verticesを直接書き換え
1351
  plyData.vertices.forEach(vertex => {
1352
  vertex.x += plyOffset.x;
1353
  vertex.y += plyOffset.y;
1354
  vertex.z += plyOffset.z;
1355
  });
1356
 
1357
+ console.log('[STEP 3] ✓ PLY data updated with offset');
1358
 
1359
+ // GSを再ロード(表示用)
1360
  const newHeader = plyData.header;
1361
  const newPlyData = parser.createPLYFile(newHeader, plyData.vertices, plyData.vertexSize);
1362
  const blob = new Blob([newPlyData], { type: 'application/octet-stream' });
1363
  const adjustedPlyUrl = URL.createObjectURL(blob);
1364
 
1365
+ await gs.viewer.dispose();
1366
  gs = await GVRM.initGS(adjustedPlyUrl, undefined, undefined, scene);
1367
  console.log('[STEP 3] ✓ GS reloaded with adjusted position');
1368
 
 
1371
  } else {
1372
  console.log('[STEP 3] No PLY offset to apply');
1373
  }
1374
+
1375
  ui.hidePositionAdjustment();
1376
  ui.setStatus('Filtering splats with bounding box...');
1377
+
1378
  // フィルタリング実行
1379
  console.log('[STEP 4] Starting filtering...');
1380
+ console.log('[STEP 4] Using plyData with', plyData.vertices.length, 'vertices');
1381
+
1382
+ // ⭐ デバッグ: フィルタリング前の座標範囲を確認
1383
+ let preMinX = Infinity, preMinY = Infinity, preMinZ = Infinity;
1384
+ let preMaxX = -Infinity, preMaxY = -Infinity, preMaxZ = -Infinity;
1385
+
1386
+ plyData.vertices.forEach(v => {
1387
+ preMinX = Math.min(preMinX, v.x);
1388
+ preMinY = Math.min(preMinY, v.y);
1389
+ preMinZ = Math.min(preMinZ, v.z);
1390
+ preMaxX = Math.max(preMaxX, v.x);
1391
+ preMaxY = Math.max(preMaxY, v.y);
1392
+ preMaxZ = Math.max(preMaxZ, v.z);
1393
+ });
1394
+
1395
+ console.log('[STEP 4] Pre-filter bounds:');
1396
+ console.log(' X:', preMinX.toFixed(3), 'to', preMaxX.toFixed(3));
1397
+ console.log(' Y:', preMinY.toFixed(3), 'to', preMaxY.toFixed(3));
1398
+ console.log(' Z:', preMinZ.toFixed(3), 'to', preMaxZ.toFixed(3));
1399
+
1400
+ // ⭐⭐⭐ フィルタリング実行(修正後のplyDataを使用)⭐⭐⭐
1401
  const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation);
1402
+
1403
  if (filteredVertices.length === 0) {
1404
  console.error('[STEP 4] ❌ No splats found in the box!');
1405
  alert('⚠️ No splats found in the box!\n\nPlease adjust the box size/position and try again.\n\nCheck the browser console for detailed debug information.');
1406
  ui.showPositionAdjustment();
1407
  return;
1408
  }
1409
+
1410
  if (filteredVertices.length < 10) {
1411
  console.warn('[STEP 4] ⚠️ Only', filteredVertices.length, 'splats found');
1412
  alert(`⚠️ Only ${filteredVertices.length} splats found!\n\nThis is too few. Please adjust the box.\n\nCheck the browser console for detailed debug information.`);
1413
  ui.showPositionAdjustment();
1414
  return;
1415
  }
1416
+
1417
+ console.log('[STEP 4] ✓ Filtering complete:', filteredVertices.length, 'splats kept');
1418
+
1419
+ ui.hidePositionAdjustment();
1420
+ ui.setStatus('Filtering splats with bounding box...');
1421
 
1422
+
1423
+ ///////////////////////////////////////////////////////1215 11:49
1424
+
1425
  // スプラットを中心化
1426
  console.log('[STEP 5] Centering splats...');
1427