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 .bon from Bones folder" \
- types:"SKI Bones (*.bon)|*.bon" \
- historyCategory:"SKIObjectPresets"
- g = fopen gname "rb"
-
- clearlistener()
- 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
- )
- struct weight_data
- (
- boneids,weights
- )
- clearlistener()
-
- fseek g 0x0 #seek_set
- MOXBEKSA=readFixedString g 8
- Version = ReadLong g
- numBones = ReadLong g
- numTotalBones = ReadLong g
- Unk1 = ReadLong g
- numTexture = ReadLong g
- numMaterial = ReadLong g
- CountLong = ReadLong g
- Unk = ReadLong g
- fseek g 0x3C #seek_cur
-
- Print ("Info End @ 0x"+((bit.intAsHex(ftell g))as string))
-
- BNArr = #()
-
- for a = 1 to numTotalBones do (
-
- BoneNameSize = ReadLong g
- BoneName = readFixedString g BoneNameSize
- BoneId = ReadLong g
- BoneParent = ReadLong g
- BoneChild = ReadLong g
- LongCount = ReadLong g
-
- c11 = ReadFloat g; c12 = ReadFloat g; c13 = ReadFloat g; c14 = ReadFloat g
- c21 = ReadFloat g; c22 = ReadFloat g; c23 = ReadFloat g; c24 = ReadFloat g
- c31 = ReadFloat g; c32 = ReadFloat g; c33 = ReadFloat g; c34 = ReadFloat g
- c41 = ReadFloat g; c42 = ReadFloat g; c43 = ReadFloat g; c44 = ReadFloat g
-
- d11 = ReadFloat g; d12 = ReadFloat g; d13 = ReadFloat g; d14 = ReadFloat g
- d21 = ReadFloat g; d22 = ReadFloat g; d23 = ReadFloat g; d24 = ReadFloat g
- d31 = ReadFloat g; d32 = ReadFloat g; d33 = ReadFloat g; d34 = ReadFloat g
- d41 = ReadFloat g; d42 = ReadFloat g; d43 = ReadFloat g; d44 = ReadFloat g
-
- for x = 1 to LongCount do (
- Unk1 = Readlong g
- )
-
- tfm = matrix3 [d11,d12,d13] [d21,d22,d23] [d31,d32,d33] ([d41,d42,d43]*100)
- tfm2 = matrix3 [c11,c12,c13] [c21,c22,c23] [c31,c32,c33] [c41,c42,c43]
-
- if (BoneParent != -1) do (
- tfm2 = tfm2 * BNArr[(BoneParent + 1)].objecttransform
- )
- newBone = bonesys.createbone \
- tfm.row4 \
- (tfm.row4 + 0.01 * (normalize tfm.row1)) \
- (normalize tfm.row3)
- newBone.name = BoneName
- 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 != -1) then
- newBone.parent = BNArr[(BoneParent)+1]
- append BNArr newBone
- )
-
- rootRT = dummy name:"Main_Root" boxsize:[.1,.1,.1]
- for b in BNArr where b.parent==undefined do b.parent = rootRT
- rootRT.transform = (matrix3 [-1,0,0] [0,0,1] [0,-1,0] [0,0,0])
-
- Print ("Bone End @ 0x"+((bit.intAsHex(ftell g))as string))
-
- fclose g