Skip to content

Add snap-to-volume mode with continuous dragging for skeleton editing#79

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/add-new-feature-for-issue-34
Draft

Add snap-to-volume mode with continuous dragging for skeleton editing#79
Copilot wants to merge 6 commits intomainfrom
copilot/add-new-feature-for-issue-34

Conversation

Copy link
Contributor

Copilot AI commented Dec 8, 2025

Updated Implementation for Issue #34: Snap to Volume Center

This PR implements a snap-to-volume feature with improved code organization.


✨ Feature: Snap to Volume Center

Description: A new transform mode that allows users to drag joints continuously across the mesh, with the joint automatically positioning at the volume center of the mesh area under the cursor.

How it works:

  • Click the 📍 button in the Transform section to activate snap-to-volume mode
  • Click on a bone/joint to select it
  • Hold mouse button down and drag across the mesh
  • The joint continuously follows the cursor and snaps to the calculated volume center as you drag
  • Release mouse button to finalize the position

Interaction Model:

  • Mouse Down: Select bone and start dragging, store undo state
  • Mouse Move (while dragging): Continuously update bone position to follow volume center under cursor
  • Mouse Up: Stop dragging, refresh weight painting

🏗️ Code Architecture

SnapToVolumeHandler Class (src/lib/SnapToVolumeHandler.ts)

  • Encapsulates all snap-to-volume functionality in a dedicated handler class
  • Manages dragging state and interaction logic
  • Provides clean separation of concerns from main engine
  • Methods:
    • handle_mouse_down() - Initiates dragging
    • handle_dragging() - Updates bone position during drag
    • handle_mouse_up() - Finalizes position and cleanup
    • calculate_local_volume_center() - Computes volume center from nearby vertices

Integration with Mesh2MotionEngine

  • Mesh2MotionEngine creates and holds reference to SnapToVolumeHandler
  • Public wrapper methods delegate to handler:
    • is_snap_to_volume_dragging() - Check drag state
    • handle_snap_to_volume_dragging() - Handle mouse move
    • handle_snap_to_volume_mouse_up() - Handle mouse up

Benefits of Refactoring:

  • Reduced complexity in main Mesh2MotionEngine class
  • Better code organization and maintainability
  • Easier to test and extend snap-to-volume functionality
  • Clear separation between engine orchestration and feature implementation

🎨 UI Changes

Transform Section:

  • 📍 (Snap to Volume Center) button alongside existing Translate and Rotate buttons
  • Button includes aria-label for accessibility

✅ Technical Implementation

  • Raycasts mesh on every mouse move to continuously calculate volume center
  • Calculates local bounding box of vertices within configurable radius (0.15 units)
  • Automatically applies mirror mode transformations when enabled
  • Integrates with undo/redo system
  • Disables orbit controls during dragging to prevent conflicts

📝 Code Quality

  • Extracted ~200 lines of code into dedicated handler class
  • Proper null/undefined checks
  • Type guards for safe type assertions
  • Accessible UI with aria-label
  • Named constants for magic numbers
  • Clean separation of concerns

🎯 Related Issue

Addresses #34

Original prompt

Work on this feature. #34


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…en parent bone is transformed

Co-authored-by: scottpetrovic <2573552+scottpetrovic@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 8, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
mesh2motion-app 7005ba6 Commit Preview URL

Branch Preview URL
Dec 08 2025, 10:00 PM

Copilot AI and others added 2 commits December 8, 2025 20:55
… at volume center

Co-authored-by: scottpetrovic <2573552+scottpetrovic@users.noreply.github.com>
…l, and extract magic number

Co-authored-by: scottpetrovic <2573552+scottpetrovic@users.noreply.github.com>
Copilot AI changed the title [WIP] Add new feature for issue 34 Add snap-to-volume and move-only-joint modes for skeleton editing Dec 8, 2025
Copilot AI requested a review from scottpetrovic December 8, 2025 21:06
@scottpetrovic
Copy link
Collaborator

@copilot I think we need to remove the "move-only joint" mode functionality. That is too much for this PR. Additionally we need to work on the "snap-to-volume" user interaction. When you drag a joint with mouse down, the joint should move until you do a mouse up event. Currently this dragging doesn't happen when I move the joint around to snap to a new volume point

…r snap-to-volume mode

Co-authored-by: scottpetrovic <2573552+scottpetrovic@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 8, 2025

@copilot I think we need to remove the "move-only joint" mode functionality. That is too much for this PR. Additionally we need to work on the "snap-to-volume" user interaction. When you drag a joint ...

Done! Changes made in commit 444ff19:

  1. Removed "Move Only Joint" feature - Completely removed the checkbox and all related functionality
  2. Implemented continuous dragging for snap-to-volume - Now supports mouse down + drag + mouse up interaction:
    • Mouse down: Selects bone and starts dragging
    • Mouse move: Continuously updates bone position to follow volume center under cursor
    • Mouse up: Finalizes position and refreshes weight painting

The snap-to-volume mode now works like a drag operation where the joint smoothly follows your cursor across the mesh surface.

Updated UI

Copilot AI changed the title Add snap-to-volume and move-only-joint modes for skeleton editing Add snap-to-volume mode with continuous dragging for skeleton editing Dec 8, 2025
/**
* Handle mouse down in snap to volume mode - start dragging
*/
private handle_snap_to_volume_mouse_down (mouse_event: MouseEvent): void {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this functionality to an external class for the transform controls. I feel like we have too much code in the main Mesh2Motion engine class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 7005ba6. Created SnapToVolumeHandler class in src/lib/SnapToVolumeHandler.ts that encapsulates all snap-to-volume functionality (~250 lines). The Mesh2MotionEngine now delegates to this handler, keeping the main engine class cleaner and more focused on orchestration.

@scottpetrovic
Copy link
Collaborator

@copilot I have written a couple of comments on the pull request. Can you take those into account and refactor your code?

… class

Co-authored-by: scottpetrovic <2573552+scottpetrovic@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 8, 2025

@copilot I have written a couple of comments on the pull request. Can you take those into account and refactor your code?

Refactored in commit 7005ba6. Extracted snap-to-volume functionality into a dedicated SnapToVolumeHandler class to reduce complexity in the main Mesh2MotionEngine class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants