3 let qof f
= Qtr.make f
.(5) f
.(6) f
.(7) f
.(8);;
4 let vof f
= Vec.make f
.(1) f
.(2) f
.(3);;
6 type t
= int * (string * int32 array
* float array
* int array
* float);;
9 let d = Array.init
3 (fun n
-> Xff.r32 sbuf
(n
*4)) in
10 let f9 = Array.init
9 (fun n
-> Xff.rfloat sbuf
(12 +n
*4)) in
11 let h = Array.init
3 (fun n
-> Xff.rint sbuf
(48 + n
*4)) in
12 let f = Xff.rfloat sbuf
60 in
13 (Xff.rcstrtabent strtab
0 (Int32.to_int
d.(0)), d, f9, h, f)
17 if Array.length xff
.Xff.sections
!= 2
19 Xff.sbuferr sbufxff
0 "number of xff sections is not 2"
21 let sectpos = xff
.Xff.sections
.(1).Xff.off
in
22 let sectbuf = Xff.sbufplus sbufxff
sectpos in
23 let skbbuf = Xff.sbufplus
sectbuf xff
.Xff.entry
in
24 if not
(Xff.check32
skbbuf 0 1l)
26 Xff.sbuferr
skbbuf 0 "bad skb signature"
29 let count1 = Xff.rint
skbbuf 4 in
30 let _pos1 = Xff.rint
skbbuf 8 in
31 let tabpos1 = Xff.rint
skbbuf 12 in
32 let strtab1 = Xff.sbufplus
sectbuf tabpos1 in
34 let bones = Array.init
count1 (fun n
->
35 let pos = Xff.rint
skbbuf (44 + n
*8) in
36 let sbuf = Xff.sbufplus
sectbuf pos in
37 pos + sectpos, rt sbuf strtab1)
42 let vertices bones quats
=
43 let parentinfo = Array.make
(Array.length
bones + 1) (Qtr.id
, Vec.origin
) in
44 let mapf i
(pos, (name
, offsets
, floats
, neighbors
, float)) =
45 let curq = quats
.(i
) in
46 let curv = vof floats
in
48 let parent = neighbors
.(2) in
49 let parentq, parentv
= parentinfo.(parent + 1) in
51 let v = Qtr.apply
parentq curv in
52 let v = Vec.add
v parentv
in
54 let q = Qtr.compose
curq parentq in
55 parentinfo.(i
+ 1) <- (q, v);
56 Vec.elts parentv
, Vec.elts
v;
58 Array.mapi
mapf bones;
62 let quad = lazy (GluQuadric.create
()) in
64 GlMat.mode `modelview
;
66 GlMat.translate3
(origin
);
67 let radius = Rend.view
.Rend.radial_scale
*.0.009 in
68 let quad = Lazy.force
quad in
69 GluQuadric.sphere ~
radius ~stacks
:5 ~slices
:5 ~
quad ();
74 fun ?
(dsphere
=false) quats
->
75 let rta = vertices bones quats
in
77 GlDraw.polygon_mode `both `line
;
78 GlDraw.color
(0., 0., 1.);
79 Gl.disable `depth_test
;
80 for i
= 0 to Array.length
bones - 1 do
81 let v0, v1
= rta.(i
) in
83 GlDraw.line_width
0.1;
86 GlDraw.line_width
2.0;
92 Gl.enable `depth_test
;
96 Array.map
(fun (_
, (_
, _
, f, _
, _
)) -> qof f) bones
105 let posecount, rotations
= anim
in
107 let poseno'
= poseno mod posecount in
108 if poseno'
< 0 then posecount + poseno'
else poseno'
110 let skeldraw n quats
=
113 | 1 -> draw bones quats
()
114 | _
-> draw ~dsphere
:true bones quats
()
116 let skbquats = skbquats bones in
125 method private advance quats dir
=
126 let t = t +. !Rend.slerp_step
in
129 let sposeno = dposeno
130 and dposeno
= clip (dposeno
+ dir
) in
131 {< quats
= quats
; sposeno = sposeno; dposeno
= dposeno
; t = 0.0 >}
133 {< quats
= quats
; sposeno = sposeno; dposeno
= dposeno
; t = t >}
136 [("s", "toggle skeleton (S type)",
137 if drawindex
= 0 then "off" else string_of_int drawindex
)
138 ;"B", sprintf
"toggle animation direction", string_of_int dir
139 ;"f", "forward one frame", sprintf
"%d, %f" sposeno t
140 ;"b", "backward one frame", sprintf
"%d, %f" sposeno t
141 ;"", "", "total frames " ^ string_of_int
posecount
142 ;"r", "go to bind pose", ""
143 ;"1,2", "go to first/last frame", ""
146 method draw = skeldraw drawindex quats
151 let quats = Anb.interpolated rotations
sposeno dposeno
t in
159 | 'B'
-> {< dir
= -dir
>}
162 Skin.set_anim
skbquats;
164 {< drawindex
= 1; quats = skbquats >}
167 let sposeno, dposeno
=
170 else clip (posecount - 1), 0
172 let quats = Anb.exact rotations
sposeno in
174 let t = if dir
> 0 then 1.0 else 0.0 in
175 {< quats = quats; sposeno = sposeno; dposeno
= dposeno
; t = t >}
177 | 's'
-> {< drawindex
= if drawindex
= 0 then 1 else 0 >}
178 | 'S'
-> {< drawindex
= (drawindex
+ 1) mod 3 >}
187 method help
= ["s", "toggle skeleton", if dodraw
then "on" else "off"]
188 method draw = if dodraw
then draw ()
190 if c
= 's'
then {< dodraw
= not dodraw
>} else self
196 (fun (_
, (_
, _
, floats
, neighbors
, _
)) -> (neighbors
.(2), floats
))
206 match !Rend.skb_name
with
209 Filename.chop_extension
name ^
".skb"
211 let xff, sbuf = Xff.test2
name in
212 let bones = r1 xff sbuf in
213 begin match !Rend.anb_names
with
215 let quats = skbquats bones in
216 dummy (draw bones quats)
219 let xff, sbuf = Xff.test2
(Filename.basename aname
) in
220 let anim = Anb.r
xff sbuf in
221 let (_
, abones
) = anim in
222 if Array.length abones
!= Array.length
bones
224 failwith
(sprintf
"invalid animation %s for skeleton %s"
228 let rec run1 = function
229 | [] -> failwith
"no animations"
232 let anim = ranb hd
in
235 prerr_endline
(Printexc.to_string exn
);
237 and run2 accu
= function
242 Anb.append
accu (ranb hd
)
244 prerr_endline
(Printexc.to_string exn
);
249 let anim = run1 list
in
254 prerr_endline
(Printexc.to_string exn
);