简体   繁体   English

使用WPF绘制3D线

[英]Drawing 3D Lines with WPF

We all know there are no native functionality within WPF 4.5 to draw pure lines in 3D space on a viewport3D. 我们都知道WPF 4.5中没有本机功能可以在viewport3D的3D空间中绘制纯线。

And I'm aware of the fact there are a few 3D-toolkits for WPF. 我知道有一些用于WPF的3D工具包。 But for my masterthesis I built my own 3D-engine. 但是对于我的掌握,我构建了自己的3D引擎。 It's almost complete but i would like to be able to draw the wireframes of my object (for example to show tessellation of a sphere). 它几乎完成了,但是我希望能够绘制对象的线框(例如,显示球体的细分)。 my engine can render almost every basic geometric form (cube, sphere, cone, cylinder, pyramid, ..) 我的引擎几乎可以渲染所有基本几何形状(立方体,球体,圆锥体,圆柱体,金字塔等)。

have you any idea how to draw lines? 你知道如何画线吗? (my only idea is to use a very thin cylinder or cube ... but i don't think that is very efficient because i have to render at least 8 points (12 triangles) for one single line) (我唯一的想法是使用一个非常薄的圆柱体或立方体...但是我认为这不是非常有效,因为我必须为一行绘制至少8个点(12个三角形))

因此,您只需将必要的数据以及颜色,多重采样,宽度或它可能需要的任何信息一起传递到引擎的像素着色器,然后使用PS画线。

If you are fine with unitary-width lines and you don't mind rendering wireframed then you can go that way. 如果您适合使用单位宽度的线条,并且不介意使用线框渲染,则可以采用这种方法。

A more complete alternative is drawing quadrangles composed by two adjacent triangles. 一个更完整的替代方法是绘制由两个相邻三角形组成的四边形。 You can use lines as primitives and take advantage of the geometry shader's capabilities and use it to generate the quad. 您可以将线用作图元,并利用几何着色器的功能并使用它来生成四边形。

Create a geometry shader receiving the two points forming each line and outputting a triangle list. 创建一个几何着色器,以接收形成每条线的两个点并输出一个三角形列表。 You just need to append four points to the output stream. 您只需要在输出流上附加四个点即可。 Use the computations shown in this paper from NVIDIA, to calculate each of the four coordinates of the quad. 使用NVIDIA 中本文显示的计算方法来计算四边形的四个坐标。

While the input of the geometry shader were lines, the output will be two triangles properly set up forming your line. 当几何着色器的输入是直线时,输出将是正确设置的两个三角形,形成您的直线。 Actually, this technique offers quite some flexibility since the quads are not constraint to being rectangles (ie each side can have different widths). 实际上,此技术提供了相当大的灵活性,因为四边形并不局限于矩形(即,每侧可以具有不同的宽度)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM