david-cattermole / mayaMatchMoveSolver

A Bundle Adjustment solver for MatchMove related tasks.
https://david-cattermole.github.io/mayaMatchMoveSolver/
Other
102 stars 27 forks source link

Maya API - Custom Camera Transform nodes raise an error #123

Closed david-cattermole closed 3 years ago

david-cattermole commented 5 years ago

Problem

mmSolver only works with Maya transform and camera nodes. Sub-classed, custom plug-ins will cause an assertion error (because they are untested). We should attempt to allow all types of transform nodes, even if they are custom plug-ins.

Expected behavior: If a camera (transform and shape node) are custom (derived API nodes), then we should not error.

Actual behavior: When loading 2D Marker data onto a camera with custom Maya transform plugin (MPxTransform), we get an assertion error.

# Traceback (most recent call last):
#   File "/home/davidc/maya/modules/mayaMatchMoveSolver-0.2.1-maya2018-linux/python/mmSolver/tools/solver/ui/solver_window.py", line 365, in loadMarkerCB
#     loadmarker_tool.open_window()
#   File "/home/davidc/maya/modules/mayaMatchMoveSolver-0.2.1-maya2018-linux/python/mmSolver/tools/loadmarker/tool.py", line 22, in open_window
#     loadmarker_window.main()
#   File "/home/davidc/maya/modules/mayaMatchMoveSolver-0.2.1-maya2018-linux/python/mmSolver/tools/loadmarker/ui/loadmarker_window.py", line 121, in main
#     delete=delete
#   File "/home/davidc/maya/modules/mayaMatchMoveSolver-0.2.1-maya2018-linux/python/mmSolver/ui/base_maya_window.py", line 120, in open_window
#     cls.instance = cls(parent=parent, name=name)
#   File "/home/davidc/maya/modules/mayaMatchMoveSolver-0.2.1-maya2018-linux/python/mmSolver/tools/loadmarker/ui/loadmarker_window.py", line 38, in __init__
#     self.addSubForm(loadmarker_layout.LoadMarkerLayout)
#   File "/home/davidc/maya/modules/mayaMatchMoveSolver-0.2.1-maya2018-linux/python/mmSolver/ui/base_maya_window.py", line 79, in addSubForm
#     self.subForm = SubForm(self)
#   File "/home/davidc/maya/modules/mayaMatchMoveSolver-0.2.1-maya2018-linux/python/mmSolver/tools/loadmarker/ui/loadmarker_layout.py", line 77, in __init__
#     self.populateUi()
#   File "/home/davidc/maya/modules/mayaMatchMoveSolver-0.2.1-maya2018-linux/python/mmSolver/tools/loadmarker/ui/loadmarker_layout.py", line 85, in populateUi
#     selected_cameras
#   File "/home/davidc/maya/modules/mayaMatchMoveSolver-0.2.1-maya2018-linux/python/mmSolver/tools/loadmarker/ui/loadmarker_layout.py", line 122, in updateCameraList
#     self.populateCameraModel(model)
#   File "/home/davidc/maya/modules/mayaMatchMoveSolver-0.2.1-maya2018-linux/python/mmSolver/tools/loadmarker/ui/loadmarker_layout.py", line 136, in populateCameraModel
#     camera_nodes = lib.get_cameras()
#   File "/home/davidc/maya/modules/mayaMatchMoveSolver-0.2.1-maya2018-linux/python/mmSolver/tools/loadmarker/lib.py", line 83, in get_cameras
#     cam = mmapi.Camera(shape=node)
#   File "/home/davidc/maya/modules/mayaMatchMoveSolver-0.2.1-maya2018-linux/python/mmSolver/_api/camera.py", line 47, in __init__
#     self.set_shape_node(shape)
#   File "/home/davidc/maya/modules/mayaMatchMoveSolver-0.2.1-maya2018-linux/python/mmSolver/_api/camera.py", line 163, in set_shape_node
#     assert tfm_dag.apiType() == OpenMaya.MFn.kTransform
# AssertionError

Steps to Reproduce

  1. Select a custom transform camera node plug-in.
  2. Run the Load Markers UI tool.
  3. We get an error.

Software Versions

david-cattermole commented 5 years ago

I have changed the mmSolver API to allow custom Maya transform node plug-ins, now. Assuming the custom transform node still uses the standard Maya translate, rotate and scale attributes, I expect any Maya transform plug-in node to work with mmSolver.

This will be merged into the master branch as part of #72 and #57.

david-cattermole commented 4 years ago

It has been reported that this issue is happening again, in v0.3.2.

david-cattermole commented 4 years ago

The problem in question seems to be due to type checking against the transform node type explicitly.

For example: https://github.com/david-cattermole/mayaMatchMoveSolver/blob/acf2d416592a077b39e99a30de79f7c6765d9053/python/mmSolver/utils/camera.py#L51

To effectively fix the bug, and ensure we don't reintroduce the bug, we need to write unit tests for (all?) tools that work with cameras. We will need to create a test transform plug-in, and load it during the unit tests.

This is a relatively low priority problem, because workflows exist to work around the problem, and the user base affected is small.

david-cattermole commented 3 years ago

Custom transform plug-in nodes will now work for cameras.

All the unit tests seem to work. It's still possible there's some mmSolver.tool.* code that doesn't work, but the utilities and API work correctly with custom transform nodes.

The only requirement of a transform node is that it's derived from a transform. It is not possible to derive a custom MPxNode with the same attributes - it must derive from MPxTransform.