Ask a questionAsk a question
 

AnswerDifficulty applying video texture

  • Friday, October 30, 2009 7:20 PMm6a2x6 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi!

    I'm new to WPF and I would like to have some light on an obscure problem I am having.

    I'm actually just trying to mix two tutorials i found on the Net, that is making a new 3D Mesh to show a triangle on a ViewPort3D and another one that can use a video from a MediaPlayer for a brush. I actually can apply a SolidColorBrush to my Mesh, but not a DrawingBrush made from a VideoDrawing. This DrawingBrush works perfect on a simple 2D rectangle...

    Here is an example of my testing application:

    The video rectangle is a simple rectangle with the DrawingBrush applied. The triangle is the Mesh with the SolidColorBrush applied. If i try to apply the DrawingBrush to the triangle, just nothing appears... There is a MediaElement which is above the rectangle but it does not show on the picture and works just fine...


    Free Image Hosting at www.ImageShack.us

    Here is my xaml code:
    <Window x:Class="Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Max's Media Player" Height="576" Width="427">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="260*" />
                <RowDefinition Height="278*" />
            </Grid.RowDefinitions>
            <Button Height="37" HorizontalAlignment="Left" Margin="16,18,0,0" Name="Button1" VerticalAlignment="Top" Width="111">Play</Button>
            <MediaElement Margin="0,9,10,0" Name="MediaElement1" Source="test.mpg" Height="94" HorizontalAlignment="Right" VerticalAlignment="Top" Width="156" />
            <Button HorizontalAlignment="Left" Margin="16,114,0,109" Name="Button2" Width="111">Stop</Button>
            <Button Height="37" HorizontalAlignment="Left" Margin="16,66,0,0" Name="Button3" VerticalAlignment="Top" Width="111">Pause</Button>
            <CheckBox Height="17" HorizontalAlignment="Left" Margin="16,0,0,82" Name="CheckBox1" VerticalAlignment="Bottom" Width="111">Mute</CheckBox>
            
            <Canvas Grid.Row="1" Margin="14.29,11.432,11.432,18.577" Name="Canvas1">
                <Viewport3D Name="mainViewport" ClipToBounds="True" Height="247.991" Canvas.Left="0" Canvas.Top="0" Width="379.278" Focusable="True">
                    <Viewport3D.Camera>
                        <PerspectiveCamera 
    	      FarPlaneDistance="100"
    	      LookDirection="-11,-10,-9"
    	      UpDirection="0,1,0"
    	      NearPlaneDistance="1" 
    	      Position="11,10,9" 
    	      FieldOfView="70" />
                        </Viewport3D.Camera>
                        <ModelVisual3D>
                            <ModelVisual3D.Content>
                                <DirectionalLight 
    	        Color="White" 
    	        Direction="-2,-3,-1" />
                            </ModelVisual3D.Content>
                        
                    </ModelVisual3D>
                    
                </Viewport3D>
            </Canvas>
            <Button Height="38.583" HorizontalAlignment="Left" Margin="18.577,0,0,27.151" Name="Button4" VerticalAlignment="Bottom" Width="105.746">3D!</Button>
            <Rectangle Height="100" Margin="195,0,10,27.151" Name="Rectangle1" Stroke="Black" VerticalAlignment="Bottom" />
        </Grid>
    </Window>
    
    
    And my ButtonClick code:

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button4.Click
            Dim PremierTriangle As New MeshGeometry3D
            Dim Point0 As New Point3D(0, 5, 0)
            Dim Point1 As New Point3D(5, 0, 0)
            Dim Point2 As New Point3D(0, 0, 5)
    
            PremierTriangle.Positions.Add(Point0)
            PremierTriangle.Positions.Add(Point1)
            PremierTriangle.Positions.Add(Point2)
    
            PremierTriangle.TriangleIndices.Add(0)
            PremierTriangle.TriangleIndices.Add(2)
            PremierTriangle.TriangleIndices.Add(1)
    
            Dim Normale As New Vector3D(0, 1, 0)
            PremierTriangle.Normals.Add(Normale)
            PremierTriangle.Normals.Add(Normale)
            PremierTriangle.Normals.Add(Normale)
    
            Dim Materiel1 As New DiffuseMaterial(New SolidColorBrush(Colors.DarkBlue))
    
    
            Dim MediaPlayer1 As New MediaPlayer()
            Dim uri As New System.Uri("I:\Mes documents\Visual Studio 2008\Projects\WpfApplication2\WpfApplication2\test.mpg")
            MediaPlayer1.Open(uri)
            Dim VDrawing1 As New VideoDrawing()
            VDrawing1.Rect = New Rect(0, 0, 100, 100)
            VDrawing1.Player = MediaPlayer1
            Dim DrawBrush1 As New DrawingBrush()
            DrawBrush1.Drawing = VDrawing1
            VDrawing1.Player.Play()
            Dim Materiel2 As New DiffuseMaterial(DrawBrush1)
    
    
            Dim ImBrsh As New ImageBrush
            Try
                ImBrsh.ImageSource = New BitmapImage(New Uri("I:\Mes documents\Visual Studio 2008\Projects\WpfApplication2\WpfApplication2\bin\Debug\image.bmp"))
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            Dim Materiel3 As New DiffuseMaterial(ImBrsh)
            
            Rectangle1.Fill = DrawBrush1
    
            Dim LeModeleTriangle As New GeometryModel3D()
            LeModeleTriangle.Geometry = PremierTriangle
            LeModeleTriangle.Material = Materiel1
            Dim LeModele As New ModelVisual3D()
            LeModele.Content = LeModeleTriangle
            Me.mainViewport.Children.Add(LeModele)
        End Sub
    
    Thank you for helping me debug!

Answers

All Replies