Mesh entity displayed as wireframe object

You can have a mesh entity displayed always in wireframe mode, regardless of the DisplayMode, by using the following class derived from Mesh:

 

Capture.PNG

 

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

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

        gl.Color3fv(Utility.ColorToFloatArray(Color)); 

        base.Draw(data); 

        Post(data.RenderContext); 
    } 

    protected override void SetShader(DrawParams data)
    { 
        if (data.ShaderParams != null)
        { 
            bool prevLighting = data.ShaderParams.Lighting; 

            data.ShaderParams.Lighting = false; 

            base.SetShader(data); 

            data.ShaderParams.Lighting = prevLighting; 
        } 
    } 

    protected override void DrawForShadow(RenderParams data)
    { 
        Pre(data.RenderContext); 

        base.DrawForShadow(data); 

        Post(data.RenderContext); 
    } 

    protected override void Render(RenderParams data)
    { 
        Pre(data.RenderContext); 

        data.RenderContext.SetColorWireframe(Color); 
                 
        base.Render(data); 

        Post(data.RenderContext); 
    } 

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

        data.RenderContext.SetColorWireframe(Color.Yellow); // Set the Selection color 
                 
        base.DrawSelected(data); 

        Post(data.RenderContext); 
    } 

    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_PolygonLine_NoCullFace);                 
    } 
}
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.