Wavefrontexport von Vertex
Hi!
Hier eine kleine Funktion zum exportieren von Obj Datein.
Also in Milkshape kann ich sie laden, aber man muss sie zweimal
flippen (alles selektieren und dann 2mal reverse vertex order), damit
man es richtig sieht. In LithUnwrap kann ich es leider garnicht laden,
ka warum, vieleicht emuliert ja Milkshape da irgendwas :wink:
Naja hier der Code + Example:
[code:1:6d38a42158]
; Graphicsettings ----------------------------------------------------------
Graphics3D 640,480,32,2
SetBuffer BackBuffer()
; --------------------------------------------------------------------------

; A simple sphere ----------------------------------------------------------
Sphere = CreateSphere(5)
SaveObj(Sphere,"Test.obj")
AppTitle "Exported as " + Chr$(34) + "Test.obj" + Chr$(34)
; --------------------------------------------------------------------------

; The camera ---------------------------------------------------------------
Camera = CreateCamera()
PositionEntity Camera,0,2,2
PointEntity Camera,Sphere
; --------------------------------------------------------------------------

; A light ------------------------------------------------------------------
Light = CreateLight(1,Camera)
; --------------------------------------------------------------------------

; Mainloop -----------------------------------------------------------------
While Not KeyDown(1)
TurnEntity Sphere,0,1,1
UpdateWorld : RenderWorld : Flip
Wend
; --------------------------------------------------------------------------

; The end ------------------------------------------------------------------
ClearWorld : End
; --------------------------------------------------------------------------

; Function to export as Wavefront(*.Obj) -----------------------------------
Function SaveObj(Entity,File$)
Local Stream,S,Surface,V,WLine$,T
Local Vertex,CS,V0,V1,V2

Stream = WriteFile(File$)

WriteLine Stream,"# Exported with Blitz3D"
WriteLine Stream,""

; Vertices
For S = 1 To CountSurfaces(Entity)
Surface = GetSurface(Entity,S)
For V = 0 To CountVertices(Surface) - 1
WLine$ = ""
WLine$ = WLine$ + "v " + VertexX#(Surface,V) + " "
WLine$ = WLine$ + VertexY#(Surface,V) + " "
WLine$ = WLine$ + VertexZ#(Surface,V)
WriteLine Stream,WLine$
Next
Next
WriteLine Stream,""

; Texturcoords
For S = 1 To CountSurfaces(Entity)
Surface = GetSurface(Entity,S)
For V = 1 To CountVertices(Surface) - 1
WLine$ = ""
WLine$ = WLine$ + "vt " + VertexU#(Surface,V) + " "
WLine$ = WLine$ + VertexV#(Surface,V)
WriteLine Stream,WLine$
Next
Next
WriteLine Stream,""

; Vertexnormals
For S = 1 To CountSurfaces(Entity)
Surface = GetSurface(Entity,S)
For V = 0 To CountVertices(Surface) - 1
WLine$ = ""
WLine$ = WLine$ + "vn " + VertexNX#(Surface,V) + " "
WLine$ = WLine$ + VertexNX#(Surface,V) + " "
WLine$ = WLine$ + VertexNZ#(Surface,V)
WriteLine Stream,WLine$
Next
Next
WriteLine Stream,""

; Groups
For S = 1 To CountSurfaces(Entity)
WriteLine Stream,"g Surface " + S
Surface = GetSurface(Entity,S)
For T = 0 To CountTriangles(Surface)
Vertex = Vertex + 3

If S <> 1 Then
CS = CountVertices(GetSurface(Entity,S - 1)) + 1
V0 = TriangleVertex(Surface,T,0) + CS
V1 = TriangleVertex(Surface,T,1) + CS
V2 = TriangleVertex(Surface,T,2) + CS
Else
V0 = TriangleVertex(Surface,T,0) + 1
V1 = TriangleVertex(Surface,T,1) + 1
V2 = TriangleVertex(Surface,T,2) + 1
EndIf
WLine$ = ""
WLine$ = WLine$ + "f " + V0 + "/" + (Vertex - 2) + " "
WLine$ = WLine$ + V1 + "/" + (Vertex - 1) + " "
WLine$ = WLine$ + V2 + "/" + (Vertex - 0)
WriteLine Stream,WLine$
Next
Next

CloseFile Stream
End Function
; --------------------------------------------------------------------------
[/code:1:6d38a42158]
mfg olli



Suche:
(unterstützt mySQL Wildcards ala %)
Titel:
Text:
Autor: