home *** CD-ROM | disk | FTP | other *** search
Text File | 2014-03-24 | 33.4 KB | 1,357 lines |
- if (heapSize < 200000) then
- heapSize = 2000000 -- allow ~ 40 MB instead of just 7.5 MB. Prevents "Runtime Error: Out of scripter memory"
-
- fname = getOpenFileName \
- caption:"Open .mod from Mesh folder" \
- types:"Sengoku Basara 4 (*.mod)|*.mod" \
- historyCategory:"SB_4ObjectPresets"
- f = fopen fname "rb"
-
- clearlistener()
-
- fn readBElong fstream = (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3)
-
- fn readBEword fstream = (
- short = readshort fstream #unsigned
- short = bit.swapBytes short 1 2
- return short
- )
-
- fn readBEfloat fstream = (bit.intAsFloat (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3))
-
- 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 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_Struct
- (
- VertCount, VSize,VId,VId2,VType, FacePos, FaceCount,VStart
- )
-
- clearlistener()
-
- fseek f 0x6 #seek_set
- BoneCount = ReadBEword f
- meshcount = ReadBEword f
- fseek f 0xc #seek_set
- VertexCount = ReadBElong f --12
- fseek f 0x18 #seek_set
- VertSize = ReadBElong f --24
- Long05 = ReadBElong f --28
- Long06 = ReadBElong f --32
- BoneOff = ReadBElong f --36
- print (meshcount as string)
- matcount2 = ReadBEword f
- fseek f 0x30 #seek_set
- itemoff = readBElong f
- print (itemoff as string)
- fseek f 0x34 #seek_set
- vertOffset = readBElong f
- print (vertOffset as string)
- faceOffset = readBElong f
- fileEnd = readBElong f
- print (faceOffset as string)
-
- fseek f BoneOff #seek_set
- BNArr = #()
- BoneParent = #()
- for a = 1 to BoneCount Do (
- boneid = readbyte f#unsigned
- append BoneParent (readbyte f#unsigned)
- childid = readbyte f#unsigned
- unkid = readbyte f#unsigned
- floata = ReadBEfloat f
- floatb = ReadBEfloat f
- bonex = ReadBEfloat f
- boney = ReadBEfloat f
- bonez = ReadBEfloat f
- )
-
- for a = 1 to BoneCount do (
- getPos = ftell f + 64
- fseek f getPos #seek_set
- )
-
- for a = 1 to BoneCount do (
-
- c11 = ReadBEfloat f; c12 = ReadBEfloat f; c13 = ReadBEfloat f; c14 = ReadBEfloat f
- c21 = ReadBEfloat f; c22 = ReadBEfloat f; c23 = ReadBEfloat f; c24 = ReadBEfloat f
- c31 = ReadBEfloat f; c32 = ReadBEfloat f; c33 = ReadBEfloat f; c34 = ReadBEfloat f
- c41 = ReadBEfloat f; c42 = ReadBEfloat f; c43 = ReadBEfloat f; c44 = ReadBEfloat f
-
- tfm = matrix3 [c11,c12,c13] [c21,c22,c23] [c31,c32,c33] ([c41,c42,c43]*100)
-
- newBone = bonesys.createbone \
- tfm.row4 \
- (tfm.row4 + 0.01 * (normalize tfm.row1)) \
- (normalize tfm.row3)
- newBone.name = (a as string)
- newBone.width = 0.01
- newBone.height = 0.01
- newBone.transform = inverse tfm
- newBone.setBoneEnable false 0
- newBone.wirecolor = white
- newbone.showlinks = true
- newBone.pos.controller = TCB_position ()
- newBone.rotation.controller = TCB_rotation ()
- if (BoneParent[a] != -1) then
- newBone.parent = BNArr[(BoneParent[a])+1]
- append BNArr newBone
- )
-
- Print ("Last Read @ 0x"+((bit.intAsHex(ftell f))as string))
-
- Mesh_Info=#()
-
- fseek f itemoff #seek_set
-
- for i = 1 to meshcount do (
- getPos = ftell f + 56
- unk1 = ReadBEword f
- VertCount = ReadBEword f
- unk2 = readBElong f
- VId2 = readbyte f #unsigned
- VId = readbyte f #unsigned
- VSize = readbyte f
- VType = readbyte f
- null = ReadBEword f
- unk4 = readbyte f
- unk5 = readBElong f
- unk6 = readBElong f
- unk7 = readbyte f
- FacePos = readBElong f
- FaceCount = readBElong f
- Null01 = ReadBElong f
- bone0 = ReadBEword f+1
- MeshtID = ReadBEword f
- VStart = ReadBEword f
- VEnd = ReadBEword f
- Mshj = ReadBElong f
- Null02 = ReadBElong f
- Null03 = ReadBElong f
- append Mesh_Info (Mesh_Info_Struct VertCount:VertCount VSize:VSize VId:VId VId2:VId2 VType:VType FacePos:FacePos FaceCount:FaceCount VStart:VStart )
- fseek f getPos #seek_set
- )
-
- Print ("Item Off End Read @ 0x"+((bit.intAsHex(ftell f))as string))
-
- print Mesh_Info
-
- fseek f vertOffset #seek_set
-
- for i = 1 to meshcount do (
-
- vertArray=#()
- faceArray=#()
- UV_array=#()
- Weight_array=#()
-
- if (Mesh_Info[i].VSize)==12 do
- for x = 1 to Mesh_Info[i].VertCount do (
- Bone3 = -1
- Bone4 = -1
- weight3 = 0
- weight4 = 0
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
-
- Bone1 = readbyte f #unsigned
- Bone2 = readbyte f #unsigned
-
- weight1 = 0
- weight2 = 1.00
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
-
- 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 )
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2 )
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3 )
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4 )
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==16 do
- for x = 1 to Mesh_Info[i].VertCount do (
- Bone3 = -1
- Bone4 = -1
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
- weight1 = (ReadBEword f /32767.00)
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
- unk2 = (readbyte f #unsigned/255.00)
- Bone1 = readbyte f #unsigned
- unk3 = (readbyte f #unsigned/255.00)
- Bone2 = readbyte f #unsigned
-
- if weight1!=1.00 then
- weight2 = (1.00 - weight1)
- weight4 = 0
-
- if weight1==1.00 then
- weight2 = 0
- weight3 = 0
-
- 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 )
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2 )
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3 )
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4 )
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==20 then
- if (Mesh_Info[i].VType)==16 do
- for x = 1 to Mesh_Info[i].VertCount do (
- Bone3 = -1
- Bone4 = -1
- weight3 = 0
- weight4 = 0
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
-
- Bone1 = readbyte f #unsigned
- Bone2 = readbyte f #unsigned
-
- weight1 = 0
- weight2 = 1.00
-
- unk1 = (readbyte f #unsigned/255.00)
- unk2 = (readbyte f #unsigned/255.00)
- unk3 = (readbyte f #unsigned/255.00)
- unk4 = (readbyte f #unsigned/255.00)
- unk5 = (readbyte f #unsigned/255.00)
- unk6 = (readbyte f #unsigned/255.00)
- unk7 = (readbyte f #unsigned/255.00)
- unk8 = (readbyte f #unsigned/255.00)
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
- 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 )
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2 )
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3 )
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4 )
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==20 then
- if (Mesh_Info[i].VType)==18 do
- for x = 1 to Mesh_Info[i].VertCount do (
- Bone3 = -1
- Bone4 = -1
- weight3 = 0
- weight4 = 0
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
-
- Bone1 = readbyte f #unsigned
- Bone2 = readbyte f #unsigned
-
- weight1 = 0
- weight2 = 1.00
-
- unk1 = (readbyte f #unsigned/255.00)
- unk2 = (readbyte f #unsigned/255.00)
- unk3 = (readbyte f #unsigned/255.00)
- unk4 = (readbyte f #unsigned/255.00)
- unk5 = (readbyte f #unsigned/255.00)
- unk6 = (readbyte f #unsigned/255.00)
- unk7 = (readbyte f #unsigned/255.00)
- unk8 = (readbyte f #unsigned/255.00)
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
- 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 )
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2 )
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3 )
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4 )
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==20 then
- if (Mesh_Info[i].VType)==19 do
- for x = 1 to Mesh_Info[i].VertCount do (
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
- p1 = ReadBEword f
-
- Bone1 = readbyte f #unsigned
- Bone2 = readbyte f #unsigned
- Bone3 = readbyte f #unsigned
- Bone4 = readbyte f #unsigned
-
- weight1 = (readbyte f #unsigned/255.00)
- weight2 = (readbyte f #unsigned/255.00)
- weight3 = (readbyte f #unsigned/255.00)
- weight4 = (readbyte f #unsigned/255.00)
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
- 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 )
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2 )
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3 )
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4 )
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==24 then
- if (Mesh_Info[i].VId2)==129 do
- for x = 1 to Mesh_Info[i].VertCount do (
- Bone3 = -1
- Bone4 = -1
- weight3 = 0
- weight4 = 0
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
-
- Bone1 = readbyte f #unsigned
- Bone2 = readbyte f #unsigned
-
- weight1 = 0
- weight2 = 1.00
-
- unk1 = (readbyte f #unsigned/255.00)
- unk2 = (readbyte f #unsigned/255.00)
- unk3 = (readbyte f #unsigned/255.00)
- unk4 = (readbyte f #unsigned/255.00)
- unk5 = (readbyte f #unsigned/255.00)
- unk6 = (readbyte f #unsigned/255.00)
- unk7 = (readbyte f #unsigned/255.00)
- unk8 = (readbyte f #unsigned/255.00)
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
- unk1= readBEHalfFloat f
- unk2= readBEHalfFloat f*-1
-
- 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 )
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2 )
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3 )
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4 )
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==24 then
- if (Mesh_Info[i].VId2)==130 do
- for x = 1 to Mesh_Info[i].VertCount do (
- Bone3 = -1
- Bone4 = -1
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
- weight1 = (ReadBEword f /32767.00)
- p1= ReadBEword f
- p2= ReadBEword f
- p3= ReadBEword f
- p4= ReadBEword f
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
- bone1 = (ReadBEHalfFloat f) as integer
- bone2 = (ReadBEHalfFloat f) as integer
-
- -- print bone1
- -- print bone2
-
- weight4 = 0
-
- if weight1!=1.00 then
- weight2 = (1.00 - weight1)
- weight3 = 0
-
-
- if weight1==1.00 then
- weight2 = 0
- weight3 = 0
-
- 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 )
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2 )
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3 )
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4 )
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==28 then
- if (Mesh_Info[i].VType)==16 do
- for x = 1 to Mesh_Info[i].VertCount do (
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
-
- weight1 = (ReadBEword f /32767.00)
-
- p1= ReadBEword f
- p2= ReadBEword f
- p3= ReadBEword f
- p4= ReadBEword f
-
- bone1 = readbyte f #unsigned
- bone2 = readbyte f #unsigned
- bone3 = readbyte f #unsigned
- bone4 = readbyte f #unsigned
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
- weight2 = readBEHalfFloat f
- weight3 = readBEHalfFloat f
-
- weight4 = 1.00-(weight1+weight2+weight3)
-
- if weight1==1.00 then
- weight2 = 0
- weight3 = 0
- weight4 = 0
-
- 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)
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2)
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3)
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4)
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==28 then
- if (Mesh_Info[i].VType)==18 do
- if (Mesh_Info[i].VId2)==128 do
- for x = 1 to Mesh_Info[i].VertCount do (
- Bone1 = -1
- Bone2 = -1
- Bone3 = -1
- Bone4 = -1
- weight1 = 0
- weight2 = 0
- weight3 = 0
- weight4 = 0
- vx = readBEfloat f
- vy = readBEfloat f
- vz = readBEfloat f
-
- p1= ReadBEword f
- p2= ReadBEword f
- p3= ReadBEword f
- p4= ReadBEword f
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
- weight01 = readbyte f #unsigned
- weight02 = readbyte f #unsigned
- weight03 = readbyte f #unsigned
- weight04 = readbyte f #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.00)
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2/255.00)
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3/255.00)
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4/255.00)
- )
- )
- append Weight_array w
- append vertArray [vx,vy,vz]
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==28 then
- if (Mesh_Info[i].VType)==18 do
- if (Mesh_Info[i].VId2)==129 do
- for x = 1 to Mesh_Info[i].VertCount do (
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
-
- weight1 = (ReadBEword f /32767.00)
-
- p1= ReadBEword f
- p2= ReadBEword f
- p3= ReadBEword f
- p4= ReadBEword f
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
- bone1 = (ReadBEHalfFloat f) as integer
- bone2 = (ReadBEHalfFloat f) as integer
-
- unk2 = readBEHalfFloat f
- unk3 = readBEHalfFloat f
-
- -- print bone1
- -- print bone2
-
- weight4 = 0
-
- if weight1!=1.00 then
- weight2 = (1.00 - weight1)
- weight3 = 0
-
-
- if weight1==1.00 then
- weight2 = 0
- weight3 = 0
-
- 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)
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2)
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3)
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4)
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==28 then
- if (Mesh_Info[i].VType)==18 do
- if (Mesh_Info[i].VId2)==130 do
- for x = 1 to Mesh_Info[i].VertCount do (
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
-
- weight1 = (ReadBEword f /32767.00)
-
- p1= ReadBEword f
- p2= ReadBEword f
- p3= ReadBEword f
- p4= ReadBEword f
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
- bone1 = (ReadBEHalfFloat f) as integer
- bone2 = (ReadBEHalfFloat f) as integer
-
- unk2 = readBEHalfFloat f
- unk3 = readBEHalfFloat f
-
- -- print bone1
- -- print bone2
-
- weight4 = 0
-
- if weight1!=1.00 then
- weight2 = (1.00 - weight1)
- weight3 = 0
-
-
- if weight1==1.00 then
- weight2 = 0
- weight3 = 0
-
- 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)
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2)
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3)
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4)
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==28 then
- if (Mesh_Info[i].VType)==18 do
- if (Mesh_Info[i].VId2)==131 do
- for x = 1 to Mesh_Info[i].VertCount do (
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
-
- weight1 = (ReadBEword f /32767.00)
-
- p1= ReadBEword f
- p2= ReadBEword f
- p3= ReadBEword f
- p4= ReadBEword f
-
- bone1 = readbyte f #unsigned
- bone2 = readbyte f #unsigned
- bone3 = readbyte f #unsigned
- bone4 = readbyte f #unsigned
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
- weight2 = readBEHalfFloat f
- weight3 = readBEHalfFloat f
-
- weight4 = 1.00-(weight1+weight2+weight3)
-
- if weight1==1.00 then
- weight2 = 0
- weight3 = 0
- weight4 = 0
-
- 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)
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2)
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3)
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4)
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==28 then
- if (Mesh_Info[i].VType)==18 do
- if (Mesh_Info[i].VId2)==132 do
- for x = 1 to Mesh_Info[i].VertCount do (
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
-
- weight1 = (ReadBEword f /32767.00)
-
- p1= ReadBEword f
- p2= ReadBEword f
- p3= ReadBEword f
- p4= ReadBEword f
-
-
- bone1 = readbyte f #unsigned
- bone2 = readbyte f #unsigned
- bone3 = readbyte f #unsigned
- bone4 = readbyte f #unsigned
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
- weight2 = readBEHalfFloat f
- weight3 = readBEHalfFloat f
-
- weight4 = 1.00-(weight1+weight2+weight3)
-
- if weight1==1.00 then
- weight2 = 0
- weight3 = 0
- weight4 = 0
-
- 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)
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2)
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3)
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4)
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==28 then
- if (Mesh_Info[i].VType)==19 do
- for x = 1 to Mesh_Info[i].VertCount do (
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
-
- p1= ReadBEword f
-
- bone1 = readbyte f #unsigned
- bone2 = readbyte f #unsigned
- bone3 = readbyte f #unsigned
- bone4 = readbyte f #unsigned
- bone5 = readbyte f #unsigned
- bone6 = readbyte f #unsigned
- bone7 = readbyte f #unsigned
- bone8 = readbyte f #unsigned
-
- weight1 = readbyte f #unsigned
- weight2 = readbyte f #unsigned
- weight3 = readbyte f #unsigned
- weight4 = readbyte f #unsigned
- weight5 = readbyte f #unsigned
- weight6 = readbyte f #unsigned
- weight7 = readbyte f #unsigned
- weight8 = readbyte f #unsigned
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
- 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(weight1 != 0) then
- maxweight = maxweight + weight5
- if(weight2 != 0) then
- maxweight = maxweight + weight6
- if(weight3 != 0) then
- maxweight = maxweight + weight7
- if(weight4 != 0) then
- maxweight = maxweight + weight8
-
- if(maxweight != 0) then (
- if(weight1 != 0) then (
- w1 = weight1 as float
- append w.boneids (bone1 + 1)
- append w.weights (w1/255.00)
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2/255.00)
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3/255.00)
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4/255.00)
- )
- if(weight5 != 0) then (
- w1 = weight5 as float
- append w.boneids (bone1 + 1)
- append w.weights (w1/255.00)
- )
- if(weight6 != 0) then (
- w2 = weight6 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2/255.00)
- )
- if(weight7 != 0) then (
- w3 = weight7 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3/255.00)
- )
- if(weight8 != 0) then (
- w8 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4/255.00)
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==32 do
- for x = 1 to Mesh_Info[i].VertCount do (
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
- weight1 = (ReadBEword f/32767.00)
-
- p1= ReadBEword f
- p2= ReadBEword f
- p3= ReadBEword f
- p4= ReadBEword f
-
- bone1 = readbyte f #unsigned
- bone2 = readbyte f #unsigned
- bone3 = readbyte f #unsigned
- bone4 = readbyte f #unsigned
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
- weight2 = readBEHalfFloat f
- weight3 = readBEHalfFloat f
-
- p5= ReadBEword f
- p6= ReadBEword f
-
- weight4 = 1.00-(weight1+weight2+weight3)
-
- if weight1==1.00 then
- weight2 = 0
- weight3 = 0
-
-
- 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)
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2)
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3)
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4)
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
- if (Mesh_Info[i].VSize)==36 do
- for x = 1 to Mesh_Info[i].VertCount do (
- vx = (ReadBEword f /32767.00)
- vy = (ReadBEword f /32767.00)
- vz = (ReadBEword f /32767.00)
- weight1 = (ReadBEword f/32767.00)
-
- p1= ReadBEword f
- p2= ReadBEword f
-
- unk1 = readbyte f #unsigned
- weight2 = readbyte f #unsigned /255.00
- weight3 = readbyte f #unsigned /255.00
- weight4 = readbyte f #unsigned /255.00
-
- bone1 = readbyte f #unsigned
- bone2 = readbyte f #unsigned
- bone3 = readbyte f #unsigned
- bone4 = readbyte f #unsigned
-
- p5= ReadBEword f
- p6= ReadBEword f
-
- tu= readBEHalfFloat f
- tv= readBEHalfFloat f*-1
-
- unk2 = (ReadBEword f/32767.00)
- unk3 = (ReadBEword f/32767.00)
-
- weight4 = 1.00-(weight1+weight2+weight3)
-
- if weight1==1.00 then
- weight2 = 0
- weight3 = 0
- weight4 = 0
-
- p7= readBEHalfFloat f
- p8= readBEHalfFloat f
-
- 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)
- )
- if(weight2 != 0) then (
- w2 = weight2 as float
- append w.boneids (bone2 + 1)
- append w.weights (w2)
- )
- if(weight3 != 0) then (
- w3 = weight3 as float
- append w.boneids (bone3 + 1)
- append w.weights (w3)
- )
- if(weight4 != 0) then (
- w4 = weight4 as float
- append w.boneids (bone4 + 1)
- append w.weights (w4)
- )
- )
- append Weight_array w
- append vertArray ([vx,vy,vz]*100)
- append UV_array [tu,tv,0]
- )
-
- ModelEnd=ftell f
-
- fseek f faceOffset #seek_set
- FaceBuffStart=ftell f
- faceStart=(FaceBuffStart+(Mesh_Info[i].FacePos*2))
-
- fseek f (FaceBuffStart+(Mesh_Info[i].FacePos*2)) #seek_set
-
- StartDirection = -1
- f1 = ((ReadBEword f) + 1) - Mesh_Info[i].VStart
- f2 = ((ReadBEword f) + 1) - Mesh_Info[i].VStart
- FaceDirection = StartDirection
- while ((ftell f) < (faceStart + (2 * Mesh_Info[i].FaceCount))) Do (
- f3 = (ReadBEword f)
- if (f3==0xFFFF) then (
- f1 = ((ReadBEword f) + 1) - Mesh_Info[i].VStart
- f2 = ((ReadBEword f) + 1) - Mesh_Info[i].VStart
- FaceDirection = StartDirection
- ) else (
- f3 += (1 - Mesh_Info[i].VStart)
- FaceDirection *= -1
- if (f1!=f2)AND(f2!=f3)AND(f3!=f1) then (
- if FaceDirection > 0 then append Facearray [f1,f2,f3]
- else append Facearray [f1,f3,f2]
- )
- f1 = f2
- f2 = f3
- )
- )
-
- Print ("Last Read @ 0x"+((bit.intAsHex(ftell f))as string))
-
- try(
- msh = mesh vertices:vertArray faces:faceArray
- 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]
- msh.displayByLayer = false
- msh.backfacecull = on
- msh.wirecolor = (color 230 200 210)
-
- max modify mode
- select msh
- skinMod = skin ()
- addModifier msh skinMod
- for i = 1 to BoneCount do
- (
- maxbone = BNArr[i]
- if i != BoneCount then
- skinOps.addBone skinMod maxbone 0
- else
- skinOps.addBone skinMod maxbone 1
- )
- modPanel.setCurrentObject skinMod
- for i = 1 to (Mesh_Info[i].VertCount) 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 "failed!!\n")
- fseek f ModelEnd #seek_set
- format "Mesh %\n\tMesh End: %\n\tFace Start: %\n\tVertex Size: %\n\tVertex Id: %\n\tVertex Type: %\n\n" i ("0x"+((bit.intAsHex(ModelEnd))as string)) ("0x"+((bit.intAsHex(faceStart))as string)) (Mesh_Info[i].VSize as string) (Mesh_Info[i].VId as string) (Mesh_Info[i].VType as string)
- )
-
- fclose f