stpete2 commited on
Commit
dafb889
·
verified ·
1 Parent(s): eb04c0d

Upload preprocess_manual.js

Browse files
Files changed (1) hide show
  1. preprocess_manual.js +124 -29
preprocess_manual.js CHANGED
@@ -73,6 +73,8 @@ function setupCameraControls(camera, renderer) {
73
  // Replace the createManualUI function 2025/12/07
74
  // ==========================================
75
 
 
 
76
  function createManualUI(scene, camera, renderer) {
77
  console.log('[createManualUI] Creating manual preprocessing UI...');
78
 
@@ -178,7 +180,24 @@ function createManualUI(scene, camera, renderer) {
178
  <label>PLY Z Offset: <span id="ply-z-value">0.0</span>m</label><br>
179
  <input type="range" id="ply-z" min="-10.0" max="10.0" step="0.1" value="0.0" style="width: 100%;">
180
  </div>
 
 
181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  <button id="reset-all-btn" style="
183
  margin-top: 10px;
184
  padding: 8px 15px;
@@ -261,6 +280,9 @@ function createManualUI(scene, camera, renderer) {
261
  width: 100%;
262
  ">Apply Box Filter</button>
263
 
 
 
 
264
  <!-- Step 2: Bone Assignment -->
265
  <div id="bone-assignment-section" style="display: none; margin-top: 30px;">
266
  <h3>Step 2: Assign Splats to Bones</h3>
@@ -436,6 +458,7 @@ function createManualUI(scene, camera, renderer) {
436
  </div>
437
  `;
438
 
 
439
  document.body.appendChild(uiContainer);
440
 
441
  let boundingBoxHelper = null;
@@ -476,23 +499,37 @@ function createManualUI(scene, camera, renderer) {
476
  if (controlsEl) controlsEl.style.display = 'block';
477
  },
478
 
479
- createBoundingBox: function(size = { x: 2, y: 2, z: 2 }, position = { x: 0, y: 0, z: 0 }) {
480
- if (boundingBoxHelper) {
481
- scene.remove(boundingBoxHelper);
482
- }
483
-
484
- const geometry = new THREE.BoxGeometry(size.x, size.y, size.z);
485
- const edges = new THREE.EdgesGeometry(geometry);
486
- const material = new THREE.LineBasicMaterial({ color: 0x00ff00, linewidth: 2 });
487
- boundingBoxHelper = new THREE.LineSegments(edges, material);
488
- boundingBoxHelper.position.set(position.x, position.y, position.z);
489
- scene.add(boundingBoxHelper);
490
-
491
- //renderer.render(scene, camera);
492
-
493
- return boundingBoxHelper;
494
- },
495
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
496
  updateBoundingBox: function(size, position) {
497
  if (boundingBoxHelper) {
498
  scene.remove(boundingBoxHelper);
@@ -526,28 +563,39 @@ function createManualUI(scene, camera, renderer) {
526
  /**
527
  * Bounding Box内のスプラットのみをフィルタリング
528
  */
529
- /////////////////////////////
530
 
531
- function filterSplatsByBox(plyData, boxSize, boxPosition) {
 
532
  const halfX = boxSize.x / 2;
533
  const halfY = boxSize.y / 2;
534
  const halfZ = boxSize.z / 2;
535
 
 
 
 
 
536
  const filteredVertices = plyData.vertices.filter(vertex => {
537
- const x = vertex.x - boxPosition.x;
538
- const y = vertex.y - boxPosition.y;
539
- const z = vertex.z - boxPosition.z;
 
 
 
540
 
 
 
 
 
541
  return (
542
- x >= -halfX && x <= halfX &&
543
- y >= -halfY && y <= halfY &&
544
- z >= -halfZ && z <= halfZ
545
  );
546
  });
547
 
548
  console.log(`[filterSplatsByBox] Filtered: ${filteredVertices.length} / ${plyData.vertices.length} splats (${(filteredVertices.length/plyData.vertices.length*100).toFixed(1)}%)`);
549
 
550
- // ⭐ 警告: 点群が大幅に減少している場合
551
  if (filteredVertices.length < plyData.vertices.length * 0.5) {
552
  console.warn('[filterSplatsByBox] ⚠️ WARNING: More than 50% of splats filtered out!');
553
  console.warn('[filterSplatsByBox] Original:', plyData.vertices.length, '→ Filtered:', filteredVertices.length);
@@ -557,7 +605,8 @@ function filterSplatsByBox(plyData, boxSize, boxPosition) {
557
  return filteredVertices;
558
  }
559
 
560
- //////////////////////////////
 
561
 
562
 
563
  /**
@@ -976,6 +1025,33 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
976
  });
977
  }
978
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
979
 
980
  // PLY offset sliders
981
  const setupPlyOffsetSlider = (id, valueId, axis) => {
@@ -1006,10 +1082,24 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1006
  setupPlyOffsetSlider('ply-y', 'ply-y-value', 'y');
1007
  setupPlyOffsetSlider('ply-z', 'ply-z-value', 'z');
1008
 
 
 
1009
  // Reset button
1010
  const resetAllBtn = document.getElementById('reset-all-btn');
1011
  if (resetAllBtn) {
1012
  resetAllBtn.addEventListener('click', () => {
 
 
 
 
 
 
 
 
 
 
 
 
1013
  // Reset box
1014
  boxSize = { x: 3, y: 3, z: 3 };
1015
  boxPosition = { x: 0, y: 1, z: 0 };
@@ -1041,6 +1131,7 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1041
  ui.updateBoundingBox(boxSize, boxPosition);
1042
  });
1043
  }
 
1044
 
1045
  // Confirm button
1046
  const confirmBoxBtn = document.getElementById('confirm-box-btn');
@@ -1073,8 +1164,12 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1073
  ui.setStatus('Filtering splats with bounding box...');
1074
 
1075
  // Filter splats immediately
1076
- const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition);
1077
-
 
 
 
 
1078
  if (filteredVertices.length === 0) {
1079
  alert('No splats found in the box! Please adjust the box size/position and try again.');
1080
  ui.showPositionAdjustment();
 
73
  // Replace the createManualUI function 2025/12/07
74
  // ==========================================
75
 
76
+ //////////////////////////////////////////12/13 17:30
77
+
78
  function createManualUI(scene, camera, renderer) {
79
  console.log('[createManualUI] Creating manual preprocessing UI...');
80
 
 
180
  <label>PLY Z Offset: <span id="ply-z-value">0.0</span>m</label><br>
181
  <input type="range" id="ply-z" min="-10.0" max="10.0" step="0.1" value="0.0" style="width: 100%;">
182
  </div>
183
+ <!-- Box Rotation Controls -->
184
+ <h4 style="margin: 15px 0 10px 0; color: #FF9800;">🔄 Box Rotation</h4>
185
 
186
+ <div style="margin: 10px 0;">
187
+ <label>Rotate Y (Yaw): <span id="box-rot-y-value-step0">0</span>°</label><br>
188
+ <input type="range" id="box-rot-y-step0" min="-180" max="180" step="1" value="0" style="width: 100%;">
189
+ </div>
190
+ <div style="margin: 10px 0;">
191
+ <label>Rotate X (Pitch): <span id="box-rot-x-value-step0">0</span>°</label><br>
192
+ <input type="range" id="box-rot-x-step0" min="-90" max="90" step="1" value="0" style="width: 100%;">
193
+ </div>
194
+ <div style="margin: 10px 0;">
195
+ <label>Rotate Z (Roll): <span id="box-rot-z-value-step0">0</span>°</label><br>
196
+ <input type="range" id="box-rot-z-step0" min="-180" max="180" step="1" value="0" style="width: 100%;">
197
+ </div>
198
+
199
+
200
+
201
  <button id="reset-all-btn" style="
202
  margin-top: 10px;
203
  padding: 8px 15px;
 
280
  width: 100%;
281
  ">Apply Box Filter</button>
282
 
283
+
284
+
285
+
286
  <!-- Step 2: Bone Assignment -->
287
  <div id="bone-assignment-section" style="display: none; margin-top: 30px;">
288
  <h3>Step 2: Assign Splats to Bones</h3>
 
458
  </div>
459
  `;
460
 
461
+
462
  document.body.appendChild(uiContainer);
463
 
464
  let boundingBoxHelper = null;
 
499
  if (controlsEl) controlsEl.style.display = 'block';
500
  },
501
 
502
+ //////////////12/13 17:15 start
503
+
504
+ createBoundingBox: function(size = { x: 2, y: 2, z: 2 }, position = { x: 0, y: 0, z: 0 }, rotation = { x: 0, y: 0, z: 0 }) {
505
+ if (boundingBoxHelper) {
506
+ scene.remove(boundingBoxHelper);
507
+ }
508
+
509
+ const geometry = new THREE.BoxGeometry(size.x, size.y, size.z);
510
+ const edges = new THREE.EdgesGeometry(geometry);
511
+ const material = new THREE.LineBasicMaterial({ color: 0x00ff00, linewidth: 2 });
512
+ boundingBoxHelper = new THREE.LineSegments(edges, material);
513
+ boundingBoxHelper.position.set(position.x, position.y, position.z);
514
+
515
+ // ⭐ 回転を追加 (Euler angles in radians)
516
+ boundingBoxHelper.rotation.set(rotation.x, rotation.y, rotation.z);
517
+
518
+ scene.add(boundingBoxHelper);
519
+
520
+ return boundingBoxHelper;
521
+ },
522
+
523
+ updateBoundingBox: function(size, position, rotation = { x: 0, y: 0, z: 0 }) {
524
+ if (boundingBoxHelper) {
525
+ scene.remove(boundingBoxHelper);
526
+ }
527
+ return this.createBoundingBox(size, position, rotation);
528
+ },
529
+
530
+ //////////////12/13 17:15 end
531
+
532
+
533
  updateBoundingBox: function(size, position) {
534
  if (boundingBoxHelper) {
535
  scene.remove(boundingBoxHelper);
 
563
  /**
564
  * Bounding Box内のスプラットのみをフィルタリング
565
  */
566
+ /////////////////////////////12/13 17:20 start
567
 
568
+
569
+ function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0, y: 0, z: 0 }) {
570
  const halfX = boxSize.x / 2;
571
  const halfY = boxSize.y / 2;
572
  const halfZ = boxSize.z / 2;
573
 
574
+ // Create rotation matrix (inverse rotation to transform points into box space)
575
+ const rotationMatrix = new THREE.Matrix4();
576
+ rotationMatrix.makeRotationFromEuler(new THREE.Euler(-boxRotation.x, -boxRotation.y, -boxRotation.z));
577
+
578
  const filteredVertices = plyData.vertices.filter(vertex => {
579
+ // Transform vertex to box-local space
580
+ const localPos = new THREE.Vector3(
581
+ vertex.x - boxPosition.x,
582
+ vertex.y - boxPosition.y,
583
+ vertex.z - boxPosition.z
584
+ );
585
 
586
+ // Apply inverse rotation
587
+ localPos.applyMatrix4(rotationMatrix);
588
+
589
+ // Check if inside box bounds
590
  return (
591
+ localPos.x >= -halfX && localPos.x <= halfX &&
592
+ localPos.y >= -halfY && localPos.y <= halfY &&
593
+ localPos.z >= -halfZ && localPos.z <= halfZ
594
  );
595
  });
596
 
597
  console.log(`[filterSplatsByBox] Filtered: ${filteredVertices.length} / ${plyData.vertices.length} splats (${(filteredVertices.length/plyData.vertices.length*100).toFixed(1)}%)`);
598
 
 
599
  if (filteredVertices.length < plyData.vertices.length * 0.5) {
600
  console.warn('[filterSplatsByBox] ⚠️ WARNING: More than 50% of splats filtered out!');
601
  console.warn('[filterSplatsByBox] Original:', plyData.vertices.length, '→ Filtered:', filteredVertices.length);
 
605
  return filteredVertices;
606
  }
607
 
608
+
609
+ //////////////////////////////12/13 17:20 end
610
 
611
 
612
  /**
 
1025
  });
1026
  }
1027
  };
1028
+ /////////////////////////12/13 17:15 start
1029
+
1030
+ // この変数を追加 (line 1002付近):
1031
+ let boxRotation = { x: 0, y: 0, z: 0 };
1032
+
1033
+ // Box rotation sliders (setupPlyOffsetSlider の後に追加):
1034
+ const setupBoxRotSlider = (id, valueId, axis) => {
1035
+ const slider = document.getElementById(id);
1036
+ const valueDisplay = document.getElementById(valueId);
1037
+
1038
+ if (slider && valueDisplay) {
1039
+ slider.addEventListener('input', (e) => {
1040
+ const degrees = parseFloat(e.target.value);
1041
+ valueDisplay.textContent = degrees.toFixed(0);
1042
+ boxRotation[axis] = degrees * Math.PI / 180; // Convert to radians
1043
+ ui.updateBoundingBox(boxSize, boxPosition, boxRotation);
1044
+ });
1045
+ }
1046
+ };
1047
+
1048
+ // Setup rotation sliders (setupPlyOffsetSlider の呼び出しの後に追加):
1049
+ setupBoxRotSlider('box-rot-y-step0', 'box-rot-y-value-step0', 'y');
1050
+ setupBoxRotSlider('box-rot-x-step0', 'box-rot-x-value-step0', 'x');
1051
+ setupBoxRotSlider('box-rot-z-step0', 'box-rot-z-value-step0', 'z');
1052
+
1053
+
1054
+ /////////////////////////12/13 17:15 end
1055
 
1056
  // PLY offset sliders
1057
  const setupPlyOffsetSlider = (id, valueId, axis) => {
 
1082
  setupPlyOffsetSlider('ply-y', 'ply-y-value', 'y');
1083
  setupPlyOffsetSlider('ply-z', 'ply-z-value', 'z');
1084
 
1085
+
1086
+ /////////////////////////12/13 17:15 start
1087
  // Reset button
1088
  const resetAllBtn = document.getElementById('reset-all-btn');
1089
  if (resetAllBtn) {
1090
  resetAllBtn.addEventListener('click', () => {
1091
+
1092
+
1093
+ // Reset rotation addition ########
1094
+ boxRotation = { x: 0, y: 0, z: 0 };
1095
+ document.getElementById('box-rot-y-step0').value = 0;
1096
+ document.getElementById('box-rot-x-step0').value = 0;
1097
+ document.getElementById('box-rot-z-step0').value = 0;
1098
+ document.getElementById('box-rot-y-value-step0').textContent = '0';
1099
+ document.getElementById('box-rot-x-value-step0').textContent = '0';
1100
+ document.getElementById('box-rot-z-value-step0').textContent = '0';
1101
+
1102
+
1103
  // Reset box
1104
  boxSize = { x: 3, y: 3, z: 3 };
1105
  boxPosition = { x: 0, y: 1, z: 0 };
 
1131
  ui.updateBoundingBox(boxSize, boxPosition);
1132
  });
1133
  }
1134
+ /////////////////////////12/13 17:15 end
1135
 
1136
  // Confirm button
1137
  const confirmBoxBtn = document.getElementById('confirm-box-btn');
 
1164
  ui.setStatus('Filtering splats with bounding box...');
1165
 
1166
  // Filter splats immediately
1167
+ /////////////////////12/13 17:27
1168
+
1169
+ //const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition);
1170
+ const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation);
1171
+
1172
+
1173
  if (filteredVertices.length === 0) {
1174
  alert('No splats found in the box! Please adjust the box size/position and try again.');
1175
  ui.showPositionAdjustment();