################################################################ # Sun angles animation. Create a sequence animating the sun. ################################################################ from pymaxwell import * from math import * def sun_angles_animation(mxs,out_path,out_name,n_frames): scene = Cmaxwell(mwcallback) if scene.readMXS(mxs): zenith = 90.0 # sun starts at the bottom (horizon) azimith = 0.0 scene.getEnvironment().setSunPositionType(1) incz = 180.0 / n_frames # sun goes up and down inca = 4*360.0 / n_frames # 4 turnarounds for i in range(n_frames): new_zenith = sin(radians(abs(zenith-incz*i)))*pi/2.0 new_azimuth = radians(azimith+inca*i) scene.getEnvironment().setSunAngles(new_zenith,new_azimuth) z,a,ok = scene.getEnvironment().getSunAngles() print str(z)+' '+str(a)+' '+str(i) frame_name = mxs_outpath+mxs_outname+'{0:0>4d}'.format(i)+'.mxs' if not scene.writeMXS(frame_name): print 'error saving '+frame_name return 0 params = [] params.append('-mxs:'+frame_name) params.append('-a:0-'+str(n_frames)) params.append('-mxi:'+mxs_outpath+'render.mxi') params.append('-output:'+mxs_outpath+'render.jpg') params.append('-sl:3') params.append('-nowait') runMaxwell(params) else: print 'error reading '+mxs return 0 return 1 mxs = 'C:/scenes/pythontest/cylinder_sky.mxs' mxs_outpath = 'C:/scenes/pythontest/cylinder_sky/' mxs_outname = 'cylinder_sky' if not sun_angles_animation(mxs,mxs_outpath,mxs_outname,240): print 'ERROR' else: print 'OK'