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

Place the object in front of the camera in XR mode (Android) #221

Open
mvaligursky opened this issue Jun 9, 2023 · 0 comments
Open

Place the object in front of the camera in XR mode (Android) #221

mvaligursky opened this issue Jun 9, 2023 · 0 comments
Labels
good first issue Good for newcomers

Comments

@mvaligursky
Copy link
Contributor

mvaligursky commented Jun 9, 2023

Currently when entering the XR, the object is placed right under the camera, forcing us to point the device down to look at it. Ideally it'd be placed in directly in front, on a detected plane. Code that could be adjusted to do this:

            let positionSet = false;
            if (scene.app.xr.isAvailable(XRTYPE_AR)) {

                scene.app.xr.on("start", () => {
                    console.log("Immersive AR session has started");

                    if (scene.app.xr.hitTest.supported) {
                        console.log("start hittest");

                        // place the mesh when a plane is detected
                        scene.app.xr.hitTest.start({
                            entityTypes: [XRTRACKABLE_POINT, XRTRACKABLE_PLANE],
                            callback: (err, hitTestSource) => {
                                if (err) {
                                    console.log("Failed to start AR hit test");
                                    return;
                                }

                                hitTestSource.on('result', function (position, rotation) {

                                    if (!positionSet) {
                                        positionSet = true;
                                        entity.setPosition(position);
                                    }
                                });
                            }
                        });
                    }
                });

We might need to back up the original position, and restore it when the XR session ends.

@mvaligursky mvaligursky added the good first issue Good for newcomers label Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant