N1% = 1
N2% = 2
PRINT "[PYRO-FYRE] 3D STUDIO 3DS2MTR CONVERTER"
PRINT
INPUT "Insert source file:", SOURCE$
INPUT "Insert target file:", TARGET$
OPEN "I", #1, SOURCE$
TARGET& = 1
OPEN "B", #2, TARGET$
N$ = "M-MODL "
N$ = N$ + STRING$(42, 32) + CHR$(&H1A)
FOR N% = 1 TO 50
  D% = ASC(MID$(N$, N%, 1))
  PUT #2, TARGET&, D%
  TARGET& = TARGET& + 1
NEXT

WHILE NOT EOF(1)
  WHILE NOT EOF(1) AND LEFT$(N$, 13) <> "Named object:"
    INPUT #1, N$
  WEND
  INPUT #1, N$
  INPUT #1, N$
  M$ = ""
  M% = 1
  DO
    K$ = MID$(N$, M%, 1)
    IF K$ = ":" THEN EXIT DO
    M% = M% + 1
  LOOP
  M% = M% + 2
  DO
    K$ = MID$(N$, M%, 1)
    IF K$ = " " THEN EXIT DO
    M$ = M$ + K$
    M% = M% + 1
  LOOP
  N% = VAL(M$)
  PUT #2, TARGET&, N%
  TARGET& = TARGET& + 2
  M$ = ""
  M% = M% + 1
  DO
    K$ = MID$(N$, M%, 1)
    IF K$ = ":" THEN EXIT DO
    M% = M% + 1
  LOOP
  M% = M% + 2
  DO
    K$ = MID$(N$, M%, 1)
    IF K$ = " " OR K$ = "" THEN EXIT DO
    M$ = M$ + K$
    M% = M% + 1
  LOOP
  N% = VAL(M$)
  PUT #2, TARGET&, N%
  TARGET& = TARGET& + 2
  M$ = ""
  WHILE NOT EOF(1) AND N$ <> "Vertex list:"
    INPUT #1, N$
  WEND
  WHILE NOT EOF(1) AND N$ <> "Face list:"
    INPUT #1, N$
    IF LEFT$(N$, 6) = "Vertex" THEN
      M$ = ""
      M% = 1
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = ":" THEN EXIT DO
        M% = M% + 1
      LOOP
      M% = M% + 1
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = ":" THEN EXIT DO
        M% = M% + 1
      LOOP
      M% = M% + 2
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = "." OR K$ = " " OR K$ = "" THEN EXIT DO
        M$ = M$ + K$
        M% = M% + 1
      LOOP
      N% = VAL(M$)
      PUT #2, TARGET&, N%
      TARGET& = TARGET& + 2
      M$ = ""
      M% = M% + 1
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = ":" THEN EXIT DO
        M% = M% + 1
      LOOP
      M% = M% + 2
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = "." OR K$ = " " OR K$ = "" THEN EXIT DO
        M$ = M$ + K$
        M% = M% + 1
      LOOP
      N% = VAL(M$)
      PUT #2, TARGET&, N%
      TARGET& = TARGET& + 2
      M$ = ""
      M% = M% + 1
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = ":" THEN EXIT DO
        M% = M% + 1
      LOOP
      M% = M% + 2
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = "." OR K$ = " " OR K$ = "" THEN EXIT DO
        M$ = M$ + K$
        M% = M% + 1
      LOOP
      N% = VAL(M$)
      PUT #2, TARGET&, N%
      TARGET& = TARGET& + 2
      M$ = ""
    END IF
  WEND
  WHILE NOT EOF(1)
    INPUT #1, N$
    IF LEFT$(N$, 4) = "Face" THEN
      M$ = ""
      M% = 1
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = ":" THEN EXIT DO
        M% = M% + 1
      LOOP
      M% = M% + 1
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = ":" THEN EXIT DO
        M% = M% + 1
      LOOP
      M% = M% + 1
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = " " THEN EXIT DO
        M$ = M$ + K$
        M% = M% + 1
      LOOP
      N% = VAL(M$)
      PUT #2, TARGET&, N%
      TARGET& = TARGET& + 2
      M$ = ""
      M% = M% + 1
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = ":" THEN EXIT DO
        M% = M% + 1
      LOOP
      M% = M% + 1
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = " " THEN EXIT DO
        M$ = M$ + K$
        M% = M% + 1
      LOOP
      N% = VAL(M$)
      PUT #2, TARGET&, N%
      TARGET& = TARGET& + 2
      M$ = ""
      M% = M% + 1
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = ":" THEN EXIT DO
        M% = M% + 1
      LOOP
      M% = M% + 1
      DO
        K$ = MID$(N$, M%, 1)
        IF K$ = " " OR K$ = "" THEN EXIT DO
        M$ = M$ + K$
        M% = M% + 1
      LOOP
      N% = VAL(M$)
      PUT #2, TARGET&, N%
      TARGET& = TARGET& + 2
      N% = N1%
      SWAP N1%, N2%
      PUT #2, TARGET&, N%
      TARGET& = TARGET& + 2
      M$ = ""
    END IF
  WEND
WEND
CLOSE #2
CLOSE #1
'Named object: "Object01"
'Tri-mesh, Vertices: 130     Faces: 256
'Vertex 0:  X: -0.576701     Y: 0.000006     Z: 40.406147
'Face list:
'Face 0:    A:0 B:4 C:11 AB:1 BC:1 CA:1
END

ERREUR:
PRINT "Error found!" + CHR$(7)
END

