Esempio n. 1
0
        // Main draw routine. Gets called by maya with draw requests.
        //
        public override void draw(MDrawRequest request, M3dView view)
        {
            // Get the token from the draw request.
            // The token specifies what needs to be drawn.
            //
            DrawShapeStyle token = (DrawShapeStyle)request.token;

            switch (token)
            {
            case DrawShapeStyle.kDrawWireframe:
            case DrawShapeStyle.kDrawWireframeOnShaded:
            case DrawShapeStyle.kDrawVertices:
                drawVertices(request, view);
                break;

            case DrawShapeStyle.kDrawSmoothShaded:
                break;                           // Not implemented, left as exercise

            case DrawShapeStyle.kDrawFlatShaded: // Not implemented, left as exercise
                break;
            }
        }
Esempio n. 2
0
        public override void draw(MDrawRequest request, M3dView view)
        //
        // From the given draw request, get the draw data and determine
        // which quadric to draw and with what values.
        //
        {
            MDrawData data = request.drawData();

            quadricGeom geom = data.geometry() as quadricGeom;

            DrawShapeStyle token       = (DrawShapeStyle)request.token;
            bool           drawTexture = false;

            view.beginGL();

            if ((token == DrawShapeStyle.kDrawSmoothShaded) || (token == DrawShapeStyle.kDrawFlatShaded))
            {
                OpenGL.glEnable((uint)OpenGL.GL_POLYGON_OFFSET_FILL);

                // Set up the material
                //
                MMaterial material = request.material;
                material.setMaterial(request.multiPath, request.isTransparent);

                // Enable texturing
                //
                drawTexture = material.materialIsTextured;
                if (drawTexture)
                {
                    OpenGL.glEnable((uint)OpenGL.GL_TEXTURE_2D);
                }

                // Apply the texture to the current view
                //
                if (drawTexture)
                {
                    material.applyTexture(view, data);
                }
            }

            IntPtr qobj = GLUFunctionInvoker.gluNewQuadric();

            switch (token)
            {
            case DrawShapeStyle.kDrawWireframe:
            case DrawShapeStyle.kDrawWireframeOnShaded:
                GLUFunctionInvoker.gluQuadricDrawStyle(qobj, GLU_LINE);
                break;

            case DrawShapeStyle.kDrawSmoothShaded:
                GLUFunctionInvoker.gluQuadricNormals(qobj, GLU_SMOOTH);
                GLUFunctionInvoker.gluQuadricTexture(qobj, GLtrue);
                GLUFunctionInvoker.gluQuadricDrawStyle(qobj, GLU_FILL);
                break;

            case DrawShapeStyle.kDrawFlatShaded:
                GLUFunctionInvoker.gluQuadricNormals(qobj, GLU_FLAT);
                GLUFunctionInvoker.gluQuadricTexture(qobj, GLtrue);
                GLUFunctionInvoker.gluQuadricDrawStyle(qobj, GLU_FILL);
                break;
            }

            switch (geom.shapeType)
            {
            case (short)DrawShapeType.kDrawCylinder:
                GLUFunctionInvoker.gluCylinder(qobj, geom.radius1, geom.radius2, geom.height,
                                               geom.slices, geom.stacks);
                break;

            case (short)DrawShapeType.kDrawDisk:
                GLUFunctionInvoker.gluDisk(qobj, geom.radius1, geom.radius2, geom.slices, geom.loops);
                break;

            case (short)DrawShapeType.kDrawPartialDisk:
                GLUFunctionInvoker.gluPartialDisk(qobj, geom.radius1, geom.radius2, geom.slices,
                                                  geom.loops, geom.startAngle, geom.sweepAngle);
                break;

            case (short)DrawShapeType.kDrawSphere:
            default:
                GLUFunctionInvoker.gluSphere(qobj, geom.radius1, geom.slices, geom.stacks);
                break;
            }

            // Turn off texture mode
            //
            if (drawTexture)
            {
                OpenGL.glDisable((uint)OpenGL.GL_TEXTURE_2D);
            }

            view.endGL();
        }