Wireframe rendering in WPF

2019-01-26 10:34发布

I have to write a wireframe 3D renderer in a big WPF app that does many things But WPF has no native ability to do this.

Some people use "3D Tools for WPF" by Microsoft, specifically its ScreenSpaceLines3D class. But on the web there are complaints about slow performance and various bugs with that class, and the class library doesn't seem to have been maintained since 2007!

Others have suggested the LinesVisual3D class from the Helix 3D toolkit, but apparently that's buggy, too ( http://helixtoolkit.codeplex.com/workitem/9957 )

Charles Petzold has a 3D library - does anyone know it's reasonably robust?

So do I have any good options here? For example, is there a good way to do OpenGL3D in a WPF window? Are there other good WPF libraries that can do this reliably?

Thanks in advance.

标签: wpf 3d
3条回答
我想做一个坏孩纸
2楼-- · 2019-01-26 10:44

This page seems to have information about using OpenGL. Microsoft also mentions using Direct3d and XNA. XNA is pretty easy to use, and if you know OpenGL already, you probably won't have much problem learning Direct3d. I admit though that when I learned Direct3d, the material on it weren't as good as OpenGL material.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-26 11:04

Check out SlimDX. XNA and Managed DirectX etc.. are deprecated or old. Possibly also check SharpDX i haven't checked it in a while. We use SlimDX for DirectX in .NET and it is good. What you are probably looking at doing is using SlimDX to render on a D3DImage for WPF interop. Another possible option is using a hosted WinForms control and using the handle of that to interop with DirectX with SlimDX which might be faster, but you lose some easier interop with WPF's rendering engine etc. If you use the D3DImage it becomes an ImageBrush that you can set as the background of anything and you do not have to worry about airspace issues etc.

Edit: oh yeah, for some reason SlimDX doesn't have their samples in the download anymore, but their source code has the samples if you download it.

查看更多
三岁会撩人
4楼-- · 2019-01-26 11:07

I've seen many replies referring to 3rd party solutions for this problem.

For a pure WPF solution, I create a new Model3D from the existing Model3D, where each facet is created with a hole in it. i.e. split into 6 new facets, with the width of each 'line' proportional to the original facet size.

Reason for this is that it looks better than fixed line width, but you can use fixed line width if required.

Optionally fill in the centre hole as a new facet in black (separate Model3D in the group), and you have hidden line removal.

For three points in the facet, A0, B0 and C0, calculate the mid points of AB, AC and BC. the new point A1 is 1/20th along the line towards BC. Repeat for next two points B1 and C1.

The 6 new facets for the 'lines' are represented by the following combinations:

A0, B0, B1
A0, B1, A1
A0, C1, C0
A0, A1, C1
B0, C0, C1
B0, C1, B1

Add A1, B1 and C1 to another model for the hidden line removal variant.

查看更多
登录 后发表回答