stpete2 commited on
Commit
bffae5c
·
verified ·
1 Parent(s): efd51d5

Upload preprocess_manual.js

Browse files
Files changed (1) hide show
  1. preprocess_manual.js +61 -13
preprocess_manual.js CHANGED
@@ -522,9 +522,12 @@ function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0,
522
  const halfY = boxSize.y / 2;
523
  const halfZ = boxSize.z / 2;
524
 
525
- // Create rotation matrix (inverse rotation to transform points into box space)
526
  const rotationMatrix = new THREE.Matrix4();
527
- rotationMatrix.makeRotationFromEuler(new THREE.Euler(-boxRotation.x, -boxRotation.y, -boxRotation.z));
 
 
 
528
 
529
  const filteredVertices = plyData.vertices.filter(vertex => {
530
  // Transform vertex to box-local space
@@ -535,7 +538,7 @@ function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0,
535
  );
536
 
537
  // Apply inverse rotation
538
- localPos.applyMatrix4(rotationMatrix);
539
 
540
  // Check if inside box bounds
541
  return (
@@ -547,10 +550,9 @@ function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0,
547
 
548
  console.log(`[filterSplatsByBox] Filtered: ${filteredVertices.length} / ${plyData.vertices.length} splats (${(filteredVertices.length/plyData.vertices.length*100).toFixed(1)}%)`);
549
 
550
- if (filteredVertices.length < plyData.vertices.length * 0.5) {
551
- console.warn('[filterSplatsByBox] ⚠️ WARNING: More than 50% of splats filtered out!');
552
- console.warn('[filterSplatsByBox] Original:', plyData.vertices.length, '→ Filtered:', filteredVertices.length);
553
- console.warn('[filterSplatsByBox] Consider expanding the bounding box');
554
  }
555
 
556
  return filteredVertices;
@@ -976,6 +978,9 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
976
  // Create initial bounding box
977
  ui.createBoundingBox(boxSize, boxPosition);
978
 
 
 
 
979
  // Box size sliders
980
  const setupBoxSizeSlider = (id, valueId, axis) => {
981
  const slider = document.getElementById(id);
@@ -986,7 +991,7 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
986
  const value = parseFloat(e.target.value);
987
  valueDisplay.textContent = value.toFixed(1);
988
  boxSize[axis] = value;
989
- ui.updateBoundingBox(boxSize, boxPosition);
990
  });
991
  }
992
  };
@@ -1001,10 +1006,11 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1001
  const value = parseFloat(e.target.value);
1002
  valueDisplay.textContent = value.toFixed(1);
1003
  boxPosition[axis] = value;
1004
- ui.updateBoundingBox(boxSize, boxPosition);
1005
  });
1006
  }
1007
  };
 
1008
  /////////////////////////12/13 17:15 start
1009
 
1010
  // この変数を追加 (line 1002付近):
@@ -1108,7 +1114,7 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1108
 
1109
  gsScene.position.set(0, 0, 0);
1110
  gsScene.updateMatrixWorld();
1111
- ui.updateBoundingBox(boxSize, boxPosition);
1112
  });
1113
  }
1114
  /////////////////////////12/13 17:15 end
@@ -1150,16 +1156,58 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1150
  ui.setStatus('Filtering splats with bounding box...');
1151
 
1152
  // Filter splats immediately
 
 
 
1153
  const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation);
1154
-
1155
  if (filteredVertices.length === 0) {
1156
  alert('No splats found in the box! Please adjust the box size/position and try again.');
1157
  ui.showPositionAdjustment();
1158
  return;
1159
  }
1160
-
1161
  console.log(`[preprocessManual] Filtered ${filteredVertices.length}/${plyData.vertices.length} splats`);
1162
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1163
  // ========================================
1164
  // ⭐ フィルタ済みPLYファイルを保存
1165
  // ========================================
 
522
  const halfY = boxSize.y / 2;
523
  const halfZ = boxSize.z / 2;
524
 
525
+ // 修正: 符号を反転(正しい方向に回転)
526
  const rotationMatrix = new THREE.Matrix4();
527
+ rotationMatrix.makeRotationFromEuler(new THREE.Euler(boxRotation.x, boxRotation.y, boxRotation.z));
528
+
529
+ // Inverse matrix for transforming points into box space
530
+ const inverseRotationMatrix = new THREE.Matrix4().copy(rotationMatrix).invert();
531
 
532
  const filteredVertices = plyData.vertices.filter(vertex => {
533
  // Transform vertex to box-local space
 
538
  );
539
 
540
  // Apply inverse rotation
541
+ localPos.applyMatrix4(inverseRotationMatrix);
542
 
543
  // Check if inside box bounds
544
  return (
 
550
 
551
  console.log(`[filterSplatsByBox] Filtered: ${filteredVertices.length} / ${plyData.vertices.length} splats (${(filteredVertices.length/plyData.vertices.length*100).toFixed(1)}%)`);
552
 
553
+ if (filteredVertices.length < plyData.vertices.length * 0.1) {
554
+ console.warn('[filterSplatsByBox] ⚠️ WARNING: Less than 10% of splats kept!');
555
+ console.warn('[filterSplatsByBox] Box may be too small or positioned incorrectly');
 
556
  }
557
 
558
  return filteredVertices;
 
978
  // Create initial bounding box
979
  ui.createBoundingBox(boxSize, boxPosition);
980
 
981
+
982
+
983
+ // Box size sliders
984
  // Box size sliders
985
  const setupBoxSizeSlider = (id, valueId, axis) => {
986
  const slider = document.getElementById(id);
 
991
  const value = parseFloat(e.target.value);
992
  valueDisplay.textContent = value.toFixed(1);
993
  boxSize[axis] = value;
994
+ ui.updateBoundingBox(boxSize, boxPosition, boxRotation); // ⭐ 回転を渡す
995
  });
996
  }
997
  };
 
1006
  const value = parseFloat(e.target.value);
1007
  valueDisplay.textContent = value.toFixed(1);
1008
  boxPosition[axis] = value;
1009
+ ui.updateBoundingBox(boxSize, boxPosition, boxRotation); // ⭐ 回転を渡す
1010
  });
1011
  }
1012
  };
1013
+
1014
  /////////////////////////12/13 17:15 start
1015
 
1016
  // この変数を追加 (line 1002付近):
 
1114
 
1115
  gsScene.position.set(0, 0, 0);
1116
  gsScene.updateMatrixWorld();
1117
+ ui.updateBoundingBox(boxSize, boxPosition, boxRotation); // ⭐ 最後の引数を追加
1118
  });
1119
  }
1120
  /////////////////////////12/13 17:15 end
 
1156
  ui.setStatus('Filtering splats with bounding box...');
1157
 
1158
  // Filter splats immediately
1159
+
1160
+ ////////////////////////////12/15 17:00
1161
+
1162
  const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation);
1163
+
1164
  if (filteredVertices.length === 0) {
1165
  alert('No splats found in the box! Please adjust the box size/position and try again.');
1166
  ui.showPositionAdjustment();
1167
  return;
1168
  }
1169
+
1170
  console.log(`[preprocessManual] Filtered ${filteredVertices.length}/${plyData.vertices.length} splats`);
1171
+
1172
+ // ⭐⭐⭐ 新規追加: フィルタリング後のスプラットを中心化 ⭐⭐⭐
1173
+ console.log('[preprocessManual] Centering filtered splats to origin...');
1174
+
1175
+ // 新しい中心を計算
1176
+ let newMinX = Infinity, newMinY = Infinity, newMinZ = Infinity;
1177
+ let newMaxX = -Infinity, newMaxY = -Infinity, newMaxZ = -Infinity;
1178
+
1179
+ filteredVertices.forEach(vertex => {
1180
+ newMinX = Math.min(newMinX, vertex.x);
1181
+ newMinY = Math.min(newMinY, vertex.y);
1182
+ newMinZ = Math.min(newMinZ, vertex.z);
1183
+ newMaxX = Math.max(newMaxX, vertex.x);
1184
+ newMaxY = Math.max(newMaxY, vertex.y);
1185
+ newMaxZ = Math.max(newMaxZ, vertex.z);
1186
+ });
1187
+
1188
+ const newCenterX = (newMaxX + newMinX) / 2;
1189
+ const newCenterY = (newMaxY + newMinY) / 2;
1190
+ const newCenterZ = (newMaxZ + newMinZ) / 2;
1191
+
1192
+ console.log('[preprocessManual] Original center:', { x: newCenterX.toFixed(2), y: newCenterY.toFixed(2), z: newCenterZ.toFixed(2) });
1193
+
1194
+ // 中心を原点に移動
1195
+ filteredVertices.forEach(vertex => {
1196
+ vertex.x -= newCenterX;
1197
+ vertex.y -= newCenterY;
1198
+ vertex.z -= newCenterZ;
1199
+ });
1200
+
1201
+ console.log('[preprocessManual] ✓ Splats centered to origin (0, 0, 0)');
1202
+
1203
+ // ⭐⭐⭐ 中心化終了 ⭐⭐⭐
1204
+
1205
+ // ========================================
1206
+ // ⭐ フィルタ済みPLYファイルを保存
1207
+ // ========================================
1208
+
1209
+ ////////////////////////////12/15 17:00
1210
+
1211
  // ========================================
1212
  // ⭐ フィルタ済みPLYファイルを保存
1213
  // ========================================