Quote: "When I set the ambient occlusion and other settings to highest it takes longer."
don't use ambient occlusion, it's very slow and needs very big number of rays to get nice results
Quote: "Wonder how long will it take for a 2048 X 2048 terrain ?"
i don't think it will even work for that many polygons, it will probably crash.
also, it is worth to mention, in a few occasions when i lightmapped my terrains (which were very small 64x64) a got very bad results.
Dark lights doesn't handle terrains very well
Quote: "But whenever I click on the save button I get - " File name is not valid!" dialogue. "
please post the whole source of the lightmapper ide (the modified version). I can't find open file dialog anywhere in the code. I think i have the modified version
Here it is, try it yourself:
Rem Project: LightmapperIDE
Rem Created: 13/06/2006 07:45:49
rem Include (not needed in IDE project)
`#include "fpsc-entityelement-loader.dba"
rem Init
set display mode 640,480,32,1
set camera range 1,10000
sync on : sync rate 0 : color backdrop rgb(8,8,32)
set camera fov 90 : autocam off
set normalization on
set text font "Verdana"
set text to bold
set text size 18
rem Program Flags (demo eats tenth polygon from export)
demoversion=0
if demoversion=1
ss$="workspace\media\darklightsdemologo.bmp"
st$="workspace\media\logos\DLlogodemo128.tga"
else
ss$="workspace\media\darklightslogo.bmp"
st$="workspace\media\logos\DLlogo128.tga"
endif
set image colorkey 255,0,255
load image ss$,12321
load image st$,12322
set sprite 1,0,1 : sprite 1,0,0,12321
size sprite 1,screen width(),screen height()
`for a=0 to 255 step 5 : set sprite alpha 1,a : sync : next a
set image colorkey 0,0,0
spritepagefade=255
rem Colours
currentcolour as DWORD
currentcolourR=255 : currentcolourG=255 : currentcolourB=255
rem light data
type lighttype
used as integer
x as float
y as float
z as float
r as float
g as float
b as float
size as float
falloff as float
attenuation as float
endtype
dim light(100) as lighttype
light(0).size=50
light(0).falloff=150
light(0).attenuation=16
rem User light obj start
lightindex=10 : lightindexmax=10
rem Default Dir
root$=get dir$()
rem Light cursor
make object sphere 2,1,50,50 : set object wireframe 2,1 : set object cull 2,0 : set alpha mapping on 2,4 : set object transparency 2,2
make object box 3,100,0.5,0.5 : ghost object on 3
make object box 4,0.5,100,0.5 : ghost object on 4
make object box 5,0.5,0.5,100 : ghost object on 5
make object sphere 6,10,2,8 : set object diffuse 6,0 : set object wireframe 6,1
make object sphere 7,1,50,50 : set object wireframe 7,1 : set object cull 7,0 : set alpha mapping on 7,4 : set object transparency 7,2
rem MyScene folder startup
set dir root$+"\MyScenes"
rem control panel
panelmax=5
dim panel$(panelmax)
panel$(0)="F1-HELP"
panel$(1)="F2-LOAD"
panel$(2)="F3-LIGHTMAP"
panel$(3)="F4-QUICKMAP"
panel$(4)="F5-SAVE"
buttonwidth=screen width()/panelmax
spritemode=0
if spritemode=1
load image root$+"\workspace\media\back.png",1
sprite 1,0,screen height()-60,1
size sprite 1,screen width(),60
load image root$+"\workspace\media\button.png",2
for b=0 to panelmax-1
sprite 2+b,b*buttonwidth,screen height()-60,2
size sprite 2+b,buttonwidth,60
set sprite alpha 2+b,100
next b
endif
rem lighting
set ambient light 50 : make light 1
tip$="TIP : USE THE MOUSE WHEEL TO MOVE UP AND DOWN"
rem Default tool model
model$=root$+"\workspace\defaultscene\levelbank\testlevel\universe.dbo"
file$=left$(model$,len(model$)-len(dbo$))
loadscenemodel(model$,1,1)
gosub _load_lightpos
rem Vars
gosub _dialog_init
sizechanged=1 : colourchanged=1 : attenchange=1
initialtip=1
original=1
zoom#=100
rem Main loop
disable escapekey
do
`
rem Load if present
if file exist(model$)=1
`
rem Edit loop
clear=mousemovex()
clear=mousemovey()
clear=mousemovez()
masterkey=0 : press=1 : helpmode=0 : exitprogram=0
while (masterkey<60 or masterkey>63) and exitprogram=0
`
rem Fade page out (and logo)
paste image 12322,0,0,1
if spritepagefade>0
dec spritepagefade,5
if spritepagefade<=0
spritepagefade=0
hide sprite 1
else
set sprite alpha 1,spritepagefade
endif
endif
`
rem SPACE - reload original
if escapekey()=1 then exitprogram=1
if spacekey()=1 and original=0 then loadscenemodel(model$,1,0) : original=1 : set ambient light 50
`
rem prompts
masterkey=scancode()
if masterkey=0 then presskey=0
if masterkey=59 and presskey=0 then helpmode=1-helpmode : presskey=1
if helpmode=1 then set cursor 0,0 : scry=0 : scrx=250
`
rem smooth mode
smoothspeed#=1.0
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[HOLD SHIFT]" : set cursor scrx,scry : print "smooth mode"
if shiftkey()=1 then smoothspeed#=0.1
`
rem mouselook camera
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[W][S][A][D] + Mouse" : set cursor scrx,scry : print "move and rotate camera"
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[Mouse Wheel]" : set cursor scrx,scry : print "move up and down"
hide mouse
angy# = object angle y(2)
angx# = camera angle x()
xrotate object 2,0
if sweepmode=0
rem cursor movement
if keystate(17)=1 or upkey()=1 then move object 2,4*smoothspeed#
if keystate(31)=1 or downkey()=1 then move object 2,-4*smoothspeed#
mmz=mousemovez()
if mmz>0 then move object down 2,12*smoothspeed#
if mmz<0 then move object up 2,12*smoothspeed#
if keystate(209)=1 then move object down 2,4*smoothspeed#
if keystate(201)=1 then move object up 2,4*smoothspeed#
xrotate camera 0
if keystate(30)=1 or leftkey()=1 then yrotate object 2,angy#-90 : move object 2,4*smoothspeed# : yrotate object 2,angy#
if keystate(32)=1 or rightkey()=1 then yrotate object 2,angy#+90 : move object 2,4*smoothspeed# : yrotate object 2,angy#
else
rem sweep movement
position object 2,curvevalue(sweeptox#,object position x(2),3.0),curvevalue(sweeptoy#,object position y(2),3.0),curvevalue(sweeptoz#,object position z(2),3.0)
dec sweepmode
endif
yrotate object 2,angy#+mousemovex()/2.0
position camera object position x(2),object position y(2),object position z(2)
yrotate camera object angle y(2)
xrotate camera angx#+mousemovey()/2.0
move camera zoom#*-1
`
rem zoom camera
inczoom#=0.0
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[<][>]" : set cursor scrx,scry : print "zoom camera"
if keystate(51)=1 and zoom#>10 then inczoom#=-2.0
if keystate(52)=1 and zoom#<1000 then inczoom#=2.0
if inczoom#<>0.0
inc zoom#,inczoom#*smoothspeed#
endif
`
rem place light cursor
position object 3,object position x(2),object position y(2),object position z(2)
position object 4,object position x(2),object position y(2),object position z(2)
position object 5,object position x(2),object position y(2),object position z(2)
position object 6,object position x(2),object position y(2),object position z(2)
position object 7,object position x(2),object position y(2),object position z(2)
set point light 0,object position x(2),object position y(2),object position z(2)
color light 0,currentcolourR*2,currentcolourG*2,currentcolourB*2
set point light 1,object position x(2),object position y(2),object position z(2)
color light 1,32,32,32 : set light range 1,5000
`
rem light cursor controls
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[{][}]" : set cursor scrx,scry : print "change light range"
if keystate(26)=1 and light(0).size>20 then light(0).size=light(0).size-(1+(3.0*smoothspeed#)) : sizechanged=1
if keystate(27)=1 and light(0).size<100000 then light(0).size=light(0).size+(1+(3.0*smoothspeed#)) : sizechanged=1
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[-][+]" : set cursor scrx,scry : print "change light falloff"
if keystate(12)=1 and light(0).falloff>0 then light(0).falloff=light(0).falloff-(1+(3.0*smoothspeed#)) : sizechanged=1
if keystate(13)=1 and light(0).falloff<100000 then light(0).falloff=light(0).falloff+(1+(3.0*smoothspeed#)) : sizechanged=1
if sizechanged=1
rem change cursor
ssc#=light(0).size*100 : scale object 2,ssc#,ssc#,ssc#
fsc#=(light(0).size+light(0).falloff)*100 : scale object 7,fsc#,fsc#,fsc#
scale object 3,light(0).size,100,100
scale object 4,100,light(0).size,100
scale object 5,100,100,light(0).size
set light range 0,light(0).size
sizechanged=0
attenchange=1
endif
`
rem light cursore color
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[TAB]" : set cursor scrx,scry : print "pick from colour wheel"
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[1][2][3][4][5][6][7]" : set cursor scrx,scry : print "preset light colours"
if keystate(15)=1 and presskey=0 then gosub _color_wheel
if inkey$()="1" then currentcolourR=255 : currentcolourG=255 : currentcolourB=255 : colourchanged=1
if inkey$()="2" then currentcolourR=255 : currentcolourG=0 : currentcolourB=0 : colourchanged=1
if inkey$()="3" then currentcolourG=255 : currentcolourR=0 : currentcolourB=0 : colourchanged=1
if inkey$()="4" then currentcolourB=255 : currentcolourG=0 : currentcolourR=0 : colourchanged=1
if inkey$()="5" then currentcolourR=255 : currentcolourG=255 : currentcolourB=0 : colourchanged=1
if inkey$()="6" then currentcolourR=255 : currentcolourG=0 : currentcolourB=255 : colourchanged=1
if inkey$()="7" then currentcolourR=0 : currentcolourG=255 : currentcolourB=255 : colourchanged=1
if colourchanged=1
currentcolour=rgb(currentcolourR,currentcolourG,currentcolourB)
for o=2 to 6 : set object emissive o,currentcolour : next o
colourchanged=0
endif
`
rem light attenuation control
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[SPACE]" : set cursor scrx,scry : print "decrease attenuation"
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[CONTROL]" : set cursor scrx,scry : print "increase attenuation"
if spacekey()=1 and light(0).attenuation>1 then light(0).attenuation=light(0).attenuation-1 : attenchange=1
if controlkey()=1 and light(0).attenuation<512 then light(0).attenuation=light(0).attenuation+1 : attenchange=1
if attenchange=1
B#=light(0).size+light(0).falloff
A#=light(0).attenuation/(B#*B#)
plotattenuationgraph(A#,B#,9)
attenchange=0
endif
if image exist(9)=1
ypos=150+10
center text screen width()-90,ypos-150,"ATTENUATION"
center text screen width()-90,ypos-125,str$(light(0).attenuation)+"\("+str$(int(light(0).size+light(0).falloff))+"^2)"
paste image 9,screen width()-170,ypos-130,1
endif
`
rem detect light highlight
if dragging=0
highlight=pick object(screen width()/2,screen height()/2,11,lightindexmax)
if highlight>0 then scrollhighlight=highlight
for o=11 to lightindexmax
if object exist(o)=1
scale object o,75,75,75 : set alpha mapping on o,30
if highlight=o then scale object o,100,100,100 : set alpha mapping on o,99
endif
next o
endif
`
rem highlight next/prev light
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[P]" : set cursor scrx,scry : print "go to previous light"
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[N]" : set cursor scrx,scry : print "go to next light"
scrollmode=0
if inkey$()="p" and presskey=0 then scrollmode=1
if inkey$()="n" and presskey=0 then scrollmode=2
if scrollmode>0 and lightindexmax>=11
if scrollhighlight=0 then scrollhighlight=11
lasto=scrollhighlight
if scrollmode=1 then o=scrollhighlight-1
if scrollmode=2 then o=scrollhighlight+1
if o<11 then o=lightindexmax
if o>lightindexmax then o=11
while o<>lasto and object exist(o)=0
if scrollmode=1 then dec o
if scrollmode=2 then inc o
if o<11 then o=lightindexmax
if o>lightindexmax then o=11
endwhile
if object exist(o)=1
sweepmode=20
sweeptox#=object position x(o)
sweeptoy#=object position y(o)
sweeptoz#=object position z(o)
scrollhighlight=o : presskey=1
endif
endif
`
rem LMB+DRAG - drag current light
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[Left Button Drag]" : set cursor scrx,scry : print "move light in scene"
if mouseclick()=0 then press=0
if mouseclick()=1 and press=0 and highlight>0 and dragging=0
dragging=highlight : press=1
dragx#=object position x(dragging)-object position x(2)
dragy#=object position y(dragging)-object position y(2)
dragz#=object position z(dragging)-object position z(2)
endif
if dragging>0 and press=0 then dragging=0
if dragging>0
position object dragging,object position x(2)+dragx#,object position y(2)+dragy#,object position z(2)+dragz#
endif
`
rem LMB - add a light
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[Left Button Click]" : set cursor scrx,scry : print "add light to scene"
if mouseclick()=0 then press=0
if mouseclick()=1 and press=0 and highlight=0
for o=11 to lightindexmax
if object exist(o)=0 then exit
next o
if o<=lightindex
lightindex=o
else
lightindex=lightindexmax
inc lightindex
endif
clone object lightindex,6
if lightindexmax<lightindex then lightindexmax=lightindex
set object emissive lightindex,rgb(currentcolourR,currentcolourG,currentcolourB)
set object wireframe lightindex,0 : ghost object off lightindex
light(lightindex).r=currentcolourR
light(lightindex).g=currentcolourG
light(lightindex).b=currentcolourB
light(lightindex).size=light(0).size
light(lightindex).falloff=light(0).falloff
light(lightindex).attenuation=light(0).attenuation
position object lightindex,object position x(2),object position y(2),object position z(2)
press=1
endif
`
rem RMB - remove a light
if helpmode=1 then inc scry,20 : set cursor 10,scry : print "[Right Button Click]" : set cursor scrx,scry : print "remove light from scene"
if mouseclick()=0 then press=0
if mouseclick()=2 and press=0
if highlight>0
if object exist(highlight)=1
delete object highlight
endif
endif
press=1
endif
`
rem buttons
for b=0 to panelmax-1
s$=panel$(b) : center text (b*buttonwidth)+(buttonwidth/2),screen height()-38,s$
next b
`
rem Restore reminder
if original=0 then center text screen width()/2,screen height()-100,"PRESS SPACE TO END LIGHTMAP PREVIEW"
if initialtip=1 then center text screen width()/2,screen height()-100,tip$
if masterkey<>0 then initialtip=0
`
rem Update
sync
`
endwhile
`
rem Exit now
if exitprogram=1
rem ask if sure?
sck=0
while sck<>21 and sck<>49
sck=scancode()
center text screen width()/2,screen height()/2,"ARE YOU SURE YOU WANT TO QUIT? (y/n)"
set cursor 0,0
print sck
sync
endwhile
if sck=21
rem go quit
show sprite 1
`for a=0 to 255 step 5
` set sprite alpha 1,a
` sync
`next a
position camera 0,1000000,0
point camera 0,1000001,0
color backdrop 0
sleep 1000
for a=255 to 0 step -5
set sprite alpha 1,a
sync
next a
end
endif
endif
`
rem Which option
show mouse
select masterkey
case 60 : rem load
rem Load new model
newmodel$=lower$(getFileName("load","Load in X, 3DS or DBO model",".x;.3ds;.dbo","*.x;*.3ds;*.dbo"))
if lower$(right$(newmodel$,2))=".x" or lower$(right$(newmodel$,4))=".dbo"
if file exist(newmodel$)=1
model$=newmodel$
if right$(model$,1)="x" then dbo$=".x" else dbo$=".dbo"
file$=left$(model$,len(model$)-len(dbo$))
loadscenemodel(model$,1,1)
gosub _load_lightpos
original=1
set dir root$
endif
else
tip$="LOAD WARNING : YOU MUST SPECIFY A .X OR .DBO MODEL FILE TO IMPORT!" : initialtip=1
endif
endcase
case 61 : rem lightmap
rem intercept with settings dialog
gosub _lightmap_settings
if leave=1
rem Build lightmap
olddir$=get dir$()
set dir root$+"\workspace"
gosub _lightmap_scene
set dir olddir$
original=0
endif
endcase
case 62 : rem quick lightmap - no dialog
rem Build lightmap
olddir$=get dir$()
set dir root$+"\workspace"
gosub _lightmap_scene
set dir olddir$
original=0
endcase
case 63 : rem save
rem Ask for SAVE AS filename
savemodel$=lower$(getFileName("save","Save as DBO",".dbo","*.dbo"))
if savemodel$<>""
rem file entered
if lower$(right$(savemodel$,4))=".dbo"
rem Delete any old saved model
if file exist(savemodel$)=1 then delete file savemodel$
rem intercept with settings dialog
gosub _lightmap_settings
if leave=1
rem Build lightmap for saved model
lightmapsaving=1
gosub _lightmap_scene
lightmapsaving=0
rem If demo, hack begin
if demoversion=1 then gosub _hack_object_one
rem Save DBO
save object savemodel$,1
rem Save DAT
gosub _save_lightpos
rem Complete
original=0
endif
else
tip$="SAVE WARNING : YOU MUST SPECIFY A .DBO MODEL FILE TO EXPORT!" : initialtip=1
endif
endif
endcase
endselect
`
else
`
rem Quit - no model
end
`
endif
`
rem End loop
loop
_hack_object_one:
`
rem Demo version eats tenth polygon from all meshes, as a restriction to trial users
perform checklist for object limbs 1
limbmax=checklist quantity()
for l=0 to limbmax-1
lock vertexdata for limb 1,l,2
diff=(10+rnd(5))*3 : v=0
vertmax=get vertexdata vertex count()
vx#=get vertexdata position x(v+1)
vy#=get vertexdata position y(v+1)
vz#=get vertexdata position z(v+1)
set vertexdata position v,vx#,vy#,vz#
for v=diff to vertmax-diff step diff
vx#=get vertexdata position x(v+1)
vy#=get vertexdata position y(v+1)
vz#=get vertexdata position z(v+1)
set vertexdata position v,vx#,vy#,vz#
next v
unlock vertexdata
next l
`
return
_color_wheel:
`
rem ensure mouse and keys silent
while mouseclick()<>0 : sync : endwhile
while keystate(15)=1 : sync : endwhile
`
rem show wheel and allow user to pick pixel
show mouse
col as DWORD
addx=(screen width()-512)/2
addy=(screen height()-512)/2
insideloop=0
if image exist(3)=0 then load image root$+"\workspace\media\circle.tga",3
create bitmap 1,512,512
paste image 3,0,0
set current bitmap 0
clear entry buffer : ent$=""
while insideloop=0
rem pick
mx=mousex() : my=mousey()
if mx>addx+512-64 and my<addy+32
rem using manual colour entry
else
col=0
if mx>addx and mx<addx+512
if my>addy and my<addy+512
set current bitmap 1
col=point(mousex()-addx,mousey()-addy)
set current bitmap 0
endif
endif
endif
rem prompt
if keystate(15)=1 then insideloop=1
if mouseclick()<>0 then insideloop=2
ink 0,0 : box addx,addy,addx+64,addy+32
ink rgb(currentcolourR,currentcolourG,currentcolourB),0 : box addx+2,addy+2,addx+62,addy+30
ink 0,0 : box addx+512-64,addy,addx+512,addy+32
ink col,0 : box addx+512-62,addy+2,addx+512-2,addy+30
rem text
ink rgb(255,255,255),0
center text addx+32,addy-20,"CURRENT"
center text addx+32,addy+35,str$(currentcolourR)+","+str$(currentcolourG)+","+str$(currentcolourB)
center text addx+512-32,addy-20,"NEW"
center text addx+512-32,addy+35,str$(rgbr(col))+","+str$(rgbg(col))+","+str$(rgbb(col))
center text screen width()/2,40,"CLICK ANYWHERE INSIDE THE CIRCLE TO PICK A COLOUR"
center text screen width()/2,60,"PRESS TAB TO CANCEL SELECTION"
keys$=entry$() : clear entry buffer
for k=1 to len(keys$)
key$=mid$(keys$,k)
if ((key$>="0" and key$<="9") or key$=",") and len(ent$)<11
ent$=ent$+key$
endif
if asc(key$)=8 and len(ent$)>0
ent$=left$(ent$,len(ent$)-1)
endif
next k
center text screen width()/2,addy+512+20,"MANUAL R-G-B COLOUR ENTRY : "+upper$(ent$)
paste image 3,addx,addy,1
rem manual
if returnkey()=1 and len(ent$)>0
digi=0
dim dig$(3)
dig$(0)="0"
dig$(1)="0"
dig$(2)="0"
tent$=ent$
for n=1 to len(tent$)
if mid$(tent$,n)="," and digi<2
dig$(digi)=left$(tent$,n-1)
tent$=right$(tent$,len(tent$)-(len(dig$(digi))+1))
inc digi : n=0
endif
next n
dig$(digi)=tent$
col=rgb(val(dig$(0)),val(dig$(1)),val(dig$(2)))
position mouse addx+512-32,addy+16
ent$=""
endif
rem update
sync
endwhile
delete bitmap 1
hide mouse
clear=mousemovex()
clear=mousemovey()
clear=mousemovez()
press=1 : presskey=1
`
rem wheel colour
if insideloop=2
currentcolourR=rgbr(col)
currentcolourG=rgbg(col)
currentcolourB=rgbb(col)
colourchanged=1
endif
`
return
_lightmap_settings:
`
if spritemode=1 then for b=-1 to panelmax-1 : hide sprite 2+b : next b
gosub _dialog
`
return
_dialog_init:
`
rem start data
dim fielddata(10)
fielddata(0)=0
fielddata(1)=0
fielddata(2)=5
fielddata(3)=5
fielddata(4)=1
fielddata(5)=10
fielddata(6)=1
fielddata(7)=0
`
rem panel gfx
load image root$+"\workspace\media\panel.tga",997
load image root$+"\workspace\media\text1.tga",998
load image root$+"\workspace\media\text2.tga",999
`
return
_dialog:
`
rem setup
fieldmax=8
dim field$(fieldmax)
dim fieldmax(fieldmax)
field$(0)="AMBIENT OCCLUSION" : fieldmax(0)=4
field$(1)="SUN LIGHT" : fieldmax(1)=6
field$(2)="TEXTURE SIZE" : fieldmax(2)=7
field$(3)="QUALITY LEVEL" : fieldmax(3)=20
field$(4)="BLUR LEVEL" : fieldmax(4)=3
field$(5)="SHADOW POWER" : fieldmax(5)=20
field$(6)="BLEND MODE" : fieldmax(6)=1
field$(7)="OFF-POLY PIXELS" : fieldmax(7)=3
`
rem vars
selected=0
`
rem the text
set text size 14
`
rem loop
leave=0
while leave=0
`
rem exit keys
if returnkey()=1 then leave=1
if escapekey()=1 then leave=2
`
rem control
if upkey()=0 and downkey()=0 and leftkey()=0 and rightkey()=0 then presskey=0
if upkey()=1 and selected>0 and presskey=0 then dec selected : presskey=1
if downkey()=1 and selected<fieldmax-1 and presskey=0 then inc selected : presskey=1
if leftkey()=1 and fielddata(selected)>0 and presskey=0 then fielddata(selected)=fielddata(selected)-1 : presskey=1
if rightkey()=1 and fielddata(selected)<fieldmax(selected) and presskey=0 then fielddata(selected)=fielddata(selected)+1 : presskey=1
`
rem display
paste image 997,(screen width()-564)/2,(screen height()-500)/2
paste image 998,(screen width()-442)/2,(screen height()/2)-175
paste image 999,(screen width()-442)/2,(screen height()/2)+105
for i=0 to fieldmax-1
fd$=str$(fielddata(i))
select i
case 0 : rem ambient occlusion
helpdesc1$="an ambient occlusion technique applied"
helpdesc2$="by casting hundreds of rays, either from"
helpdesc3$="close range or from the distant skysphere"
if fielddata(i)=0 then fd$="off"
if fielddata(i)=1 then fd$="fast and near"
if fielddata(i)=2 then fd$="fast and far"
if fielddata(i)=3 then fd$="best and near"
if fielddata(i)=4 then fd$="best and far"
endcase
case 1 : rem sun
helpdesc1$="a simple and fast directional light"
helpdesc2$="creates a sinle ray direction of light"
helpdesc3$="used to cast strong light and shadows"
if fielddata(i)=0 then fd$="none"
if fielddata(i)=1 then fd$="dawn"
if fielddata(i)=2 then fd$="morning"
if fielddata(i)=3 then fd$="afternoon"
if fielddata(i)=4 then fd$="evening"
if fielddata(i)=5 then fd$="dusk"
if fielddata(i)=6 then fd$="night"
endcase
case 2 : rem texture
helpdesc1$="the destination texture size of the"
helpdesc2$="lightmaps to be created from the scene"
helpdesc3$="(older 3D cards support only 256x256)"
if fielddata(i)=0 then fd$="32x32"
if fielddata(i)=1 then fd$="64x64"
if fielddata(i)=2 then fd$="128x128"
if fielddata(i)=3 then fd$="256x256"
if fielddata(i)=4 then fd$="512x512"
if fielddata(i)=5 then fd$="1024x1024"
if fielddata(i)=6 then fd$="2048x2048"
if fielddata(i)=7 then fd$="4096x4096"
endcase
case 3,5 : rem quality / shadow
if i=3
helpdesc1$="describes the resolution of the lightmap"
helpdesc2$="a low value is quicker but less accurate"
helpdesc3$="a high value is slower but sharper"
else
helpdesc1$="describes the depth of shadows produced"
helpdesc2$="a low value will increase shadow strength"
helpdesc3$="a high value will decrease shadow strength"
endif
fd$=str$(fielddata(i)/10.0,1)
endcase
case 4 : rem blur
helpdesc1$="degree of post-lightmap blurring"
helpdesc2$="a value of zero performs no blurring"
helpdesc3$="a higher value will increase blurring"
endcase
case 6 : rem blend
helpdesc1$="fixed function modulation mode"
helpdesc2$="MODULATEX1 produces normal blending"
helpdesc3$="MODULATEX2 multiplies LM blending by 2"
if fielddata(i)=0 then fd$="X1"
if fielddata(i)=1 then fd$="X2"
endcase
case 7 : rem off-poly pixels
helpdesc1$="mode to deal with pixels outside a polygon"
helpdesc2$="the best mode is a combo of all and nearest"
helpdesc3$="or the polygon normal can be used instead"
if fielddata(i)=0 then fd$="best"
if fielddata(i)=1 then fd$="all"
if fielddata(i)=2 then fd$="nearest"
if fielddata(i)=3 then fd$="normal only"
endcase
endselect
if i=selected then helpdescused1$=helpdesc1$ : helpdescused2$=helpdesc2$ : helpdescused3$=helpdesc3$
if i=selected then ink rgb(255,255,0),0 else ink rgb(48,32,32),0
text (screen width()/2)+20-text width(field$(i)),((screen height()/2)-150)+(i*30),field$(i)
text (screen width()/2)+30,((screen height()/2)-150)+(i*30),fd$
next i
ink rgb(255,255,0),0
center text screen width()/2,(screen height()/2)+120,helpdescused1$
center text screen width()/2,(screen height()/2)+140,helpdescused2$
center text screen width()/2,(screen height()/2)+160,helpdescused3$
sync
endwhile
while escapekey()<>0 : endwhile
ink rgb(255,255,255),0
`
return
_lightmap_scene:
rem object to lightmap must be loaded directly, SYNC must not refresh object
if object exist(1)=1 then delete object 1
load object model$,1
rem name of model
st=-1 : en=0
for n=len(model$) to 1 step -1
if mid$(model$,n)="/" or mid$(model$,n)="\" and st=-1 then st=n
if mid$(model$,n)="." and en=0 then en=n-1
next n
if en=0 then en=1
name$=right$(model$,len(model$)-st)
name$=left$(name$,en-st)
rem lightmap process begin
LM Start
rem lightmapping folder
if path exist("lightmaps")=0 then make directory "lightmaps"
rem clear lightmap folder
if path exist("lightmaps")=1
set dir "lightmaps"
perform checklist for files
for c=1 to checklist quantity()
c$=checklist string$(c)
if c$<>"." and c$<>".."
if right$(lower$(c$),4)=".png"
delete file c$
endif
endif
next c
set dir ".."
endif
rem add transparent objects
eleobjbase=1001 : eleobj=eleobjbase
for e=1 to entityelementlist
if entityelement(e).bankindex>0
if entityelement(e).staticflag=0
if object exist(eleobj)=1
LM Add Transparent Collision Object eleobj,1
endif
inc eleobj
endif
endif
next e
rem place point lights
for i = 11 to lightindexmax
if object exist(i)=1
posX# = object position x(i)
posY# = object position y(i)
posZ# = object position z(i)
colR# = light(i).r/255.0
colG# = light(i).g/255.0
colB# = light(i).b/255.0
radius# = light(i).size+light(i).falloff
zerorange# = radius#
atten# = light(lightindex).attenuation/(radius#*radius#)
outer#=1.0+(light(i).falloff)
brighter#=radius#/outer#
colR#=colR#*brighter#
colG#=colG#*brighter#
colB#=colB#*brighter#
LM Add Custom Point Light posX#,posY#,posZ#,radius#,zerorange#,atten#,colR#,colG#,colB#
endif
next i
rem gather settings
i=0
if fielddata(i)>0
rem ambient occlusion (rays, distance and pattern mode)
distance#=object size(1)/10.0
if fielddata(i)=1 then LM Set Ambient Occlusion On 20,distance#,0
if fielddata(i)=3 then LM Set Ambient Occlusion On 20,distance#,0
distance#=object size(1)*10.0
if fielddata(i)=2 then LM Set Ambient Occlusion On 100,distance#,1
if fielddata(i)=4 then LM Set Ambient Occlusion On 100,distance#,1
LM Set Ambient Light 0.4,0.4,0.4
set ambient light 0
endif
i=1
if fielddata(i)=1 then sx#=0.9 : sy#=-0.1 : cc#=0.2
if fielddata(i)=2 then sx#=0.7 : sy#=-0.3 : cc#=0.5
if fielddata(i)=3 then sx#=0.0 : sy#=-1 : cc#=1.0
if fielddata(i)=4 then sx#=-0.5 : sy#=-0.5 : cc#=0.5
if fielddata(i)=5 then sx#=-0.8 : sy#=-0.2 : cc#=0.2
if fielddata(i)=6 then sx#=0.0 : sy#=-1.0 : cc#=0.1
if fielddata(i)>0
rem directinal light for entire scene, dirx,diry,dirz,red,green,blue
LM Add Directional Light sx#,sy#,0.0,cc#,cc#,cc#
endif
i=2
if fielddata(i)=0 then texsize=32
if fielddata(i)=1 then texsize=64
if fielddata(i)=2 then texsize=128
if fielddata(i)=3 then texsize=256
if fielddata(i)=4 then texsize=512
if fielddata(i)=5 then texsize=1024
if fielddata(i)=6 then texsize=2048
if fielddata(i)=7 then texsize=4096
rem quality, blur, shadow
i=3 : quality#=fielddata(i)/10.0
i=4 : blurmode=fielddata(i)
i=5 : shadowstr#=fielddata(i)/10.0
i=6
if fielddata(i)=0 then blendmode=4
if fielddata(i)=1 then blendmode=5
i=7 : invalidpixelmode=fielddata(i)
rem shadow
`LM Set Shadow Power shadowstr#
rem blend mode visual
LM Set Blend Mode blendmode
rem invalid pixel mode
LM Set Mode invalidpixelmode
rem add level as a collision object to cast shadows
LM Add Collision Object 1
LM Build collision Data
rem add level as a light map object to receive lightmaps
LM Set Light Map Name name$
LM Add Light Map Object 1,1
rem start the light mapping thread: <tex size>, <quality>
rem Boost Curved Surface Quality <maxSize>,<Boost> (<maxSize>=-1=all curved surfaces)
LM Boost Curved Surface Quality -1,4.0
LM Build Light Maps Thread texsize,quality#,blurmode
rem prompt
prompt$=""
if fielddata(0)>0 then prompt$=prompt$+"(INTENSE OCCLUSION PROCESSING) "
prompt$=prompt$+"ESC=Quit"
rem get current status and display whilst running
load dll "Kernel32.dll",1
while LM Get Complete()=0
if demoversion=1 and lightmapsaving=1 then center text screen width()/2,20,"DEMO VERSION - SOME POLYGONS ARE BEING REMOVED FROM THE SAVED MODEL"
if escapekey()=1 then LM Terminate Thread
call dll 1,"Sleep",100
fillwidth#=(LM Get Percent()/100.0)*(screen width()+0.0)
ink rgb(0,0,0),0 : box 0,screen height()-20,screen width(),screen height()-0
ink rgb(0,0,128),0 : box 0,screen height()-20,fillwidth#,screen height()-0
ink rgb(255,255,255),0 : center text screen width()/2,screen height()-18,LM Get Status()+" "+prompt$
sync
endwhile
delete dll 1
rem light mapping complete remove all collision and light map objects and lights.
LM Reset
rem restore preview loop
if spritemode=1 then for b=-1 to panelmax-1 : show sprite 2+b : next b
return
rem Subroutine to load and save
_remove_model_ext:
en=0
for n=len(tfile$) to 1 step -1
if mid$(tfile$,n)="." and en=0 then en=n-1
next n
modelnoext$=left$(tfile$,en)
return
_save_lightpos:
`
rem get no ext version of model name
tfile$=savemodel$ : gosub _remove_model_ext
`
rem save light data
dim page$(lightindexmax+1)
for pageindex=0 to lightindexmax : page$(pageindex)="" : next pageindex
pageindex=0
for i = 11 to lightindexmax
if object exist(i)=1
posX# = object position x(i)
posY# = object position y(i)
posZ# = object position z(i)
colR# = light(i).r
colG# = light(i).g
colB# = light(i).b
size#=light(i).size
o#=light(i).falloff
a#=light(i).attenuation
line$="x="+str$(posX#,2)+" y="+str$(posY#,2)+" z="+str$(posZ#,2)+" r="+str$(colR#,2)+" g="+str$(colG#,2)+" b="+str$(colB#,2)+" i="+str$(size#,2)+" o="+str$(o#,2)+" a="+str$(a#,2)
page$(pageindex)=line$
inc pageindex
endif
next i
LMDfile$=modelnoext$+".dat"
if file exist(LMDfile$)=1 then delete file LMDfile$
save array LMDfile$,page$()
`
return
_load_lightpos:
`
rem get no ext version of model name
tfile$=model$ : gosub _remove_model_ext
`
rem remove old lights
for i = 11 to 999
if object exist(i)=1
delete object i
endif
next i
`
rem load light data
LMDfile$=modelnoext$+".dat"
if file exist(LMDfile$)=1
`
pageindex=0
dim page$(999)
for i=0 to 999 : page$(i)="" : next i
load array LMDfile$,page$()
i=11
while pageindex<999
`
rem extract data from line
line$=page$(pageindex) : inc pageindex
if len(line$)>2
`
rem get data from line
ltr$="x" : gosub _eat_line_spit_value : posX#=value#
ltr$="y" : gosub _eat_line_spit_value : posY#=value#
ltr$="z" : gosub _eat_line_spit_value : posZ#=value#
ltr$="r" : gosub _eat_line_spit_value : colR#=value#
ltr$="g" : gosub _eat_line_spit_value : colG#=value#
ltr$="b" : gosub _eat_line_spit_value : colB#=value#
ltr$="i" : gosub _eat_line_spit_value : size#=value#
ltr$="o" : gosub _eat_line_spit_value : o#=value#
ltr$="a" : gosub _eat_line_spit_value : a#=value#
`
rem set current light to lightpos data
lightindex=i : inc i
currentcolourR=colR#
currentcolourG=colG#
currentcolourB=colB#
light(0).size=size#
light(0).falloff=o#
light(0).attenuation=a#
position object 2,posX#,posY#,posZ#
`
rem create light and entry
clone object lightindex,6
if lightindexmax<lightindex then lightindexmax=lightindex
set object emissive lightindex,rgb(currentcolourR,currentcolourG,currentcolourB)
set object wireframe lightindex,0 : ghost object off lightindex
light(lightindex).r=currentcolourR
light(lightindex).g=currentcolourG
light(lightindex).b=currentcolourB
light(lightindex).size=light(0).size
light(lightindex).falloff=light(0).falloff
light(lightindex).attenuation=light(0).attenuation
position object lightindex,object position x(2),object position y(2),object position z(2)
`
else
pageindex=1000
endif
`
endwhile
`
endif
`
rem update gui
attenchange=1
colourchanged=1
sizechanged=1
`
return
_eat_line_spit_value:
`
nopos=0
value#=0.0
if len(line$)>2
for n=1 to len(line$)
if lower$(mid$(line$,n))=ltr$
inc n,2
for o=n to len(line$)
if lower$(mid$(line$,o))=" " or o=len(line$)
value$=right$(line$,len(line$)-2)
value$=left$(value$,o-n)
value#=val(value$)
line$=right$(line$,len(line$)-o)
nopos=1
exit
endif
next o
exit
endif
next n
endif
`
return
rem Function to load regular or FPSC universe-style model
function loadscenemodel(previewmodel$,objid,restorecamera)
`
rem remove old model
if object exist(1)=1 then delete object 1
`
rem remove any old entities
gosub _entity_clear
`
rem check if an FPSC universe
fpscuniverse$="levelbank\testlevel\universe.dbo"
if lower$(right$(previewmodel$,len(fpscuniverse$)))=fpscuniverse$
rem nested in an FPSC folder
olddir$=get dir$()
backedupdir$=left$(previewmodel$,len(previewmodel$)-len(fpscuniverse$))
set dir backedupdir$
load object fpscuniverse$,objid
rem load FPSC assets (if any)
gosub _entity_arrays
gosub _entity_loadelementsdata
gosub _entity_makeelements
rem restore Myscenes folder
set dir olddir$
else
rem regular model
load object previewmodel$,objid
endif
`
rem camera start position
if restorecamera=1
cx#=object collision center x(1)
cy#=object collision center y(1)
cz#=object collision center z(1)
position object 2,cx#,cy#,cz#+(object size z(1)*-0.5)
endif
`
endfunction
rem Graph the attenuation to an image
function plotattenuationgraph(A#,B#,ID)
`
rem sets the quality of the line
numSegments = 320 : numSegments = 320/numSegments
`
rem sets the extent of the line
height = 100 : width = 320 : radius# = width
`
rem first point
x = 0 : y = -height + 100
`
rem graph function
create bitmap 2,320,120
ink rgb(255,255,255),0 : cls
for i = 1 to radius#/numSegments
x2 = (i*numSegments)
if x2 > radius#
y2 = 110
else
y2 = (1.0 / ( 1.0 + A#*(x2*x2) )) * (1.0 - x2/B#)*(-height) + 110
endif
line x/2,y,x2/2,y2
line x/2,y+1,x2/2,y2+1
x = x2 : y = y2
next i
line 0,0,159,0
line 0,119,159,119
line 0,0,0,119
line 159,0,159,119
get image ID,0,0,160,120,1
delete bitmap 2
`
endfunction
function getFileName(mode$,FileBoxTitle$,ShownFileFilter$,RealFileFilter$)
FileBoxTitle$ = FileBoxTitle$+"^"
FileFilter$ = ShownFileFilter$+"^"+RealFileFilter$+"^^"
rem Load the DLLs
user32=findFreeDllSlot()
load dll "user32.dll",user32
kernel32=findFreeDllSlot()
load dll "kernel32.dll",kernel32
comdlg32=findFreeDllSlot()
load dll "comdlg32.dll",comdlg32
rem Offset Table OPENFILENAME Struct
lStructSize = 0
hwndOwner = 4
hInstance = 8
lpstrFilter = 12
lpstrCustomFilter = 16
nMaxCustFilter = 20
nFilterIndex = 24
lpstrFile = 28
nMaxFile = 32
lpstrFileTitle = 36
nMaxFileTitle = 40
lpstrInitialDir = 44
lpstrTitle = 48
Flags = 52
nFileOffset = 56
nFileExtension = 58
lpstrDefExt = 60
lCustData = 64
lpfnHook = 68
lpTemplateName = 72
StructEnd = 76
rem OPENFILENAME Flag Table
OFN_ALLOWMULTISELECT = 512:rem 0x00000200
OFN_CREATEPROMPT = 8192:rem 0x00002000
OFN_ENABLEHOOK = 32:rem 0x00000020
OFN_ENABLETEMPLATE = 64:rem 0x00000040
OFN_ENABLETEMPLATEHANDLE = 128:rem 0x00000080
OFN_EXPLORER = 524288:rem 0x00080000
OFN_EXTENSIONDIFFERENT = 1024:rem 0x00000400
OFN_FILEMUSTEXIST = 4096:rem 0x00001000
OFN_HIDEREADONLY = 4:rem 0x00000004
OFN_LONGNAMES = 2097152:rem 0x00200000
OFN_NOCHANGEDIR = 8:rem 0x00000008
OFN_NODEREFERENCELINKS = 1048576:rem 0x00100000
OFN_NOLONGNAMES = 262144:rem 0x00040000
OFN_NONETWORKBUTTON = 131072:rem 0x00020000
OFN_NOREADONLYRETURN = 32768:rem 0x00008000
OFN_NOTESTFILECREATE = 65536:rem 0x00010000
OFN_NOVALIDATE = 256:rem 0x00000100
OFN_OVERWRITEPROMPT = 2:rem 0x00000002
OFN_PATHMUSTEXIST = 2048:rem 0x00000800
OFN_READONLY = 1:rem 0x00000001
OFN_SHAREAWARE = 16384:rem 0x00004000
OFN_SHOWHELP = 16:rem 0x00000010
rem FileBox Info
FileBoxFlags = OFN_EXPLORER + OFN_FILEMUSTEXIST + OFN_PATHMUSTEXIST + OFN_LONGNAMES + OFN_HIDEREADONLY + OFN_NONETWORKBUTTON
PathBufferSize = 256
hWnd = call dll(user32,"GetActiveWindow")
hMod = call dll(kernel32,"GetModuleHandleA",0)
rem Create necessary memblocks
OFN_MB = findFreeMemblockSlot()
make memblock OFN_MB,StructEnd
PathBuffer_MB = findFreeMemblockSlot()
make memblock PathBuffer_MB,PathBufferSize
FileFilter_MB = findFreeMemblockSlot()
make memblock FileFilter_MB,len(FileFilter$)
FileBoxTitle_MB = findFreeMemblockSlot()
make memblock FileBoxTitle_MB,len(FileBoxTitle$)
rem Get the memblocks pointers
OFN = get memblock ptr(OFN_MB)
PathBuffer = get memblock ptr(PathBuffer_MB)
FileFilter = get memblock ptr(FileFilter_MB)
FileBoxTitle = get memblock ptr(FileBoxTitle_MB)
rem write Strings to Memblock
writeStringToMemblock(FileFilter_MB,FileFilter$)
writeStringToMemblock(FileBoxTitle_MB,FileBoxTitle$)
rem Write to OPENFILENAME Struct
write memblock dword OFN_MB,lStructSize,StructEnd
write memblock dword OFN_MB,hWndOwner,hWnd
write memblock dword OFN_MB,hInstance,hMod
write memblock dword OFN_MB,lpstrFilter,FileFilter
write memblock dword OFN_MB,lpstrFile,PathBuffer
write memblock dword OFN_MB,nMaxFile,PathBufferSize
write memblock dword OFN_MB,Flags,FileBoxFlags
write memblock dword OFN_MB,lpstrTitle,FileBoxTitle
rem Open the FileBox
if mode$="save"
call dll comdlg32,"GetSaveFileNameA",OFN
else
call dll comdlg32,"GetOpenFileNameA",OFN
endif
result$ = readStringFromMemblock(PathBuffer_MB)
rem Delete the memblocks
delete memblock OFN_MB
delete memblock PathBuffer_MB
delete memblock FileFilter_MB
delete memblock FileBoxTitle_MB
rem Delete the DLL from the memory
delete dll user32
delete dll kernel32
delete dll comdlg32
endfunction result$
rem Write a character string to the specified memblock
function writeStringToMemblock(numMemblock,text$)
for pos=1 to len(text$)
b=asc(mid$(text$,pos))
if b=asc("^") then b=0
write memblock byte numMemblock,pos-1,b
next pos
endfunction
rem Read a character string from the specified memblock
function readStringFromMemblock(numMemblock)
pos=0:text$=""
do
b=memblock byte(numMemblock,pos)
if b=0 then exit
text$=text$+chr$(b)
inc pos
loop
endfunction text$
rem Return the number of the first unused memblock
function findFreeMemblockSlot()
found=0:numMemblock=1
repeat
if memblock exist(numMemblock)=0 then exitfunction numMemblock
inc numMemblock
until numMemblock=256
endfunction 0
rem Return the first free DLL slot
function findFreeDllSlot()
found=0:numDLL=1
repeat
if dll exist(numDLL)=0 then exitfunction numDLL
inc numDLL
until numDLL=256
endfunction 0