Been working on this this weekend and now have terrains loading with the layers. Just need to sort the alpha layering and vertex colors. It seems he didn't use the same ordering for the alpha and color saving as he did with the heights. I am having to use the heights from bottom left to top right and bottom to top and then left to right. I am having to use the alpha values from shifted 270 degrees from that. It also seems the color data may be 270 deg from the height data AND mirrored 180 deg from that.
SS attached of the alpha in place. I just need to use a better transparency mode it seems to fix the blockiness.
[edit] New code fixes ordering of alpha and vertex colors. Fixed all issues with alpha and coloring. Just need to figure out how to blend them more seemlessly now 0_o Also added code to not make double polys that would be hidden anyway (alpha of 0).
`3DW Importer WIP
`======================
`Joey Barfield
`Lost In Thought
`======================
`Main Source File
`get command line data
templevelname$ = CL$()
`setup screen values
Sync on : sync rate 0
hide mouse
`autocam off
backdrop on
color backdrop rgb(176, 176, 255)
set camera range 0.5, 300000
`load effect for blending textures per limb
load effect "stage test.fx", 1, 0
set effect technique 1, "t0"
`setup variables for use with the loader
gosub Make_Types_Vars
`load default image if image file not found
load image "dev\NoTex.bmp", numImgs
inc numImgs, 1
`parse level for data
load_level( templevelname$ )
`save lightmaps from the data for viewing only
Export_Lightmaps()
`setup meshs from data
setup_meshs()
`create brush objects from data
create_brushes()
`create terrains
Create_Terrains()
`Main testing loop
do
`basic mlook and movement
rotate camera camera angle x()+(mousemovey()/2),camera angle y()+(mousemovex()/2),0
if camera angle x()>90 then xrotate camera 90
if camera angle x()<-90 then xrotate camera -90
cx#=camera angle x() : cy#=camera angle y() : cz#=camera angle z()
if upkey()=1
move camera 30
endif
if downkey()=1
move camera -30
endif
if rightkey()=1
xrotate camera 0: yrotate camera cy# + 90: move camera 30: xrotate camera cx#: yrotate camera cy#
endif
if leftkey()=1
xrotate camera 0: yrotate camera cy# - 90: move camera 30: xrotate camera cx#: yrotate camera cy#
endif
`print stats
set cursor 0,0
print "Fps : ", screen fps(), " : Polys : ", statistic(1)
print "Total : Read Data: ", TotalDataSize, " : ", total_read
`update screen
sync
loop
end
Make_Types_Vars:
type Header
MapVer as word
Flags as byte
NameCnt as integer
NameOffset as integer
ObjectCnt as integer
ObjectOffset as Integer
endtype
type objTable
objClass as dword
dataSize as integer
endtype
type keysInf
keyName as dword
keyVal as dword
endtype
type material
flags as byte
groupName as dword
objectName as dword
extName as dword
Index as integer
FileName as string
imgNum as integer
endtype
type meshRef
flags as byte
groupName as dword
objectName as dword
limbCnt as byte
limbCnt2 as byte
MaxLimbs as byte
Index as integer
FileName as string
objNum as integer
used as integer
endtype
type group
flags as byte
groupInd as integer
realgroupInd as integer
Index as integer
endtype
type visgroup
flags as byte
name as dword
color as dword
Index as integer
endtype
type mesh
flags as byte
keys as integer
MaxKeys as integer
groupInd as integer
realgroupInd as integer
visGroupInd as integer
realVisGroupInd as integer
color as dword
meshRefInd as integer
realMeshRefInd as integer
PosX as float
PosY as float
PosZ as float
RotX as float
RotY as float
RotZ as float
ScaleX as float
ScaleY as float
ScaleZ as float
MaxVertCnt as word
Index as integer
objNum as integer
limbCnt as byte
limbCnt2 as byte
endtype
type meshLimb
MaterialInd as integer
realMaterialInd as integer
vertCnt as word
endtype
type MeshLimbVert
color as dword
endtype
type lightMap
flags as byte
resolution as byte
format as integer
imgNum as integer
Index as integer
endtype
type brush
flags as byte
keys as integer
MaxKeys as integer
groupInd as integer
realgroupInd as integer
visGroupInd as integer
realVisGroupInd as integer
color as dword
vertCnt as byte
MaxVertCnt as byte
faceCnt as byte
MaxFaceCnt as byte
maxIndiceCnt as byte
Index as integer
objNum as integer
endtype
type brushVert
vertPosX as float
vertPosY as float
vertPosZ as float
vertColor as dword
ucoord as float
vcoord as float
endtype
type brushFace
flags as byte
facex as float
facey as float
facez as float
faced as float
tex_posx as float
tex_posy as float
tex_scalex as float
tex_scaley as float
tex_rotx as float
tex_roty as float
planeU1 as float
planeU2 as float
planeU3 as float
planeU4 as float
planeV1 as float
planeV2 as float
planeV3 as float
planeV4 as float
luxel_size as float
SmoothGroupInd as integer
MaterialInd as integer
realMaterialInd as integer
LightmapInd as integer
realLightmapInd as integer
indiceCnt as byte
limbNum as integer
endtype
type brushFaceInd
vertInd as byte
mainU as float
mainV as float
LightmapU as float
LightmapV as float
endtype
type entity
flags as byte
posX as float
posY as float
posZ as float
keys as integer
MaxKeys as integer
groupInd as integer
realgroupInd as integer
visGroupInd as integer
realVisGroupInd as integer
Index as integer
endtype
type terrain
flags as byte
posX as float
posY as float
posZ as float
width as float
height as float
nameInd as dword
resolution as integer
sectors as integer
detail_levels as integer
lightmapRes as float
layerCnt as integer
maxLayerCnt as integer
maxRes as integer
Index as integer
endtype
type terrainResCol
color as dword
endtype
type terrainResHgt
xpos as float
height as float
zpos as float
endtype
type terrainLayer
nameInd as dword
MaterialInd as integer
realMaterialInd as integer
endtype
type terrainLayerAlpha
alpha as dword
endtype
global HeaderInfo as Header
dim materialInf(0) as material
dim meshRefInf(0) as meshRef
dim groupInf(0) as group
dim visgroupInf(0) as visgroup
dim meshInf(0) as mesh
dim lightmapInf(0) as lightMap
dim brushInf(0) as brush
dim entityInf(0) as entity
dim terrainInf(0) as terrain
Global numImgs
numImgs = 1
Global numObjs
numObjs = 1
Global bytes_read
bytes_read = 0
global total_read
global TotalDataSize
global meshDataCnt
meshDataCnt = 0
global meshBeginPos
global meshIbegPos
global totalNumMeshs
totalNumMeshs = 0
global brushDataCnt
brushDataCnt = 0
global brushBeginPos
global brushIbegPos
global totalNumBrushs
totalNumBrushs = 0
global terrainDataCnt
terrainDataCnt = 0
global terrainBeginPos
global terrainIbegPos
global totalNumTerrains
totalNumTerrains = 0
`hold tempory UV data for each terrain tile
dim Univ_UV_Hold( 3,1 )
Univ_UV_Hold( 0,0 ) = 0.0
Univ_UV_Hold( 0,1 ) = 1.0
Univ_UV_Hold( 1,0 ) = 0.0
Univ_UV_Hold( 1,1 ) = 0.0
Univ_UV_Hold( 2,0 ) = 1.0
Univ_UV_Hold( 2,1 ) = 0.0
Univ_UV_Hold( 3,0 ) = 1.0
Univ_UV_Hold( 3,1 ) = 1.0
return
function load_level( levelname$ )
`open test file for reading
TotalDataSize = file size(levelname$)
open to read 1, levelname$
make memblock from file 1, 1
close file 1
a = 0
`read header
HeaderInfo.MapVer = memblock word(1,a)
inc a, 2
`if wrong map version then end with prompt
if HeaderInfo.MapVer <> 14
message "Error", "Wrong map version"
end
endif
HeaderInfo.Flags = memblock byte(1,a)
inc a, 1
HeaderInfo.NameCnt = memblock dword(1,a)
inc a, 4
HeaderInfo.NameOffset = memblock dword(1,a)
inc a, 4
HeaderInfo.ObjectCnt = memblock dword(1,a)
inc a, 4
HeaderInfo.ObjectOffset = memblock dword(1,a)
inc a, 4
total_read = 19
bytes_read = 0
dim Name_Table$(HeaderInfo.NameCnt)
for i = 1 to HeaderInfo.NameCnt
test$ = "null"
temp$ = ""
repeat
temp1 = memblock byte(1, HeaderInfo.NameOffset+bytes_read)
test$ = chr$(temp1)
temp$ = temp$ + test$
inc bytes_read, 1
until test$ = ""
Name_Table$(i) = temp$
next i
total_read = total_read + bytes_read
bytes_read = 0
dim objTableInf(HeaderInfo.ObjectCnt) as objTable
groupread = 0
for i = 1 to HeaderInfo.ObjectCnt
objTableInf(i).objClass = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
`get mesh count data for array dimming
if meshDataCnt = 0
if Name_Table$(objTableInf(i).objClass) = "mesh"
meshDataCnt = 1
meshBeginPos = bytes_read
meshIbegPos = i
for l = meshIbegPos to HeaderInfo.ObjectCnt
if l > meshIbegPos
tempobjClass = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
else
tempobjClass = objTableInf(l).objClass
endif
if Name_Table$(tempobjClass) <> "mesh"
exit
endif
inc bytes_read, 8
Gather_Mesh_Stats()
next l
bytes_read = meshBeginPos
i = meshIbegPos
dim meshKeyInf(totalNumMeshs,meshInf(0).MaxKeys) as keysInf
dim MeshLimbInf(totalNumMeshs,meshRefInf(0).MaxLimbs) as meshLimb
dim MeshLimbVertInf(totalNumMeshs,meshRefInf(0).MaxLimbs,meshInf(0).MaxVertCnt) as MeshLimbVert
endif
endif
`get brush count data for array dimming
if brushDataCnt = 0
if Name_Table$(objTableInf(i).objClass) = "brush"
brushDataCnt = 1
brushBeginPos = bytes_read
brushIbegPos = i
for l = brushIbegPos to HeaderInfo.ObjectCnt
if l > brushIbegPos
tempobjClass = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
else
tempobjClass = objTableInf(l).objClass
endif
if Name_Table$(tempobjClass) <> "brush"
exit
endif
inc bytes_read, 8
Gather_Brush_Stats()
next l
bytes_read = brushBeginPos
i = brushIbegPos
dim brushKeyInf(totalNumBrushs,brushInf(0).MaxKeys) as keysInf
dim brushVertInf(totalNumBrushs,brushInf(0).MaxVertCnt) as brushVert
dim brushFaceInf(totalNumBrushs,brushInf(0).MaxFaceCnt) as brushFace
dim brushFaceIndInf(totalNumBrushs,brushInf(0).MaxFaceCnt,brushInf(0).maxIndiceCnt) as brushFaceInd
endif
endif
`get terrain count data for array dimming
if terrainDataCnt = 0
if Name_Table$(objTableInf(i).objClass) = "terrain"
terrainDataCnt = 1
terrainBeginPos = bytes_read
terrainIbegPos = i
for l = terrainIbegPos to HeaderInfo.ObjectCnt
if l > terrainIbegPos
tempobjClass = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
else
tempobjClass = objTableInf(l).objClass
endif
if Name_Table$(tempobjClass) <> "terrain"
exit
endif
inc bytes_read, 8
Gather_Terrain_Stats()
next l
bytes_read = terrainBeginPos
i = terrainIbegPos
dim terrainResColInf(totalNumTerrains,terrainInf(0).maxRes, terrainInf(0).maxRes) as terrainResCol
dim terrainResHgtInf(totalNumTerrains,terrainInf(0).maxRes+1, terrainInf(0).maxRes+1) as terrainResHgt
dim terrainLayerInf(totalNumTerrains,terrainInf(0).MaxlayerCnt) as terrainLayer
dim terrainLayerAlphaInf(totalNumTerrains,terrainInf(0).MaxlayerCnt,terrainInf(0).maxRes+1, terrainInf(0).maxRes+1) as terrainLayerAlpha
endif
endif
inc bytes_read, 4
objTableInf(i).dataSize = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
select Name_Table$(objTableInf(i).objClass)
case "material"
Read_Material( i )
endcase
case "meshreference"
Read_MeshRef( i )
endcase
case "group"
Read_Group( i )
endcase
case "visgroup"
Read_Visgroup( i )
endcase
case "mesh"
Read_Mesh( i )
endcase
case "lightmap"
Read_Lightmap( i )
endcase
case "brush"
Read_Brush( i )
endcase
case "entity"
Read_Entity( i )
endcase
case "terrain"
Read_Terrain( i )
endcase
endselect
if total_read + bytes_read > TotalDataSize
message "Error occured", "Too much data read"
end
endif
next i
delete memblock 1
`sort group real indexs as they may have loaded out of order
`on complex groups
Sort_Groups()
`error checking for reading
total_read = total_read + bytes_read
if total_read < TotalDataSize
message "Error occured", str$(total_read)+":"+str$(TotalDataSize)
end
endif
endfunction
function Read_Material( index )
array insert at bottom materialInf(0)
tempArryCnt = array count(materialInf(0))
materialInf(tempArryCnt).flags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
materialInf(tempArryCnt).groupName = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
materialInf(tempArryCnt).objectName = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
materialInf(tempArryCnt).FileName = Name_Table$(materialInf(tempArryCnt).groupName)+"\"+Name_Table$(materialInf(tempArryCnt).objectName)
if (2 && materialInf(tempArryCnt).flags)
`materialInf(tempArryCnt).extName = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
`materialInf(tempArryCnt).FileName = materialInf(tempArryCnt).FileName+Name_Table$(materialInf(tempArryCnt).extName)
materialInf(tempArryCnt).FileName = "dev\NoTex.bmp"
materialInf(tempArryCnt).imgNum = 1
else
resExt$ = Find_Material( materialInf(tempArryCnt).FileName )
if resExt$ <> ""
materialInf(tempArryCnt).imgNum = numImgs
materialInf(tempArryCnt).FileName = materialInf(tempArryCnt).FileName + resExt$
load image materialInf(tempArryCnt).FileName, numImgs
inc numImgs, 1
else
materialInf(tempArryCnt).FileName = "dev\NoTex.bmp"
materialInf(tempArryCnt).extName = 0
materialInf(tempArryCnt).imgNum = 1
endif
endif
materialInf(tempArryCnt).Index = index
endfunction
function Read_MeshRef( index )
array insert at bottom meshRefInf(0)
tempArryCnt = array count(meshRefInf(0))
meshRefInf(tempArryCnt).flags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
meshRefInf(tempArryCnt).groupName = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
meshRefInf(tempArryCnt).objectName = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
meshRefInf(tempArryCnt).FileName = Name_Table$(meshRefInf(tempArryCnt).groupName)+"\"+Name_Table$(meshRefInf(tempArryCnt).objectName)
if file exist(meshRefInf(tempArryCnt).FileName+".x") = 1
meshRefInf(tempArryCnt).FileName = meshRefInf(tempArryCnt).FileName+".x"
load object meshRefInf(tempArryCnt).FileName, numObjs
meshRefInf(tempArryCnt).objNum = numObjs
inc numObjs, 1
for j = 0 to 10000
if limb exist(meshRefInf(tempArryCnt).objNum,j) = 1
templimbnum = j
else
exit
endif
next j
meshRefInf(tempArryCnt).limbCnt2 = templimbnum
else
meshRefInf(tempArryCnt).objNum = 0
meshRefInf(tempArryCnt).limbCnt2 = 0
endif
meshRefInf(tempArryCnt).limbCnt = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
if tempArryCnt = 1
meshRefInf(0).MaxLimbs = meshRefInf(tempArryCnt).limbCnt
else
if meshRefInf(tempArryCnt).limbCnt > meshRefInf(0).MaxLimbs
meshRefInf(0).MaxLimbs = meshRefInf(tempArryCnt).limbCnt
endif
endif
meshRefInf(tempArryCnt).Index = index
meshRefInf(tempArryCnt).used = 0
endfunction
function Read_Group( index )
array insert at bottom groupInf(0)
tempArryCnt = array count(groupInf(0))
groupInf(tempArryCnt).flags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
groupInf(tempArryCnt).groupInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
groupInf(tempArryCnt).Index = index
endfunction
function Read_Visgroup( index )
array insert at bottom visgroupInf(0)
tempArryCnt = array count(visgroupInf(0))
visgroupInf(tempArryCnt).flags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
visgroupInf(tempArryCnt).name = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
tempDwordName1 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
tempDwordName2 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read+1)
tempDwordName3 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read+2)
inc bytes_read, 3
tempDwordName = 255 << 24
tempDwordName = tempDwordName+(tempDwordName1 << 16)
tempDwordName = tempDwordName+(tempDwordName2 << 8)
tempDwordName = tempDwordName+tempDwordName3
visgroupInf(tempArryCnt).color = tempDwordName
visgroupInf(tempArryCnt).Index = index
endfunction
function Gather_Mesh_Stats()
`keep up witn number of meshs
inc totalNumMeshs, 1
`read flags for scale and lightmap info
tempmeshflags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
`get number of keys in mesh
tempmeshkeys = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
`get max num keys in any mesh
if totalNumMeshs = 1
meshInf(0).MaxKeys = tempmeshkeys
else
if tempmeshkeys > meshInf(0).MaxKeys
meshInf(0).MaxKeys = tempmeshkeys
endif
endif
`skip keyname and values for now
for j = 1 to tempmeshkeys
inc bytes_read, 8
next j
`skip group, visgroup, and color for now
inc bytes_read, 11
`get mesh ref index to objain limb cnt from later
tempMeshRefInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
`convert mesh index to our real mesh index for faster finding later
tempArryCnt2 = array count(meshRefInf(0))
for j = 1 to tempArryCnt2
if meshRefInf(j).Index = tempMeshRefInd
tempRealMeshRefInd = j
exit
endif
next j
`skip mesh position and rotation for now
inc bytes_read, 24
`skip mesh scale for now if it applies
if not (1 && tempmeshflags)
inc bytes_read, 12
endif
for j = 1 to meshRefInf(tempRealMeshRefInd).limbCnt
`skip material index for now
inc bytes_read, 4
`if mesh is lightmapped
if (16 && tempmeshflags)
`get number of verts in mesh
tempMeshVertCnt = memblock word(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 2
`get max num verts in any mesh
if tempArryCnt = 1 and j = 1
meshInf(0).MaxVertCnt = tempMeshVertCnt
else
if tempMeshVertCnt > meshInf(0).MaxVertCnt
meshInf(0).MaxVertCnt = tempMeshVertCnt
endif
endif
`skip vert lightmap color for now
for k = 1 to tempMeshVertCnt
inc bytes_read, 3
next k
endif
next j
endfunction
function Read_Mesh( index )
array insert at bottom meshInf(0)
tempArryCnt = array count(meshInf(0))
totalNumMeshs = tempArryCnt
meshInf(tempArryCnt).flags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
meshInf(tempArryCnt).keys = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
for j = 1 to meshInf(tempArryCnt).keys
meshKeyInf(tempArryCnt,j).keyName = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
meshKeyInf(tempArryCnt,j).keyVal = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
next j
meshInf(tempArryCnt).groupInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
if meshInf(tempArryCnt).groupInd > 0
tempArryCnt2 = array count(groupInf(0))
for j = 1 to tempArryCnt2
if groupInf(j).Index = meshInf(tempArryCnt).groupInd
meshInf(tempArryCnt).realgroupInd = j
exit
endif
next j
endif
inc bytes_read, 4
meshInf(tempArryCnt).visGroupInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
if meshInf(tempArryCnt).visgroupInd > 0
tempArryCnt2 = array count(visgroupInf(0))
for j = 1 to tempArryCnt2
if visgroupInf(j).Index = meshInf(tempArryCnt).visgroupInd
meshInf(tempArryCnt).realvisgroupInd = j
exit
endif
next j
endif
inc bytes_read, 4
tempDwordName1 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
tempDwordName2 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read+1)
tempDwordName3 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read+2)
inc bytes_read, 3
tempDwordName = 255 << 24
tempDwordName = tempDwordName+(tempDwordName1 << 16)
tempDwordName = tempDwordName+(tempDwordName2 << 8)
tempDwordName = tempDwordName+tempDwordName3
meshInf(tempArryCnt).color = tempDwordName
meshInf(tempArryCnt).meshRefInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
tempArryCnt2 = array count(meshRefInf(0))
for j = 1 to tempArryCnt2
if meshRefInf(j).Index = meshInf(tempArryCnt).meshRefInd
meshInf(tempArryCnt).realMeshRefInd = j
exit
endif
next j
meshInf(tempArryCnt).PosX = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
meshInf(tempArryCnt).PosY = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
meshInf(tempArryCnt).PosZ = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
meshInf(tempArryCnt).RotX = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
meshInf(tempArryCnt).RotY = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
meshInf(tempArryCnt).RotZ = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
if not (1 && meshInf(tempArryCnt).flags)
meshInf(tempArryCnt).ScaleX = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
meshInf(tempArryCnt).ScaleY = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
meshInf(tempArryCnt).ScaleZ = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
else
meshInf(tempArryCnt).ScaleX = 1.0
meshInf(tempArryCnt).ScaleY = 1.0
meshInf(tempArryCnt).ScaleZ = 1.0
endif
for j = 1 to meshRefInf(meshInf(tempArryCnt).realMeshRefInd).limbCnt
MeshLimbInf(tempArryCnt,j).materialInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
if MeshLimbInf(tempArryCnt,j).materialInd > 0
tempArryCnt2 = array count(materialInf(0))
for k = 1 to tempArryCnt2
if materialInf(k).Index = MeshLimbInf(tempArryCnt,j).materialInd
MeshLimbInf(tempArryCnt,j).realmaterialInd = k
exit
endif
next k
endif
inc bytes_read, 4
if (16 && meshInf(tempArryCnt).flags)
MeshLimbInf(tempArryCnt,j).vertCnt = memblock word(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 2
for k = 1 to MeshLimbInf(tempArryCnt,j).vertCnt
tempDwordName1 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
tempDwordName2 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read+1)
tempDwordName3 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read+2)
inc bytes_read, 3
tempDwordName = 255 << 24
tempDwordName = tempDwordName+(tempDwordName1 << 16)
tempDwordName = tempDwordName+(tempDwordName2 << 8)
tempDwordName = tempDwordName+tempDwordName3
MeshLimbVertInf(tempArryCnt,j,k).color = tempDwordName
`MeshLimbVertInf(tempArryCnt,j,k).color = rgb(tempDwordName1, tempDwordName2, tempDwordName3)
next k
endif
next j
meshInf(tempArryCnt).Index = index
meshInf(tempArryCnt).objNum = 0
endfunction
function setup_meshs()
tempArryCnt = array count(meshInf(0))
for i = 1 to tempArryCnt
tempObjnum = meshRefInf(meshInf(i).realMeshRefInd).objNum
if tempObjnum > 0
if meshRefInf(meshInf(i).realMeshRefInd).used = 0
meshRefInf(meshInf(i).realMeshRefInd).used = 1
meshInf(i).objNum = tempObjnum
else
meshInf(i).objNum = numObjs
clone object meshInf(i).objNum, tempObjnum, 0
inc numObjs, 1
endif
meshInf(i).limbCnt = meshRefInf(meshInf(i).realMeshRefInd).limbCnt
meshInf(i).limbCnt2 = meshRefInf(meshInf(i).realMeshRefInd).limbCnt2
position object meshInf(i).objNum, meshInf(i).PosX, meshInf(i).PosY, meshInf(i).PosZ
rotate object meshInf(i).objNum, object angle x(tempObjnum)-meshInf(i).RotX, object angle y(tempObjnum)-meshInf(i).RotY, object angle z(tempObjnum)-meshInf(i).RotZ
scale object meshInf(i).objNum, meshInf(i).ScaleX*100, meshInf(i).ScaleY*100, meshInf(i).ScaleZ*100
set object transparency meshInf(i).objNum, 4
if (16 && meshInf(i).flags)
convert object fvf meshInf(i).objNum, 338
`set object ambient meshInf(i).objNum, 0
`set object light meshInf(i).objNum, 0
endif
tempcurlimb2 = meshRefInf(meshInf(i).realMeshRefInd).limbCnt+1
for j = 0 to meshRefInf(meshInf(i).realMeshRefInd).limbCnt2
lock vertexdata for limb meshInf(i).objNum, j
tempcnt = get vertexdata vertex count()
if tempcnt > 0
for k = tempcurlimb2-1 to 0 step -1
if MeshLimbInf(i,k).vertCnt > 0
tempcurlimb2 = k
exit
endif
next k
texture limb meshInf(i).objNum, j, materialInf(MeshLimbInf(i,k).realmaterialInd).imgNum
if (16 && meshInf(i).flags)
for k = 1 to tempcnt
set vertexdata diffuse k-1, MeshLimbVertInf(i,tempcurlimb2,k).color
next k
endif
endif
sync
unlock vertexdata
next j
else
meshInf(i).limbCnt = 0
meshInf(i).limbCnt2 = 0
endif
next i
endfunction
function Read_Lightmap( index )
array insert at bottom lightmapInf(0)
tempArryCnt = array count(lightmapInf(0))
lightmapInf(tempArryCnt).flags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
lightmapInf(tempArryCnt).resolution = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
tempLMres = (2^lightmapInf(tempArryCnt).resolution)
inc bytes_read, 1
lightmapInf(tempArryCnt).format = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
lightmapInf(tempArryCnt).imgNum = numImgs
inc numImgs, 1
make memblock 99, 12+ ((tempLMres * tempLMres)*4)
write memblock dword 99, 0, tempLMres
write memblock dword 99, 4, tempLMres
write memblock dword 99, 8, 32
pos99 = 12
for j = 1 to tempLMres
for k = 1 to tempLMres
write memblock byte 99, pos99+2, memblock byte(1, HeaderInfo.ObjectOffset+bytes_read+2)
write memblock byte 99, pos99+1, memblock byte(1, HeaderInfo.ObjectOffset+bytes_read+1)
write memblock byte 99, pos99, memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
write memblock byte 99, pos99+3, 255
inc bytes_read, 3
inc pos99, 4
next k
next j
make image from memblock lightmapInf(tempArryCnt).imgNum, 99
delete memblock 99
lightmapInf(tempArryCnt).Index = index
endfunction
function Gather_Brush_Stats()
`keep up with how many brushes there are
inc totalNumBrushs, 1
`read flags (if 4 && flags then brush is hidden)
tempbrushflags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
`get number of keys in brush
tempbrushkeys = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
`get the max num keys in any brush
if totalNumBrushs = 1
brushInf(0).MaxKeys = tempbrushkeys
else
if tempbrushkeys > brushInf(0).MaxKeys
brushInf(0).MaxKeys = tempbrushkeys
endif
endif
`skip keyname and value data for now
for j = 1 to tempbrushkeys
inc bytes_read, 8
next j
`skip group, visgroup, and color data for now
inc bytes_read, 11
`read number of verts in brush
tempbrushvertCnt = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
`get the max num verts in any brush
if totalNumBrushs = 1
brushInf(0).MaxVertCnt = tempbrushvertCnt
else
if tempbrushvertCnt > brushInf(0).MaxVertCnt
brushInf(0).MaxVertCnt = tempbrushvertCnt
endif
endif
`skip vert positions for now
for j = 1 to tempbrushvertCnt
inc bytes_read, 12
next j
`get number of faces in brush
tempbrushfaceCnt = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
`get the max num faces in any brush
if totalNumBrushs = 1
brushInf(0).MaxFaceCnt = tempbrushfaceCnt
else
if tempbrushfaceCnt > brushInf(0).MaxFaceCnt
brushInf(0).MaxFaceCnt = tempbrushfaceCnt
endif
endif
for j = 1 to tempbrushfaceCnt
`if 4 && faceflags then face is deleted
tempbrushFaceflags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 85
`if lightmapped skip lightmap index for now
if (16 && tempbrushFaceflags)
inc bytes_read, 4
endif
`get number of indices in brush
tempbrushFaceindiceCnt = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
`get max num indices in any brush
if totalNumBrushs = 1 and j = 1
brushInf(0).maxIndiceCnt = tempbrushFaceindiceCnt
else
if tempbrushFaceindiceCnt > brushInf(0).maxIndiceCnt
brushInf(0).maxIndiceCnt = tempbrushFaceindiceCnt
endif
endif
`skip vert number and texture coords for now
for k = 1 to tempbrushFaceindiceCnt
inc bytes_read, 9
`if it applies skip the lightmap coords for now
if (16 && tempbrushFaceflags)
inc bytes_read, 8
endif
next k
next j
endfunction
function Read_Brush( index )
array insert at bottom brushInf(0)
tempArryCnt = array count(brushInf(0))
brushInf(tempArryCnt).objNum = 0
brushInf(tempArryCnt).flags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
brushInf(tempArryCnt).keys = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
if tempArryCnt = 1
brushInf(0).MaxKeys = brushInf(tempArryCnt).keys
else
if brushInf(tempArryCnt).keys > brushInf(0).MaxKeys
brushInf(0).MaxKeys = brushInf(tempArryCnt).keys
endif
endif
for j = 1 to brushInf(tempArryCnt).keys
brushKeyInf(tempArryCnt,j).keyName = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushKeyInf(tempArryCnt,j).keyVal = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
next j
brushInf(tempArryCnt).groupInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
if brushInf(tempArryCnt).groupInd > 0
tempArryCnt2 = array count(groupInf(0))
for j = 1 to tempArryCnt2
if groupInf(j).Index = brushInf(tempArryCnt).groupInd
brushInf(tempArryCnt).realgroupInd = j
exit
endif
next j
endif
inc bytes_read, 4
brushInf(tempArryCnt).visgroupInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
if brushInf(tempArryCnt).visgroupInd > 0
tempArryCnt2 = array count(visgroupInf(0))
for j = 1 to tempArryCnt2
if visgroupInf(j).Index = brushInf(tempArryCnt).visgroupInd
brushInf(tempArryCnt).realvisgroupInd = j
exit
endif
next j
endif
inc bytes_read, 4
tempDwordName1 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
tempDwordName2 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read+1)
tempDwordName3 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read+2)
inc bytes_read, 3
tempDwordName = 255 << 24
tempDwordName = tempDwordName+(tempDwordName1 << 16)
tempDwordName = tempDwordName+(tempDwordName2 << 8)
tempDwordName = tempDwordName+tempDwordName3
brushInf(tempArryCnt).color = tempDwordName
brushInf(tempArryCnt).vertCnt = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
if tempArryCnt = 1
brushInf(0).MaxVertCnt = brushInf(tempArryCnt).vertCnt
else
if brushInf(tempArryCnt).vertCnt > brushInf(0).MaxVertCnt
brushInf(0).MaxVertCnt = brushInf(tempArryCnt).vertCnt
endif
endif
for j = 1 to brushInf(tempArryCnt).vertCnt
brushVertInf(tempArryCnt,j).vertPosX = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushVertInf(tempArryCnt,j).vertPosY = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushVertInf(tempArryCnt,j).vertPosZ = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
next j
brushInf(tempArryCnt).faceCnt = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
if tempArryCnt = 1
brushInf(0).MaxFaceCnt = brushInf(tempArryCnt).FaceCnt
else
if brushInf(tempArryCnt).FaceCnt > brushInf(0).MaxFaceCnt
brushInf(0).MaxFaceCnt = brushInf(tempArryCnt).FaceCnt
endif
endif
for j = 1 to brushInf(tempArryCnt).faceCnt
brushFaceInf(tempArryCnt,j).flags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
rem if 4 && flags = 4 then face is deleted
brushFaceInf(tempArryCnt,j).facex = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).facey = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).facez = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).faced = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).tex_posx = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).tex_posy = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).tex_scalex = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).tex_scaley = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).tex_rotx = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).tex_roty = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).planeU1 = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).planeU2 = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).planeU3 = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).planeU4 = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).planeV1 = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).planeV2 = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).planeV3 = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).planeV4 = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).luxel_size = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).SmoothGroupInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceInf(tempArryCnt,j).MaterialInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
if brushFaceInf(tempArryCnt,j).MaterialInd > 0
tempArryCnt2 = array count(materialInf(0))
for k = 1 to tempArryCnt2
if materialInf(k).Index = brushFaceInf(tempArryCnt,j).MaterialInd
brushFaceInf(tempArryCnt,j).realMaterialInd = k
exit
endif
next k
endif
inc bytes_read, 4
if (16 && brushFaceInf(tempArryCnt,j).flags)
brushFaceInf(tempArryCnt,j).LightmapInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
if brushFaceInf(tempArryCnt,j).LightmapInd > 0
tempArryCnt2 = array count(lightmapInf(0))
for k = 1 to tempArryCnt2
if lightmapInf(k).Index = brushFaceInf(tempArryCnt,j).LightmapInd
brushFaceInf(tempArryCnt,j).realLightmapInd = k
exit
endif
next k
endif
else
brushFaceInf(tempArryCnt,j).realLightmapInd = 0
endif
brushFaceInf(tempArryCnt,j).indiceCnt = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
if tempArryCnt = 1 and j = 1
brushInf(0).maxIndiceCnt = brushFaceInf(tempArryCnt,j).indiceCnt
else
if brushFaceInf(tempArryCnt,j).indiceCnt > brushInf(0).maxIndiceCnt
brushInf(0).maxIndiceCnt = brushFaceInf(tempArryCnt,j).indiceCnt
endif
endif
for k = 1 to brushFaceInf(tempArryCnt,j).indiceCnt
brushFaceIndInf(tempArryCnt,j,k).vertInd = (memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)+1)
inc bytes_read, 1
brushFaceIndInf(tempArryCnt,j,k).mainU = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceIndInf(tempArryCnt,j,k).mainV = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
if (16 && brushFaceInf(tempArryCnt,j).flags)
brushFaceIndInf(tempArryCnt,j,k).LightmapU = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
brushFaceIndInf(tempArryCnt,j,k).LightmapV = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
endif
next k
brushFaceInf(tempArryCnt,j).limbNum = -1
next j
brushInf(tempArryCnt).Index = index
endfunction
function create_brushes()
`cycle through each brush
dim tempVertHold(2)
tempArryCnt = array count(brushInf(0))
for i = 1 to tempArryCnt
FVF_FORM = 0
FVF_SIZE = 0
Brush_Mesh_Verts = 0
brushInf(i).objNum = numObjs
brush_trans = 0
inc numObjs, 1
templimbnum = 0
`hold materials for each limb dim for face count since there
`won't be more than one limb per face max
dim tempMatHold(brushInf(i).faceCnt, 2)
`sort the brush's faces into limbs of like materials
for j = 1 to brushInf(i).faceCnt
Brush_Vert_Num = (brushFaceInf(i,j).indiceCnt - 2)*3
`if face not deleted
if (4 && brushFaceInf(i,j).flags) = 0
if j = 1
`assign limb 0 and save materials for first face
if brushFaceInf(i,j).realLightmapInd > 0
tempMatHold(templimbnum, 0) = lightmapInf(brushFaceInf(i,j).realLightmapInd).imgNum
else
tempMatHold(templimbnum, 0) = 0
endif
tempMatHold(templimbnum, 1) = materialInf(brushFaceInf(i,j).realMaterialInd).imgNum
`keep track of number of verts per limb
tempMatHold(templimbnum, 2) = Brush_Vert_Num
brushFaceInf(i,j).limbNum = templimbnum
else
`for each other face check to see if it matches any other
`if so then assign it the same limb number else make new limb
if brushFaceInf(i,j).realLightmapInd > 0
tempLMind = lightmapInf(brushFaceInf(i,j).realLightmapInd).imgNum
else
tempLMind = 0
endif
tempMatind = materialInf(brushFaceInf(i,j).realMaterialInd).imgNum
testendlimbs = templimbnum
for k = 0 to testendlimbs
if tempMatHold(k, 0) = tempLMind and tempMatHold(k, 1) = tempMatind
brushFaceInf(i,j).limbNum = k
inc tempMatHold(k, 2), Brush_Vert_Num
exit
else
if k = testendlimbs
inc templimbnum, 1
tempMatHold(templimbnum, 0) = tempLMind
tempMatHold(templimbnum, 1) = tempMatind
brushFaceInf(i,j).limbNum = templimbnum
tempMatHold(templimbnum, 2) = Brush_Vert_Num
endif
endif
next k
endif
endif
next j
`write each limb's data into memblocks from the sorted info
for j = 0 to templimbnum
`stores the number of verts in the limb
Brush_Mesh_Verts = tempMatHold(j, 2)
`if any of the faces are lightmapped the whole object needs
`to have a second texture stage
for k = 1 to brushInf(i).faceCnt
if (16 && brushFaceInf(i,k).flags)
FVF_FORM = 514
FVF_SIZE = 28
exit
else
if k = brushInf(i).faceCnt
FVF_FORM = 274
FVF_SIZE = 32
endif
endif
next k
`write memblock header
make memblock 99, 12+(FVF_SIZE*Brush_Mesh_Verts)
write memblock dword 99, 0, FVF_FORM
write memblock dword 99, 4, FVF_SIZE
write memblock dword 99, 8, Brush_Mesh_Verts
`write vert data into the memblock to make mesh from
pos_mem = 12
`search each face to see if it belongs to the current limb if so write
`data from it, else skip it for now
for k = 1 to brushInf(i).faceCnt
`if face's limb number matches the current limb we are writing
if brushFaceInf(i,k).limbNum = j
`write the faces data in clockwise order, since 3dws uses CCW
`we have to reorder them backwards and since it uses face data
`we have to convert it to polygons with the fan method
for l = brushFaceInf(i,k).indiceCnt to 3 step -1
`set the 3 indexs for the current poly by fanning indices
tempVertHold(0) = 1
tempVertHold(1) = l
tempVertHold(2) = l-1
for m = 0 to 2
`Current Vert's data of the current polygon
currVertInd = brushFaceIndInf(i,k,tempVertHold(m)).vertInd
`write the vert's positions to the memblock
write memblock float 99, pos_mem, brushVertInf(i,currVertInd).vertPosX
inc pos_mem, 4
write memblock float 99, pos_mem, brushVertInf(i,currVertInd).vertPosY
inc pos_mem, 4
write memblock float 99, pos_mem, brushVertInf(i,currVertInd).vertPosZ
inc pos_mem, 4
`if it is not lightmapped skip the normals data for now and they will
`be created after object creation
if FVF_FORM = 274
write memblock float 99, pos_mem, 0.0
inc pos_mem, 4
write memblock float 99, pos_mem, 1.0
inc pos_mem, 4
write memblock float 99, pos_mem, 0.0
inc pos_mem, 4
`inc pos_mem, 12
endif
`write the main texture's UV data
write memblock float 99, pos_mem, brushFaceIndInf(i,k,tempVertHold(m)).mainU
inc pos_mem, 4
write memblock float 99, pos_mem, brushFaceIndInf(i,k,tempVertHold(m)).mainV
inc pos_mem, 4
`if lightmapped, write the lightmap textures UV data
if FVF_FORM = 514
write memblock float 99, pos_mem, brushFaceIndInf(i,k,tempVertHold(m)).LightmapU
inc pos_mem, 4
write memblock float 99, pos_mem, brushFaceIndInf(i,k,tempVertHold(m)).LightmapV
inc pos_mem, 4
endif
next m
next l
endif
next k
`make the mesh to become the limb
make mesh from memblock 99, 99
`make object for limb 0 and add limbs for the others
if j = 0
make object brushInf(i).objNum, 99, 0
else
add limb brushInf(i).objNum, j, 99
endif
`clean up mesh and memblock data when done with the current brush
delete mesh 99
delete memblock 99
next j
`texture limbs from sorted data
for j = 0 to templimbnum
if FVF_FORM = 514
texture limb brushInf(i).objNum, j, 1, tempMatHold(j, 0)
texture limb brushInf(i).objNum, j, 0, tempMatHold(j, 1)
else
texture limb brushInf(i).objNum, j, 0, tempMatHold(j, 1)
endif
if right$(limb texture name(brushInf(i).objNum, j, 0),3) = "tga"
if right$(limb texture name(brushInf(i).objNum, j, 0),14) = "antiportal.tga"
hide limb brushInf(i).objNum, j
else
brush_trans = 1
endif
if right$(limb texture name(brushInf(i).objNum, j, 0),10) = "portal.tga"
hide limb brushInf(i).objNum, j
else
brush_trans = 1
endif
if right$(limb texture name(brushInf(i).objNum, j, 0),14) = "portalzone.tga"
hide limb brushInf(i).objNum, j
else
brush_trans = 1
endif
endif
if tempMatHold(j, 1) = 0
hide limb brushInf(i).objNum, j
endif
if right$(limb texture name(brushInf(i).objNum, j, 0),9) = "caulk.bmp"
hide limb brushInf(i).objNum, j
endif
if right$(limb texture name(brushInf(i).objNum, j, 0),10) = "hitbox.bmp"
hide limb brushInf(i).objNum, j
endif
next j
`calculate normals for non-lightmapped models
if FVF_FORM = 274
set object normals brushInf(i).objNum
`turn off light and ambience for lightmapped objects and
`use the shader to blend the textures
else
set object light brushInf(i).objNum, 0
set object ambient brushInf(i).objNum, 0
set object effect brushInf(i).objNum, 1
endif
if brush_trans = 1
set object texture brushInf(i).objNum, 0, 0
set object transparency brushInf(i).objNum, 2
endif
`clean up sort data after each brush
undim tempMatHold(0)
next i
undim tempVertHold(0)
endfunction
function Read_Entity( index )
array insert at bottom entityInf(0)
tempArryCnt = array count(entityInf(0))
entityInf(tempArryCnt).flags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
entityInf(tempArryCnt).posX = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
entityInf(tempArryCnt).posY = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
entityInf(tempArryCnt).posZ = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
entityInf(tempArryCnt).keys = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
if tempArryCnt = 1
entityInf(0).MaxKeys = entityInf(tempArryCnt).keys
else
if entityInf(tempArryCnt).keys > entityInf(0).MaxKeys
entityInf(0).MaxKeys = entityInf(tempArryCnt).keys
endif
endif
dim entityKeyInf(tempArryCnt,entityInf(0).MaxKeys) as keysInf
for j = 1 to entityInf(tempArryCnt).keys
entityKeyInf(tempArryCnt,j).keyName = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
entityKeyInf(tempArryCnt,j).keyVal = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
next j
entityInf(tempArryCnt).groupInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
if entityInf(tempArryCnt).groupInd > 0
tempArryCnt2 = array count(groupInf(0))
for j = 1 to tempArryCnt2
if groupInf(j).Index = entityInf(tempArryCnt).groupInd
entityInf(tempArryCnt).realgroupInd = j
exit
endif
next j
endif
inc bytes_read, 4
entityInf(tempArryCnt).visgroupInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
if entityInf(tempArryCnt).visgroupInd > 0
tempArryCnt2 = array count(visgroupInf(0))
for j = 1 to tempArryCnt2
if visgroupInf(j).Index = entityInf(tempArryCnt).visgroupInd
entityInf(tempArryCnt).realvisgroupInd = j
exit
endif
next j
endif
inc bytes_read, 4
entityInf(tempArryCnt).Index = index
endfunction
function Gather_Terrain_Stats()
`keep up with total number of terrains
inc totalNumTerrains, 1
`read flags for color data skipping
tempterrainflags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 25
`get resolution
tempterrainresolution = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 16
`get number of layers in terrain
tempterrainlayerCnt = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
`get max num layers in any terrain
if totalNumTerrains = 1
terrainInf(0).maxLayerCnt = tempterrainlayerCnt
else
if tempterrainlayerCnt > terrainInf(0).maxLayerCnt
terrainInf(0).maxLayerCnt = tempterrainlayerCnt
endif
endif
`calc max resolution
temploopval = tempterrainresolution
`get max res of any terrain
if totalNumTerrains = 1
terrainInf(0).maxRes = temploopval
else
if temploopval > terrainInf(0).maxRes
terrainInf(0).maxRes = temploopval
endif
endif
`calc resolution_2
temploopval = tempterrainresolution^2
`if applicable skip color info
if (1 && tempterrainflags)
for j = 1 to temploopval
inc bytes_read, 3
next j
endif
`calc res1_2 value for terrain
temploopval = (tempterrainresolution+1)^2
`skip terrain height values for now
for j = 1 to temploopval
inc bytes_read, 4
next j
`skip layer and material indexs for now
for j = 1 to tempterrainlayerCnt
inc bytes_read, 8
if j > 1
`if applicable skip alpha of other layers
for k = 1 to tempterrainresolution^2
inc bytes_read, 1
next k
endif
next j
endfunction
function Read_Terrain( index )
array insert at bottom terrainInf(0)
tempArryCnt = array count(terrainInf(0))
terrainInf(tempArryCnt).flags = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 1
terrainInf(tempArryCnt).posX = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
terrainInf(tempArryCnt).posY = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
terrainInf(tempArryCnt).posZ = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
terrainInf(tempArryCnt).width = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
terrainInf(tempArryCnt).height = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
terrainInf(tempArryCnt).nameInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
terrainInf(tempArryCnt).resolution = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
terrainInf(tempArryCnt).sectors = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
terrainInf(tempArryCnt).detail_levels = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
terrainInf(tempArryCnt).lightmapRes = memblock float(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
terrainInf(tempArryCnt).layerCnt = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
temp_terr_tile_size# = terrainInf(tempArryCnt).width/terrainInf(tempArryCnt).resolution
for j = terrainInf(tempArryCnt).resolution to 1 step -1
for k = 1 to terrainInf(tempArryCnt).resolution
if (1 && terrainInf(tempArryCnt).flags)
tempDwordName1 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read)
tempDwordName2 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read+1)
tempDwordName3 = memblock byte(1, HeaderInfo.ObjectOffset+bytes_read+2)
inc bytes_read, 3
tempDwordName = (tempDwordName1 << 24)
tempDwordName = tempDwordName+(tempDwordName2 << 16)
tempDwordName = tempDwordName+(tempDwordName3 << 8)
`tempDwordName = (255 << 16)+(255 << 8)+(255)
else
tempDwordName = (255 << 16)+(255 << 8)+(255)
endif
terrainResColInf(tempArryCnt,k,j).color = tempDwordName
next k
next j
temploopval = terrainInf(tempArryCnt).resolution+1
for j = 1 to temploopval
for k = 1 to temploopval
terrainResHgtInf(tempArryCnt,j,k).height = (memblock float(1, HeaderInfo.ObjectOffset+bytes_read) * terrainInf(tempArryCnt).height)+terrainInf(tempArryCnt).posY
inc bytes_read, 4
terrainResHgtInf(tempArryCnt,j,k).xpos = (temp_terr_tile_size#*(j-1))+(terrainInf(tempArryCnt).posX-(terrainInf(tempArryCnt).width/2))
terrainResHgtInf(tempArryCnt,j,k).zpos = (temp_terr_tile_size#*(k-1))+(terrainInf(tempArryCnt).posZ-(terrainInf(tempArryCnt).width/2))
next k
next j
for j = 1 to terrainInf(tempArryCnt).layerCnt
terrainLayerInf(tempArryCnt,j).nameInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
terrainLayerInf(tempArryCnt,j).MaterialInd = memblock dword(1, HeaderInfo.ObjectOffset+bytes_read)
inc bytes_read, 4
if terrainLayerInf(tempArryCnt,j).MaterialInd > 0
tempArryCnt2 = array count(materialInf(0))
for k = 1 to tempArryCnt2
if materialInf(k).Index = terrainLayerInf(tempArryCnt,j).MaterialInd
terrainLayerInf(tempArryCnt,j).realMaterialInd = k
exit
endif
next k
endif
for k = 1 to terrainInf(tempArryCnt).resolution
for l = 1 to terrainInf(tempArryCnt).resolution
if j > 1
terrainLayerAlphaInf(tempArryCnt,j,l,k).alpha = (memblock byte(1, HeaderInfo.ObjectOffset+bytes_read) << 24)
inc bytes_read, 1
else
terrainLayerAlphaInf(tempArryCnt,j,l,k).alpha = (255 << 24)
endif
next l
next k
next j
terrainInf(tempArryCnt).Index = index
endfunction
function Create_Terrains()
`set default FVF data to 0 (can be left out)
FVF_FORM = 0
FVF_SIZE = 0
Terr_limb_Verts = 0
`create each terrain in the level
for i = 1 to totalNumTerrains
`if lightmapped use diffuse color
if (1 && terrainInf(i).flags)
FVF_FORM = 322
FVF_SIZE = 24
`else calculate and use normals
else
FVF_FORM = 338
FVF_SIZE = 36
endif
`calc the number of points wide of each sector
sector_points_size = (terrainInf(i).resolution/terrainInf(i).sectors)+1
`calc the number of limbs per layer
temp_layer_num_limbs = (terrainInf(i).sectors^2)
`calc the number of limbs in the terrain
temp_terr_num_limbs = temp_layer_num_limbs*terrainInf(i).layerCnt
`calc the number of verts per limb
Terr_limb_Verts = 6*((sector_points_size-1)^2)
`calc the base memblock size for each limb
temp_terr_memb_size = 12+(FVF_SIZE*Terr_limb_Verts)
`write headers for memblocks
make memblock 1, temp_terr_memb_size
write memblock dword 1, 0, FVF_FORM
write memblock dword 1, 4, FVF_SIZE
write memblock dword 1, 8, Terr_limb_Verts
curr_limb_num = 1
`create layers' limbs' data
for j = 1 to terrainInf(i).layerCnt
curr_terr_img_num = materialInf(terrainLayerInf(i,j).realMaterialInd).imgNum
`do rows second
for k = 1 to terrainInf(i).sectors
`do columns first
for l = 1 to terrainInf(i).sectors
`set the base memblock positions to 12 (after the headers)
memb_index_pos = 12
data_column_offset = ((sector_points_size-1)*(l-1))
data_row_offset = ((sector_points_size-1)*(k-1))
Terr_limb_Verts_wrote = 0
for m = data_row_offset+1 to (data_row_offset+sector_points_size)-1
for n = data_column_offset+1 to (data_column_offset+sector_points_size)-1
if terrainLayerAlphaInf(i,j,m,n).alpha > 0
`write vert's x,y,z positions
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m,n).xpos
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m,n).height
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m,n).zpos
inc memb_index_pos, 4
`skip vert's normals if not lightmapped (will calc later)
if FVF_FORM = 338
inc memb_index_pos, 12
endif
`write vert's diffuse color with alpha
write memblock dword 1, memb_index_pos, terrainResColInf(i,m,n).color+terrainLayerAlphaInf(i,j,m,n).alpha
inc memb_index_pos, 4
`write vert's UV data
write memblock float 1, memb_index_pos, Univ_UV_Hold( 0,0 )
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, Univ_UV_Hold( 0,1 )
inc memb_index_pos, 4
`write vert's x,y,z positions
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m,n+1).xpos
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m,n+1).height
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m,n+1).zpos
inc memb_index_pos, 4
`skip vert's normals if not lightmapped (will calc later)
if FVF_FORM = 338
inc memb_index_pos, 12
endif
`write vert's diffuse color with alpha
write memblock dword 1, memb_index_pos, terrainResColInf(i,m,n).color+terrainLayerAlphaInf(i,j,m,n).alpha
inc memb_index_pos, 4
`write vert's UV data
write memblock float 1, memb_index_pos, Univ_UV_Hold( 1,0 )
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, Univ_UV_Hold( 1,1 )
inc memb_index_pos, 4
`write vert's x,y,z positions
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m+1,n).xpos
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m+1,n).height
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m+1,n).zpos
inc memb_index_pos, 4
`skip vert's normals if not lightmapped (will calc later)
if FVF_FORM = 338
inc memb_index_pos, 12
endif
`write vert's diffuse color with alpha
write memblock dword 1, memb_index_pos, terrainResColInf(i,m,n).color+terrainLayerAlphaInf(i,j,m,n).alpha
inc memb_index_pos, 4
`write vert's UV data
write memblock float 1, memb_index_pos, Univ_UV_Hold( 3,0 )
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, Univ_UV_Hold( 3,1 )
inc memb_index_pos, 4
`write vert's x,y,z positions
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m,n+1).xpos
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m,n+1).height
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m,n+1).zpos
inc memb_index_pos, 4
`skip vert's normals if not lightmapped (will calc later)
if FVF_FORM = 338
inc memb_index_pos, 12
endif
`write vert's diffuse color with alpha
write memblock dword 1, memb_index_pos, terrainResColInf(i,m,n).color+terrainLayerAlphaInf(i,j,m,n).alpha
inc memb_index_pos, 4
`write vert's UV data
write memblock float 1, memb_index_pos, Univ_UV_Hold( 1,0 )
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, Univ_UV_Hold( 1,1 )
inc memb_index_pos, 4
`write vert's x,y,z positions
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m+1,n+1).xpos
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m+1,n+1).height
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m+1,n+1).zpos
inc memb_index_pos, 4
`skip vert's normals if not lightmapped (will calc later)
if FVF_FORM = 338
inc memb_index_pos, 12
endif
`write vert's diffuse color with alpha
write memblock dword 1, memb_index_pos, terrainResColInf(i,m,n).color+terrainLayerAlphaInf(i,j,m,n).alpha
inc memb_index_pos, 4
`write vert's UV data
write memblock float 1, memb_index_pos, Univ_UV_Hold( 2,0 )
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, Univ_UV_Hold( 2,1 )
inc memb_index_pos, 4
`write vert's x,y,z positions
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m+1,n).xpos
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m+1,n).height
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, terrainResHgtInf(i,m+1,n).zpos
inc memb_index_pos, 4
`skip vert's normals if not lightmapped (will calc later)
if FVF_FORM = 338
inc memb_index_pos, 12
endif
`write vert's diffuse color with alpha
write memblock dword 1, memb_index_pos, terrainResColInf(i,m,n).color+terrainLayerAlphaInf(i,j,m,n).alpha
inc memb_index_pos, 4
`write vert's UV data
write memblock float 1, memb_index_pos, Univ_UV_Hold( 3,0 )
inc memb_index_pos, 4
write memblock float 1, memb_index_pos, Univ_UV_Hold( 3,1 )
inc memb_index_pos, 4
inc Terr_limb_Verts_wrote, 6
endif
next n
next m
if Terr_limb_Verts_wrote > 0
temp_terr_memb2_size = 12+(FVF_SIZE*Terr_limb_Verts_wrote)
make memblock 2, temp_terr_memb2_size
write memblock dword 2, 0, FVF_FORM
write memblock dword 2, 4, FVF_SIZE
write memblock dword 2, 8, Terr_limb_Verts_wrote
copy memblock 1, 2, 12, 12, (temp_terr_memb2_size-12)
make mesh from memblock 1, 2
delete memblock 2
if curr_limb_num = 1
make object numObjs, 1, curr_terr_img_num
else
add limb numObjs, curr_limb_num-1, 1
texture limb numObjs, curr_limb_num-1, curr_terr_img_num
endif
`delete mesh used for limbs
delete mesh 1
inc curr_limb_num, 1
endif
next l
next k
next j
`delete memblock used for limbs
delete memblock 1
if FVF_FORM = 338
set object normals numObjs
else
set object light numObjs, 0
set object ambient numObjs, 0
endif
inc numObjs, 1
next i
endfunction
function Find_Material( filename$ )
if file exist( filename$+".bmp" ) = 1
ext$ = ".bmp"
else
if file exist( filename$+".jpg" ) = 1
ext$ = ".jpg"
else
if file exist( filename$+".png" ) = 1
ext$ = ".png"
else
if file exist( filename$+".tga" ) = 1
ext$ = ".tga"
else
if file exist( filename$+".dds" ) = 1
ext$ = ".dds"
else
ext$ = ""
endif
endif
endif
endif
endif
endfunction ext$
function Sort_Groups()
tempArryCnt = array count(groupInf(0))
for k = 1 to tempArryCnt
if groupInf(k).groupInd > 0
for j = 1 to tempArryCnt
if groupInf(j).Index = groupInf(k).groupInd
groupInf(k).realgroupInd = j
exit
endif
next j
endif
next k
endfunction
function Export_Lightmaps()
tempArryCnt = array count(lightmapInf(0))
for i = 1 to tempArryCnt
tempimgname$ = "test_LM"+str$(i)+".bmp"
if file exist(tempimgname$) = 1 then delete file tempimgname$
save image tempimgname$, lightmapInf(i).imgNum
next i
endfunction