简体   繁体   English

3D视图中的WPF 2D动画:性能问题

[英]WPF 2D in 3D view Animations : Performance issue

I've put a TextBlock in a 3D panel ( Planerator ) and I used a Storyboard to animate it. 我在一个3D面板( Planerator )中放置了一个TextBlock ,我使用了一个Storyboard来为它制作动画。 (as crawl text) (作为抓取文本)

When the field of view is 1 everything works fine, But if I set the field of view to more than 50 the frame rate will drop sharply and rendering will be choppy. 当视野为1时,一切正常,但如果我将视野设置为50以上,帧速率将急剧下降,渲染将会不稳定。

I used the CompositionTarget.rendering . 我使用了CompositionTarget.rendering

Please see the following images: 请看下面的图片:

在此输入图像描述

在此输入图像描述

I need to 2D animations in 3d view with good performance. 我需要3D视图中的2D动画具有良好的性能。

Please tell me how can I solve this problem? 请告诉我如何解决这个问题? Should I leave WPF and go to the DirectX? 我应该离开WPF并转到DirectX吗?

UPDATE 1 : 更新1:

I just want to move ONE 2Dtext in 3D space , but the performance is poor.(rendering isn't smooth it is choppy) 我只想在3D空间中移动一个 2Dtext,但性能很差。(渲染不顺畅,不稳定)

This is a sample project . 这是一个示例项目

UPDATE 2: 更新2:

This is the sample project updated version based on cokeman19's answer. 这是基于cokeman19的答案的示例项目更新版本。 (the performance have been improved ~10 frames, But I need to perfect rendering) (性能提升了~10帧,但我需要完美渲染)

UPDATE 3 : 更新3:

Finally, I got an acceptable performance with the help of the cokeman19's answer and the contents of this page . 最后,在cokeman19的回答和本页内容的帮助下,我获得了可接受的表现。

I'm not sure if it's just a byproduct of the sample app, but under Planerator.CreateVisualChild() , it doesn't seem to be necessary to set the GeometryModel3D.BackMaterial . 我不确定它是否只是示例应用程序的副产品,但在Planerator.CreateVisualChild() ,似乎没有必要设置GeometryModel3D.BackMaterial For reference: 以供参考:

VisualBrush vb = new VisualBrush(_logicalChild);
SetCachingForObject(vb);  // big perf wins by caching!!
Material backMaterial = new DiffuseMaterial(vb);
...
GeometryModel3D backModel = new GeometryModel3D() { ..., BackMaterial = backMaterial };

The BackMaterial is a VisualBrush wrapper around the logical child, which doesn't belong to the visual tree, so rendering doesn't seem to make sense here. BackMaterial是一个围绕逻辑子的VisualBrush包装器,它不属于可视树,因此这里的渲染似乎没有意义。 Moreover, the logical child (the LayoutInvalidationCatcher class), is in turn a wrapper around the visual child, which is already rendered (using _logicalChild ) in setting frontModel.Visual . 此外,逻辑子( LayoutInvalidationCatcher类)又是可视子对象的包装器,在设置frontModel.Visual已经呈现(使用_logicalChild )。

Removing the code for the creation and setting of BackMaterial brings the FPS up to ~55. 删除用于创建和设置BackMaterial的代码使FPS达到~55。

In addition, if it's an option, setting the following brings the FPS back up to 60, with no noticeable degradation in quality. 此外,如果它是一个选项,设置以下使FPS回升到60,质量没有明显降低。

RenderOptions.SetEdgeMode(_viewport3d, EdgeMode.Aliased);

Update: 更新:

The only other gain I was able to make was to set the CacheMode to BitmapCache , which may not be appliable for your needs. 我能够做的唯一其他收获是将CacheMode设置为BitmapCache ,这可能无法满足您的需求。

frontModel.CacheMode = new BitmapCache(20) { EnableClearType = false };

Even on my slowest machine, this allowed for maximum FPS, but there are some drawbacks. 即使在我最慢的机器上,这也允许最大的FPS,但是存在一些缺点。 Because the zoom level is so high on the text element, and this technique creates a picture to use in the animation (instead of animating the UIElement itself), I had to set the scale level to 20 before it became almost visually imperceptible. 因为缩放级别是文本元素的那么高,而且这种方法创建的画面在动画中使用(而不是动画的UIElement本身),我不得不把等级设置为20之前,它几乎成为视觉上感觉不到的。 This of course has memory implications, as well. 这当然也有记忆含义。

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

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