Example #1
0
 public static FootPrintDrawAgentGL getDrawAgent()
 {
     if (null == singleton)
     {
         singleton = new FootPrintDrawAgentGL();
     }
     return(singleton);
 }
Example #2
0
        public static void draw(MDrawContext context, MUserData userData)
        {
            // This function is called by maya internal, .Net SDK has transfered MUserData to the derived one
            // Users don't need do the MUserData.getData(oldData) by themselves
            FootPrintData footData = MUserData.getData(userData) as FootPrintData;

            if (footData == null)
            {
                return;
            }

            MDAGDrawOverrideInfo objectOverrideInfo = footData.fDrawOV;

            if (objectOverrideInfo.fOverrideEnabled && !objectOverrideInfo.fEnableVisible)
            {
                return;
            }

            uint displayStyle = context.getDisplayStyle();

            bool drawAsBoundingBox = (displayStyle & (uint)MFrameContext.DisplayStyle.kBoundingBox) != 0 ||
                                     (footData.fDrawOV.fLOD == MDAGDrawOverrideInfo.DrawOverrideLOD.kLODBoundingBox);

            if (drawAsBoundingBox && !footData.fCustomBoxDraw)
            {
                return;
            }

            // get renderer
            Autodesk.Maya.OpenMayaRender.MHWRender.MRenderer theRenderer = Autodesk.Maya.OpenMayaRender.MHWRender.MRenderer.theRenderer();
            if (theRenderer == null)
            {
                return;
            }

            // get state data
            MMatrix transform =
                context.getMatrix(MDrawContext.MatrixType.kWorldViewMtx);

            MMatrix projection =
                context.getMatrix(MDrawContext.MatrixType.kProjectionMtx);

            // Check to see if we are drawing in a shadow pass.
            // If so then we keep the shading simple which in this
            // example means to disable any extra blending state changes
            //
            MPassContext passCtx        = context.passContext;
            MStringArray passSem        = passCtx.passSemantics;
            bool         castingShadows = false;

            for (int i = 0; i < passSem.length; i++)
            {
                if (passSem[i] == MPassContext.kShadowPassSemantic)
                {
                    castingShadows = true;
                }
            }
            bool debugPassInformation = false;

            if (debugPassInformation)
            {
                string passId = passCtx.passIdentifier;
                MGlobal.displayInfo("footprint node drawing in pass[" + passId + "], semantic[");
                for (int i = 0; i < passSem.length; i++)
                {
                    MGlobal.displayInfo(passSem[i]);
                }
                MGlobal.displayInfo("\n");
            }

            // get cached data
            float multiplier = footData.fMultiplier;

            float[] color = new float[4] {
                footData.fColor[0],
                footData.fColor[1],
                footData.fColor[2],
                1.0f
            };

            bool requireBlending = false;

            // If we're not casting shadows then do extra work
            // for display styles
            if (!castingShadows)
            {
                // Use some monotone version of color to show "default material mode"
                //
                if ((displayStyle & (uint)MFrameContext.DisplayStyle.kDefaultMaterial) != 0)
                {
                    color[0] = color[1] = color[2] = (color[0] + color[1] + color[2]) / 3.0f;
                }
                // Do some alpha blending if in x-ray mode
                //
                else if ((displayStyle & (uint)MFrameContext.DisplayStyle.kXray) != 0)
                {
                    requireBlending = true;
                    color[3]        = 0.3f;
                }
            }

            // Set blend and raster state
            //
            MStateManager    stateMgr            = context.stateManager;
            MBlendState      pOldBlendState      = null;
            MRasterizerState pOldRasterState     = null;
            bool             rasterStateModified = false;

            if ((stateMgr != null) && ((displayStyle & (uint)MFrameContext.DisplayStyle.kGouraudShaded) != 0))
            {
                // draw filled, and with blending if required
                if (requireBlending)
                {
                    if (blendState == null)
                    {
                        MBlendStateDesc desc = new MBlendStateDesc();
                        desc.targetBlends.blendEnable           = true;
                        desc.targetBlends.destinationBlend      = MBlendState.BlendOption.kInvSourceAlpha;
                        desc.targetBlends.alphaDestinationBlend = MBlendState.BlendOption.kInvSourceAlpha;
                        blendState = MStateManager.acquireBlendState(desc);
                    }

                    if (blendState != null)
                    {
                        pOldBlendState      = stateMgr.blendState;
                        stateMgr.blendState = blendState;
                    }
                }

                // Override culling mode since we always want double-sided
                //
                pOldRasterState = (stateMgr != null) ? stateMgr.rasterizerState : null;
                if (pOldRasterState != null)
                {
                    MRasterizerStateDesc desc = new MRasterizerStateDesc(pOldRasterState.desc);
                    // It's also possible to change this to kCullFront or kCullBack if we
                    // wanted to set it to that.
                    MRasterizerState.CullMode cullMode = MRasterizerState.CullMode.kCullNone;
                    if (desc.cullMode != cullMode)
                    {
                        if (rasterState != null)
                        {
                            // Just override the cullmode
                            desc.cullMode = cullMode;
                            rasterState   = MStateManager.acquireRasterizerState(desc);
                        }
                        if (rasterState == null)
                        {
                            rasterStateModified      = true;
                            stateMgr.rasterizerState = rasterState;
                        }
                    }
                }
            }

            //========================
            // Start the draw work
            //========================

            // Prepare draw agent, default using OpenGL
            FootPrintDrawAgentGL drawAgentRef = FootPrintDrawAgentGL.getDrawAgent();
            FootPrintDrawAgent   drawAgentPtr = drawAgentRef;

            if (drawAgentPtr != null)
            {
                // Set color
                drawAgentPtr.setColor(new MColor(color[0], color[1], color[2], color[3]));
                // Set matrix
                drawAgentPtr.setMatrix(transform, projection);

                drawAgentPtr.beginDraw();

                if (drawAsBoundingBox)
                {
                    // If it is in bounding bode, draw only bounding box wireframe, nothing else
                    MPoint min = footData.fCurrentBoundingBox.min;
                    MPoint max = footData.fCurrentBoundingBox.max;

                    drawAgentPtr.drawBoundingBox(min, max);
                }
                else
                {
                    // Templated, only draw wirefame and it is not selectale
                    bool overideTemplated = objectOverrideInfo.fOverrideEnabled &&
                                            (objectOverrideInfo.fDisplayType == MDAGDrawOverrideInfo.DrawOverrideDisplayType.kDisplayTypeTemplate);
                    // Override no shaded, only show wireframe
                    bool overrideNoShaded = objectOverrideInfo.fOverrideEnabled && !objectOverrideInfo.fEnableShading;

                    if (overideTemplated || overrideNoShaded)
                    {
                        drawAgentPtr.drawWireframe(multiplier);
                    }
                    else
                    {
                        if (((displayStyle & (uint)MFrameContext.DisplayStyle.kGouraudShaded) != 0) ||
                            ((displayStyle & (uint)MFrameContext.DisplayStyle.kTextured)) != 0)
                        {
                            drawAgentPtr.drawShaded(multiplier);
                        }

                        if ((displayStyle & (uint)MFrameContext.DisplayStyle.kWireFrame) != 0)
                        {
                            drawAgentPtr.drawWireframe(multiplier);
                        }
                    }
                }

                drawAgentPtr.endDraw();
            }

            //========================
            // End the draw work
            //========================

            // Restore old blend state and old raster state
            if ((stateMgr != null) && ((displayStyle & (uint)MFrameContext.DisplayStyle.kGouraudShaded) != 0))
            {
                if ((stateMgr != null) && (pOldBlendState != null))
                {
                    stateMgr.setBlendState(pOldBlendState);
                }
                if (rasterStateModified && (pOldBlendState != null))
                {
                    stateMgr.setRasterizerState(pOldRasterState);
                }
            }
        }
Example #3
0
 private FootPrintDrawAgentGL(FootPrintDrawAgentGL v)
 {
 }
Example #4
0
 public static FootPrintDrawAgentGL getDrawAgent()
 {
     if(null == singleton)
         singleton = new FootPrintDrawAgentGL();
     return singleton;
 }
Example #5
0
 private FootPrintDrawAgentGL( FootPrintDrawAgentGL v )
 {
 }