Esempio n. 1
0
        /// <summary>
        /// IRenderer interface method
        /// Renders a model in a viewport
        /// </summary>
        public bool RenderModel(RMModel model, Rhino.DocObjects.ViewportInfo viewport)
        {
            if (null == model || null == viewport || !model.IsReadyForRendering)
            {
                return(false);
            }

            Model = model;

            CheckGLError("intro call"); //HACK: necessary on some Android GPUs (don't delete this check)

            viewport.SetFrustumNearFar(model.BBox);

            // Disable Blending and set the depth function
            GL.DepthFunc(DepthFunction.Gequal);
            GL.Disable(EnableCap.Blend);

            // Get the shader...
            ActiveShader = FastDrawing ? GetShader("PerVertexLighting") : GetShader("PerPixelLighting");

            // Render calls...
            if (model != null)
            {
                // First, render all opaque objects that are not instances
                foreach (var obj in model.DisplayMeshes)
                {
                    if (obj != null)
                    {
                        RenderObject(obj, viewport, false);
                    }
                }

                // Second, render all opaque objects that are instances
                foreach (var obj in model.DisplayInstanceMeshes)
                {
                    if (obj != null)
                    {
                        RenderObject(obj, viewport, true);
                    }
                }

                // Third, we're done drawing our instances, so set the ModelViewMatrix's XForm back to the identity matrix.
                ActiveShader.SetModelViewMatrix(Rhino.Geometry.Transform.Identity);

                // Fourth, render all transparent meshes...
                RenderTransparentObjects(model);
            }

            // Disable the shader
            ActiveShader.Disable();

            return(true);
        }
Esempio n. 2
0
 private static bool AdjustFrustum(ViewportInfo vp, ClippingInfo clipping)
 {
     vp.SetFrustumNearFar (vp.FrustumNear * 0.1, vp.FrustumFar * 10);
     return true;
 }
Esempio n. 3
0
        public static bool SetupFrustum(ViewportInfo vp, ClippingInfo clipping)
        {
            double    n0 = vp.FrustumNear;
            double    f0 = vp.FrustumFar;

            // Because picking relies heavily on the projection, we first set the
            // viewport frustum here, capture and save it, then let the conduits
            // do what ever they want with it...eventually the viewport will be put
            // back to the captured state before leaving the pipeline...
            ClippingInfo m_SavedClipping = clipping;
            vp.SetFrustumNearFar(clipping.bbox_near, clipping.bbox_far,
                                 clipping.min_near_dist, clipping.min_near_over_far,
                                 clipping.target_dist
                                 );

            vp.GetFrustum(out m_SavedClipping.left,
                          out m_SavedClipping.right,
                          out m_SavedClipping.bottom,
                          out m_SavedClipping.top,
                          out m_SavedClipping.bbox_near,
                          out m_SavedClipping.bbox_far);

            // Next, set the values that the pipeline will actually use...
            if (!(AdjustFrustum(vp, clipping)))
                return false;

            return true;
        }