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