views:

175

answers:

3

I have a few 3D meshes in my WPF application, and I need to add some animations to them, not the typical animations, but rather a sequence of PNG images for creating a graphical animation.

Think of it like I need to add a cartoon animation to the side of a Cube.

I know very well about the Viewport2DVisual3D, but when I replace my normal ModelVisual3D with a Viewport2DVisual3D, I get horrible performance! Around the 5 FPS mark.

As soon as I remove the material with IsVisualHostMaterial set to true, the frame rate is restored to a normal state.

Performance is always a tricky subject, but what I was thinking was creating a Visual Brush with an image source of a WriteableBitmap or RenderTargetBitmap and then draw my PNG's to that sequence.

Does this sound OK, or should I not be getting the poor performance that I'm getting?

A: 

I haven't yet had a need to dig deeply into WPF's 3D optimizations, but I know that Direct3D is capable of rendering using a writable buffer so if MILCore implements it correctly your idea of WritableBitmap or RenderTargetBitmap have a reasonable chance of working. Vista's Flip 3D is able to make this work with high performance using arbitrary applications (even GDI applications) and also uses a writable buffer.

If that doesn't work, another idea for you is to convert your animation into a video, either the traditional way or by creating a DirectShow stream from a sequence of BitmapFrames.

Hopefully someone else can come along and give you a better answer.

Ray Burns
Its strange, I dont feel like what Im doing should perform badly... it just is
Mark
As I read it, the new IsVisualHostMaterial allows you to actually interact with the 2D visual on the 3D object using keyboard, mouse clicks, etc. So it seems to do a lot more than just presenting content. My guess would be that is why it slows things down so much.
Ray Burns
I see, so maybe keeping away from that is the way to go and just adding a new material as I need to?
Mark
Maybe. I'm no expert specifically on WPF 3D performance at this time. I'm just throwing out ideas from what I do know based on my Direct3D experience, my experience with WPF 3D, and my general WPF implementation knowlege.
Ray Burns
A: 

If your PNGs are representing a video stream, why not convert them to a video format at the outset? Creating an AVI from frames is easy. Horses for courses, as they say. It could be the PNG decoder slowing you down.

Nestor
yeah, perhaps, but the issue of poor performance is hitting me before I add a PNG at all to the scene.The viewport2dvisual3d.Visual Property is killing me even if there is nothing added in there...But, anyways, can you provide some links to AVI from PNG's?
Mark
I used the code at the link in a commercial project a while back. If you have any problems with it, let me know and I can probably get you the exact code I ended up using. http://www.adp-gmbh.ch/csharp/avi/write_avi.html
Nestor
+1  A: 

Actually, come to think of it, have you tried using this?

<DiffuseMatrial>
  <DiffuseMaterial.Brush>
    <VisualBrush ...>
      <VisualBrush.Visual>
        ...

I know that MILCore handles VisualBrush by rendering the backing Visual as a separate operation, so I wouldn't be surprised if it worked very efficiently with 3D.

Update

It also occurs to me you might try:

<DiffuseMaterial>
  <DiffuseMaterial.Brush>
    <DrawingBrush ...>
      <DrawingBrush.Drawing>
        <ImageDrawing ImageSource="{Binding ...} />

This would bypass the use of Visual entirely and possibly run much faster than Viewport2DVisual3D or VisualBrush.

Ray Burns
yeah, but according to the docs: http://msdn.microsoft.com/en-us/library/bb613553.aspx a Visual Brush is the least performant of all the brushes in 3D land... BUT to answer you question, no, I havent tried that :)
Mark
I hear what you're saying, and it's obvious that VisualBrush ought to be slower than all the brushes. But it seems to me that any Viewport2DVisual3D would have all the same issues as VisualBrush and then some. So my gut feeling tells me uncached VisualBrush should always be as fast as (or faster than) uncached Viewport2DVisual2D, and the same for the cached versions.
Ray Burns
True! I will give it a shot, thanks for the help so far, if you have some more thoughts please let me know
Mark