对于复杂的应用程序,WPF 3D 是 DirectX 和 OpenGL 的良好替代品吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8941383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is WPF 3D good alternate of DirectX and OpenGL for complex applications?
提问by SpeedBirdNine
I have used WPF's 3D capabilities for learning, and for a few implementations, and I have found it to be very capable, and I am also learning DirectX 11, and it is very tricky compared to using 3D classes in WPF. I have only used WPF 3D for very basic stuff, my question is:
我已经使用 WPF 的 3D 功能进行学习,并进行了一些实现,我发现它非常有能力,而且我也在学习 DirectX 11,与在 WPF 中使用 3D 类相比,它非常棘手。我只将 WPF 3D 用于非常基本的东西,我的问题是:
Is WPF 3D equally good for advanced applications such as 3D modelling tools, game engines and 3D simulations etc to be an alternative to DirectX and OpenGL?
作为 DirectX 和 OpenGL 的替代品,WPF 3D 是否同样适用于 3D 建模工具、游戏引擎和 3D 模拟等高级应用程序?
If there is anything else in the same league, please mention it too.
如果在同一个联盟里还有什么,请也提一下。
回答by Dr. ABT
Good question. The answer is it depends!!
好问题。答案是视情况而定!!
On a more useful note I can say this: A few years ago I developed a CAD-style 3D rendering application in OpenGL. This had to display CAD models of oil rigs with up to 1,000,000 objects and allow the user to zoom right in to detail, or zoom out, move objects etc... I can say with some certainty that WPF wouldn't be suitable for this type of application as it would just be too slow. This application was developed using C++/CLI and bridged from a .NET GUI (Toolbar, window) to C++ to OpenGL (render surface) and even that introduced a performance hit over a native C++/OpenGL application due to thunking. So, if you want the highest performance, you cannot beat native C++ with DirectX or OpenGL.
更有用的是,我可以这样说:几年前,我在 OpenGL 中开发了一个 CAD 风格的 3D 渲染应用程序。这必须显示具有多达 1,000,000 个对象的石油钻井平台的 CAD 模型,并允许用户直接放大细节,或缩小、移动对象等......我可以肯定地说 WPF 不适合这个类型的应用程序,因为它太慢了。此应用程序是使用 C++/CLI 开发的,并从 .NET GUI(工具栏、窗口)桥接到 C++ 到 OpenGL(渲染表面),甚至由于thunking导致性能下降超过本机 C++/OpenGL 应用程序。所以,如果你想要最高的性能,你不能用 DirectX 或 OpenGL 打败原生 C++。
WPF can provide high performance 3D graphics and smooth interactivity for simpler 3D applications. For instance, a 3D chart surface or a 3D carousel, even a 3D CAD model viewer so long as the model was fairly simple. Once the object count starts to ramp up you will notice the rendering engine can't handle it - that's when you need to switch to a rendering engine that allows direct access to the GPU.
WPF 可以为更简单的 3D 应用程序提供高性能的 3D 图形和流畅的交互性。例如,3D 图表表面或 3D 旋转木马,甚至 3D CAD 模型查看器,只要模型相当简单。一旦对象数量开始增加,您会注意到渲染引擎无法处理它——这时您需要切换到允许直接访问 GPU 的渲染引擎。
For a halfway house solution (managed + DirectX), try SharpDX. This is basically an open source implementation of Managed DirectX and is extremely powerful and versatile. The performance hit of managed vs. native C++ is minor (~5%) and when done right, managed DirectX can be extremely performant.
对于中途解决方案(托管 + DirectX),请尝试SharpDX。这基本上是托管 DirectX 的开源实现,并且非常强大和通用。托管与本机 C++ 的性能影响很小 (~5%),如果做得好,托管 DirectX 可以非常高效。
Something we've done is integrate DirectX directly with WPF via D3DImage. We've achieved this in a WPF 3D Chart Controlwhich uses DirectX11 for the drawing (not WPF3D). This shares directly from native DirectX to WPF but you can get equally good results with SharpDX, which we've used to create a high speed WPF Drawing Pluginhere.
我们所做的是通过D3DImage直接将 DirectX 与 WPF 集成。我们已经在WPF 3D 图表控件中实现了这一点,该控件使用 DirectX11 进行绘图(不是 WPF3D)。这直接从本机 DirectX 共享到 WPF,但您可以使用SharpDX获得同样好的结果,我们在这里用它来创建高速WPF 绘图插件。
For a showcase of WPF3D I suggest you try this link. As you notice WPF3D can make extremely visually appealling and sometimes complex examples but you won't find any 1,000,000 object oil rigs in there ;)
对于 WPF3D 的展示,我建议您尝试此链接。正如您所注意到的,WPF3D 可以制作极具视觉吸引力且有时很复杂的示例,但您在其中找不到任何 1,000,000 个对象石油钻井平台;)
Finally, what is it that you wanted to do in WPF 3D? Just a point of interest or do you have a specific project to implement and want to know if it would be suitable?
最后,您想在 WPF 3D 中做什么?只是一个兴趣点,或者您是否有要实施的特定项目并想知道它是否合适?
Best regards,
此致,
回答by Sergey Orlov
There are two models of 3D Graphics: 1. Pipeline or infinite loop approach (3D Games, Hard level3D Cad systems with 100.000 and more objects - meshes) 2. Smart abstract model WPF3D with classic support of OOP without any OnDraw, OnPaintmethods. It is very important to use Media3D methods of WPF by right way. So most important thing is without any OnDraw, OnPaint.
3D 图形有两种模型: 1. 流水线或无限循环方法(3D 游戏,具有 100.000 和更多对象的硬级3D Cad 系统- 网格) 2. 智能抽象模型 WPF3D,具有经典的 OOP 支持,没有任何 OnDraw、OnPaint方法。正确使用 WPF 的 Media3D 方法非常重要。所以最重要的是没有任何 OnDraw, OnPaint。
You must analyze your application type and features and choose.
您必须分析您的应用程序类型和功能并进行选择。
It is not so correct opinion about WPF 3D as for most simple application, but for full managed OOP objects. For example, take a look on screenshots on my site TIMO Structural CAE
对于大多数简单的应用程序,WPF 3D 并不是那么正确,而是完全托管的 OOP 对象。例如,查看我网站TIMO Structural CAE上的屏幕截图
It is full managed 3D WPF app.
它是完全托管的 3D WPF 应用程序。
回答by Dan Bryant
If you really want to do something complex, you're actually better off using an established graphics engine (typically developed for games), rather than using DirectX or OpenGL directly. The WPF 3D engine provides a similar level of abstraction, though it has a drastically smaller feature set (you're still going to have to work pretty hard if you want shadows, reflections, refraction, bump maps, skeletal animation, etc.)
如果您真的想做一些复杂的事情,实际上最好使用已建立的图形引擎(通常为游戏开发),而不是直接使用 DirectX 或 OpenGL。WPF 3D 引擎提供了类似的抽象级别,尽管它的功能集要小得多(如果您想要阴影、反射、折射、凹凸贴图、骨骼动画等,您仍然需要非常努力地工作)
That said, I've used it successfully for visualization of an in-house 3D simulation tool and it's more than adequate for my needs. It performs fairly well even with a crowded scene and the basic lighting support is enough to clearly visualize the geometry. It was also quite easy to get working, which is a big plus in my book (didn't have much time to invest in developing visualization.)
也就是说,我已经成功地将它用于内部 3D 模拟工具的可视化,它足以满足我的需求。即使在拥挤的场景中,它的表现也相当不错,并且基本的照明支持足以清晰地可视化几何体。工作也很容易,这在我的书中是一个很大的优势(没有太多时间投资开发可视化。)
回答by Samuel Slade
If by WPF's 3D you mean it's ability to display hardware accelerated 3D graphics, then I would say yes. If, however, you mean WPF's 3D framework; then I would be tempted to say no.
如果 WPF 的 3D 是指它能够显示硬件加速的 3D 图形,那么我会说是的。但是,如果您指的是 WPF 的 3D 框架;那么我会很想说不。
I haven't used a great deal of the WPF 3D framework, but from what I have used, I have found it to involve a lot of hard-coded points. That being said, there is probably ways around that, but I generally don't think the framework was ever built with advanced 3D graphics in mind (such as modelling tools and game engines).
我没有大量使用WPF 3D框架,但是从我使用的内容来看,我发现它涉及很多硬编码点。话虽如此,可能有办法解决这个问题,但我通常认为该框架在构建时并没有考虑到高级 3D 图形(例如建模工具和游戏引擎)。
However, what I have found it to be good at, is displaying 3D rendered content and smoothly integrating the rendered content with it's UI composition system. I have used WPF extensively in this way as an application host for rendering and manipulating 3D content - specifically in terms of a 3D modelling context.
但是,我发现它擅长的是显示 3D 渲染的内容,并将渲染的内容与其 UI 组合系统顺利集成。我以这种方式广泛使用 WPF 作为渲染和操作 3D 内容的应用程序主机 - 特别是在 3D 建模上下文方面。
For such situations, you can use the D3DImage
control embedded within a WPF application to allow DirectX content to be rendered directly on your application. You can either render to this surface using DirectX itself, or a managed wrapper such as SlimDX. The latter of which I have found to be very good as it supports DirectX versions 9, 10 and 11, and it is a fairly thin wrapper so a lot of the DirectX API is usable in almost the same way.
对于这种情况,您可以使用D3DImage
嵌入在 WPF 应用程序中的控件来允许 DirectX 内容直接在您的应用程序上呈现。您可以使用 DirectX 本身或托管包装器(例如SlimDX )渲染到此表面。我发现后者非常好,因为它支持 DirectX 版本 9、10 和 11,并且它是一个相当薄的包装器,因此许多 DirectX API 几乎可以以相同的方式使用。
Overall, I would say it entirely depends on your required usage of the 3D system.
总的来说,我会说这完全取决于您对 3D 系统的要求。
回答by Peter Tate
While the answer is of course it depends. I will be bold and say that WPF 3D is great for learning, simple needs, and integrating 3D into an otherwise 2D application.
虽然答案当然是它取决于。我会大胆地说 WPF 3D 非常适合学习、简单的需求以及将 3D 集成到其他 2D 应用程序中。
Since you're considering WPF, I'll assume you're looking at using C# to write something that installs on Windows. In addition to what others recommend, I suggest looking at XNA, which is not part of WPF, but a subset of which is available in Silverlight 5 (if you want to stick with XAML).
由于您正在考虑使用 WPF,我假设您正在考虑使用 C# 编写可安装在 Windows 上的内容。除了其他人推荐的内容之外,我建议查看 XNA,它不是 WPF 的一部分,而是 Silverlight 5 中提供的一个子集(如果您想坚持使用 XAML)。
I've programmed in OpenGL with C, DirectX in C++ and Managed DirectX (obsolte) and WPF 3D. WPF 3D provides a very high level of abstraction, provides a lot of convenience features, and is suitable for some applications. I've used it in the past on an application that combined 2D and 3D graphics and it worked well for this application. In this case, I needed arbitrary clipping planes, which was a feature that wasn't available, and it was easier to manually do the clipping than to use a different API that provided this feature but lacked much of the high level convenience.
我已经使用 C 语言在 OpenGL 中进行了编程,C++ 中的 DirectX 以及托管 DirectX(已过时)和 WPF 3D。WPF 3D 提供了非常高的抽象层次,提供了很多方便的特性,适用于一些应用程序。我过去曾在一个结合了 2D 和 3D 图形的应用程序中使用过它,并且它在这个应用程序中运行良好。在这种情况下,我需要任意剪裁平面,这是一个不可用的功能,并且手动剪裁比使用提供此功能但缺乏很多高级便利性的其他 API 更容易。