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.i = i; j
= j
; k
= k
; s
= 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 posecount
(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 v = sqrt
(1. -. (a*.a +. b
*.b
+. c
*.c
)) in
47 if mask
land 0b10000 != 0 then -.v else v
50 let i, j
, k
, s
, mask
= expand int32s.(poseno
) typ
in
57 (omsqrt j k s mask
, j, k
, s
)
62 (i, omsqrt i k s mask
, k
, s
)
67 (i, j, omsqrt i j s mask
, s
)
72 (i, j, k
, omsqrt i j k mask
)
73 | _
-> failwith
"Me fail english? That's Umpossible!"
75 { Qtr.i = i; j = j; k
= k
; s
= s
}
77 Array.init posecount
toquat
80 let quat12 posecount sectbuf sbuf
=
81 let floats = Array.init
6 (fun i -> Xff.rfloat sbuf
(i*4)) in
82 let offset = Xff.rint sbuf
24 in
83 let sbuf16 = Xff.sbufplus sectbuf
offset in
85 float v /. 32768.0 *. floats.(n
*2 + 1) +. floats.(n
*2)
87 eprintf
"quat12 is dead wrong@.";
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
94 and roll
= madd c
2 in
96 Qtr.from_euler
yaw pitch roll
98 Array.init posecount
toquat
101 let quat13 posecount sectbuf sbuf
=
102 let bias = Xff.rfloat sbuf
0
103 and scale
= Xff.rfloat sbuf
4
104 and x
= Xff.rfloat sbuf
8
105 and y
= Xff.rfloat sbuf
12
106 and z
= Xff.rfloat sbuf
16 in
107 let offset = Xff.rint sbuf
20 in
108 let sbuf16 = Xff.sbufplus sectbuf
offset in
110 let fixp = Xff.r16s
sbuf16 (poseno
*2) in
111 let fltp = float fixp /. 32768.0 in
112 let phi = fltp*.scale
+. bias in
113 let q = Qtr.from_axis_angle x y z
phi in
114 { q with Qtr.s
= q.Qtr.s
}
116 Array.init posecount
toquat
119 let skin bones poseno
=
120 let quats = Array.map
(fun a -> Array.get
a poseno
) bones
in
125 if Array.length xff
.Xff.sections
!= 2
127 Xff.sbuferr sbufxff
0 "number of xff sections is not 2"
129 let sectpos = xff
.Xff.sections
.(1).Xff.off
in
130 let sectbuf = Xff.sbufplus sbufxff
sectpos in
131 let anbbuf = Xff.sbufplus
sectbuf xff
.Xff.entry
in
133 let bonecount = Xff.rint
anbbuf 20 in
135 let off = Xff.rint
anbbuf 16 in
136 Array.init
bonecount (fun i -> Xff.rint
sectbuf (off + i*4))
139 let off = Xff.rint
anbbuf 8 in
140 Array.init
bonecount (fun i -> Xff.r8
sectbuf (off + i))
142 let posecount = 0xffff land Xff.rint
anbbuf 4 in
146 let sbuf = Xff.sbufplus
sectbuf d in
148 | 0 -> quat0 posecount sbuf
149 | 3 | 4 | 5 | 6 -> quat3456 b
posecount sectbuf sbuf
150 | 12 -> quat12 posecount sectbuf sbuf
151 | 13 -> quat13 posecount sectbuf sbuf
152 | _
-> failwith
"Me fail english? That's Umpossible!"
154 posecount, Array.init
bonecount rbone