mayaMatchMoveSolver icon indicating copy to clipboard operation
mayaMatchMoveSolver copied to clipboard

Maya Tool - Center 2D tool - Version 2

Open david-cattermole opened this issue 3 years ago • 0 comments

Feature

The current Center 2D tool works fairly well, however because of it's implementation there are a number of limits.

This issue is a proposal to create a "version 2" of the Center 2D tool. The older tool could still be available, but will be deprecated.

The current tool's documentation is here: https://david-cattermole.github.io/mayaMatchMoveSolver/tools_generaltools.html#center-2d-on-selection

Usage Steps (simple)

  1. Select transform node (such as a rig controller)
  2. Activate viewport.
  3. Run the center 2D tool.
  4. With the native 2D pan/zoom tool, move the viewport to another part of the viewport.
  5. Press "play" to see the transform node from 1 animate, and the relative position of the viewport is maintained.

Usage Steps (extended)

This is how I think the usage steps should be:

  1. Select node or vertex.
  2. Add node/vertex to the "current" camera.
    • This will add the node/vertex to an Object Set node that is linked to the camera.
  3. Move your 2D view in the camera's viewport.
    • This is using the native Maya 2D Pan/Zoom tool.
  4. User presses play, next/previous frame or clicks on a different frame number in the Maya timeline.
    • Get the new and current frames (these could be completely different, either forward or backward.)
    • On the "current" frame (the frame Maya was on before the frame changed)...
      • Compute or get the (cached?) 2D average position.
    • On the "new" frame....
      • Compute the 3D positions for all nodes/vertices in the Object Set.
      • Average all the 3D positions into a single 3D position.
      • Convert the averaged 3D position into a 2D position, for the current camera.
    • Use the difference between the "current" and "new" 2D positions to compute the new position.
    • Store (cache) any needed data on the Object Set for future use.
  5. Go back to step 1, 2, 3, or 4.

Ideas for Implementation

The existing center 2D tool uses connections with a mmReprojection node. Unfortunately this approach means the user cannot change the 2D pan position - it is locked. There are 2 solutions to this:

  1. Do not use a node connection to control the 2D pan position
  2. Create a new node that can handle the relative offsets logic, AND a custom Maya "tool context" to control and set the node.

2 seems complicated to me. I prefer 1 because it's more flexible.

My idea is to use Maya on-frame-changed callbacks and store "what needs to be centered on" in an Object Set. The Object Set needs to be connected to the camera (via a message attribute connection for example). There can only ever be 1 Object Set for each Camera. The Object Set may contain any number of vertices and transform nodes.

When the user plays the timeline, the callback is run each frame. The callback must find the Object Set and Camera, then query the world-space position on the current frame. Once we have the world-space positions, we can convert these to screen-space using the maya.cmds.mmReprojection command. Here is an example use of the maya.cmds.mmReprojection command.

The difficulty for this approach/tool is the mapping between Object Set and Camera, and ensuring the callbacks do not slow down Maya or cause unexpected problems.

Another big unanswered question is how to perform the "relative" offsets, what are we relative to? Do we need the user to specify a "hero frame"?

2D Rotation and 2D Scale (future)

A future improvement we could think about is stabilizing and calculating a relative 2D rotation and 2D scale.

For example, we select 3 vertices on the face of a character, left ear, right ear and nose, when moving from frame to frame, the 2D rotation and 2D scale is stabilised.

Originally posted by @david-cattermole in https://github.com/david-cattermole/mayaMatchMoveSolver/issues/135#issuecomment-743781988

Software Versions

  • mmSolver version: all future versions

  • Maya version: All supported Maya versions.

  • Operating System (OS): All supported operating systems.

david-cattermole avatar Dec 20 '20 20:12 david-cattermole