Upload preprocess_manual.js
Browse files- preprocess_manual.js +113 -9
preprocess_manual.js
CHANGED
|
@@ -219,6 +219,28 @@ function createManualUI(scene, camera, renderer) {
|
|
| 219 |
width: 48%;
|
| 220 |
margin-right: 2%;
|
| 221 |
">Reset All</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
<button id="confirm-box-btn" style="
|
| 223 |
margin-top: 10px;
|
| 224 |
padding: 8px 15px;
|
|
@@ -559,7 +581,36 @@ function createFilteredPLY(parser, originalHeader, filteredVertices, vertexSize)
|
|
| 559 |
return URL.createObjectURL(blob);
|
| 560 |
}
|
| 561 |
|
| 562 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
|
| 564 |
// ========================================
|
| 565 |
// Keyboard Controls - Global Variables and Helper Functions
|
|
@@ -1068,6 +1119,12 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
|
|
| 1068 |
/////////////////////////12/13 17:15 end
|
| 1069 |
|
| 1070 |
// Confirm button
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1071 |
const confirmBoxBtn = document.getElementById('confirm-box-btn');
|
| 1072 |
if (confirmBoxBtn) {
|
| 1073 |
confirmBoxBtn.addEventListener('click', async () => {
|
|
@@ -1098,12 +1155,8 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
|
|
| 1098 |
ui.setStatus('Filtering splats with bounding box...');
|
| 1099 |
|
| 1100 |
// Filter splats immediately
|
| 1101 |
-
/////////////////////12/13 17:27
|
| 1102 |
-
|
| 1103 |
-
//const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition);
|
| 1104 |
const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation);
|
| 1105 |
-
|
| 1106 |
-
|
| 1107 |
if (filteredVertices.length === 0) {
|
| 1108 |
alert('No splats found in the box! Please adjust the box size/position and try again.');
|
| 1109 |
ui.showPositionAdjustment();
|
|
@@ -1112,7 +1165,59 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
|
|
| 1112 |
|
| 1113 |
console.log(`[preprocessManual] Filtered ${filteredVertices.length}/${plyData.vertices.length} splats`);
|
| 1114 |
|
| 1115 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1116 |
const filteredPlyUrl = createFilteredPLY(
|
| 1117 |
parser,
|
| 1118 |
plyData.header,
|
|
@@ -1140,9 +1245,7 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
|
|
| 1140 |
ui.setStatus('Step 2: Assign splats to bones');
|
| 1141 |
ui.showBoneAssignment();
|
| 1142 |
|
| 1143 |
-
// ========================================
|
| 1144 |
// Step 2: Bone Assignment
|
| 1145 |
-
// ========================================
|
| 1146 |
const promise2 = setupBoneAssignment(
|
| 1147 |
ui, scene, camera, renderer,
|
| 1148 |
gvrm, character, filteredGs, filteredPlyUrl,
|
|
@@ -1160,6 +1263,7 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
|
|
| 1160 |
});
|
| 1161 |
}
|
| 1162 |
|
|
|
|
| 1163 |
}); // GVRM.initGS().then()閉じる
|
| 1164 |
}); // parser.parsePLY().then()閉じる
|
| 1165 |
}); // ui.initialize().then()閉じる
|
|
|
|
| 219 |
width: 48%;
|
| 220 |
margin-right: 2%;
|
| 221 |
">Reset All</button>
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
<!-- 保存状態表示 -->
|
| 225 |
+
<div id="save-status" style="
|
| 226 |
+
margin: 10px 0;
|
| 227 |
+
padding: 8px;
|
| 228 |
+
background: #1a1a2e;
|
| 229 |
+
border-radius: 5px;
|
| 230 |
+
font-size: 11px;
|
| 231 |
+
color: #4CAF50;
|
| 232 |
+
display: none;
|
| 233 |
+
border-left: 3px solid #4CAF50;
|
| 234 |
+
">
|
| 235 |
+
💾 Filtered PLY will be saved on confirm
|
| 236 |
+
</div>
|
| 237 |
+
|
| 238 |
+
<button id="reset-all-btn" style="...">Reset All</button>
|
| 239 |
+
<button id="confirm-box-btn" style="...">✓ Confirm & Filter</button>
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
|
| 244 |
<button id="confirm-box-btn" style="
|
| 245 |
margin-top: 10px;
|
| 246 |
padding: 8px 15px;
|
|
|
|
| 581 |
return URL.createObjectURL(blob);
|
| 582 |
}
|
| 583 |
|
| 584 |
+
//////////////////////////////////////////////12/14 13:40 start
|
| 585 |
+
|
| 586 |
+
/**
|
| 587 |
+
* PLYファイルをダウンロード
|
| 588 |
+
*/
|
| 589 |
+
function downloadPLY(plyData, filename) {
|
| 590 |
+
const blob = new Blob([plyData], { type: 'application/octet-stream' });
|
| 591 |
+
const url = URL.createObjectURL(blob);
|
| 592 |
+
|
| 593 |
+
const link = document.createElement('a');
|
| 594 |
+
link.href = url;
|
| 595 |
+
link.download = filename;
|
| 596 |
+
link.style.display = 'none';
|
| 597 |
+
|
| 598 |
+
document.body.appendChild(link);
|
| 599 |
+
link.click();
|
| 600 |
+
|
| 601 |
+
// クリーンアップ
|
| 602 |
+
setTimeout(() => {
|
| 603 |
+
document.body.removeChild(link);
|
| 604 |
+
URL.revokeObjectURL(url);
|
| 605 |
+
}, 100);
|
| 606 |
+
|
| 607 |
+
console.log('[downloadPLY] Downloaded:', filename);
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
//////////////////////////////////////////////12/14 13:40 end
|
| 612 |
+
|
| 613 |
+
///////////////////////////////////////////////////12/13 14:00
|
| 614 |
|
| 615 |
// ========================================
|
| 616 |
// Keyboard Controls - Global Variables and Helper Functions
|
|
|
|
| 1119 |
/////////////////////////12/13 17:15 end
|
| 1120 |
|
| 1121 |
// Confirm button
|
| 1122 |
+
|
| 1123 |
+
// ----------------------------------------
|
| 1124 |
+
// 完全版: confirmBoxBtn のイベントリスナー
|
| 1125 |
+
// Line 1107から約100行を以下に置き換え
|
| 1126 |
+
// ----------------------------------------
|
| 1127 |
+
|
| 1128 |
const confirmBoxBtn = document.getElementById('confirm-box-btn');
|
| 1129 |
if (confirmBoxBtn) {
|
| 1130 |
confirmBoxBtn.addEventListener('click', async () => {
|
|
|
|
| 1155 |
ui.setStatus('Filtering splats with bounding box...');
|
| 1156 |
|
| 1157 |
// Filter splats immediately
|
|
|
|
|
|
|
|
|
|
| 1158 |
const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition, boxRotation);
|
| 1159 |
+
|
|
|
|
| 1160 |
if (filteredVertices.length === 0) {
|
| 1161 |
alert('No splats found in the box! Please adjust the box size/position and try again.');
|
| 1162 |
ui.showPositionAdjustment();
|
|
|
|
| 1165 |
|
| 1166 |
console.log(`[preprocessManual] Filtered ${filteredVertices.length}/${plyData.vertices.length} splats`);
|
| 1167 |
|
| 1168 |
+
// ========================================
|
| 1169 |
+
// ⭐ フィルタ済みPLYファイルを保存
|
| 1170 |
+
// ========================================
|
| 1171 |
+
try {
|
| 1172 |
+
ui.setStatus('Saving filtered PLY file...');
|
| 1173 |
+
|
| 1174 |
+
// Create new header with updated vertex count
|
| 1175 |
+
const newHeader = plyData.header.map(line => {
|
| 1176 |
+
if (line.startsWith('element vertex')) {
|
| 1177 |
+
return `element vertex ${filteredVertices.length}`;
|
| 1178 |
+
}
|
| 1179 |
+
return line;
|
| 1180 |
+
});
|
| 1181 |
+
|
| 1182 |
+
// Create PLY file data
|
| 1183 |
+
const filteredPlyData = parser.createPLYFile(
|
| 1184 |
+
newHeader,
|
| 1185 |
+
filteredVertices,
|
| 1186 |
+
plyData.vertexSize
|
| 1187 |
+
);
|
| 1188 |
+
|
| 1189 |
+
// Generate filename
|
| 1190 |
+
const originalFilename = gsPath.split('/').pop().replace('.ply', '');
|
| 1191 |
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, -5);
|
| 1192 |
+
const filteredFilename = `${originalFilename}_filtered_${timestamp}.ply`;
|
| 1193 |
+
|
| 1194 |
+
// Download the file
|
| 1195 |
+
downloadPLY(filteredPlyData, filteredFilename);
|
| 1196 |
+
|
| 1197 |
+
console.log('[preprocessManual] ✓ Filtered PLY saved:', filteredFilename);
|
| 1198 |
+
console.log('[preprocessManual] Original vertices:', plyData.vertices.length);
|
| 1199 |
+
console.log('[preprocessManual] Filtered vertices:', filteredVertices.length);
|
| 1200 |
+
console.log('[preprocessManual] Reduction:',
|
| 1201 |
+
((1 - filteredVertices.length / plyData.vertices.length) * 100).toFixed(1), '%');
|
| 1202 |
+
|
| 1203 |
+
// Show success message
|
| 1204 |
+
ui.setStatus(`✓ Saved: ${filteredFilename}`);
|
| 1205 |
+
|
| 1206 |
+
// Wait a moment for user to see the message
|
| 1207 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
| 1208 |
+
|
| 1209 |
+
} catch (error) {
|
| 1210 |
+
console.error('[preprocessManual] Error saving filtered PLY:', error);
|
| 1211 |
+
alert('Failed to save filtered PLY file: ' + error.message);
|
| 1212 |
+
// Continue anyway
|
| 1213 |
+
}
|
| 1214 |
+
|
| 1215 |
+
// ========================================
|
| 1216 |
+
// Continue with normal processing
|
| 1217 |
+
// ========================================
|
| 1218 |
+
ui.setStatus('Loading filtered splats...');
|
| 1219 |
+
|
| 1220 |
+
// Create filtered PLY URL for loading into viewer
|
| 1221 |
const filteredPlyUrl = createFilteredPLY(
|
| 1222 |
parser,
|
| 1223 |
plyData.header,
|
|
|
|
| 1245 |
ui.setStatus('Step 2: Assign splats to bones');
|
| 1246 |
ui.showBoneAssignment();
|
| 1247 |
|
|
|
|
| 1248 |
// Step 2: Bone Assignment
|
|
|
|
| 1249 |
const promise2 = setupBoneAssignment(
|
| 1250 |
ui, scene, camera, renderer,
|
| 1251 |
gvrm, character, filteredGs, filteredPlyUrl,
|
|
|
|
| 1263 |
});
|
| 1264 |
}
|
| 1265 |
|
| 1266 |
+
|
| 1267 |
}); // GVRM.initGS().then()閉じる
|
| 1268 |
}); // parser.parsePLY().then()閉じる
|
| 1269 |
}); // ui.initialize().then()閉じる
|