T.ED Available here (for free)

Community Forums/Developer Stations/T.ED Available here (for free)

D4NM4N(Posted 2014) [#1]
As you know T.Ed has not been for sale for almost a year now. I have taken it down for 4 main reasons.

-One is because of my job in a company writing educational apps/games for kids, it takes up a -lot- of my time, but i love it. Unfortunately my own stuff is a contractual conflict of interest.

-The other is due to the multitude of changes to windows since Vista. Mainly things like UAC etc. TEd still works fine on windows 7 and 8 but needs some twiddling to run fully (like "run as admin", or setting folder permissions up).

-I have not the time to offer the levels of support for it that i believe paying customers deserve.

-I am no longer actively developing for "windows legacy" only windows store, android, ios, linux, and osx.


But am providing it here mainly to the bb community.

I would like to take this opportunity thank everyone who bought it in the past 10 odd years and hope you found it useful. I have delayed this freebie offer for as long as i dare out of respect for those that bought it
Again, thank you.


So.. without more blah-blah here it is.

Here you go:

https://dl.dropboxusercontent.com/u/18440078/T.ED_full_setup.zip

Here are the loaders (including two horrible looking demos from an early version! :D although it is the "epr" example you want really ) ;

https://dl.dropboxusercontent.com/u/18440078/Tedloaders.zip

..... And the name / reg code to be pasted at the very -top- of the keyfile that opens (meaning the first two lines!)

BlitzCommunity
252J2-E5B9D-WGYWS-G5CF2

If i ever decide to re-make it cross platform or update it to V7 then this code will no longer work (although existing purchased ones will), but this one will always work on all versions up to V6.x on windows.

I do have a small request, i know it probably wont happen, but this freebie is intended for mainly the blitz community, so I would ask you don't broadcast it too much :)

NOTE: Some programs include hidden characters so if copy-paste fails then try entring manually. NOTE2: If program fails to save settings / not register etc.. when using Vista/7/8 you -may- need to either turn off UAC, run as admin or give the program folder the right permissions.



-----------------------------------------------------------------------------------
Here is some code for more advanced users who may wish to import / pipeline / export ted files directly. This is the code from the actual program itself that saves and loads .ted files:

NOTE: This code will load the raw un-optimized terrains (unlike the exported ones) and are not really suitable for direct game insertion (unless the terrain is quite small). However the exporters in ted strip all geometry that has no alpha values on upper layer quad patches, making it a lot less geometry. So for most people i reccommend looking at the loader demos.
Also note this code as i said designed for advanced users only as more of a "Specification" and -may- not work just out of the box, but all the stuff needed is there.
format_codebox('
initterrain.code.bb

;----------------------------------------------------------------------
;Free all mod meshs and all trn meshes and lightmaps
;----------------------------------------------------------------------
For b=1 To 100
For a=1 To 100
If trn_modifier(a,b) FreeEntity trn_modifier(a,b) :trn_modifier(a,b)=0:
If trn_mesh (a,b) FreeEntity trn_mesh (a,b) :trn_mesh (a,b)=0

trn_layer1(a,b)=0:
trn_layer2(a,b)=0:
trn_layer3(a,b)=0:
trn_layer4(a,b)=0:
trn_layer5(a,b)=0:
trn_layer6(a,b)=0:
trn_updateflags(a,b)=0
Next
Next

;----------------------------------------------------------------------
;create new quads of mesh(contains layers) and modifier mesh
;----------------------------------------------------------------------
tim=MilliSecs()
For b=1 To trn_quadnumberY
For a=1 To trn_quadnumberX

;----------------------------------------------------------------------
;create our modifier mesh
;-----------------------------------------------------------------
trn_modifier(a,b)=createquad(x,z)
EntityTexture trn_modifier(a,b),tex_grid


;----------------------------------------------------------------------
;create main mesh and add layers for each tex
;----------------------------------------------------------------------
trn_mesh(a,b)=CreateMesh()


EntityBlend trn_mesh(a,b),1

HideEntity trn_mesh(a,b)

If MilliSecs()>=tim+1000 tim=MilliSecs():dgui_messagebox(-1,"Processing","Creating Quad - "+Int((Float(b)/trn_quadnumbery)*100)+"%")

trn_layer6(a,b)=newsurface(trn_mesh(a,b), trn_modifier(a,b),0,1)
trn_layer5(a,b)=newsurface(trn_mesh(a,b), trn_modifier(a,b),0,1)
trn_layer4(a,b)=newsurface(trn_mesh(a,b), trn_modifier(a,b),0,1)
trn_layer3(a,b)=newsurface(trn_mesh(a,b), trn_modifier(a,b),0,1)
trn_layer2(a,b)=newsurface(trn_mesh(a,b), trn_modifier(a,b),0,1)
trn_layer1(a,b)=newsurface(trn_mesh(a,b), trn_modifier(a,b),1,0)


EntityFX trn_modifier(a,b),0



Next
Next

;-------------------------------------------------------------------------------------------------------------------------------------
;scale,centerize and finish this scale is an inital cale and should only be called on a new map
;-------------------------------------------------------------------------------------------------------------------------------------
If askforvals do_scale(quadscalerx*100,quadscalery*100,quadscalerz*100,1);20000 is a percentage as quad start at size 1(=200 quadsize!)

')

format_codebox('tedloader.code.bb


Function loadversionV10(h$,file,undoload)
;TEd file format spec
;Assuming standard file has been opened:

;Check Version
If Instr (h$,"10.0")
Repeat
fline$=ReadLine (file)

DebugLog fline$
Select fline$
Case "[INITS]"
Readchunk_INITS(file)
Case "[CAM]"
Readchunk_CAM(file)
Case "[FOG]"
Readchunk_FOG(file)
Case "[LIGHT]"
Readchunk_LIGHT(file)
Case "[WATER]"
Readchunk_WATER(file)
Case"[SKY]"
Readchunk_SKY(file)

;---------------------------------------------NOTE--------------------------------------------------------------------------------------------
;Everything Before this point (any order) must be Read in before calling init terrain.
Case "[CREATE]"
init_environment(1);write changed properties like lightmap size etc
init_terrain(False)
DebugLog "Loaded terrain initialized"


;everything after (any order) must follow the init terrain
;---------------------------------------------NOTE--------------------------------------------------------------------------------------------

;----------------------------------------------------------------------
;Mesh info
;----------------------------------------------------------------------
DebugLog "quads"
Case "[TEXTURES]"
ReadchunkV10_TEXTURES(file)
Case "[QUADS]"
ReadchunkV10_QUADS(file)
Case "[LIGHTMAPS]"
ReadchunkV10_LIGHTMAPS(file)
Case "[SOURCES]"
clear_all_props()
readchunk_SOURCES(file)
CreateAllSourcesFromData()
Case "[INSTANCES]"
clear_all_instances()
readchunk_INSTANCES(file)
CreateAllinstancesFromData()
End Select
Until Eof (file)

EndIf

;----------------------------------------------------------------------
;finalize
;----------------------------------------------------------------------
DebugLog "Finalised..."
CloseFile file


;----------------------------------------------------------------------
;req update of all verts
;----------------------------------------------------------------------
do_scale(100,100,100,0);100% just to reposition
editlatch=1

FlushMouse()
FlushKeys()
End Function


;public chunks
Function Readchunk_INITS(file)
Repeat
linein$=ReadLine(file)
key$=usv(linein$,1,"=")
value$=usv(linein$,2,"=")
key$=Replace(key$," ","")

Select key$
Case "TED_Terrain_Resolution"
trn_size = usv (value,1,",")
Case "TED_Blocks_XZ"
trn_quadnumberX = usv (value,1,",")
trn_quadnumberY = usv (value,2,",")
Case "TED_Block_Size_XZ";this is not really needed, its just here for clarity, sizes are calculated in main program
Trn_BlockSizeX# = USV(value,1,",")
Trn_BlockSizeZ# = USV(value,2,",")
Case "TED_LightMap_OnOff"
lightmap_onoff = usv (value,1,",")
Case "TED_Set_Level"
trn_setlevel = usv (value,1,",")
Case "TED_Alpha_Limit"
setup_alphalimit = usv (value,1,",")
Case "TED_Lightmap_Size"
setup_lightmapresolution = usv (value,1,",")
End Select
If Instr(key$,"[FILTERS]")
Delete Each texture_filters
Repeat
lines$=ReadLine(file)
DebugLog lines
If lines<>"" And lines<>"[/FILTERS]"
key$=Lower(usv(lines,1,"="))
values$=usv(lines,2,"=")
tef.texture_filters=New texture_filters
tef\key=Key
tef\values=values
DebugLog "Read:"+key+" "+values
EndIf
If Eof(file) DebugLog"ERROR IN Filters":Return
Until Instr(lines,"[/FILTERS]")
EndIf
If Instr(key$,"[CUSTOM]")
Delete Each custom_inits
Repeat
lines$=ReadLine(file)
DebugLog lines
If lines<>"" And lines<>"[/CUSTOM]"
key$=Lower(usv(lines,1,"="))
values$=usv(lines,2,"=")
ins.custom_inits=New custom_inits
ins\key=Key
ins\values=values
EndIf
If Eof(file) DebugLog"ERROR IN CUSTOM":Return
Until Instr(lines,"[/CUSTOM]")
EndIf
If Eof(file) dgui_messagebox(0,"Error","Problem In initschunk, no terminator found!") :Return
Until Instr(linein$,"[/INITS]")
DebugLog "Loaded inits"
End Function

Function Readchunk_CAM(file)
Repeat
linein$=ReadLine(file)
key$=usv(linein$,1,"=")
value$=usv(linein$,2,"=")
key$=Replace(key$," ","")

Select key$
Case "TED_Cam_Pos_XYZ"
camx# =usv (value,1,",")
camy# =usv (value,2,",")
camz# =usv (value,3,",")
Case "TED_Cam_Rot_XYZ"
campi# =usv (value,1,",")
camya# =usv (value,2,",")
camro# =usv (value,3,",")
Case "TED_Cam_Range"
setup_camerarange =usv (value,1,",")
Case "TED_Pick_Range"
setup_pickrange =usv (value,1,",")
End Select

If Eof(file) dgui_messagebox(0,"Error","Problem In camchunk, no terminator found!") :Return
Until Instr(linein$,"[/CAM]")
DebugLog "Loaded cam"
;----------------------------------------------------------------------
;move&rotate cam
;----------------------------------------------------------------------
PositionEntity camlocktarget,camx,camy,camz,True
RotateEntity camlocktarget,campi,camya,camro,True
;RotateEntity cam,campi,camya,camro,True
;RotateEntity cam,campi,camya,camro
;dest_cam_yaw#=camya
;dest_cam_pitch#=campi



End Function

Function Readchunk_FOG(file)
Repeat
linein$=ReadLine(file)
key$=usv(linein$,1,"=")
value$=usv(linein$,2,"=")
key$=Replace(key$," ","")

Select key$
Case "TED_Fog_Range_NF"
fog_rangenear =usv(value$,1,",")
fog_rangefar =usv(value$,2,",")
Case "TED_Fog_Color_RGB"
fog_r =usv(value$,1,",")
fog_g =usv(value$,2,",")
fog_b =usv(value$,3,",")
End Select
If Eof(file) dgui_messagebox(0,"Error","Problem In fogchunk, no terminator found!") :Return
Until Instr(linein$,"[/FOG]")
DebugLog "Loaded fog"
End Function

Function Readchunk_LIGHT(file)
Repeat
linein$=ReadLine(file)
key$=usv(linein$,1,"=")
value$=usv(linein$,2,"=")
key$=Replace(key$," ","")

Select key$
Case "TED_Sun_Elevation"
sun_elevation_angle =usv(value$,1,",")
Case "TED_Sun_Rotation"
sun_rotation_angle =usv(value$,1,",")
Case "TED_Sun_Color_RGB"
sun_r =usv(value$,1,",")
sun_g =usv(value$,2,",")
sun_b =usv(value$,3,",")
Case "TED_Ambient_Color_RGB"
ambient_r =usv(value$,1,",")
ambient_g =usv(value$,2,",")
ambient_b =usv(value$,3,",")
End Select
If Eof(file) dgui_messagebox(0,"Error","Problem In lightchunk, no terminator found!") :Return
Until Instr(linein$,"[/LIGHT]")
DebugLog "Loaded light"
End Function

Function Readchunk_WATER(file)
Repeat
linein$=ReadLine(file)
key$=usv(linein$,1,"=")
value$=usv(linein$,2,"=")
key$=Replace(key$," ","")

Select key$
Case "TED_Water_Height"
water_height =usv(value$,1,",")
Case "TED_Water_Color_RGBA"
water_r =usv(value$,1,",")
water_g =usv(value$,2,",")
water_b =usv(value$,3,",")
water_alpha =usv(value$,4,",")

End Select
If Eof(file) dgui_messagebox(0,"Error","Problem In waterchunk, no terminator found!") :Return
Until Instr(linein$,"[/WATER]")
DebugLog "Loaded water"
End Function

Function Readchunk_SKY(file)
Repeat
linein$=ReadLine(file)
key$=usv(linein$,1,"=")
value$=usv(linein$,2,"=")
key$=Replace(key$," ","")

Select key$
Case "TED_Sky_Up" skyboxfile_up$ =usv(value$,1,",")
Case "TED_Sky_Dn" skyboxfile_dn$ =usv(value$,1,",")
Case "TED_Sky_Le" skyboxfile_le$ =usv(value$,1,",")
Case "TED_Sky_Ri" skyboxfile_ri$ =usv(value$,1,",")
Case "TED_Sky_Fr" skyboxfile_fr$ =usv(value$,1,",")
Case "TED_Sky_Ba" skyboxfile_ba$ =usv(value$,1,",")
Case "TED_Sky_Height" setup_skyboxheight =usv(value$,1,",")
End Select
If Eof(file) dgui_messagebox(0,"Error","Problem In skychunk, no terminator found!") :Return
Until Instr(linein$,"[/SKY]")
DebugLog "Loaded sky"
End Function

Function readchunk_SOURCES(file)

Repeat
linein$=ReadLine(file)
key$=usv(linein$,1,"=")
value$=usv(linein$,2,"=")
key$=Replace(key$," ","")
DebugLog linein
Select key$
Case "TED_Source_Count" Number_Of_Sources = usv(value$,1,",")
Case "[SRC]"
pr.propmesh=New propmesh
Repeat
linein$=ReadLine(file)
key$=usv(linein$,1,"=")
value$=usv(linein$,2,"=")
key$=Replace(key$," ","")
Select key$

Case "TED_Id" pr\id$ =usv(value$,1,",")
Case "TED_Name" pr\name$ =usv(value$,1,",")
Case "TED_Filename" pr\filename$=usv(value$,1,",")
Case "TED_Type" pr\style$ =usv(value$,1,",")

Case "TED_Selected" pr\selected% =usv(value$,1,",")
Case "TED_Visible" pr\visible% =usv(value$,1,",")
Case "TED_Blend" pr\Blend% =usv(value$,1,",")
Case "TED_Shading" pr\Shading$ =usv(value$,1,",")
Case "TED_Fx" pr\FX% =usv(value$,1,",")
Case "TED_Sprite_View_Mode" pr\SViewMode%=usv(value$,1,",")

Case "TED_Anim_Mode" pr\animmode%=usv(value$,1,",")
Case "TED_Anim_Speed" pr\Animspeed#=usv(value$,1,",")
Case "TED_Specular" pr\specular# =usv(value$,1,",")
Case "TED_Shadows" pr\shadows# =usv(value$,1,",")

Case "TED_Entity_RGBA"
pr\R% =usv(value$,1,",")
pr\G% =usv(value$,2,",")
pr\B% =usv(value$,3,",")
pr\A# =usv(value$,4,",")

Case "TED_Fade_Range_NF"
pr\AutoFadeN# =usv(value$,1,",")
pr\AutoFadeF# =usv(value$,2,",")

Case "TED_Cull_Range"
pr\cullrange# =usv(value$,1,",")

Case "TED_Pos_XYZ"
pr\px# =usv(value$,1,",")
pr\py# =usv(value$,2,",")
pr\pz# =usv(value$,3,",")

Case "TED_Rot_XYZ"
pr\rx# =usv(value$,1,",")
pr\ry# =usv(value$,2,",")
pr\rz# =usv(value$,3,",")

Case "TED_Sca_XYZ"
pr\sx# =usv(value$,1,",")
pr\sy# =usv(value$,2,",")
pr\sz# =usv(value$,3,",")

Case "[CUSTOM]"
ctm=0
Repeat
ctm=ctm+1
linein$=ReadLine(file)
If Not Instr(linein$,"[/CUSTOM]") pr\custom[ctm]=linein$
Until Instr(linein$,"[/CUSTOM]") Or ctm=50

End Select
If Eof(file) dgui_messagebox(0,"Error","Problem In source block, no terminator found!"):Return
Until Instr(linein$,"[/SRC]")
End Select
If Eof(file) dgui_messagebox(0,"Error","Problem In sources, no terminator found!"):Return

Until Instr(linein$,"[/SOURCES]")


End Function

Function readchunk_INSTANCES(file)
Repeat
linein$=ReadLine(file)
key$=usv(linein$,1,"=")
value$=usv(linein$,2,"=")
key$=Replace(key$," ","")

Select key$
Case "TED_Instance_Count" Number_Of_Instances = usv(value$,1,",")
Case "[INS]"
i.propinstance=New propinstance
Repeat
linein$=ReadLine(file)
key$=usv(linein$,1,"=")
value$=usv(linein$,2,"=")
key$=Replace(key$," ","")
Select key$

Case "TED_Id" i\id$ =usv(value$,1,",")
Case "TED_Name" i\name$ =usv(value$,1,",")
Case "TED_Type" i\style$ =usv(value$,1,",")

Case "TED_Selected" i\selected% =usv(value$,1,",")
Case "TED_Visible" i\visible% =usv(value$,1,",")
Case "TED_Blend" i\Blend% =usv(value$,1,",")
Case "TED_Shading" i\Shading% =usv(value$,1,",")
Case "TED_Fx" i\FX% =usv(value$,1,",")
Case "TED_Sprite_View_Mode" i\SViewMode%=usv(value$,1,",")

Case "TED_Anim_Mode" i\animmode%=usv(value$,1,",")
Case "TED_Anim_Speed" i\Animspeed#=usv(value$,1,",")
Case "TED_Specular" i\specular# =usv(value$,1,",")
Case "TED_Shadows" i\shadows# =usv(value$,1,",")

Case "TED_Entity_RGBA"
i\R% =usv(value$,1,",")
i\G% =usv(value$,2,",")
i\B% =usv(value$,3,",")
i\A# =usv(value$,4,",")

Case "TED_Fade_Range_NF"
i\AutoFadeN# =usv(value$,1,",")
i\AutoFadeF# =usv(value$,2,",")

Case "TED_Cull_Range"
i\cullrange# =usv(value$,1,",")

Case "TED_Pos_XYZ"
i\px# =usv(value$,1,",")
i\py# =usv(value$,2,",")
i\pz# =usv(value$,3,",")

Case "TED_Rot_XYZ"
i\rx# =usv(value$,1,",")
i\ry# =usv(value$,2,",")
i\rz# =usv(value$,3,",")

Case "TED_Sca_XYZ"
i\sx# =usv(value$,1,",")
i\sy# =usv(value$,2,",")
i\sz# =usv(value$,3,",")

Case "[CUSTOM]"
ctm=0
Repeat
ctm=ctm+1
linein$=ReadLine(file)
If Not Instr(linein$,"[/CUSTOM]") i\custom[ctm]=linein$
If Eof(file) Or ctm=51 dgui_messagebox(0,"Error","Problem In custom props, no terminator found!"):Return
Until Instr(linein$,"[/CUSTOM]")

End Select
If Eof(file) dgui_messagebox(0,"Error","Problem In instance block, no terminator found!")
Until Instr(linein$,"[/INS]")
End Select
If Eof(file) dgui_messagebox(0,"Error","Problem In instances, no terminator found!")
Until Instr(linein$,"[/INSTANCES]")

End Function




;private chunks
Function ReadchunkV10_QUADS(file)
For b=1 To trn_quadnumberY
For a=1 To trn_quadnumberX
is=GetSurface(trn_modifier(a,b),1)
s1=trn_layer1(a,b)
s2=trn_layer2(a,b)
s3=trn_layer3(a,b)
s4=trn_layer4(a,b)
s5=trn_layer5(a,b)
s6=trn_layer6(a,b)
For v=0 To CountVertices(is)-1
vx#=ReadFloat (file)
vy#=ReadFloat (file)
vz#=ReadFloat (file)

vr=ReadByte (file)
vg=ReadByte (file)
vb=ReadByte (file)

va2#=ReadFloat (file)
va3#=ReadFloat (file)
va4#=ReadFloat (file)
va5#=ReadFloat (file)
va6#=ReadFloat (file)

VertexCoords is,v,vx,vy,vz
If vx<0 Or vz<0 DebugLog vx+" "+vz
VertexColor s1,v,vr,vg,vb,1
VertexColor s2,v,vr,vg,vb,va2
VertexColor s3,v,vr,vg,vb,va3
VertexColor s4,v,vr,vg,vb,va4
VertexColor s5,v,vr,vg,vb,va5
VertexColor s6,v,vr,vg,vb,va6
trn_updateflags(a,b)=1
Next
Next
Next
DebugLog "Loaded quads"
End Function

Function ReadchunkV10_TEXTURES(file)
tex_filename1$=ReadLine (file)
tex_filename2$=ReadLine (file)
tex_filename3$=ReadLine (file)
tex_filename4$=ReadLine (file)
tex_filename5$=ReadLine (file)
tex_filename6$=ReadLine (file)
tex_uvscale(1)=ReadByte (file)
tex_uvscale(2)=ReadByte (file)
tex_uvscale(3)=ReadByte (file)
tex_uvscale(4)=ReadByte (file)
tex_uvscale(5)=ReadByte (file)
tex_uvscale(6)=ReadByte (file)
DebugLog "Loaded texture names"

End Function

Function ReadchunkV10_LIGHTMAPS(file)
DebugLog "Lightmaps"
If lightmap_onoff
init_lightmap(setup_lightmapresolution)
For b=1 To trn_quadnumberY
For a=1 To trn_quadnumberX
SetBuffer TextureBuffer(trn_lightmap(a,b))
For d=0 To setup_lightmapresolution
For c=0 To setup_lightmapresolution
re=ReadByte (file)
gr=ReadByte (file)
bl=ReadByte (file)
WritePixel c,d,argb(re,gr,bl)
Next
Next
SetBuffer BackBuffer()
Next
Next
EndIf
DebugLog "Loaded lightmaps"
End Function



')

format_codebox('
tedsave.code.bb

;============================================
;Ted Code (C) Daniel Harvey - Do not use without permission
;============================================


;----------------------------------------------------------------------
;write ted file
;----------------------------------------------------------------------
file = WriteFile (filename$)

;write header all ted files must have this as write string and then a padded linefeed this
;is to make for compatibility with older versions!
WriteString file,"Ted File V10.0"
WriteLine file,"";pad out the line!

Writechunk_INITS(file)
If senv
Writechunk_CAM(file)
Writechunk_FOG(file)
Writechunk_LIGHT(file)
Writechunk_WATER(file)
Writechunk_SKY(file)
EndIf

If Not undosave
;---------------------------------------------NOTE--------------------------------------------------------------------------------------------
;Everything Before this point must be Read in before calling init terrain when loading. (or written if making the file)
WriteLine file,"":WriteLine file,"[CREATE]"
WriteLine file,"":WriteLine file,"create terrain!"
WriteLine file,"":WriteLine file,"[/CREATE]"
;everything after must follow the init terrain
;---------------------------------------------NOTE--------------------------------------------------------------------------------------------
EndIf

If sprops
If Not undosave Writechunk_SOURCES(file)
Writechunk_INSTANCES(file)
EndIf
If sterrain
If Not undosave Writechunk_TEXTURES(file)
If Not undosave Writechunk_LIGHTMAPS(file)
Writechunk_QUADS(file)
EndIf

;----------------------------------------------------------------------
;finalize file
;----------------------------------------------------------------------
CloseFile file

;----------------------------------------------------------------------
;set environment with any new settings
;----------------------------------------------------------------------
init_environment()

;----------------------------------------------------------------------
;do not change aptitle if undosave
;----------------------------------------------------------------------
If undosave Return

;----------------------------------------------------------------------
;change docname
;----------------------------------------------------------------------
docname$=strip_path(filename$)
AppTitle "T.ED "+version$+" - "+docname$+ " - Terrain Editor (C)Dan Harvey D-Grafix Software 2005","Do you want To quit TED?"







Function Writechunk_INITS(file)
;Scope variables, these must be at the top half of the file before the [create] label!
WriteLine file,"-----------------------------------------------------------------------------------------------------------":
WriteLine file,"[INITS]"
WriteLine file,"TED_Terrain_Resolution="+trn_size
WriteLine file,"TED_Blocks_XZ="+trn_quadnumberX%+","+trn_quadnumberY%
WriteLine file,"TED_Block_Size_XZ="+trn_BlockSizeX#+","+trn_BlocksizeZ#
WriteLine file,"TED_LightMap_OnOff="+lightmap_onoff%
WriteLine file,"TED_Set_Level="+trn_setlevel#
WriteLine file,"TED_Alpha_Limit="+setup_alphalimit#
WriteLine file,"TED_Lightmap_Size="+TextureWidth(trn_lightmap(1,1))
WriteLine file,";Texturemaps - can be used to speed up dynamic loading (by not loading mesh+textures)"
WriteLine file,"TED_Layer1File="+strip_path(tex_filename1)
WriteLine file,"TED_Layer2File="+strip_path(tex_filename2)
WriteLine file,"TED_Layer3File="+strip_path(tex_filename3)
WriteLine file,"TED_Layer4File="+strip_path(tex_filename4)
WriteLine file,"TED_Layer5File="+strip_path(tex_filename5)
WriteLine file,"TED_Layer6File="+strip_path(tex_filename6)
WriteSubChunk_Filters(file)
WriteSubChunk_CustomInits(file)
WriteLine file,""
WriteLine file,"[/INITS]"
WriteLine file,""
End Function

Function WriteSubChunk_Filters(file)
WriteLine file,"[FILTERS]"
For tef.texture_filters=Each texture_filters
WriteLine file,tef\key+"="+tef\values
Next
WriteLine file,""
WriteLine file,"[/FILTERS]"
WriteLine file,""
End Function

Function WriteSubChunk_CustomInits(file)
WriteLine file,"[CUSTOM]"
For ini.custom_inits=Each custom_inits
WriteLine file,ini\key+"="+ini\values
Next
WriteLine file,""
WriteLine file,"[/CUSTOM]"
WriteLine file,""
End Function

Function Writechunk_CAM(file)
WriteLine file,"-----------------------------------------------------------------------------------------------------------":
WriteLine file,"[CAM]"
WriteLine file,"TED_Cam_Pos_XYZ="+EntityX(cam)+","+EntityY(cam)+","+EntityZ(cam)
WriteLine file,"TED_Cam_Rot_XYZ="+EntityPitch(cam)+","+EntityYaw(cam)+","+EntityRoll(cam)
WriteLine file,"TED_Cam_Range="+setup_camerarange
WriteLine file,"TED_Pick_Range="+setup_pickrange
WriteLine file,"TED_Cam_Zoom="+setup_camerazoom
WriteLine file,"[/CAM]"
WriteLine file,""
End Function

Function Writechunk_FOG(file)
WriteLine file,"-----------------------------------------------------------------------------------------------------------":
WriteLine file,"[FOG]"
WriteLine file,"TED_Fog_Range_NF="+fog_rangenear#+","+fog_rangefar#
WriteLine file,"TED_Fog_Color_RGB="+fog_r%+","+fog_g%+","+fog_b%
WriteLine file,"[/FOG]"
WriteLine file,""
End Function

Function Writechunk_LIGHT(file)
WriteLine file,"-----------------------------------------------------------------------------------------------------------":
WriteLine file,"[LIGHT]"
WriteLine file,"TED_Sun_Elevation="+sun_elevation_angle%
WriteLine file,"TED_Sun_Rotation="+sun_rotation_angle%
WriteLine file,"TED_Sun_Color_RGB="+sun_r%+","+sun_g%+","+sun_b%
WriteLine file,"TED_Ambient_Color_RGB="+ambient_r%+","+ambient_g%+","+ambient_b%
WriteLine file,"[/LIGHT]"
WriteLine file,"":
End Function

Function Writechunk_WATER(file)
WriteLine file,"-----------------------------------------------------------------------------------------------------------":
WriteLine file,"[WATER]"
WriteLine file,"TED_Water_Height="+water_height#
WriteLine file,"TED_Water_Color_RGBA="+water_r%+","+water_g%+","+water_b%+","+water_alpha#
WriteLine file,"[/WATER]"
WriteLine file,""
End Function

Function Writechunk_SKY(file)
WriteLine file,"-----------------------------------------------------------------------------------------------------------":
WriteLine file,"[SKY]"
WriteLine file, "TED_Sky_Up="+skyboxfile_up$
WriteLine file, "TED_Sky_Dn="+skyboxfile_dn$
WriteLine file, "TED_Sky_Le="+skyboxfile_le$
WriteLine file, "TED_Sky_Ri="+skyboxfile_ri$
WriteLine file, "TED_Sky_Fr="+skyboxfile_fr$
WriteLine file, "TED_Sky_Ba="+skyboxfile_ba$
WriteLine file, "TED_Sky_Height="+setup_skyboxheight%
WriteLine file,"[/SKY]"
WriteLine file,"":
End Function

Function Writechunk_SOURCES(file)
WriteLine file,"-----------------------------------------------------------------------------------------------------------":
WriteLine file,"[SOURCES]"
;count prop sources
npr=0
For pr.propmesh=Each propmesh
npr=npr+1
Next

;write number of prop sources to save/read
WriteLine file,"TED_Source_Count="+npr%

;write prop data
For pr.propmesh=Each propmesh
WriteLine file, "[SRC]"
WriteLine file, "TED_Id="+pr\id$
WriteLine file, "TED_Name="+pr\name$
WriteLine file, "TED_Filename="+pr\filename$
WriteLine file, "TED_Type="+pr\style$

WriteLine file, "TED_Selected="+pr\selected%
WriteLine file, "TED_Visible="+pr\visible%
WriteLine file, "TED_Blend="+pr\Blend%
WriteLine file, "TED_Shading="+pr\Shading$
WriteLine file, "TED_Fx="+pr\FX%
WriteLine file, "TED_Sprite_View_Mode="+pr\SViewMode%
WriteLine file, "TED_Anim_Mode="+pr\animmode%
WriteLine file, "TED_Anim_Speed="+pr\Animspeed#
WriteLine file, "TED_Entity_RGBA="+pr\R%+","+pr\G%+","+pr\B%+","+pr\A#
WriteLine file,"TED_Fade_Range_NF="+pr\AutoFadeN#+","+pr\AutoFadeF#
WriteLine file,"TED_Cull_Range="+pr\cullrange#
WriteLine file,"TED_Specular="+pr\specular#
WriteLine file,"TED_Shadows="+pr\shadows#
WriteLine file,"TED_Pos_XYZ="+pr\px#+","+pr\py#+","+pr\pz#
WriteLine file,"TED_Rot_XYZ="+pr\rx#+","+pr\ry#+","+pr\rz#
WriteLine file,"TED_Sca_XYZ="+pr\sx#+","+pr\sy#+","+pr\sz#

WriteLine file,"[CUSTOM]"
For s= 1 To 50
If pr\custom[s]<>"" WriteLine file, pr\CUSTOM$[s]
Next
WriteLine file,"[/CUSTOM]"
WriteLine file,"[/SRC]"
WriteLine file,";-----------------------------------------------"
Next
WriteLine file,"[/SOURCES]"
WriteLine file,"":
End Function
;
Function Writechunk_INSTANCES(file)
WriteLine file,"-----------------------------------------------------------------------------------------------------------":
WriteLine file,"[INSTANCES]"
;count prop sources
npr=0
For ii.propinstance=Each propinstance
npr=npr+1
Next

;write number of prop sources to save/read
WriteLine file,"TED_Instance_Count="+npr

;write prop data
For i.propinstance=Each propinstance
WriteLine file, "[INS]"
WriteLine file, "TED_Id="+i\id$
WriteLine file, "TED_Name="+i\name$
WriteLine file, "TED_Type="+i\style$

WriteLine file, "TED_Selected="+i\selected%
WriteLine file, "TED_Visible="+i\visible%
WriteLine file, "TED_Blend="+i\Blend%
WriteLine file, "TED_Fx="+i\FX%
WriteLine file, "TED_Shading="+i\Shading$
WriteLine file, "TED_Sprite_View_Mode="+i\SViewMode%
WriteLine file, "TED_Anim_Mode="+i\animmode%
WriteLine file, "TED_Anim_Speed="+i\Animspeed#
WriteLine file, "TED_Entity_RGBA="+i\R%+","+i\G%+","+i\B%+","+i\A#
WriteLine file,"TED_Fade_Range_NF="+i\AutoFadeN#+","+i\AutoFadeF#
WriteLine file,"TED_Cull_Range="+i\cullrange#
WriteLine file,"TED_Specular="+i\specular#
WriteLine file,"TED_Shadows="+i\shadows#
WriteLine file,"TED_Pos_XYZ="+i\px#+","+i\py#+","+i\pz#
WriteLine file,"TED_Rot_XYZ="+i\rx#+","+i\ry#+","+i\rz#
WriteLine file,"TED_Sca_XYZ="+i\sx#+","+i\sy#+","+i\sz#

WriteLine file,"[CUSTOM]"
For s= 1 To 50
If i\custom[s]<>"" WriteLine file, i\CUSTOM$[s]
Next
WriteLine file,"[/CUSTOM]"
WriteLine file,"[/INS]"
WriteLine file,";-----------------------------------------------"
Next
WriteLine file,"[/INSTANCES]"
WriteLine file,"":
End Function

Function Writechunk_TEXTURES(file)
;----------------------------------------------------------------------
;texture names complete with path
;----------------------------------------------------------------------
WriteLine file,"":WriteLine file,"[TEXTURES]"
WriteLine file,TextureName(tex_layer1)
WriteLine file,TextureName(tex_layer2)
WriteLine file,TextureName(tex_layer3)
WriteLine file,TextureName(tex_layer4)
WriteLine file,TextureName(tex_layer5)
WriteLine file,TextureName(tex_layer6)
WriteByte file,tex_uvscale(1)
WriteByte file,tex_uvscale(2)
WriteByte file,tex_uvscale(3)
WriteByte file,tex_uvscale(4)
WriteByte file,tex_uvscale(5)
WriteByte file,tex_uvscale(6)
WriteLine file,"[/TEXTURES]"
WriteLine file,"":
End Function

Function Writechunk_LIGHTMAPS(file)
;----------------------------------------------------------------------
;save lightmaps physical bmp data
;----------------------------------------------------------------------
If lightmap_onoff

WriteLine file,"":WriteLine file,"[LIGHTMAPS]"
setup_lightmapresolution=TextureWidth(trn_lightmap(1,1))
For b=1 To trn_quadnumberY
For a=1 To trn_quadnumberX
SetBuffer TextureBuffer(trn_lightmap(a,b))
For d=0 To setup_lightmapresolution
For c=0 To setup_lightmapresolution
GetColor c,d
WriteByte (file,ColorRed())
WriteByte (file,ColorGreen())
WriteByte (file,ColorBlue())
Next
Next
SetBuffer BackBuffer()
Next
Next
WriteLine file,"":WriteLine file,"[/LIGHTMAPS]":
WriteLine file,""

EndIf
End Function

Function Writechunk_QUADS(file)
;----------------------------------------------------------------------
;Mesh info
;----------------------------------------------------------------------
WriteLine file,"":WriteLine file,"[QUADS]"
For b=1 To trn_quadnumberY
For a=1 To trn_quadnumberX
is=GetSurface(trn_modifier(a,b),1)
s1=trn_layer1(a,b)
s2=trn_layer2(a,b)
s3=trn_layer3(a,b)
s4=trn_layer4(a,b)
s5=trn_layer5(a,b)
s6=trn_layer6(a,b)


For v=0 To CountVertices(is)-1
WriteFloat file, VertexX(is,v)
WriteFloat file, VertexY(is,v)
WriteFloat file, VertexZ(is,v)

WriteByte file, VertexRed(s1,v)
WriteByte file, VertexGreen(s1,v)
WriteByte file, VertexBlue(s1,v)

WriteFloat file, VertexAlpha(s2,v)
WriteFloat file, VertexAlpha(s3,v)
WriteFloat file, VertexAlpha(s4,v)
WriteFloat file, VertexAlpha(s5,v)
WriteFloat file, VertexAlpha(s6,v)

Next
Next
Next
WriteLine file,"":WriteLine file,"[/QUADS]"
WriteLine file,""

End Function


;----------------------------------------------------------------------
;function to shift all the meshes axis over by half a quad for export. this is to stop texture alpha probs
;----------------------------------------------------------------------
Function shiftmesh4export(shiftit,onoff$)
onoff=Lower(onoff)
If shiftit=0 Return
For b=1 To trn_quadnumberY
For a=1 To trn_quadnumberX
md#=MeshDepth(trn_modifier(a,b))
mw#=MeshWidth(trn_modifier(a,b))
If shiftit=-1 Then
If onoff="on" PositionMesh trn_modifier(a,b),(mw/2),0,(md/2) Else PositionMesh trn_modifier(a,b),-(mw/2),0,-(md/2)
If onoff="on" Then PositionMesh trn_mesh(a,b),(mw/2),0,(md/2) Else PositionMesh trn_mesh(a,b),-(mw/2),0,-(md/2)
EndIf
If shiftit=1 Then
If onoff="on" PositionMesh trn_modifier(a,b),-(mw/2),0,-(md/2) Else PositionMesh trn_modifier(a,b),(mw/2),0,(md/2)
If onoff="on" Then PositionMesh trn_mesh(a,b),-(mw/2),0,-(md/2) Else PositionMesh trn_mesh(a,b),(mw/2),0,(md/2)
EndIf
Next
Next
End Function

;----------------------------------------------------------------------
;Copy textures to exported folder
;----------------------------------------------------------------------
Function copytextures(filename$,dir$)
;save lightmaps
If lightmap_onoff exportlightmaps(filename$,dir$)

filename=strip_path(filename)
If lightmap_onoff
For b=1 To trn_quadnumberY
For A=1 To trn_quadnumberX
If trn_quadnumberx>1 Or trn_quadnumbery>1 Then numb$="("+a+","+b+")"
SaveBuffer(TextureBuffer(trn_lightmap(a,b)),dir+filename+numb$+"_lm.bmp")
;DebugLog tex_filename1
Next
Next
EndIf

;DebugLog dir

name1$=strip_path(tex_filename1)
name2$=strip_path(tex_filename2)
name3$=strip_path(tex_filename3)
name4$=strip_path(tex_filename4)
name5$=strip_path(tex_filename5)
name6$=strip_path(tex_filename6)
CopyFile tex_filename1,dir+name1
CopyFile tex_filename2,dir+name2
CopyFile tex_filename3,dir+name3
CopyFile tex_filename4,dir+name4
CopyFile tex_filename5,dir+name5
CopyFile tex_filename6,dir+name6


End Function

Function exportlightmaps(filename$,dir$,asone=0)
;save lightmaps
DebugLog "Maps:Lightmaps"
filename=strip_path(filename)
filename=Replace (Lower(filename),"_LM","")
filename=Replace (Lower(filename),"_lm","")
filename=Replace (Lower(filename),".bmp","")
If lightmap_onoff
If Not asone
For b=1 To trn_quadnumberY
For A=1 To trn_quadnumberX
If trn_quadnumberx>1 Or trn_quadnumbery>1 Then numb$="("+a+","+b+")"
SaveBuffer(TextureBuffer(trn_lightmap(a,b)),dir+filename+numb$+"_LM.bmp")
;DebugLog tex_filename1
Next
Next
Else
lmsx=TextureWidth(trn_lightmap(1,1))
lmsy=TextureHeight(trn_lightmap(1,1))
temp=CreateImage (trn_quadnumberX*lmsx,trn_quadnumberY*lmsy)
For b=1 To trn_quadnumberY
For A=1 To trn_quadnumberX
CopyRect(0,0,lmsx,lmsy,(a-1)*lmsx,(b-1)*lmsy,TextureBuffer (trn_lightmap(a,b)),ImageBuffer(temp))
Next
Next
SaveBuffer(ImageBuffer (temp),dir+filename+"_LM.bmp")
FreeImage temp
EndIf
EndIf
End Function

;----------------------------------------------------------------------
;Undos
;----------------------------------------------------------------------
;Function write_undo()
; If Not setup_undooff none=1;save_terrain(appdir+"TED_UNDO_FILE")
;End Function
;Function undo()
; If Not setup_undooff load_terrain(appdir+"TED_UNDO_FILE")
;End Function



;----------------------------------------------------------------------
;strips the path from a filename
;----------------------------------------------------------------------
Function strip_path$(f$)
f$=Lower$(f$) ; Full (!) Texture Path
lastknown=0
For p=1 To Len (f$)
If Instr(f$,"\",p) Then lastknown=lastknown+1
Next
fnl=Len(f$)-lastknown
f$=Right(f$,fnl)
;DebugLog "filename stripped"+ f$

Return f$
End Function
Function strip_filename$(full$)
full$=Replace(full$,"/","\")
If Instr(full$,"\")
pos= Instr(full$,"\")
For Char=1 To Len(full)
pos=Instr(full$,"\",Char)
If pos lst=pos
Next
Return Left (full,lst)
EndIf
End Function

;----------------------------------------------------------------------
;changes a loaded texture (called from menu)
;----------------------------------------------------------------------
Function change_texture()
If Not Instr (trn_tool,"PAINT") Then trn_tool="":dgui_messagebox(0,"Error", ">>You must choose a texture layer to change first.")
Select trn_tool
Case "PAINT1"
ChangeDir appdir+"textures"
texchanged=1:icoshadpos=oldicoshadpos
tf$=getopenfile("Load Texture",lastdirtex$,"All Files (*.dds *.bmp *.png *.jpg)" + Chr$(0) + "*.dds; *.bmp; *.jpg; *.png" + Chr$(0))
If tf<>"" Then tex_filename1=tf
lastdirtex=CurrentDir()
Case "PAINT2"
ChangeDir appdir+"textures"
texchanged=1:icoshadpos=oldicoshadpos
tf$=getopenfile("Load Texture",lastdirtex$,"All Files (*.dds *.bmp *.png *.jpg)" + Chr$(0) + "*.dds; *.bmp; *.jpg; *.png" + Chr$(0))
If tf<>"" Then tex_filename2=tf
lastdirtex=CurrentDir()
Case "PAINT3"
ChangeDir appdir+"textures"
texchanged=1:icoshadpos=oldicoshadpos
tf$=getopenfile("Load Texture",lastdirtex$,"All Files (*.dds *.bmp *.png *.jpg)" + Chr$(0) + "*.dds; *.bmp; *.jpg; *.png" + Chr$(0))
If tf<>"" Then tex_filename3=tf
lastdirtex=CurrentDir()
Case "PAINT4"
ChangeDir appdir+"textures"
texchanged=1:icoshadpos=oldicoshadpos
tf$=getopenfile("Load Texture",lastdirtex$,"All Files (*.dds *.bmp *.png *.jpg)" + Chr$(0) + "*.dds; *.bmp; *.jpg; *.png" + Chr$(0))
If tf<>"" Then tex_filename4=tf
lastdirtex=CurrentDir()
Case "PAINT5"
ChangeDir appdir+"textures"
texchanged=1:icoshadpos=oldicoshadpos
tf$=getopenfile("Load Texture",lastdirtex$,"All Files (*.dds *.bmp *.png *.jpg)" + Chr$(0) + "*.dds; *.bmp; *.jpg; *.png" + Chr$(0))
If tf<>"" Then tex_filename5=tf
lastdirtex=CurrentDir()
Case "PAINT6"
ChangeDir appdir+"textures"
texchanged=1:icoshadpos=oldicoshadpos
tf$=getopenfile("Load Texture",lastdirtex$,"All Files (*.dds *.bmp *.png *.jpg)" + Chr$(0) + "*.dds; *.bmp; *.jpg; *.png" + Chr$(0))
If tf<>"" Then tex_filename6=tf
lastdirtex=CurrentDir()
End Select
If texchanged texchanged=0 : init_textures()


End Function

;----------------------------------------------------------------------
;Import HMap & alpha maps
;----------------------------------------------------------------------
Function import_terrain()

;----------------------------------------------------------------------
;ask for color&alpha or height
;----------------------------------------------------------------------
Repeat
tryagain=0
q1$=">>Mesh/Sprite (Propsource)"
q2$=">>Heightmap"
q3$=">>Alphamap"
q4$=">>Colormap"
q5$=">>RAW FP32(.r32)"
q6$=">>"
q7$=""
q8$=""
opt=dgui_quickoptionbox("Select Import type",q1$,q2$,q3$,q4$,q5$,q6$,q7$,q8$,1)
Select opt
Case 0 Return
Case 1
Add_newprop():Return
Case 2
use$="HEIGHT"
q1$="8 Bit Grayscale => Range of 256 (Recommended)"
q2$="16 Bit Logical RG => Range of 65535"
q3$="24 Bit Logical RGB => Works with custom scale (Advanced users)"
q4$="24 Bit Reverse BGR => Works with custom scale (Advanced users)"
q5$="12 Bit Color Enhanced => Range of 4096 (Advanced users)"
q6$="24 Bit Luminance => Range of 256 (Advanced users)"

opt=dgui_quickoptionbox("Select Import type",q1$,q2$,q3$,q4$,q5$,q6$,"","",1)
Select opt
Case 0 Return
Case 1 res=8
Case 2 res=16
Case 3 res=24+1
Case 4 res=24+2
Case 5 res=12
Case 6 res=24
End Select
Case 3
q1$=">>Alpha map layer 2"
q2$=">>Alpha map layer 3"
q3$=">>Alpha map layer 4"
q4$=">>Alpha map layer 5"
q5$=">>Alpha map layer 6"
q6$=""
q7$=""
q8$=""
opt2=dgui_quickoptionbox( "Select Import type",q1,q2,q3,q4,q5,q6,q7,q8,1)
Select opt2
Case 0 tryagain=1
Case 1 use$="ALPHA2"
Case 2 use$="ALPHA3"
Case 3 use$="ALPHA4"
Case 4 use$="ALPHA5"
Case 5 use$="ALPHA6"
End Select
Case 4
use$="COLOR1"
Case 5
use$="R32"
import_r32raw():Return
End Select
Until tryagain=0

;----------------------------------------------------------------------
;open file window
;----------------------------------------------------------------------

ChangeDir appdir+"maps"
fn$=getopenfile("Load Map",lastdirmap,"All Files (*.bmp *.png *.jpg)" + Chr$(0) +"*.bmp; *.jpg; *.png" + Chr$(0))
If fn="" Return
lastdirmap=CurrentDir()
;----------------------------------------------------------------------
;load bitmap and flip it vertically
;----------------------------------------------------------------------
temp=LoadImage (fn$)
map=CreateImage (ImageWidth(temp),ImageHeight(temp))
b=0
For a=ImageHeight(temp)-1 To 0 Step -1
CopyRect 0,a,ImageWidth(map),1,0,b,ImageBuffer(temp),ImageBuffer(map)
b=b+1
Next
FreeImage temp
;----------------------------------------------------------------------
;work out image v mesh size
;----------------------------------------------------------------------
needsX=(trn_size*trn_quadnumberX)-(trn_quadnumberX-1)
needsy=(trn_size*trn_quadnumberY)-(trn_quadnumberY-1)
w=ImageWidth(map)
h=ImageHeight(map)

;----------------------------------------------------------------------
;error check size
;----------------------------------------------------------------------
If w<>needs Or h<>needs Then
ResizeImage map,needsX,needsY
w=ImageWidth(map)
h=ImageHeight(map)
;DebugLog w +" " + h
EndIf

;----------------------------------------------------------------------
;split bitmap into 32x32 or 64x64 chunks to mesh size
;and modify appropriate jobbie
;----------------------------------------------------------------------
If use$="HEIGHT"
multiplier24=inputbox("Color Value Division","What was the multiplier when heightmap was saved? Ted's save default is 100","100")
offset=inputbox("Offset - This moves the terrain mesh down by a set amount.","-what is the lowest point of the terrain to be?:","0")
EndIf
For b=1 To trn_quadnumberY
For a=1 To trn_quadnumberX
dgui_messagebox(-1,"Importing",">>Processing Line:"+Str(b)+ " of "+Str( trn_quadnumbery),">>Please Wait.")
segs(a,b)=CreateImage (trn_size,trn_size)

CopyRect(a-1)*(trn_size-1),(b-1)*(trn_size-1),trn_size,trn_size,0,0,ImageBuffer(map),ImageBuffer(segs(a,b))

surf=GetSurface(trn_modifier(a,b),1)

SetBuffer ImageBuffer(segs(a,b))
For d=0 To trn_size-1
For c=0 To trn_size-1
;get col for heightmaps
rgb%=ReadPixel(c,d)
;getcol for alpha and colormaps
GetColor c,d
red=ColorRed()
gre=ColorGreen()
blu=ColorBlue()
If use="HEIGHT"
; Get each 8bit component color
bloo%=((rgb%)Shr 16) And $FF
gren%=((rgb% ) Shr 8) And $FF
redd%=(rgb% And $FF)
; Height map resolution
If res=0 res=8
Select res
Case 8
;Calc 8bit height Grayscale (rgb all equal)
hgt#=(gren)+offset
Case 12
;Calc 12bit height (g and r channels, g most significant)
hgt#=(gren% Shl 4 + (redd% And $0F))+offset
Case 16
;Calc 16bit height (full g and r channels, g most significant)
hgt#=((gren% Shl 8 + redd%)+offset)
Case 24
;Calc 24bit Luminance = 0.3 x R + 0.59 x G + 0.11 x B
hgt#=(0.3 * redd%)+(0.59 * gren%)+(0.11 * bloo%) + offset
Case 25
;Calc 24bit logical
;hgt=argb(red,gre,blu) + offset
hgt#=((Float(blu+(256*gre)+(65536*red))/multiplier24))+offset
Case 26
;Calc 24bit logical
;hgt=argb(red,gre,blu) + offset
hgt#=((Float(red+(256*gre)+(65536*blu))/multiplier24))+offset
End Select
;average = (((red+gre+blu)/3)-128)
v=c+(d*trn_size)
vx#=VertexX(surf,v)
vz#=VertexZ(surf,v)
;VertexCoords surf,v,vx,average,vz
TFormPoint 0,hgt#,0,0,trn_modifier(a,b)
VertexCoords surf,v,vx,TFormedY(),vz
trn_updateflags(a,b)=1
editlatch=1
EndIf
If use="COLOR1"
v=c+(d*trn_size)

VertexColor trn_layer1(a,b),v,red,gre,blu,1
VertexColor trn_layer2(a,b),v,red,gre,blu,VertexAlpha(trn_layer2(a,b),v)
VertexColor trn_layer3(a,b),v,red,gre,blu,VertexAlpha(trn_layer3(a,b),v)
VertexColor trn_layer4(a,b),v,red,gre,blu,VertexAlpha(trn_layer4(a,b),v)
VertexColor trn_layer5(a,b),v,red,gre,blu,VertexAlpha(trn_layer5(a,b),v)
VertexColor trn_layer6(a,b),v,red,gre,blu,VertexAlpha(trn_layer6(a,b),v)
editlatch=2
EndIf
If Instr(use,"ALPHA")
If use="ALPHA2" psurf=trn_layer2(a,b)
If use="ALPHA3" psurf=trn_layer3(a,b)
If use="ALPHA4" psurf=trn_layer4(a,b)
If use="ALPHA5" psurf=trn_layer5(a,b)
If use="ALPHA6" psurf=trn_layer6(a,b)
v=c+(d*trn_size)
vr#=VertexRed(trn_layer1(a,b),v)
vg#=VertexGreen(trn_layer1(a,b),v)
vb#=VertexBlue(trn_layer1(a,b),v)
raw=(red+gre+blu)/3
If raw<1 va#=0.000
If raw>0 va#=0.000
If raw>42 va#=setup_alphalimit*.2
If raw> 85 va#=setup_alphalimit*.4
If raw>127 va#=setup_alphalimit*.6
If raw>170 va#=setup_alphalimit*.8
If raw>213 va#=setup_alphalimit
VertexColor psurf,v,vr,vg,vb,va
editlatch=2
EndIf
Next
Next
SetBuffer BackBuffer()
FreeImage segs(a,b)
Next
Next
RenderWorld()

;----------------------------------------------------------------------
;free all bitmaps
;----------------------------------------------------------------------
FreeImage map

If use="HEIGHT" dgui_messagebox(0,"Import Complete",">>Ted imports height in exact 3d units. If you are using a large",">>terrain you will need To scale the Y axis To suit your needs!",">>Also, if the seams look sharp, use the 'seam smooth' option in tools to smooth them out!. ")
End Function
Function import_r32raw()
;----------------------------------------------------------------------
;open file window
;----------------------------------------------------------------------

ChangeDir appdir+"maps"
fn$=getopenfile("Floating Point Raw",lastdirmap,"All Files (*.r32 *.raw)" + Chr$(0) +"*.r32; *.raw" + Chr$(0))
If fn="" Return

r32file=OpenFile(fn)
If r32file
calc=Sqr(FileSize(fn)/4)
r32sizex=inputbox("R32 Import Size X","",calc)
r32sizey=inputbox("R32 Import Size Y","",calc)
r32x=0
r32y=r32sizeY-1
multip=inputbox("Height Multiplier (R32 values 0.0-1.0)","",500)
hoffs=inputbox("Height Offset (multiplier)","",-multip/2)
If r32sizex=0 Return
If r32sizey=0 Return
nomore=0
dgui_messagebox(-1,"Processing","Importing Data, please wait")
Repeat
r32val#=ReadFloat(r32file)
;DebugLog r32val#
getworldMSV(r32X,r32y,1)
If Not getworld_error
;DebugLog "ok"+r32x+" "+r32y
vtx=VertexX (getworld_surf,getworld_index)
vtz=VertexZ (getworld_surf,getworld_index)
VertexCoords (getworld_surf,getworld_index,vtx,(r32val#*multip)+hoffs,vtz)
EndIf
r32x=r32x+1
If r32x>r32sizeX-1 Then r32x=0: r32y=r32y-1
If r32y<0 Then r32y=0: nomore=1
Until Eof(r32file) Or nomore
forcefullterrainupdate()
similarise_terrain()
CloseFile r32file
EndIf
End Function
;----------------------------------------------------------------------
;Load terrrain
;----------------------------------------------------------------------
Function load_terrain(filename$,undoload=0)

;----------------------------------------------------------------------
;error check filename
;----------------------------------------------------------------------
If filename$="" Return
If Not undoload If Upper(Right(filename$,4))<>".TED" filename=filename+".TED"

;----------------------------------------------------------------------
;read ted file
;----------------------------------------------------------------------
file = ReadFile (filename$)

;----------------------------------------------------------------------
;error check if not exist
;----------------------------------------------------------------------
If Not file dgui_messagebox(0,"Error!",">>File not found!"):Return

;----------------------------------------------------------------------
;data read
;----------------------------------------------------------------------
h$ =ReadString (file) ;header

If Instr(h$,"1.0") loadversion1_6(h$,file,undoload)
If Instr(h$,"2.0") loadversion1_6(h$,file,undoload)
If Instr(h$,"3.0") loadversion1_6(h$,file,undoload)
If Instr(h$,"4.0") loadversion1_6(h$,file,undoload)
If Instr(h$,"5.0") loadversion1_6(h$,file,undoload)
If Instr(h$,"6.0") loadversion1_6(h$,file,undoload)
If Instr(h$,"7.0") loadversion7(h$,file,undoload)
If Instr(h$,"8.0") loadversion8(h$,file,undoload)
If Instr(h$,"9.0") loadversion9(h$,file,undoload)
If Instr(h$,"10.0") loadversionV10(h$,file,undoload)


update_instances(1)

;----------------------------------------------------------------------
;no apptitle change for undo
;----------------------------------------------------------------------
If undoload Return

;----------------------------------------------------------------------
;change apptitle
;----------------------------------------------------------------------
docname$=strip_path(filename$)
AppTitle "T.ED "+version$+" - "+docname$+ " - Terrain Editor (C)Dan Harvey D-Grafix Software 2005","Do you want To quit TED? Unsaved work will be lost!"


End Function


')


D4NM4N(Posted 2014) [#2]
PS: Please don't use the support email/forums/website from the app. It will not be answered. However I don't mind answering the odd intelligently asked question here when i can.


GaryV(Posted 2014) [#3]
Thank you. This was very generous of you.


Ian Thompson(Posted 2014) [#4]
Thanks Dan, this is very generous of you. :)


Yue(Posted 2014) [#5]
thanks you!!


Calibrator(Posted 2014) [#6]
Thanks!

> Unfortunately my own stuff is a contractual conflict of interest.

Does that mean that you can't work on your own stuff *at all*?

Just wondering...


Hotshot2005(Posted 2014) [#7]
I bought it years ago and this is Excellent software!

Now it is Free, grab it while you can :)


mv333(Posted 2014) [#8]
Maybe you should update the website link here :

Blitz Toolbox


D4NM4N(Posted 2014) [#9]
Only a site mod can do that


N_Gnom(Posted 2014) [#10]
D4NM4N: is spriteforge available atm?
Or is it free too?
I need such tool.


*(Posted 2014) [#11]
Crikey I bought this years ago and now its free, damn I only got about a decade of use out of it LOL j/k :)


grindalf(Posted 2014) [#12]
How am I only just finding this tool now. This is awesome :)
Doesn't help me with my current project but its still awesome.


Juggernaut(Posted 2017) [#13]
The links in the first post are not working. Can anybody please re-upload ?


Dan(Posted 2017) [#14]
Here, both files as 7z in Expirebox, valid for 2 days


gpete(Posted 2017) [#15]
Nice....experimenting with the various export modes.....thank you!~