

          ReverseTree.pov
          (POV Vers: 3.6)
         
 by Leroy Whetstone E-mail: lrwii@joplin.com
 
 This zip contains:
  ReverseTree.pov --- the tree maker
  TestTrees.pov------ Shows Mesh2 Tree with or with out leafs
  UVtest.inc -------- A Mesh2 Tree (made with ReverseTree.pov)
  UVtest.txt -------- Data for a Mesh2 Tree(made with ReverseTree.pov)
  PointsTest.txt ---- all the Limb end points of Tree(made with ReverseTree.pov)
  LeafShow.pov------- Shows a leaf in many locations
  Leaf0.inc -------- a leaf example
  Leaf1.inc -------- a leaf example
  Leaf2.inc -------- a leaf example
  Leaf3.inc -------- a leaf example
  ReadMe.txt-------- Here!
  
 The main idea behide 'ReverseTree' is that you start with the end points
of the limbs and work your way back to the trunk. To make it eazier to 
do this the number of end point must be a power of two and the number of
branchs from the truck also must be a power of two.(2,4,8,16,32,64...)
Although this is limiting, it has an advantage that you can shape a tree 
to any thing you like. 'ReverseTree' has several built-in shapes and
a custom shape you can modify. Also if you made a tree that is almost
perfect but one or more limbs are causing trouble, 'ReverseTree' will
let you move those limbs only.

=============  Getting started ========================
 unzip ReverseTree.zip into any folder you like
       then set your INI file accordingly
        then render 'ReverseTree.pov' 
       and you'll have your first tree
   I'd make a rename copy. So I'd have a back up.
======================================================

 What 'ReverseTree' does:
  makes a Mesh2 tree: 
    with or without UV mapping
    with or without Leafs
  makes Snow tree:
     a Mesh2 tree(with or without UV mapping or Leafs)
     with some of the branches missing so you can 
     texture it as snow and move it over a full tree
  Loads and Saves: The Endpoints of the limbs
  Loads and Saves: All variables that made a tree
  

 'ReverseTree.pov' has a lot variables to do its thing. 
  Here a list. Don't worry you don't have to know every one
  to get started.
    
 These are the variables that load and save things.
  They are commented out as default. To use them delete the '//'
  and change the string to the file you want.  

  //#declare Loadata="UVtest.txt"; //load variables to make tree
  //#declare SaveData="UVtest.txt";// Save variable to make tree
  //#declare LoadEnpoints="PointsTest.txt"// Load tree end points only
  //#declare SaveEnpoints="PointsTest.txt"// Save tree end points only
  //#declare SaveMesh="UVtest.inc";// save Mesh2 Tree/Leafs objects
 
 These are the variables are for the Display Only.
 
  DiRot=45; rotate view of tree 
  Tpig= Tree pigment set up for UV mapping 
  Spig= Snow pigment set up for UV mapping 
  Lfpig= Leaf pigment set up for UV mapping 
 
=========  Here are the Tree variables ===========================
  
 Variable    Default               Function  
 RS        1955;(interger)     random seed for limbs
 VS        6259;(interger)     random JITter seed
 TreeUV     on;(on\off)        UV mapping (on\off)
 Shape       0;(interger)      limbs bounding shape 
                               0-sphere      4-Y cone  
                               1-cube        5-x cone  
                               2-Y cylinder  6-y plane 
                               3-X cylinder  7-Custom  

 In_Shape   no;(yes\no)       end point of limbs IN shape(yes) 
                                   or ON shape(no)
 SHalf     yes;(yes/no)       shape fliped up y=abs(y)  
 Rad   <5,5,5>;(float Vector) Scale of Shape(Tree branches ends)
 Jit   <0,0,0>;(float Vector) 0=no random jitter of end points
 Cmov  <0,0,0>;(float Vector) move center of tree branching Shape
                              y branchs lower/rasied toward ground
 Bas        64;(interger)     number of end points (powers of 2)
 XXX         2;(interger)     number of braches from trunk(powers of 2)
                                     end of loop 0<XXX<Bas
 Smooth     on;(on\off)       smooth triangle switch
 Trino       3;(interger)     number of triangles per branch radius>2

 Aged       no;(yes/no)       younger limbs branch into older limbs 
 Bp        .15;(Float)        percent of branch  lenght  0< Bp <1 
 Bseg        3;(interger)     Bseg>=1 single branch segments
 Bran       .5;(Float)        Branch segments range
 BTnk       .4;(Float)        Trunk segments range
 Ps         .01;(Float)       start Branch radius >0
 Tnk          3;(Float)       length of trunk>0 
 TnkR       .25;(Float)       Trunk radius at branching >0 & >Ps
 TnkRl       .3;(Float)       Trunk radius at roots >0 & >Ps
 Roots        4;(interger)    Roots branches 0= no root ball
 RootH      .25;(Float)       Roots height up trunk < Tnk
 RootRs      .2;(Float)       Roots start min radius < TnkRl
 RootRd     .01;(Float)       Roots end radius < TnkR >0
 RootL        3;(Float)       Roots lenght
 Rtv        435;(interger)    random Root seed
 
     This the default for 'Shape'= 7
 CustomShape=union{sphere{y*.5,1}cylinder{-y,y,1}};

=========== Values for Snow Trees ===================
 Variable    Default               Function   
 Snow        no;(yes\no)       yes= make a snow Tree no= regular Tree
 Snv        .75;(float)        percent of snow on tree 0<Snv<=1
 SnS        325;(interger)     random Snow value


================= Values for Leafs ==============================
 
     commented out LFile for no leaves
 //#declare LFile="Leaf1.inc"; a single leaf base(mesh triangles)

 Variable    Default               Function   
 LSmooth     on;(on\off)  smooth triangle switch
 Luv         on;(on\off)  uv mapping switch
 LShape      0;(interger) shape of leaves with sphere scaled with rad
                           0 random
                           1 partial drooping
                           2 Full drooping 
                           3 Star rotate leaf from center
                           4 crown leafs point up from center
                           5 one leaf at end of limb
 LRad    <1,1,1>;      sphere radius of leaf bunch
        (float vector)
 Lsph      no; (yes\no)   no=leafs on sphere yes= leafs in sphere 
 Lmin      .75;(vector)    min scale size
 Lmax        1;(vector)    max scale size
 Lno         8;(interger) number of leafs in bunch
 Lseed    6415;(interger) random leaf seed


========================= Having Fun ===================================
      Here we'll cover the basic variables and how to use them.
(I'll pretend that you have already render 'ReverseTree' at lease once)

 The first thing beside all that load and saving stuff is... 
  'Bas' determines how many limbs there will be. And
  'XXX' determines how many limbs come from the trunk.
  Remember, they both have to be the an power of two.
          'XXX' has to smaller than 'Bas'
  'Bas' can be very high(1024 or more) if you like, but the mesh file
  will be very big. 'XXX' could be very high compared to 'Bas'. A value
  of a power of two one lower than 'Bas' will give you a weed. Try it!

 The next big thing is 'Shape' the default is sphere. This bounds the
 end of the limbs a sphere centered at the top of the trunk. Other
 shapes can be use try them out and see what you think.
 If you use a custom shape you made it should be centered a <0,0,0> 

 'Shape' has a lot of helper variables that will deform the shape chosen.
  'Rad' is a vector that scales the shape(most shapes fit a box{-1,1}.
  'SHalf' will flip the lower half up the shape upward from the trunks top
  'Cmov' is a vector that will move the caluclating trunk top 
        but not affect the real trunks height.The trunk starts a y=-.1 to
        y*'Tnk'.(See 'Tnk' below)
  'In_Shape' and 'Jit' affect the way the end points of limbs are chosen.
   When 'In_Shape' is 'on' end points are randomly placed inside the shape.
      When 'off' end points are randomly placed on the surface the shape.
   While 'Jit'(a vector) will move the end points randomly around what 
   nomally would be chosen. It has the most effect when 'In_Shape' is off.
   All elemets of 'Jit' shold be positive or zero. zero is no jitter.             
    I almost for got 'Vs' is the random seed value that 'Jit' uses.
  
 The next three variable deals with how the mesh2 is made.
  'Smooth' when 'on' puts the normal_vector in the Mesh2  
  'TreeUV' when 'on' puts the uv_vector in the Mesh2 (allows uv_mapping)  
           it is mapped like the spherical pattern with one at the Root
           and zero at the limbs tips.
  'Trino' is the number of triangles that will make the circumference of
          a limb. With a 'Trino' of 3 a basic Limb will take 6 triangles.
          More on limbs later.
          
  Oh! We'er now at the variables that deal with how limbs are made.
  But, how to orginize them? Well..., I tell you the way they came about.

  Lets start with 'Ps' the radius of the outer most limbs and 'TnkR'
  the radius of the top of the trunk. At one time that was all I need
  to make the limbs and branches of a tree. From'Ps to'TnkR' at each
  branch 'Ps' got closer to 'TnkR' until they matched. Tree done. 
    Ok, its a little more complicated than that. You start with a list
  of end points. Sort though them to find the closest pairs. Each pair
  is use to calculate the branch point between them. The limbs are made
  from the each end point to their branch point. Now you take the list
  of branch points and turn them into end points. And go through the hole
  thing again,again,again and... until your done.  
    Then I added 'Bp'(percent of branch  lenght) this works when the 
  calculating branch points. Branch points lie somewhere on a line
  from the mid point of two end points to the top of the trunk. 'Bp'
  is the precentage of the mid point devided be the lenght of 
  midpoint to top of trunk. This is the branch point.
   Thats a load. All you need to remember is the smaller 'Bp' is the
  closer the branches will be to the bounding shape. The larger it is
  the closer to the trunk branches will be.
   Now come the fun part. So far the trees made this way where all right.
  But I like to have older looking trees without having a lot of end 
  points. Thats where 'Age' come in. It will put an age to each end point.
  When a pair of end points are chosen to calculate a branch point only
  the older endpoint will be use to calculate a branch point. This kind 
  of works but the effect is sometimes hard to see.
   We got something here that is not hard to see! 'Bseg' starts a whole
  new way of making limbs. It cuts each limb into peices and 'Bran' moves 
  them around randomly from the old limb location. It does incease the
  mesh2 size some. Ok, a lot! But even a small values of 'Bseg' and 'Bran'
  can make make decent limbs. 
   I should say something about the way 'Bran' move the limb parts around.
  Each limb starts and ends at branch point and the end point. There is a
  perpendicular vector to the vector between those points. 'Bran' is the
  max length of the perpendicular vector at each cut. There are as many
  of those perpendicular vector as there is cuts. The limb is made up of
  parts cut and move to to those perpendicular vector.
   'BTnk' does the same for the trunk as 'Bran' does for limbs. I put it
  in because some values of 'Bran' when used for the trunk were wrong.
  
  Well, we're now on to the trunk variables. 'Tnk' is the height of the 
 trunk. The trunk starts at -y*.1 and ends at y*'Tnk'. 'TnkR' is the
 radius at the branch end of the trunk. While 'TnkRl' is the radius at
 the root end. 

   The last of the tree variables Deals with Roots. This is the last thing
 I added to the tree.'Roots' is the number of roots made. They are placed
 at equal distances around the trunk.'RootH' is the height the roots 
 pushes the trunk up.(so the roots show)'RootRs' is the minimium radius
 a root can have near the trunk, the maximuim is 'TnkRl'. 'RootRd' is the
 radius at the end of a all roots.'RootL' is the lenght of all roots. 
 'Rtv' is the random seed that randomize the root radius near the trunk
 and the starting point of placing them.
    
========================== THE SNOW TREE =============================
 
  If you read about Snow trees above, you know that a Snow tree is a 
 regular tree with some limbs missing. A snow tree use all the variables
 for a regular tree plus these 3. 
   'Snow' is the switch to turn on a snow tree.
   'Snv' is the percent of snow on the tree.(Limbs left)
   'SnS' is the random seed to put the snow on
  There are a few things you need to know about Snow trees. 
 One, Snow trees drops whole limbs, even if you use 'Bseg' to deform them.
 Second, Roots are never dropped. If you don't want snowy roots then 
 'Roots' should be zero.
 And lastly you can have uv mapping and leafs with snow trees.
 But uv mapping only affects the tree part. Leafs don't have uv mapping.
 If you want snowy leafs you can either use snow pigment for both 'Tree' 
 and 'Leafs' and drop uv mapping or keep uv mapping for the 'Tree' and 
 have another snow pigment for the 'Leafs'.
  ('Tree','Leafs' are Mesh2 objects 'ReverseTree' makes)

========================== Leafs ============================= 

  My leafs are kind primitive. They are base on my old High School
 or Junior High or Grade school way of drawing leafs on trees. After
 drawing the tree limbs and branches, draw little circles at the end
 of the limbs and anywhere that look good.   
  Here I used spheres instead of circles and I place leafs in or on
 those sphere. The spheres are still at the end of the limbs but I've
 stop putting any more elsewhere. Each sphere has its own bunch of leafs.  

  What I've done here is have a file for an individual leaf that has three
 arrays with values that are the same values as if it where a mesh2.
 The values need to be in array because you'll need a lot of leafs.
 The three arrays are LeafPnt(points),LeafTri(triangles) and 
 LeafUV(uv mapping). You don't have to have 'LeafUV' if don't plan to use
 uv_mapping of your leafs.
        ( 'LeafShow.pov' will help you make your own leafs. )
 One thing here, all leafs should start at <0,0,0> and end in the -y
 direction. My leafs examples are rather simple. You could make a lot
 better ones. Just remember that every triangle of a leave will be
 mutilpied by number of limbs('Bas')and by number of leafs in bunch('Lno')
 Thats a lot of triangles! And points to go with it!
 
 Now a few thing before we get to the heart of the matter.
  'LFile' holds the individual leaf file name. If it is commented out 
          there will be no leafs. 
  'LSmooth' is the smooth triangle switch
  'Luv'  is the uv_mapping switch
  'Lno' is the number of leafs in a bunch at a limbs end
  'Lseed' is random leaf seed use to rotate, scale and place leafs

 The leaf heart: the shape and size of the spherical leaf bunches. 
   'LRad' is the spherical radius of all leaf bunches. The smaller
 the value the closer to the limb the leafs are placed. As you see
 'LRad' is a vector so the sphere does have to be a 'sphere'.
   'Lsph' controls weather leafs are on or in sphere the sphere. If
 'in sphere' is chosen some leafs will be closer to the limb that others.  
   Now to the fun part. As with a a few of the pov files I'v made, while
  getting this ready for your use, I found that the leaf placement really
  ... sucked. Of course, I was have have through the leafs documentation
  before I found out. Time for a rewrite and a lot of testing. I think I
  came up with a better organize leaf placement. You be the judge!   

   'LShape' has 6 values that place leafs based on 'LRad' and 'Lsph'.
  All the leafs are rotated first then place, rotate again then placed 
  permently.
  
 Value 0  this rotates and place leafs totally randomly.

 Value 1 the first rotate is limited and the last rotation is around the 
         y axis. This give you a slight drooping leafs.

 Value 2 the first rotation is exactly oppsite of the last rotation
         and the last rotation is around the around the y axis. So all
         the leafs face away from the center. 
         This give you a strongly drooping leafs.
         
 Value 3 the randomly place leaf with be rotate away from the center
         on the bounding Sphere.
         This give leafs a spike look.
 Value 4 this is simular to 3 but it is limit so leafs tend to point up
         This give leafs a crown effect.
 
 Value 5 This is the last one and different! Here you place One Leaf at
         the end of a limb. No mater what 'Lrad'or 'Lno' are. It has a
         limited rotation toward and away the trunk.
                  

 Finally the last variables for the leafs, these deal with leaf size.
  'Lmin' and "Lmax'  minimium and maxium sizes they are vectors.
   Leafs are scaled by random vector between these two value before 
   they are rotater and placed. I've have set it up so you could use 
   a float value instead of a vector if you like.


===================== After thoughts =======================================

 After going over this I would blame you if just delete the whole $^%$%
thing. Give up and download already made tree models from the internet.
 But, if you stick with it you might find something in it you can use.
I've made a forest with its predecesors. Not only the big trees but bushes
and weeds. 
 The trouble with things like this is that at first you get something 
neat. Then you want to add just a little something then another and 
another and so on .... until you have have a whole lot of litle 
somethings. There is so much stuff that 'Reverse Tree" could do that I
could write a book, not a thin book, a big fat heavy book. But I don't
write.(this Here is about it)

 So Have fun!   
     