home *** CD-ROM | disk | FTP | other *** search
/ Current Shareware 1994 January / SHAR194.ISO / graphuti / lparser2.zip / LPARSER.TXT < prev    next >
Text File  |  1993-10-13  |  19KB  |  451 lines

  1. ┌─────────┬────────────────────────────────┬───────────────────────────────┐
  2. │ Name:   │ L-SYSTEM PARSER/MUTATOR        │ (C) RenderStar Technology BV. │
  3. ├─────────┼────────────────────────────────┼──────────┬───────┬────────────┤
  4. │ Author: │ Laurens J. Lapre               │ Version: │  2.0  │ 1993-10-13 │
  5. ├─────────┴────────────────────────────────┴──────────┴───────┴────────────┤
  6. │ RenderStar Technology BV, Keizersgracht 448                              │
  7. │ 1016 GD Amsterdam, the Netherlands                                       │
  8. │ Fax (+31) 20 622 4939                                                    │
  9. ├─────────┬─────────────────────┬───────────────────┬──────────────────────┤
  10. │ Email:  │ 2:283/203.8 fidonet │ 'Lj Lapre' PCGnet │  ljlapre@hacktic.nl  │
  11. └─────────┴─────────────────────┴───────────────────┴──────────────────────┘
  12.  
  13.  
  14. Disclaimer
  15. ──────────────────────────────────────────────────────────────────────────── 
  16. This software is free and may be freely distributed, but is copyrighted by 
  17. the company RenderStar Technology BV. This software is provided as is 
  18. without any guarantees. The author and company assume no liability for 
  19. damages, direct or consequential, which may result from the use of this 
  20. software. The 'lparser.exe' file may not be used as part of any commercial 
  21. package without the explicit written consent of the author or company.
  22.  
  23.  
  24. General
  25. ──────────────────────────────────────────────────────────────────────────── 
  26. An l-system is a rule like description of a 3d form. It contains  
  27. descriptions of parts and how they should be assembeld together. The program 
  28. reads a l-system description in and processes it into a 3d form which can 
  29. then be outputed in several formats, including DXF and POV. 
  30.  
  31. The description is applied to itself a number of times (= recursion levels) 
  32. so fractal and recursive forms are very easy to describe in an l-system. 
  33. That's why they are used a lot for plants and natural looking organic forms. 
  34. By increasing the recursion level the form slowly 'grows' and becomes more 
  35. complex. 
  36.  
  37. This implementation of a l-system parser also allows 'mutations' to take 
  38. place during the growing of the form. These mutations can change the form 
  39. slightly or quite dramaticly. This allows you to create a form once and then 
  40. create a whole series of forms all clearly 'descendant' from the original 
  41. l-system.
  42.  
  43. Too help people get started a lot of example l-systems and POV files have 
  44. been included.
  45.  
  46. The lparser.exe is a protected mode program using the royalty free 
  47. Rational dos-extender (dos4gw.exe) supplied with Watcom 9. It needs a 
  48. 386/387 or 486 with 4meg ram.
  49.  
  50.  
  51. Execute like this :
  52. ──────────────────────────────────────────────────────────────────────────── 
  53. lparser [options] [name]
  54.  
  55. examples :
  56.  
  57. lparser -x rcylin -d lsys03.ls
  58. lparser -vc -t0.5 -u10 -i30000 -g lsys05
  59. lparser spider
  60.  
  61. Name is an l-system file with the ls extension. It will standard generate a 
  62. RenderStar compatible 'output.vol' file. 
  63.  
  64. The standard output.vol file can be taken directly to the lviewer with the 
  65. command : 'lviewer output'. You will get some information about the loaded 
  66. object and it will bring you into a standard VGA 640x480 16 color screen. 
  67. Here you can rotate the object, zoom in/out and pan. For key usage see 
  68. the lviewer.txt file.
  69.  
  70. It can also be shown and rendered directly in RenderStar with the command : 
  71. 'rs2 l'. The l.* files are RenderStar support files.
  72.  
  73.  
  74. Persistence of Vision (POV) output :
  75. ──────────────────────────────────────────────────────────────────────────── 
  76. Part off the POV file is setup by the user and the output.pov file is then
  77. attached to the user's file.
  78.  
  79. -v            make POV object file
  80.  
  81. Generates a POV file format description. Only the body part of the file is 
  82. generated with a series of a l_base objects and leafs as triangles. See the 
  83. 'exam.pov' file for more explanation. One can change the object definition of 
  84. the l_base element used in the l-system form to any one of the valid POV 
  85. shapes as long as the shape can be scaled differently in all 3 directions. 
  86. With POV 2 this can also be a sphere. 
  87.  
  88. The file 'setup1.pov' can be used to connect to the output.inc file created 
  89. with lparser -vc. The first 8 colors in the pov rendering will then match the 
  90. ones in the viewer. The view will be about the same (except for the scale) as 
  91. the initial startup configuration in the viewer.
  92.  
  93. -b            make POV blob file
  94.  
  95. Instead of outputting objects, postionend components are written to the 
  96. output.pov file. These can be used to create 'bloby' objects. See 
  97. 'bloby.pov' for an example how to set this up. All triangles are skipped.
  98.  
  99. The file 'setup2.pov' can be used to connect to the 'output.inc' file created 
  100. with lparser -bc. 
  101.  
  102. -B            make multiple POV blob files
  103.  
  104. Each color part of the final form is written into its own output?.pov file. 
  105. This allows you to have mutiple blob's each with its own color and material. 
  106. See 'mbloby.pov' for an example. All triangles are skipped. The b*.pov files 
  107. contain several different forms and setups done with POV's blob functions.
  108.  
  109. The file 'setup3.pov' can be used to connect to the 'output?.inc' files created 
  110. with lparser -Bc. 
  111.  
  112. -c            output inc files instead of POV file
  113.  
  114. The output files will now have the 'inc' extension for easier including in 
  115. other POV files like 'setup.pov'.
  116.  
  117.  
  118. DXF output :
  119. ──────────────────────────────────────────────────────────────────────────── 
  120. -d            make dxf file (use with '-x cube' for fast dxf file writing)
  121.  
  122. This creates AutoCad R12 polyline polyface meshes in dxf file format which 
  123. can be used in Acad and 3DS. It's a much more efficient format than the 
  124. 3dface format. It uses blocks and inserts. The most efficient dxf file (in 
  125. size and write/load time) is generated with : lparser -x cube -d [name]. If 
  126. you read the file into Acad12 make sure you have a new (no prototype) drawing 
  127. since the file contains block definitions as well. The objects will have 
  128. color and layer attributes set. By changing all object color attributes to 
  129. BYLAYER one can use the layer overview for easy, by layer, color setting.
  130.  
  131. -3            make dxf file
  132.  
  133. This is a simple 3dface only dxf file format which will always work. It has 
  134. no blocks or inserts but can become very large.
  135.  
  136.  
  137. RAW output :
  138. ──────────────────────────────────────────────────────────────────────────── 
  139. -R            make raw file
  140.  
  141. This is a simple ascii RAW file format, it can become very large. One triangle 
  142. per line.
  143.  
  144.  
  145. Other options :
  146. ──────────────────────────────────────────────────────────────────────────── 
  147. -t [num]      set minimum thickness
  148.  
  149. This allows you to set the minimum thickness a form will get during 
  150. recursive generation. It is to make sure the forms don't get too 'thin' to 
  151. be seen and render correctly. It's typicly around 0.5 to 1.0.
  152.  
  153. -u [num]      mutate [num] times
  154.  
  155. Mutate the l-system a number of times before starting the geometry generation 
  156. fase and write the mutated l-system to disc as the file 'mutation.ls'. By 
  157. re-using this file one can build mutation series of forms.
  158.  
  159. -r [num]      overrule recursion depth 
  160. -a [num]      overrule angle
  161.  
  162. Overrule these values on the commandline. They are also set in the l-system 
  163. file but they will not be used when an overrule option is used on the 
  164. commandline. One can 'open' a form by starting with a angle of zero and 
  165. increase it to the final angle. This makes nice animations. Doing the same 
  166. with the -r option will slowly 'grow' the form into its final shape.
  167.  
  168. -p [num]      limit polygons to [num]
  169.  
  170. Limit the total amount off polygons/objects outputed during the parsing of 
  171. the final l-system production. After mutation the form may have grown very 
  172. (VERY!) large. The whole form could be inserted in each of its branches ! 
  173. The default limit is 200.000 polygons/objects.
  174.  
  175. -i [num]      limit string length to about [num]
  176.  
  177. Limit the length of the final production string. This is also a way of 
  178. limiting the size and generation time of a form. When certain mutations 
  179. occur the generating time can become very long. The -i option can limit this 
  180. time. Use like : lparser -p50000 -i30000 lsys00. The default string limit 
  181. is 500.000 chars. The program can handle final l-systems strings up to 1 
  182. million chars.
  183.  
  184. -x [name]       use name.vol as base form
  185.  
  186. Instead of a simple block a special object (*.vol) can be used as a base 
  187. element. Example forms are ball, cube, cone, cylin8 (cylinder with 8 faces), 
  188. cylin16 (cylinder with 16 faces), min (only two faces in a cross), rcylin 
  189. (cylinder with rounded edges) and tube. This is for generating vol or dxf 
  190. files only. Try : lparser -x ball lsys00. Just use the small *.vol files 
  191. supplied with the parser for this purpose. Using larger lparser generated 
  192. .vol files may not work. The changing of the base forms for POV output is 
  193. done by the user in the POV headers. See *.pov for examples.
  194.  
  195. -l            show final L-string
  196.  
  197. Prints the l-system production to the screen. This is the final string which 
  198. is then interpreted into a 3d form.
  199.  
  200. -g            add ground plane
  201.  
  202. Adds a large ground plane (2 triangles) touching the lowest point of the 
  203. form. This is for easy shadow projection and horizon.
  204.  
  205.  
  206. More info ... 
  207. ──────────────────────────────────────────────────────────────────────────── 
  208. The book 'Evolutionary Art and Computers' by S. Todd and W. Latham was used 
  209. to base the genetic 3d form mutation principles on. In here you'll find a lot 
  210. of interesting ideas on how to 'grow' and 'evolve' organic looking 3d forms 
  211. of your own. ISBN 0-12-437185-X
  212.  
  213. The implemented l-system is based on the one described in the book : 'The 
  214. Algorithmic Beauty of Plants' (BOP) by P. Prusinkiewicz and A. Lindenmayer 
  215. (this is where the 'L' from l-systems come form). If you want more 
  216. information on making your own l-systems you'll want to check out this book. 
  217. A lot can be done by changing the l-systems suplied with the parser and 
  218. seeing for yourself what changes in the final form. ISBN 0-387-97297-8
  219.  
  220. For this you can use the the following l-system files:
  221.  
  222. bop00.ls          cordate leave     BOP pag 123
  223. bop01.ls          plant        BOP pag 27
  224. bop02.ls          bush        BOP pag 26
  225. bop03.ls          form in 2d    BOP pag 25
  226. bop04.ls          block form    BOP pag 20
  227. bop05.ls          fractal        BOP pag 9
  228. bop06.ls        dragon curves   BOP pag 9
  229. bop07.ls        compound leave  BOP pag 130
  230.  
  231. tree00.ls    monopodial tree    BOP page 56
  232. tree01.ls    monopodial tree    BOP page 56
  233. tree02.ls    ternary tree    BOP page 60
  234. tree03.ls       willow type tree
  235. tree04.ls       conifer type tree
  236. tree05.ls    'best' tree
  237. tree06.ls    conifer type tree
  238. tree07.ls    tropism experiment
  239.  
  240. Fractals :
  241.  
  242. fract*.ls        L-systems from FractInt
  243.  
  244. Free form experiments:
  245.  
  246. lsys00.ls         lobster form
  247. lsys01.ls            "    var 1
  248. lsys02.ls            "    var 2
  249. lsys03.ls            "    var 3
  250. lsys04.ls            "    var 4
  251. lsys05.ls         spiral bush
  252. lsys06.ls         tree base
  253. lsys07.ls         half circle
  254. lsys08.ls            "    var 1
  255. lsys09.ls         cello plant
  256. lsys10.ls         circle form
  257.  
  258. Mutations:
  259.  
  260. mut00 - mut08      mutations of lsys00.ls
  261. mut09 - mut14      mutations of spider.ls
  262. mut15 - mut18      distant relatives of lsys02.ls
  263.  
  264. Spiral forms:
  265.  
  266. spiral00.ls       overview of spiral types
  267. spiral01.ls       spiral form
  268. spiral02.ls       spiral tree
  269. spiral03.ls       large spiral plant var 1
  270. spiral04.ls       large spiral plant var 2
  271.  
  272. 'Plant/Animal' forms:
  273.  
  274. airhorse.ls    part seahorse but with external lung
  275. dinofly.ls    what would this be without a dino ?
  276. flower.ls    cordate leave arangement
  277. spider.ls    octo-spider
  278.  
  279.  
  280. Syntax and movement
  281. ──────────────────────────────────────────────────────────────────────────── 
  282. For those who are already familiar with l-systems, here are the commands and 
  283. their functions for this lparser's 'dialect'. All commands are 1 char only 
  284. and simpler then for most lparsers. This is to keep them from getting 
  285. 'broken' by the mutation process and speeds up the parsing.
  286.  
  287. There is also the posibilty to add an argument to a command. Instead
  288. off doing +++ one can do +(30) if the basic angle was 10 degrees. The 
  289. argument can be a real value.
  290.  
  291. The tropism command will allow you to let gravity pull branches downward by 
  292. adding a 't' element togeter with and 'F'. See the file 'tropism.ls' and 
  293. 'tree*.ls' for examples. When you are not sure about the current 'down' 
  294. direction do a '$' command first. This will roll the turtle horizontal and 
  295. make sure the current up vector is oriented in the positive z-axis direction.
  296.  
  297. The turtle will start at the origin with the Z-axis as forward direction and 
  298. Y-axis as left direction. See the file 'axis.ls' for an detailed example. 
  299. Here you can experiment with the basic orientations and see how the 3d 
  300. turtle is using a 'right-handed' coordinate system. Use your right hand with 
  301. your thumb as up, forefinger as forward and an other finger as left 
  302. direction. 
  303.  
  304. By adding &(90) in front of an axiom the turtle axis will align with the 
  305. right handed coordinate system used in the viewer. Adding an additional
  306. +(90) will make it easier when working with 2d l-systems. See the
  307. 'fract*.ls' files for examples.
  308.  
  309. ┌─────────────────────────────────────────────────────────────────────┐
  310. │ Turtle Orientation commands                                         │
  311. ├─────────────────────────────────────────────────────────────────────┤
  312. │ +    turn left around up vector                      │
  313. │ +(x)    turn x left around up vector                      │
  314. │ -     turn right around up vector                      │
  315. │ -(x)     turn x right around up vector                      │
  316. │ &    pitch down around left vector                      │
  317. │ &(x)    pitch x down around left vector                      │
  318. │ ^    pitch up around left vector                      │
  319. │ ^(x)    pitch x up around left vector                      │
  320. │ <    roll left (counter clockwise) around forward vector          │
  321. │ <(x)    roll x left around forward vector                  │
  322. │ >    roll right (clockwise) around forward vector              │
  323. │ >(x)    roll x right around forward vector                  │
  324. ├─────────────────────────────────────────────────────────────────────┤
  325. │ Special Orientation commands                                        │
  326. ├─────────────────────────────────────────────────────────────────────┤
  327. │ |    turn 180 deg around up vector                      │
  328. │ %    roll 180 deg around forward vector                  │
  329. │ $    roll until horizontal                           │
  330. │ ~    turn/pitch/roll in a random direction                  │
  331. │ t    correction for gravity with 0.2                          │
  332. │ t(x)    correction for gravity with x                          │
  333. ├─────────────────────────────────────────────────────────────────────┤
  334. │ Movement commands                       when {} active          │
  335. ├─────────────────────────────────────────────────────────────────────┤
  336. │ F    move forward and draw full length    record vertex          │
  337. │ F(x)    move x forward and draw              record vertex          │
  338. │ f    move forward with full length         record vertex           │
  339. │ f(x)    move x forward                    record vertex           │
  340. │ g    move forward with full length         don't record vertex      │
  341. │ g(x)    move x forward                         don't record vertex      │
  342. │ Z    move forward and draw half length    record vertex          │
  343. │ Z(x)    move x forward                       record vertex          │
  344. │ z    move forward with half length         record vertex          │
  345. │ z(x)    move x forward                       record vertex          │
  346. │ .    don't move                 record vertex            │
  347. ├─────────────────────────────────────────────────────────────────────┤
  348. │ Structure commands                              │
  349. ├─────────────────────────────────────────────────────────────────────┤
  350. │ [    push current state                          │
  351. │ ]    pop current state                          │
  352. │ {    start polygon shape                          │
  353. │ }    end polygon shape                          │
  354. ├─────────────────────────────────────────────────────────────────────┤
  355. │ Inc/Dec commands                              │
  356. ├─────────────────────────────────────────────────────────────────────┤
  357. │ "    increment length with 1.1                      │
  358. │ '    decrement length with 0.9                      │
  359. │ "(x)    multiply length with x also '(x)                  │
  360. │ ;    increment angle    with 1.1                      │
  361. │ :    decrement angle with 0.9                      │
  362. │ :(x)    multiply angle with x also ;(x)                      │
  363. │ ?    increment thickness with 1.4                      │
  364. │ !    decrement thickness with 0.7                      │
  365. │ ?(x)    multiply thickness with x also !(x)                  │
  366. ├─────────────────────────────────────────────────────────────────────┤
  367. │ Additional commands                              │
  368. ├─────────────────────────────────────────────────────────────────────┤
  369. │ c    increment color index                          │
  370. │ c(x)    set color index to x                          │
  371. │ *    reset color, thickness, length and angle              │
  372. │ @    end of object                              │
  373. └─────────────────────────────────────────────────────────────────────┘
  374.  
  375.  
  376. This is an example of a simple form definition (spiral01.ls) :
  377. ──────────────────────────────────────────────────────────────────────────── 
  378. 20
  379. 10
  380. 100
  381. a
  382. a=Fs+;'a
  383. s=[::c!!!!&&[b]^^^^[b]]
  384. b=F!+F+;'b
  385. @
  386.  
  387.  
  388. This is an example of a complex form definition with comments (spider.ls) :
  389. ──────────────────────────────────────────────────────────────────────────── 
  390. 15                    # recursion level
  391. 10                    # basic angle
  392. 40                    # starting thickness
  393. C                    # axiom
  394. #-------------------------------------- Creature
  395. C=%LABHT
  396. #-------------------------------------- Body
  397. B=[???????zZZZ]
  398. #-------------------------------------- Arms
  399. A=[zf&&&&&&&&&"""[pj>>>>>>>>>S]|[qj<<<<<<<<<S]]
  400. p=Ft+:'p                # left
  401. q=Ft-:'q                # right
  402. j=;"j
  403. #-------------------------------------- Scorpers
  404. S=['''!!r%^^r]
  405. r=[Z?Z?Zu]                # jaw assembly
  406. u=Z[co]!'^::u                # jaw and tooth    
  407. #-------------------------------------- Legs
  408. L=[c">>>>[s]>>>>[s]>>>>[s]>>>[s]>>>>>>[s]>>>[s]>>>>[s]>>>>[s]]
  409. s=+++li+++dccc??""FF            # down legs
  410. l=Ft+:'l                # upper leg
  411. d=FFF'd                    # lower leg
  412. i=;i
  413. #-------------------------------------- Head
  414. H=["">>>>>>>>>&&&&&&??FFFF!![???h][???k]%^^[??k]]
  415. k=[Z?Z?Za]                # jaw assembly
  416. a=Z[co]!'a                # jaw    
  417. o=&&&&&&&&&!!!!!F            # teeth
  418. h=[^^gcccc"Z][^^ecccc"Z]        # eyes
  419. g=z!+z!+z!+z                # left eye
  420. e=z!-z!-z!-z                # right eye
  421. #-------------------------------------- Tail
  422. T=[f---------??""""""mccccF]
  423. m=Ft+;'m                # curl
  424. t=['::c!!!&&[f<<<n]^^^^f>>>n]        # spikes
  425. n=[c{--z++z++z--|--z++z++z}]        # leaf
  426. #-------------------------------------- End
  427. @
  428.  
  429.  
  430. This is an example of using the argument based commands (tree__00.ls) :
  431. ──────────────────────────────────────────────────────────────────────────── 
  432. 10
  433. 45
  434. 15
  435. FFAL
  436. A=F[&'(.8)!BL]>(137)'!(.9)A
  437. B=F[-'(.8)!(.9)$CL]'!(.9)C
  438. C=F[+'(.8)!(.9)$BL]'!(.9)B
  439. L=~cc{+(30)f(2)-(120)f(2)-(120)f(2)}
  440. @
  441.  
  442.  
  443. Thanks to :
  444. ──────────────────────────────────────────────────────────────────────────── 
  445. C.J.van der Mark [2:283/203.11 fidonet, 9:580/203.11 PCGnet] for testing all 
  446. versions, feedback and working on the various POV formats.
  447.  
  448. BBS Bennekom [2:283/203 fidonet, 9:580/203 PCGnet] for acting as go-between.
  449. ──────────────────────────────────────────────────────────────────────────── 
  450.  
  451.