playcanvas / engine

Powerful web graphics runtime built on WebGL, WebGPU, WebXR and glTF
https://playcanvas.com
MIT License
9.73k stars 1.36k forks source link

XrJoint does not expose the WebXR joint id #7131

Closed willeastcott closed 3 days ago

willeastcott commented 3 days ago

It would be useful to be able to query the WebXR spec id of an XrJoint. This is because, when a new hand-based XrInputSource is added, it has an XrHand that in turn, has an array of XrJoints. A typical scenario is loading a GLB model of a hand and linking XrJoints to entities in the instantiated hand model. The names of these entities/nodes stored in the GLB are the WebXR ids. So you want to do something like:

if (inputSource.hand) {
    for (const joint of inputSource.hand.joints) {
        const jointEntity = handRoot.findByName(joint.id); // Need to expose id getter
        // store jointEntity in a map to update every frame from the hands joint
    }
}
Maksims commented 3 days ago

Just to mention, for efficiency, it is better to iterate once through entities, and get a joint by id. As going through joints and then looking for entity by name (findByName) is O(n*j) instead of O(n). Unless you build an index of entities by name first, and then iterate through joints and get entity from index by name. Which is slightly worse than first option.