dmsurti / AssimpKit

A library (macOS, iOS) that converts the files supported by Assimp to Scene Kit scenes.
http://assimpkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
474 stars 54 forks source link

Add skeletal animation support #5

Closed dmsurti closed 7 years ago

dmsurti commented 7 years ago

This adds support for skeletal animation using SCNSkinner and CAKeyframeAnimation. The following are the high level steps:

Step 1:

The importer builds a list of unique bones, the bone nodes and the bone inverse bind transforms. Then it works out the skeleton node by picking the depth of each unique bone from the root. If there are more than 1 bones at the same minimum depth, it picks the parent as the skeleton node.

Step 2

The bone and vertex weight data provided by assimp is parsed into a list of bone weights and bone indices which map into the list of unique bones prepared in the earlier step.

Step 3

The animation data is then parsed to prepare a list of CAKeyframeAnimation for each channel of the animation, which maps to a deform bone. The position, rotation and scale keys are mapped to position, orientation and scale key paths for each bone node. Each keyframe animation duration is aiAnimation->mDuration / mTicksPerSecond if mTicksPerSecond != 0, otherwise it is just mDuration.