########################################################################### # YafDay.py ########################################################################### # Timed Daylight for Yafray # This script home www.selleri.org/Blender ########################################################################### # Copyright (C) 2003 Stefano Selleri # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ########################################################################### # Revision History # 25-03-2003 v. 00.00.01 - Project starts ########################################################################### import os; import re; import sys; import getopt; import string; from math import * ####################################################################### def main(argv): ####################################################################### # MAIN function ####################################################################### Latitudo = 43.754 Heading = 180.0 Start = 6.0 End = 18.0 Frames = 100 OnlyFiles = 0 OnlySky = 0 YafrayCommand = "yafray" try: opts, args = getopt.getopt(sys.argv[1:],"L:H:s:e:y:f:nhS",["help"]); except getopt.GetoptError: print "Use the -h or --help switches for full help\n"; sys.exit(2) for opt,arg in opts: if opt in ("-h", "--help"): YafDayHelp() sys.exit() elif opt == '-L': Latitudo = float(arg) elif opt == '-H': Heading = float(arg) elif opt == '-s': Start = float(arg) elif opt == '-e': End = float(arg) elif opt == '-f': Frames = int(arg) elif opt == '-n': OnlyFiles = 1 elif opt == '-S': OnlySky = 1 elif opt == '-y': YafrayCommand = arg if (len(args)>0): XMLfile = args[0] FP = open(XMLfile,"r") Skeleton = FP.read(-1) FP.close() else: if (OnlySky!=1): print "Use the -h or --help switches for full help\n" sys.exit(2) Theta0 = pi/2 - (Latitudo*pi/180.) Phi0 = - Heading*(pi/180.) if (Frames>1): for f in range (Frames): t = pi * ( (End - Start)*f/(Frames-1) + Start ) / 12 u = cos(t) v = sin(t) x1 = v y1 = u * cos(Theta0) z1 = - u * sin(Theta0) x = x1 * cos(Phi0) + y1 * sin(Phi0) y = - x1 * sin(Phi0) + y1 * cos(Phi0) z = z1 Sunsky = " type=\"sunsky\" name =\"Here Comes The Sun!\" turbidity =\"4.000000\" add_sun=\"on\"> "; if (OnlySky!=1): ss = re.search("", Skeleton,re.S+re.I) s1 = Skeleton.replace(ss.group(1),Sunsky,1) s1 = re.sub("", "", s1,re.S+re.I) FO = open("frame"+string.zfill(str(f+1),4)+".xml","w") FO.write(s1) FO.close() if (OnlyFiles!=1): os.system(YafrayCommand+" frame"+string.zfill(str(f+1),4)+".xml"); else: print ""+Sunsky+""; ####################################################################### def YafDayHelp(): ####################################################################### # Help function ####################################################################### print "YafDay (C) 2003 Stefano Selleri - Released under GNU GPL\n" print " Hacks a given YafRay XML file creating a daylight animation, " print " i.e. a moving Sun\n"; print " Usage: python YafDay.py [-nS] [-s start] [-e end] [-f frames] " print " [-L Latitudo] [-H heading] [-y yafray] Base.xml\n" print "Base.xml A YafRay XML file to be hacked. This is done by:" print " REPALACING an EXISTING group" print " with an appropriate new one" print " REPLACING the EXISTING outfile name with f#.tga with " print " # an appropriate 4 digit number for the current frame." print " New file is named frame#.xml\n" print "-n if used the frame#.xml files are created, but yafray" print " is not executed.\n" print "-S if used computed groups are printed to" print " screen and no other operation at all is carried out.\n" print "-s start Float number of the start hour of the day in 24h notation" print " i.e. 6.5 is 6:30 am 19.25 is 7:15 pm [defaults to 6:00am]\n" print "-e end Float number of the end hour of the day [defaults to 6:00pm]"; print "-f frames Integer number of frames to produce [defaults to 100]"; print "-L Latitudo Float of the latitudo, in degrees. [defaults to 43.754 (Florence)]\n" print "-H Heading Direction of the North in the Global coordinate system" print " It is the angle (degrees) between the North and the positive y" print " direction (well, not completely sure of this) [defaults to 180]\n" print "-y yafray The command line to launch yafray. Default is 'yafray' which" print " of course works only if yafray is in the PATH...\n" if __name__ == "__main__": main(sys.argv[1:])