Re: granny engine .gr2 question
Posted: Wed Dec 22, 2010 3:05 am
*BUMP*
I was having a problem getting GR2 files into 3dsmax, and the SMDs wouldnt import into the latest milkshape either. I tried to import the MS files into 3dsmax and some worked, and some didn't. problems were either out of memory, or a total crash of 3dsmax.
I created another script to import the MS files, seems to be easier on resources, as some outputed MS files from GRNReader were 50mb+
I suspect that was the reason behind max crashing. the script I made reads the outputed MS piece by piece, instead of trying to load 50MB into the interpreter at once O_o
I was having a problem getting GR2 files into 3dsmax, and the SMDs wouldnt import into the latest milkshape either. I tried to import the MS files into 3dsmax and some worked, and some didn't. problems were either out of memory, or a total crash of 3dsmax.
I created another script to import the MS files, seems to be easier on resources, as some outputed MS files from GRNReader were 50mb+
I suspect that was the reason behind max crashing. the script I made reads the outputed MS piece by piece, instead of trying to load 50MB into the interpreter at once O_o
Code: Select all
fsource = GetOpenFileName \
caption:"imports gr2.sm files" \
types: "GRN Reader MaxScript Dump(*gr2.ms)|*.MS|All files (*.*)|*.*|"
if (fsource!=undefined) AND ((doesFileExist fsource)==true) then(
f = fopen fsource "rb"
fext= getFilenameType fsource
fpath= getFilenamePath fsource
fbatch= getFiles (fpath+"*"+fext)
fname= getFilenameFile fsource
fsize= getFileSize fsource
st = timestamp() --get start time in milliseconds
clearlistener()
openLog (fpath+fname+"_log.txt") mode:"w" outputOnly:true
print (fname+fext+"\n"+localTime+"\n")
--===========================================================================
undo off(
fn ReadFixedString bstream fixedLen =
(
local str = ""
strON=true
floatnum=false
for i = 1 to fixedLen do (
if strON==true do(
str0=ReadByte bstream #unsigned
if str0==0x2E do floatnum=true
if str0==0x0D do (fseek bstream 1 #seek_cur)
-- if str0==0x2C do (fseek bstream -1 #seek_cur)
if str0==0x5D do (fseek bstream -1 #seek_cur)
if str0==0x5B do str0=0
if str0==0x20 OR str0==0x0D OR str0==0x2C OR str0==0x5D
then strON=false
else str += bit.intAsChar str0
))
if floatnum==true then (str as float) else (str as integer)
)
with redraw off (
offsetArray=#()
do (
byte1 = readbyte f#unsigned
if (byte1==0x66) then(
byte2 = readbyte f#unsigned
if (byte2==0x6E) then(
byte3 = readbyte f#unsigned
if (byte3==0x20) then(
byte4 = readbyte f#unsigned
if (byte4==0x63) then(
byte5 = readbyte f#unsigned
if (byte5==0x72) then(
byte6 = readbyte f#unsigned
if (byte6==0x65) then(
byte7 = readbyte f#unsigned
if (byte7==0x61) then(
byte8 = readbyte f#unsigned
if (byte8==0x74) then(
append offsetArray (ftell f+27)
skip=false
))))))))) while (ftell f)!=fsize
for x =1 to offsetArray.count do(
vertArray=#()
faceArray=#()
uvwArray=#()
fseek f offsetArray[x] #seek_set
vertCount=readFixedString f 8
fseek f 0x09 #seek_cur
faceCount=readFixedString f 8
fseek f 18 #seek_cur
vertCount=readFixedString f 8
fseek f 19 #seek_cur
for y = 1 to vertCount do(
fseek f 13 #seek_cur
idx=readFixedString f 8;fseek f 1 #seek_cur
vx=(readFixedString f 10)*100
vy=(readFixedString f 10)*100
vz=(readFixedString f 10)*100
fseek f 18 #seek_cur
idx=readFixedString f 8;fseek f 1 #seek_cur
tu=readFixedString f 10
tv=readFixedString f 10
tw=readFixedString f 10
fseek f 18 #seek_cur
idx=readFixedString f 8;fseek f 1 #seek_cur
nx=readFixedString f 10
ny=readFixedString f 10
nz=readFixedString f 10
append vertArray[vx,vz,vy]
append uvwArray[tu,tv,tw]
fseek f 3 #seek_cur
)
for y = 1 to faceCount do(
fseek f 13 #seek_cur
idx=readFixedString f 8;fseek f 1 #seek_cur
fa=readFixedString f 8
fb=readFixedString f 8
fc=readFixedString f 8
append faceArray[fc,fb,fa]
fseek f 3 #seek_cur
)
msh = mesh vertices:vertArray faces:faceArray
msh.numTVerts = vertArray.count
buildTVFaces msh
for j = 1 to vertArray.count do setTVert msh j uvwArray[j]
for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
)
--===========================================================================
Print ("Last Read @ 0x"+((bit.intAsHex(ftell f))as string))
gc()
fclose f
flushLog()
closeLog()
enableSceneRedraw()
Print ("Done! ("+((((timestamp())-st)/60)as string)+" Seconds)") --print time to finish
))) else (Print "Aborted.")