home *** CD-ROM | disk | FTP | other *** search
- '------------------------------------------------------------------\
- ' Vcad2PV.BAS - Makes PV Ray Tracer Compatible Triangle Data |
- ' Files from VersaCAD Complex Polygon or Extrusion |
- ' ASCII Files created using the vcad2pv.mac macro |
- ' (or compatible ASCII input files) |
- ' |
- ' Robert Cleere (CIS 72050,3677) Ver. 2.0 09/24/91 |
- '------------------------------------------------------------------/
- ' Revision History \
- ' ---------------- |
- ' |
- ' Rev 1.0 09/09/91 Basic Release |
- ' |
- ' Rev 1.1 09/16/91 Fixed coordinate read problem (GetData) |
- ' |
- ' Rev 2.0 09/24/91 Converted output file to PVRay Format |
- '------------------------------------------------------------------/
-
-
- CLS
-
- DEFINT I
-
- DEFSNG E, S, X-Z ' Single Precision Variables
-
- DEFSTR A-E ' String Variables
-
- ZExt = 0 ' Z Extrusion Depth (Relative to File Value)
-
- NodeCom$ = "" ' Node Coordinate String (Common - Poly Only)
-
- NodeA$ = "" ' Node Coordinate String (Node A - Poly/Ext)
- NodeB$ = "" ' Node Coordinate String (Node B - Poly/Ext)
- NodeC$ = "" ' Node Coordinate String (Node C - Ext Only)
- NodeD$ = "" ' Node Coordinate String (Node D - Ext Only)
-
- Extrude$ = "n" ' Complex Polygon or Extrusion Flag
-
- COLOR 3
- PRINT "/--------------------------------------------------------\"
- PRINT "| VersaCad to Persistance of Vision Ray Tracer Converter |"
- PRINT "|--------------------------------------------------------|"
- PRINT "| Version 2.0 Robert Cleere 09/24/91 |"
- PRINT "|--------------------------------------------------------|"
- PRINT "| This program Makes PV Ray Tracer Compatible Triangle |"
- PRINT "| Data Files from VersaCAD Complex Polygon or Extrusion |"
- PRINT "| ASCII Files created using the VCAD2PV.MAC macro |"
- PRINT "| (or compatible ASCII input files) |"
- PRINT "\--------------------------------------------------------/"
- COLOR 7
- PRINT
- INPUT "Input Filename "; InFile$
- INPUT "Output Filename "; OutFile$
- PRINT
- INPUT "Is the data file a Z Axis Extrusion (y/n) "; Extrude$
- PRINT
-
- OPEN InFile$ FOR INPUT AS #1 ' Open Files
- OPEN OutFile$ FOR OUTPUT AS #2
-
- ON ERROR GOTO EndOfFile ' Set EOF Trap
-
- '----------------- Copy Header from Input File ---------------------
-
- i1 = 1
-
- DO
-
- INPUT #1, a$ ' Copy 1st 7 Lines of File
- PRINT #2, a$
-
- i1 = i1 + 1
-
- LOOP WHILE i1 < 8
-
- PRINT #2, ""
-
- '-------------- Write .DAT File Header to Output File --------------
-
- PRINT #2, "Declare Name = /* Declare Object */"
- PRINT #2, ""
- PRINT #2, " Object"
- PRINT #2, ""
- PRINT #2, " Union"
-
- '------------- Jump to Extrude Routine if Selected -----------------
-
- IF Extrude$ = "y" OR Extrude$ = "Y" THEN GOTO Extrude
-
- '-----------------------------------------------------------------\
- Plane: ' Figure Triangles from Complex Polygon File |
- '------------------------------------------------------------------|
- ' |
- ' This method builds 3 sided triangles from a complex polygon. |
- ' The program assumes the viewer is looking along the Z axis. | |
- ' |
- '------------------ Example Input Coordinates ---------------------|
- ' |
- ' (Common) |
- ' 2 1 5 |
- ' o---------------o---------------o |
- ' \ / |
- ' \ / |
- ' \ / |
- ' \ / |
- ' o---------------o |
- ' 3 4 |
- ' |
- '------------------------------------------------------------------|
- ' |
- '------------------- Example Output Triangles ---------------------|
- ' |
- ' o---------------o---------------o |
- ' \ / \ / |
- ' \ A / \ C / |
- ' \ / B \ / |
- ' \ / \ / |
- ' o---------------o |
- ' |
- '------------------------------------------------------------------|
-
- ReadPlane: ' Get Common Node from File
-
- INPUT #1, a$ ' Read Line from File
-
- IF MID$(a$, 1, 2) = "/*" THEN GOTO ReadPlane ' Skip Line if Comment
-
- GOSUB GetData ' Break a$ into x - y - z
-
- GOSUB FixLength ' Make Number 10 Characters Long
-
- NodeCom$ = b$ + " " + c$ + " " + d$ ' Build Common Node String
-
- ReadPlane1: ' Get Node A from Input File
-
- INPUT #1, a$ ' Read Line From File
-
- IF MID$(a$, 1, 2) = "/*" THEN GOTO ReadPlane1' Skip Line if Comment
-
- IF a$ = "" THEN GOTO ReadPlane1 ' Skip Line if Blank
-
- GOSUB GetData ' Break a$ into x - y - z
-
- GOSUB FixLength
-
- NodeA$ = b$ + " " + c$ + " " + d$ ' Build Node A String
-
- ReadPlane2: ' Get Next Node
-
- INPUT #1, a$ ' Read Line From File
-
- IF MID$(a$, 1, 2) = "/*" THEN GOTO ReadPlane2' Skip Comments
-
- IF a$ = "" THEN GOTO ReadPlane2 ' Skip Line if Blank
-
- GOSUB GetData ' Break a$ into x - y - z
-
- GOSUB FixLength ' Make Strings 10 char long
-
- NodeB$ = b$ + " " + c$ + " " + d$ ' Build Node B String
-
- ' Add Triangle to .DAT File
-
- PRINT #2, " "
- PRINT #2, " Triangle < "; NodeCom$; " >"
- PRINT #2, " < "; NodeA$; " >"
- PRINT #2, " < "; NodeB$; " >"
- PRINT #2, " End_Triangle"
-
- NodeA$ = NodeB$ ' Swap Nodes for next triangle
-
- GOTO ReadPlane2 ' Resume Read
-
- '-----------------------------------------------------------------\
- Extrude: ' Figure Extrusion from File |
- '------------------------------------------------------------------|
- ' |
- ' This method builds 3 sided triangles from coordinate pairs and |
- ' assumes the viewer is looking along the Z axis. |
- ' |
- '---------------- Example Input Coordinates -----------------------|
- ' |
- ' pt1 pt2 |
- ' (0,0,0) (10,0,0) |
- ' o o |
- ' |
- '------------------------------------------------------------------|
- ' |
- '----------------- Example Output Triangles -----------------------|
- ' |
- ' ptA ptB |
- ' (0,0,0) (10,0,0) |
- ' o------------o |
- ' | /| |
- ' | / | |
- ' | / | |
- ' | / | |
- ' | / | |
- ' | / | |
- ' o------------o |
- ' (0,0,5) (10,0,5) |
- ' ptD ptC |
- ' |
- ' Resulting DAT File has two triangles (A-B-D and B-C-D) |
- ' |
- '------------------------------------------------------------------/
-
- INPUT "Enter Z Extrusion Value "; ZExt
- PRINT
-
- ReadExt:
-
- INPUT #1, a$ ' Read Line from File
-
- IF MID$(a$, 1, 2) = "/*" THEN GOTO ReadExt ' Skip Comments
-
- IF a$ = "" THEN GOTO ReadExt ' Skip Line if Blank
-
- GOSUB GetData ' Break a$ into x - y - z
-
- GOSUB FixLength
-
- NodeA$ = b$ + " " + c$ + " " + d$ ' Build Node A String
-
- s1 = VAL(d$) ' Get Z Coordinate - Numeric
-
- s1 = s1 + ZExt ' Change Z Value for Node C Calc
-
- d$ = STR$(s1) ' Get Z Coordinate - String
-
- GOSUB FixLength
-
- NodeD$ = b$ + " " + c$ + " " + d$ ' Build Node D String
-
- ReadExt2: ' Get Nodes B and C
-
- INPUT #1, a$ ' Read Line From File
-
- IF MID$(a$, 1, 2) = "/*" THEN GOTO ReadExt2 ' Skip Comments
-
- IF a$ = "" THEN GOTO ReadExt2 ' Skip Line if Blank
-
- GOSUB GetData ' Break a$ into x - y - z
-
- GOSUB FixLength
-
- NodeB$ = b$ + " " + c$ + " " + d$ ' Build Node B String
-
- s1 = VAL(d$) ' Get Z Coordinate - Numeric
-
- s1 = s1 + ZExt ' Change Z Value for Node C Calc
-
- d$ = STR$(s1) ' Get Z Coordinate - String
-
- GOSUB FixLength
-
- NodeC$ = b$ + " " + c$ + " " + d$ ' Build Node C String
-
- ' Add Both Triangles to .DAT File
-
- PRINT #2, " "
- PRINT #2, " Triangle < "; NodeA$; " >"
- PRINT #2, " < "; NodeB$; " >"
- PRINT #2, " < "; NodeD$; " >"
- PRINT #2, " End_Triangle"
- PRINT #2, " "
- PRINT #2, " Triangle < "; NodeB$; " >"
- PRINT #2, " < "; NodeC$; " >"
- PRINT #2, " < "; NodeD$; " >"
- PRINT #2, " End_Triangle"
-
- NodeA$ = NodeB$ ' Swap Nodes
- NodeD$ = NodeC$
-
- GOTO ReadExt2 ' Resume Read
-
-
- '-----------------------------------------------------------------\
- FixLength: '|
- '-----------------------------------------------------------------/
-
- ' ALL this routine does is to make each coordinate string value 10
- ' characters long to produce a nicely aligned output file. I KNOW
- ' there are more elegant ways to do this but it does work !
-
- ' Add 0 to left of Decimal point of X coordinate if needed
-
- a$ = b$
- IF LEFT$(b$, 2) = "-." THEN a$ = RIGHT$(b$, LEN(b$) - 1)
- IF LEFT$(b$, 2) = "-." THEN b$ = "-0" + a$
-
- IF LEFT$(b$, 2) = " ." THEN a$ = RIGHT$(b$, LEN(b$) - 1)
- IF LEFT$(b$, 2) = " ." THEN b$ = " 0" + a$
-
- ' Add 0 to left of Decimal point of Y coordinate if needed
-
- a$ = c$
- IF LEFT$(c$, 2) = "-." THEN a$ = RIGHT$(c$, LEN(c$) - 1)
- IF LEFT$(c$, 2) = "-." THEN c$ = "-0" + a$
-
- IF LEFT$(c$, 2) = " ." THEN a$ = RIGHT$(c$, LEN(c$) - 1)
- IF LEFT$(c$, 2) = " ." THEN c$ = " 0" + a$
-
- ' Add 0 to left of Decimal point of Z coordinate if needed
-
- a$ = d$
- IF LEFT$(d$, 2) = "-." THEN a$ = RIGHT$(d$, LEN(d$) - 1)
- IF LEFT$(d$, 2) = "-." THEN d$ = "-0" + a$
-
- IF LEFT$(d$, 2) = " ." THEN a$ = RIGHT$(d$, LEN(d$) - 1)
- IF LEFT$(d$, 2) = " ." THEN d$ = " 0" + a$
-
- i1 = LEN(b$)
-
- IF i1 = 9 THEN b$ = b$ + " "
- IF i1 = 8 THEN b$ = b$ + " "
- IF i1 = 7 THEN b$ = b$ + " "
- IF i1 = 6 THEN b$ = b$ + " "
- IF i1 = 5 THEN b$ = b$ + " "
- IF i1 = 4 THEN b$ = b$ + " "
- IF i1 = 3 THEN b$ = b$ + " "
- IF i1 = 2 THEN b$ = b$ + " "
- IF i1 = 1 THEN b$ = b$ + " "
-
- i1 = LEN(c$)
-
- IF i1 = 9 THEN c$ = c$ + " "
- IF i1 = 8 THEN c$ = c$ + " "
- IF i1 = 7 THEN c$ = c$ + " "
- IF i1 = 6 THEN c$ = c$ + " "
- IF i1 = 5 THEN c$ = c$ + " "
- IF i1 = 4 THEN c$ = c$ + " "
- IF i1 = 3 THEN c$ = c$ + " "
- IF i1 = 2 THEN c$ = c$ + " "
- IF i1 = 1 THEN c$ = c$ + " "
-
- i1 = LEN(d$)
-
- IF i1 = 9 THEN d$ = d$ + " ": RETURN
- IF i1 = 8 THEN d$ = d$ + " ": RETURN
- IF i1 = 7 THEN d$ = d$ + " ": RETURN
- IF i1 = 6 THEN d$ = d$ + " ": RETURN
- IF i1 = 5 THEN d$ = d$ + " ": RETURN
- IF i1 = 4 THEN d$ = d$ + " ": RETURN
- IF i1 = 3 THEN d$ = d$ + " ": RETURN
- IF i1 = 2 THEN d$ = d$ + " ": RETURN
- IF i1 = 1 THEN d$ = d$ + " ": RETURN
-
- '-----------------------------------------------------------------\
- EndOfFile: '|
- '-----------------------------------------------------------------/
-
- '--------------- Write .DAT File Trailer to File ------------------
-
- PRINT #2, " "
- PRINT #2, " End_Union"
- PRINT #2, " "
- PRINT #2, " Scale < 1.00 1.00 1.00 >"
- PRINT #2, ""
- PRINT #2, " End_Object"
- PRINT #2, ""
-
- CLOSE #1 ' Close Input File
-
- CLOSE #2 ' Close Output File
-
- PRINT "Conversion Complete"
-
- SYSTEM ' Return to System
-
-
- '-----------------------------------------------------------------\
- GetData: '|
- '-----------------------------------------------------------------/
-
- ' Breaks down coordinate trio string into separate strings
- '
- ' Input = a$ (String with three numeric values - x,y,z )
- ' Output = b$,c$,d$ (Strings - x,y,z coord respectively)
-
- i1 = 0 ' Zero String Pointer
-
- GOSUB GetNumber ' Get X Coordinate
- b$ = f$
-
- GOSUB GetNumber ' Get Y Coordinate
- c$ = f$
-
- GOSUB GetNumber ' Get Z Coordinate
- d$ = f$
-
- RETURN
-
-
- GetNumber:
-
- f$ = ""
-
- GetNum1:
-
- i1 = i1 + 1
-
- IF MID$(a$, i1, 1) = " " THEN GOTO GetNum1 ' Skip Leading Spaces
-
- GetNum2:
-
- f$ = f$ + MID$(a$, i1, 1) ' Add this Char to String
-
- i1 = i1 + 1 ' Inc string position pointer
-
- IF i1 > LEN(a$) THEN RETURN ' Return if end of String
-
- IF MID$(a$, i1, 1) = " " THEN RETURN ' Return if end of Number
-
- GOTO GetNum2 ' Continue building string
-
-
-