Expand description
§About this library
A small library for loading and manipulating BioVision motion files.
§The bvh file format
The Bvh file format is comprised of two main sections: the ‘Heirarchy’ section,
which defines the joints of the skeleton, and the ‘Motion’ section, which defines
the motion values for each channel.
This project contains some samples in the data directory.
§Heierarchy
The ‘Heirarchy’ section defines the skeleton as a tree of joints, where there is a single root joint, and a chain of child joints extending out from each joint, terminated by an ‘End Site’ section.
Each joint has:
- A list of channels, which are the degrees of freedom in which the joint may move. Channels are listed in the order in which the transformation should be applied to the global transform for the root.
- An offset, which is the vector distance from the parent joint.
- An optional end site, which is used to cap off a chain of joints. This is only used to calculate the length of the final bone in the chain.
HEIRARCHY
ROOT <Root-name>
{
OFFSET <Root-offset-x> <Root-offset-y> <Root-offset-z>
CHANNELS <Num-root-joint-channels> Xposition Yposition <other-root-channels ...>
JOINT <Joint-1-name>
{
OFFSET <Joint-1-offset-x> <Joint-1-offset-y> <Joint-1-offset-z>
CHANNELS <Num-joint-1-channels> <Joint-1-channels ...>
JOINT <Joint-2-name>
{
OFFSET <Joint-2-offset-x> <Joint-2-offset-y> <Joint-2-offset-z>
CHANNELS <Num-joint-2-channels> <Joint-2-channels ...>
JOINT <Joint-with-end-site>
{
OFFSET ...
CHANNELS ...
End Site
{
OFFSET <end-site-offset-x> <end-site-offset-y> <end-site-offset-z>
}
}
... More child joints
}
JOINT <Joint-3-name>
{
OFFSET <Joint-3-offset-x> <Joint-3-offset-y> <Joint-3-offset-z>
CHANNELS <Num-joint-3-channels> <Joint-3-channels ...>
... More child joints
}
... More child joints
}
... More child joints
}Note that the bvh data is defined in terms of a right-handed coordinate system, where the positive y-axis is the up vector.
§Motion
The MOTION section of the bvh file records the number of frames, the frame time, and
defines the full range of motions for each channel, frame by frame.
MOTION
Frames: <num-frames>
Frame Time: <frame-time>
<frame-0-channel-0-value> <frame-0-channel-1-value> <frame-0-channel-2-value> ...
<frame-1-channel-0-value> <frame-1-channel-1-value> <frame-1-channel-2-value> ...
<frame-2-channel-0-value> <frame-2-channel-1-value> <frame-2-channel-2-value> ...
⋮The frame time is recorded in seconds, and tells the animation system how long each frame of the animation should last for. This value is usually around 0.033333333, which is close to 30 frames per second.
The list of motion values is a matrix, where each row represents a frame. Each column of
the row represents a transformation around the channel axis - for example a motion value
of 130.0 for an Xposition channel would correspond to a rotation of 130.0 degrees around
the x-axis.
Note that rotations are conventionally in degrees, although it will be up to your application how to interpret each motion’s value.
§Using this library.
§Creating a Bvh struct:
There are a few ways to create a Bvh struct:
-
You can use the
from_readerfunction, which will parse aBufReadas a bvh file. Thefrom_bytesfunction is a convenient wrapper function to parse an in-memory slice of bytes as abvhfile. Note that the file does not need to be strictly UTF-8, although it should be an ascii-compatible encoding. These functions are also available as associated methods on theBvhtype directly asBvh::from_readerBvh::from_readerandBvh::from_bytes -
You can use the
bvh!macro to construct aBvhinstance in your source files using the same syntax as you would use for a standard bvh file. -
You can use the
buildermodule to dynamically construct a bvh. This is useful for converting data from other formats into aBvhstruct. -
You can create an empty
Bvhusing theBvh::neworDefault::defaultDefault::defaultmethods.
§Other operations:
Once you have a valid Bvh struct, there are a number of ways you can inspect and
manipulate it:
-
The
Bvh::jointsmethod can be used to iterate through eachJointof theBvh. EachJointcan be inspected through itsJointDataJointData, which can be obtained with theJoint::datamethod. -
The
Bvh::framesmethod returns aFramesiterator over each frame of the animation. AFramecan only be indexed by aChannelbelonging to an associatedJointof theBvh, although you can convert it into an&[f32]using theFrame::as_slicemethod. -
You can serialise the
Bvhinto aWritetype using theBvh::write_toBvh::write_tomethod. There is also theBvh::to_bstringmethod, which converts theBvhinto aBString. Various aspects of the formatting can be customised using theWriteOptionstype, such as the line termination style, indentation method, and floating point accuracy.
§Examples
This library comes with some example applications, which can be viewed on Github.
§Other resources
- More information on this file format can be found here.
- A large library of bvh files is freely available from CMU’s motion capture database CMU’s motion capture database.
Modules§
- builder
- Defines a
Builderstruct used to build aBvhdynamically. - errors
- Errors which may occur when manipulating
Bvhfiles. - ffi
- The ffi interface to the
bvh_animcrate. You must enable theffifeature to access this module. - write
- Contains options for
bvhfile formatting.
Macros§
Structs§
- Bvh
- A complete
bvhfile. - Channel
- A
Channelcomposed of aChannelTypeand an index into the corresponding motion data. - Frame
- A wrapper for a slice of motion values, so that they can be indexed by
Channel. - Frames
- An iterator over the frames of a
Bvh. - Frames
Mut - A mutable iterator over the frames of a
Bvh. - Joint
- A view of a joint which provides access to various relevant data.
- Joint
Mut - A view of a joint which provides mutable access.
- Joint
Name - Wrapper struct for the
Jointname type. - Joints
- An iterator over the
Joints of aBvhskeleton. - Joints
Mut - A mutable iterator over the
Joints of aBvhskeleton.
Enums§
- Axis
- An enum which represents an axis along a direction in 3D space.
- Channel
Type - The available degrees of freedom along which a
Jointmay be manipulated. - Joint
Data - Internal representation of a joint.
Functions§
- from_
bytes - Parse a sequence of bytes as if it were an in-memory
Bvhfile. - from_
reader - Loads the
Bvhfrom thereader. - from_
str - Parse a
stras if it were an in-memoryBvhfile.