Rendered mesh in Wireframe DisplayMode

 With the following code it's possible to have a mesh that is always draw in Rendered even in Wireframe DisplayMode:

 

 

        class MyRenderedMesh : Mesh
        {
            public MyRenderedMesh(Mesh another)
                : base(another)
            {
            }

            protected override void DrawWireframe(DrawParams data)
            {
                Pre(data.RenderContext);
                SetRenderedShader(data);

                Color col = Color;
                if (data.Selected)
                    col = Color.Yellow;

                data.RenderContext.SetColorDiffuse(col, col);
                
                Draw(data);

                Post(data.RenderContext);

            }

            void SetRenderedShader(DrawParams data)
            {
                if (data.ShaderParams != null)
                {
                    bool prevLighting = data.ShaderParams.Lighting;
                    var prevPrimitiveType = data.ShaderParams.PrimitiveType;

                    data.ShaderParams.Lighting = true;
                    data.ShaderParams.PrimitiveType = shaderPrimitiveType.Polygon;

                    base.SetShader(data);

                    data.ShaderParams.Lighting = prevLighting;
                    data.ShaderParams.PrimitiveType = prevPrimitiveType;
                }
            }

            protected override void DrawIsocurves(DrawParams data)
            {
                //base.DrawIsocurves(data);
            }


            protected override void DrawForSelection(DrawParams data)
            {
                Pre(data.RenderContext);

                base.DrawForSelection(data);

                Post(data.RenderContext);
            }

            private static void Post(RenderContextBase context)
            {
                context.PopRasterizerState();
            }

            private void Pre(RenderContextBase context)
            {
                context.PushRasterizerState();
                context.SetState(rasterizerStateType.CCW_PolygonFill_CullFaceBack_PolygonOffset_1_1);
            }
        }

 

viewportLayout1.Entities.Add(new MyRenderedMesh(Mesh.CreateSphere(10, 10, 10)),0, Color.Red);

var cone = Mesh.CreateCone(10, 0, new Point3D(20, 0, 0), new Point3D(20, 0, 20), 15);
viewportLayout1.Entities.Add(cone, 0, Color.Green);
            
viewportLayout1.DisplayMode = displayType.Wireframe;

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

1 comment

Please sign in to leave a comment.