views:

45

answers:

0

Hi

I use Viewport3d and display my 3D Elements with inherited UIElement3D classes... Now I want to make different images of my viewport (different views). That means I have to make a new viewport3d at runtime and apply my specific view for the image on it..

see the following code:

' Start creating Image
Dim bitmap As New RenderTargetBitmap(800,
                                     800,
                                     96,
                                     96,
                                     PixelFormats.Default)

'--------------------
'Render xamlViewport works perfect
bitmap.Render(xamlViewport)

Using stream As FileStream = New FileStream("C:\\temp\\test_xamlviewport.png", FileMode.Create)
  Dim encoder As New PngBitmapEncoder
  encoder.Frames.Add(BitmapFrame.Create(bitmap))
  encoder.Save(stream)
End Using


'---------------------
'Render local Viewport don't work
Dim oViewport As New Viewport3D

oViewport.Height = 800
oViewport.Width = 800

oViewport.Children.Add(New C3DCuboid())
oViewport.Camera = New PerspectiveCamera(New Point3D(4, 7, 6), New Vector3D(-4, -7, -6), New Vector3D(0, 1, 0), 45)

Dim oVisual As New ModelVisual3D
oVisual.Content = New DirectionalLight(Colors.White, New Vector3D(-1, -2, -3))

oViewport.Children.Add(oVisual)
oViewport.Measure(New Size(800, 800))
oViewport.Arrange(New Rect(New Size(800, 800)))

bitmap = New RenderTargetBitmap(800,
                                 800,
                                 96,
                                 96,
                                 PixelFormats.Default)

bitmap.Render(oViewport)

Using stream As FileStream = New FileStream("C:\\temp\\test_localviewport.png", FileMode.Create)
  Dim encoder As New PngBitmapEncoder
  encoder.Frames.Add(BitmapFrame.Create(bitmap))
  encoder.Save(stream)
End Using

The first picture (test_xamlviewport.png) is shown correctly, but the second picture where I create my own Viewport3D Object and print it is empty (test_localviewport.png).

How can I force to Render my UIElement3D Objects or why it doesn't work if i make a new Viewport vs print the existing XAML viewport instance?

Here you find a sample solution which reproduce my problem http://cid-df67ca3f85229bd1.office.live.com/self.aspx/Development/WpfApplication2.zip

Regards Roland