home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / VCAD2P.ZIP / VCAD2PV.BAS < prev    next >
Encoding:
BASIC Source File  |  1991-09-19  |  15.6 KB  |  418 lines

  1. '------------------------------------------------------------------\
  2. '  Vcad2PV.BAS - Makes PV Ray Tracer Compatible Triangle Data      |
  3. '                Files from VersaCAD Complex Polygon or Extrusion  |
  4. '                ASCII Files created using the vcad2pv.mac macro   |          
  5. '                (or compatible ASCII input files)                 |             
  6. '                                                                  |
  7. '      Robert Cleere (CIS 72050,3677)    Ver. 2.0     09/24/91     |
  8. '------------------------------------------------------------------/
  9. '                         Revision History                         \
  10. '                         ----------------                         |
  11. '                                                                  |
  12. '  Rev 1.0      09/09/91   Basic Release                           |
  13. '                                                                  |
  14. '  Rev 1.1      09/16/91   Fixed coordinate read problem (GetData) |
  15. '                                                                  |
  16. '  Rev 2.0      09/24/91   Converted output file to PVRay Format   |
  17. '------------------------------------------------------------------/
  18.  
  19.  
  20. CLS
  21.  
  22. DEFINT I
  23.  
  24. DEFSNG E, S, X-Z            ' Single Precision Variables
  25.  
  26. DEFSTR A-E                  ' String Variables
  27.  
  28. ZExt = 0                    ' Z Extrusion Depth (Relative to File Value)
  29.  
  30. NodeCom$ = ""               ' Node Coordinate String (Common - Poly Only)
  31.  
  32. NodeA$ = ""                 ' Node Coordinate String (Node A - Poly/Ext)
  33. NodeB$ = ""                 ' Node Coordinate String (Node B - Poly/Ext)
  34. NodeC$ = ""                 ' Node Coordinate String (Node C - Ext Only)
  35. NodeD$ = ""                 ' Node Coordinate String (Node D - Ext Only)
  36.  
  37. Extrude$ = "n"              ' Complex Polygon or Extrusion Flag
  38.  
  39. COLOR 3
  40. PRINT "/--------------------------------------------------------\"
  41. PRINT "| VersaCad to Persistance of Vision Ray Tracer Converter |"
  42. PRINT "|--------------------------------------------------------|"
  43. PRINT "| Version 2.0                   Robert Cleere   09/24/91 |"
  44. PRINT "|--------------------------------------------------------|"
  45. PRINT "| This program Makes PV Ray Tracer Compatible Triangle   |"
  46. PRINT "| Data Files from VersaCAD Complex Polygon or Extrusion  |"
  47. PRINT "| ASCII Files created using the VCAD2PV.MAC macro        |"
  48. PRINT "| (or compatible ASCII input files)                      |"
  49. PRINT "\--------------------------------------------------------/"
  50. COLOR 7
  51. PRINT
  52. INPUT "Input  Filename "; InFile$
  53. INPUT "Output Filename "; OutFile$
  54. PRINT
  55. INPUT "Is the data file a Z Axis Extrusion (y/n) "; Extrude$
  56. PRINT
  57.  
  58. OPEN InFile$ FOR INPUT AS #1                 ' Open Files
  59. OPEN OutFile$ FOR OUTPUT AS #2
  60.  
  61. ON ERROR GOTO EndOfFile                      ' Set EOF Trap
  62.  
  63. '----------------- Copy Header from Input File ---------------------
  64.  
  65. i1 = 1
  66.  
  67. DO
  68.  
  69.   INPUT #1, a$                               ' Copy 1st 7 Lines of File
  70.   PRINT #2, a$
  71.  
  72.   i1 = i1 + 1
  73.  
  74. LOOP WHILE i1 < 8
  75.  
  76. PRINT #2, ""
  77.  
  78. '-------------- Write .DAT File Header to Output File --------------
  79.  
  80. PRINT #2, "Declare Name =                /* Declare Object */"
  81. PRINT #2, ""
  82. PRINT #2, "  Object"
  83. PRINT #2, ""
  84. PRINT #2, "    Union"
  85.  
  86. '------------- Jump to Extrude Routine if Selected -----------------
  87.  
  88. IF Extrude$ = "y" OR Extrude$ = "Y" THEN GOTO Extrude
  89.  
  90. '-----------------------------------------------------------------\
  91. Plane:               ' Figure Triangles from Complex Polygon File  |
  92. '------------------------------------------------------------------|
  93. '                                                                  |
  94. ' This method builds 3 sided triangles from a complex polygon.     |
  95. ' The program assumes the viewer is looking along the Z axis.      |            |
  96. '                                                                  |
  97. '------------------ Example Input Coordinates ---------------------|
  98. '                                                                  |
  99. '                            (Common)                              |
  100. '              2                 1                 5               |
  101. '                o---------------o---------------o                 |
  102. '                 \                             /                  |
  103. '                   \                         /                    |
  104. '                     \                     /                      |
  105. '                       \                 /                        |
  106. '                        o---------------o                         |
  107. '                       3                 4                        |
  108. '                                                                  |
  109. '------------------------------------------------------------------|
  110. '                                                                  |
  111. '------------------- Example Output Triangles ---------------------|
  112. '                                                                  |
  113. '                o---------------o---------------o                 |
  114. '                 \             / \             /                  |
  115. '                   \    A    /     \    C    /                    |
  116. '                     \     /    B    \     /                      |
  117. '                       \ /             \ /                        |
  118. '                        o---------------o                         |
  119. '                                                                  |
  120. '------------------------------------------------------------------|
  121.  
  122. ReadPlane:                                   ' Get Common Node from File
  123.  
  124. INPUT #1, a$                                 ' Read Line from File
  125.  
  126. IF MID$(a$, 1, 2) = "/*" THEN GOTO ReadPlane ' Skip Line if Comment
  127.  
  128. GOSUB GetData                                ' Break a$ into x - y - z
  129.  
  130. GOSUB FixLength                              ' Make Number 10 Characters Long
  131.  
  132. NodeCom$ = b$ + "  " + c$ + "  " + d$        ' Build Common Node String
  133.  
  134. ReadPlane1:                                  ' Get Node A from Input File
  135.  
  136. INPUT #1, a$                                 ' Read Line From File
  137.  
  138. IF MID$(a$, 1, 2) = "/*" THEN GOTO ReadPlane1' Skip Line if Comment
  139.  
  140. IF a$ = "" THEN GOTO ReadPlane1              ' Skip Line if Blank
  141.  
  142. GOSUB GetData                                ' Break a$ into x - y - z
  143.  
  144. GOSUB FixLength
  145.  
  146. NodeA$ = b$ + "  " + c$ + "  " + d$          ' Build Node A String
  147.  
  148. ReadPlane2:                                  ' Get Next Node
  149.  
  150. INPUT #1, a$                                 ' Read Line From File
  151.  
  152. IF MID$(a$, 1, 2) = "/*" THEN GOTO ReadPlane2' Skip Comments
  153.  
  154. IF a$ = "" THEN GOTO ReadPlane2              ' Skip Line if Blank
  155.  
  156. GOSUB GetData                                ' Break a$ into x - y - z
  157.  
  158. GOSUB FixLength                              ' Make Strings 10 char long
  159.  
  160. NodeB$ = b$ + "  " + c$ + "  " + d$          ' Build Node B String
  161.  
  162. ' Add Triangle to .DAT File
  163.  
  164. PRINT #2, "   "
  165. PRINT #2, "      Triangle    < "; NodeCom$; " >"
  166. PRINT #2, "                  < "; NodeA$; " >"
  167. PRINT #2, "                  < "; NodeB$; " >"
  168. PRINT #2, "      End_Triangle"
  169.  
  170. NodeA$ = NodeB$                              ' Swap Nodes for next triangle
  171.  
  172.    GOTO ReadPlane2                           ' Resume Read
  173.  
  174. '-----------------------------------------------------------------\
  175. Extrude:                              ' Figure Extrusion from File |
  176. '------------------------------------------------------------------|
  177. '                                                                  |
  178. ' This method builds 3 sided triangles from coordinate pairs and   |
  179. ' assumes the viewer is looking along the Z axis.                  |
  180. '                                                                  |
  181. '---------------- Example Input Coordinates -----------------------|
  182. '                                                                  |
  183. '                    pt1          pt2                              |
  184. '                 (0,0,0)       (10,0,0)                           |
  185. '                    o            o                                |
  186. '                                                                  |
  187. '------------------------------------------------------------------|
  188. '                                                                  |
  189. '----------------- Example Output Triangles -----------------------|
  190. '                                                                  |
  191. '                    ptA          ptB                              |
  192. '                  (0,0,0)      (10,0,0)                           |
  193. '                     o------------o                               |
  194. '                     |           /|                               |
  195. '                     |         /  |                               |
  196. '                     |       /    |                               |
  197. '                     |     /      |                               |
  198. '                     |   /        |                               |
  199. '                     | /          |                               |
  200. '                     o------------o                               |
  201. '                  (0,0,5)      (10,0,5)                           |
  202. '                    ptD          ptC                              |
  203. '                                                                  |
  204. '    Resulting DAT File has two triangles (A-B-D and B-C-D)        |
  205. '                                                                  |
  206. '------------------------------------------------------------------/
  207.  
  208. INPUT "Enter Z Extrusion Value "; ZExt
  209. PRINT
  210.  
  211. ReadExt:
  212.  
  213. INPUT #1, a$                                 ' Read Line from File
  214.  
  215. IF MID$(a$, 1, 2) = "/*" THEN GOTO ReadExt   ' Skip Comments
  216.  
  217. IF a$ = "" THEN GOTO ReadExt                 ' Skip Line if Blank
  218.  
  219. GOSUB GetData                                ' Break a$ into x - y - z
  220.  
  221. GOSUB FixLength
  222.  
  223. NodeA$ = b$ + "  " + c$ + "  " + d$          ' Build Node A String
  224.  
  225. s1 = VAL(d$)                                 ' Get Z Coordinate - Numeric
  226.  
  227. s1 = s1 + ZExt                               ' Change Z Value for Node C Calc
  228.  
  229. d$ = STR$(s1)                                ' Get Z Coordinate - String
  230.  
  231. GOSUB FixLength
  232.  
  233. NodeD$ = b$ + "  " + c$ + "  " + d$          ' Build Node D String
  234.  
  235. ReadExt2:                                    ' Get Nodes B and C
  236.  
  237. INPUT #1, a$                                 ' Read Line From File
  238.  
  239. IF MID$(a$, 1, 2) = "/*" THEN GOTO ReadExt2  ' Skip Comments
  240.  
  241. IF a$ = "" THEN GOTO ReadExt2                ' Skip Line if Blank
  242.  
  243. GOSUB GetData                                ' Break a$ into x - y - z
  244.  
  245. GOSUB FixLength
  246.  
  247. NodeB$ = b$ + "  " + c$ + "  " + d$          ' Build Node B String
  248.  
  249. s1 = VAL(d$)                                 ' Get Z Coordinate - Numeric
  250.  
  251. s1 = s1 + ZExt                               ' Change Z Value for Node C Calc
  252.  
  253. d$ = STR$(s1)                                ' Get Z Coordinate - String
  254.  
  255. GOSUB FixLength
  256.  
  257. NodeC$ = b$ + "  " + c$ + "  " + d$          ' Build Node C String
  258.  
  259. ' Add Both Triangles to .DAT File
  260.  
  261. PRINT #2, "   "
  262. PRINT #2, "      Triangle    < "; NodeA$; " >"
  263. PRINT #2, "                  < "; NodeB$; " >"
  264. PRINT #2, "                  < "; NodeD$; " >"
  265. PRINT #2, "      End_Triangle"
  266. PRINT #2, "   "
  267. PRINT #2, "      Triangle    < "; NodeB$; " >"
  268. PRINT #2, "                  < "; NodeC$; " >"
  269. PRINT #2, "                  < "; NodeD$; " >"
  270. PRINT #2, "      End_Triangle"
  271.  
  272. NodeA$ = NodeB$                              ' Swap Nodes
  273. NodeD$ = NodeC$
  274.   
  275.    GOTO ReadExt2                             ' Resume Read
  276.                        
  277.  
  278. '-----------------------------------------------------------------\
  279. FixLength:                                                       '|
  280. '-----------------------------------------------------------------/
  281.  
  282. ' ALL this routine does is to make each coordinate string value 10
  283. ' characters long to produce a nicely aligned output file.  I KNOW
  284. ' there are more elegant ways to do this but it does work !
  285.  
  286. ' Add 0 to left of Decimal point of X coordinate if needed
  287.  
  288. a$ = b$
  289. IF LEFT$(b$, 2) = "-." THEN a$ = RIGHT$(b$, LEN(b$) - 1)
  290. IF LEFT$(b$, 2) = "-." THEN b$ = "-0" + a$
  291.  
  292. IF LEFT$(b$, 2) = " ." THEN a$ = RIGHT$(b$, LEN(b$) - 1)
  293. IF LEFT$(b$, 2) = " ." THEN b$ = " 0" + a$
  294.  
  295. ' Add 0 to left of Decimal point of Y coordinate if needed
  296.  
  297. a$ = c$
  298. IF LEFT$(c$, 2) = "-." THEN a$ = RIGHT$(c$, LEN(c$) - 1)
  299. IF LEFT$(c$, 2) = "-." THEN c$ = "-0" + a$
  300.  
  301. IF LEFT$(c$, 2) = " ." THEN a$ = RIGHT$(c$, LEN(c$) - 1)
  302. IF LEFT$(c$, 2) = " ." THEN c$ = " 0" + a$
  303.  
  304. ' Add 0 to left of Decimal point of Z coordinate if needed
  305.  
  306. a$ = d$
  307. IF LEFT$(d$, 2) = "-." THEN a$ = RIGHT$(d$, LEN(d$) - 1)
  308. IF LEFT$(d$, 2) = "-." THEN d$ = "-0" + a$
  309.  
  310. IF LEFT$(d$, 2) = " ." THEN a$ = RIGHT$(d$, LEN(d$) - 1)
  311. IF LEFT$(d$, 2) = " ." THEN d$ = " 0" + a$
  312.  
  313. i1 = LEN(b$)
  314.  
  315. IF i1 = 9 THEN b$ = b$ + " "
  316. IF i1 = 8 THEN b$ = b$ + "  "
  317. IF i1 = 7 THEN b$ = b$ + "   "
  318. IF i1 = 6 THEN b$ = b$ + "    "
  319. IF i1 = 5 THEN b$ = b$ + "     "
  320. IF i1 = 4 THEN b$ = b$ + "      "
  321. IF i1 = 3 THEN b$ = b$ + "       "
  322. IF i1 = 2 THEN b$ = b$ + "        "
  323. IF i1 = 1 THEN b$ = b$ + "         "
  324.  
  325. i1 = LEN(c$)
  326.  
  327. IF i1 = 9 THEN c$ = c$ + " "
  328. IF i1 = 8 THEN c$ = c$ + "  "
  329. IF i1 = 7 THEN c$ = c$ + "   "
  330. IF i1 = 6 THEN c$ = c$ + "    "
  331. IF i1 = 5 THEN c$ = c$ + "     "
  332. IF i1 = 4 THEN c$ = c$ + "      "
  333. IF i1 = 3 THEN c$ = c$ + "       "
  334. IF i1 = 2 THEN c$ = c$ + "        "
  335. IF i1 = 1 THEN c$ = c$ + "         "
  336.  
  337. i1 = LEN(d$)
  338.  
  339. IF i1 = 9 THEN d$ = d$ + " ": RETURN
  340. IF i1 = 8 THEN d$ = d$ + "  ": RETURN
  341. IF i1 = 7 THEN d$ = d$ + "   ": RETURN
  342. IF i1 = 6 THEN d$ = d$ + "    ": RETURN
  343. IF i1 = 5 THEN d$ = d$ + "     ": RETURN
  344. IF i1 = 4 THEN d$ = d$ + "      ": RETURN
  345. IF i1 = 3 THEN d$ = d$ + "       ": RETURN
  346. IF i1 = 2 THEN d$ = d$ + "        ": RETURN
  347. IF i1 = 1 THEN d$ = d$ + "         ": RETURN
  348.  
  349. '-----------------------------------------------------------------\
  350. EndOfFile:                                                       '|
  351. '-----------------------------------------------------------------/
  352.  
  353. '--------------- Write .DAT File Trailer to File ------------------
  354.                                             
  355. PRINT #2, "   "
  356. PRINT #2, "    End_Union"
  357. PRINT #2, "   "
  358. PRINT #2, "    Scale < 1.00 1.00 1.00 >"
  359. PRINT #2, ""
  360. PRINT #2, "  End_Object"
  361. PRINT #2, ""
  362.  
  363. CLOSE #1                                     ' Close Input File
  364.  
  365. CLOSE #2                                     ' Close Output File
  366.  
  367. PRINT "Conversion Complete"
  368.  
  369. SYSTEM                                       ' Return to System
  370.  
  371.  
  372. '-----------------------------------------------------------------\
  373. GetData:                                                         '|
  374. '-----------------------------------------------------------------/
  375.  
  376. ' Breaks down coordinate trio string into separate strings
  377. '
  378. ' Input  = a$       (String with three numeric values - x,y,z )
  379. ' Output = b$,c$,d$ (Strings - x,y,z coord respectively)
  380.  
  381. i1 = 0                                       ' Zero String Pointer
  382.  
  383. GOSUB GetNumber                              ' Get X Coordinate
  384. b$ = f$
  385.  
  386. GOSUB GetNumber                              ' Get Y Coordinate
  387. c$ = f$
  388.  
  389. GOSUB GetNumber                              ' Get Z Coordinate
  390. d$ = f$
  391.  
  392.       RETURN
  393.  
  394.  
  395. GetNumber:
  396.  
  397. f$ = ""
  398.  
  399. GetNum1:
  400.  
  401. i1 = i1 + 1
  402.  
  403. IF MID$(a$, i1, 1) = " " THEN GOTO GetNum1   ' Skip Leading Spaces
  404.  
  405. GetNum2:
  406.  
  407. f$ = f$ + MID$(a$, i1, 1)                    ' Add this Char to String
  408.  
  409. i1 = i1 + 1                                  ' Inc string position pointer
  410.  
  411. IF i1 > LEN(a$) THEN RETURN                  ' Return if end of String
  412.  
  413. IF MID$(a$, i1, 1) = " " THEN RETURN         ' Return if end of Number
  414.  
  415.     GOTO GetNum2                             ' Continue building string
  416.  
  417.  
  418.