orig/genpine.csh
author Axel Jacobs <axel@jaloxa.eu>
Mon, 14 Apr 2014 22:21:17 +0100
changeset 73 87fa3132a136
parent 0 0aa115157c9c
permissions -rw-r--r--
New IES test file with spaces in file name
     1 #!/bin/csh -f
     2 # RCSid: $Id: genpine.csh,v 2.4 2011/01/24 04:28:06 greg Exp $
     3 #
     4 # Generate a tree
     5 # Pine version 2
     6 #
     7 # First send header and parse arguments
     8 #
     9 onintr done
    10 echo \# $0 $*
    11 set nleaves=150
    12 set nlevels=4
    13 set aspect=1.2
    14 unset needles
    15 while ($#argv > 0)
    16 	switch ($argv[1])
    17 	case -r:
    18 		shift argv
    19 		set nlevels=$argv[1]
    20 		breaksw
    21 	case -n:
    22 		shift argv
    23 		set nleaves=$argv[1]
    24 		breaksw
    25 	case -o:
    26 		shift argv
    27 		set needles=$argv[1]
    28 		breaksw
    29 	case -a:
    30 		shift argv
    31 		set aspect=$argv[1]
    32 		breaksw
    33 	default:
    34 		echo bad option $argv[1]
    35 		exit 1
    36 	endsw
    37 	shift argv
    38 end
    39 #
    40 #  Send materials
    41 #
    42 cat << _EOF_
    43 
    44 void plastic bark_mat
    45 0
    46 0
    47 5 .6 .5 .45 0 0
    48 
    49 void plastic leaf_mat
    50 0
    51 0
    52 5 .11 .36 .025 0 0
    53 _EOF_
    54 #
    55 # Next start seedling
    56 #
    57 set tree=/tmp/t$$
    58 set oldtree=/tmp/ot$$
    59 set thisrad=.035
    60 cat << _EOF_ > $tree
    61 
    62 void colorpict bark_pat
    63 9 red green blue pinebark.hdr cyl.cal cyl_match_u cyl_match_v -s $thisrad
    64 0
    65 2 1.5225225 1
    66 
    67 bark_pat alias my_bark_mat bark_mat
    68 
    69 my_bark_mat cone top
    70 0
    71 0
    72 8
    73 	0	0	0
    74 	0	0	1
    75 	$thisrad	.02
    76 
    77 my_bark_mat sphere tip
    78 0
    79 0
    80 4	0	0	1	.02
    81 _EOF_
    82 if ( ! $?needles ) set needles=n.$nleaves.oct
    83 if ( ! -f $needles ) then
    84 oconv -f "\!cnt $nleaves | rcalc -e nl=$nleaves -o needle.fmt" > $needles
    85 endif
    86 echo leaf_mat instance needles 1 $needles 0 0 >> $tree
    87 #
    88 # Now grow tree:
    89 #
    90 #	1) Save oldtree
    91 #	2) Move tree up and extend trunk
    92 #	3) Duplicate oldtree at branch positions
    93 #	4) Repeat
    94 #
    95 @ i=0
    96 while ($i < $nlevels)
    97 	mv -f $tree $oldtree
    98 	set lastrad=$thisrad
    99 	set move=`ev "(2*$aspect)^($i+1)"`
   100 	set thisrad=`ev "$lastrad+$move*.015"`
   101 	xform -ry `ev "25/($i+1)"` -t 0 0 $move $oldtree > $tree
   102 	echo void colorpict bark_pat 9 red green blue pinebark.hdr \
   103 			cyl.cal cyl_match_u cyl_match_v -s $thisrad >> $tree
   104 	echo 0 2 1.5225225 1 bark_pat alias my_bark_mat bark_mat >> $tree
   105 	echo my_bark_mat cone level$i 0 0 8 0 0 0 0 0 \
   106 			$move $thisrad $lastrad >> $tree
   107 	set spin=(`ev "rand($i)*360" "rand($i+$nlevels)*360" "rand($i+2*$nlevels)*360" "rand($i+3*$nlevels)*360" "rand($i+4*$nlevels)*360" "rand($i+5*$nlevels)*360" "rand($i+6*$nlevels)*360"`)
   108 	xform -n b1 -s 1.1 -rz $spin[2] -ry -80 -rz $spin[1] -rz 5 -t 0 0 \
   109 		`ev "$move*.42"` $oldtree >> $tree
   110 	xform -n b2 -s 1.1 -rz $spin[3] -ry -78 -rz $spin[1] -rz 128 -t 0 0 \
   111 		`ev "$move*.44"` $oldtree >> $tree
   112 	xform -n b3 -s 1.1 -rz $spin[4] -ry -75 -rz $spin[1] -rz 255 -t 0 0 \
   113 		`ev "$move*.40"` $oldtree >> $tree
   114 	xform -n b4 -rz $spin[5] -ry -80 -rz $spin[1] -rz 58 -t 0 0 \
   115 		`ev "$move*.92"` $oldtree >> $tree
   116 	xform -n b5 -rz $spin[6] -ry -78 -rz $spin[1] -rz 181 -t 0 0 \
   117 		`ev "$move*.84"` $oldtree >> $tree
   118 	xform -n b6 -rz $spin[7] -ry -75 -rz $spin[1] -rz 297 -t 0 0 \
   119 		`ev "$move*.88"` $oldtree >> $tree
   120 	@ i++
   121 end
   122 #
   123 # Send final tree
   124 #
   125 cat $tree
   126 done:
   127 rm -f $tree $oldtree