3D Triangle - WPF
Posted
by user300423
on Stack Overflow
See other posts from Stack Overflow
or by user300423
Published on 2010-03-24T00:25:18Z
Indexed on
2010/03/24
0:33 UTC
Read the original article
Hit count: 472
wpf
I am trying to apply an image brush to a Triangle in WPF without success. What am i doing wrong?
This is my attempt:
Dim ModelTri As New MeshGeometry3D
ModelTri.Positions.Add(New Point3D(0, 0, 0))
ModelTri.Positions.Add(New Point3D(100, 0, 0))
ModelTri.Positions.Add(New Point3D(100, 100, 0))
Dim MeshTri As New MeshGeometry3D
MeshTri.TriangleIndices.Add(0)
MeshTri.TriangleIndices.Add(1)
MeshTri.TriangleIndices.Add(2)
'Texture
Dim TexturePoints As New PointCollection
TexturePoints.Add(New Point(100, 0))
TexturePoints.Add(New Point(0, 100))
TexturePoints.Add(New Point(100, 100))
MeshTri.TextureCoordinates = TexturePoints
'Image Brush
Dim imgBrush As New ImageBrush()
imgBrush.ImageSource = New BitmapImage(New Uri("Mercury.jpg", UriKind.Relative))
imgBrush.Stretch = Stretch.Fill
imgBrush.TileMode = TileMode.Tile
imgBrush.SetValue(NameProperty, "imgBrush")
Dim Mat As Material
Dim DMaterial As New DiffuseMaterial
DMaterial.Brush = imgBrush
Dim Bind As New Binding("imgBrush")
Bind.Source = imgBrush
BindingOperations.SetBinding(DMaterial, BindingGroupProperty, Bind)
'This doesnt work
Mat = DMaterial
'This works
'Mat = New DiffuseMaterial(New SolidColorBrush(Colors.Khaki))
Dim triangleModel As GeometryModel3D = New GeometryModel3D(ModelTri, Mat)
Dim model As New ModelVisual3D()
model.Content = triangleModel
Viewport.Children.Add(model)
© Stack Overflow or respective owner