Ponies & Light

ofxSkeleton

ofxSkeleton

Skeletal animation with openFrameworks

ofxSkeleton

Download

Here’s the source code: http://github.com/tgfrerer/ofxSkeleton

Description

This addon allows you to build (and debug-draw) skeleton structures, useful for skeletal animation and skinning.

Also includes a rudimentary CCD inverse kinematics solver for bone chains.

Use case:

typedef shared_ptr<pal::ofxSkeleton::ofxJoint>  JointP_t;
        
for (int i = 0; i < 4; i++){
        mSkeleton.push_back(JointP_t(new ofxJoint));
}

mFoot = mSkeleton[0];
mKnee = mSkeleton[1];
mHip  = mSkeleton[2];
mRoot = mSkeleton[3];

mFoot->setName("Foot");
mKnee->setName("Knee");
mHip->setName("Hip");
mRoot->setName("Root");

// build skeleton based on joints.
// this applies a hierarchy, and allows you to set children 
// bones' offsets relative to their parent's.

mFoot->bone(mKnee)->bone(mHip)->bone(mRoot);

mRoot->setGlobalPosition(ofVec3f(0));

mHip->setPosition(ofVec3f(0,100,0));
mKnee->setPosition(ofVec3f(0,50,0));
mFoot->setPosition(ofVec3f(0,50,0));

// some knee rotation
mKnee->setOrientation(ofQuaternion(-30, ofVec3f(1,0,0)));

// query global positions for individual joints
ofLogNotice() << mFoot->getGlobalPosition();

for (int i = 0; i < 4; i++){
        // draw debug view with joint spheres and bone pyramids
        mSkeleton[i]->draw(5);        

        // draw axes for joints
        mSkeleton[i]->drawAxes(15);
}

// query transform matrix for joint (useful for skinning)
ofLogNotice() << mKnee->getGlobalTransformMatrix();

Example Projects

This addon comes with two examples, one fairly simple, one more complex. The reference render is of the more complex example.

imageofxSkeleton example reference render

Dependencies

  • ♥ openframeworks >= 0.8.0

License

   _____    ___     
  /    /   /  /     ofxSkeleton
 /  __/ * /  /__    (c) ponies & light, 2012, 2013. All rights reserved.
/__/     /_____/    poniesandlight.co.uk

Created by tim, 2012, 2013.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Contact:

Unit 3, 410 Hackney Road,
E2 7AP London, UK