stpete2 commited on
Commit
42a2d60
ยท
verified ยท
1 Parent(s): a341801

Upload preprocess_manual.js

Browse files
Files changed (1) hide show
  1. preprocess_manual.js +186 -100
preprocess_manual.js CHANGED
@@ -514,52 +514,146 @@ function createManualUI(scene, camera, renderer) {
514
  /**
515
  * Bounding Boxๅ†…ใฎใ‚นใƒ—ใƒฉใƒƒใƒˆใฎใฟใ‚’ใƒ•ใ‚ฃใƒซใ‚ฟใƒชใƒณใ‚ฐ
516
  */
517
- /////////////////////////////12/13 17:20 start
518
 
519
 
 
 
 
 
 
520
  function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0, y: 0, z: 0 }) {
 
 
 
 
 
 
 
 
 
 
 
 
521
  const halfX = boxSize.x / 2;
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
534
  const localPos = new THREE.Vector3(
535
  vertex.x - boxPosition.x,
536
  vertex.y - boxPosition.y,
537
  vertex.z - boxPosition.z
538
  );
539
 
540
- // Apply inverse rotation
541
  localPos.applyMatrix4(inverseRotationMatrix);
542
 
543
- // Check if inside box bounds
544
- return (
545
  localPos.x >= -halfX && localPos.x <= halfX &&
546
  localPos.y >= -halfY && localPos.y <= halfY &&
547
  localPos.z >= -halfZ && localPos.z <= halfZ
548
  );
 
 
549
  });
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;
559
  }
560
 
561
-
562
- //////////////////////////////12/13 17:20 end
563
 
564
 
565
  /**
@@ -1127,28 +1221,62 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
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;
@@ -1156,7 +1284,6 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1156
  vertex.z += plyOffset.z;
1157
  });
1158
 
1159
- // GSใ‚’ๅ†่ชญ่พผ
1160
  await gs.viewer.dispose();
1161
 
1162
  const newHeader = plyData.header;
@@ -1165,44 +1292,38 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
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
 
@@ -1219,50 +1340,23 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
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 => {
1267
  if (line.startsWith('element vertex')) {
1268
  return `element vertex ${filteredVertices.length}`;
@@ -1270,45 +1364,36 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1270
  return line;
1271
  });
1272
 
1273
- // Create PLY file data
1274
  const filteredPlyData = parser.createPLYFile(
1275
  newHeader,
1276
  filteredVertices,
1277
  plyData.vertexSize
1278
  );
1279
 
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:',
1292
- ((1 - filteredVertices.length / plyData.vertices.length) * 100).toFixed(1), '%');
1293
 
1294
- // Show success message
1295
  ui.setStatus(`โœ“ Saved: ${filteredFilename}`);
1296
-
1297
- // Wait a moment for user to see the message
1298
  await new Promise(resolve => setTimeout(resolve, 1000));
1299
 
1300
  } catch (error) {
1301
- console.error('[preprocessManual] Error saving filtered PLY:', error);
1302
  alert('Failed to save filtered PLY file: ' + error.message);
1303
- // Continue anyway
1304
  }
1305
 
1306
- // ========================================
1307
- // Continue with normal processing
1308
- // ========================================
1309
  ui.setStatus('Loading filtered splats...');
1310
 
1311
- // Create filtered PLY URL for loading into viewer
1312
  const filteredPlyUrl = createFilteredPLY(
1313
  parser,
1314
  plyData.header,
@@ -1316,27 +1401,27 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1316
  plyData.vertexSize
1317
  );
1318
 
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...');
1328
 
1329
- // Load VRM
1330
  const character = await GVRM.initVRM(vrmPath, scene, camera, renderer, null);
1331
- console.log('[preprocessManual] VRM loaded');
1332
 
1333
- // Create GVRM instance
1334
  const gvrm = new GVRM(character, filteredGs);
1335
 
1336
  ui.setStatus('Step 2: Assign splats to bones');
1337
  ui.showBoneAssignment();
1338
 
1339
- // Step 2: Bone Assignment
 
 
 
 
1340
  const promise2 = setupBoneAssignment(
1341
  ui, scene, camera, renderer,
1342
  gvrm, character, filteredGs, filteredPlyUrl,
@@ -1354,6 +1439,7 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
1354
  });
1355
  }
1356
 
 
1357
 
1358
  }); // GVRM.initGS().then()้–‰ใ˜ใ‚‹
1359
  }); // parser.parsePLY().then()้–‰ใ˜ใ‚‹
 
514
  /**
515
  * Bounding Boxๅ†…ใฎใ‚นใƒ—ใƒฉใƒƒใƒˆใฎใฟใ‚’ใƒ•ใ‚ฃใƒซใ‚ฟใƒชใƒณใ‚ฐ
516
  */
517
+ /////////////////////////////12/15 17:20 start
518
 
519
 
520
+ // ========================================
521
+ // ไฟฎๆญฃ็‰ˆ filterSplatsByBox ้–ขๆ•ฐ๏ผˆ่ฉณ็ดฐใชใƒ‡ใƒใƒƒใ‚ฐไป˜ใ๏ผ‰
522
+ // Line 594ไป˜่ฟ‘ใ‚’็ฝฎใๆ›ใˆ
523
+ // ========================================
524
+
525
  function filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation = { x: 0, y: 0, z: 0 }) {
526
+ console.log('[filterSplatsByBox] ===== FILTERING START =====');
527
+ console.log('[filterSplatsByBox] Input parameters:');
528
+ console.log(' Box Size:', boxSize);
529
+ console.log(' Box Position:', boxPosition);
530
+ console.log(' Box Rotation (radians):', boxRotation);
531
+ console.log(' Box Rotation (degrees):', {
532
+ x: (boxRotation.x * 180 / Math.PI).toFixed(1),
533
+ y: (boxRotation.y * 180 / Math.PI).toFixed(1),
534
+ z: (boxRotation.z * 180 / Math.PI).toFixed(1)
535
+ });
536
+ console.log(' Total input vertices:', plyData.vertices.length);
537
+
538
  const halfX = boxSize.x / 2;
539
  const halfY = boxSize.y / 2;
540
  const halfZ = boxSize.z / 2;
541
 
542
+ console.log('[filterSplatsByBox] Box half-extents:', { halfX, halfY, halfZ });
543
+
544
+ // Create rotation matrix
545
  const rotationMatrix = new THREE.Matrix4();
546
  rotationMatrix.makeRotationFromEuler(new THREE.Euler(boxRotation.x, boxRotation.y, boxRotation.z));
547
 
548
  // Inverse matrix for transforming points into box space
549
  const inverseRotationMatrix = new THREE.Matrix4().copy(rotationMatrix).invert();
550
 
551
+ console.log('[filterSplatsByBox] Rotation matrix created');
552
+
553
+ // ใƒ‡ใƒใƒƒใ‚ฐ: ๆœ€ๅˆใฎ10ๅ€‹ใฎ้ ‚็‚นใ‚’่ฉณ็ดฐใซใƒญใ‚ฐ
554
+ console.log('[filterSplatsByBox] Sample vertices (first 10):');
555
+ for (let i = 0; i < Math.min(10, plyData.vertices.length); i++) {
556
+ const v = plyData.vertices[i];
557
+ const localPos = new THREE.Vector3(
558
+ v.x - boxPosition.x,
559
+ v.y - boxPosition.y,
560
+ v.z - boxPosition.z
561
+ );
562
+ localPos.applyMatrix4(inverseRotationMatrix);
563
+
564
+ const inside = (
565
+ localPos.x >= -halfX && localPos.x <= halfX &&
566
+ localPos.y >= -halfY && localPos.y <= halfY &&
567
+ localPos.z >= -halfZ && localPos.z <= halfZ
568
+ );
569
+
570
+ console.log(` Vertex ${i}:`, {
571
+ world: { x: v.x.toFixed(3), y: v.y.toFixed(3), z: v.z.toFixed(3) },
572
+ local: { x: localPos.x.toFixed(3), y: localPos.y.toFixed(3), z: localPos.z.toFixed(3) },
573
+ inside: inside
574
+ });
575
+ }
576
+
577
+ // ๅฎŸ้š›ใฎใƒ•ใ‚ฃใƒซใ‚ฟใƒชใƒณใ‚ฐ
578
+ const filteredVertices = plyData.vertices.filter((vertex, index) => {
579
  const localPos = new THREE.Vector3(
580
  vertex.x - boxPosition.x,
581
  vertex.y - boxPosition.y,
582
  vertex.z - boxPosition.z
583
  );
584
 
 
585
  localPos.applyMatrix4(inverseRotationMatrix);
586
 
587
+ const inside = (
 
588
  localPos.x >= -halfX && localPos.x <= halfX &&
589
  localPos.y >= -halfY && localPos.y <= halfY &&
590
  localPos.z >= -halfZ && localPos.z <= halfZ
591
  );
592
+
593
+ return inside;
594
  });
595
 
596
+ // ใƒ•ใ‚ฃใƒซใ‚ฟใƒชใƒณใ‚ฐ็ตๆžœใฎ็ตฑ่จˆ
597
+ const retentionRate = (filteredVertices.length / plyData.vertices.length * 100).toFixed(1);
598
 
599
+ console.log('[filterSplatsByBox] ===== FILTERING COMPLETE =====');
600
+ console.log('[filterSplatsByBox] Results:');
601
+ console.log(' Filtered:', filteredVertices.length, '/', plyData.vertices.length);
602
+ console.log(' Retention rate:', retentionRate, '%');
603
+
604
+ // ใƒ•ใ‚ฃใƒซใ‚ฟใƒชใƒณใ‚ฐๅพŒใฎ็ฏ„ๅ›ฒใ‚’่จˆ็ฎ—
605
+ if (filteredVertices.length > 0) {
606
+ let minX = Infinity, minY = Infinity, minZ = Infinity;
607
+ let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
608
+
609
+ filteredVertices.forEach(v => {
610
+ minX = Math.min(minX, v.x);
611
+ minY = Math.min(minY, v.y);
612
+ minZ = Math.min(minZ, v.z);
613
+ maxX = Math.max(maxX, v.x);
614
+ maxY = Math.max(maxY, v.y);
615
+ maxZ = Math.max(maxZ, v.z);
616
+ });
617
+
618
+ console.log('[filterSplatsByBox] Filtered bounds (world space):');
619
+ console.log(' X:', minX.toFixed(3), 'to', maxX.toFixed(3), '(size:', (maxX - minX).toFixed(3), ')');
620
+ console.log(' Y:', minY.toFixed(3), 'to', maxY.toFixed(3), '(size:', (maxY - minY).toFixed(3), ')');
621
+ console.log(' Z:', minZ.toFixed(3), 'to', maxZ.toFixed(3), '(size:', (maxZ - minZ).toFixed(3), ')');
622
+ console.log(' Center:', {
623
+ x: ((minX + maxX) / 2).toFixed(3),
624
+ y: ((minY + maxY) / 2).toFixed(3),
625
+ z: ((minZ + maxZ) / 2).toFixed(3)
626
+ });
627
+
628
+ // ๆœŸๅพ…ใ•ใ‚Œใ‚‹BOXใฎ็ฏ„ๅ›ฒใจๆฏ”่ผƒ
629
+ const expectedMinX = boxPosition.x - halfX;
630
+ const expectedMaxX = boxPosition.x + halfX;
631
+ const expectedMinY = boxPosition.y - halfY;
632
+ const expectedMaxY = boxPosition.y + halfY;
633
+ const expectedMinZ = boxPosition.z - halfZ;
634
+ const expectedMaxZ = boxPosition.z + halfZ;
635
+
636
+ console.log('[filterSplatsByBox] Expected bounds (if rotation = 0):');
637
+ console.log(' X:', expectedMinX.toFixed(3), 'to', expectedMaxX.toFixed(3));
638
+ console.log(' Y:', expectedMinY.toFixed(3), 'to', expectedMaxY.toFixed(3));
639
+ console.log(' Z:', expectedMinZ.toFixed(3), 'to', expectedMaxZ.toFixed(3));
640
+ }
641
+
642
+ // ่ญฆๅ‘Š
643
  if (filteredVertices.length < plyData.vertices.length * 0.1) {
644
  console.warn('[filterSplatsByBox] โš ๏ธ WARNING: Less than 10% of splats kept!');
645
  console.warn('[filterSplatsByBox] Box may be too small or positioned incorrectly');
646
  }
647
 
648
+ if (filteredVertices.length === 0) {
649
+ console.error('[filterSplatsByBox] โŒ ERROR: No vertices passed the filter!');
650
+ console.error('[filterSplatsByBox] Check box position and size');
651
+ }
652
+
653
  return filteredVertices;
654
  }
655
 
656
+ //////////////////////////////12/15 17:20 end
 
657
 
658
 
659
  /**
 
1221
  // ----------------------------------------
1222
  /////////////////// 12/15 18:00 ๅ…จ้ขๆใ็›ดใ—
1223
 
1224
+ // ========================================
1225
+ // ไฟฎๆญฃ็‰ˆ confirmBoxBtn๏ผˆๅฎŒๅ…จใชใƒ‡ใƒใƒƒใ‚ฐ็‰ˆ๏ผ‰
1226
+ // Line 1090-1220ไป˜่ฟ‘ใ‚’็ฝฎใๆ›ใˆ
1227
+ // ========================================
1228
+
1229
  const confirmBoxBtn = document.getElementById('confirm-box-btn');
1230
  if (confirmBoxBtn) {
1231
  confirmBoxBtn.addEventListener('click', async () => {
1232
+ console.log('\n\n');
1233
+ console.log('โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•');
1234
+ console.log(' CONFIRM BOX BUTTON CLICKED');
1235
+ console.log('โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•');
1236
+
1237
+ // ็พๅœจใฎBOX่จญๅฎšใ‚’ใƒญใ‚ฐ
1238
+ console.log('[STEP 1] Current BOX Settings:');
1239
+ console.log(' Box Size:', boxSize);
1240
+ console.log(' Box Position:', boxPosition);
1241
+ console.log(' Box Rotation (radians):', boxRotation);
1242
+ console.log(' Box Rotation (degrees):', {
1243
+ x: (boxRotation.x * 180 / Math.PI).toFixed(1) + 'ยฐ',
1244
+ y: (boxRotation.y * 180 / Math.PI).toFixed(1) + 'ยฐ',
1245
+ z: (boxRotation.z * 180 / Math.PI).toFixed(1) + 'ยฐ'
1246
+ });
1247
+ console.log(' PLY Offset:', plyOffset);
1248
+
1249
+ // ๅ…ƒใฎPLYใƒ‡ใƒผใ‚ฟใฎ็ฏ„ๅ›ฒใ‚’่กจ็คบ
1250
+ console.log('[STEP 2] Original PLY Data:');
1251
+ console.log(' Total vertices:', plyData.vertices.length);
1252
+
1253
+ let origMinX = Infinity, origMinY = Infinity, origMinZ = Infinity;
1254
+ let origMaxX = -Infinity, origMaxY = -Infinity, origMaxZ = -Infinity;
1255
+
1256
+ plyData.vertices.forEach(v => {
1257
+ origMinX = Math.min(origMinX, v.x);
1258
+ origMinY = Math.min(origMinY, v.y);
1259
+ origMinZ = Math.min(origMinZ, v.z);
1260
+ origMaxX = Math.max(origMaxX, v.x);
1261
+ origMaxY = Math.max(origMaxY, v.y);
1262
+ origMaxZ = Math.max(origMaxZ, v.z);
1263
+ });
1264
+
1265
+ console.log(' Original bounds:');
1266
+ console.log(' X:', origMinX.toFixed(3), 'to', origMaxX.toFixed(3));
1267
+ console.log(' Y:', origMinY.toFixed(3), 'to', origMaxY.toFixed(3));
1268
+ console.log(' Z:', origMinZ.toFixed(3), 'to', origMaxZ.toFixed(3));
1269
+ console.log(' Original center:', {
1270
+ x: ((origMinX + origMaxX) / 2).toFixed(3),
1271
+ y: ((origMinY + origMaxY) / 2).toFixed(3),
1272
+ z: ((origMinZ + origMaxZ) / 2).toFixed(3)
1273
  });
1274
 
1275
  cleanupAnimation();
1276
 
1277
+ // PLY Offsetใฎ้ฉ็”จ
 
 
1278
  if (plyOffset.x !== 0 || plyOffset.y !== 0 || plyOffset.z !== 0) {
1279
+ console.log('[STEP 3] Applying PLY offset:', plyOffset);
1280
 
1281
  plyData.vertices.forEach(vertex => {
1282
  vertex.x += plyOffset.x;
 
1284
  vertex.z += plyOffset.z;
1285
  });
1286
 
 
1287
  await gs.viewer.dispose();
1288
 
1289
  const newHeader = plyData.header;
 
1292
  const adjustedPlyUrl = URL.createObjectURL(blob);
1293
 
1294
  gs = await GVRM.initGS(adjustedPlyUrl, undefined, undefined, scene);
1295
+ console.log('[STEP 3] โœ“ GS reloaded with adjusted position');
1296
 
1297
+ // PLY offsetใ‚’ใƒชใ‚ปใƒƒใƒˆ
1298
  plyOffset = { x: 0, y: 0, z: 0 };
1299
+ } else {
1300
+ console.log('[STEP 3] No PLY offset to apply');
1301
  }
1302
 
1303
  ui.hidePositionAdjustment();
1304
  ui.setStatus('Filtering splats with bounding box...');
1305
 
1306
+ // ใƒ•ใ‚ฃใƒซใ‚ฟใƒชใƒณใ‚ฐๅฎŸ่กŒ
1307
+ console.log('[STEP 4] Starting filtering...');
 
 
 
 
1308
  const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation);
1309
 
 
 
 
1310
  if (filteredVertices.length === 0) {
1311
+ console.error('[STEP 4] โŒ No splats found in the box!');
1312
+ 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.');
1313
  ui.showPositionAdjustment();
1314
  return;
1315
  }
1316
 
1317
  if (filteredVertices.length < 10) {
1318
+ console.warn('[STEP 4] โš ๏ธ Only', filteredVertices.length, 'splats found');
1319
+ alert(`โš ๏ธ Only ${filteredVertices.length} splats found!\n\nThis is too few. Please adjust the box.\n\nCheck the browser console for detailed debug information.`);
1320
  ui.showPositionAdjustment();
1321
  return;
1322
  }
1323
 
1324
+ // ใ‚นใƒ—ใƒฉใƒƒใƒˆใ‚’ไธญๅฟƒๅŒ–
1325
+ console.log('[STEP 5] Centering splats...');
 
 
1326
 
 
1327
  let newMinX = Infinity, newMinY = Infinity, newMinZ = Infinity;
1328
  let newMaxX = -Infinity, newMaxY = -Infinity, newMaxZ = -Infinity;
1329
 
 
1340
  const centerY = (newMaxY + newMinY) / 2;
1341
  const centerZ = (newMaxZ + newMinZ) / 2;
1342
 
1343
+ console.log('[STEP 5] Before centering:', {
1344
+ center: { x: centerX.toFixed(3), y: centerY.toFixed(3), z: centerZ.toFixed(3) }
 
 
1345
  });
1346
 
 
1347
  filteredVertices.forEach(vertex => {
1348
  vertex.x -= centerX;
1349
  vertex.y -= centerY;
1350
  vertex.z -= centerZ;
1351
  });
1352
 
1353
+ console.log('[STEP 5] โœ“ Splats centered to origin');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1354
 
1355
+ // ใƒ•ใ‚ฃใƒซใ‚ฟๆธˆใฟPLYใ‚’ไฟๅญ˜
1356
+ console.log('[STEP 6] Saving filtered PLY...');
 
1357
  try {
1358
  ui.setStatus('Saving filtered & centered PLY file...');
1359
 
 
1360
  const newHeader = plyData.header.map(line => {
1361
  if (line.startsWith('element vertex')) {
1362
  return `element vertex ${filteredVertices.length}`;
 
1364
  return line;
1365
  });
1366
 
 
1367
  const filteredPlyData = parser.createPLYFile(
1368
  newHeader,
1369
  filteredVertices,
1370
  plyData.vertexSize
1371
  );
1372
 
 
1373
  const originalFilename = gsPath.split('/').pop().replace('.ply', '');
1374
  const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, -5);
1375
+ const filteredFilename = `${originalFilename}_filtered_${timestamp}.ply`;
1376
 
 
1377
  downloadPLY(filteredPlyData, filteredFilename);
1378
 
1379
+ console.log('[STEP 6] โœ“ PLY saved:', filteredFilename);
1380
+ console.log('[STEP 6] Statistics:');
1381
+ console.log(' Original:', plyData.vertices.length, 'vertices');
1382
+ console.log(' Filtered:', filteredVertices.length, 'vertices');
1383
+ console.log(' Reduction:', ((1 - filteredVertices.length / plyData.vertices.length) * 100).toFixed(1), '%');
1384
 
 
1385
  ui.setStatus(`โœ“ Saved: ${filteredFilename}`);
 
 
1386
  await new Promise(resolve => setTimeout(resolve, 1000));
1387
 
1388
  } catch (error) {
1389
+ console.error('[STEP 6] โŒ Error saving PLY:', error);
1390
  alert('Failed to save filtered PLY file: ' + error.message);
 
1391
  }
1392
 
1393
+ // ๆฎ‹ใ‚Šใฎๅ‡ฆ็†
1394
+ console.log('[STEP 7] Loading filtered splats into viewer...');
 
1395
  ui.setStatus('Loading filtered splats...');
1396
 
 
1397
  const filteredPlyUrl = createFilteredPLY(
1398
  parser,
1399
  plyData.header,
 
1401
  plyData.vertexSize
1402
  );
1403
 
 
1404
  await gs.viewer.dispose();
1405
 
 
1406
  const filteredGs = await GVRM.initGS(filteredPlyUrl, undefined, undefined, scene);
1407
+ console.log('[STEP 7] โœ“ Filtered GS loaded');
1408
 
1409
  ui.removeBoundingBox();
1410
  ui.setStatus('Loading VRM...');
1411
 
 
1412
  const character = await GVRM.initVRM(vrmPath, scene, camera, renderer, null);
1413
+ console.log('[STEP 7] โœ“ VRM loaded');
1414
 
 
1415
  const gvrm = new GVRM(character, filteredGs);
1416
 
1417
  ui.setStatus('Step 2: Assign splats to bones');
1418
  ui.showBoneAssignment();
1419
 
1420
+ console.log('โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•');
1421
+ console.log(' BOX FILTERING COMPLETE');
1422
+ console.log('โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•');
1423
+ console.log('\n\n');
1424
+
1425
  const promise2 = setupBoneAssignment(
1426
  ui, scene, camera, renderer,
1427
  gvrm, character, filteredGs, filteredPlyUrl,
 
1439
  });
1440
  }
1441
 
1442
+ ////////////////// 12/15 18:00 ๅ…จ้ขๆใ็›ดใ—
1443
 
1444
  }); // GVRM.initGS().then()้–‰ใ˜ใ‚‹
1445
  }); // parser.parsePLY().then()้–‰ใ˜ใ‚‹