+2 New functions, Directx / image to OgreMesh converter

Share your advanced PureBasic knowledge/code with the community.
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

+2 New functions, Directx / image to OgreMesh converter

Post by mpz »

Hi,

Here are two Sourcecodes and a program link. The first code shows a program to konvert directx meshs to a PB Sourcecode with creating of a Ogre mesh "on the fly". The second code is the created source code as example. I use a alpha version of my mp_directx library.

Update: Now with Textur and Color support

have fun,
Michael

Donwload DirectXtoMeshKonverter01.exe
http://rapidshare.de/files/41010848/Dir ... 1.exe.html

DirectXtoMeshKonverter.exe

Code: Select all

;////////////////////////////////////////////////////////////////
;//
;// Project Title: MP 3D Engine
;// File Title: DirectXtoMeshKonverter.pb
;// Created On: 28.10.2008
;// Updated On: 
;// Author: Michael Paulwitz
;// OS:Windows
;// Ver: 1.01
;// Used with my Alphaversion of MP_Directx9 library
;// based on Steven "Dreglor" Garcias DX9 files
;// konvertiert/convert x,y,z,nx,ny,nz,col,u,v, Textur
;////////////////////////////////////////////////////////////////

Procedure.s NullTrim(String.s)
  ; Cut all "0" from end of the string
  ; Schneidet alle Nullen vom Ende des Strings weg.
  While Right(String,1) = "0" 
     String = Left(string,Len(string)-1)
  Wend 
  If Right(String,1) = "." 
     String = Left(string,Len(string)-1)
  EndIf
  ProcedureReturn String
EndProcedure

;- Init 

If MP_Graphics3D (640,480,0,3); Create 3D Fenster/Windows

  If CreateMenu(0, WindowID(0)) ; Menü erstellen/Create Menu 
    MenuTitle("&Datei/File") 
      MenuItem( 1, "&Lade/Load DirectX Mesh") 
      MenuBar() 
      MenuItem( 2, "&Ende/End") 
    MenuTitle("&Ogre Mesh speichern/save") 
      MenuItem(3, "Speicher/Save Mesh Sourcecode") 
    MenuTitle("&Hilfe/Help") 
      MenuItem(4, "Über/About 3D to Mesh") 
  EndIf 

Else 

  End ; Kann Fenster nicht erstellen/Cant Create Windows

EndIf 

camera=MP_CreateCamera() ; Kamera erstellen / Create Camera
light=MP_CreateLight(1,1,1,1) ; Es werde Licht / Light on

mesh1 = MP_CreateCube() ; Würfel erstelln / Cretae Cube

Textur = MP_CreateTextureFromFileInMemory (?Logo,?Logo-?Endlogo) ; Include Grafikdatei wird Texture / Include Grafik to Texture 

MP_EntityTexture(mesh1, Textur) ; Texture auf Mesh1 ; Texture go to Mesh1

MP_Alpha(Textur,2) ; Texture get Alphamode 2 

scale.f = 3 
MP_EntityScaling (mesh1,scale,scale,scale) ; Auf Bildschirm maximieren / maximum to Screen

x.f=0 : y.f=0 : z.f=6 ; Mesh Koordinaten 

While Not MP_KeyDown(#PB_Key_Escape) ; Esc abfrage / SC pushed?

 Select MP_WindowEvent()  ; WindowsEvent abfrage 
      Case #PB_Event_Menu 
        Select EventMenu()  ; Welches Menü? / Menuquestion 

          Case 1 ; 3D Objekt als Directx File laden /  
              Pattern$ = "Direct x Files(*.x)|*.x" 
              directory$ = "C:\Programme\PureBasic\media\" 
              File.s = OpenFileRequester("Lade Directx Datei / Load Direct x File!", directory$, Pattern$,  0) 
              If File 
                  If mesh1:mp_freeentity(mesh1):EndIf ; Altes Mesh löschen / Free old Mesh
                  mesh1=MP_LoadMesh(File.s)            ; Neues Mesh laden  / Load new Mesh
                  TextureMesh.l = MP_GetEntityTexture (mesh1) ; Textur des geladen Mesh finden / Find Mesh Texture 
                  Texturname.s = MP_GetTextureName (TextureMesh) ; Name der Textur / Name of Texture 
              EndIf
              max.f = MP_MeshHeight(mesh1) ; find Maximum of Mesh
             
              If MP_MeshWidth(mesh1) > max
                max = MP_MeshWidth(mesh1) 
              EndIf

              If MP_Meshdepth(mesh1) > max
                max = MP_Meshdepth(mesh1) 
              EndIf

              scale.f = 3 / max ; 

              MP_EntityScaling (mesh1,scale,scale,scale) ; Auf Bildschirm maximieren / maximum to Screen
          Case 2 ; Ende 
             End 
          Case 3 ; Ogre Mesh erzeugen / Create Ogre Mesh 
              File.s = SaveFileRequester("Speicher/Save Ogre Mesh Code", "Ogremesh.pb", "OgreMesh Files(*.pb)|*.pb",  0) 

              If CreateFile(1, File.s) ; Erstelle/Create Code
                  Restore StringData
                  Repeat
                    Read.s Purestring.s 
                    WriteStringN(1, Purestring)
                  Until Purestring.s  = "End"

                  WriteStringN(1, "" )         
                  WriteStringN(1, "DataSection" )
                  WriteStringN(1, "   StringSect:")
                  WriteStringN(1, "      Data.s "+Chr(34)+Texturname+Chr(34))
                  WriteStringN(1, "")               
                  WriteStringN(1, "   NumericalData:")
                  WriteStringN(1, "   Data.l "+Str(MP_CountVertices(Mesh1))+","+Str(MP_CountTriangles(Mesh1))) ; Zähle/Count Vertices und/and Triangle
                  WriteStringN(1, "")
                  WriteStringN(1, "   Vertice:  ;x,y,z,nx,ny,nz,col,u,v = Vertex + Normal + Col + UV Koordinaten" )
                  For n =  0 To MP_CountVertices(Mesh1)-1
                    vx.s =  NullTrim(StrF(MP_VertexX (Mesh1, n)))
                    vy.s =  NullTrim(StrF(MP_VertexY (Mesh1, n)))
                    vz.s =  NullTrim(StrF(MP_VertexZ (Mesh1, n)))
                    nx.s =  NullTrim(StrF(MP_VertexNX(Mesh1, n)))
                    ny.s =  NullTrim(StrF(MP_VertexNY(Mesh1, n)))
                    nz.s =  NullTrim(StrF(MP_VertexNZ(Mesh1, n)))
                   Col.s =  NullTrim(StrF(MP_VertexColor(Mesh1, n)))
                     u.s =  NullTrim(StrF(-1*MP_VertexU (Mesh1, n))) ; Koordinaten vertauscht für Textur/Wrong UV Coords INTO Ogre so i change them
                     v.s =  NullTrim(StrF(MP_VertexV (Mesh1, n)))
                     WriteStringN(1, "   Data.f "+vx+","+vy+","+vz+","+nx+","+ny+","+nz+","+col+","+u+","+v )
                     SetWindowTitle(0, "Write: "+Str(n)+"/"+Str(MP_CountVertices(Mesh1)-1)+" Vertices") 
                  Next
                  WriteStringN(1, "")
                  WriteStringN(1, "   Triangle: ; Vertice x,y,z verbinden/Create Triangle" )
                  For n =  1 To MP_CountTriangles(Mesh1)
                      corner_0 = MP_TriangleVertex(Mesh1,n, 0) ;
                      corner_1 = MP_TriangleVertex(Mesh1,n, 1) ;
                      corner_2 = MP_TriangleVertex(Mesh1,n, 2) ;
                      WriteStringN(1, "   Data.w "+Str(corner_2)+","+Str(corner_0)+","+Str(corner_1) )
                      SetWindowTitle(0, "Write: "+Str(n)+"/"+Str(MP_CountTriangles(Mesh1))+" Triangle") 
                  Next
                  WriteStringN(1, "EndDataSection")
                  CloseFile(1)
                  MessageRequester("Info", "Ogre Mesh Code erzeugt/created", 0)
                  SetWindowTitle(0, "Ready") 

              Else
                  MessageRequester("Error", "Kann die Datei nicht schreiben/Can't write file", 0)
              EndIf
               
          Case 4 ; Über 
             info.s = "DirectXtoMeshKonverter"+Chr(10)+Chr(10) 
             info.s = info.s + "Mit diesem Programm kann man aus direct x Dateien"+Chr(10) 
             info.s = info.s + "Purebasic Mesh Dateien erzeugen"+Chr(10)+Chr(10)
             info.s = info.s + "With this program you can create PB Meshcode from direct x files"+Chr(10) +Chr(10)
             info.s = info.s + "Bewege/Move Mesh mit/with Cursor Tasten/Keys"+Chr(10) +Chr(10)
             info.s = info.s + "(c) Michael Paulwitz tested with PB 4.3 Beta4 "+Chr(10) 
             MessageRequester("Info", info.s, 0) 
         EndSelect 
      Case #PB_Event_CloseWindow 
         End 
EndSelect 

 ; nen bishen apielen und das Objekt drehen 
 If MP_KeyDown(#PB_Key_Left)=1 : x=x-1 : EndIf ;links Debug #PB_Key_Left 
 If MP_KeyDown(#PB_Key_Right)=1 : x=x+1 : EndIf ;rechts #PB_Key_Right 
 If MP_KeyDown(#PB_Key_Down)=1 : y=y-1 : EndIf ;Runter #PB_Key_Down 
 If MP_KeyDown(#PB_Key_Up)=1 : y=y+1 : EndIf ;rauf #PB_Key_Up 
 If MP_KeyDown(#PB_Key_Z)=1  : z=z+0.1 : EndIf ;y Vertauscht bei y-z bei deutscher tastatur 
 If MP_KeyDown(#PB_Key_A)=1  : z=z-0.1 : EndIf ;a #PB_Key_A 

 If mesh1 ; Objekt drehen
    MP_DrawText (2,2,RGB(255,255,255),"Triangles: "+Str(MP_CountTriangles(Mesh1))+"  Vertices: "+Str(MP_CountVertices(Mesh1))) 
    MP_PositionEntity (Mesh1,0,0,z) 
    MP_RotateEntity (Mesh1,x,y,0) 
 EndIf 

    MP_RenderWorld () 
    MP_Flip () 
Wend 
End

DataSection

StringData:
Data.s "#Mesh = 0" 
Data.s "If InitEngine3D() And InitSprite() And InitKeyboard()" 
Data.s "  OpenWindow(0,0,0,640,480,"+Chr(34)+"3D Mesh TEST  - Key A and Y/Z bewegt/move Mesh"+Chr(34)+",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)" 
Data.s "  OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,0)" 
Data.s " "
Data.s "    Restore NumericalData"
Data.s "    Read.l Vert"
Data.s "    Read.l Tria"
Data.s " "
Data.s "    CreateMesh(#Mesh, vert)"
Data.s " "    
Data.s "    SetMeshData(#Mesh, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_Color  | #PB_Mesh_UVCoordinate, ?Vertice, Vert);3)"
Data.s "    SetMeshData(#Mesh, #PB_Mesh_Face, ?Triangle, Tria); 1)"
Data.s " "
Data.s "    Restore StringSect"
Data.s "    Read.s Texturname.s" 
Data.s "    Add3DArchive("+Chr(34)+"."+Chr(34)+", #PB_3DArchive_FileSystem) ; Textur in Ordner / Add folder" 
Data.s "    if FileSize(Texturname) <> -1"
Data.s "        CreateEntity(#Mesh, MeshID(0), CreateMaterial(0, LoadTexture(0, Texturname.s)))" 
Data.s "        CreateLight(0, RGB(255,255,255), 100.0, 0, 0)   ; White Light"
Data.s "    Else"
Data.s "        CreateEntity(#Mesh, MeshID(0),#PB_Material_None)"
Data.s "        CreateLight(0, RGB(0,0,255), 100.0, 0, 0)   ; Blue Light"
Data.s "        CreateLight(1, RGB(255,0,0), -100.0, 0, 0)  ; Red Light"
Data.s "        CreateLight(2, RGB(255,255,0), 0.0, 100, 0)   ; Yellow Light"
Data.s "    Endif"
Data.s " "
Data.s "    CreateCamera(0, 0, 0, 100, 100)"
Data.s "    z+40"
Data.s "    CameraLocate(0,0,0,z)"
Data.s " "
Data.s "    Repeat"
Data.s "      ExamineKeyboard()"
Data.s "      Select WindowEvent()" 
Data.s "        Case #PB_Event_CloseWindow" 
Data.s "          Quit = #True"
Data.s "      EndSelect"
Data.s " "
Data.s "      If KeyboardPushed(#PB_Key_A) ; Key A = Zoom +"
Data.s "         z-1"
Data.s "         CameraLocate(0,0,0,z)" 
Data.s "      EndIf"
Data.s " "
Data.s "      If KeyboardPushed(#PB_Key_Z) ; Key Z = Zoom +"
Data.s "         z+1"
Data.s "         CameraLocate(0,0,0,z)"
Data.s "      EndIf"
Data.s " "
Data.s "      If KeyboardPushed(#PB_Key_Y) ; Key Y = Zoom +"
Data.s "         z+1"
Data.s "         CameraLocate(0,0,0,z)"
Data.s "      EndIf"
Data.s " "
Data.s "      RotateEntity(#Mesh, 1, 1, 1, #PB_Relative)"
Data.s " "
Data.s "      ClearScreen(RGB(0,0,0))"
Data.s "      RenderWorld()"
Data.s "      FlipBuffers()"
Data.s " "  
Data.s "    Until KeyboardPushed(#PB_Key_Escape) Or Quit"
Data.s "Else"
Data.s "  MessageRequester("+Chr(34)+"Error"+Chr(34)+", "+Chr(34)+"Cant init DirectX 3D Engine"+Chr(34)+",0)"
Data.s "EndIf"
Data.s " "  
Data.s "End" 

Logo: IncludeBinary "c:\alphabox.tga" ; My Grafikfile
endlogo:

Example works with PB 4.30 Beta4

Code: Select all


#Mesh = 0
If InitEngine3D() And InitSprite() And InitKeyboard()
  OpenWindow(0,0,0,640,480,"3D Mesh TEST  - Key A and Y/Z bewegt/move Mesh",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,0)
 
    Restore NumericalData
    Read.l Vert
    Read.l Tria
 
    CreateMesh(#Mesh, vert)
 
    SetMeshData(#Mesh, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_Color  | #PB_Mesh_UVCoordinate, ?Vertice, Vert);3)
    SetMeshData(#Mesh, #PB_Mesh_Face, ?Triangle, Tria); 1)
 
    Restore StringSect
    Read.s Texturname.s
    Add3DArchive(".", #PB_3DArchive_FileSystem) ; Textur in Ordner / Add folder
    If FileSize(Texturname) <> -1
        CreateEntity(#Mesh, MeshID(0), CreateMaterial(0, LoadTexture(0, Texturname.s)))
        CreateLight(0, RGB(255,255,255), 100.0, 0, 0)   ; White Light
    Else
        CreateEntity(#Mesh, MeshID(0),#PB_Material_None)
        CreateLight(0, RGB(0,0,255), 100.0, 0, 0)   ; Blue Light
        CreateLight(1, RGB(255,0,0), -100.0, 0, 0)  ; Red Light
        CreateLight(2, RGB(255,255,0), 0.0, 100, 0)   ; Yellow Light
    EndIf
 
    CreateCamera(0, 0, 0, 100, 100)
    z+40
    CameraLocate(0,0,0,z)
 
    Repeat
      ExamineKeyboard()
      Select WindowEvent()
        Case #PB_Event_CloseWindow
          Quit = #True
      EndSelect
 
      If KeyboardPushed(#PB_Key_A) ; Key A = Zoom +
         z-1
         CameraLocate(0,0,0,z)
      EndIf
 
      If KeyboardPushed(#PB_Key_Z) ; Key Z = Zoom +
         z+1
         CameraLocate(0,0,0,z)
      EndIf
 
      If KeyboardPushed(#PB_Key_Y) ; Key Y = Zoom +
         z+1
         CameraLocate(0,0,0,z)
      EndIf
 
      RotateEntity(#Mesh, 1, 1, 1, #PB_Relative)
 
      ClearScreen(RGB(0,0,0))
      RenderWorld()
      FlipBuffers()
 
    Until KeyboardPushed(#PB_Key_Escape) Or Quit
Else
  MessageRequester("Error", "Cant init DirectX 3D Engine",0)
EndIf
 
End

DataSection
   StringSect:
      Data.s "rockwall.bmp"

   NumericalData:
   Data.l 148,144

   Vertice:  ;x,y,z,nx,ny,nz,col,u,v = Vertex + Normal + Col + UV Koordinaten
   Data.f 0.006191,0,5.186832,0,0,1,0,-1,0.9995
   Data.f 0.006191,1.163303,5.186832,0,0,1,0,-1,0.000499
   Data.f 0.006191,1.163303,3.892398,0,1,0,0,-0.126757,0.5
   Data.f 0.006191,0,3.892398,-0,0,-1,0,-1,0.9995
   Data.f 1.757687,0,4.877996,0.34202,0,0.939693,0,-0.944444,0.9995
   Data.f 1.757687,1.163303,4.877996,0.34202,0,0.939693,0,-0.944444,0.000499
   Data.f 1.314964,1.163303,3.661626,0,1,0,0,-0.149267,0.372343
   Data.f 1.314964,0,3.661626,-0.34202,0,-0.939693,0,-0.944444,0.9995
   Data.f 3.297926,0,3.988738,0.642788,0,0.766044,0,-0.888889,0.9995
   Data.f 3.297926,1.163303,3.988738,0.642788,0,0.766044,0,-0.888889,0.000499
   Data.f 2.46588,1.163303,2.997144,0,1,0,0,-0.21408,0.260084
   Data.f 2.46588,0,2.997144,-0.642788,0,-0.766044,0,-0.888889,0.9995
   Data.f 4.441134,0,2.626317,0.866025,0,0.5,0,-0.833333,0.9995
   Data.f 4.441134,1.163303,2.626317,0.866025,0,0.5,0,-0.833333,0.000499
   Data.f 3.320121,1.163303,1.9791,0,1,0,0,-0.313379,0.176762
   Data.f 3.320121,0,1.9791,-0.866025,0,-0.5,0,-0.833333,0.9995
   Data.f 5.049422,0,0.955059,0.984808,0,0.173648,0,-0.777778,0.9995
   Data.f 5.049422,1.163303,0.955059,0.984808,0,0.173648,0,-0.777778,0.000499
   Data.f 3.774653,1.163303,0.730283,0,1,0,0,-0.435187,0.132428
   Data.f 3.774653,0,0.730283,-0.984808,0,-0.173648,0,-0.777778,0.9995
   Data.f 5.049422,0,-0.823457,0.984808,0,-0.173648,0,-0.722222,0.9995
   Data.f 5.049422,1.163303,-0.823457,0.984808,0,-0.173648,0,-0.722222,0.000499
   Data.f 3.774653,1.163303,-0.59868,0,1,0,0,-0.564813,0.132428
   Data.f 3.774653,0,-0.59868,-0.984808,0,0.173648,0,-0.722222,0.9995
   Data.f 4.441134,0,-2.494714,0.866025,0,-0.5,0,-0.666667,0.9995
   Data.f 4.441134,1.163303,-2.494714,0.866025,0,-0.5,0,-0.666667,0.000499
   Data.f 3.320121,1.163303,-1.847497,0,1,0,0,-0.686621,0.176762
   Data.f 3.320121,0,-1.847497,-0.866025,0,0.5,0,-0.666667,0.9995
   Data.f 3.297926,0,-3.857136,0.642788,0,-0.766045,0,-0.611111,0.9995
   Data.f 3.297926,1.163303,-3.857136,0.642788,0,-0.766045,0,-0.611111,0.000499
   Data.f 2.465879,1.163303,-2.865542,0,1,0,0,-0.785921,0.260084
   Data.f 2.465879,0,-2.865542,-0.642788,0,0.766045,0,-0.611111,0.9995
   Data.f 1.757686,0,-4.746393,0.34202,0,-0.939693,0,-0.555556,0.9995
   Data.f 1.757686,1.163303,-4.746393,0.34202,0,-0.939693,0,-0.555556,0.000499
   Data.f 1.314964,1.163303,-3.530023,0,1,0,0,-0.850733,0.372344
   Data.f 1.314964,0,-3.530023,-0.34202,0,0.939693,0,-0.555556,0.9995
   Data.f 0.006191,0,-5.055229,-0,0,-1,0,-0.5,0.9995
   Data.f 0.006191,1.163303,-5.055229,-0,0,-1,0,-0.5,0.000499
   Data.f 0.006191,1.163303,-3.760795,0,1,0,0,-0.873243,0.5
   Data.f 0.006191,0,-3.760795,0,0,1,0,-0.5,0.9995
   Data.f -1.745305,0,-4.746393,-0.34202,0,-0.939693,0,-0.444444,0.9995
   Data.f -1.745305,1.163303,-4.746393,-0.34202,0,-0.939693,0,-0.444444,0.000499
   Data.f -1.302582,1.163303,-3.530023,0,1,0,0,-0.850733,0.627657
   Data.f -1.302582,0,-3.530023,0.34202,0,0.939693,0,-0.444444,0.9995
   Data.f -3.285544,0,-3.857135,-0.642788,0,-0.766044,0,-0.388889,0.9995
   Data.f -3.285544,1.163303,-3.857135,-0.642788,0,-0.766044,0,-0.388889,0.000499
   Data.f -2.453498,1.163303,-2.865541,0,1,0,0,-0.78592,0.739916
   Data.f -2.453498,0,-2.865541,0.642788,0,0.766044,0,-0.388889,0.9995
   Data.f -4.428752,0,-2.494713,-0.866026,0,-0.5,0,-0.333333,0.9995
   Data.f -4.428752,1.163303,-2.494713,-0.866025,0,-0.5,0,-0.333333,0.000499
   Data.f -3.307739,1.163303,-1.847496,0,1,0,0,-0.686621,0.823238
   Data.f -3.307739,0,-1.847496,0.866026,0,0.5,0,-0.333333,0.9995
   Data.f -5.03704,0,-0.823455,-0.984808,0,-0.173648,0,-0.277778,0.9995
   Data.f -5.03704,1.163303,-0.823455,-0.984808,0,-0.173648,0,-0.277778,0.000499
   Data.f -3.76227,1.163303,-0.598679,0,1,0,0,-0.564813,0.867572
   Data.f -3.76227,0,-0.598679,0.984808,0,0.173648,0,-0.277778,0.9995
   Data.f -5.037039,0,0.95506,-0.984808,0,0.173648,0,-0.222222,0.9995
   Data.f -5.037039,1.163303,0.95506,-0.984808,0,0.173648,0,-0.222222,0.000499
   Data.f -3.76227,1.163303,0.730284,0,1,0,0,-0.435187,0.867572
   Data.f -3.76227,0,0.730284,0.984808,0,-0.173648,0,-0.222222,0.9995
   Data.f -4.428751,0,2.626318,-0.866025,0,0.5,0,-0.166667,0.9995
   Data.f -4.428751,1.163303,2.626318,-0.866025,0,0.5,0,-0.166667,0.000499
   Data.f -3.307738,1.163303,1.9791,0,1,0,0,-0.313379,0.823237
   Data.f -3.307738,0,1.9791,0.866025,0,-0.5,0,-0.166667,0.9995
   Data.f -3.285543,0,3.988739,-0.642787,0,0.766045,0,-0.111111,0.9995
   Data.f -3.285543,1.163303,3.988739,-0.642787,0,0.766045,0,-0.111111,0.000499
   Data.f -2.453497,1.163303,2.997145,0,1,0,0,-0.214079,0.739916
   Data.f -2.453497,0,2.997145,0.642787,0,-0.766045,0,-0.111111,0.9995
   Data.f -1.745303,0,4.877996,-0.34202,0,0.939693,0,-0.055555,0.9995
   Data.f -1.745303,1.163303,4.877996,-0.34202,0,0.939693,0,-0.055555,0.000499
   Data.f -1.302581,1.163303,3.661626,0,1,0,0,-0.149267,0.627656
   Data.f -1.302581,0,3.661626,0.34202,0,-0.939693,0,-0.055555,0.9995
   Data.f 0.006191,1.163303,5.186832,0,1,0,0,-0.0005,0.5
   Data.f 1.757687,1.163303,4.877996,0,1,0,0,-0.030623,0.329161
   Data.f 0.006191,1.163303,3.892398,-0,0,-1,0,-1,0.000499
   Data.f 1.314964,1.163303,3.661626,-0.34202,0,-0.939693,0,-0.944444,0.000499
   Data.f 0.006191,0,3.892398,0,-1,0,0,-0.126757,0.5
   Data.f 1.314964,0,3.661626,0,-1,0,0,-0.149267,0.372343
   Data.f 1.757687,0,4.877996,0,-1,0,0,-0.030623,0.329161
   Data.f 0.006191,0,5.186832,0,-1,0,0,-0.0005,0.5
   Data.f 3.297926,1.163303,3.988738,0,1,0,0,-0.117361,0.178927
   Data.f 2.46588,1.163303,2.997144,-0.642788,0,-0.766044,0,-0.888889,0.000499
   Data.f 2.46588,0,2.997144,0,-1,0,0,-0.21408,0.260084
   Data.f 3.297926,0,3.988738,0,-1,0,0,-0.117361,0.178927
   Data.f 4.441134,1.163303,2.626317,0,1,0,0,-0.25025,0.06742
   Data.f 3.320121,1.163303,1.9791,-0.866025,0,-0.5,0,-0.833333,0.000499
   Data.f 3.320121,0,1.9791,0,-1,0,0,-0.313379,0.176762
   Data.f 4.441134,0,2.626317,0,-1,0,0,-0.25025,0.06742
   Data.f 5.049422,1.163303,0.955059,0,1,0,0,-0.413263,0.008088
   Data.f 3.774653,1.163303,0.730283,-0.984808,0,-0.173648,0,-0.777778,0.000499
   Data.f 3.774653,0,0.730283,0,-1,0,0,-0.435187,0.132428
   Data.f 5.049422,0,0.955059,0,-1,0,0,-0.413263,0.008088
   Data.f 5.049422,1.163303,-0.823457,0,1,0,0,-0.586737,0.008088
   Data.f 3.774653,1.163303,-0.59868,-0.984808,0,0.173648,0,-0.722222,0.000499
   Data.f 3.774653,0,-0.59868,0,-1,0,0,-0.564813,0.132428
   Data.f 5.049422,0,-0.823457,0,-1,0,0,-0.586737,0.008088
   Data.f 4.441134,1.163303,-2.494714,0,1,0,0,-0.74975,0.06742
   Data.f 3.320121,1.163303,-1.847497,-0.866025,0,0.5,0,-0.666667,0.000499
   Data.f 3.320121,0,-1.847497,0,-1,0,0,-0.686621,0.176762
   Data.f 4.441134,0,-2.494714,0,-1,0,0,-0.74975,0.06742
   Data.f 3.297926,1.163303,-3.857136,0,1,0,0,-0.88264,0.178927
   Data.f 2.465879,1.163303,-2.865542,-0.642788,0,0.766045,0,-0.611111,0.000499
   Data.f 2.465879,0,-2.865542,0,-1,0,0,-0.785921,0.260084
   Data.f 3.297926,0,-3.857136,0,-1,0,0,-0.88264,0.178927
   Data.f 1.757686,1.163303,-4.746393,0,1,0,0,-0.969377,0.329161
   Data.f 1.314964,1.163303,-3.530023,-0.34202,0,0.939693,0,-0.555556,0.000499
   Data.f 1.314964,0,-3.530023,0,-1,0,0,-0.850733,0.372344
   Data.f 1.757686,0,-4.746393,0,-1,0,0,-0.969377,0.329161
   Data.f 0.006191,1.163303,-5.055229,0,1,0,0,-0.9995,0.5
   Data.f 0.006191,1.163303,-3.760795,0,0,1,0,-0.5,0.000499
   Data.f 0.006191,0,-3.760795,0,-1,0,0,-0.873243,0.5
   Data.f 0.006191,0,-5.055229,0,-1,0,0,-0.9995,0.5
   Data.f -1.745305,1.163303,-4.746393,0,1,0,0,-0.969377,0.670839
   Data.f -1.302582,1.163303,-3.530023,0.34202,0,0.939693,0,-0.444444,0.000499
   Data.f -1.302582,0,-3.530023,0,-1,0,0,-0.850733,0.627657
   Data.f -1.745305,0,-4.746393,0,-1,0,0,-0.969377,0.670839
   Data.f -3.285544,1.163303,-3.857135,0,1,0,0,-0.882639,0.821073
   Data.f -2.453498,1.163303,-2.865541,0.642788,0,0.766044,0,-0.388889,0.000499
   Data.f -2.453498,0,-2.865541,0,-1,0,0,-0.78592,0.739916
   Data.f -3.285544,0,-3.857135,0,-1,0,0,-0.882639,0.821073
   Data.f -4.428752,1.163303,-2.494713,0,1,0,0,-0.74975,0.93258
   Data.f -3.307739,1.163303,-1.847496,0.866026,0,0.5,0,-0.333333,0.000499
   Data.f -3.307739,0,-1.847496,0,-1,0,0,-0.686621,0.823238
   Data.f -4.428752,0,-2.494713,0,-1,0,0,-0.74975,0.93258
   Data.f -5.03704,1.163303,-0.823455,0,1,0,0,-0.586737,0.991912
   Data.f -3.76227,1.163303,-0.598679,0.984808,0,0.173648,0,-0.277778,0.000499
   Data.f -3.76227,0,-0.598679,0,-1,0,0,-0.564813,0.867572
   Data.f -5.03704,0,-0.823455,0,-1,0,0,-0.586737,0.991912
   Data.f -5.037039,1.163303,0.95506,0,1,0,0,-0.413262,0.991912
   Data.f -3.76227,1.163303,0.730284,0.984808,0,-0.173648,0,-0.222222,0.000499
   Data.f -3.76227,0,0.730284,0,-1,0,0,-0.435187,0.867572
   Data.f -5.037039,0,0.95506,0,-1,0,0,-0.413262,0.991912
   Data.f -4.428751,1.163303,2.626318,0,1,0,0,-0.25025,0.93258
   Data.f -3.307738,1.163303,1.9791,0.866025,0,-0.5,0,-0.166667,0.000499
   Data.f -3.307738,0,1.9791,0,-1,0,0,-0.313379,0.823237
   Data.f -4.428751,0,2.626318,0,-1,0,0,-0.25025,0.93258
   Data.f -3.285543,1.163303,3.988739,0,1,0,0,-0.11736,0.821072
   Data.f -2.453497,1.163303,2.997145,0.642787,0,-0.766045,0,-0.111111,0.000499
   Data.f -2.453497,0,2.997145,0,-1,0,0,-0.214079,0.739916
   Data.f -3.285543,0,3.988739,0,-1,0,0,-0.11736,0.821072
   Data.f -1.745303,1.163303,4.877996,0,1,0,0,-0.030623,0.670839
   Data.f -1.302581,1.163303,3.661626,0.34202,0,-0.939693,0,-0.055555,0.000499
   Data.f -1.302581,0,3.661626,0,-1,0,0,-0.149267,0.627656
   Data.f -1.745303,0,4.877996,0,-1,0,0,-0.030623,0.670839
   Data.f 0.006191,0,5.186832,0,0,1,0,0,0.9995
   Data.f 0.006191,1.163303,5.186832,0,0,1,0,0,0.000499
   Data.f 0.006191,1.163303,3.892398,-0,0,-1,0,0,0.000499
   Data.f 0.006191,0,3.892398,-0,0,-1,0,0,0.9995

   Triangle: ; Vertice x,y,z verbinden/Create Triangle
   Data.w 5,0,4
   Data.w 1,0,5
   Data.w 6,72,73
   Data.w 2,72,6
   Data.w 7,74,75
   Data.w 3,74,7
   Data.w 78,76,77
   Data.w 79,76,78
   Data.w 9,4,8
   Data.w 5,4,9
   Data.w 10,73,80
   Data.w 6,73,10
   Data.w 11,75,81
   Data.w 7,75,11
   Data.w 83,77,82
   Data.w 78,77,83
   Data.w 13,8,12
   Data.w 9,8,13
   Data.w 14,80,84
   Data.w 10,80,14
   Data.w 15,81,85
   Data.w 11,81,15
   Data.w 87,82,86
   Data.w 83,82,87
   Data.w 17,12,16
   Data.w 13,12,17
   Data.w 18,84,88
   Data.w 14,84,18
   Data.w 19,85,89
   Data.w 15,85,19
   Data.w 91,86,90
   Data.w 87,86,91
   Data.w 21,16,20
   Data.w 17,16,21
   Data.w 22,88,92
   Data.w 18,88,22
   Data.w 23,89,93
   Data.w 19,89,23
   Data.w 95,90,94
   Data.w 91,90,95
   Data.w 25,20,24
   Data.w 21,20,25
   Data.w 26,92,96
   Data.w 22,92,26
   Data.w 27,93,97
   Data.w 23,93,27
   Data.w 99,94,98
   Data.w 95,94,99
   Data.w 29,24,28
   Data.w 25,24,29
   Data.w 30,96,100
   Data.w 26,96,30
   Data.w 31,97,101
   Data.w 27,97,31
   Data.w 103,98,102
   Data.w 99,98,103
   Data.w 33,28,32
   Data.w 29,28,33
   Data.w 34,100,104
   Data.w 30,100,34
   Data.w 35,101,105
   Data.w 31,101,35
   Data.w 107,102,106
   Data.w 103,102,107
   Data.w 37,32,36
   Data.w 33,32,37
   Data.w 38,104,108
   Data.w 34,104,38
   Data.w 39,105,109
   Data.w 35,105,39
   Data.w 111,106,110
   Data.w 107,106,111
   Data.w 41,36,40
   Data.w 37,36,41
   Data.w 42,108,112
   Data.w 38,108,42
   Data.w 43,109,113
   Data.w 39,109,43
   Data.w 115,110,114
   Data.w 111,110,115
   Data.w 45,40,44
   Data.w 41,40,45
   Data.w 46,112,116
   Data.w 42,112,46
   Data.w 47,113,117
   Data.w 43,113,47
   Data.w 119,114,118
   Data.w 115,114,119
   Data.w 49,44,48
   Data.w 45,44,49
   Data.w 50,116,120
   Data.w 46,116,50
   Data.w 51,117,121
   Data.w 47,117,51
   Data.w 123,118,122
   Data.w 119,118,123
   Data.w 53,48,52
   Data.w 49,48,53
   Data.w 54,120,124
   Data.w 50,120,54
   Data.w 55,121,125
   Data.w 51,121,55
   Data.w 127,122,126
   Data.w 123,122,127
   Data.w 57,52,56
   Data.w 53,52,57
   Data.w 58,124,128
   Data.w 54,124,58
   Data.w 59,125,129
   Data.w 55,125,59
   Data.w 131,126,130
   Data.w 127,126,131
   Data.w 61,56,60
   Data.w 57,56,61
   Data.w 62,128,132
   Data.w 58,128,62
   Data.w 63,129,133
   Data.w 59,129,63
   Data.w 135,130,134
   Data.w 131,130,135
   Data.w 65,60,64
   Data.w 61,60,65
   Data.w 66,132,136
   Data.w 62,132,66
   Data.w 67,133,137
   Data.w 63,133,67
   Data.w 139,134,138
   Data.w 135,134,139
   Data.w 69,64,68
   Data.w 65,64,69
   Data.w 70,136,140
   Data.w 66,136,70
   Data.w 71,137,141
   Data.w 67,137,71
   Data.w 143,138,142
   Data.w 139,138,143
   Data.w 145,68,144
   Data.w 69,68,145
   Data.w 2,140,72
   Data.w 70,140,2
   Data.w 147,141,146
   Data.w 71,141,147
   Data.w 79,142,76
   Data.w 143,142,79
EndDataSection

Last edited by mpz on Fri Feb 20, 2009 12:42 pm, edited 2 times in total.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Hi,

I wanted to try out your tool. (exe)
But a messagebox was poping up, with a message like... "Couldn't start application, 'cause d3dx9_31.dll wasn't found.".
I suppose, this DLL is from DX9 SDK. Maybe you should add this DLL to your downloadpacket.

Regards

Wolf
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Try downloading the latest DirectX 9 runtime files, Hroudtwolf. If you're using Vista these are no included in DirectX 10.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Hey, thx.
Now, it works.

Regards
Wolf
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Post by mpz »

New Version,

now with image to 3D Terrain function. You can use images with Grayscale, color and Alphachannel Pictures...

http://rapidshare.de/files/44512371/Dir ... 2.exe.html

I hope somebody need this

Greetings Michael

Code: Select all

;////////////////////////////////////////////////////////////////
;//
;// Project Title: MP 3D Engine
;// File Title: DirectXtoMeshKonverter.pb
;// Created On: 28.10.2008
;// Updated On: 2.2.2009
;// Now with picture to 3D Terrain
;// Author: Michael Paulwitz
;// OS:Windows
;// Ver: 1.04
;//
;// Used with my Alphaversion of MP_Directx9 library
;// based on Steven "Dreglor" Garcias DX9 files
;// 
;// You can load direct x files and convert to PB Mesh
;// Load a picture as Highmaop and save it to PB Mesh or Direct x, use color and size 
;// Move Mes With cursor keys And a/y/z Keys 
;// 
;////////////////////////////////////////////////////////////////

Procedure.s NullTrim(String.s)
  ; Cut all "0" from end of the string
  ; Schneidet alle Nullen vom Ende des Strings weg.
  While Right(String,1) = "0" 
     String = Left(string,Len(string)-1)
  Wend 
  If Right(String,1) = "." 
     String = Left(string,Len(string)-1)
  EndIf
  ProcedureReturn String
EndProcedure

;- Init 

If MP_Graphics3D (640,480,0,3); Create 3D Fenster/Windows

  If CreateMenu(0, WindowID(0)) ; Menü erstellen/Create Menu 
    MenuTitle("&Datei/File") 
      MenuItem( 1, "&Lade/Load DirectX Mesh") 
      MenuItem( 2, "&Lade/Load Grafik File") 
      MenuBar() 
      MenuItem( 3, "&Ende/End") 
    MenuTitle("&Ogre Mesh speichern/save") 
      MenuItem(4, "Speicher/Save Ogre Mesh Sourcecode")
      MenuItem(5, "Speicher/Save Ogre Mesh only Datacode")
      MenuItem(6, "Speicher/Save Direct x")
    MenuTitle("&3D Terrain Konfig") 
      MenuItem(7, "Size 32")
      Size = 32
      SetMenuItemState(0,7,1) 
      MenuItem(8, "Size 64")
      MenuItem(9, "Size 128")
      MenuItem(10, "Size 156")
      MenuBar()
      MenuItem(11, "Benutze Rot/Use Red")
      ColUse = 2
      SetMenuItemState(0,11,1) 
      MenuItem(12, "Benutze Grün/Use Green")
      MenuItem(13, "Benutze Blau/Use Blue")
      MenuItem(14, "Benutze Alpha/Use Alpha")
      MenuBar()
      MenuItem(15, "Höhe Min/High Min")
      MenuItem(16, "Höhe Med/High Med")
      High = 15
      SetMenuItemState(0,15,1) 
      MenuItem(17, "Höhe Max/High Max")
    MenuTitle("&Hilfe/Help") 
      MenuItem(18, "Über/About 3D to Mesh") 
  EndIf 

Else 

  End ; Kann Fenster nicht erstellen/Cant Create Windows

EndIf 

camera=MP_CreateCamera() ; Kamera erstellen / Create Camera
light=MP_CreateLight(1,1,1,1) ; Es werde Licht / Light on

mesh1 = MP_CreateCube() ; Würfel erstelln / Cretae Cube

Textur = MP_CreateTextureFromFileInMemory (?Logo,?Logo-?Endlogo) ; Include Grafikdatei wird Texture / Include Grafik to Texture 

MP_EntityTexture(mesh1, Textur) ; Texture auf Mesh1 ; Texture go to Mesh1

MP_Alpha(Textur,2) ; Texture get Alphamode 2 

max.f = MP_MeshHeight(mesh1) ; find Maximum of Mesh
If MP_MeshWidth(mesh1) > max
   max = MP_MeshWidth(mesh1) 
EndIf

If MP_Meshdepth(mesh1) > max
   max = MP_Meshdepth(mesh1)
EndIf

scale.f = 3 
MP_EntityScaling (mesh1,scale,scale,scale) ; Auf Bildschirm maximieren / maximum to Screen

x.f=0 : y.f=0 : z.f=6 ; Mesh Koordinaten 

While Not MP_KeyDown(#PB_Key_Escape) ; Esc abfrage / SC pushed?

 Select MP_WindowEvent()  ; WindowsEvent abfrage 
      Case #PB_Event_Menu 
        Select EventMenu()  ; Welches Menü? / Menuquestion 

          Case 1 ; 3D Objekt als Directx File laden /  
              Pattern$ = "Direct x Files(*.x)|*.x" 
              directory$ = "C:\Programme\PureBasic\media\" 
              File.s = OpenFileRequester("Lade Directx Datei / Load Direct x File!", directory$, Pattern$,  0) 
              If File 
                  If mesh1:mp_freeentity(mesh1):EndIf ; Altes Mesh löschen / Free old Mesh
                  mesh1=MP_LoadMesh(File.s)            ; Neues Mesh laden  / Load new Mesh
                  TextureMesh.l = MP_GetEntityTexture (mesh1) ; Textur des geladen Mesh finden / Find Mesh Texture 
                  Texturname.s = MP_GetTextureName (TextureMesh) ; Name der Textur / Name of Texture
                 
                  x.f=0 : y.f=0 : z.f=6 ; Mesh Koordinaten 
                 
                  max.f = MP_MeshHeight(mesh1) ; find Maximum of Mesh
             
                  If MP_MeshWidth(mesh1) > max
                    max = MP_MeshWidth(mesh1) 
                  EndIf

                  If MP_Meshdepth(mesh1) > max
                    max = MP_Meshdepth(mesh1) 
                  EndIf

                  scale.f = 3 / max ; 

                  MP_EntityScaling (mesh1,scale,scale,scale) ; Auf Bildschirm maximieren / maximum to Screen
              EndIf
          Case 2 ; Picture als Textur laden/
              Pattern$ = "Grafikdateien |*.bmp;*.dds;*.dib;*.hdr;*.jpg;*.pfm;*.png;*.ppm;*.tga"
              directory$ = "C:\Programme\PureBasic\media\" 
              File.s = OpenFileRequester("Lade Grafik zur 3D Umwandlung/ Load Grafik to 3D converting", directory$, Pattern$, 0)
              If File 
                  If mesh1:mp_freeentity(mesh1):EndIf ; Altes Mesh löschen / Free old Mesh
                  ;mesh1=MP_LoadMesh(File.s)            ; Neues Mesh laden  / Load new Mesh
                  
                  mesh1=MP_LoadTerrain_Var (File.s, Size,Size,ColUse,High) ; Create Terrain (file, sizex, sizex , colorsearch, Highfactor)
                  
                  TextureMesh.l = MP_GetEntityTexture (mesh1) ; Textur des geladen Mesh finden / Find Mesh Texture 
                  Texturname.s = MP_GetTextureName (TextureMesh) ; Name der Textur / Name of Texture
                  ;Texturname.s = File.s
                  x.f=0 : y.f=0 : z.f=6 ; Mesh Koordinaten 
                 
                  max.f = MP_MeshHeight(mesh1) ; find Maximum of Mesh
             
                  If MP_MeshWidth(mesh1) > max
                    max = MP_MeshWidth(mesh1) 
                  EndIf

                  If MP_Meshdepth(mesh1) > max
                    max = MP_Meshdepth(mesh1) 
                  EndIf

                  scale.f = 3 / max ; 

                  MP_EntityScaling (mesh1,scale,scale,scale) ; Auf Bildschirm maximieren / maximum to Screen


              EndIf
          Case 3 ; Ende 
              End 
          Case 4 ; Ogre Mesh erzeugen / Create Ogre Mesh 
              File.s = SaveFileRequester("Speicher/Save Ogre Mesh Code", "Ogremesh.pb", "OgreMesh Files(*.pb)|*.pb",  0) 

              If CreateFile(1, File.s) ; Erstelle/Create Code
                  Restore StringData
                  Repeat
                    Read.s Purestring.s 
                    WriteStringN(1, Purestring)
                  Until Purestring.s  = "End"

                  WriteStringN(1, "" )         
                  WriteStringN(1, "DataSection" )
                  WriteStringN(1, "   StringSect:")
                  WriteStringN(1, "      Data.s "+Chr(34)+Texturname+Chr(34))
                  WriteStringN(1, "")               
                  WriteStringN(1, "   NumericalData:")
                  WriteStringN(1, "   Data.l "+Str(MP_CountVertices(Mesh1))+","+Str(MP_CountTriangles(Mesh1))+","+Str(max)) ; Zähle/Count Vertices und/and Triangle
                  WriteStringN(1, "")
                  WriteStringN(1, "   Vertice:  ;x,y,z,nx,ny,nz,col,u,v = Vertex + Normal + Col + UV Koordinaten" )
                  For n =  0 To MP_CountVertices(Mesh1)-1
                    ;Debug MP_VertexX (Mesh1, n)
                    vx.s =  NullTrim(StrF(MP_VertexX (Mesh1, n)))
                    vy.s =  NullTrim(StrF(MP_VertexY (Mesh1, n)))
                    vz.s =  NullTrim(StrF(MP_VertexZ (Mesh1, n)))
                    nx.s =  NullTrim(StrF(MP_VertexNX(Mesh1, n)))
                    ny.s =  NullTrim(StrF(MP_VertexNY(Mesh1, n)))
                    nz.s =  NullTrim(StrF(MP_VertexNZ(Mesh1, n)))
                   Col.s =  NullTrim(StrF(MP_VertexColor(Mesh1, n)))
                     u.s =  NullTrim(StrF(MP_VertexU (Mesh1, n))) ; Koordinaten vertauscht für Textur/Wrong UV Coords INTO Ogre so i change them
;                     u.s =  NullTrim(StrF(-1*MP_VertexU (Mesh1, n))) ; Koordinaten vertauscht für Textur/Wrong UV Coords INTO Ogre so i change them
                     v.s =  NullTrim(StrF(MP_VertexV (Mesh1, n)))
                     WriteStringN(1, "   Data.f "+vx+","+vy+","+vz+","+nx+","+ny+","+nz+","+col+","+u+","+v )
                     SetWindowTitle(0, "Write: "+Str(n)+"/"+Str(MP_CountVertices(Mesh1)-1)+" Vertices") 
                  Next
                  WriteStringN(1, "")
                  WriteStringN(1, "   Triangle: ; Vertice x,y,z verbinden/Create Triangle" )
                  For n =  1 To MP_CountTriangles(Mesh1)
                      corner_0 = MP_TriangleVertex(Mesh1,n, 0) ;
                      corner_1 = MP_TriangleVertex(Mesh1,n, 1) ;
                      corner_2 = MP_TriangleVertex(Mesh1,n, 2) ;
                      WriteStringN(1, "   Data.w "+Str(corner_2)+","+Str(corner_0)+","+Str(corner_1) )
                      SetWindowTitle(0, "Write: "+Str(n)+"/"+Str(MP_CountTriangles(Mesh1))+" Triangle") 
                  Next
                  WriteStringN(1, "EndDataSection")
                  CloseFile(1)
                  MessageRequester("Info", "Ogre Mesh Code erzeugt/created", 0)
                  SetWindowTitle(0, "Ready") 

              Else
                  MessageRequester("Error", "Kann die Datei nicht schreiben/Can't write file", 0)
              EndIf
               
          Case 5 ; Ogre Mesh erzeugen / Create Ogre Mesh 
              File.s = SaveFileRequester("Speicher/Save Ogre Mesh Code for sechsrad", "Ogremesh.pb", "OgreMesh Files(*.pb)|*.pb",  0) 

              If CreateFile(1, File.s) ; Erstelle/Create Code

                  WriteStringN(1, "DataSection" )
                  WriteStringN(1, "   StringSect:")
                  WriteStringN(1, "      Data.s "+Chr(34)+Texturname+Chr(34))
                  WriteStringN(1, "")               
                  WriteStringN(1, "   NumericalData:")
                  WriteStringN(1, "   Data.l "+Str(MP_CountVertices(Mesh1))+","+Str(MP_CountTriangles(Mesh1))+","+Str(max)) ; Zähle/Count Vertices und/and Triangle
                  WriteStringN(1, "")
                  WriteStringN(1, "   Vertice:  ;x,y,z,nx,ny,nz,col,u,v = Vertex + Normal + Col + UV Koordinaten" )
                  For n =  0 To MP_CountVertices(Mesh1)-1
                    vx.s =  NullTrim(StrF(MP_VertexX (Mesh1, n)))
                    vy.s =  NullTrim(StrF(MP_VertexY (Mesh1, n)))
                    vz.s =  NullTrim(StrF(MP_VertexZ (Mesh1, n)))
                    nx.s =  NullTrim(StrF(MP_VertexNX(Mesh1, n)))
                    ny.s =  NullTrim(StrF(MP_VertexNY(Mesh1, n)))
                    nz.s =  NullTrim(StrF(MP_VertexNZ(Mesh1, n)))
                   Col.s =  NullTrim(StrF(MP_VertexColor(Mesh1, n)))
                     u.s =  NullTrim(StrF(MP_VertexU (Mesh1, n))) ; Koordinaten vertauscht für Textur/Wrong UV Coords INTO Ogre so i change them
                  ;   u.s =  NullTrim(StrF(-1*MP_VertexU (Mesh1, n))) ; Koordinaten vertauscht für Textur/Wrong UV Coords INTO Ogre so i change them
                     v.s =  NullTrim(StrF(MP_VertexV (Mesh1, n)))
                     WriteStringN(1, "   Data.f "+vx+","+vy+","+vz+","+nx+","+ny+","+nz+","+col+","+u+","+v )
                     SetWindowTitle(0, "Write: "+Str(n)+"/"+Str(MP_CountVertices(Mesh1)-1)+" Vertices") 
                  Next
                  WriteStringN(1, "")
                  WriteStringN(1, "   Triangle: ; Vertice x,y,z verbinden/Create Triangle" )
                  For n =  1 To MP_CountTriangles(Mesh1)
                      corner_0 = MP_TriangleVertex(Mesh1,n, 0) ;
                      corner_1 = MP_TriangleVertex(Mesh1,n, 1) ;
                      corner_2 = MP_TriangleVertex(Mesh1,n, 2) ;
                      WriteStringN(1, "   Data.w "+Str(corner_2)+","+Str(corner_0)+","+Str(corner_1) )
                      SetWindowTitle(0, "Write: "+Str(n)+"/"+Str(MP_CountTriangles(Mesh1))+" Triangle") 
                  Next
                  WriteStringN(1, "EndDataSection")
                  CloseFile(1)
                  MessageRequester("Info", "Ogre Mesh Code erzeugt/created", 0)
                  SetWindowTitle(0, "Ready") 

              Else
                  MessageRequester("Error", "Kann die Datei nicht schreiben/Can't write file", 0)
              EndIf
          Case 6 ; Direct x Mesh erzeugen / Create Direct x Mesh 
              File.s = SaveFileRequester("Speicher/Save Mesh as Direct x", "*.x", "Direct x Files(*.x)|*.x",  0)
              If File.s 
                 MP_SaveMesh(File.s,Mesh1)
              EndIf   
          Case 7 ; Size of 3D Terrain
                SetMenuItemState(0,7,1) : SetMenuItemState(0,8,0) : SetMenuItemState(0,9,0): SetMenuItemState(0,10,0)
                Size = 32 
          Case 8
                SetMenuItemState(0,7,0) : SetMenuItemState(0,8,1) : SetMenuItemState(0,9,0): SetMenuItemState(0,10,0)
                Size = 64 
          Case 9
                SetMenuItemState(0,7,0) : SetMenuItemState(0,8,0) : SetMenuItemState(0,9,1): SetMenuItemState(0,10,0)
                Size = 128
          Case 10
                SetMenuItemState(0,7,0) : SetMenuItemState(0,8,0) : SetMenuItemState(0,9,0): SetMenuItemState(0,10,1)
                Size = 156
          Case 11 ; Look for Color
                SetMenuItemState(0,11,1) : SetMenuItemState(0,12,0) : SetMenuItemState(0,13,0) : SetMenuItemState(0,14,0)
                ColUse = 2
          Case 12
                SetMenuItemState(0,11,0) : SetMenuItemState(0,12,1) : SetMenuItemState(0,13,0) : SetMenuItemState(0,14,0)
                ColUse = 1
          Case 13
                SetMenuItemState(0,11,0) : SetMenuItemState(0,12,0) : SetMenuItemState(0,13,1) : SetMenuItemState(0,14,0)
                ColUse = 0
          Case 14
                SetMenuItemState(0,11,0) : SetMenuItemState(0,12,0) : SetMenuItemState(0,13,0) : SetMenuItemState(0,14,1)
                ColUse = 3
          Case 15 ; Highnes of file
                SetMenuItemState(0,15,1) : SetMenuItemState(0,16,0) : SetMenuItemState(0,17,0) 
                High = 50
          Case 16
                SetMenuItemState(0,15,0) : SetMenuItemState(0,16,1) : SetMenuItemState(0,17,0) 
                High = 15
          Case 17
                SetMenuItemState(0,15,0) : SetMenuItemState(0,16,0) : SetMenuItemState(0,17,1) 
                High = 6
          Case 18 ; Über 
             info.s = "DirectXtoMeshKonverter"+Chr(10)+Chr(10)
             info.s + "Mit diesem Programm kann man ein Direct x Mesh laden und als"+Chr(10)
             info.s + "PB Mesh speichern, oder ein Bild als 3D Terrain erzeugen und speichern"+Chr(10)+Chr(10)
                       
             info.s + "With this program you can create PB Meshcode from direct x files"+Chr(10)                 
             info.s + "or a you can create a 3D Terrain from a picture"+Chr(10) +Chr(10)                       
              
             info.s + "Bewege/Move Mesh mit/with Cursor Tasten/Keys and a/y/z"+Chr(10) +Chr(10)
             info.s + "Ver: 0.2 beta (c) Michael Paulwitz compiled with PB 4.3"+Chr(10) 
             MessageRequester("Info", info.s, 0) 
               
         EndSelect 
      Case #PB_Event_CloseWindow 
         End 
EndSelect 

 ; nen bishen apielen und das Objekt drehen 
 If MP_KeyDown(#PB_Key_Left)=1 : x-1 : EndIf ;links Debug #PB_Key_Left 
 If MP_KeyDown(#PB_Key_Right)=1 : x+1 : EndIf ;rechts #PB_Key_Right 
 If MP_KeyDown(#PB_Key_Down)=1 : y-1 : EndIf ;Runter #PB_Key_Down 
 If MP_KeyDown(#PB_Key_Up)=1 : y+1 : EndIf ;rauf #PB_Key_Up 
 If MP_KeyDown(#PB_Key_Z)=1  : z+0.1 : EndIf ;y Vertauscht bei y-z bei deutscher tastatur 
 If MP_KeyDown(#PB_Key_Y)=1  : z+0.1 : EndIf ;y Vertauscht bei y-z bei deutscher tastatur 
 If MP_KeyDown(#PB_Key_A)=1  : z-0.1 : EndIf ;a #PB_Key_A 

 If mesh1 ; Objekt drehen
    MP_DrawText (2,2,RGB(255,255,255),"Triangles: "+Str(MP_CountTriangles(Mesh1))+"  Vertices: "+Str(MP_CountVertices(Mesh1))) 
    MP_PositionEntity (Mesh1,0,0,z) 
    MP_RotateEntity (Mesh1,x,y,0) 
    x + 0.05
    y + 0.1
 EndIf 
    
    MP_RenderWorld () 
    MP_Flip () 
Wend 
End

DataSection

StringData:
Data.s "#Mesh = 0" 
Data.s "If InitEngine3D() And InitSprite() And InitKeyboard()" 
Data.s "  OpenWindow(0,0,0,640,480,"+Chr(34)+"3D Mesh TEST  - Key A and Y/Z bewegt/move Mesh"+Chr(34)+",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)" 
Data.s "  OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,0)" 
Data.s " "
Data.s "    Restore NumericalData"
Data.s "    Read.l Vert"
Data.s "    Read.l Tria"
Data.s "    Read.l Max"
Data.s " "
Data.s "    CreateMesh(#Mesh, vert)"
Data.s " "    
Data.s "    SetMeshData(#Mesh, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_Color  | #PB_Mesh_UVCoordinate, ?Vertice, Vert);3)"
Data.s "    SetMeshData(#Mesh, #PB_Mesh_Face, ?Triangle, Tria); 1)"
Data.s " "
Data.s "    Restore StringSect"
Data.s "    Read.s Texturname.s" 
Data.s "    Add3DArchive("+Chr(34)+"."+Chr(34)+", #PB_3DArchive_FileSystem) ; Textur in Ordner / Add folder" 
Data.s "    if FileSize(Texturname) <> -1"
Data.s "        CreateEntity(#Mesh, MeshID(0), CreateMaterial(0, LoadTexture(0, Texturname.s)))" 
Data.s "        CreateLight(0, RGB(255,255,255), 100.0, 0, 0)   ; White Light"
Data.s "    Else"
Data.s "        CreateEntity(#Mesh, MeshID(0),#PB_Material_None)"
Data.s "        CreateLight(0, RGB(0,0,255), 100.0, 0, 0)   ; Blue Light"
Data.s "        CreateLight(1, RGB(255,0,0), -100.0, 0, 0)  ; Red Light"
Data.s "        CreateLight(2, RGB(255,255,0), 0.0, 100, 0)   ; Yellow Light"
Data.s "    Endif"
Data.s " "
Data.s "    CreateCamera(0, 0, 0, 100, 100)"
Data.s "    z+(max*2)"
Data.s "    CameraLocate(0,0,0,z)"
Data.s " "
Data.s "    Repeat"
Data.s "      ExamineKeyboard()"
Data.s "      Select WindowEvent()" 
Data.s "        Case #PB_Event_CloseWindow" 
Data.s "          Quit = #True"
Data.s "      EndSelect"
Data.s " "
Data.s "      If KeyboardPushed(#PB_Key_A) ; Key A = Zoom +"
Data.s "         z-1"
Data.s "         CameraLocate(0,0,0,z)" 
Data.s "      EndIf"
Data.s " "
Data.s "      If KeyboardPushed(#PB_Key_Z) ; Key Z = Zoom +"
Data.s "         z+1"
Data.s "         CameraLocate(0,0,0,z)"
Data.s "      EndIf"
Data.s " "
Data.s "      If KeyboardPushed(#PB_Key_Y) ; Key Y = Zoom +"
Data.s "         z+1"
Data.s "         CameraLocate(0,0,0,z)"
Data.s "      EndIf"
Data.s " "
Data.s "      RotateEntity(#Mesh, 1, 1, 1, #PB_Relative)"
Data.s " "
Data.s "      ClearScreen(RGB(0,0,0))"
Data.s "      RenderWorld()"
Data.s "      FlipBuffers()"
Data.s " "  
Data.s "    Until KeyboardPushed(#PB_Key_Escape) Or Quit"
Data.s "Else"
Data.s "  MessageRequester("+Chr(34)+"Error"+Chr(34)+", "+Chr(34)+"Cant init DirectX 3D Engine"+Chr(34)+",0)"
Data.s "EndIf"
Data.s " "  
Data.s "End" 

Logo: IncludeBinary "c:\alphabox.tga" ; My Grafikfile
endlogo:
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Post by mpz »

Hi,

here comes my program with 2 new functions and a new name.

MPs 3D Tool V 0.3
Program to create:

Ogre Meshs from Direct x Meshs
Create Directx Meshs with new textures
Create 3D Terains/Objekte from any grafik file
Create normal maps from Highmaps/grafikfile
Create a new grafik file with Alpha chanel (you input a grafik file for the alpha chanel, Color grafik file + grafik file for the Alpha chanel = grafik.tga, both grafik files must only have the same size... )

Tool load here:
http://rapidshare.de/files/45465355/MPs ... 3.exe.html

or there :
http://easymirror.q-soft.ch/?tok=cduuda ... wtMDMtZXhl

Greetings Michael
_________________
Albeite ohne mullen und knullen
Post Reply