home *** CD-ROM | disk | FTP | other *** search
- if (heapSize < 200000) then
- heapSize = 2000000 -- allow ~ 40 MB instead of just 7.5 MB. Prevents "Runtime Error: Out of scripter memory"
- gname = getOpenFileName \
- caption:"Open .mesh from FEAR MMO Model folder" \
- types:"F.E.A.R 1 Model (*.model00p)|*.model00p" \
- historyCategory:"F1ObjectPresets"
- g = fopen gname "rb"
-
- clearlistener()
-
- fn ReadHalfFloat fstream =
- (
- hf=readshort 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 readFixedString bstream fixedLen = (
- local str = ""
- for i = 1 to fixedLen do (
- str += bit.intAsChar (ReadByte bstream #unsigned))
- str
- )
-
- struct weight_data
- (
- boneids,weights
- )
-
- struct Mesh_Info
- (
- VertPos,VertCount,VertSize,FacePos,FaceCount,BoneMapCount,UnkId,Null,Null2
- )
-
- clearlistener()
-
- fseek g 0x14 #seek_set
- AnimOrMesh=readlong g
- if AnimOrMesh!=0 then (
- tarr = #()
- rarr = #()
- Barr = #()
- BPArr = #()
-
- fseek g 0x8 #seek_set
- DataSizeFirst=readlong g
- CAfterBones=readlong g
- BoneCount=readlong g
- LODCountUnk=readlong g
- MatCountUnk=readlong g
- MeshCount=readlong g
- fseek g 0x24 #seek_set
- LODCount=readlong g
- BoneHashCount=readlong g
- StringSize=readlong g
- AfterMatCount=readlong g
- MatCount=readlong g
- fseek g 0x54 #seek_set
- LongSecCount=readlong g
- SecStride=readlong g
- fseek g (0x60) #seek_set
-
- Print ("Strings Start @ 0x"+((bit.intAsHex(ftell g))as string))
-
- BoneOrderNameArray=#()
-
- while ftell g<(0x60+StringSize) do (
- BoneOrderName=readstring g
- if BoneOrderName!="" then append BoneOrderNameArray BoneOrderName
- )
-
- fseek g (0x5C+StringSize) #seek_set
-
- for i=1 to LongSecCount do (
- readlong g
- )
-
- Print ("Bone Start @ 0x"+((bit.intAsHex(ftell g))as string))
-
- for i=1 to BoneCount do (
-
- BoneNameOff=readlong g
- PosName=ftell g
- fseek g (0x5C+BoneNameOff) #seek_set
- BoneName=readstring g
- fseek g (PosName) #seek_set
- BoneId=readshort g
- readbyte g
-
- c11 = ReadFloat g; c12 = ReadFloat g; c13 = ReadFloat g; c14 = ReadFloat g
- c21 = ReadFloat g; c22 = ReadFloat g; c23 = ReadFloat g
-
- BoneParent=readlong g
-
- tfm = (quat c11 c12 c13 c14) as matrix3
- bvx=c11
- bvy=c12
- bvz=c13
-
- append tarr [bvx,bvy,bvz]
- append rarr tfm
- append Barr BoneName
- append BPArr BoneParent
- )
-
- BNArr = #()
- for i = 1 to BoneCount Do (
- if isvalidnode (getNodeByName Barr[i]) != true then (
- tfm = rarr[i]
- tfm.row4 = tarr[i]
- newBone = bonesys.createbone \
- tfm.row4 \
- (tfm.row4 + 0.01 * (normalize tfm.row1)) \
- (normalize tfm.row3)
- newBone.name = Barr[i]
- newBone.width = 0.01
- newBone.height = 0.01
- newBone.transform = tfm
- newBone.setBoneEnable false 0
- newBone.wirecolor = yellow
- newbone.showlinks = true
- newBone.pos.controller = TCB_position ()
- newBone.rotation.controller = TCB_rotation ()
- if BNArr.count > 0 then (
- newBone.parent = BNArr[BNArr.count]
- deleteitem BNArr BNArr.count
- )
- )
- if isvalidnode (getNodeByName Barr[i]) == true then (
- newBone = getNodeByName Barr[i]
- )
- for j = 1 to BPArr[i] do append BNArr newBone
- )
-
- Print ("Bone End @ 0x"+((bit.intAsHex(ftell g))as string))
-
- rootRT = bone name:"Main_Root" boxsize:[5.0,5.0,5.0]
- boneMain= getnodebyname Barr[1]
- boneMain.parent = rootRT
- rootRT.transform = (matrix3 [-1,0,0] [0,0,1] [0,-1,0] [0,0,0])
-
-
- FearBone=#()
- FearBoneOrder=#()
- FearHelper=BoneOrderNameArray
- FearHelper2=Barr
- for i=1 to BoneOrderNameArray.count do (
- for a=1 to BoneCount do (
- if FearHelper[i]==FearHelper2[a] then append FearBoneOrder i
- )
- )
-
- for i=1 to BoneCount do (
- FearBones=getnodebyname BoneOrderNameArray[(FearBoneOrder[i])]
- append FearBone FearBones
- )
-
- Unk=readlong g
- for i=1 to BoneHashCount do (
- SecNextBones=readshort g
- SecNextBones2=readshort g
- for i=1 to BoneCount do (
- readlong g
- )
- )
-
- Print ("Bones Count Long End @ 0x"+((bit.intAsHex(ftell g))as string))
-
- fseek g ((SecStride)) #seek_cur
-
- Print ("After Bones Section Start @ 0x"+((bit.intAsHex(ftell g))as string))
-
- for i=1 to (CAfterBones) do (
- fseek g (0x24) #seek_cur
- Count8=readlong g
- for i=1 to Count8 do (
- fseek g (0x8) #seek_cur
- )
- )
-
- Print ("After Bones Section End @ 0x"+((bit.intAsHex(ftell g))as string))
-
- Count2=readlong g
- for i=1 to Count2 do (
- UnkOff=readlong g
- BoneCount2=readlong g
- for i=1 to BoneCount2 do (
- readlong g
- )
- print UnkOff
- )
-
- Print ("After Bones Section 2 End @ 0x"+((bit.intAsHex(ftell g))as string))
-
- Count3=readlong g
- for i=1 to Count3 do (
- fseek g (0x28) #seek_cur
- )
-
- Print ("After Bones Section 3 End @ 0x"+((bit.intAsHex(ftell g))as string))
-
- MeshNameArray=#()
- MeshNameCount=readlong g
- for i=1 to MeshNameCount-1 do (
- MeshNameSize=readshort g
- MeshName=readFixedString g MeshNameSize
- print MeshName
- append MeshNameArray MeshName
- )
-
- Print ("Mesh Name End @ 0x"+((bit.intAsHex(ftell g))as string))
-
- readbyte g
- CountAfter=readlong g
- for i=1 to CountAfter do (
- readlong g
- )
-
- for i=1 to MatCount do (
- fseek g (0x29) #seek_cur
- Check7=readlong g
- if Check7==7 then fseek g (0x24) #seek_cur
- if Check7==6 then (
- CountL=readlong g
- Check7_1=readlong g
- if Check7_1==7 then fseek g (0x24) #seek_cur
- if Check7_1==5 then (
- fseek g (0x1C) #seek_cur
- )
- if Check7_1==3 then (
- fseek g (0xC) #seek_cur
- )
- if Check7_1==2 then (
- fseek g (0x18) #seek_cur
- )
- ----------------------
- for i=1 to CountL do (
- Check7_2=readlong g
- if Check7_2==7 then fseek g (0x24) #seek_cur
- if Check7_2==5 then (
- fseek g (0x1C) #seek_cur
- )
- if Check7_2==3 then (
- fseek g (0xC) #seek_cur
- )
- if Check7_2==2 then (
- fseek g (0x18) #seek_cur
- )
- )
- ----------------------
- )
- if Check7==5 then (
- fseek g (0x1C) #seek_cur
- )
- if Check7==3 then (
- fseek g (0xC) #seek_cur
- )
- if Check7==2 then (
- fseek g (0x18) #seek_cur
- )
- )
-
- Print ("!!!!! @ 0x"+((bit.intAsHex(ftell g))as string))
-
- MCount=readlong g
- if MCount!=0 then
- for i=1 to MCount do (
- IdSize1=readlong g
- IdSize2=readlong g
- IdSize3=readlong g
- if IdSize1==3 then fseek g (0x54) #seek_cur
- if IdSize1==4 then fseek g (0x64) #seek_cur
- )
- if MCount==0 then fseek g (0x8) #seek_cur
-
-
- Print ("00 @ 0x"+((bit.intAsHex(ftell g))as string))
-
- SecIdCount=readlong g
- for i=1 to SecIdCount do (
- Print ("Mat Section Position! @ 0x"+((bit.intAsHex(ftell g))as string))
- fseek g (0x67) #seek_cur
- Short01Pos=ftell g
- Short01=readlong g
- if Short01==1 then fseek g (0x56) #seek_cur
- if Short01!=1 then fseek g (Short01Pos) #seek_set
- )
-
- Print ("01 @ 0x"+((bit.intAsHex(ftell g))as string))
-
- CountNew=readlong g
- for i=1 to CountNew do (
- UnkOff_00=readlong g
- CountData=readlong g
- readshort g
- for i=1 to CountData do (
- UnkCount=readlong g
- UnkID=readbyte g
- DataCount=readlong g
- -- print (DataCount as string)
- for i=1 to DataCount do (
- ModelNumber=readlong g
- NullPos=ftell g
- Null=readshort g
- if Null==0 then fseek g (0x0) #seek_cur
- if Null!=0 then fseek g (NullPos) #seek_set
- print (ModelNumber as string)
- )
- )
- )
-
- Print ("!!!!!!! @ 0x"+((bit.intAsHex(ftell g))as string))
-
- fseek g 0xC #seek_cur
-
- LODCount=2
- for a=1 to LODCount do (
-
- vertArray = #()
- faceArray = #()
- UV_array = #()
- Weight_array=#()
-
- UnkMeshType=readlong g
- MeshCount=readlong g
- VertId=readlong g
- VertexSecSize=readlong g
- FaceSecSize=readlong g
-
- VertexStartPos=ftell g
-
- fseek g (VertexSecSize) #seek_cur
-
- Print ("Vertex Section End @ 0x"+((bit.intAsHex(ftell g))as string))
-
- FaceStartPos=ftell g
- fseek g (FaceSecSize) #seek_cur
-
- Print ("Face Section End @ 0x"+((bit.intAsHex(ftell g))as string))
-
- CountDataSec=readlong g
-
- for i=1 to CountDataSec do (
- DataSize=readlong g
- fseek g (DataSize) #seek_cur
- )
-
- Print ("Info Start @ 0x"+((bit.intAsHex(ftell g))as string))
-
- SubCount=readlong g
-
- Mesh_Info_Array=#()
- BoneMapPosArray=#()
- for i=1 to SubCount do (
- BoneMapPos=ftell g
- append BoneMapPosArray BoneMapPos
- VertPos=readlong g
- VertCount=readlong g
- VertSize=readlong g
- FacePos=readlong g
- Null=readlong g
- FaceCount=readlong g
- UnkId=readlong g
- BoneMapCount=readlong g
- Null2=readlong g
- for a=1 to BoneMapCount do (
- BoneMapId=readbyte g#usigned
- )
- append Mesh_Info_Array (Mesh_Info VertPos:VertPos VertCount:VertCount VertSize:VertSize FacePos:FacePos FaceCount:FaceCount BoneMapCount:BoneMapCount UnkId:UnkId Null:Null Null2:Null2)
- )
-
- print Mesh_Info_Array
- print BoneMapPosArray
-
- Print ("Info End @ 0x"+((bit.intAsHex(ftell g))as string))
-
- for i=1 to SubCount do (
-
- vertArray = #()
- faceArray = #()
- UV_array = #()
- Normal_Array=#()
- Weight_array=#()
-
- BMapPos=BoneMapPosArray[i]
-
- fseek g (BMapPos+28) #seek_set
-
- Print ("BMap Start @ 0x"+((bit.intAsHex(ftell g))as string))
-
- BoneMapArray=#()
- BoneMapCount02=readlong g
- Null02=readlong g
- for a=1 to BoneMapCount02 do (
- BoneMapId02=readbyte g#usigned
- append BoneMapArray (BoneMapID02+1)
- )
-
- fseek g (VertexStartPos) #seek_set
-
- Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell g))as string))
-
- if a==1 then
- if Mesh_Info_Array[i].VertSize==64 then
- for x =1 to (Mesh_Info_Array[i].VertCount) do (
- getPos = ftell g + Mesh_Info_Array[i].VertSize
-
- vx = ReadFloat g
- vy = ReadFloat g
- vz = ReadFloat g
-
- fseek g 12 #seek_cur
-
- tu = ReadFloat g
- tv = ReadFloat g*-1
-
- fseek g 24 #seek_cur
-
- weight3 = readbyte g #unsigned
- weight2 = readbyte g #unsigned
- weight1 = readbyte g #unsigned
- weight4 =readbyte g #unsigned
-
- bone1 = readbyte g #unsigned
- bone2 = readbyte g #unsigned
- bone3 = readbyte g #unsigned
- bone4 = readbyte g #unsigned
-
- w = (weight_data boneids:#() weights:#())
- maxweight = 0
- if(weight1 != 0) then
- maxweight = maxweight + weight1
- if(weight2 != 0) then
- maxweight = maxweight + weight2
- if(weight3 != 0) then
- maxweight = maxweight + weight3
- if(weight4 != 0) then
- maxweight = maxweight + weight4
-
- if(maxweight != 0) then (
- if(weight1 != 0) then (
- w1 = weight1 as float
- append w.boneids (bone1 + 1)
- append w.weights (w1 / 255.0)
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2 / 255.0)
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3 / 255.0)
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4 / 255.0)
- )
- )
- append Weight_array w
- fseek g getPos #seek_set
- append vertArray ([-vx,-vz,vy])
- append UV_Array [tu,tv,0]
- )
-
- if a!=1 then
- if Mesh_Info_Array[i].VertSize==64 then
- for x =1 to (Mesh_Info_Array[i].VertCount) do (
- getPos = ftell g + Mesh_Info_Array[i].VertSize
-
- vx = ReadFloat g
- vy = ReadFloat g
- vz = ReadFloat g
-
- nx = ReadFloat g
- ny = ReadFloat g
- nz = ReadFloat g
-
- fseek g 0x10 #seek_cur
-
- weight3 = readbyte g #unsigned
- weight2 = readbyte g #unsigned
- weight1 = readbyte g #unsigned
- weight4 =readbyte g #unsigned
-
- fseek g 0x8 #seek_cur
-
- bone1 = readbyte g #unsigned
- bone2 = readbyte g #unsigned
- bone3 = readbyte g #unsigned
- bone4 = readbyte g #unsigned
-
- w = (weight_data boneids:#() weights:#())
- maxweight = 0
- if(weight1 != 0) then
- maxweight = maxweight + weight1
- if(weight2 != 0) then
- maxweight = maxweight + weight2
- if(weight3 != 0) then
- maxweight = maxweight + weight3
- if(weight4 != 0) then
- maxweight = maxweight + weight4
-
- if(maxweight != 0) then (
- if(weight1 != 0) then (
- w1 = weight1 as float
- append w.boneids (bone1 + 1)
- append w.weights (w1 / 255.0)
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2 / 255.0)
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3 / 255.0)
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4 / 255.0)
- )
- )
- append Weight_array w
- fseek g getPos #seek_set
- append vertArray ([-vx,-vz,vy])
- append Normal_Array [-nx,-nz,ny]
- append UV_Array ([0,0,0])
- )
-
- if Mesh_Info_Array[i].VertSize==32 then
- for x =1 to (Mesh_Info_Array[i].VertCount) do (
- getPos = ftell g + Mesh_Info_Array[i].VertSize
-
- vx = ReadFloat g
- vy = ReadFloat g
- vz = ReadFloat g
-
- tu = ReadFloat g
- tv = ReadFloat g*-1
-
- fseek g getPos #seek_set
- append vertArray ([-vx,-vz,vy])
- append UV_Array [0,0,0]
- )
-
- VertexStartPos+=(Mesh_Info_Array[i].VertCount*Mesh_Info_Array[i].VertSize)
-
- fseek g (FaceStartPos+(Mesh_Info_Array[i].FacePos*2)) #seek_set
-
- Print ("FaceStart @ 0x"+((bit.intAsHex(ftell g))as string))
-
- for x = 1 to Mesh_Info_Array[i].FaceCount do (
- fa=(readshort g #unsigned+ 1)-Mesh_Info_Array[i].VertPos
- fb=(readshort g #unsigned+ 1)-Mesh_Info_Array[i].VertPos
- fc=(readshort g #unsigned+ 1)-Mesh_Info_Array[i].VertPos
- append faceArray [fc,fb,fa]
- )
-
- if vertArray.count!=0 then
- Try(
- msh = mesh vertices:vertArray faces:faceArray
- if a==1 then msh.name="F.E.A.R 1 Model "+ i as string
- if a!=1 then (
- msh.name="F.E.A.R 1 Shadow-Mesh "+ i as string
- for j = 1 to Normal_Array.count do setNormal msh j Normal_Array[j]
- )
- 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]
-
- max modify mode
- select msh
- skinMod = skin ()
- addModifier msh skinMod
- for i = 1 to BoneMapCount02 do
- (
- maxbone = FearBone[(BoneMapArray[i])]
- if i != BoneMapCount02 then
- skinOps.addBone skinMod maxbone 0
- else
- skinOps.addBone skinMod maxbone 1
- )
- modPanel.setCurrentObject skinMod
- for i = 1 to Weight_array.count do (
- w = Weight_array[i]
- bi = #() --bone index array
- wv = #() --weight value array
-
- for j = 1 to w.boneids.count do
- (
- boneid = w.boneids[j]
- weight = w.weights[j]
- append bi boneid
- append wv weight
- )
-
- skinOps.ReplaceVertexWeights skinMod i bi wv
- )
- )catch(format "Wrong Skel or Messed Bones!!\n")
- )
-
- CountDataSec2=readlong g
-
- for i=1 to CountDataSec2 do (
- DataSize2=readlong g
- fseek g (DataSize2) #seek_cur
- )
-
- SubCount2=readlong g
-
- for i=1 to SubCount2 do (
- getPos = ftell g + 28
- fseek g getPos #seek_set
- BoneMapCount2=readlong g
- Null3=readlong g
- for a=1 to BoneMapCount2 do (
- BoneMapId2=readbyte g#usigned
- )
- )
- Print ("MeshEnd @ 0x"+((bit.intAsHex(ftell g))as string))
- )
- fclose g
- )
- if AnimOrMesh==0 then fclose g