model-viewer
model-viewer copied to clipboard
Place the object in front of the camera in XR mode (Android)
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.