How do I save mesh to .x file
How do I save mesh to .x file
How do I save mesh to .x file
How do I save mesh to .x file
How do I save mesh to .x file
How do I save mesh to .x file How do I save mesh to .x file How do I save mesh to .x file How do I save mesh to .x file How do I save mesh to .x file How do I save mesh to .x file How do I save mesh to .x file How do I save mesh to .x file
How do I save mesh to .x file How do I save mesh to .x file
How do I save mesh to .x file
Go Back  Xtreme Visual Basic Talk > > > > How do I save mesh to .x file


Reply
 
Thread Tools Display Modes
  #1  
Old 02-26-2005, 09:52 AM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Default How do I save mesh to .x file


Some one help me. This is driving me nuts , I just cannot figure how to save a preloaded mesh with dx 9 and vb .net......
this is about what I have tried


Dim Adjacency() As Integer
Dim materials As ExtendedMaterial() = Nothing
Player1.GenerateAdjacency(0, Adjacency)
FileName = "C:\GameVB\X Models\junk.x"
Player1.Save(FileName, Adjacency, materials, XFileFormat.Text)

I am assuming that there is a lot more to it than this so if any one can fill in the blanks please do.
Reply With Quote
  #2  
Old 02-27-2005, 08:18 PM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Cool I did it

undefinedundefined
I did it ! I did it !!!



I found the Way to properly load and Save .x files check this out

'first set your global variables

Private MeshMaterials() As Material
Private MeshTextures() As Texture
Private ExMaterials As ExtendedMaterial() = Nothing
'the meshes
Public AraMesh As mesh



Code:
   Public Sub LoadLogo()
        Dim i As Integer = 0
        MeshTextures = Nothing
        MeshMaterials = Nothing
        AraMesh = Nothing
     
        ' Turn on the zbuffer
        Device.RenderState.ZBufferEnable = True

        ' Turn on ambient lighting 
        Device.RenderState.Ambient = System.Drawing.Color.White
        ' Load the mesh from the specified file

        'get selected file name and save it to string
        Dim FileName As String = "C:\localHardDrive\somefolder\somemesh.x"
        AraMesh = Mesh.FromFile(FileName, MeshFlags.SystemMemory, Device, ExMaterials)

        ' Set the directory up two to load the right data (since the default build location is bin\debug or bin\release
        Directory.SetCurrentDirectory(Application.StartupPath + "\..\textures")

        If MeshTextures Is Nothing Then
            ' We need to extract the material properties and texture names 
            MeshTextures = New Texture(ExMaterials.Length) {}
            MeshMaterials = New Direct3D.Material(ExMaterials.Length) {}
           try
                For i = 0 To ExMaterials.Length - 1
                    MeshMaterials(i) = ExMaterials(i).Material3D
                    ' Set the ambient color for the material (D3DX does not do this)
                    MeshMaterials(i).Ambient = MeshMaterials(i).Diffuse
                    ' Create the texture
                    MeshTextures(i) = TextureLoader.FromFile(Device, ExMaterials(i).TextureFilename)
                    '    MeshTextures(i) = TextureLoader.FromFile(Device, ExMaterials(i).TextureFilename)

                Next i
         catch
                MessageBox.Show("Error loading textures click ok to add textures.   " & "Add this image to directory: " & ExMaterials(i).TextureFilename, "Error 01", MessageBoxButtons.OKCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) Then
                    
            End Try

        End If
    End Sub
ok that is the way to load an .x file now for the saving part

' first make an save file dialog object

dim SFD as new SaveFileDialog

Code:
 Public Sub SaveToX()
        Dim FileName As String
      'set up the dialog to have a .x extension
        With SFD
            .RestoreDirectory = True
            .OverwritePrompt = True
            .Filter = "X files(*.x)|*.x"
                .InitialDirectory = Reader.ReadToEnd
                .InitialDirectory = Application.StartupPath
            .Title = "Save Mesh"
            .DefaultExt = ".x"
        End With
     
        If SFD.ShowDialog = DialogResult.OK Then
            FileName = SFD.FileName
        Else
            Exit Sub
        End If
        Dim Adjacency(AraMesh.NumberFaces * 3) As Integer
        AraMesh.GenerateAdjacency(0, Adjacency)
        AraMesh.Save(FileName, Adjacency, ExMaterials, XFileFormat.Text)
    End Sub
the important thing to remember here is to generate the adjancency else the mesh will not save
as well make sure the extended materials variable you use is the same one you used to load the mesh or if you modified the mesh and added textures to it you need to extract your mesh's material to an extendedmaterial variable that part I am not sure how to do though

so there you have it I hope this code works for you if you have any problems or comments feel free to post them

later
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
How do I save mesh to .x file
How do I save mesh to .x file
How do I save mesh to .x file How do I save mesh to .x file
How do I save mesh to .x file
How do I save mesh to .x file
How do I save mesh to .x file How do I save mesh to .x file How do I save mesh to .x file How do I save mesh to .x file How do I save mesh to .x file How do I save mesh to .x file How do I save mesh to .x file
How do I save mesh to .x file
How do I save mesh to .x file
 
How do I save mesh to .x file
How do I save mesh to .x file
 
-->