This is fantastic
cheers!
Got a few ideas. Add the ability to spread the lightmap automatically across many lightmaps so the resolution is still nice when lightmapping a large object.
btw Modified the code work on the latest u6 release
If you can't get the lightmap functions to work with u6 then just replace it with this.
`-------`
` basic LightMap Generation Function
` by Evolved
`-------`
`-------`
type ColBox
xa as integer
xb as integer
ya as integer
yb as integer
endtype
type PolyData
VxA as float
VyA as float
VzA as float
VxB as float
VyB as float
VzB as float
VxC as float
VyC as float
VzC as float
VindexA as integer
VindexB as integer
VindexC as integer
endtype
#Constant FVF_xyz 0x002
#Constant FVF_NORMAL 0x010
#Constant FVF_tex2 0x200
`-------`
function Setup_Data( O , L )
global dim Light_Rang_#(L)
global dim Light_Pos_X_#(L)
global dim Light_Pos_Y_#(L)
global dim Light_Pos_Z_#(L)
global dim Light_Ang_X_#(L)
global dim Light_Ang_Y_#(L)
global dim Light_Ang_Z_#(L)
global dim Light_SpotRadius_#(L)
global dim Light_R_#(L)
global dim Light_G_#(L)
global dim Light_B_#(L)
global dim Light_Type(L)
global dim Object_Lightmap_Texture(O)
global dim Exclude_Object_Lightmap(O)
global dim Size#(0)
global dim Resolution#(0)
global dim Blur(0)
global dim Shadows(0)
global dim AmbientR(0)
global dim AmbientG(0)
global dim AmbientB(0)
global dim DRONE_OBJECT(0)
global dim MEMBLOCK_OBJECT(0)
global dim MEMBLOCK_OBJECT2(0)
global dim MEMBLOCK_IMAGE(0)
global dim VECTOR3(0)
DRONE_OBJECT(0)=1000
MEMBLOCK_OBJECT(0)=250
MEMBLOCK_OBJECT2(0)=251
MEMBLOCK_IMAGE(0)=252
VECTOR3(0)=250
endfunction
`-------`
function LightMap_Properties( Size# , Resolution# , Blur, Shadows , AmbientR , AmbientG , AmbientB )
Size#(0)=Size#
Resolution#(0)=Resolution#
Blur(0)=Blur
Shadows(0)=Shadows
AmbientR(0)=AmbientR
AmbientG(0)=AmbientG
AmbientB(0)=AmbientB
endfunction
`-------`
function Generate_LightMap( ImageNum , SO , EO , SL , EL )
`setup
litpixels=0
NewTexture=1
Biasx#=-0.25
Biasy#=-0.25
lastposx=Blur(0)+2
start_x=0
start_y=0
vectexnum=0
DoneVertexes=0
set image colorkey AmbientR(0),AmbientG(0),AmbientB(0)
dim col_box() as ColBox
dim xspace(Size#(0))
vec=make vector3(VECTOR3(0))
`make drone object
make object box DRONE_OBJECT(0),0,0,0
`set object collisiion
for ob=SO to EO
if Exclude_Object_Lightmap(ob)=0
setupComplexObject ob,1,0
make mesh from object 1,ob
make memblock from mesh MEMBLOCK_OBJECT(0),1
delete mesh 1
vectexnum=vectexnum+memblock dword(MEMBLOCK_OBJECT(0),8)
delete memblock MEMBLOCK_OBJECT(0)
endif
next ob
`progress bar
DarkSide_Set_Progress_Bar_Title "Lightmap Progress"
DarkSide_Set_Progress_Bar_Style 0
DarkSide_Make_Progress_Bar
`set bitmap
create bitmap 1,Size#(0)+4,Size#(0)+4
set current bitmap 1
ink rgb(AmbientR(0),AmbientG(0),AmbientB(0)),0
box 0,0,Size#(0),Size#(0)
`make image memblock
if image exist(ImageNum)=1 then delete image ImageNum
get image ImageNum,0,0,Size#(0),Size#(0)
make memblock from image MEMBLOCK_IMAGE(0),ImageNum
write memblock dword MEMBLOCK_IMAGE(0),0,Size#(0)
write memblock dword MEMBLOCK_IMAGE(0),4,Size#(0)
delete image ImageNum
`start looping through all objets
for ob=SO to EO
if Exclude_Object_Lightmap(ob)=0
`reset lightmap Texture
Object_Lightmap_Texture(ob)=0
`object data
objpx#=object position x(ob)
objpy#=object position y(ob)
objpz#=object position z(ob)
objax#=object angle x(ob)
objay#=object angle y(ob)
objaz#=object angle z(ob)
objsx#=100*(object size x(ob,1)/object size x(ob))
objsy#=100*(object size y(ob,1)/object size y(ob))
objsz#=100*(object size z(ob,1)/object size z(ob))
texture=limb texture(ob,0)
`base object memblock
FVF=( FVF_xyz || FVF_NORMAL || FVF_tex2)
convert object fvf ob,FVF
position object ob,0,0,0
make mesh from object 1,ob
make memblock from mesh MEMBLOCK_OBJECT(0),1
delete mesh 1
`base lightmap object memblock
rotate object ob,0,0,0
scale object ob,100,100,100
make mesh from object 1,ob
make memblock from mesh MEMBLOCK_OBJECT2(0),1
delete mesh 1
`restore object
New_Texture:
position object ob,objpx#,objpy#,objpz#
rotate object ob,objax#,objay#,objaz#
scale object ob,objsx#,objsy#,objsz#
`start looping through vertexes
Vertexes=memblock dword(MEMBLOCK_OBJECT(0),8)
for v=0 to Vertexes-1
`reset arrays
dim Poly() as PolyData
dim Addpoly()
dim Finallights()
NextVertex=0
polyadded=0
`start repeat loop
repeat
nextpoly=0
dim Uselight()
`store vertex data
array insert at bottom Poly()
c = array count(Poly())
Poly(c).VxA=memblock float(MEMBLOCK_OBJECT(0),12+(40*v)+0)+objpx#
Poly(c).VyA=memblock float(MEMBLOCK_OBJECT(0),12+(40*v)+4)+objpy#
Poly(c).VzA=memblock float(MEMBLOCK_OBJECT(0),12+(40*v)+8)+objpz#
Poly(c).VindexA=v
v=v+1
Poly(c).VxB=memblock float(MEMBLOCK_OBJECT(0),12+(40*v)+0)+objpx#
Poly(c).VyB=memblock float(MEMBLOCK_OBJECT(0),12+(40*v)+4)+objpy#
Poly(c).VzB=memblock float(MEMBLOCK_OBJECT(0),12+(40*v)+8)+objpz#
Poly(c).VindexB=v
v=v+1
Poly(c).VxC=memblock float(MEMBLOCK_OBJECT(0),12+(40*v)+0)+objpx#
Poly(c).VyC=memblock float(MEMBLOCK_OBJECT(0),12+(40*v)+4)+objpy#
Poly(c).VzC=memblock float(MEMBLOCK_OBJECT(0),12+(40*v)+8)+objpz#
Poly(c).VindexC=v
v=v+1
`poly normals
XN#=(Poly(c).VyB-Poly(c).VyA)*(Poly(c).VzC-Poly(c).VzA)-(Poly(c).VzB-Poly(c).VzA)*(Poly(c).VyC-Poly(c).VyA)
YN#=(Poly(c).VzB-Poly(c).VzA)*(Poly(c).VxC-Poly(c).VxA)-(Poly(c).VxB-Poly(c).VxA)*(Poly(c).VzC-Poly(c).VzA)
ZN#=(Poly(c).VxB-Poly(c).VxA)*(Poly(c).VyC-Poly(c).VyA)-(Poly(c).VyB-Poly(c).VyA)*(Poly(c).VxC-Poly(c).VxA)
`find poly position and size
INCposx#=-10000:DECposx#=10000:INCposy#=-10000:DECposy#=10000:INCposz#=-10000:DECposz#=10000
if Poly(c).VxA>INCposx# then INCposx#=Poly(c).VxA
if DECposx#>Poly(c).VxA then DECposx#=Poly(c).VxA
if Poly(c).VxB>INCposx# then INCposx#=Poly(c).VxB
if DECposx#>Poly(c).VxB then DCEposx#=Poly(c).VxB
if Poly(c).VxC>INCposx# then INCposx#=Poly(c).VxC
if DECposx#>Poly(c).VxC then DECposx#=Poly(c).VxC
if Poly(c).VyA>INCposy# then INCposy#=Poly(c).VyA
if DECposy#>Poly(c).VyA then DECposy#=Poly(c).VyA
if Poly(c).VyB>INCposy# then INCposy#=Poly(c).VyB
if DECposy#>Poly(c).VyB then DECposy#=Poly(c).VyB
if Poly(c).VyC>INCposy# then INCposy#=Poly(c).VyC
if DECposy#>Poly(c).VyC then DECposy#=Poly(c).VyC
if Poly(c).VzA>INCposz# then INCposz#=Poly(c).VzA
if DECposz#>Poly(c).VzA then DECposz#=Poly(c).VzA
if Poly(c).VzB>INCposz# then INCposz#=Poly(c).VzB
if DECposz#>Poly(c).VzB then DECposz#=Poly(c).VzB
if Poly(c).VzC>INCposz# then INCposz#=Poly(c).VzC
if DECposz#>Poly(c).VzC then DECposz#=Poly(c).VzC
position object DRONE_OBJECT(0),INCposx#,INCposy#,INCposz#
point object DRONE_OBJECT(0),DECposx#,DECposy#,DECposz#
set vector3 VECTOR3(0),INCposx#-DECposx#,INCposy#-DECposy#,INCposz#-DECposz#
dis#=length vector3(VECTOR3(0))
move object DRONE_OBJECT(0),dis#/2
pos_x#=object position x(DRONE_OBJECT(0))
pos_y#=object position y(DRONE_OBJECT(0))
pos_z#=object position z(DRONE_OBJECT(0))
set vector3 VECTOR3(0),INCposx#-DECposx#,0,0:size_x#=length vector3(VECTOR3(0))
set vector3 VECTOR3(0),0,INCposy#-DECposy#,0:size_y#=length vector3(VECTOR3(0))
set vector3 VECTOR3(0),0,0,INCposz#-DECposz#:size_z#=length vector3(VECTOR3(0))
`poly angle
position object DRONE_OBJECT(0),0,0,0
point object DRONE_OBJECT(0),XN#,YN#,ZN#
angx#=wrapvalue(object angle x(DRONE_OBJECT(0)))
angy#=wrapvalue(object angle y(DRONE_OBJECT(0)))
angz#=wrapvalue(object angle z(DRONE_OBJECT(0)))
`find poly angle group
if angy#>134 and angy#<226 then polyangle=1
if angy#<46 and angy#>-1 then polyangle=2
if angy#>314 and angy#<361 then polyangle=2
if angy#>224 and angy#<316 then polyangle=3
if angy#>44 and angy#<136 then polyangle=4
if angx#>44 and angx#<136 then polyangle=5
if angx#>224 and angx#<316 then polyangle=6
`only use polys that are facing at a light source
`and in range by collision box
polyuse=1
for l=SL to EL
col_pos_xa#=pos_x#-(size_x#+light_rang_#(l))
col_pos_xb#=pos_x#+(size_x#+light_rang_#(l))
col_pos_ya#=pos_y#-(size_y#+light_rang_#(l))
col_pos_yb#=pos_y#+(size_y#+light_rang_#(l))
col_pos_za#=pos_z#-(size_z#+light_rang_#(l))
col_pos_zb#=pos_z#+(size_z#+light_rang_#(l))
if light_pos_X_#(l)>col_pos_xa# and light_pos_X_#(l)<col_pos_xb# and light_pos_y_#(l)>col_pos_ya# and light_pos_y_#(l)<col_pos_yb# and light_pos_z_#(l)>col_pos_za# and light_pos_z_#(l)<col_pos_zb#
DisAngle#=Angle_Dis(angx#,angy#,angz#,Poly(c).VxA,Poly(c).VyA,Poly(c).VzA,light_pos_X_#(l),light_pos_Y_#(l),light_pos_Z_#(l))
if DisAngle#>0
polyuse=0
array insert at bottom Uselight()
lc = array count(Uselight())
Uselight(lc)=l
endif
endif
next l
`store polys we want to use
if NextVertex=0 and polyuse=0
anglegroup=polyangle
array insert at bottom Addpoly()
ac = array count(Addpoly())
Addpoly(ac)=c
nextpoly=1
polyadded=1
lc = array count(Uselight())
for l=0 to lc
array insert at bottom Finallights()
Finallights(l)=Uselight(l)
next l
NextVertex=1
endif
if NextVertex=1 and polyuse=0 and polyangle=anglegroup
ac = array count(Addpoly())
Add=0
for i=0 to ac
if Poly(c).VxA=Poly(Addpoly(i)).VxA and Poly(c).VyA=Poly(Addpoly(i)).VyA and Poly(c).VzA=Poly(Addpoly(i)).VzA then Add=Add+1
if Poly(c).VxA=Poly(Addpoly(i)).VxB and Poly(c).VyA=Poly(Addpoly(i)).VyB and Poly(c).VzA=Poly(Addpoly(i)).VzB then Add=Add+1
if Poly(c).VxA=Poly(Addpoly(i)).VxC and Poly(c).VyA=Poly(Addpoly(i)).VyC and Poly(c).VzA=Poly(Addpoly(i)).VzC then Add=Add+1
if Poly(c).VxB=Poly(Addpoly(i)).VxA and Poly(c).VyB=Poly(Addpoly(i)).VyA and Poly(c).VzB=Poly(Addpoly(i)).VzA then Add=Add+1
if Poly(c).VxB=Poly(Addpoly(i)).VxB and Poly(c).VyB=Poly(Addpoly(i)).VyB and Poly(c).VzB=Poly(Addpoly(i)).VzB then Add=Add+1
if Poly(c).VxB=Poly(Addpoly(i)).VxC and Poly(c).VyB=Poly(Addpoly(i)).VyC and Poly(c).VzB=Poly(Addpoly(i)).VzC then Add=Add+1
if Poly(c).VxC=Poly(Addpoly(i)).VxA and Poly(c).VyC=Poly(Addpoly(i)).VyA and Poly(c).VzC=Poly(Addpoly(i)).VzA then Add=Add+1
if Poly(c).VxC=Poly(Addpoly(i)).VxB and Poly(c).VyC=Poly(Addpoly(i)).VyB and Poly(c).VzC=Poly(Addpoly(i)).VzB then Add=Add+1
if Poly(c).VxC=Poly(Addpoly(i)).VxC and Poly(c).VyC=Poly(Addpoly(i)).VyC and Poly(c).VzC=Poly(Addpoly(i)).VzC then Add=Add+1
next i
if Add>1
array insert at bottom Addpoly()
ac = array count(Addpoly())
Addpoly(ac)=c
nextpoly=1
polyadded=1
lc = array count(Uselight())
for l=0 to lc
uselight_=0
lightcalc = array count(Finallights())
for l_test = 0 to lightcalc
if Finallights(l_test)=Uselight(l) then uselight_=1
next l_test
if uselight_=0
array insert at bottom Finallights()
lightcalc = array count(Finallights())
Finallights(lightcalc)=Uselight(l)
endif
next l
endif
endif
`Reste uv data to non lit areas
if polyadded=0
write memblock float MEMBLOCK_OBJECT2(0),44+(40*Poly(c).VindexA)+0,1/Size#(0)
write memblock float MEMBLOCK_OBJECT2(0),44+(40*Poly(c).VindexA)+4,1/Size#(0)
write memblock float MEMBLOCK_OBJECT2(0),44+(40*Poly(c).VindexB)+0,1/Size#(0)
write memblock float MEMBLOCK_OBJECT2(0),44+(40*Poly(c).VindexB)+4,1/Size#(0)
write memblock float MEMBLOCK_OBJECT2(0),44+(40*Poly(c).VindexC)+0,1/Size#(0)
write memblock float MEMBLOCK_OBJECT2(0),44+(40*Poly(c).VindexC)+4,1/Size#(0)
endif
`Next poly
undim Uselight()
if polyadded=0 then endloop=1
if polyadded=1 then endloop=0
if v>Vertexes-1 and anglegroup=polyangle then endloop=1:nextpoly=0
until nextpoly=0
if endloop=0 then v=v-4
if endloop=1 then v=v-1
`if were need to add lit areas to a polgon then continue
if polyadded=1
`overall size and position
INCposx#=-10000:DECposx#=10000:INCposy#=-10000:DECposy#=10000:INCposz#=-10000:DECposz#=10000
ac = array count(Addpoly())
for i = 0 to ac
if Poly(Addpoly(i)).VxA>INCposx# then INCposx#=Poly(Addpoly(i)).VxA
if DECposx#>Poly(Addpoly(i)).VxA then DECposx#=Poly(Addpoly(i)).VxA
if Poly(Addpoly(i)).VxB>INCposx# then INCposx#=Poly(Addpoly(i)).VxB
if DECposx#>Poly(Addpoly(i)).VxB then DECposx#=Poly(Addpoly(i)).VxB
if Poly(Addpoly(i)).VxC>INCposx# then INCposx#=Poly(Addpoly(i)).VxC
if DECposx#>Poly(Addpoly(i)).VxC then DECposx#=Poly(Addpoly(i)).VxC
if Poly(Addpoly(i)).VyA>INCposy# then INCposy#=Poly(Addpoly(i)).VyA
if DECposy#>Poly(Addpoly(i)).VyA then DECposy#=Poly(Addpoly(i)).VyA
if Poly(Addpoly(i)).VyB>INCposy# then INCposy#=Poly(Addpoly(i)).VyB
if DECposy#>Poly(Addpoly(i)).VyB then DECposy#=Poly(Addpoly(i)).VyB
if Poly(Addpoly(i)).VyC>INCposy# then INCposy#=Poly(Addpoly(i)).VyC
if DECposy#>Poly(Addpoly(i)).VyC then DECposy#=Poly(Addpoly(i)).VyC
if Poly(Addpoly(i)).VzA>INCposz# then INCposz#=Poly(Addpoly(i)).VzA
if DECposz#>Poly(Addpoly(i)).VzA then DECposz#=Poly(Addpoly(i)).VzA
if Poly(Addpoly(i)).VzB>INCposz# then INCposz#=Poly(Addpoly(i)).VzB
if DECposz#>Poly(Addpoly(i)).VzB then DECposz#=Poly(Addpoly(i)).VzB
if Poly(Addpoly(i)).VzC>INCposz# then INCposz#=Poly(Addpoly(i)).VzC
if DECposz#>Poly(Addpoly(i)).VzC then DECposz#=Poly(Addpoly(i)).VzC
next i
position object DRONE_OBJECT(0),DECposx#,DECposy#,DECposz#
point object DRONE_OBJECT(0),INCposx#,INCposy#,INCposz#
set vector3 VECTOR3(0),INCposx#-DECposx#,INCposy#-DECposy#,INCposz#-DECposz#
dis#=length vector3(VECTOR3(0))
move object DRONE_OBJECT(0),dis#/2
pos_x#=object position x(DRONE_OBJECT(0))
pos_y#=object position y(DRONE_OBJECT(0))
pos_z#=object position z(DRONE_OBJECT(0))
set vector3 VECTOR3(0),INCposx#-DECposx#,0,0:size_x#=length vector3(VECTOR3(0))
set vector3 VECTOR3(0),0,INCposy#-DECposy#,0:size_y#=length vector3(VECTOR3(0))
set vector3 VECTOR3(0),0,0,INCposz#-DECposz#:size_z#=length vector3(VECTOR3(0))
`2d scale
if anglegroup=1 or anglegroup=2 then sx#=size_x#:sy#=size_y#
if anglegroup=3 or anglegroup=4 then sx#=size_z#:sy#=size_y#
if anglegroup=5 or anglegroup=6 then sx#=size_x#:sy#=size_z#
`loop through pixels
for y=Blur(0)+2 to Size#(0)-1
for x=lastposx to Size#(0)-1
`last X texture space used
if ((sx#/Resolution#(0))+(Blur(0)+2)+1)>(Size#(0)-xspace(y))-1 then lastposx=Blur(0)+2:goto Next_Pixely:
if x+(sx#/Resolution#(0))+(Blur(0)+2)+1>Size#(0)-1 then lastposx=Blur(0)+2:goto Next_Pixely:
`if texture space not in use
if x+(sx#/Resolution#(0))+(Blur(0)+2)<Size#(0)-1
if y+(sy#/Resolution#(0))+(Blur(0)+2)<Size#(0)-1
`cheack if space is not in use on the overall 2d scale
for c=0 to array count(col_box())
if x>col_box(c).xa-((sx#/Resolution#(0))+(Blur(0)+2)+2) and x<col_box(c).xb
if y>col_box(c).ya-((sy#/Resolution#(0))+(Blur(0)+2)+2) and y<col_box(c).yb
x=col_box(c).xb-1
goto Next_Pixel:
endif
endif
next c
`if the texture space is not in use then use it
start_x=x
start_y=y
array insert at bottom col_box()
c = array count(col_box())
col_box(c).xa=x-2
col_box(c).ya=y-2
col_box(c).xb=x+(sx#/Resolution#(0))+(Blur(0)+2)+2
col_box(c).yb=y+(sy#/Resolution#(0))+(Blur(0)+2)+2
xspace(y)=xspace(y)+(sx#/Resolution#(0))+(Blur(0)+2)+2
lastposx=x+(sx#/Resolution#(0))+(Blur(0)+2)
goto Use_Texture_Space
endif
endif
Next_Pixel:
`if current face size exceeds texture size
if x+(sx#/Resolution#(0))+(Blur(0)+2)>Size#(0)-1
if y+(sy#/Resolution#(0))+(Blur(0)+2)>Size#(0)-1
goto Skip_Pixel:
endif
endif
`next pixel x/y
next x
Next_Pixely:
next y
Skip_Pixel:
`genrate texture and start a new one
Get_LightMap_Image(ImageNum,Blur(0),Size#(0))
set image colorkey AmbientR(0) , AmbientG(0) , AmbientB(0)
ImageNum=ImageNum+1
`reset array data
undim col_box()
undim xspace(Size#(0))
undim Poly()
undim Addpoly()
undim Finallights()
dim col_box() as colbox
dim xspace(Size#(0))
lastposx=Blur(0)+2
start_x=0
start_y=0
`reset image memblock
delete memblock MEMBLOCK_IMAGE(0)
ink rgb(AmbientR(0),AmbientG(0),AmbientB(0)),0
box 0,0,Size#(0),Size#(0)
if image exist(ImageNum+1)=1 then delete image ImageNum+1
get image ImageNum+1,0,0,Size#(0),Size#(0)
make memblock from image MEMBLOCK_IMAGE(0),ImageNum+1
write memblock dword MEMBLOCK_IMAGE(0),0,Size#(0)
write memblock dword MEMBLOCK_IMAGE(0),4,Size#(0)
delete image ImageNum+1
`if texture is new then the object wont fit on to the
`current texture size so exit the calculation
if NewTexture=1 then goto End_Lightmap_Calculation
NewTexture=1
goto New_Texture:
`texture space is free so fill in the newly uesed spots
Use_Texture_Space:
NewTexture=0
`start looping through pixels
for x=0 to (sx#/Resolution#(0))
for y=0 to (sy#/Resolution#(0))
`start drone object from correct position
select anglegroup
case 1
rotate object DRONE_OBJECT(0),0,0,0
position object DRONE_OBJECT(0),DECposx#+(x*Resolution#(0)),INCposy#-(y*Resolution#(0)),pos_z#-(1+(size_z#/2))
if x=0 then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0))+0.1,object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))
if y=0 then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0))-0.1,object position z(DRONE_OBJECT(0))
if x=(sx#/Resolution#(0)) then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0))-0.1,object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))
if y=(sy#/Resolution#(0)) then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0))+0.1,object position z(DRONE_OBJECT(0))
endcase
case 2
rotate object DRONE_OBJECT(0),0,0,0
position object DRONE_OBJECT(0),DECposx#+(x*Resolution#(0)),INCposy#-(y*Resolution#(0)),pos_z#+(1+(size_z#/2))
if x=0 then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0))+0.1,object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))
if y=0 then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0))-0.1,object position z(DRONE_OBJECT(0))
if x=(sx#/Resolution#(0)) then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0))-0.1,object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))
if y=(sy#/Resolution#(0)) then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0))+0.1,object position z(DRONE_OBJECT(0))
endcase
case 3
rotate object DRONE_OBJECT(0),0,90,0
position object DRONE_OBJECT(0),pos_x#-(1+(size_x#/2)),INCposy#-(y*Resolution#(0)),DECposz#+(x*Resolution#(0))
if x=0 then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))+0.1
if y=0 then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0))-0.1,object position z(DRONE_OBJECT(0))
if x=(sx#/Resolution#(0)) then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))-0.1
if y=(sy#/Resolution#(0)) then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0))+0.1,object position z(DRONE_OBJECT(0))
endcase
case 4
rotate object DRONE_OBJECT(0),0,90,0
position object DRONE_OBJECT(0),pos_x#+(1+(size_x#/2)),INCposy#-(y*Resolution#(0)),DECposz#+(x*Resolution#(0))
if x=0 then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))+0.1
if y=0 then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0))-0.1,object position z(DRONE_OBJECT(0))
if x=(sx#/Resolution#(0)) then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))-0.1
if y=(sy#/Resolution#(0)) then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0))+0.1,object position z(DRONE_OBJECT(0))
endcase
case 5
rotate object DRONE_OBJECT(0),90,0,0
position object DRONE_OBJECT(0),DECposx#+(x*Resolution#(0)),pos_y#-(1+(size_y#/2)),INCposz#-(y*Resolution#(0))
if x=0 then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0))+0.1,object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))
if y=0 then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))-0.1
if x=(sx#/Resolution#(0)) then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0))-0.1,object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))
if y=(sy#/Resolution#(0)) then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))+0.1
endcase
case 6
rotate object DRONE_OBJECT(0),90,0,0
position object DRONE_OBJECT(0),DECposx#+(x*Resolution#(0)),pos_y#+(1+(size_y#/2)),INCposz#-(y*Resolution#(0))
if x=0 then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0))+0.1,object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))
if y=0 then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))-0.1
if x=(sx#/Resolution#(0)) then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0))-0.1,object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))
if y=(sy#/Resolution#(0)) then position object DRONE_OBJECT(0),object position x(DRONE_OBJECT(0)),object position y(DRONE_OBJECT(0)),object position z(DRONE_OBJECT(0))+0.1
endcase
endselect
`store old position data
x1#=object position x(DRONE_OBJECT(0))
y1#=object position y(DRONE_OBJECT(0))
z1#=object position z(DRONE_OBJECT(0))
`move drone object
if anglegroup=1 then move object DRONE_OBJECT(0),5+size_z#
if anglegroup=2 then move object DRONE_OBJECT(0),0-(5+(size_z#))
if anglegroup=3 then move object DRONE_OBJECT(0),5+size_x#
if anglegroup=4 then move object DRONE_OBJECT(0),0-(5+(size_x#))
if anglegroup=5 then move object DRONE_OBJECT(0),0-(5+(size_y#))
if anglegroup=6 then move object DRONE_OBJECT(0),5+size_y#
`store new position data
x2#=object position x(DRONE_OBJECT(0))
y2#=object position y(DRONE_OBJECT(0))
z2#=object position z(DRONE_OBJECT(0))
`collision ray
collide#=intersectObject(ob,0,x1#,y1#,z1#,x2#,y2#,z2#,0)
`if we hit some thing we need to continue
if collide#>0
`get collision data
colx#=getStaticCollisionX()
coly#=getStaticCollisionY()
colz#=getStaticCollisionZ()
normx#=getCollisionNormalX()
normy#=getCollisionNormalY()
normz#=getCollisionNormalZ()
`collisiion angle
position object DRONE_OBJECT(0),colx#+normx#/10.0,coly#+normy#/10.0,colz#+normz#/10.0
point object DRONE_OBJECT(0),colx#+normx#,coly#+normy#,colz#+normz#
angx#=object angle x(DRONE_OBJECT(0)):angy#=object angle y(DRONE_OBJECT(0)):angz#=object angle z(DRONE_OBJECT(0))
`move object forward slightly
move object DRONE_OBJECT(0),0.1
colx#=object position x(DRONE_OBJECT(0))
coly#=object position y(DRONE_OBJECT(0))
colz#=object position z(DRONE_OBJECT(0))
`pixel colour
pixel_R=AmbientR(0)
pixel_G=AmbientG(0)
pixel_B=AmbientB(0)
`start looping through lights
lc = array count(Finallights())
for l_=0 to lc
l=Finallights(l_)
`light in range ?
set vector3 VECTOR3(0),colx#-Light_Pos_X_#(l),coly#-Light_Pos_Y_#(l),colz#-Light_Pos_Z_#(l)
dis#=length vector3(VECTOR3(0))
if dis#<light_rang_#(l)
`shadowing
Ray=0
if Shadows(0)=1 then Ray=intersectObject(1,1,Light_Pos_X_#(l),Light_Pos_Y_#(l),Light_Pos_Z_#(l),colx#,coly#,colz#,0)
if Ray=0
`fall off angle
DisAngle#=Angle_Dis(angx#,angy#,angz#,colx#,coly#,colz#,Light_Pos_X_#(l),Light_Pos_Y_#(l),Light_Pos_Z_#(l))
`add spot light to fall off angle
if Light_Type(l)=1
DisAngle#=Angle_Dis(Light_Ang_X_#(L),Light_Ang_Y_#(L),Light_Ang_Z_#(L),Light_Pos_X_#(l),Light_Pos_Y_#(l),Light_Pos_Z_#(l),colx#,coly#,colz#)
DisAngle#=(DisAngle#-Light_SpotRadius_#(L))*1.5
DisAngle#=DisAngle#-(DisAngle#/100)
endif
Anglefalloff#=1-(DisAngle#/50)
if Anglefalloff#<0 then Anglefalloff#=0
if Anglefalloff#>1 then Anglefalloff#=1
`colour
col_R#=((Light_R_#(l)-AmbientR(0))/255)-Anglefalloff#
col_G#=((light_G_#(l)-AmbientG(0))/255)-Anglefalloff#
col_B#=((light_B_#(l)-AmbientB(0))/255)-Anglefalloff#
if col_R#<0 then col_R#=0
if col_G#<0 then col_G#=0
if col_B#<0 then col_B#=0
`fall off rate
falloff#=(1-(dis#/Light_Rang_#(l)))*255
if falloff#<0 then falloff#=0
`add final colour
pixel_R=pixel_R+((falloff#*(0.01+col_R#)))
pixel_G=pixel_G+((falloff#*(0.01+col_G#)))
pixel_B=pixel_B+((falloff#*(0.01+col_B#)))
if pixel_R>255 then pixel_R=255
if pixel_G>255 then pixel_G=255
if pixel_B>255 then pixel_B=255
`next light
endif
endif
next l_
`write pixel colour to memblock
position=12+(((start_y+y)-1)*Size#(0)*4)+(((start_x+x)-1)*4)
write memblock byte MEMBLOCK_IMAGE(0),position,pixel_B
write memblock byte MEMBLOCK_IMAGE(0),position+1,pixel_G
write memblock byte MEMBLOCK_IMAGE(0),position+2,pixel_R
write memblock byte MEMBLOCK_IMAGE(0),position+3,255
`next Pixels
endif
litpixels=litpixels+1
next y
next x
`set uv data
ac = array count(Addpoly())
for i=0 to ac
if anglegroup=1 or anglegroup=2
u1#=((start_x+Biasx#)+((Poly(Addpoly(i)).VxA-pos_x#)+(size_x#/2))/Resolution#(0))
v1#=((start_y+Biasy#)-((Poly(Addpoly(i)).VyA-pos_y#)-(size_y#/2))/Resolution#(0))
u2#=((start_x+Biasx#)+((Poly(Addpoly(i)).VxB-pos_x#)+(size_x#/2))/Resolution#(0))
v2#=((start_y+Biasy#)-((Poly(Addpoly(i)).VyB-pos_y#)-(size_y#/2))/Resolution#(0))
u3#=((start_x+Biasx#)+((Poly(Addpoly(i)).VxC-pos_x#)+(size_x#/2))/Resolution#(0))
v3#=((start_y+Biasy#)-((Poly(Addpoly(i)).VyC-pos_y#)-(size_y#/2))/Resolution#(0))
endif
if anglegroup=3 or anglegroup=4
u1#=((start_x+Biasx#)+((Poly(Addpoly(i)).VzA-pos_z#)+(size_z#/2))/Resolution#(0))
v1#=((start_y+Biasy#)-((Poly(Addpoly(i)).VyA-pos_y#)-(size_y#/2))/Resolution#(0))
u2#=((start_x+Biasx#)+((Poly(Addpoly(i)).VzB-pos_z#)+(size_z#/2))/Resolution#(0))
v2#=((start_y+Biasy#)-((Poly(Addpoly(i)).VyB-pos_y#)-(size_y#/2))/Resolution#(0))
u3#=((start_x+Biasx#)+((Poly(Addpoly(i)).VzC-pos_z#)+(size_z#/2))/Resolution#(0))
v3#=((start_y+Biasy#)-((Poly(Addpoly(i)).VyC-pos_y#)-(size_y#/2))/Resolution#(0))
endif
if anglegroup=5 or anglegroup=6
u1#=((start_x+Biasx#)+((Poly(Addpoly(i)).VxA-pos_x#)+(size_x#/2))/Resolution#(0))
v1#=((start_y+Biasy#)-((Poly(Addpoly(i)).VzA-pos_z#)-(size_z#/2))/Resolution#(0))
u2#=((start_x+Biasx#)+((Poly(Addpoly(i)).VxB-pos_x#)+(size_x#/2))/Resolution#(0))
v2#=((start_y+Biasy#)-((Poly(Addpoly(i)).VzB-pos_z#)-(size_z#/2))/Resolution#(0))
u3#=((start_x+Biasx#)+((Poly(Addpoly(i)).VxC-pos_x#)+(size_x#/2))/Resolution#(0))
v3#=((start_y+Biasy#)-((Poly(Addpoly(i)).VzC-pos_z#)-(size_z#/2))/Resolution#(0))
endif
write memblock float MEMBLOCK_OBJECT2(0),44+(40*Poly(Addpoly(i)).VindexA)+0,u1#/Size#(0)
write memblock float MEMBLOCK_OBJECT2(0),44+(40*Poly(Addpoly(i)).VindexA)+4,v1#/Size#(0)
write memblock float MEMBLOCK_OBJECT2(0),44+(40*Poly(Addpoly(i)).VindexB)+0,u2#/Size#(0)
write memblock float MEMBLOCK_OBJECT2(0),44+(40*Poly(Addpoly(i)).VindexB)+4,v2#/Size#(0)
write memblock float MEMBLOCK_OBJECT2(0),44+(40*Poly(Addpoly(i)).VindexC)+0,u3#/Size#(0)
write memblock float MEMBLOCK_OBJECT2(0),44+(40*Poly(Addpoly(i)).VindexC)+4,v3#/Size#(0)
next i
`end lit areas
endif
`up data progress bar
DarkSide_Set_Progress_Bar_Status (((DoneVertexes+v)*1000)/vectexnum)
`reset poly arrays
undim Poly()
undim Addpoly()
`next vertex
next v
DoneVertexes=DoneVertexes+Vertexes
`change object mesh from memblock
make mesh from memblock 1,MEMBLOCK_OBJECT2(0)
change mesh ob,0,1
delete mesh 1
position object ob,objpx#,objpy#,objpz#
rotate object ob,objax#,objay#,objaz#
scale object ob,objsx#,objsy#,objsz#
texture object ob,texture
Object_Lightmap_Texture(ob)=ImageNum
`delete base memblocks
delete memblock MEMBLOCK_OBJECT(0)
delete memblock MEMBLOCK_OBJECT2(0)
`next object
endif
next ob
`skip for mesh that wont fit on to the textue size
End_Lightmap_Calculation:
`grab light map imgae
Get_LightMap_Image(ImageNum,Blur(0),Size#(0))
`unlock bitmap
set current bitmap 0
delete bitmap 1
delete memblock MEMBLOCK_IMAGE(0)
`delete drone object and vector
delete object DRONE_OBJECT(0)
vec=delete vector3(VECTOR3(0))
`reset Pixel Space arrays
undim col_box()
undim xspace(Size#(0))
undim Finallights()
`Kill Progress Bar
DarkSide_Kill_Progress_Bar
set image colorkey 0,0,0
`apply lightmap texture etc to newly lit objects
for ob=SO to EO
if Exclude_Object_Lightmap(ob)=0
if Object_Lightmap_Texture(ob)>0
if image exist(Object_Lightmap_Texture(ob))=1
set blend mapping on ob,1,Object_Lightmap_Texture(ob),0,5
endif
set object light ob,0
removeObject ob
endif
endif
next ob
endfunction litpixels
`-------`
function Get_LightMap_Image(T,B,S#)
if image exist(T)=1 then delete image T
make image from memblock T,MEMBLOCK_IMAGE(0)
paste image T,0,0,1:paste image T,1,0,1:paste image T,2,0,1
paste image T,0,1,1:paste image T,2,1,1
paste image T,0,2,1:paste image T,1,2,1:paste image T,2,2,1
paste image T,1,1,1
delete image T
Blur bitmap 1,B
set image colorkey 0,0,0
get image T,1,1,S#+1,S#+1
endfunction
`-------`
function Angle_Dis( ang_x# , ang_y# , ang_z# , posxa# , posya# , posza# , posxb# , posyb# , poszb# )
position object DRONE_OBJECT(0),posxa#,posya#,posza#
point object DRONE_OBJECT(0),posxb#,posyb#,poszb#
move object DRONE_OBJECT(0),50
x1#=object position x(DRONE_OBJECT(0)):y1#=object position y(DRONE_OBJECT(0)):z1#=object position z(DRONE_OBJECT(0))
rotate object DRONE_OBJECT(0),ang_x#,ang_y#,ang_z#
position object DRONE_OBJECT(0),posxa#,posya#,posza#
move object DRONE_OBJECT(0),50
x2#=object position x(DRONE_OBJECT(0)):y2#=object position y(DRONE_OBJECT(0)):z2#=object position z(DRONE_OBJECT(0))
set vector3 VECTOR3(0),x1#-x2#,y1#-y2#,z1#-z2#
dis#=70-length vector3(VECTOR3(0))
dis#=dis#*1.43
endfunction dis#
`-------`
function Light_Position( L , px# , py# , pz# )
Light_Type(L)=0
Light_Pos_X_#(L)=px#
Light_Pos_Y_#(L)=py#
Light_Pos_Z_#(L)=pz#
endfunction
`-------`
function SpotLight_Position( L , px# , py# , pz# , ax# , ay# , az# , Radius# )
Light_Type(L)=1
Light_Pos_X_#(L)=px#
Light_Pos_Y_#(L)=py#
Light_Pos_Z_#(L)=pz#
Light_Ang_X_#(L)=ax#
Light_Ang_Y_#(L)=ay#
Light_Ang_Z_#(L)=az#
Light_SpotRadius_#(L)=Radius#
if Light_SpotRadius_#(L)>100 then Light_SpotRadius_#(L)=100
if Light_SpotRadius_#(L)<0 then Light_SpotRadius_#(L)=0
endfunction
`-------`
function Light_Color( L , R , G , B , Range# )
Light_R_#(L)=R
Light_G_#(L)=G
Light_B_#(L)=B
Light_Rang_#(L)=Range#
endfunction
`-------`
function Set_UV_Mapping( O , TSizex# , TSizeY# , Pos )
`object data
objpx#=object position x(O)
objpy#=object position y(O)
objpz#=object position z(O)
objax#=object angle x(O)
objay#=object angle y(O)
objaz#=object angle z(O)
objsx#=100*(object size x(O,1)/object size x(O))
objsy#=100*(object size y(O,1)/object size y(O))
objsz#=100*(object size z(O,1)/object size z(O))
texture=limb texture(O,0)
`generate base memblock from mesh
position object O,0,0,0
make mesh from object 1,O
make memblock from mesh 1,1
delete mesh 1
`generate object memblock from mesh
rotate object O,0,0,0
scale object O,100,100,100
make mesh from object 1,O
make memblock from mesh 2,1
delete mesh 1
`arrays
Vertexes=memblock dword(1,8)
VertexSize=memblock dword(1,4)
dim Vx#(3)
dim Vy#(3)
dim Vz#(3)
dim Vindex(3)
`start looping through vertexes
for v=0 to Vertexes-3
`store vertex data
Vx#(1)=memblock float(1,12+(VertexSize*v)+0)+objpx#
Vy#(1)=memblock float(1,12+(VertexSize*v)+4)+objpy#
Vz#(1)=memblock float(1,12+(VertexSize*v)+8)+objpz#
Vindex(1)=v
v=v+1
Vx#(2)=memblock float(1,12+(VertexSize*v)+0)+objpx#
Vy#(2)=memblock float(1,12+(VertexSize*v)+4)+objpy#
Vz#(2)=memblock float(1,12+(VertexSize*v)+8)+objpz#
Vindex(2)=v
v=v+1
Vx#(3)=memblock float(1,12+(VertexSize*v)+0)+objpx#
Vy#(3)=memblock float(1,12+(VertexSize*v)+4)+objpy#
Vz#(3)=memblock float(1,12+(VertexSize*v)+8)+objpz#
Vindex(3)=v
`poly normal
xn#=(Vy#(2)-Vy#(1))*(Vz#(3)-Vz#(1))-(Vz#(2)-Vz#(1))*(Vy#(3)-Vy#(1))
yn#=(Vz#(2)-Vz#(1))*(Vx#(3)-Vx#(1))-(Vx#(2)-Vx#(1))*(Vz#(3)-Vz#(1))
zn#=(Vx#(2)-Vx#(1))*(Vy#(3)-Vy#(1))-(Vy#(2)-Vy#(1))*(Vx#(3)-Vx#(1))
`poly angle
position object O,0,0,0
point object O,xn#,yn#,zn#
`find poly angle group
if object angle y(O)<46 and object angle y(O)>-1 then polyangle=1
if object angle y(O)>314 and object angle y(O)<361 then polyangle=1
if object angle y(O)>44 and object angle y(O)<136 then polyangle=2
if object angle y(O)>134 and object angle y(O)<226 then polyangle=4
if object angle y(O)>224 and object angle y(O)<316 then polyangle=5
if object angle x(O)>224 and object angle x(O)<316 then polyangle=6
if object angle x(O)>44 and object angle x(O)<136 then polyangle=3
`find polys uv to vertex position
select polyangle
case 1
u1#=(Vx#(1)/TSizex#):v1#=(Vy#(1)/TSizey#)
u2#=(Vx#(2)/TSizex#):v2#=(Vy#(2)/TSizey#)
u3#=(Vx#(3)/TSizex#):v3#=(Vy#(3)/TSizey#)
endcase
case 2
u1#=-(Vz#(1)/TSizex#):v1#=(Vy#(1)/TSizey#)
u2#=-(Vz#(2)/TSizex#):v2#=(Vy#(2)/TSizey#)
u3#=-(Vz#(3)/TSizex#):v3#=(Vy#(3)/TSizey#)
endcase
case 3
u1#=-(Vx#(1)/TSizex#):v1#=(Vz#(1)/TSizey#)
u2#=-(Vx#(2)/TSizex#):v2#=(Vz#(2)/TSizey#)
u3#=-(Vx#(3)/TSizex#):v3#=(Vz#(3)/TSizey#)
endcase
case 4
u1#=-(Vx#(1)/TSizex#):v1#=(Vy#(1)/TSizey#)
u2#=-(Vx#(2)/TSizex#):v2#=(Vy#(2)/TSizey#)
u3#=-(Vx#(3)/TSizex#):v3#=(Vy#(3)/TSizey#)
endcase
case 5
u1#=(Vz#(1)/TSizex#):v1#=(Vy#(1)/TSizey#)
u2#=(Vz#(2)/TSizex#):v2#=(Vy#(2)/TSizey#)
u3#=(Vz#(3)/TSizex#):v3#=(Vy#(3)/TSizey#)
endcase
case 6
u1#=(Vx#(1)/TSizex#):v1#=(Vz#(1)/TSizey#)
u2#=(Vx#(2)/TSizex#):v2#=(Vz#(2)/TSizey#)
u3#=(Vx#(3)/TSizex#):v3#=(Vz#(3)/TSizey#)
endcase
endselect
`set memblock uv data to new uv data
write memblock float 2,Pos+(VertexSize*Vindex(1))+0,u1#
write memblock float 2,Pos+(VertexSize*Vindex(1))+4,v1#
write memblock float 2,Pos+(VertexSize*Vindex(2))+0,u2#
write memblock float 2,Pos+(VertexSize*Vindex(2))+4,v2#
write memblock float 2,Pos+(VertexSize*Vindex(3))+0,u3#
write memblock float 2,Pos+(VertexSize*Vindex(3))+4,v3#
` next vertex
next v
` reset arrays
undim Vx#(3)
undim Vy#(3)
undim Vz#(3)
undim Vindex(3)
` remake base object from new memblock data
make mesh from memblock 1,2
change mesh O,0,1
delete mesh 1
position object O,objpx#,objpy#,objpz#
rotate object O,objax#,objay#,objaz#
scale object O,objsx#,objsy#,objsz#
texture object O,texture
` delete memblocks
delete memblock 1
delete memblock 2
endfunction
`-------`
function Get_LightMap_Texture( O )
return#=Object_Lightmap_Texture(O)
endfunction return#
`-------`
function Exclude_Object( O , E )
Exclude_Object_Lightmap(O)=E
endfunction
`-------`