Upload preprocess_manual.js
Browse files- 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/
|
| 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 |
-
|
| 533 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 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 |
-
|
|
|
|
| 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('
|
| 1134 |
-
console.log('
|
| 1135 |
-
|
| 1136 |
-
|
| 1137 |
-
|
| 1138 |
-
|
| 1139 |
-
|
| 1140 |
-
|
| 1141 |
-
|
| 1142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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('[
|
| 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('[
|
| 1169 |
|
| 1170 |
-
//
|
| 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 |
-
|
|
|
|
| 1190 |
ui.showPositionAdjustment();
|
| 1191 |
return;
|
| 1192 |
}
|
| 1193 |
|
| 1194 |
if (filteredVertices.length < 10) {
|
| 1195 |
-
|
|
|
|
| 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('[
|
| 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 |
-
|
| 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}
|
| 1284 |
|
| 1285 |
-
// Download the file
|
| 1286 |
downloadPLY(filteredPlyData, filteredFilename);
|
| 1287 |
|
| 1288 |
-
console.log('[
|
| 1289 |
-
console.log('[
|
| 1290 |
-
console.log('
|
| 1291 |
-
console.log('
|
| 1292 |
-
|
| 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('[
|
| 1302 |
alert('Failed to save filtered PLY file: ' + error.message);
|
| 1303 |
-
// Continue anyway
|
| 1304 |
}
|
| 1305 |
|
| 1306 |
-
//
|
| 1307 |
-
|
| 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('[
|
| 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('[
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()้ใใ
|