File: tree_1.inc

package info (click to toggle)
terraform 0.9.0-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,008 kB
  • ctags: 2,529
  • sloc: ansic: 28,422; sh: 3,336; pascal: 1,896; makefile: 710; yacc: 318
file content (239 lines) | stat: -rw-r--r-- 7,840 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#include "woods.inc"
#include "textures.inc"

//-------//-------//-------//-------//-------//-------//-------//
// meshcone.inc
//
// Macro for one "cone" made from triangles.
//
// By: Paul T. Dawson

#macro MeshCone ( BaseVector, LENGTH, DIAM1, DIAM2, TiltVector, Tex )

  // If INCREMENT is lower, there will be more triangles!
  #local INCREMENT = 20;

  // Go around the edges of the cone, do one section at a time.
  #local A = 0; 
  #while ( A < 360 )

    // Starting locations.
    #local Corner1 = vrotate ( <DIAM1,0,0>, <0,A+INCREMENT,0> );
    #local Corner2 = vrotate ( <DIAM2,LENGTH,0>, <0,A+INCREMENT,0> );
    #local Corner3 = vrotate ( <DIAM2,LENGTH,0>, <0,A,0> );
    #local Corner4 = vrotate ( <DIAM1,0,0>, <0,A,0> );

    // Rotate everything.
    #local Corner1 = vrotate ( Corner1, TiltVector );
    #local Corner2 = vrotate ( Corner2, TiltVector );
    #local Corner3 = vrotate ( Corner3, TiltVector );
    #local Corner4 = vrotate ( Corner4, TiltVector );

    // Translate everything.
    #local Corner1 = Corner1 + BaseVector;
    #local Corner2 = Corner2 + BaseVector;
    #local Corner3 = Corner3 + BaseVector;
    #local Corner4 = Corner4 + BaseVector;

    // Make the triangles.
    triangle { Corner1 Corner2 Corner3 texture {Tex} }
    triangle { Corner1 Corner3 Corner4 texture {Tex} }
                
    #declare COUNT_TRIANGLES = COUNT_TRIANGLES + 2;

    #local A = A + INCREMENT; 
  #end

  // Calculate the top center of the cone.
  #declare Cone_End = <0,LENGTH,0>;
  #declare Cone_End = vrotate ( Cone_End, TiltVector );
  #declare Cone_End = Cone_End + BaseVector;

#end


//-------//-------//-------//-------//-------//-------//-------//
// meshtree.inc
//
// Macro for one "tree" made from triangles.
//
// By: Paul T. Dawson

#macro MeshTree ( 
  Number_Of_Large_Branches,
  Number_Of_Medium_Branches,
  Number_Of_Small_Branches,
  Number_Of_Leaves,
        
  Branch_Minimum_Angle,
  Branch_Maximum_Angle,

  Tree_Trunk_Size,
  Large_Branch_Size_Min,
  Large_Branch_Size_Max,
  Medium_Branch_Size_Min,
  Medium_Branch_Size_Max,
  Small_Branch_Size_Min,
  Small_Branch_Size_Max,
        
  T_Tree_1,
  T_Tree_2,

  Seed_1
)


//-------//-------//-------//-------//-------//-------//-------//
// Start the mesh right here.
mesh {
  // Don't change these!
  // They are calculated from your variables.
  #declare R1 = seed(Seed_1);

  #declare Bmin = Branch_Minimum_Angle;
  #declare Bmax = Branch_Maximum_Angle - Branch_Minimum_Angle;

  #declare Large_Branch_Size_Range =
                Large_Branch_Size_Max - Large_Branch_Size_Min;

  #declare Medium_Branch_Size_Range =
                Medium_Branch_Size_Max - Medium_Branch_Size_Min;

  #declare Small_Branch_Size_Range =
                Small_Branch_Size_Max - Small_Branch_Size_Min;

  #declare COUNT_TRIANGLES = 0;

  // Start with the trunk.
  #declare Trunk_Start = < 0, 0, 0 >;
  #declare Trunk_Length = Tree_Trunk_Size;
  #declare Trunk_Angle = <0,0,0>;

  MeshCone ( Trunk_Start, Trunk_Length, 0.6, 0.5, Trunk_Angle, T_Tree_1 )

  #declare Trunk_End = Cone_End;


  // Right here, you know where Trunk_End (the top of the trunk) is,
  // so start putting large branches onto that point.
  #declare Large_Loop = 1;
    #while ( Large_Loop <= Number_Of_Large_Branches )

      #declare Large_Start = Trunk_End;
      #declare Large_Length = ( rand(R1) * Large_Branch_Size_Range ) +
                Large_Branch_Size_Min;
      #declare Large_Tilt = (rand(R1)*Bmax)+Bmin;
      #declare Large_Rotate = ( 360 / Number_Of_Large_Branches ) * Large_Loop;
      #declare Large_Angle = < Large_Tilt, Large_Rotate, 0 >;
        
      MeshCone ( Large_Start, Large_Length, 0.4, 0.2, Large_Angle, T_Tree_1 )

      // The outer end of this branch.
      #declare Large_End = Cone_End;

      // Now you know where Large_End (the outer end of one branch) is,
      // so start putting medium branches onto that point.
      #declare Medium_Loop = 1;
        #while ( Medium_Loop <= Number_Of_Medium_Branches )

          #declare Medium_Start = Large_End;
          #declare Medium_Length = ( rand(R1) * Medium_Branch_Size_Range ) +
                Medium_Branch_Size_Min;
          #declare Medium_Tilt = (rand(R1)*Bmax)+Bmin;
          #declare Medium_Rotate = ( 360 / Number_Of_Medium_Branches ) * Medium_Loop;
          #declare Medium_Angle = < Medium_Tilt, Medium_Rotate, 0 >;

          MeshCone ( Medium_Start, Medium_Length, 0.2, 0.1, Medium_Angle, T_Tree_1 )

          // The outer end of this branch.
          #declare Medium_End = Cone_End;


         // Right here, you know where Medium_End (the outer end of 1 branch) is,
         // so start putting small branches onto that point.
          #declare Small_Loop = 1;

            #while ( Small_Loop <= Number_Of_Small_Branches )
              #declare Small_Start = Medium_End;
              #declare Small_Length = ( rand(R1) * Small_Branch_Size_Range ) +
                Small_Branch_Size_Min;
              #declare Small_Tilt = (rand(R1)*Bmax)+Bmin;
              #declare Small_Rotate = ( 360 / Number_Of_Small_Branches ) * Small_Loop;
              #declare Small_Angle = < Small_Tilt, Small_Rotate, 0 >;
        
              MeshCone ( Small_Start, Small_Length, 0.1, 0.05, Small_Angle, T_Tree_1 )

              // The outer end of this branch.
              #declare Small_End = Cone_End;


             // Now you have Small_End (the outer end of one small branch),
             // so go ahead and put some leaves on that point.
             #declare Leaf_Loop = 1;
               #while ( Leaf_Loop <= Number_Of_Leaves )

                 #declare L1 = Small_End + < 0, 0.1, 0 >;
                 #declare L2 = Small_End - < 0, 0.1, 0 >;
                 #declare L3 = Small_End + <(rand(R1)-0.5)*2,(rand(R1)-0.5)*2,(rand(R1)-0.5)*2>;
                 #declare LEAF_ROT = < rand(R1)*30, rand(R1)*360,0>;
                 #declare L4 = vrotate ( < -0.10, -0.25, 0 >, LEAF_ROT ) + L3;
                 #declare L5 = vrotate ( <  0.10, -0.25, 0 >, LEAF_ROT ) + L3;
                 #declare L6 = vrotate ( <  0.00, -1.00, 0 >, LEAF_ROT ) + L3;

                 triangle { L1 L2 L3 texture {T_Tree_2} }
                 triangle { L3 L4 L5 texture {T_Tree_2} }
                 triangle { L4 L5 L6 texture {T_Tree_2} }
        
                 #declare COUNT_TRIANGLES = COUNT_TRIANGLES + 3;


                // End all of the loops.
                 #declare Leaf_Loop   = Leaf_Loop   + 1; 
	       #end

             #declare Small_Loop  = Small_Loop  + 1; 
	   #end

         #declare Medium_Loop = Medium_Loop + 1; 
       #end

     #declare Large_Loop  = Large_Loop  + 1; 
   #end
   // End the mesh, and the macro!
}

#debug concat ( "Triangles in one tree = ",
                str(COUNT_TRIANGLES,0,0) )

#end


// Build one tree.
#declare Entire_Tree = MeshTree (
        8,    // Number_Of_Large_Branches
        8,    // Number_Of_Medium_Branches
        8,    // Number_Of_Small_Branches
        12,   // Number_Of_Leaves
                
        20,   // Branch_Minimum_Angle
        140,  // Branch_Maximum_Angle

        10,   // Tree_Trunk_Size
        4,    // Large_Branch_Size_Min
        5,    // Large_Branch_Size_Max
        2,    // Medium_Branch_Size_Min
        3,    // Medium_Branch_Size_Max
        1,    // Small_Branch_Size_Min
        2,    // Small_Branch_Size_Max

        texture { T_Wood32 } ,    // T_Tree_1
        texture { Jade },         // T_Tree_2
        
        9432  // Seed_1
        )

// tree macro 
#macro tree_1 ()
  object { Entire_Tree scale <0.06, 0.06, 0.06> }
#end