From 7219f6623742d33b9ff8b0900cc4f160bfc850c4 Mon Sep 17 00:00:00 2001 From: David Cattermole Date: Mon, 2 Jan 2023 16:14:14 +1030 Subject: [PATCH] Draw MM native ImagePlanes in background pass. This allows surfaces to be hidden-line wireframe, with an MM ImagePlane behind it. Before this change, Maya native ImagePlanes were drawn behind "hidden line" surfaces, but now both native and MM ImagePlanes work as expected. --- include/mmSolver/nodeTypeIds.h | 3 +++ src/mmSolver/pluginMain.cpp | 2 +- src/mmSolver/render/RenderOverride.cpp | 29 +++++++++++++++++++++++--- src/mmSolver/render/SceneRender.cpp | 22 ++++++++++++------- src/mmSolver/render/SceneRender.h | 3 ++- 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/include/mmSolver/nodeTypeIds.h b/include/mmSolver/nodeTypeIds.h index af2d985bb..fd6b13928 100644 --- a/include/mmSolver/nodeTypeIds.h +++ b/include/mmSolver/nodeTypeIds.h @@ -127,6 +127,9 @@ #define MM_IMAGE_PLANE_SHAPE_TYPE_ID 0x0012F187 #define MM_IMAGE_PLANE_SHAPE_TYPE_NAME "mmImagePlaneShape" +#define MM_IMAGE_PLANE_SHAPE_NODE_CLASSIFY \ + "auxiliary/camera:geometry/camera:imageplane:drawdb/geometry/mmSolver/" \ + "imagePlane" #define MM_IMAGE_PLANE_SHAPE_DRAW_CLASSIFY "drawdb/geometry/mmSolver/imagePlane" #define MM_IMAGE_PLANE_SHAPE_DRAW_REGISTRANT_ID "mmImagePlaneShape" #define MM_IMAGE_PLANE_SHAPE_SELECTION_TYPE_NAME "mmImagePlaneShapeSelection" diff --git a/src/mmSolver/pluginMain.cpp b/src/mmSolver/pluginMain.cpp index fbd537267..aebde4246 100644 --- a/src/mmSolver/pluginMain.cpp +++ b/src/mmSolver/pluginMain.cpp @@ -314,7 +314,7 @@ MStatus initializePlugin(MObject obj) { const MString markerClassification = MM_MARKER_DRAW_CLASSIFY; const MString bundleClassification = MM_BUNDLE_DRAW_CLASSIFY; const MString imagePlaneShapeClassification = - MM_IMAGE_PLANE_SHAPE_DRAW_CLASSIFY; + MM_IMAGE_PLANE_SHAPE_NODE_CLASSIFY; const MString skyDomeClassification = MM_SKY_DOME_DRAW_CLASSIFY; const MString lineClassification = MM_LINE_DRAW_CLASSIFY; REGISTER_LOCATOR_NODE(plugin, mmsolver::MarkerShapeNode::nodeName(), diff --git a/src/mmSolver/render/RenderOverride.cpp b/src/mmSolver/render/RenderOverride.cpp index f53c1b0fa..92688101d 100644 --- a/src/mmSolver/render/RenderOverride.cpp +++ b/src/mmSolver/render/RenderOverride.cpp @@ -312,13 +312,35 @@ MStatus RenderOverride::updateRenderOperations() { m_op_names[kSceneManipulatorPass] = "mmRenderer_SceneRender_Manipulator"; m_op_names[kPresentOp] = "mmRenderer_PresentTarget"; + // Draw these objects for transparency. + auto wire_draw_object_types = + ~(MHWRender::MFrameContext::kExcludeMeshes | + MHWRender::MFrameContext::kExcludeNurbsCurves | + MHWRender::MFrameContext::kExcludeNurbsSurfaces | + MHWRender::MFrameContext::kExcludeSubdivSurfaces); + + // Draw all non-geometry normally. + auto non_wire_draw_object_types = + ((~wire_draw_object_types) | + MHWRender::MFrameContext::kExcludeImagePlane | + MHWRender::MFrameContext::kExcludePluginShapes); + + // What objects types to draw for depth buffer? + auto depth_draw_object_types = + wire_draw_object_types | MHWRender::MFrameContext::kExcludeImagePlane; + + // Draw image planes in the background always. + auto bg_draw_object_types = + ~(MHWRender::MFrameContext::kExcludeImagePlane | + MHWRender::MFrameContext::kExcludePluginShapes); + SceneRender *sceneOp = nullptr; // Depth pass. sceneOp = new SceneRender(m_op_names[kSceneDepthPass]); sceneOp->setViewRectangle(rect); sceneOp->setSceneFilter(MHWRender::MSceneRender::kRenderShadedItems); - sceneOp->setExcludeTypes(MHWRender::MFrameContext::kExcludeImagePlane); + sceneOp->setExcludeTypes(depth_draw_object_types); sceneOp->setDisplayModeOverride(display_mode_shaded); // do not override objects to be drawn. sceneOp->setDoSelectable(false); @@ -330,6 +352,7 @@ MStatus RenderOverride::updateRenderOperations() { sceneOp = new SceneRender(m_op_names[kSceneBackgroundPass]); sceneOp->setViewRectangle(rect); sceneOp->setSceneFilter(MHWRender::MSceneRender::kRenderShadedItems); + // sceneOp->setExcludeTypes(bg_draw_object_types); // override drawn objects to only image planes under cameras. sceneOp->setDoSelectable(true); sceneOp->setDoBackground(true); @@ -356,7 +379,7 @@ MStatus RenderOverride::updateRenderOperations() { sceneOp = new SceneRender(m_op_names[kSceneWireframePass]); sceneOp->setViewRectangle(rect); sceneOp->setSceneFilter(MHWRender::MSceneRender::kRenderUIItems); - sceneOp->setExcludeTypes(MHWRender::MFrameContext::kExcludeManipulators); + sceneOp->setExcludeTypes(wire_draw_object_types); sceneOp->setDisplayModeOverride(display_mode_wireframe); // do not override objects to be drawn. sceneOp->setDoSelectable(false); @@ -389,7 +412,7 @@ MStatus RenderOverride::updateRenderOperations() { sceneOp = new SceneRender(m_op_names[kSceneManipulatorPass]); sceneOp->setViewRectangle(rect); sceneOp->setSceneFilter(MHWRender::MSceneRender::kRenderUIItems); - sceneOp->setExcludeTypes(~MHWRender::MFrameContext::kExcludeManipulators); + sceneOp->setExcludeTypes(non_wire_draw_object_types); sceneOp->setDoSelectable(false); sceneOp->setDoBackground(false); sceneOp->setClearMask(clear_mask_none); diff --git a/src/mmSolver/render/SceneRender.cpp b/src/mmSolver/render/SceneRender.cpp index 654073f0f..65153a102 100644 --- a/src/mmSolver/render/SceneRender.cpp +++ b/src/mmSolver/render/SceneRender.cpp @@ -123,8 +123,11 @@ SceneRender::postEffectsOverride() { const MSelectionList *SceneRender::objectSetOverride() { // If m_do_selectable is false and m_do_background is false: do // not override. - mSelectionList.clear(); - if (m_do_selectable && m_do_background) { + m_selection_list.clear(); + if (!m_do_selectable && !m_do_background) { + // This is the most common branch, so it is first. + return nullptr; + } else if (m_do_selectable && m_do_background) { // If m_do_selectable is true and m_do_background is true: // override drawn objects to only image planes under cameras. MItDag it; @@ -137,10 +140,14 @@ const MSelectionList *SceneRender::objectSetOverride() { if (path.pathCount() < 2) { continue; } - mSelectionList.add(path); + m_selection_list.add(path); + } else if (item.apiType() == MFn::kPluginLocatorNode) { + MDagPath path; + it.getPath(path); + m_selection_list.add(path); } } - return &mSelectionList; + return &m_selection_list; } else if (m_do_selectable && !m_do_background) { // If m_do_selectable is true and m_do_background is false: // override drawn objects to all image planes not under cameras. @@ -148,13 +155,14 @@ const MSelectionList *SceneRender::objectSetOverride() { it.traverseUnderWorld(false); for (it.reset(); !it.isDone(); it.next()) { auto item = it.currentItem(); - if (item.hasFn(MFn::kImagePlane)) { + if (item.hasFn(MFn::kImagePlane) || + (item.apiType() == MFn::kPluginLocatorNode)) { MDagPath path; it.getPath(path); - mSelectionList.add(path); + m_selection_list.add(path); } } - return &mSelectionList; + return &m_selection_list; } return nullptr; } diff --git a/src/mmSolver/render/SceneRender.h b/src/mmSolver/render/SceneRender.h index f09b53a9b..705a87768 100644 --- a/src/mmSolver/render/SceneRender.h +++ b/src/mmSolver/render/SceneRender.h @@ -111,7 +111,8 @@ class SceneRender : public MHWRender::MSceneRender { void setDoBackground(const bool value) { m_do_background = value; } protected: - MSelectionList mSelectionList; + // Objects Set override. Override which objects are drawn. + MSelectionList m_selection_list; // 3D viewport panel name, if available MString m_panel_name;