Upload 2 files
Browse files- log.md +11 -47
- preprocess_manual.js +228 -295
log.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
preprocess_manual.js:16 [preprocess_manual.js] ===== MODULE LOADING =====
|
| 3 |
main.js:16 [MAIN] DOMContentLoaded fired
|
| 4 |
main.js:269 [MAIN] Calling setupPathsFromUrlOrSelect...
|
| 5 |
main.js:46 [MAIN] setupPathsFromUrlOrSelect started
|
|
@@ -21,32 +20,32 @@ main.js:190 [MAIN] Manual file selected: fountain_trim9.ply Extension: ply
|
|
| 21 |
main.js:198 [MAIN] Reading manual file...
|
| 22 |
main.js:201 [MAIN] Manual file read complete, size: 57407083
|
| 23 |
main.js:209 [MAIN] Manual mode file loaded: fountain_trim9.ply
|
| 24 |
-
main.js:210 [MAIN] gsPath: blob:http://127.0.0.1:5500/
|
| 25 |
main.js:211 [MAIN] gsFileName: fountain_trim9.ply
|
| 26 |
main.js:110 [MAIN] Hiding select UI
|
| 27 |
main.js:215 [MAIN] ===== Resolving with MANUAL MODE =====
|
| 28 |
main.js:261 [MAIN] File load promise resolved: Object
|
| 29 |
main.js:271 [MAIN] setupPathsFromUrlOrSelect returned: Object
|
| 30 |
main.js:277 [MAIN] After pathResult:
|
| 31 |
-
main.js:278 - gsPath: blob:http://127.0.0.1:5500/
|
| 32 |
main.js:279 - gvrmPath: undefined
|
| 33 |
main.js:280 - isManualMode: true
|
| 34 |
main.js:283 [MAIN] Initializing renderer...
|
| 35 |
main.js:289 [MAIN] Initializing camera...
|
| 36 |
main.js:316 [MAIN] Initializing scene...
|
| 37 |
main.js:323 [MAIN] Three.js initialization complete
|
| 38 |
-
main.js:506 [MAIN] Processing GS file: blob:http://127.0.0.1:5500/
|
| 39 |
main.js:507 [MAIN] Manual mode: true
|
| 40 |
main.js:519 [MAIN] fileName: fountain_trim9.gvrm
|
| 41 |
main.js:529 [MAIN] ===== STARTING MANUAL PREPROCESSING MODE =====
|
| 42 |
main.js:530 [MAIN] Parameters:
|
| 43 |
main.js:531 - vrmPath: ./assets/sotai.vrm
|
| 44 |
-
main.js:532 - gsPath: blob:http://127.0.0.1:5500/
|
| 45 |
main.js:533 - fileName: fountain_trim9.gvrm
|
| 46 |
preprocess_manual.js:977 [preprocessManual] ===== FUNCTION CALLED =====
|
| 47 |
preprocess_manual.js:978 [preprocessManual] Parameters:
|
| 48 |
preprocess_manual.js:979 vrmPath: ./assets/sotai.vrm
|
| 49 |
-
preprocess_manual.js:980 gsPath: blob:http://127.0.0.1:5500/
|
| 50 |
preprocess_manual.js:981 fileName: fountain_trim9.gvrm
|
| 51 |
preprocess_manual.js:984 [preprocessManual] Creating Promise...
|
| 52 |
preprocess_manual.js:84 [createManualUI] Creating manual preprocessing UI...
|
|
@@ -81,7 +80,6 @@ preprocess_manual.js:1610 [preprocessManual] Camera positioned at: Object
|
|
| 81 |
preprocess_manual.js:1617 [preprocessManual] Initial box setup - size: Object
|
| 82 |
preprocess_manual.js:1660 [preprocessManual] UI sliders initialized to PLY-aligned values
|
| 83 |
preprocess_manual.js:1666 [preprocessManual] ✓ Camera and Box aligned to PLY
|
| 84 |
-
preprocess_manual.js:1546 [animateControls] Status check: Object
|
| 85 |
preprocess_manual.js:1399
|
| 86 |
|
| 87 |
|
|
@@ -192,8 +190,8 @@ preprocess_manual.js:2048 [STEP 5] Centering splats...
|
|
| 192 |
preprocess_manual.js:2066 [STEP 5] Before centering: Object
|
| 193 |
preprocess_manual.js:2076 [STEP 5] ✓ Splats centered to origin
|
| 194 |
preprocess_manual.js:2079 [STEP 6] Saving filtered PLY...
|
| 195 |
-
preprocess_manual.js:770 [downloadPLY] Downloaded:
|
| 196 |
-
preprocess_manual.js:2102 [STEP 6] ✓ PLY saved:
|
| 197 |
preprocess_manual.js:2103 [STEP 6] Statistics:
|
| 198 |
preprocess_manual.js:2104 Original: 231474 vertices
|
| 199 |
preprocess_manual.js:2105 Filtered: 202550 vertices
|
|
@@ -219,40 +217,6 @@ preprocess_manual.js:2302 [setupBoneAssignment] Available bones: 54
|
|
| 219 |
preprocess_manual.js:2303 [setupBoneAssignment] Bone names: Array(54)
|
| 220 |
preprocess_manual.js:2343 [updateBoneSelector] Updating for mode: required19
|
| 221 |
preprocess_manual.js:2355 [updateBoneSelector] Added 20 groups
|
| 222 |
-
preprocess_manual.js:
|
| 223 |
-
|
| 224 |
-
preprocess_manual.
|
| 225 |
-
preprocess_manual.js:2580 - Paint mode with drag support
|
| 226 |
-
preprocess_manual.js:2581 - Smooth brush strokes with interpolation
|
| 227 |
-
preprocess_manual.js:2582 - Sphere selection with improved center detection
|
| 228 |
-
preprocess_manual.js:3013 [setupBoneAssignment] ✓ Improved splat selection system initialized
|
| 229 |
-
preprocess_manual.js:3014 [setupBoneAssignment] Features:
|
| 230 |
-
preprocess_manual.js:3015 - Finds nearest splat within 50px (adjustable)
|
| 231 |
-
preprocess_manual.js:3016 - Paint mode with drag support
|
| 232 |
-
preprocess_manual.js:3017 - Smooth brush strokes with interpolation
|
| 233 |
-
preprocess_manual.js:3018 - Sphere selection with improved center detection
|
| 234 |
-
preprocess_manual.js:3027 [setupBoneAssignment] Camera controls initialized
|
| 235 |
-
preprocess_manual.js:3040 [setupBoneAssignment] Setting up camera lock...
|
| 236 |
-
preprocess_manual.js:3047 [setupBoneAssignment] ✓ Camera lock button found
|
| 237 |
-
preprocess_manual.js:3111 [setupBoneAssignment] ✓ Camera lock button configured
|
| 238 |
-
preprocess_manual.js:3112 [setupBoneAssignment] Initial state: UNLOCKED
|
| 239 |
-
preprocess_manual.js:2405 [setupBoneAssignment] Paint mode enabled
|
| 240 |
-
preprocess_manual.js:2390 [setupBoneAssignment] Selected target: group_0
|
| 241 |
-
preprocess_manual.js:2909 Uncaught ReferenceError: getTargetColor is not defined
|
| 242 |
-
at applyAssignmentToIndices (preprocess_manual.js:2909:25)
|
| 243 |
-
at handlePaintAtPosition (preprocess_manual.js:2876:5)
|
| 244 |
-
at HTMLCanvasElement.<anonymous> (preprocess_manual.js:2475:3)Understand this error
|
| 245 |
-
preprocess_manual.js:2909 Uncaught ReferenceError: getTargetColor is not defined
|
| 246 |
-
at applyAssignmentToIndices (preprocess_manual.js:2909:25)
|
| 247 |
-
at handlePaintAtPosition (preprocess_manual.js:2876:5)
|
| 248 |
-
at HTMLCanvasElement.<anonymous> (preprocess_manual.js:2835:3)Understand this error
|
| 249 |
-
preprocess_manual.js:3134 [setupBoneAssignment] Assigning splats around center to group_0
|
| 250 |
-
preprocess_manual.js:3154 [setupBoneAssignment] Group: 1. Head Bones: Array(1)
|
| 251 |
-
preprocess_manual.js:2909 Uncaught ReferenceError: getTargetColor is not defined
|
| 252 |
-
at applyAssignmentToIndices (preprocess_manual.js:2909:25)
|
| 253 |
-
at HTMLCanvasElement.<anonymous> (preprocess_manual.js:2494:5)Understand this error
|
| 254 |
-
preprocess_manual.js:2909 Uncaught ReferenceError: getTargetColor is not defined
|
| 255 |
-
at applyAssignmentToIndices (preprocess_manual.js:2909:25)
|
| 256 |
-
at HTMLCanvasElement.<anonymous> (preprocess_manual.js:2855:5)Understand this error
|
| 257 |
-
preprocess_manual.js:3134 [setupBoneAssignment] Assigning splats around center to group_0
|
| 258 |
-
preprocess_manual.js:3154 [setupBoneAssignment] Group: 1. Head Bones: Array(1)
|
|
|
|
| 1 |
+
[preprocess_manual.js] ===== MODULE LOADING =====
|
|
|
|
| 2 |
main.js:16 [MAIN] DOMContentLoaded fired
|
| 3 |
main.js:269 [MAIN] Calling setupPathsFromUrlOrSelect...
|
| 4 |
main.js:46 [MAIN] setupPathsFromUrlOrSelect started
|
|
|
|
| 20 |
main.js:198 [MAIN] Reading manual file...
|
| 21 |
main.js:201 [MAIN] Manual file read complete, size: 57407083
|
| 22 |
main.js:209 [MAIN] Manual mode file loaded: fountain_trim9.ply
|
| 23 |
+
main.js:210 [MAIN] gsPath: blob:http://127.0.0.1:5500/c951d997-a0b3-4c4f-8b76-7b80daeabd37
|
| 24 |
main.js:211 [MAIN] gsFileName: fountain_trim9.ply
|
| 25 |
main.js:110 [MAIN] Hiding select UI
|
| 26 |
main.js:215 [MAIN] ===== Resolving with MANUAL MODE =====
|
| 27 |
main.js:261 [MAIN] File load promise resolved: Object
|
| 28 |
main.js:271 [MAIN] setupPathsFromUrlOrSelect returned: Object
|
| 29 |
main.js:277 [MAIN] After pathResult:
|
| 30 |
+
main.js:278 - gsPath: blob:http://127.0.0.1:5500/c951d997-a0b3-4c4f-8b76-7b80daeabd37
|
| 31 |
main.js:279 - gvrmPath: undefined
|
| 32 |
main.js:280 - isManualMode: true
|
| 33 |
main.js:283 [MAIN] Initializing renderer...
|
| 34 |
main.js:289 [MAIN] Initializing camera...
|
| 35 |
main.js:316 [MAIN] Initializing scene...
|
| 36 |
main.js:323 [MAIN] Three.js initialization complete
|
| 37 |
+
main.js:506 [MAIN] Processing GS file: blob:http://127.0.0.1:5500/c951d997-a0b3-4c4f-8b76-7b80daeabd37
|
| 38 |
main.js:507 [MAIN] Manual mode: true
|
| 39 |
main.js:519 [MAIN] fileName: fountain_trim9.gvrm
|
| 40 |
main.js:529 [MAIN] ===== STARTING MANUAL PREPROCESSING MODE =====
|
| 41 |
main.js:530 [MAIN] Parameters:
|
| 42 |
main.js:531 - vrmPath: ./assets/sotai.vrm
|
| 43 |
+
main.js:532 - gsPath: blob:http://127.0.0.1:5500/c951d997-a0b3-4c4f-8b76-7b80daeabd37
|
| 44 |
main.js:533 - fileName: fountain_trim9.gvrm
|
| 45 |
preprocess_manual.js:977 [preprocessManual] ===== FUNCTION CALLED =====
|
| 46 |
preprocess_manual.js:978 [preprocessManual] Parameters:
|
| 47 |
preprocess_manual.js:979 vrmPath: ./assets/sotai.vrm
|
| 48 |
+
preprocess_manual.js:980 gsPath: blob:http://127.0.0.1:5500/c951d997-a0b3-4c4f-8b76-7b80daeabd37
|
| 49 |
preprocess_manual.js:981 fileName: fountain_trim9.gvrm
|
| 50 |
preprocess_manual.js:984 [preprocessManual] Creating Promise...
|
| 51 |
preprocess_manual.js:84 [createManualUI] Creating manual preprocessing UI...
|
|
|
|
| 80 |
preprocess_manual.js:1617 [preprocessManual] Initial box setup - size: Object
|
| 81 |
preprocess_manual.js:1660 [preprocessManual] UI sliders initialized to PLY-aligned values
|
| 82 |
preprocess_manual.js:1666 [preprocessManual] ✓ Camera and Box aligned to PLY
|
|
|
|
| 83 |
preprocess_manual.js:1399
|
| 84 |
|
| 85 |
|
|
|
|
| 190 |
preprocess_manual.js:2066 [STEP 5] Before centering: Object
|
| 191 |
preprocess_manual.js:2076 [STEP 5] ✓ Splats centered to origin
|
| 192 |
preprocess_manual.js:2079 [STEP 6] Saving filtered PLY...
|
| 193 |
+
preprocess_manual.js:770 [downloadPLY] Downloaded: c951d997-a0b3-4c4f-8b76-7b80daeabd37_filtered_2025-12-18T06-13-21.ply
|
| 194 |
+
preprocess_manual.js:2102 [STEP 6] ✓ PLY saved: c951d997-a0b3-4c4f-8b76-7b80daeabd37_filtered_2025-12-18T06-13-21.ply
|
| 195 |
preprocess_manual.js:2103 [STEP 6] Statistics:
|
| 196 |
preprocess_manual.js:2104 Original: 231474 vertices
|
| 197 |
preprocess_manual.js:2105 Filtered: 202550 vertices
|
|
|
|
| 217 |
preprocess_manual.js:2303 [setupBoneAssignment] Bone names: Array(54)
|
| 218 |
preprocess_manual.js:2343 [updateBoneSelector] Updating for mode: required19
|
| 219 |
preprocess_manual.js:2355 [updateBoneSelector] Added 20 groups
|
| 220 |
+
preprocess_manual.js:2720 [setupBoneAssignment] ✓ All helper functions and events initialized
|
| 221 |
+
error.js:58 [setupBoneAssignment] Error: ReferenceError: selectSphereBtn is not defined
|
| 222 |
+
at preprocess_manual.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preprocess_manual.js
CHANGED
|
@@ -2412,18 +2412,160 @@ function setupBoneAssignment(ui, scene, camera, renderer, gvrm, character, filte
|
|
| 2412 |
////helper関数挿入
|
| 2413 |
|
| 2414 |
// ========================================
|
| 2415 |
-
//
|
| 2416 |
-
//
|
| 2417 |
-
// // Selection Radius
|
| 2418 |
-
// // ========================================"
|
| 2419 |
-
// の直後に追加してください
|
| 2420 |
// ========================================
|
| 2421 |
|
| 2422 |
-
|
| 2423 |
-
|
| 2424 |
-
|
| 2425 |
-
|
| 2426 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2427 |
|
| 2428 |
/**
|
| 2429 |
* 球体範囲内の全Splatを検索
|
|
@@ -2451,10 +2593,83 @@ function findSplatsInSphere(center, radius, filteredGs) {
|
|
| 2451 |
return indicesInSphere;
|
| 2452 |
}
|
| 2453 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2454 |
// ========================================
|
| 2455 |
// マウスイベント処理
|
| 2456 |
// ========================================
|
| 2457 |
|
|
|
|
|
|
|
| 2458 |
let lastPaintMouseX = null;
|
| 2459 |
let lastPaintMouseY = null;
|
| 2460 |
|
|
@@ -2471,7 +2686,6 @@ renderer.domElement.addEventListener('mousedown', (event) => {
|
|
| 2471 |
lastPaintMouseX = mouse.x;
|
| 2472 |
lastPaintMouseY = mouse.y;
|
| 2473 |
|
| 2474 |
-
// 最初のクリック位置でペイント
|
| 2475 |
handlePaintAtPosition(mouse.x, mouse.y);
|
| 2476 |
});
|
| 2477 |
|
|
@@ -2482,12 +2696,11 @@ renderer.domElement.addEventListener('mousemove', (event) => {
|
|
| 2482 |
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
|
| 2483 |
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
|
| 2484 |
|
| 2485 |
-
// パスに沿ってペイント
|
| 2486 |
const affectedIndices = findSplatsAlongMousePath(
|
| 2487 |
mouse.x, mouse.y,
|
| 2488 |
lastPaintMouseX, lastPaintMouseY,
|
| 2489 |
camera, filteredGs,
|
| 2490 |
-
30
|
| 2491 |
);
|
| 2492 |
|
| 2493 |
if (affectedIndices.length > 0) {
|
|
@@ -2504,95 +2717,10 @@ renderer.domElement.addEventListener('mouseup', () => {
|
|
| 2504 |
lastPaintMouseY = null;
|
| 2505 |
});
|
| 2506 |
|
| 2507 |
-
|
| 2508 |
-
* ペイント処理を実行
|
| 2509 |
-
*/
|
| 2510 |
-
function handlePaintAtPosition(mouseX, mouseY) {
|
| 2511 |
-
const result = findNearestSplatWithRadius(mouseX, mouseY, camera, filteredGs, 30);
|
| 2512 |
-
|
| 2513 |
-
if (result && result.indices.length > 0) {
|
| 2514 |
-
applyAssignmentToIndices(result.indices, selectedTarget, paintModeEraser);
|
| 2515 |
-
} else {
|
| 2516 |
-
console.log('[Paint] No splats found under cursor');
|
| 2517 |
-
}
|
| 2518 |
-
}
|
| 2519 |
|
| 2520 |
-
|
| 2521 |
-
// 球体選択ボタン
|
| 2522 |
-
// ========================================
|
| 2523 |
-
|
| 2524 |
-
const selectSphereBtn = document.getElementById('select-sphere-btn');
|
| 2525 |
-
|
| 2526 |
-
if (selectSphereBtn) {
|
| 2527 |
-
selectSphereBtn.addEventListener('click', () => {
|
| 2528 |
-
if (!selectedTarget) {
|
| 2529 |
-
alert('Please select a target bone or group first!');
|
| 2530 |
-
return;
|
| 2531 |
-
}
|
| 2532 |
-
|
| 2533 |
-
selectionMode = 'sphere';
|
| 2534 |
-
console.log('[Sphere Selection] Mode activated, radius:', selectionRadius, 'm');
|
| 2535 |
-
console.log('[Sphere Selection] Click on a splat to select all nearby splats');
|
| 2536 |
-
|
| 2537 |
-
const onSphereClick = (event) => {
|
| 2538 |
-
const rect = renderer.domElement.getBoundingClientRect();
|
| 2539 |
-
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
|
| 2540 |
-
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
|
| 2541 |
-
|
| 2542 |
-
// ⭐ 改善: 最も近いsplatを見つ���る
|
| 2543 |
-
const nearestResult = findNearestSplat(mouse.x, mouse.y, camera, filteredGs, 100);
|
| 2544 |
-
|
| 2545 |
-
if (!nearestResult) {
|
| 2546 |
-
alert('No splat found near click. Please click closer to the object.');
|
| 2547 |
-
renderer.domElement.removeEventListener('click', onSphereClick);
|
| 2548 |
-
selectionMode = null;
|
| 2549 |
-
return;
|
| 2550 |
-
}
|
| 2551 |
-
|
| 2552 |
-
const centerIdx = nearestResult.index;
|
| 2553 |
-
|
| 2554 |
-
const centerX = filteredGs.centers0[centerIdx * 3 + 0];
|
| 2555 |
-
const centerY = filteredGs.centers0[centerIdx * 3 + 1];
|
| 2556 |
-
const centerZ = filteredGs.centers0[centerIdx * 3 + 2];
|
| 2557 |
-
const center = new THREE.Vector3(centerX, centerY, centerZ);
|
| 2558 |
-
|
| 2559 |
-
console.log('[Sphere Selection] Center splat:', centerIdx, 'at', center);
|
| 2560 |
-
|
| 2561 |
-
const indicesInSphere = findSplatsInSphere(center, selectionRadius, filteredGs);
|
| 2562 |
-
|
| 2563 |
-
if (indicesInSphere.length === 0) {
|
| 2564 |
-
alert('No splats found in sphere. Try increasing the radius.');
|
| 2565 |
-
renderer.domElement.removeEventListener('click', onSphereClick);
|
| 2566 |
-
selectionMode = null;
|
| 2567 |
-
return;
|
| 2568 |
-
}
|
| 2569 |
-
|
| 2570 |
-
applyAssignmentToIndices(indicesInSphere, selectedTarget, false);
|
| 2571 |
-
|
| 2572 |
-
assignmentData.history.push({
|
| 2573 |
-
action: 'sphere_select',
|
| 2574 |
-
indices: [...indicesInSphere],
|
| 2575 |
-
target: selectedTarget
|
| 2576 |
-
});
|
| 2577 |
-
|
| 2578 |
-
console.log('[Sphere Selection] Completed:', indicesInSphere.length, 'splats assigned');
|
| 2579 |
|
| 2580 |
-
renderer.domElement.removeEventListener('click', onSphereClick);
|
| 2581 |
-
selectionMode = null;
|
| 2582 |
-
};
|
| 2583 |
-
|
| 2584 |
-
renderer.domElement.addEventListener('click', onSphereClick);
|
| 2585 |
-
});
|
| 2586 |
-
}
|
| 2587 |
-
|
| 2588 |
-
console.log('[setupBoneAssignment] ✓ Improved splat selection system initialized');
|
| 2589 |
-
console.log('[setupBoneAssignment] Features:');
|
| 2590 |
-
console.log(' - Finds nearest splat within 100px');
|
| 2591 |
-
console.log(' - Paint mode with drag support');
|
| 2592 |
-
console.log(' - Smooth brush strokes with interpolation');
|
| 2593 |
-
console.log(' - Sphere selection with improved center detection');
|
| 2594 |
-
|
| 2595 |
-
////helper関数挿入
|
| 2596 |
// ========================================
|
| 2597 |
// Statistics Update
|
| 2598 |
// ========================================
|
|
@@ -2667,78 +2795,6 @@ console.log(' - Sphere selection with improved center detection');
|
|
| 2667 |
* @param {number} maxScreenDistance - 最大許容画面距離(ピクセル、デフォルト50px)
|
| 2668 |
* @returns {Object|null} { index, screenDistance, worldDistance } or null
|
| 2669 |
*/
|
| 2670 |
-
function findNearestSplat(mouseX, mouseY, camera, filteredGs, maxScreenDistance = 50) {
|
| 2671 |
-
console.log('[findNearestSplat] Searching for splat near mouse:', { mouseX, mouseY });
|
| 2672 |
-
|
| 2673 |
-
// スクリーン座標をピクセル座標に変換
|
| 2674 |
-
const canvas = renderer.domElement;
|
| 2675 |
-
const mousePixelX = (mouseX + 1) * canvas.width / 2;
|
| 2676 |
-
const mousePixelY = (-mouseY + 1) * canvas.height / 2;
|
| 2677 |
-
|
| 2678 |
-
let nearestSplatIndex = -1;
|
| 2679 |
-
let nearestScreenDist = Infinity;
|
| 2680 |
-
let nearestWorldDist = Infinity;
|
| 2681 |
-
|
| 2682 |
-
// カメラ位置
|
| 2683 |
-
const cameraPos = camera.position;
|
| 2684 |
-
|
| 2685 |
-
// 一時的なVector3オブジェクト(パフォーマンス最適化)
|
| 2686 |
-
const worldPos = new THREE.Vector3();
|
| 2687 |
-
const screenPos = new THREE.Vector3();
|
| 2688 |
-
|
| 2689 |
-
// 全てのsplatをチェック
|
| 2690 |
-
for (let i = 0; i < filteredGs.splatCount; i++) {
|
| 2691 |
-
// Splatのワールド座標を取得
|
| 2692 |
-
worldPos.x = filteredGs.centers0[i * 3 + 0];
|
| 2693 |
-
worldPos.y = filteredGs.centers0[i * 3 + 1];
|
| 2694 |
-
worldPos.z = filteredGs.centers0[i * 3 + 2];
|
| 2695 |
-
|
| 2696 |
-
// ワールド座標 → スクリーン座標に変換
|
| 2697 |
-
screenPos.copy(worldPos);
|
| 2698 |
-
screenPos.project(camera);
|
| 2699 |
-
|
| 2700 |
-
// カメラの背後にあるsplatは除外
|
| 2701 |
-
if (screenPos.z > 1) continue;
|
| 2702 |
-
|
| 2703 |
-
// 正規化座標 → ピクセル座標
|
| 2704 |
-
const screenPixelX = (screenPos.x + 1) * canvas.width / 2;
|
| 2705 |
-
const screenPixelY = (-screenPos.y + 1) * canvas.height / 2;
|
| 2706 |
-
|
| 2707 |
-
// マウスとの2D距離(画面上)
|
| 2708 |
-
const dx = screenPixelX - mousePixelX;
|
| 2709 |
-
const dy = screenPixelY - mousePixelY;
|
| 2710 |
-
const screenDist = Math.sqrt(dx * dx + dy * dy);
|
| 2711 |
-
|
| 2712 |
-
// 最大許容距離以内で、最も近いものを記録
|
| 2713 |
-
if (screenDist < maxScreenDistance && screenDist < nearestScreenDist) {
|
| 2714 |
-
nearestScreenDist = screenDist;
|
| 2715 |
-
nearestSplatIndex = i;
|
| 2716 |
-
|
| 2717 |
-
// ワールド空間での距離も計算
|
| 2718 |
-
const worldDx = worldPos.x - cameraPos.x;
|
| 2719 |
-
const worldDy = worldPos.y - cameraPos.y;
|
| 2720 |
-
const worldDz = worldPos.z - cameraPos.z;
|
| 2721 |
-
nearestWorldDist = Math.sqrt(worldDx * worldDx + worldDy * worldDy + worldDz * worldDz);
|
| 2722 |
-
}
|
| 2723 |
-
}
|
| 2724 |
-
|
| 2725 |
-
if (nearestSplatIndex >= 0) {
|
| 2726 |
-
console.log('[findNearestSplat] ✓ Found nearest splat:', {
|
| 2727 |
-
index: nearestSplatIndex,
|
| 2728 |
-
screenDistance: nearestScreenDist.toFixed(1) + 'px',
|
| 2729 |
-
worldDistance: nearestWorldDist.toFixed(3) + 'm'
|
| 2730 |
-
});
|
| 2731 |
-
|
| 2732 |
-
return {
|
| 2733 |
-
index: nearestSplatIndex,
|
| 2734 |
-
screenDistance: nearestScreenDist,
|
| 2735 |
-
worldDistance: nearestWorldDist
|
| 2736 |
-
};
|
| 2737 |
-
}
|
| 2738 |
-
|
| 2739 |
-
console.log('[findNearestSplat] ✗ No splat found within', maxScreenDistance, 'px');
|
| 2740 |
-
return null;
|
| 2741 |
-
}
|
| 2742 |
|
| 2743 |
/**
|
| 2744 |
* 球体範囲内の全Splatを検索
|
|
@@ -2759,25 +2815,6 @@ function findNearestSplat(mouseX, mouseY, camera, filteredGs, maxScreenDistance
|
|
| 2759 |
* @param {number} brushRadius - ブラシ半径(ピクセル、デフォルト30px)
|
| 2760 |
* @returns {Array<number>} 影響を受けたSplatインデックス
|
| 2761 |
*/
|
| 2762 |
-
function findSplatsAlongMousePath(mouseX, mouseY, lastMouseX, lastMouseY, camera, filteredGs, brushRadius = 30) {
|
| 2763 |
-
const affectedSplats = new Set();
|
| 2764 |
-
|
| 2765 |
-
// パスを補間(滑らかなストロークのため)
|
| 2766 |
-
const steps = 5;
|
| 2767 |
-
for (let step = 0; step <= steps; step++) {
|
| 2768 |
-
const t = step / steps;
|
| 2769 |
-
const interpX = lastMouseX + (mouseX - lastMouseX) * t;
|
| 2770 |
-
const interpY = lastMouseY + (mouseY - lastMouseY) * t;
|
| 2771 |
-
|
| 2772 |
-
// この位置の周辺Splatを検索
|
| 2773 |
-
const result = findNearestSplatWithRadius(interpX, interpY, camera, filteredGs, brushRadius);
|
| 2774 |
-
if (result && result.indices) {
|
| 2775 |
-
result.indices.forEach(idx => affectedSplats.add(idx));
|
| 2776 |
-
}
|
| 2777 |
-
}
|
| 2778 |
-
|
| 2779 |
-
return Array.from(affectedSplats);
|
| 2780 |
-
}
|
| 2781 |
|
| 2782 |
/**
|
| 2783 |
* ブラシ半径内の全Splatを返す
|
|
@@ -2788,39 +2825,6 @@ function findSplatsAlongMousePath(mouseX, mouseY, lastMouseX, lastMouseY, camera
|
|
| 2788 |
* @param {number} brushRadius - ブラシ半径(ピクセル)
|
| 2789 |
* @returns {Object|null} { indices: Array<number> } or null
|
| 2790 |
*/
|
| 2791 |
-
function findNearestSplatWithRadius(mouseX, mouseY, camera, filteredGs, brushRadius) {
|
| 2792 |
-
const canvas = renderer.domElement;
|
| 2793 |
-
const mousePixelX = (mouseX + 1) * canvas.width / 2;
|
| 2794 |
-
const mousePixelY = (-mouseY + 1) * canvas.height / 2;
|
| 2795 |
-
|
| 2796 |
-
const affectedIndices = [];
|
| 2797 |
-
const worldPos = new THREE.Vector3();
|
| 2798 |
-
const screenPos = new THREE.Vector3();
|
| 2799 |
-
|
| 2800 |
-
for (let i = 0; i < filteredGs.splatCount; i++) {
|
| 2801 |
-
worldPos.x = filteredGs.centers0[i * 3 + 0];
|
| 2802 |
-
worldPos.y = filteredGs.centers0[i * 3 + 1];
|
| 2803 |
-
worldPos.z = filteredGs.centers0[i * 3 + 2];
|
| 2804 |
-
|
| 2805 |
-
screenPos.copy(worldPos);
|
| 2806 |
-
screenPos.project(camera);
|
| 2807 |
-
|
| 2808 |
-
if (screenPos.z > 1) continue;
|
| 2809 |
-
|
| 2810 |
-
const screenPixelX = (screenPos.x + 1) * canvas.width / 2;
|
| 2811 |
-
const screenPixelY = (-screenPos.y + 1) * canvas.height / 2;
|
| 2812 |
-
|
| 2813 |
-
const dx = screenPixelX - mousePixelX;
|
| 2814 |
-
const dy = screenPixelY - mousePixelY;
|
| 2815 |
-
const screenDist = Math.sqrt(dx * dx + dy * dy);
|
| 2816 |
-
|
| 2817 |
-
if (screenDist < brushRadius) {
|
| 2818 |
-
affectedIndices.push(i);
|
| 2819 |
-
}
|
| 2820 |
-
}
|
| 2821 |
-
|
| 2822 |
-
return affectedIndices.length > 0 ? { indices: affectedIndices } : null;
|
| 2823 |
-
}
|
| 2824 |
|
| 2825 |
// ========================================
|
| 2826 |
// マウスクリック/ドラッグイベント処理の改善例
|
|
@@ -2877,83 +2881,12 @@ renderer.domElement.addEventListener('mouseup', () => {
|
|
| 2877 |
lastPaintMouseY = null;
|
| 2878 |
});
|
| 2879 |
|
| 2880 |
-
/**
|
| 2881 |
-
* ペイント処理を実行
|
| 2882 |
-
*/
|
| 2883 |
-
function handlePaintAtPosition(mouseX, mouseY) {
|
| 2884 |
-
const result = findNearestSplatWithRadius(mouseX, mouseY, camera, filteredGs, 30);
|
| 2885 |
-
|
| 2886 |
-
if (result && result.indices.length > 0) {
|
| 2887 |
-
applyAssignmentToIndices(result.indices, selectedTarget, paintModeEraser);
|
| 2888 |
-
} else {
|
| 2889 |
-
console.log('[Paint] No splats found under cursor');
|
| 2890 |
-
}
|
| 2891 |
-
}
|
| 2892 |
-
|
| 2893 |
-
/**
|
| 2894 |
-
* Splatに割り当てを適用
|
| 2895 |
-
*/
|
| 2896 |
-
function applyAssignmentToIndices(indices, target, isEraser) {
|
| 2897 |
-
if (isEraser) {
|
| 2898 |
-
// 消しゴムモード: 割り当て解除
|
| 2899 |
-
indices.forEach(idx => {
|
| 2900 |
-
if (assignmentData.splatBoneIndices[idx] >= 0) {
|
| 2901 |
-
const oldBoneName = getBoneNameFromIndex(assignmentData.splatBoneIndices[idx]);
|
| 2902 |
-
if (assignmentData.boneAssignments[oldBoneName]) {
|
| 2903 |
-
const arrayIdx = assignmentData.boneAssignments[oldBoneName].indexOf(idx);
|
| 2904 |
-
if (arrayIdx >= 0) {
|
| 2905 |
-
assignmentData.boneAssignments[oldBoneName].splice(arrayIdx, 1);
|
| 2906 |
-
}
|
| 2907 |
-
}
|
| 2908 |
-
assignmentData.splatBoneIndices[idx] = -1;
|
| 2909 |
-
|
| 2910 |
-
// 色を元に戻す
|
| 2911 |
-
filteredGs.colors[idx * 4 + 0] = 255;
|
| 2912 |
-
filteredGs.colors[idx * 4 + 1] = 255;
|
| 2913 |
-
filteredGs.colors[idx * 4 + 2] = 255;
|
| 2914 |
-
}
|
| 2915 |
-
});
|
| 2916 |
-
|
| 2917 |
-
console.log('[Paint] Erased', indices.length, 'splats');
|
| 2918 |
-
} else {
|
| 2919 |
-
// 通常モード: 割り当て
|
| 2920 |
-
const targetColor = getTargetColor(target);
|
| 2921 |
-
const boneIndices = getTargetBoneIndices(target);
|
| 2922 |
-
|
| 2923 |
-
indices.forEach(idx => {
|
| 2924 |
-
assignmentData.splatBoneIndices[idx] = boneIndices[0]; // 最初のボーン
|
| 2925 |
-
|
| 2926 |
-
// 色を適用
|
| 2927 |
-
filteredGs.colors[idx * 4 + 0] = targetColor[0];
|
| 2928 |
-
filteredGs.colors[idx * 4 + 1] = targetColor[1];
|
| 2929 |
-
filteredGs.colors[idx * 4 + 2] = targetColor[2];
|
| 2930 |
-
|
| 2931 |
-
// 記録
|
| 2932 |
-
boneIndices.forEach(boneIdx => {
|
| 2933 |
-
const boneName = getBoneNameFromIndex(boneIdx);
|
| 2934 |
-
if (!assignmentData.boneAssignments[boneName]) {
|
| 2935 |
-
assignmentData.boneAssignments[boneName] = [];
|
| 2936 |
-
}
|
| 2937 |
-
if (!assignmentData.boneAssignments[boneName].includes(idx)) {
|
| 2938 |
-
assignmentData.boneAssignments[boneName].push(idx);
|
| 2939 |
-
}
|
| 2940 |
-
});
|
| 2941 |
-
});
|
| 2942 |
-
|
| 2943 |
-
console.log('[Paint] Painted', indices.length, 'splats with', target);
|
| 2944 |
-
}
|
| 2945 |
-
|
| 2946 |
-
// スプラットの色を更新
|
| 2947 |
-
filteredGs.splatMesh.updateDataTexturesFromBaseData(0, filteredGs.splatCount - 1);
|
| 2948 |
-
updateStats();
|
| 2949 |
-
}
|
| 2950 |
|
| 2951 |
// ========================================
|
| 2952 |
// 球体選択モード(元のコード互換)
|
| 2953 |
// ========================================
|
| 2954 |
|
| 2955 |
|
| 2956 |
-
|
| 2957 |
if (selectSphereBtn) {
|
| 2958 |
selectSphereBtn.addEventListener('click', () => {
|
| 2959 |
if (!selectedTarget) {
|
|
|
|
| 2412 |
////helper関数挿入
|
| 2413 |
|
| 2414 |
// ========================================
|
| 2415 |
+
// 🎯 挿入場所: setupBoneAssignment 関数内
|
| 2416 |
+
// ====helper関数挿入 の直後
|
|
|
|
|
|
|
|
|
|
| 2417 |
// ========================================
|
| 2418 |
|
| 2419 |
+
/**
|
| 2420 |
+
* ターゲットの色を取得
|
| 2421 |
+
*/
|
| 2422 |
+
function getTargetColor(target) {
|
| 2423 |
+
if (target.startsWith('group_')) {
|
| 2424 |
+
const groupIndex = parseInt(target.replace('group_', ''));
|
| 2425 |
+
const group = currentBoneGroups[groupIndex];
|
| 2426 |
+
if (group && group.color) {
|
| 2427 |
+
return group.color;
|
| 2428 |
+
}
|
| 2429 |
+
}
|
| 2430 |
+
return [255, 255, 255];
|
| 2431 |
+
}
|
| 2432 |
+
|
| 2433 |
+
/**
|
| 2434 |
+
* ターゲットのボーンインデックスを取得
|
| 2435 |
+
*/
|
| 2436 |
+
function getTargetBoneIndices(target) {
|
| 2437 |
+
const indices = [];
|
| 2438 |
+
|
| 2439 |
+
if (target.startsWith('group_')) {
|
| 2440 |
+
const groupIndex = parseInt(target.replace('group_', ''));
|
| 2441 |
+
const group = currentBoneGroups[groupIndex];
|
| 2442 |
+
|
| 2443 |
+
if (group && group.bones) {
|
| 2444 |
+
group.bones.forEach(boneName => {
|
| 2445 |
+
if (boneNameToIndex[boneName] !== undefined) {
|
| 2446 |
+
indices.push(boneNameToIndex[boneName]);
|
| 2447 |
+
}
|
| 2448 |
+
});
|
| 2449 |
+
}
|
| 2450 |
+
}
|
| 2451 |
+
|
| 2452 |
+
return indices;
|
| 2453 |
+
}
|
| 2454 |
+
|
| 2455 |
+
/**
|
| 2456 |
+
* ボーンインデックスからボーン名を取得
|
| 2457 |
+
*/
|
| 2458 |
+
function getBoneNameFromIndex(index) {
|
| 2459 |
+
for (const [name, idx] of Object.entries(boneNameToIndex)) {
|
| 2460 |
+
if (idx === index) {
|
| 2461 |
+
return name;
|
| 2462 |
+
}
|
| 2463 |
+
}
|
| 2464 |
+
return `bone_${index}`;
|
| 2465 |
+
}
|
| 2466 |
+
|
| 2467 |
+
/**
|
| 2468 |
+
* Splatに割り当てを適用
|
| 2469 |
+
*/
|
| 2470 |
+
function applyAssignmentToIndices(indices, target, isEraser) {
|
| 2471 |
+
if (isEraser) {
|
| 2472 |
+
indices.forEach(idx => {
|
| 2473 |
+
if (assignmentData.splatBoneIndices[idx] >= 0) {
|
| 2474 |
+
const oldBoneName = getBoneNameFromIndex(assignmentData.splatBoneIndices[idx]);
|
| 2475 |
+
if (assignmentData.boneAssignments[oldBoneName]) {
|
| 2476 |
+
const arrayIdx = assignmentData.boneAssignments[oldBoneName].indexOf(idx);
|
| 2477 |
+
if (arrayIdx >= 0) {
|
| 2478 |
+
assignmentData.boneAssignments[oldBoneName].splice(arrayIdx, 1);
|
| 2479 |
+
}
|
| 2480 |
+
}
|
| 2481 |
+
assignmentData.splatBoneIndices[idx] = -1;
|
| 2482 |
+
|
| 2483 |
+
filteredGs.colors[idx * 4 + 0] = 255;
|
| 2484 |
+
filteredGs.colors[idx * 4 + 1] = 255;
|
| 2485 |
+
filteredGs.colors[idx * 4 + 2] = 255;
|
| 2486 |
+
}
|
| 2487 |
+
});
|
| 2488 |
+
console.log('[Paint] Erased', indices.length, 'splats');
|
| 2489 |
+
} else {
|
| 2490 |
+
const targetColor = getTargetColor(target);
|
| 2491 |
+
const boneIndices = getTargetBoneIndices(target);
|
| 2492 |
+
|
| 2493 |
+
if (boneIndices.length === 0) {
|
| 2494 |
+
console.warn('[applyAssignmentToIndices] No bone indices found for target:', target);
|
| 2495 |
+
return;
|
| 2496 |
+
}
|
| 2497 |
+
|
| 2498 |
+
indices.forEach(idx => {
|
| 2499 |
+
assignmentData.splatBoneIndices[idx] = boneIndices[0];
|
| 2500 |
+
|
| 2501 |
+
filteredGs.colors[idx * 4 + 0] = targetColor[0];
|
| 2502 |
+
filteredGs.colors[idx * 4 + 1] = targetColor[1];
|
| 2503 |
+
filteredGs.colors[idx * 4 + 2] = targetColor[2];
|
| 2504 |
+
|
| 2505 |
+
boneIndices.forEach(boneIdx => {
|
| 2506 |
+
const boneName = getBoneNameFromIndex(boneIdx);
|
| 2507 |
+
if (!assignmentData.boneAssignments[boneName]) {
|
| 2508 |
+
assignmentData.boneAssignments[boneName] = [];
|
| 2509 |
+
}
|
| 2510 |
+
if (!assignmentData.boneAssignments[boneName].includes(idx)) {
|
| 2511 |
+
assignmentData.boneAssignments[boneName].push(idx);
|
| 2512 |
+
}
|
| 2513 |
+
});
|
| 2514 |
+
});
|
| 2515 |
+
console.log('[Paint] Painted', indices.length, 'splats with', target);
|
| 2516 |
+
}
|
| 2517 |
+
|
| 2518 |
+
filteredGs.splatMesh.updateDataTexturesFromBaseData(0, filteredGs.splatCount - 1);
|
| 2519 |
+
updateStats();
|
| 2520 |
+
}
|
| 2521 |
+
|
| 2522 |
+
/**
|
| 2523 |
+
* 2D画面座標から最も近い3D Splatを検索
|
| 2524 |
+
*/
|
| 2525 |
+
function findNearestSplat(mouseX, mouseY, camera, filteredGs, maxScreenDistance = 100) {
|
| 2526 |
+
const canvas = renderer.domElement;
|
| 2527 |
+
const mousePixelX = (mouseX + 1) * canvas.width / 2;
|
| 2528 |
+
const mousePixelY = (-mouseY + 1) * canvas.height / 2;
|
| 2529 |
+
|
| 2530 |
+
let nearestSplatIndex = -1;
|
| 2531 |
+
let nearestScreenDist = Infinity;
|
| 2532 |
+
|
| 2533 |
+
const cameraPos = camera.position;
|
| 2534 |
+
const worldPos = new THREE.Vector3();
|
| 2535 |
+
const screenPos = new THREE.Vector3();
|
| 2536 |
+
|
| 2537 |
+
for (let i = 0; i < filteredGs.splatCount; i++) {
|
| 2538 |
+
worldPos.x = filteredGs.centers0[i * 3 + 0];
|
| 2539 |
+
worldPos.y = filteredGs.centers0[i * 3 + 1];
|
| 2540 |
+
worldPos.z = filteredGs.centers0[i * 3 + 2];
|
| 2541 |
+
|
| 2542 |
+
screenPos.copy(worldPos);
|
| 2543 |
+
screenPos.project(camera);
|
| 2544 |
+
|
| 2545 |
+
if (screenPos.z > 1) continue;
|
| 2546 |
+
|
| 2547 |
+
const screenPixelX = (screenPos.x + 1) * canvas.width / 2;
|
| 2548 |
+
const screenPixelY = (-screenPos.y + 1) * canvas.height / 2;
|
| 2549 |
+
|
| 2550 |
+
const dx = screenPixelX - mousePixelX;
|
| 2551 |
+
const dy = screenPixelY - mousePixelY;
|
| 2552 |
+
const screenDist = Math.sqrt(dx * dx + dy * dy);
|
| 2553 |
+
|
| 2554 |
+
if (screenDist < maxScreenDistance && screenDist < nearestScreenDist) {
|
| 2555 |
+
nearestScreenDist = screenDist;
|
| 2556 |
+
nearestSplatIndex = i;
|
| 2557 |
+
}
|
| 2558 |
+
}
|
| 2559 |
+
|
| 2560 |
+
if (nearestSplatIndex >= 0) {
|
| 2561 |
+
return {
|
| 2562 |
+
index: nearestSplatIndex,
|
| 2563 |
+
screenDistance: nearestScreenDist
|
| 2564 |
+
};
|
| 2565 |
+
}
|
| 2566 |
+
|
| 2567 |
+
return null;
|
| 2568 |
+
}
|
| 2569 |
|
| 2570 |
/**
|
| 2571 |
* 球体範囲内の全Splatを検索
|
|
|
|
| 2593 |
return indicesInSphere;
|
| 2594 |
}
|
| 2595 |
|
| 2596 |
+
/**
|
| 2597 |
+
* ブラシ半径内の全Splatを返す
|
| 2598 |
+
*/
|
| 2599 |
+
function findNearestSplatWithRadius(mouseX, mouseY, camera, filteredGs, brushRadius) {
|
| 2600 |
+
const canvas = renderer.domElement;
|
| 2601 |
+
const mousePixelX = (mouseX + 1) * canvas.width / 2;
|
| 2602 |
+
const mousePixelY = (-mouseY + 1) * canvas.height / 2;
|
| 2603 |
+
|
| 2604 |
+
const affectedIndices = [];
|
| 2605 |
+
const worldPos = new THREE.Vector3();
|
| 2606 |
+
const screenPos = new THREE.Vector3();
|
| 2607 |
+
|
| 2608 |
+
for (let i = 0; i < filteredGs.splatCount; i++) {
|
| 2609 |
+
worldPos.x = filteredGs.centers0[i * 3 + 0];
|
| 2610 |
+
worldPos.y = filteredGs.centers0[i * 3 + 1];
|
| 2611 |
+
worldPos.z = filteredGs.centers0[i * 3 + 2];
|
| 2612 |
+
|
| 2613 |
+
screenPos.copy(worldPos);
|
| 2614 |
+
screenPos.project(camera);
|
| 2615 |
+
|
| 2616 |
+
if (screenPos.z > 1) continue;
|
| 2617 |
+
|
| 2618 |
+
const screenPixelX = (screenPos.x + 1) * canvas.width / 2;
|
| 2619 |
+
const screenPixelY = (-screenPos.y + 1) * canvas.height / 2;
|
| 2620 |
+
|
| 2621 |
+
const dx = screenPixelX - mousePixelX;
|
| 2622 |
+
const dy = screenPixelY - mousePixelY;
|
| 2623 |
+
const screenDist = Math.sqrt(dx * dx + dy * dy);
|
| 2624 |
+
|
| 2625 |
+
if (screenDist < brushRadius) {
|
| 2626 |
+
affectedIndices.push(i);
|
| 2627 |
+
}
|
| 2628 |
+
}
|
| 2629 |
+
|
| 2630 |
+
return affectedIndices.length > 0 ? { indices: affectedIndices } : null;
|
| 2631 |
+
}
|
| 2632 |
+
|
| 2633 |
+
/**
|
| 2634 |
+
* ペイントモード用: マウスパスに沿ってSplatを塗る
|
| 2635 |
+
*/
|
| 2636 |
+
function findSplatsAlongMousePath(mouseX, mouseY, lastMouseX, lastMouseY, camera, filteredGs, brushRadius = 30) {
|
| 2637 |
+
const affectedSplats = new Set();
|
| 2638 |
+
|
| 2639 |
+
const steps = 5;
|
| 2640 |
+
for (let step = 0; step <= steps; step++) {
|
| 2641 |
+
const t = step / steps;
|
| 2642 |
+
const interpX = lastMouseX + (mouseX - lastMouseX) * t;
|
| 2643 |
+
const interpY = lastMouseY + (mouseY - lastMouseY) * t;
|
| 2644 |
+
|
| 2645 |
+
const result = findNearestSplatWithRadius(interpX, interpY, camera, filteredGs, brushRadius);
|
| 2646 |
+
if (result && result.indices) {
|
| 2647 |
+
result.indices.forEach(idx => affectedSplats.add(idx));
|
| 2648 |
+
}
|
| 2649 |
+
}
|
| 2650 |
+
|
| 2651 |
+
return Array.from(affectedSplats);
|
| 2652 |
+
}
|
| 2653 |
+
|
| 2654 |
+
/**
|
| 2655 |
+
* ペイント処理を実行
|
| 2656 |
+
*/
|
| 2657 |
+
function handlePaintAtPosition(mouseX, mouseY) {
|
| 2658 |
+
const result = findNearestSplatWithRadius(mouseX, mouseY, camera, filteredGs, 30);
|
| 2659 |
+
|
| 2660 |
+
if (result && result.indices.length > 0) {
|
| 2661 |
+
applyAssignmentToIndices(result.indices, selectedTarget, paintModeEraser);
|
| 2662 |
+
} else {
|
| 2663 |
+
console.log('[Paint] No splats found under cursor');
|
| 2664 |
+
}
|
| 2665 |
+
}
|
| 2666 |
+
|
| 2667 |
// ========================================
|
| 2668 |
// マウスイベント処理
|
| 2669 |
// ========================================
|
| 2670 |
|
| 2671 |
+
const raycaster = new THREE.Raycaster();
|
| 2672 |
+
const mouse = new THREE.Vector2();
|
| 2673 |
let lastPaintMouseX = null;
|
| 2674 |
let lastPaintMouseY = null;
|
| 2675 |
|
|
|
|
| 2686 |
lastPaintMouseX = mouse.x;
|
| 2687 |
lastPaintMouseY = mouse.y;
|
| 2688 |
|
|
|
|
| 2689 |
handlePaintAtPosition(mouse.x, mouse.y);
|
| 2690 |
});
|
| 2691 |
|
|
|
|
| 2696 |
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
|
| 2697 |
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
|
| 2698 |
|
|
|
|
| 2699 |
const affectedIndices = findSplatsAlongMousePath(
|
| 2700 |
mouse.x, mouse.y,
|
| 2701 |
lastPaintMouseX, lastPaintMouseY,
|
| 2702 |
camera, filteredGs,
|
| 2703 |
+
30
|
| 2704 |
);
|
| 2705 |
|
| 2706 |
if (affectedIndices.length > 0) {
|
|
|
|
| 2717 |
lastPaintMouseY = null;
|
| 2718 |
});
|
| 2719 |
|
| 2720 |
+
console.log('[setupBoneAssignment] ✓ All helper functions and events initialized');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2721 |
|
| 2722 |
+
////helper関数挿入 終了
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2723 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2724 |
// ========================================
|
| 2725 |
// Statistics Update
|
| 2726 |
// ========================================
|
|
|
|
| 2795 |
* @param {number} maxScreenDistance - 最大許容画面距離(ピクセル、デフォルト50px)
|
| 2796 |
* @returns {Object|null} { index, screenDistance, worldDistance } or null
|
| 2797 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2798 |
|
| 2799 |
/**
|
| 2800 |
* 球体範囲内の全Splatを検索
|
|
|
|
| 2815 |
* @param {number} brushRadius - ブラシ半径(ピクセル、デフォルト30px)
|
| 2816 |
* @returns {Array<number>} 影響を受けたSplatインデックス
|
| 2817 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2818 |
|
| 2819 |
/**
|
| 2820 |
* ブラシ半径内の全Splatを返す
|
|
|
|
| 2825 |
* @param {number} brushRadius - ブラシ半径(ピクセル)
|
| 2826 |
* @returns {Object|null} { indices: Array<number> } or null
|
| 2827 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2828 |
|
| 2829 |
// ========================================
|
| 2830 |
// マウスクリック/ドラッグイベント処理の改善例
|
|
|
|
| 2881 |
lastPaintMouseY = null;
|
| 2882 |
});
|
| 2883 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2884 |
|
| 2885 |
// ========================================
|
| 2886 |
// 球体選択モード(元のコード互換)
|
| 2887 |
// ========================================
|
| 2888 |
|
| 2889 |
|
|
|
|
| 2890 |
if (selectSphereBtn) {
|
| 2891 |
selectSphereBtn.addEventListener('click', () => {
|
| 2892 |
if (!selectedTarget) {
|