3 let quat0 posecount sbuf
=
4 let i = Xff.rfloat sbuf
0
5 and j
= Xff.rfloat sbuf
4
6 and k
= Xff.rfloat sbuf
8
7 and s
= Xff.rfloat sbuf
12 in
8 let q = Qtr.make
i j k s
in
9 Array.create posecount
q
14 [|[|5; 9; 9; 9|]; [|9; 5; 9; 9|]; [|9; 9; 5; 9|]; [|9; 9; 9; 5|]|]
17 let toint shift mask
=
18 let i = (Int32.to_int
(Int32.shift_right_logical int32 shift
)) land mask
in
19 let i = i - ((i land ((mask
+ 1) lsr 1)) lsl 1) in
22 let bits = bits.(typ
- 3) in
25 ; 32 - bits.(0) - bits.(1)
26 ; 32 - bits.(0) - bits.(1) - bits.(2)
30 let toint i = (toint shifts.(i) ((1 lsl bits.(i)) - 1)) in
31 let tofloat i = float (toint i) /. float (1 lsl (bits.(i) - 1)) in
36 (a, b
, c
, d
, toint (typ
- 3))
39 let quat3456 typ posecount sectbuf sbuf
=
40 let floats = Array.init
8 (fun i -> Xff.rfloat sbuf
(i*4)) in
41 let offset = Xff.rint sbuf
32 in
42 let sbuf32 = Xff.sbufplus sectbuf
offset in
43 let int32s = Array.init posecount
(fun i -> Xff.r32
sbuf32 (i*4)) in
44 let madd v n
= v
*.floats.(n
*2 + 1) +. floats.(n
*2) in
45 let omsqrt a b c mask
=
46 let m = a*.a +. b
*.b
+. c
*.c
in
47 let v = if m >= 1.0 then 0.0 else sqrt
(1. -. m) in
48 if mask
land 0b10000 != 0 then -.v else v
51 let i, j
, k
, s
, mask
= expand int32s.(poseno
) typ
in
58 (omsqrt j k s mask
, j, k
, s
)
63 (i, omsqrt i k s mask
, k
, s
)
68 (i, j, omsqrt i j s mask
, s
)
73 (i, j, k
, omsqrt i j k mask
)
74 | _
-> failwith
"Me fail english? That's Umpossible!"
76 { Qtr.i = i; j = j; k
= k
; s
= s
}
78 Array.init posecount
toquat
81 let quat12 posecount sectbuf sbuf
=
82 let floats = Array.init
6 (fun i -> Xff.rfloat sbuf
(i*4)) in
83 let offset = Xff.rint sbuf
24 in
84 let sbuf16 = Xff.sbufplus sectbuf
offset in
86 float v /. 32768.0 *. floats.(n
*2 + 1) +. floats.(n
*2)
89 let a = Xff.r16s
sbuf16 (poseno
*6 + 0)
90 and b
= Xff.r16s
sbuf16 (poseno
*6 + 2)
91 and c
= Xff.r16s
sbuf16 (poseno
*6 + 4) in
92 let sign = a land 1 = 1 in
96 let s = sqrt
(1.0 -. (i*.i +. j*.j +. k
*.k
)) in
97 Qtr.make
i j k
(if sign then -.s else s)
99 Array.init posecount
toquat
102 let quat13 posecount sectbuf sbuf
=
103 let bias = Xff.rfloat sbuf
0
104 and scale
= Xff.rfloat sbuf
4
105 and x
= Xff.rfloat sbuf
8
106 and y
= Xff.rfloat sbuf
12
107 and z
= Xff.rfloat sbuf
16 in
108 let offset = Xff.rint sbuf
20 in
109 let sbuf16 = Xff.sbufplus sectbuf
offset in
111 let fixp = Xff.r16s
sbuf16 (poseno
*2) in
112 let fltp = float fixp /. 32768.0 in
113 let phi = fltp*.scale
+. bias in
114 let q = Qtr.from_axis_angle x y z
phi in
115 { q with Qtr.s = q.Qtr.s }
117 Array.init posecount
toquat
120 let skin bones poseno
=
121 let quats = Array.map
(fun a -> Array.get
a poseno
) bones
in
126 if Array.length xff
.Xff.sections
!= 2
128 Xff.sbuferr sbufxff
0 "number of xff sections is not 2"
130 let sectpos = xff
.Xff.sections
.(1).Xff.off
in
131 let sectbuf = Xff.sbufplus sbufxff
sectpos in
132 let anbbuf = Xff.sbufplus
sectbuf xff
.Xff.entry
in
134 let bonecount = Xff.rint
anbbuf 20 in
136 let off = Xff.rint
anbbuf 16 in
137 Array.init
bonecount (fun i -> Xff.rint
sectbuf (off + i*4))
140 let off = Xff.rint
anbbuf 8 in
141 Array.init
bonecount (fun i -> Xff.r8
sectbuf (off + i))
143 let posecount = 0xffff land Xff.rint
anbbuf 4 in
147 let sbuf = Xff.sbufplus
sectbuf d in
149 | 0 -> quat0 posecount sbuf
150 | 3 | 4 | 5 | 6 -> quat3456 b
posecount sectbuf sbuf
151 | 12 -> quat12 posecount sectbuf sbuf
152 | 13 -> quat13 posecount sectbuf sbuf
153 | _
-> failwith
"Me fail english? That's Umpossible!"
155 posecount, Array.init
bonecount rbone