Seethrough Meshes

Nate Bross

Contributor
Joined
Apr 6, 2005
Messages
601
Location
Chicago, IL
I worked out the following code and it works great with one exception. When I am looking at them, (I am using the wall_with_pillars.x mesh that comes with the DirectX August SDK Update) they are see through. You can easily see the object, but it is see through. You can see clearly with a screenshot I took. If you look at the pillers they are all see through. Any advice anyone has would be greatly appreciated.
Visual Basic:
    Private Mesh As Mesh
    Private Materials() As Material
    Private Textures() As Texture



    Private Sub DrawMesh()
        Dim i As Long

        For i = 0 To Materials.Length - 1

            If Not Textures(i) Is System.DBNull.Value Then

                Direct3DDevice.SetTexture(0, Textures(i))
            End If


            Direct3DDevice.Material = Materials(i)

            Mesh.DrawSubset(i)
        Next i

    End Sub
    Private Sub CreateMesh(ByVal path As String)

        Dim exMaterials() As ExtendedMaterial
        Mesh = Mesh.FromFile(path, MeshFlags.SystemMemory, Direct3DDevice, exMaterials)


        If Not Textures Is System.DBNull.Value Then

            'DisposeTextures()
        End If



        Textures = New Texture(exMaterials.Length) {}
        Materials = New Material(exMaterials.Length) {}

        Dim i As Long

        For i = 0 To exMaterials.Length - 1

            If exMaterials(i).TextureFilename <> "" Then
                Dim texturePath As String
                texturePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), exMaterials(i).TextureFilename)
                Textures(i) = TextureLoader.FromFile(Direct3DDevice, texturePath)
            End If
            Materials(i) = exMaterials(i).Material3D
            Materials(i).Ambient = Materials(i).Diffuse
        Next i
    End Sub
 

Attachments

The same 'seethrough' effect happens to all mesh files that I have tried to load. All from the DirectX SDK; however, the one above shows the best representation of the problem I am having.
 
I figured out the problem, it was Z-Buffering. Resolution:

Visual Basic:
        'Add to present params these lines....
        PresentParams.EnableAutoDepthStencil = True
        PresentParams.AutoDepthStencilFormat = DepthFormat.D16

You need to use ClearFlags.zbuffer in your Device.Clear(). Does anyone know how to pass multiple flags to a function? Right now what I use works, but I think could be much more effecient.

Visual Basic:
            Direct3DDevice.Clear(ClearFlags.ZBuffer, Color.Blue, 1.0F, 0)
            Direct3DDevice.Clear(ClearFlags.Target, Color.Blue, 1.0F, 0)
            'I tried 
            Direct3DDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Blue, 1.0F, 0)
            'This gives a snytax error about no function matches these parameters

Any ideas about that would be great.
 
Visual Basic:
'Try
            Direct3DDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Blue, 1.0F, 0)
'The C#/C++ | operator is just a binary OR operator. The "Or" keywords doubles 
'as a logical and binary OR operator in VB.
 
Back
Top