Performance issues

Topics: User Forum
Mar 1, 2007 at 10:36 PM
I animate, create and remove InteractiveVisual3Ds at runtime. When Visuals for IV3Ds are simple, performance is quite ok. For example I have 30 simple IV3Ds with an image as a Visual. I create another 30 IV3Ds, animate old ones away from users view and bring in the new ones, after this I remove old IV3Ds from the ModelVisual3D.Chilred (that contains all the IV3Ds). If I put a little more complex controls as Visual property for IV3Ds, things start getting slower. For example existing models animate out really "sticky" and new ones are displayed only after they are animated to the view. I think this performance could be boosted up a little if the whole animation would start only after new IV3Ds are completely rendered to the ViewPort3D. Only problem here is, I don't find any event telling me when WPF has rendered my items. When I create them, I position them outside of users view and start the animation.

When all the models are rendered and I animate them around the view, there's no performance decrease so this is why I believe it has something to do with starting the storyboard before things have rendered??

any ideas on this one?
Mar 20, 2007 at 7:31 PM
Upping the complexity of your visuals, especially if you have many of them, will definitely show some performance impact. I'm using a VisualBrush behind the scenes to put the Visual on the 3D object, and so the more complex that Visual, the more time WPF needs to spend rendering that Visual to a texture that the 3D object will then use. If you want more control, there also is the option of using a RenderTargetBitmap to render the Visual to a bitmap, and then to use this image as your texture. This would require some code changes, but could be good for more static content.

As far as the animation performance, what exactly does your animation look like, especially the one where they are all rendered and in view? The VisualBrush has caching turned on for performance, which should help if the visuals aren't changing and aren't sizing too much (i.e. requiring a new realization of the visual to avoid any aliasing artifacts), which is my guess why perf is good when they all are in view. If your animation in to view is sizing the 3D object, then it may not be able to take advantage of the caching perf, which could cause your problems. There are some other parameters you can tweak on caching, so you may just want to go in to InteractiveVisual3D.cs and play with some of the other options.
Mar 23, 2007 at 9:32 AM
Using RenderTargetBitmap definitively boosts performance expecially when text is involved. I could make things faster by not loading any content on my 2D controls that are 'placed' on the 3D controls when I create them and only loading things when items are selected.

When item is not selected, I use an image as a visual. I'm using cube as the 3D model so I have 6 image controls. I tried to change the InteractiveVisual3D so that I can set a DefaultMaterial property (shown when item is not selected) and then Visual property that sets the internal default material and will be shown when item is selected. I gave up debugging "unspecified error" each time material is changed from the internal material to default material. I saw there's some code in InteractiveVisual3D (GenerateMaterial method) commented as:
// begin order dependent operations
but even though doing things in similar way, I'll get an "unspecified error occurred on the render thread".

Things work fine now but come performance tuning could be done !