如何在monogame中显示所有边缘?

时间:2016-06-01 14:16:30

标签: c# 3d xna-4.0 monogame edge-detection

我正在使用Monogame 3.5,我有简单的立方体模型。我使用BasicEffect来绘制它。我希望它透明,所以我使用effect.Alpha = 0.5f。是否可以在图片上显示所有边缘?

1 个答案:

答案 0 :(得分:0)

根据您正在寻找的内容,有两种方法可以做到这一点。您可以将渲染栅格化器状态设置为显示线框,也可以使用VertexPositionColor获取边缘列表并绘制一组GraphicsDevice.DrawIndexedPrimitives

Raster Sizer State

您可以将立方体绘制为透明,然后假设您正在使用BasicEffect,则可以关闭所有着色并将颜色设置为白色。

然后,您可以在将新的rastersizer状态设置为FillMode.Wireframe的情况下重绘多维数据集。这里有一些伪代码。

//Draw the Cube Transparent
DrawCubeTransparent();

//Now save the Rastersizer state for later
RasterizerState originalRasterizerState = GraphicsDevice.RasterizerState; 


//Now set the RasterizerState too WireFrame
RasterizerState newRasterizerState = new RasterizerState();  
newRasterizerState.FillMode = FillMode.WireFrame;  
GraphicsDevice.RasterizerState = newRasterizerState; 

//Now redraw the cube as wireframe with the shading off and colour set to white
DrawCubeWireFrame();

//Now reset the Rastersizer fill state
raphicsDevice.RasterizerState = originalRasterizerState;

<强> DrawIndexedPrimitives

之前的方法可能并不理想,因为它会绘制所有三角形面,因此在你的立方体面上会有一条对角线。

另一种方法是找出你想要绘制的边,然后使用DrawIndexedPrimitives绘制一个包含所有边的顶点数组。

简单的谷歌搜索将为您提供大量使用它的示例。