Seite 1 von 1

Png2Mesh

Verfasst: 02.06.2012 20:09
von Darie
Und schon wieder ein neues Posting von mir,

bin gerade dabei aus einem PNG ein Mesh zu erstellen (wie bei Minecraft). Hab erstmal nur mit VertexColor Farbinformationen für die Faces zugewiesen und dann gemerkt, dass nur ambientes Licht damit möglich ist. Ich brauche etwas Hilfe, die UV-Koordinaten dafür richtig zu berechnen.


Download -> https://dl.dropbox.com/u/79165522/Png2Mesh.zip

MfG
Darie

Code: Alles auswählen

Global CamSpeed = 0.6 , CamMode = 0 , RenderMode = 0, FullScreen = 0
Global KeyX, KeyY, RollZ, RotX, RotY, MouseX, MouseY, FPS, VSync = 1

#SQRT13 = 0.57735026

Declare InitWorld()
Declare Keyboard()
Declare MakeMesh()

Procedure InitWorld()
  
Global Mesh$
;Mesh$ = GetFilePart(OpenFileRequester("MeshViewer",GetCurrentDirectory() , "mesh (*.mesh) | *.mesh", 0))

InitEngine3D() 
InitSprite()
InitKeyboard()
InitMouse()

UsePNGImageDecoder()
UseJPEGImageDecoder()

Add3DArchive("\", #PB_3DArchive_FileSystem) 
AntialiasingMode(#PB_AntialiasingMode_x6)
;Parse3DScripts()

If Not FullScreen
  OpenWindow(0,0,0,1280,960,"Stryder",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
  OpenWindowedScreen(WindowID(0),0,0,1280,960,0,0,0,VSync) 
 Else
  ExamineDesktops()
  OpenScreen(DesktopWidth(0),DesktopHeight(0),32,"",VSync)
EndIf

CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0, -30, 30,-40)
RotateCamera(0,-90,0, 180)

MakeMesh() ;LoadMesh(1,Mesh$)
CreateEntity(1, MeshID(1), MaterialID(1),0,0,0)
ResizeEntity(1, 5,5,5)

;CreateLight(0,$FFFFFF,0,30,0,#PB_Light_Point)
;Sun(0,500,0,$FFFFFF)
;SpotLightRange(0,0, 90)
AmbientColor($FFFFFF)

LoadTexture(0,"plane.jpg") 
CreateMaterial(0, TextureID(0))
CreatePlane(0, 20, 20, 10, 10, 10, 10)
CreateEntity(0,MeshID(0), MaterialID(0), 0, 0, 0)

CameraLookAt(0,EntityX(1),EntityY(1),EntityZ(1))

EndProcedure

Procedure Keyboard()
  
ExamineKeyboard()
     
If KeyboardPushed(#PB_Key_A)
  keyx = -1
 ElseIf KeyboardPushed(#PB_Key_D)
   keyx = 1 
 Else
  keyx = 0
EndIf

If KeyboardReleased(#PB_Key_A)
 
ElseIf KeyboardReleased(#PB_Key_D)
 
EndIf

If KeyboardPushed(#PB_Key_W)
  keyy = -1 
ElseIf KeyboardPushed(#PB_Key_S)
  keyy = 1 
Else
  keyy = 0
EndIf

If KeyboardReleased(#PB_Key_PageUp)
  rollz = 1 
ElseIf KeyboardReleased(#PB_Key_PageDown)
 rollz = 0
EndIf

If KeyboardReleased(#PB_Key_Space)
 
EndIf

If KeyboardReleased(#PB_Key_F1)
 
EndIf

If KeyboardReleased(#PB_Key_F2) 
 Rendermode = Rendermode + 1 
 Select Rendermode
   Case 0 : CameraRenderMode(0, #PB_Camera_Textured)
   Case 1 : CameraRenderMode(0, #PB_Camera_Wireframe)
   Case 2 : CameraRenderMode(0, #PB_Camera_Plot)
 EndSelect
 If Rendermode = 2 : Rendermode = -1 : EndIf
EndIf
 
 If KeyboardReleased(#PB_Key_F3)
   ;If CamMode = #True : CamMode = #False : Else : CamMode = #True : EndIf
 EndIf
      
ExamineMouse()
     
rotx = 0 : roty = 0
mousex = -MouseDeltaX()
mousey = -MouseDeltaY()
     
If MouseButton(#PB_MouseButton_Right)
 rotx = mousey
 roty = mousex
 mousex = 0
 mousey = 0
EndIf
     
EndProcedure

Procedure MakeMesh()

LoadImage(0, "a.png")
Width  = ImageWidth(0)
Height = ImageHeight(0)

CreateImage(1, Width+2,Height+2,32|#PB_Image_Transparent)
Width  = ImageWidth(1)
Height = ImageHeight(1)
Dim MyArray.s(Height)

 StartDrawing(ImageOutput(1))
 DrawingMode(#PB_2DDrawing_AllChannels)
 DrawImage(ImageID(0),1,1)
 StopDrawing()

;UsePNGImageEncoder(): SaveImage(1,"test.png",#PB_ImagePlugin_PNG)
;End

StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_AlphaChannel)
For y = 0 To Height-1
For x = 0 To Width-1
 pixel = Point(x,y)
 If Pixel <> 0
 MyArray(y) = MyArray(y) + "1" 
 Else
 MyArray(y) = MyArray(y) + "0" 
 EndIf
Next x
Next y
StopDrawing()

 For y = 0 To Height-1
  MyArray(y) = ReplaceString(MyArray(y),"010","0L0")
  MyArray(y) = ReplaceString(MyArray(y),"011","0S1")
  MyArray(y) = ReplaceString(MyArray(y),"110","1E0")
  MyArray(y) = ReplaceString(MyArray(y),"S10","SE0") 
 Next y

; StartDrawing(ImageOutput(1))
; For y = 0 To Height-1
; For x = 0 To Width-1
; If Mid(MyArray(y),x,1) = "L" : Plot(x,y, $D80300) : EndIf
; If Mid(MyArray(y),x,1) = "1" : Plot(x,y, $0000D6) : ElseIf Mid(MyArray(y),x,1) = "0" : Plot(x,y, $000000) : EndIf
; If Mid(MyArray(y),x,1) = "S" : Plot(x,y, $4BFCFF) : ElseIf Mid(MyArray(y),x,1) = "E" : Plot(x,y, $00D61F) : EndIf
; Next x 
; Next y
; StopDrawing() : SaveImage(1,"test.bmp")

CreateMesh(1) : l = 1 

For y = 0 To Height
For x = 0 To Width

pix.s = Mid(MyArray(y),x+1,1)

If pix.s = "L" ;FullFace

StartDrawing(ImageOutput(1))
pixel = Point(x,y)
StopDrawing()

AddSubMesh()
AddMeshVertex(x*l+0,y*l+1, 0) : MeshVertexColor(pixel);0
;MeshVertexTextureCoordinate((width/100)*x, (height/100)*y) 
AddMeshVertex(x*l+1,y*l+1, 0) :  MeshVertexColor(pixel);
 
AddMeshVertex(x*l+1,y*l+0, 0) : MeshVertexColor(pixel);
;MeshVertexTextureCoordinate((width/100)*x+0.6, (height/100)*y+0.6)  
AddMeshVertex(x*l+0,y*l+0, 0) :  MeshVertexColor(pixel);
 
AddMeshFace(0, 2, 3);AddMeshFace(0, 2, 1)
AddMeshFace(0, 1, 2);AddMeshFace(2, 0, 3)
AddMeshVertex(x*l+0,y*l+1, l) :  MeshVertexColor(pixel);
 
AddMeshVertex(x*l+1,y*l+1, l) :  MeshVertexColor(pixel);
 
AddMeshVertex(x*l+1,y*l+0, l) :  MeshVertexColor(pixel);
 
AddMeshVertex(x*l+0,y*l+0, l) :  MeshVertexColor(pixel);
 
AddMeshFace(7, 6, 4);Rückseite
AddMeshFace(4, 6, 5)
AddMeshFace(1, 4, 5);Oberseite
AddMeshFace(1, 0, 4)
AddMeshFace(3, 2, 7);Unterseite
AddMeshFace(2, 6, 7)
AddMeshFace(7, 4, 0);vorne
AddMeshFace(3, 7, 0);
AddMeshFace(1, 5,6);hinten
AddMeshFace(2, 1, 6);

ElseIf pix.s = "S" ;Startface

StartDrawing(ImageOutput(1))
pixel = Point(x,y)
StopDrawing()


AddSubMesh()
AddMeshVertex(x*l+0,y*l+1, 0) :  MeshVertexColor(pixel);
 ;MeshVertexTextureCoordinate(width/(x*l), height/(y*l))
AddMeshVertex(x*l+1,y*l+1, 0) :  MeshVertexColor(pixel);
 
AddMeshVertex(x*l+1,y*l+0, 0) :  MeshVertexColor(pixel);
 ;MeshVertexTextureCoordinate(width/(x*l), height/(y*l))
AddMeshVertex(x*l+0,y*l+0, 0) :  MeshVertexColor(pixel);
 
AddMeshFace(0, 2, 3);AddMeshFace(0, 2, 1)
AddMeshFace(0, 1, 2);AddMeshFace(2, 0, 3)
AddMeshVertex(x*l+0,y*l+1, l) :  MeshVertexColor(pixel);
 
AddMeshVertex(x*l+1,y*l+1, l) :  MeshVertexColor(pixel);
 
AddMeshVertex(x*l+1,y*l+0, l) :  MeshVertexColor(pixel);
AddMeshVertex(x*l+0,y*l+0, l) :  MeshVertexColor(pixel);
 
AddMeshFace(7, 6, 4);Rückseite
AddMeshFace(4, 6, 5)
AddMeshFace(1, 4, 5);Oberseite
AddMeshFace(1, 0, 4)
AddMeshFace(3, 2, 7);Unterseite
AddMeshFace(2, 6, 7)
AddMeshFace(7, 4, 0);vorne
AddMeshFace(3, 7, 0);
;AddMeshFace(1, 5,6);hinten
;AddMeshFace(2, 1, 6);

ElseIf pix.s = "E" ;EndFace

StartDrawing(ImageOutput(1))
pixel = Point(x,y)
StopDrawing()

AddSubMesh()
AddMeshVertex(x*l+0,y*l+1, 0) :  MeshVertexColor(pixel);
 ;MeshVertexTextureCoordinate(width/(x*l), height/(y*l))
AddMeshVertex(x*l+1,y*l+1, 0) :  MeshVertexColor(pixel);
 
AddMeshVertex(x*l+1,y*l+0, 0) :  MeshVertexColor(pixel);
 ;MeshVertexTextureCoordinate(width/(x*l), height/(y*l))
AddMeshVertex(x*l+0,y*l+0, 0) :  MeshVertexColor(pixel);
 
AddMeshFace(0, 2, 3);AddMeshFace(0, 2, 1)
AddMeshFace(0, 1, 2);AddMeshFace(2, 0, 3)
AddMeshVertex(x*l+0,y*l+1, l) :  MeshVertexColor(pixel);
 
AddMeshVertex(x*l+1,y*l+1, l) :  MeshVertexColor(pixel);

AddMeshVertex(x*l+1,y*l+0, l) :  MeshVertexColor(pixel);
 
AddMeshVertex(x*l+0,y*l+0, l) :  MeshVertexColor(pixel);
 
AddMeshFace(7, 6, 4);Rückseite
AddMeshFace(4, 6, 5)
AddMeshFace(1, 4, 5);Oberseite
AddMeshFace(1, 0, 4)
AddMeshFace(3, 2, 7);Unterseite
AddMeshFace(2, 6, 7)
;AddMeshFace(7, 4, 0);vorne
;AddMeshFace(3, 7, 0);
AddMeshFace(1, 5,6);hinten
AddMeshFace(2, 1, 6);

ElseIf pix.s = "1" ;MiddleFace

StartDrawing(ImageOutput(1))
pixel = Point(x,y)
StopDrawing()


AddSubMesh()
AddMeshVertex(x*l+0,y*l+1, 0) :  MeshVertexColor(pixel);
 ;MeshVertexTextureCoordinate((width/100)*x, (height/100)*y) 
AddMeshVertex(x*l+1,y*l+1, 0) :  MeshVertexColor(pixel);
 ;MeshVertexTextureCoordinate((width/100)*x+tex, (height/100)*y) 
AddMeshVertex(x*l+1,y*l+0, 0) :  MeshVertexColor(pixel);
 ;MeshVertexTextureCoordinate((width/100)*x+tex, (height/100)*y+tex) 
AddMeshVertex(x*l+0,y*l+0, 0) :  MeshVertexColor(pixel);
 ;MeshVertexTextureCoordinate((width/100)*x, (height/100)*y+tex) 
AddMeshFace(0, 2, 3);AddMeshFace(0, 2, 1)
AddMeshFace(0, 1, 2);AddMeshFace(2, 0, 3)
AddMeshVertex(x*l+0,y*l+1, l) :  MeshVertexColor(pixel);
AddMeshVertex(x*l+1,y*l+1, l) :  MeshVertexColor(pixel);
AddMeshVertex(x*l+1,y*l+0, l) :  MeshVertexColor(pixel);
AddMeshVertex(x*l+0,y*l+0, l) :  MeshVertexColor(pixel);
AddMeshFace(7, 6, 4);Rückseite
AddMeshFace(4, 6, 5)
AddMeshFace(1, 4, 5);Oberseite
AddMeshFace(1, 0, 4)
AddMeshFace(3, 2, 7);Unterseite
AddMeshFace(2, 6, 7)
;AddMeshFace(7, 4, 0);vorne
;AddMeshFace(3, 7, 0);
;AddMeshFace(1, 5,6);hinten
;AddMeshFace(2, 1, 6);

EndIf

Next x
Next y

; ;MeshVertexNormal(-#SQRT13,-#SQRT13,#SQRT13)
    
FinishMesh()

TransformMesh(1,0,0,0,0.05,0.05,0.05,0,0,0)
NormalizeMesh(1)
CreateMaterial(1, LoadTexture(1, "pickaxe.png"))
MaterialAmbientColor(1, #PB_Material_AmbientColors)
MaterialDiffuseColor(1, $FFFFFF)

;DisableMaterialLighting(1,1)
;MaterialDiffuseColor(1,$FFFFFF)
;MaterialSelfIlluminationColor(1,$FFFFFF)

;ScrollMaterial(1, 0.2, 0.2,#PB_Material_Animated)

EndProcedure


InitWorld()
;CameraRenderMode(0, #PB_Camera_Wireframe)

Repeat  
  
 If Not Fullscreen
 Select WaitWindowEvent(1) 
 Case #PB_Event_CloseWindow 
 Quit = #True 
 EndSelect 
 EndIf
 
 Keyboard()
 RotateEntity(1, 0, 0.3, 0, #PB_Relative)
 RotateCamera(0, mousey, mousex, 0,#PB_Relative)
 MoveCamera  (0, keyx*CamSpeed, 0, keyy*CamSpeed)  

 FPS = Engine3DFrameRate(#PB_Engine3D_Current)
 RenderWorld() 
 
 FlipBuffers()
 
Until KeyboardPushed(#PB_Key_Escape) Or Quit = #True

Re: Png2Mesh

Verfasst: 02.06.2012 20:21
von STARGÅTE
Da ich keine lust habe es selber zu machen, hier nur einige Hinweise:

Welche Textur-Koordinate du einem Vertex zuordnest, musst du selber wissen.
Wichtig ist dabei nur, das die Koordinaten relativ sind 25px bei 100px Texture ist also 0.25.

Damit das Licht richtig berechnet werden kann, musst du zusätzlich jedem Vertex einen Normalen-Vektor zuweise, also eine Richtung in der die mit ihm verbundene Fläche zeigt.

Re: Png2Mesh

Verfasst: 02.06.2012 21:16
von Darie
Ah okay, das hab ich mir auch so ungefähr gedacht.... Reicht ihr ein NormalizeMesh() am Ende und muss für jedes Vertex eine UV-Koordinate da sein?
Die UV-Werte sind ja in Prozent. Ergo wäre jede UV-Koordinate doch z.B. Width/100* x und für Height / 100 * y festzulegen?
Ich möchte quasi ein Pixel aus der Textur 4 Verticen, die zu zwei Faces verbunden wurden zuweisen....

Re: Png2Mesh

Verfasst: 02.06.2012 21:30
von STARGÅTE
Darie hat geschrieben:muss für jedes Vertex eine UV-Koordinate da sein?
Natürlich. Die Textur wird wie eine Folie über das Mesh gelegt, und die UV-Koordinate definiert dabei, welcher Punkt auf der Texture mit dem Vertex verbunden werden soll. Ansonsten wäre ja nicht klar, welche bereiche der Texture auf welcher Fläche liegen sollen.
Die UV-Koordinaten sind nicht in Prozent, sondern relativ, dass heißt 0.0 bis 1.0.
Also MeshVertexTextureCoordinate(X (in Pixel) / Width, Y (in Pixel) / Height)

Re: Png2Mesh

Verfasst: 02.06.2012 22:15
von Darie
Vielen Dank Stargate, jetzt stimmen die UV-Koordianten, wenn der Befehl fertig ist, poste ich ihn. Vielleicht findet er ja Verwendung....

Re: Png2Mesh

Verfasst: 03.06.2012 00:08
von Darie
So, hier ist die Procedure... ganz perfekt ist das noch nicht, weil doch einige überflüssige Verticen vorhanden sind. Mal schaun, ob ich das noch verbessern kann...

Code: Alles auswählen

Procedure MakeMeshFromPNG(png.s,extrudelength)

img    = LoadImage(#PB_Any, png.s)
Width  = ImageWidth(img)
Height = ImageHeight(img)

img2 = CreateImage(#PB_Any, Width+2,Height+2,32|#PB_Image_Transparent)
Width  = ImageWidth(img2)
Height = ImageHeight(img2)
Dim MyArray.s(Height)

StartDrawing(ImageOutput(img2))
DrawingMode(#PB_2DDrawing_AllChannels)
DrawImage(ImageID(img),1,1)
StopDrawing()

StartDrawing(ImageOutput(img2))
DrawingMode(#PB_2DDrawing_AlphaChannel)
For y = 0 To Height-1
For x = 0 To Width-1
 pixel = Alpha(Point(x,y))
 If Pixel <> 0
 MyArray(y) = MyArray(y) + "1" 
 Else
 MyArray(y) = MyArray(y) + "0" 
 EndIf
Next x
Next y
StopDrawing()

For y = 0 To Height-1
 MyArray(y) = ReplaceString(MyArray(y),"010","0L0")
 MyArray(y) = ReplaceString(MyArray(y),"011","0S1")
 MyArray(y) = ReplaceString(MyArray(y),"110","1E0")
 MyArray(y) = ReplaceString(MyArray(y),"S10","SE0") 
Next y

FreeImage(img) : FreeImage(img2)

Mesh = CreateMesh(#PB_Any) : l = 1 : le=extrudelength : tu.f = 1 / Width : tv.f = 1 / Height

For y = 0 To Height
For x = 0 To Width

pix.s = Mid(MyArray(y),x+1,1)

If pix.s = "L" ;FullFace

AddSubMesh()
AddMeshVertex(x*l+0,y*l+1, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+1,y*l+1, 0)
MeshVertexTextureCoordinate(tu*x,tv*y)  
AddMeshVertex(x*l+1,y*l+0, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y)   
AddMeshVertex(x*l+0,y*l+0, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y)  
AddMeshFace(0, 2, 3)
AddMeshFace(0, 1, 2)
AddMeshVertex(x*l+0,y*l+1, le)
MeshVertexTextureCoordinate(tu*x,tv*y)  
AddMeshVertex(x*l+1,y*l+1, le) 
MeshVertexTextureCoordinate(tu*x,tv*y)  
AddMeshVertex(x*l+1,y*l+0, le)
MeshVertexTextureCoordinate(tu*x,tv*y)  
AddMeshVertex(x*l+0,y*l+0, le)
MeshVertexTextureCoordinate(tu*x,tv*y)  
AddMeshFace(7, 6, 4);Rückseite
AddMeshFace(4, 6, 5)
AddMeshFace(1, 4, 5);Oberseite
AddMeshFace(1, 0, 4)
AddMeshFace(3, 2, 7);Unterseite
AddMeshFace(2, 6, 7)
AddMeshFace(7, 4, 0);vorne
AddMeshFace(3, 7, 0);
AddMeshFace(1, 5,6);hinten
AddMeshFace(2, 1, 6);

ElseIf pix.s = "S" ;Startface

AddSubMesh()
AddMeshVertex(x*l+0,y*l+1, 0)
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+1,y*l+1, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y)  
AddMeshVertex(x*l+1,y*l+0, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+0,y*l+0, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y)  
AddMeshFace(0, 2, 3)
AddMeshFace(0, 1, 2)

AddMeshVertex(x*l+0,y*l+1, le) 
MeshVertexTextureCoordinate(tu*x,tv*y)  
AddMeshVertex(x*l+1,y*l+1, le) 
MeshVertexTextureCoordinate(tu*x,tv*y)  
AddMeshVertex(x*l+1,y*l+0, le) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+0,y*l+0, le) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
 
AddMeshFace(7, 6, 4);Rückseite
AddMeshFace(4, 6, 5)
AddMeshFace(1, 4, 5);Oberseite
AddMeshFace(1, 0, 4)
AddMeshFace(3, 2, 7);Unterseite
AddMeshFace(2, 6, 7)
AddMeshFace(7, 4, 0);vorne
AddMeshFace(3, 7, 0);

ElseIf pix.s = "E" ;EndFace

AddSubMesh()
AddMeshVertex(x*l+0,y*l+1, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+1,y*l+1, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y)  
AddMeshVertex(x*l+1,y*l+0, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+0,y*l+0, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y)  
AddMeshFace(0, 2, 3)
AddMeshFace(0, 1, 2)
AddMeshVertex(x*l+0,y*l+1, le) 
MeshVertexTextureCoordinate(tu*x,tv*y)  
AddMeshVertex(x*l+1,y*l+1, le) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+1,y*l+0, le) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+0,y*l+0, le) 
MeshVertexTextureCoordinate(tu*x,tv*y) 

AddMeshFace(7, 6, 4);Rückseite
AddMeshFace(4, 6, 5)
AddMeshFace(1, 4, 5);Oberseite
AddMeshFace(1, 0, 4)
AddMeshFace(3, 2, 7);Unterseite
AddMeshFace(2, 6, 7)
AddMeshFace(1, 5,6);hinten
AddMeshFace(2, 1, 6);

ElseIf pix.s = "1" ;MiddleFace

AddSubMesh()
AddMeshVertex(x*l+0,y*l+1, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+1,y*l+1, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+1,y*l+0, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+0,y*l+0, 0) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshFace(0, 2, 3)
AddMeshFace(0, 1, 2)
AddMeshVertex(x*l+0,y*l+1, le) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+1,y*l+1, le)
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+1,y*l+0, le) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshVertex(x*l+0,y*l+0, le) 
MeshVertexTextureCoordinate(tu*x,tv*y) 
AddMeshFace(7, 6, 4);Rückseite
AddMeshFace(4, 6, 5)
AddMeshFace(1, 4, 5);Oberseite
AddMeshFace(1, 0, 4)
AddMeshFace(3, 2, 7);Unterseite
AddMeshFace(2, 6, 7)

EndIf

Next x
Next y
    
FinishMesh()

TransformMesh(Mesh,(MeshRadius(Mesh)/2)*-1,0,0,0.5,0.5,0.5,180,0,0)
NormalizeMesh(Mesh)
FreeArray(MyArray())

ProcedureReturn Mesh

EndProcedure
zum downloaden https://dl.dropbox.com/u/79165522/Png2Mesh.zip

Gruss
Darie

Re: Png2Mesh

Verfasst: 05.06.2012 07:51
von dige
@Darie: Vielen Dank! Ich habs nur kurz ausprobiert. Ist Dein Code auch geeignet
eine HighMap aus einem PNG in ein Mesh umzuwandeln? Also die Helligkeitswerte
für die räumliche Ausdehnung zu berücksichtigen. Da müssten vermutlich die
UV-Koordinaten anders/neu berechnet werden, oder?

Re: Png2Mesh

Verfasst: 05.06.2012 15:00
von Darie
Nein, dass kann der Code nicht. Die Farbinformationen werden nur für die Textur genutzt. Für grosse Bilder
ist der Code auch zu langsam.