Game Development Reference
In-Depth Information
The
bones
array contains the DOF information. It holds the binding matrix and its
parent's information, as shown in the following code:
"bones" : [{"parent":-1, "name":"Back", "pos":[0.000000, -0.123622,
-0.149781], "rotq":[0,0,0,1]}, {}, {}.......];
Each element of the
bones
array holds the following four elements:
•
parent
: This element holds the hierarchical information of the skeleton.
Each bone holds its parent's index. The root bone has a parent index of -1,
denoting it does not have any parent.
•
name
: This element holds the name of the bone.
•
pos
: This element is a vector and holds the position of each bone with respect
to its parent.
•
rotq
: Each bone's rotation is expressed as a quaternion rotation (
x
,
y
,
z
, and
w
) with respect to its parent.
Chapter 5
,
Camera and User Interaction
, has a
description of quaternion rotations.
For each vertex(
x
,
y
,
z
,
x1
,
y1
, and
z1
) in the
vertices
array, there are two values
defined in the
skinIndices
(
a
,
b
,
a1
, and
b1
) and
skinWeights
(
a
,
b
,
a1
, and
b1
)
arrays. We had discussed earlier in the
Understanding the basics of skinning
section that
we will use a smooth skinning algorithm to store weights and skinning information.
The
three.js
JSON model (
https://github.com/mrdoob/three.js/wiki/JSON-
Model-format-3.1
) allows only two attached bones per vertex. Hence for each
vertex, we will have two corresponding
skinIndices
and
skinWeights
defined.
Although a vertex may be associated with more than two bones, it is not advisable
or even not required in gaming. It would rarely happen that a vertex is affected by
three bones simultaneously. The
skinIndices
array holds the index of the bone in
the
bones
array.
vertices:[x,y,z,x1,y1,z1,x2,y2,z2.............xn,yn,zn];
skinIndices:[a,b,a1,b1,a2,b2..........an,bn];
skinWeights:[z,w,z1,w1,z2,w2........zn,wn];
bones:[]
The preceding arrays denote the following:
•
The vertices
x
,
y
, and
z
are attached to the bones[a] and bones[b] with
weights z and w.
•
The vertices
x1
,
y1
, and
z1
are attached to the bones[a1] and bones[b1] with
weights
z1
and
w1
.
•
The vertices
x2
,
y2
, and
z2
are attached to the bones[a2] and bones[b2] with
weights
z2
and
w2
.