Skip to content

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

@mvaligursky

Description

@mvaligursky

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions