aframegltf

How to access a GLB's Skeleton when using Aframe's entity gltf-model to load it?


I'm following this spec for loading GLB's, https://aframe.io/docs/1.4.0/components/gltf-model.html,

i've loaded a GLB file using

this format.

<a-scene>
  <a-entity gltf-model="./assets/models/Streetbud_1.7.glb"
  move position=".5 1.5 -15" scale="5 5 5"></a-entity>
</a-scene>

If i then access the model, i see the following in the console.

Model without skeleton

If i load the same model using the gltfloader from three.js with..

     gltfLoader.load('./assets/models/Streetbud_1.7.glb', (gltf) => {
....
    }

i get the following.

Model with Skeleton

Notice, in the case of the gltfLoader, the Skeleton is available in the model. I don't have this option when using the Aframe entity.

I'm looking to retarget some BVH animations to my skeleton. Any ideas on how i can get the skelton populated using ? I prefer to use the newer approach for compatibility reasons with some other libraries..


Solution

  • Should work like this:

    1. wait until the model is loaded
    2. find the root mesh object with getObject3D('mesh')
    3. traverse it looking for the isSkinnedMesh flag.
    4. access the skeleteon property.

    AFRAME.registerComponent("skinnedMesh-logger", {
       init: function() {
         this.el.addEventListener("model-loaded", e => {
           const mesh = this.el.getObject3D("mesh");
           mesh.traverse(node => {
             if (!node.isSkinnedMesh) return;
             console.log(node); // or node.skeleton
           })
         })
       }
    })