I'm trying to import the models from this game named "fengbao" into 3dsmax. I have written an MAXScript to import it but I'm failing at the indices / faces and vertices part.
Script:
Code: Select all
fn readStr binstr strLen = --reads a fixed-size string
(
str = ""
for w=1 to strLen do(str += (bit.intasChar(readByte binstr #unsigned)))
return str
)
fn clamp minVal maxVal val =
(
if val < minVal then val = minVal
else if val > maxVal then val = maxVal
return val
)
binfile = fopen "C:\\aoshan_bingshan.mesh" "rb"
version = readLong binfile
print version
subMeshNum = readLong binfile
fseek binfile 72 #seek_cur
subMeshNum = 1
for i = 0 to subMeshNum - 1 do(
smNameLen = readLong binfile #unsigned
smName = readStr binfile smNameLen
print(smName)
mtrlLen = readLong binfile #unsigned
mtrlPath = readStr binfile mtrlLen
print(mtrlPath)
m_isUseNormal = (readByte binfile == 1)
m_isUseVertexColor = (readByte binfile == 1)
m_isUseLightmapUV = (readByte binfile == 1)
m_isUseTangentBinormal = (readByte binfile == 1)
lightmapResolution = readLong binfile
lightmapResolution = clamp 8 12 lightmapResolution
fseek binfile 72 #seek_cur
vertCount = readLong binfile #unsigned
vertices = #()
for x = 0 to vertCount by 3 do (
f1 = readByte binfile
f3 = readByte binfile
f2 = readByte binfile
append vertices ([f1,f2,f3])
)
--readLong binfile #unsigned
faceCount = readLong binfile #unsigned
idxBuffSize = faceCount
indices = #()
for x = 0 to idxBuffSize by 3 do (
f1 = readByte binfile
f3 = readByte binfile
f2 = readByte binfile
append indices ([f1, f2, f3])
)
-- AABB
vMinX = readFloat binfile
vMinY = readFloat binfile
vMinZ = readFloat binfile
vMaxX = readFloat binfile
vMaxY = readFloat binfile
vMaxZ = readFloat binfile
submesh = mesh vertices:vertices faces:indices
)
I have no clue if the reading part of the indices and vertices is correct. If anything else is needed I'll supply everything thats needed. I have just barebone knowledge how vertices and indices work in this game they use vertex strides.
I've figured out that the vertex stride size is 48. Reading 4 floats for vertices does give some better output like so:
Code: Select all
for j = 0 to vertCount by 4 do (
x = readFloat binfile
y = readFloat binfile
z = readFloat binfile
unknown = readFloat binfile
append vertices ([x,y,z])
)
But messes up the indices...