Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Open GL + Lamborghini = Cool
#21
Quote:You have to write a program that imports the obj files that it exports. The obj format is actually really simple. Just open the program, create a simple cube or something, save it as an obj and open the file with notepad so you can study the way it's stored. Wink
That or read this document covering the format: http://www.wotsit.org/download.asp?f=w_obj
Reply
#22
Hehe.. I figured it out already.. this good enough?

http://members.aol.com/rattrapmax6/download/BlueOrb.zip

:wink:
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#23
:o

I would suggest using arrays, for simplicities sake.

This is what I did. Lightwave doesn't export Wavefront material files with the objects, so I named the surfaces of my objects like this...

002_Sphere_Surface
003_Torus_Surface

Then, in your program you just load the textures in that order...
Wink

I could post a demo of mine, if you want.


EDIT:
I realize you aren't using texures, but eve the vertices benefit greatly when using arrays.
Reply
#24
:o
got enough code there? :lol:
i think the idea was to write a loader that would load the file at runtime, not something that would convert the file into source ;P
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Reply
#25
I figured to make it source, but I left it where my parser should be able to Inport OBJs.... :lol:

Yeah,.. a array would be less code.. thats what the parser does, Tongue , But I'm just playing atm.. hehehe.. :wink:
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#26
he he, looks about like what i had going on, but my converter is written in Basic4GL.... i know this is a fb forum, but here's the src to my obj converter in b4gl

Code:
dim infile, outfile, code$, vertex#(10000)(2), vertexCount
dim normal#(10000)(2), normalCount, faceVertexCount(10000), faceVertex(10000)(10), faceNormal(10000)(10), faceCount
dim faceToken$, i, j, k, v#(2), n#(2), count

printr "Reading input file"

infile = OpenFileRead ("files\sphere.obj")
if FileError () <> "" then
   printr FileError ()
   end
endif

while not EndOfFile (inFile)

   code$ = lcase$ (ReadText (inFile, true))
   if code$ = "v" then

       for i = 0 to 2
           vertex#(vertexCount)(i) = val (ReadText (inFile, false))
       next
       vertexCount = vertexCount + 1
   elseif code$ = "vn" then

       for i = 0 to 2
           normal#(normalCount)(i) = val (ReadText (inFile, false))
       next
       normalCount = normalCount + 1
   elseif code$ = "f" then

              count = 0

       ' Read in the tokens
       faceToken$ = ReadText (inFile, false)
       while faceToken$ <> "" and count < 10

                     i = 1
           while i <= len (faceToken$) and mid$(faceToken$, i, 1) <> "/"
               i = i + 1
           wend

                      faceVertex (faceCount)(count) = val (left$ (faceToken$, i - 1)) - 1

          
           i = i + 1
           while i <= len (faceToken$) and mid$(faceToken$, i, 1) <> "/"
               i = i + 1
           wend

                     faceNormal (faceCount)(count) = val (mid$ (faceToken$, i + 1, 999)) - 1
           count = count + 1

                     faceToken$ = ReadText (inFile, false)
       wend
       faceVertexCount (faceCount) = count
       faceCount = faceCount + 1
   endif

  
   while ReadText (inFile, false) <> "": wend
wend
CloseFile (inFile)

printr vertexCount + " vertices"
printr normalCount + " normals"
printr faceCount + " faces"

printr "Writing output file"

outfile = OpenFileWrite ("files\Generated.gb")
if FileError () <> "" then
   printr FileError ()
   end
endif

WriteLine (outfile, "dim a#")
WriteLine (outfile, "glEnable (GL_LIGHTING)")
WriteLine (outfile, "glEnable (GL_LIGHT0)")
WriteLine (outfile, "while true")
WriteLine (outfile, "    glClear (GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)")
WriteLine (outfile, "    glLoadIdentity ()")
WriteLine (outfile, "    glTranslatef (0, 0, -10): glRotatef (25, 1, 0, 0): glRotatef (a#, 0, 1, 0)")
for i = 0 to faceCount - 1

      WriteLine (outFile, "    glBegin(GL_TRIANGLE_FAN)")
   for j = 0 to faceVertexCount (i) - 1

             v# = vertex# (faceVertex (i)(j))
       n# = normal# (faceNormal (i)(j))

             for k = 0 to 2
           v#(k) = int (v#(k) * 10000) / 10000.0
           n#(k) = int (n#(k) * 10000) / 10000.0
       next

              WriteLine (outFile, "        glNormal3f(" + n#(0) + "," + n#(1) + "," + n#(2) + "): glVertex3f(" + v#(0) + "," + v#(1) + "," + v#(2) + ")")
   next
   WriteLine (outFile, "    glEnd()")
next

WriteLine (outfile, "    SwapBuffers ()")
WriteLine (outfile, "    a# = a# + 1")
WriteLine (outfile, "wend")

CloseFile (outFile)
printr "All done"
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#27
:lol: This is mine for FB, tho it still has alot of my debuggers REMed in it.. My personal use codes are always like this.. :lol: .. It works with Wings3D OBJ's, minus they aren't too big.. :wink:

Edit: Don't comment on any unnessisary code, I was writing it one way, and had to change alot of it which left allot of things unneeded that still works.. I didn't feel like removing all of it.. :wink:

Code:
SCREEN 13

OPEN "FileName.obj" FOR INPUT AS #1
OPEN "FileName.bas" FOR OUTPUT AS #2
vert = 0
DO
    IF init = 0 THEN INPUT #1, Blank1: init = 1
    
    LINE INPUT #1, LineRender$
    '###########################
    '# Find number of vertices #
    '###########################
    IF MID$(LineRender$, 1, 1) = "#" THEN
        cont = 2
        FOR i = 2 TO LEN(LineRender$)
            cont += 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            NmTx$ += MID$(LineRender$, i, 1)
        NEXT
        Num = VAL(NmTx$)
        'FOR i = (cont + 10) TO LEN(LineRender$)
            'IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            'Fac = Fac + VAL(MID$(LineRender$, i, 1))
       ' NEXT
        DIM SHARED Vertex(Num, 3) as string
        DIM SHARED Normal(Num, 3) as string
        'DIM SHARED Face(Fac, 8) as string
    END IF
    '###########################
    '# Find value of vertices  #
    '###########################
    IF MID$(LineRender$, 1, 2) = "v " THEN
        vert = vert + 1
        cont1 = 3
        FOR i = 3 TO LEN(LineRender$)
            cont1 = cont1 + 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            IF MID$(LineRender$, 3, 1) = "-" THEN
                Vertex(vert, 1) += MID$(LineRender$, i, 1)
            ELSE
                Vertex(vert, 1) += MID$(LineRender$, i, 1)
            END IF
        NEXT
        cont2 = cont1
        FOR i = cont2 TO LEN(LineRender$)
            cont2 = cont2 + 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            IF MID$(LineRender$, cont1, 1) = "-" THEN
                Vertex(vert, 2) += MID$(LineRender$, i, 1)
            ELSE
                Vertex(vert, 2) += MID$(LineRender$, i, 1)
            END IF
        NEXT
        cont3 = cont2
        FOR i = cont3 TO LEN(LineRender$)
            cont3 = cont3 + 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            IF MID$(LineRender$, cont2, 1) = "-" THEN
                Vertex(vert, 3) += MID$(LineRender$, i, 1)
            ELSE
                Vertex(vert, 3) += MID$(LineRender$, i, 1)
            END IF
        NEXT
    END IF
    '###########################
    '# Find value of Normals   #
    '###########################
    IF MID$(LineRender$, 1, 2) = "vn" THEN
        norm = norm + 1
        cont1 = 4
        FOR i = 4 TO LEN(LineRender$)
            cont1 = cont1 + 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            IF MID$(LineRender$, 4, 1) = "-" THEN
                Normal(norm, 1) += MID$(LineRender$, i, 1)              
            ELSE
                Normal(norm, 1) += MID$(LineRender$, i, 1)
            END IF
        NEXT
        cont2 = cont1
        FOR i = cont2 TO LEN(LineRender$)
            cont2 = cont2 + 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            IF MID$(LineRender$, cont1, 1) = "-" THEN
                Normal(norm, 2) += MID$(LineRender$, i, 1)
            ELSE
                Normal(norm, 2) += MID$(LineRender$, i, 1)
            END IF
        NEXT
        cont3 = cont2
        FOR i = cont3 TO LEN(LineRender$)
            cont3 = cont3 + 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            IF MID$(LineRender$, cont2, 1) = "-" THEN
                Normal(norm, 3) += MID$(LineRender$, i, 1)
            ELSE
                Normal(norm, 3) += MID$(LineRender$, i, 1)
            END IF
        NEXT
    END IF
    '###########################
    '# Find Order Ratios       #
    '###########################
    IF MID$(LineRender$, 1, 2) = "f " THEN
        cont = 3
        DO
            IF MID$(LineRender$, cont, 1) = "/" THEN
                Number = VAL(Face$)
                PRINT #2, "glNormal3f ",  Normal(Number, 1), ",", Normal(Number, 2), ",", Normal(Number, 3)
                'PRINT #2, "glVertex3f", Vertex(Number, 1), ",", Vertex(Number, 2), ",", Vertex(Number, 3)
                cont += 2
                'PRINT Face$
                'SLEEP 100
                Face$ = ""
            'END IF
            ELSEIF MID$(LineRender$, cont, 1) = " " THEN
                Number = VAL(Face$)
                'PRINT #2, "glNormal3f ",  Normal(Number, 1), ",", Normal(Number, 2), ",", Normal(Number, 3)
                PRINT #2, "glVertex3f", Vertex(Number, 1), ",", Vertex(Number, 2), ",", Vertex(Number, 3)
                cont += 1
                'PRINT Face$
               ' SLEEP 100
                Face$ = ""
            ELSEIF cont >= LEN(LineRender$) THEN
                Face$ += MID$(LineRender$, cont, 1)
                Number = VAL(Face$)
                'PRINT #2, "glNormal3f ",  Normal(Number, 1), ",", Normal(Number, 2), ",", Normal(Number, 3)
                PRINT #2, "glVertex3f", Vertex(Number, 1), ",", Vertex(Number, 2), ",", Vertex(Number, 3)
                cont += 1
                'PRINT Face$
                'SLEEP 100
                Face$ = ""
                EXIT DO
            END IF
            Face$ += MID$(LineRender$, cont, 1)
            cont += 1
        LOOP
    END IF
    IF INKEY$ = CHR$(255) + "X" THEN END
LOOP UNTIL EOF(1)
CLOSE #1
CLOSE #2

'FOR i = 1 TO Num
'PRINT Vertex(i, 1); Vertex(i, 2); Vertex(i, 3)
'NEXT
'FOR i = 1 TO Num
'PRINT Normal(i, 1); Normal(i, 2); Normal(i, 3)
'NEXT
PRINT "Done!!"
SLEEP
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#28
lol, thats awesome... maybe we should start a challange in the challanges area, it would be

"write the smallest .obj file to openGL code converter"

and ":" symbols would obviously not be alloud

:lol:

(i bet the community thought i died)
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#29
Hehehe.. yeah, mine can be shorter.. lets see.. Heres a slim-fast version, works all the same tho.. :lol: (Removed Debugers, and needless code)

Dead? No, I figured you were at your forum.. I tried to venture there a couple of times, but my browser crashes, or basicaly stops loading when I get there.. Sad ...

Code:
SCREEN 13

OPEN "FileName.obj" FOR INPUT AS #1
OPEN "FileName.bas" FOR OUTPUT AS #2
vert = 0
DO
    IF init = 0 THEN INPUT #1, Blank1: init = 1
    
    LINE INPUT #1, LineRender$
    '###########################
    '# Find number of vertices #
    '###########################
    IF MID$(LineRender$, 1, 1) = "#" THEN
        cont = 2
        FOR i = 2 TO LEN(LineRender$)
            cont += 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            NmTx$ += MID$(LineRender$, i, 1)
        NEXT
        Num = VAL(NmTx$)
        DIM SHARED Vertex(Num, 3) as string
        DIM SHARED Normal(Num, 3) as string
    END IF
    '###########################
    '# Find value of vertices  #
    '###########################
    IF MID$(LineRender$, 1, 2) = "v " THEN
        vert = vert + 1
        cont1 = 3
        FOR i = 3 TO LEN(LineRender$)
            cont1 = cont1 + 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            Vertex(vert, 1) += MID$(LineRender$, i, 1)
        NEXT
        cont2 = cont1
        FOR i = cont2 TO LEN(LineRender$)
            cont2 = cont2 + 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            Vertex(vert, 2) += MID$(LineRender$, i, 1)
        NEXT
        cont3 = cont2
        FOR i = cont3 TO LEN(LineRender$)
            cont3 = cont3 + 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            Vertex(vert, 3) += MID$(LineRender$, i, 1)
        NEXT
    END IF
    '###########################
    '# Find value of Normals   #
    '###########################
    IF MID$(LineRender$, 1, 2) = "vn" THEN
        norm = norm + 1
        cont1 = 4
        FOR i = 4 TO LEN(LineRender$)
            cont1 = cont1 + 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            Normal(norm, 1) += MID$(LineRender$, i, 1)
        NEXT
        cont2 = cont1
        FOR i = cont2 TO LEN(LineRender$)
            cont2 = cont2 + 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            Normal(norm, 2) += MID$(LineRender$, i, 1)
        NEXT
        cont3 = cont2
        FOR i = cont3 TO LEN(LineRender$)
            cont3 = cont3 + 1
            IF MID$(LineRender$, i, 1) = " " THEN EXIT FOR
            Normal(norm, 3) += MID$(LineRender$, i, 1)
        NEXT
    END IF
    '###########################
    '# Find Order Ratios       #
    '###########################
    IF MID$(LineRender$, 1, 2) = "f " THEN
        cont = 3
        DO
            IF MID$(LineRender$, cont, 1) = "/" THEN
                Number = VAL(Face$)
                PRINT #2, "glNormal3f ",  Normal(Number, 1), ",", Normal(Number, 2), ",", Normal(Number, 3)
                cont += 2
                Face$ = ""
            ELSEIF MID$(LineRender$, cont, 1) = " " THEN
                Number = VAL(Face$)
                PRINT #2, "glVertex3f", Vertex(Number, 1), ",", Vertex(Number, 2), ",", Vertex(Number, 3)
                cont += 1
                Face$ = ""
            ELSEIF cont >= LEN(LineRender$) THEN
                Face$ += MID$(LineRender$, cont, 1)
                Number = VAL(Face$)
                PRINT #2, "glVertex3f", Vertex(Number, 1), ",", Vertex(Number, 2), ",", Vertex(Number, 3)
                cont += 1
                Face$ = ""
                EXIT DO
            END IF
            Face$ += MID$(LineRender$, cont, 1)
            cont += 1
        LOOP
    END IF
    IF INKEY$ = CHR$(255) + "X" THEN END
LOOP UNTIL EOF(1)
CLOSE #1
CLOSE #2
PRINT "Done!!"
SLEEP
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#30
hehe, check your blue orb thread for the obj file i tried to convert, it crashed your program :lol: :lol:
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)