Dim MasterMesh As Mesh Dim MMMtrls() As Material Dim MMTxtrs() As Texture |
MasterMesh = Mesh.FromFile(Application.StartupPath & "\tree.x", MeshFlags.SoftwareProcessing, D9) 'You can use the one above if you have a material and texture that you will be supplying to the mesh. 'However, the material and texture can be included within the .x file. |
Dim Ems() As ExtendedMaterial, LV As Integer 'Merely holds a material and a filename for a texture. MasterMesh = Mesh.FromFile("C:\tree.x", MeshFlags.Managed, D9, Ems) 'Loads the mesh from file. .x data goes into the Extended Material array. |
'The number of entries corresponds to the number of materials and textures. MMMtrls = New Material(Ems.GetUpperBound(0)) {} MMTxtrs = New Texture(Ems.GetUpperBound(0)) {} For LV = 0 To Ems.GetUpperBound(0) MMMtrls(LV) = Ems(LV).Material3D 'Set the material. 3D means DX3D. MMMtrls(LV).Ambient = MMMtrls(LV).Diffuse 'Ambient property is lost within the loader or in the .x file. 'But anyway, this property must be set in VB, otherwise your textures will be black when unlit. MMTxtrs(LV) = TextureLoader.FromFile(D9, Ems(LV).TextureFilename) Next 'All of this information will be used when drawing the mesh. |
For LV = 0 To MMMtrls.GetUpperBound(0) D9.Material = MMMtrls(LV) 'Set the appropriate material for this subset. D9.SetTexture(0, MMTxtrs(LV)) 'And the appropriate texture. 'Then draw the mesh subset. MasterMesh.DrawSubset(LV) Next |