npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

local-bone-to-world-bone

v0.0.1

Published

Get the world transformation matrices for a set of local bone positions

Downloads

17

Readme

local-bone-to-world-bone npm version Build Status

Calculate the world bone space matrices for a set of local bone space matrices

Given a set of pose bones (that came from a keyframe time), joint relationships, and joint indices (in order to look up pose bones) calculate and return the world bone matrices for this set of pose bones

Background / Initial motivation

I'm exporting some pose matrices from Blender and want to calculate the world bone transformations. I wrote some code over a year ago in collada-dae-parser to do this but it was a bit hacky so wrote something that I can make use of outside standalone.

Install

npm install --save local-bone-to-world-bone

Usage

var local2WorldBone = require('local-bone-to-world-bone')

// childBoneName: parentBoneName
var jointParents = {
  lower_back: null,
  upper_back: lowerBack,
  shoulder_left: upperBack,
  shoulder_right: upperBack
}

// childBoneName: indexInArrayOfPoseMatrices
var jointIndices = {
  lower_back: 0,
  upper_back: 1,
  should_left: 3,
  shoulder_right: 2
}

// An array of local bone matrices, ordered by the above jointIndices array
var localBoneMatrices = [
  // These probably won't all be identity matrices when using real data
  [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
  [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
  [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
  [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
]

var worldBoneMatrices = local2WorldBone(localBoneMatrices, jointParents, jointIndices)
console.log(worldBoneMatrices)
  /**
   * All of your bone world transformation matrices in the same order as your local bones
   * [
   *   [...],
   *   [...],
   *   [...],
   *   [...]
   * ]
   */

API

local2WorldBone(localPoseMatrices, jointParents, jointIndices) -> worldPoseMatrices

poseMatrices

Type: Array[numBones][16]

[
  [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], // someOtherRootBone
  [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], // childOfSecondRootBone
  [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], // parentBone
  [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], // childBone
  [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]  // childChildBone
]

An array that has the pose matrix for each bone. Note that they won't typically be identity matrices as they are in this trivial example.

jointParents

Type: Object

{
  parentBone: null,
  childBone: parentBone,
  childChildBone: childBone,
  someOtherRootBone: null,
  childOfSecondRootBone: someOtherRootBone
}

An object that maps each bone to it's parent, or null if it is a root bone

jointIndices

Type: Object

{
  parentBone: 2,
  childBone: 3,
  childChildBone: 4,
  someOtherRootBone: 0,
  childOfSecondRootBone: 1
}

(returned) worldPoseMatrices

Type: Array[numBones][16]

[
  [...],
  [...],
  [...],
  [...],
  [...]
]

We return an array of the world bone poses. You typically want to then multiple each world matrix by the bone's inverse bind matrix before making use of it.

Have an idea? Something not clicking?

Open an issue!

License

(c) 2017 Chinedu Francis Nwafili. MIT License