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

Upload preprocess_manual.js

Browse files
Files changed (1) hide show
  1. preprocess_manual.js +93 -45
preprocess_manual.js CHANGED
@@ -1125,22 +1125,38 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1125
  // 完全版: confirmBoxBtn のイベントリスナー
1126
  // Line 1107から約100行を以下に置き換え
1127
  // ----------------------------------------
 
1128
 
1129
  const confirmBoxBtn = document.getElementById('confirm-box-btn');
1130
  if (confirmBoxBtn) {
1131
  confirmBoxBtn.addEventListener('click', async () => {
1132
- console.log('[preprocessManual] Box confirmed:', { boxSize, boxPosition, plyOffset });
 
 
 
 
 
 
 
 
 
 
1133
 
1134
  cleanupAnimation();
1135
 
1136
- // Apply PLY offset if any
 
 
1137
  if (plyOffset.x !== 0 || plyOffset.y !== 0 || plyOffset.z !== 0) {
 
 
1138
  plyData.vertices.forEach(vertex => {
1139
  vertex.x += plyOffset.x;
1140
  vertex.y += plyOffset.y;
1141
  vertex.z += plyOffset.z;
1142
  });
1143
 
 
1144
  await gs.viewer.dispose();
1145
 
1146
  const newHeader = plyData.header;
@@ -1149,33 +1165,47 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1149
  const adjustedPlyUrl = URL.createObjectURL(blob);
1150
 
1151
  gs = await GVRM.initGS(adjustedPlyUrl, undefined, undefined, scene);
1152
- console.log('[preprocessManual] GS reloaded with adjusted position');
 
 
 
1153
  }
1154
 
1155
  ui.hidePositionAdjustment();
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);
@@ -1184,35 +1214,53 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
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
  // ========================================
1214
  try {
1215
- ui.setStatus('Saving filtered PLY file...');
1216
 
1217
  // Create new header with updated vertex count
1218
  const newHeader = plyData.header.map(line => {
@@ -1232,12 +1280,12 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1232
  // Generate filename
1233
  const originalFilename = gsPath.split('/').pop().replace('.ply', '');
1234
  const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, -5);
1235
- const filteredFilename = `${originalFilename}_filtered_${timestamp}.ply`;
1236
 
1237
  // Download the file
1238
  downloadPLY(filteredPlyData, filteredFilename);
1239
 
1240
- console.log('[preprocessManual] ✓ Filtered PLY saved:', filteredFilename);
1241
  console.log('[preprocessManual] Original vertices:', plyData.vertices.length);
1242
  console.log('[preprocessManual] Filtered vertices:', filteredVertices.length);
1243
  console.log('[preprocessManual] Reduction:',
@@ -1271,9 +1319,9 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1271
  // Dispose old GS
1272
  await gs.viewer.dispose();
1273
 
1274
- // Load filtered GS
1275
  const filteredGs = await GVRM.initGS(filteredPlyUrl, undefined, undefined, scene);
1276
- console.log('[preprocessManual] Filtered GS loaded');
1277
 
1278
  ui.removeBoundingBox();
1279
  ui.setStatus('Loading VRM...');
 
1125
  // 完全版: confirmBoxBtn のイベントリスナー
1126
  // Line 1107から約100行を以下に置き換え
1127
  // ----------------------------------------
1128
+ /////////////////// 12/15 18:00 全面描き直し
1129
 
1130
  const confirmBoxBtn = document.getElementById('confirm-box-btn');
1131
  if (confirmBoxBtn) {
1132
  confirmBoxBtn.addEventListener('click', async () => {
1133
+ console.log('[preprocessManual] ===== CONFIRM BOX CLICKED =====');
1134
+ console.log('[preprocessManual] Box settings:', {
1135
+ boxSize,
1136
+ boxPosition,
1137
+ boxRotation: {
1138
+ x: (boxRotation.x * 180 / Math.PI).toFixed(1),
1139
+ y: (boxRotation.y * 180 / Math.PI).toFixed(1),
1140
+ z: (boxRotation.z * 180 / Math.PI).toFixed(1)
1141
+ },
1142
+ plyOffset
1143
+ });
1144
 
1145
  cleanupAnimation();
1146
 
1147
+ // ========================================
1148
+ // ⭐⭐⭐ CRITICAL: PLY OffsetをplyDataに適用してからGSを再読込
1149
+ // ========================================
1150
  if (plyOffset.x !== 0 || plyOffset.y !== 0 || plyOffset.z !== 0) {
1151
+ console.log('[preprocessManual] Applying PLY offset:', plyOffset);
1152
+
1153
  plyData.vertices.forEach(vertex => {
1154
  vertex.x += plyOffset.x;
1155
  vertex.y += plyOffset.y;
1156
  vertex.z += plyOffset.z;
1157
  });
1158
 
1159
+ // GSを再読込
1160
  await gs.viewer.dispose();
1161
 
1162
  const newHeader = plyData.header;
 
1165
  const adjustedPlyUrl = URL.createObjectURL(blob);
1166
 
1167
  gs = await GVRM.initGS(adjustedPlyUrl, undefined, undefined, scene);
1168
+ console.log('[preprocessManual] GS reloaded with adjusted position');
1169
+
1170
+ // ⭐ 重要: PLY offsetをリセット(既に適用済み)
1171
+ plyOffset = { x: 0, y: 0, z: 0 };
1172
  }
1173
 
1174
  ui.hidePositionAdjustment();
1175
  ui.setStatus('Filtering splats with bounding box...');
1176
 
1177
+ // ========================================
1178
+ // ⭐⭐⭐ フィルタリング実行
1179
+ // ========================================
1180
+ console.log('[preprocessManual] Starting filtering...');
1181
+ console.log('[preprocessManual] Total vertices before filter:', plyData.vertices.length);
1182
+
1183
  const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation);
1184
+
1185
+ console.log('[preprocessManual] Filtered vertices:', filteredVertices.length);
1186
+ console.log('[preprocessManual] Retention rate:', (filteredVertices.length / plyData.vertices.length * 100).toFixed(1), '%');
1187
+
1188
  if (filteredVertices.length === 0) {
1189
+ alert('⚠️ No splats found in the box!\n\nPlease adjust the box size/position and try again.');
1190
  ui.showPositionAdjustment();
1191
  return;
1192
  }
1193
+
1194
+ if (filteredVertices.length < 10) {
1195
+ alert(`⚠️ Only ${filteredVertices.length} splats found!\n\nThis is too few. Please adjust the box.`);
1196
+ ui.showPositionAdjustment();
1197
+ return;
1198
+ }
1199
+
1200
+ // ========================================
1201
+ // ⭐⭐⭐ スプラットを中心化(原点へ移動)
1202
+ // ========================================
1203
+ console.log('[preprocessManual] ===== CENTERING SPLATS =====');
1204
+
1205
+ // 現在の中心を計算
1206
  let newMinX = Infinity, newMinY = Infinity, newMinZ = Infinity;
1207
  let newMaxX = -Infinity, newMaxY = -Infinity, newMaxZ = -Infinity;
1208
+
1209
  filteredVertices.forEach(vertex => {
1210
  newMinX = Math.min(newMinX, vertex.x);
1211
  newMinY = Math.min(newMinY, vertex.y);
 
1214
  newMaxY = Math.max(newMaxY, vertex.y);
1215
  newMaxZ = Math.max(newMaxZ, vertex.z);
1216
  });
1217
+
1218
+ const centerX = (newMaxX + newMinX) / 2;
1219
+ const centerY = (newMaxY + newMinY) / 2;
1220
+ const centerZ = (newMaxZ + newMinZ) / 2;
1221
+
1222
+ console.log('[preprocessManual] Original center:', {
1223
+ x: centerX.toFixed(3),
1224
+ y: centerY.toFixed(3),
1225
+ z: centerZ.toFixed(3)
1226
+ });
1227
+
1228
+ // 原点へ移動
1229
  filteredVertices.forEach(vertex => {
1230
+ vertex.x -= centerX;
1231
+ vertex.y -= centerY;
1232
+ vertex.z -= centerZ;
1233
  });
1234
+
1235
+ // 検証
1236
+ let checkMinX = Infinity, checkMinY = Infinity, checkMinZ = Infinity;
1237
+ let checkMaxX = -Infinity, checkMaxY = -Infinity, checkMaxZ = -Infinity;
1238
+
1239
+ filteredVertices.forEach(vertex => {
1240
+ checkMinX = Math.min(checkMinX, vertex.x);
1241
+ checkMinY = Math.min(checkMinY, vertex.y);
1242
+ checkMinZ = Math.min(checkMinZ, vertex.z);
1243
+ checkMaxX = Math.max(checkMaxX, vertex.x);
1244
+ checkMaxY = Math.max(checkMaxY, vertex.y);
1245
+ checkMaxZ = Math.max(checkMaxZ, vertex.z);
1246
+ });
1247
+
1248
+ const newCenterX = (checkMaxX + checkMinX) / 2;
1249
+ const newCenterY = (checkMaxY + checkMinY) / 2;
1250
+ const newCenterZ = (checkMaxZ + checkMinZ) / 2;
1251
+
1252
+ console.log('[preprocessManual] New center:', {
1253
+ x: newCenterX.toFixed(3),
1254
+ y: newCenterY.toFixed(3),
1255
+ z: newCenterZ.toFixed(3)
1256
+ });
1257
+ console.log('[preprocessManual] ✓ Splats centered to origin');
1258
+
1259
  // ========================================
1260
+ // ⭐ フィルタ済みPLYファイルを保存(中心化後)
1261
  // ========================================
1262
  try {
1263
+ ui.setStatus('Saving filtered & centered PLY file...');
1264
 
1265
  // Create new header with updated vertex count
1266
  const newHeader = plyData.header.map(line => {
 
1280
  // Generate filename
1281
  const originalFilename = gsPath.split('/').pop().replace('.ply', '');
1282
  const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, -5);
1283
+ const filteredFilename = `${originalFilename}_filtered_centered_${timestamp}.ply`;
1284
 
1285
  // Download the file
1286
  downloadPLY(filteredPlyData, filteredFilename);
1287
 
1288
+ console.log('[preprocessManual] ✓ Filtered & centered PLY saved:', filteredFilename);
1289
  console.log('[preprocessManual] Original vertices:', plyData.vertices.length);
1290
  console.log('[preprocessManual] Filtered vertices:', filteredVertices.length);
1291
  console.log('[preprocessManual] Reduction:',
 
1319
  // Dispose old GS
1320
  await gs.viewer.dispose();
1321
 
1322
+ // Load filtered GS (already centered)
1323
  const filteredGs = await GVRM.initGS(filteredPlyUrl, undefined, undefined, scene);
1324
+ console.log('[preprocessManual] Filtered GS loaded (centered at origin)');
1325
 
1326
  ui.removeBoundingBox();
1327
  ui.setStatus('Loading VRM...');