I'm trying to place a texture in a 3d object, using Visual Basic and WPF, but I'm not being able to do it.
If instead of an image I render a blue square, by replacing the line
mymodel3dgroup.Children.Add(New GeometryModel3D(mymesh, df))
for
mymodel3dgroup.Children.Add(New GeometryModel3D(mymesh, New DiffuseMaterial(Brushes.Blue)))
then I get a blue square. But what I need is to see the image, not just paint the object(s).
Can you please help?
My thanks in advanced
Imports System.Windows.Media.Media3D
Public Class UserControl1
Dim mymesh As New MeshGeometry3D
Dim myviewport3d As New Viewport3D
Dim mymodelvisual As New ModelVisual3D
Dim mypccamera As New PerspectiveCamera(New Point3D(0, 0, -5), New Vector3D(0, 0, 1), New Vector3D(0, 1, 0), 100)
Dim mymodel3dgroup As New Model3DGroup
Dim myMaterial As DiffuseMaterial
Private Sub UserControl1_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
contentcontrol1.Content = myviewport3d
myviewport3d.Children.Add(mymodelvisual)
myviewport3d.Camera = mypccamera
mymodel3dgroup.Children.Add(New DirectionalLight(Colors.White, New Vector3D(0, 0, 1)))
mymodelvisual.Content = mymodel3dgroup
mymesh.Positions.Add(New Point3D(0, 7, 0))
mymesh.Positions.Add(New Point3D(7, 7, 0))
mymesh.Positions.Add(New Point3D(7, 0, 0))
mymesh.Positions.Add(New Point3D(7, 0, 0))
mymesh.Positions.Add(New Point3D(0, 0, 0))
mymesh.Positions.Add(New Point3D(0, 7, 0))
Dim m As System.Windows.Media.Media3D.Material
'Dim m = New System.Windows.Media.Media3D.Material()
Dim df As System.Windows.Media.Media3D.DiffuseMaterial
Dim spm As System.Windows.Media.Media3D.SpecularMaterial
Dim ri As Uri = New Uri("d:\transferir.jpeg", UriKind.Absolute)
Dim imgSource As ImageSource = New BitmapImage(ri)
Dim ib = New ImageBrush()
ib.ImageSource = New BitmapImage(New Uri("d:\cc.png", UriKind.Absolute))
ib.Stretch = Stretch.Fill
ib.ViewboxUnits = BrushMappingMode.Absolute
ib.AlignmentX = AlignmentX.Left
ib.AlignmentY = AlignmentY.Top
ib.Opacity = 0.5
df = New System.Windows.Media.Media3D.DiffuseMaterial(ib)
spm = New System.Windows.Media.Media3D.SpecularMaterial(ib, 85)
mymodel3dgroup.Children.Add(New GeometryModel3D(mymesh, df))
End Sub
End Class