home *** CD-ROM | disk | FTP | other *** search
- if (heapSize < 20000000) then
- heapSize = 200000000
- fname = getOpenFileName \
- caption:"Open .Mesh from Mesh folder" \
- types:"TwelveSky 2 Model (*.dat)|*.dat" \
- historyCategory:"TwelveSky_2_ModelObjectPresets"
- f = fopen fname "rb"
-
- clearlistener()
-
- fn readBElong fstream = (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3)
-
- fn ReadBEshort fstream = (
- return (bit.swapBytes (readshort fstream #unsigned) 1 2)
- )
-
- fn readBEfloat fstream = (bit.intAsFloat (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3))
-
- fn ReadBEword fstream = (
- return (bit.swapBytes (readshort fstream #unsigned) 1 2)
- )
-
- fn ReadBEHalfFloat fstream =
- (
- hf=readBEword fstream
- sign = bit.get hf 16
- exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
- fraction = bit.and hf (bit.hexasint "03FF")
- if sign==true then sign = 1 else sign = 0
- exponentF = exponent + 127
- outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
- (bit.shift exponentF 23)) (bit.shift sign 31)
- return bit.intasfloat outputasfloat*2
- )
-
- fn readHalfFloat fstream = (
- hf=readshort fstream #unsigned
- sign = bit.get hf 16
- exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
- fraction = bit.and hf (bit.hexasint "03FF")
- if sign==true then sign = 1 else sign = 0
- exponentF = exponent + 127
- outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
- (bit.shift exponentF 23)) (bit.shift sign 31)
- return bit.intasfloat outputasfloat*2
- )
-
- fn readFixedString bstream fixedLen = (
- local str = ""
- for i = 1 to fixedLen do (
- str += bit.intAsChar (ReadByte bstream #unsigned))
- str
- )
- fn ReadFixedString2 bstream fixedLen =
- (
- local str = ""
- for i = 1 to fixedLen do
- (
- str0 = ReadByte bstream #unsigned
- if str0!=0x0 AND str0!=0x0 do str+= bit.intAsChar str0
- )
- str
- )
- struct weight_data
- (
- boneids,weights
- )
- clearlistener()
-
- filename=filenameFromPath fname
-
- filename2=getFilenameFile filename
-
- print ("This is FileName "+filename2)
-
- vertArray=#()
- faceArray =#()
- UV_array=#()
- Weight_array=#()
-
- fseek f (120) #seek_set
-
- VertexCount=readlong f
- WeightCount=readlong f
- UnkCount=readlong f
- FaceCount=readlong f
-
- Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell f))as string))
-
- fseek f (0x28) #seek_cur
-
- for x =1 to VertexCount do (
-
- getPos = ftell f + 32
-
- vx=(readfloat f)
- vy=(readfloat f)
- vz=(readfloat f)
-
- fseek f (12) #seek_cur
-
- tu=readFloat f
- tv=readFloat f*-1
-
- fseek f getPos #seek_set
- append vertArray ([(vx),(vz),(vy)])
- append UV_array [tu,(tv),0]
- )
-
- for x =1 to WeightCount do (
- getPos = ftell f + 32
- fseek f getPos #seek_set
- )
-
- Print ("Face Start @ 0x"+((bit.intAsHex(ftell f))as string))
-
- for y = 1 to FaceCount do ( --Faces
- fa=(readshort f #unsigned+ 1)
- fb=(readshort f #unsigned+ 1)
- fc=(readshort f #unsigned+ 1)
- append faceArray [fc,fb,fa]
- )
-
- Print ("Face End @ 0x"+((bit.intAsHex(ftell f))as string))
-
- msh = mesh vertices:vertArray faces:faceArray
- msh.name=filename2
-
- msh.numTVerts = UV_array.count
- buildTVFaces msh
- for j = 1 to UV_array.count do setTVert msh j UV_array[j]
- for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
-
- fclose f