Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add body tracking sample #178

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cabanier
Copy link
Member

@Maksims
Copy link

Maksims commented Jan 25, 2024

This is amazing!
I had to implement upper body IK multiple times, and it is not an easy task, and falls short when estimating shoulder twist.
Also legs! Yes please!

Copy link
Member

@toji toji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you said, this is just an FYI for now but I've got some comments for you anyway!


<meta http-equiv="origin-trial" content="Ahfj+MLeL6bh+LNmpnSdepftxoDHHwjUG2KWZ4jjCb1WoZxtBlzF3cDHuJNVqnhr3HXJwQ+kLaw57NO15S0mRwwAAABkeyJvcmlnaW4iOiJodHRwczovL2ltbWVyc2l2ZS13ZWIuZ2l0aHViLmlvOjQ0MyIsImZlYXR1cmUiOiJXZWJYUlBsYW5lRGV0ZWN0aW9uIiwiZXhwaXJ5IjoxNjI5ODQ5NTk5fQ==">

<title>AR Plane Detection</title>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update title

scene = new THREE.Scene();
scene.background = new THREE.Color( 0x505050 );

camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 50 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is kind of all over the place in this sample. Seems like you've probably got your editor set to tabs and these files use spaces? It'd be appreciated if you could normalize it.

document.querySelector('header').appendChild(xrButton.domElement);

if (navigator.xr) {
navigator.xr.isSessionSupported('immersive-ar')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this functionality only available in AR on Quest? If not, is there any way can we make this demo work in either AR or VR?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toji I am very curious about this too.

@cabanier Are you using some sort of polyfill? Or the API is giving you that information?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toji I am very curious about this too.

no, it can also be used in VR

@cabanier Are you using some sort of polyfill? Or the API is giving you that information?

What do you mean? a polyfill for???

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cabanier Sorry, let me rephrase. Is the WebXR implementation in the browser providing you all the information for the body tracking? Using the body-tracking feature? Or you are generating this information somewhere else and injecting in the browser? I am asking because body-tracking is not officially described/supported by the WebXR specification.

I am just very curious to understand where the bones positions/rotations comes from.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cabanier Sorry, let me rephrase. Is the WebXR implementation in the browser providing you all the information for the body tracking? Using the body-tracking feature? Or you are generating this information somewhere else and injecting in the browser?

It's a new extension to WebXR that I'm proposing: https://cabanier.github.io/webxr-body-tracking/
It uses Meta's body tracking OpenXR implementation under the hood.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cabanier Thanks for explaining. Nice work, I hope it's accepted! 🤞

@@ -132,6 +132,9 @@ <h2 class='tagline'>Proposals</h2>
description: 'Demonstrates use of the mesh detection API in an immersive-ar session. ' +
'Implements JavaScript-level hit-test on the meshes and leverages the Anchors API.' },

{ title: 'Body tracking', category: 'AR',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my question above, doesn't seem like this is an AR-only feature? So I'd recommend using a category other than "AR" here.

Go ahead and make up something that feels appropriate. You can see from the Test Pages tab that we don't exactly stick to a rigid system here. I just don't want to give the impression that it's limited to a given session type unless it actually is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, just like hands this will also work in VR. I'll code something up

const material = new THREE.MeshLambertMaterial();

spheres = new THREE.InstancedMesh( geometry, material, body.size );
spheres.translateZ( -1 ).setRotationFromMatrix (new THREE.Matrix4().makeRotationY(Math.PI));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear on how this works, and it's probably worth a comment for developers sake.

My guess is that this is a transform applied to the entire collection of instances spheres as a sort of root transform? If so, how does this result in the behavior in the video you linked, which appears to mirror your movements rather than show them rotated 180? (Although to be fair you never really moved your hands one at a time, so it's hard to tell. Full body movement suggests a mirror instead of a rotation, though.)

In any case, more comments throughout would be welcome!

matrix.identity();
}

matrix.setPosition( -position.x, position.y, position.z );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and I see that the positions are being inverted in X here too? Is THAT what causes the mirroring effect?

const position = pose.transform.position;

if (!part.jointName.includes("hand")) {
matrix.copy(scalehand);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do hands need to be scaled up 3x? In your video it looks like the opposite, and the hands are scaled down?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wait, I see. This is checking to ensure that "hand" isn't part of the name. That's pretty confusing. Can you invert the logic here?

let space = renderer.xr.getReferenceSpace();
body.forEach(part => {

const pose = frame.getPose(part, space);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to encourage people to use fillPoses() here? Or does that introduce too many complications for an otherwise simple sample.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. I forgot about that call :-)
I will update the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants