I did it!
zoya_face_fbi.png
Maxscript code:
Code: Select all
--heapSize += 2000000000
fn LZ4_decompress input = (
local i = 0, j = 0, n = input.count, out = #(), l, token, literals_length, end, offset, match_length, pos
while i < n do (
token = input[i+=1]
literals_length = bit.shift token -4
if literals_length > 0 do (
l = literals_length + 240
while l == 255 do (
l = input[i+=1]
literals_length += l
)
end = i + literals_length
while i < end do out[j+=1] = input[i+=1]
)
if i < n-1 do (
offset = bit.or input[i+=1] (bit.shift input[i+=1] 8)
if not (offset == 0 or offset > j) do (
match_length = bit.and token 0xf
l = match_length + 240
while l == 255 and i<n do (
l = input[i+=1]
match_length += l
)
pos = j - offset
end = j + match_length + 4
while j < end do out[j+=1] = out[pos+=1]
)
)
)
out
)
fn convertTrine3Tex fbi = (
if fbi == undefined do return false
local u, f, magic, version, width, height, mip, floats, other, zsize, size, tmp, un, data
local dir = getfilenamepath fbi, file = getfilenamefile fbi
local dxt1 = 827611204, dxt3 = 861165636, dxt5 = 894720068, ati2 = 843666497
local dxt = #(dxt1, dxt5, dxt5 ,ati2)
f = fopen fbi "rb"
magic = readlong f
if magic != 4017 do return false
version = readshort f
if version > 4 do return false
staff = readshort f
width = readshort f
height = readshort f
mip = readbyte f
floats = [readfloat f, readfloat f, readfloat f, readfloat f]
other = [readshort f, readshort f]
zsize = readlong f
size = readlong f
if doesfileexist (dir + file + ".lz4") then (
tmp = fopen (dir + file + ".lz4") "rb"
un = for i=1 to size collect readbyte tmp #unsigned
fclose tmp
) else (
data = for i=1 to zsize collect readbyte f #unsigned
un = LZ4_decompress data
)
fclose f
gc()
u = fopen (dir + file + ".dds") "wb"
writelong u 542327876
writelong u 124
writelong u 135175
writelong u height
writelong u width
for i=1 to 2 do writelong u 0
writelong u mip
for i=1 to 11 do writelong u 0
writelong u 32
writelong u 4
writelong u dxt[version]
for i=1 to 5 do writelong u 0
writelong u 4198408
for i=1 to 4 do writelong u 0
local all =un.count, b, p = 0, q = 0, r = 0
case version of (
1: ( -- DXT1
b = all/4
for i=1 to all/8 do (
for j=0 to 1 do writebyte u un[i+j+p] #unsigned
for j=0 to 1 do writebyte u un[i+b+j+p] #unsigned
for j=0 to 3 do writebyte u un[i+b*2+j+q] #unsigned
p += 1
q += 3
)
)
2: ( -- DXT5
b = all/8
for i=1 to all/16 do (
writebyte u un[i] #unsigned
writebyte u un[i+b/2] #unsigned
for j=0 to 5 do writebyte u un[i+b+j+p] #unsigned
for j=0 to 1 do writebyte u un[i+b*4+j+q] #unsigned
for j=0 to 1 do writebyte u un[i+b*5+j+q] #unsigned
for j=0 to 3 do writebyte u un[i+b*6+j+r] #unsigned
p += 5
q += 1
r += 3
)
)
3: ( -- DXT5 - Alpha Only
b = all/8
for i=1 to all/8 do (
writebyte u un[i] #unsigned
writebyte u un[i+b] #unsigned
for j=0 to 5 do writebyte u un[i+b*2+j+p] #unsigned
for j=0 to 7 do writebyte u 255 #unsigned
p += 5
)
)
4: ( -- ATI2
b = all/16
for i=1 to all/16 do (
writebyte u un[i] #unsigned
writebyte u un[i+b] #unsigned
for j=0 to 5 do writebyte u un[i+b*2+j+p] #unsigned
writebyte u un[i+b*8] #unsigned
writebyte u un[i+b*9] #unsigned
for j=0 to 5 do writebyte u un[i+b*10+j+p] #unsigned
p += 5
)
)
default: for i in un do writebyte u i #unsigned
)
fclose u
)
convertTrine3Tex (getOpenFileName historyCategory:"Trine 3 Textures" types:"Trine 3 .fbi (*.fbi)")
/*
dir = getSavePath initialDir:@"d:\test\data\root\instance_base\entity\object\water\"
if dir != undefined and doesfileexist dir do (
files = getAllFiles dir #(".fbi")
for file in files do convertTrine3Tex file
)
*/
PS:
You can expect soon a script for importing Trine 3 .fbm models in 3D Studio Max. This is the reason to use this subforum
You do not have the required permissions to view the files attached to this post.