// create a regular point light source #include "transforms.inc" #macro MakeTree(TH,BS,TRS,BTex,FTex) #declare TRand1 = seed(TRS); #declare BArr = array[2000] #declare BArrC = -1; #declare MArr1 = array[2000] #declare MArr2 = array[2000] #declare MArr3 = array[2000] #declare MArrC = -1; #local BC = 0; #local BTot = (TH - BS)*7; #while(BC < BTot) #declare BH = rand(TRand1)*(TH-BS) + BS; #local BC = BC + 1; #declare BArrC = BArrC + 1; #declare BYRot = 360*rand(TRand1); MakeBranch(BH,TH,TH/3) #end #declare Trunk = cone{0,TH*0.02,y*TH,TH*0.005 texture{BTex}} #local BC = 0; #declare Branches = union{ #while(BC <= BArrC) object{BArr[BC]} #local BC = BC + 1; #end texture{BTex} } #local BC = 0; #declare Foliage = mesh{ #while(BC < MArrC) triangle{MArr1[BC],MArr2[BC],MArr3[BC]} #local BC = BC + 1; #end texture{FTex} } #end #macro MakeBranch(BH,TH,BBL) //branchheight, Treeheight, basebranchlength #local BHR = max(0.1,(TH-BH)/TH + (rand(TRand1)-0.5)/5); #local BL = BBL * BHR; #local STot = max(1,int(BL*4)); #local SC = 0; #declare P1 = <0,0,0>; #declare BArr[BArrC] = #if(STot = 1) object{ #else union{ #end #while(SC < STot) #local SC = SC + 1; #local XShift = P1.x + (rand(TRand1)*0.2 - 0.1); #local YShift = P1.y + (rand(TRand1)*0.1); #local ZShift = P1.z + max(0.05,(rand(TRand1)*0.5)); #declare P2 = ; cylinder{P1, P2, BHR * 0.05} MakeTriangs(P1,P2) #declare P1 = P2; #end rotate y*BYRot translate y*BH } #end #macro MakeTriangs(SP,EP) #local AV3 = vtransform(, transform{rotate y*BYRot}); #local BV3 = vtransform(, transform{rotate y*BYRot}); #declare MArrC = MArrC + 1; #declare MArr1[MArrC] = vtransform(, transform{rotate y*BYRot}); #declare MArr2[MArrC] = vtransform(, transform{rotate y*BYRot}); #declare MArr3[MArrC] = AV3; #declare MArrC = MArrC + 1; #declare MArr1[MArrC] = MArr1[MArrC-1]; #declare MArr2[MArrC] = MArr1[MArrC-1]; #declare MArr3[MArrC] = BV3; #end #macro MakeTreeSnow(TO,TB,BRS) #local BRand1 = seed(BRS); #local BCount1 = 1; #local Working = true; #while(Working) #if(BCount1 >= TB) #local Working = false; #end #local XTrans = 10*rand(BRand1)-5; #local ZTrans = 10*rand(BRand1)-5; #local Norm = <0,0,0>; #local Inter = trace(TO, , <0,-10,0>, Norm); #local BlobTrans = ; #if(vlength(Norm)!=0) sphere{0,0.2,1 translate BlobTrans } #local BCount1 = BCount1 + 1; #end #end #end