diff --git a/packages/model-viewer/src/features/ar.ts b/packages/model-viewer/src/features/ar.ts index 685e7523c7..451ab8453f 100644 --- a/packages/model-viewer/src/features/ar.ts +++ b/packages/model-viewer/src/features/ar.ts @@ -434,13 +434,34 @@ configuration or device capabilities'); updateSourceProgress(0.2); - const exporter = new USDZExporter(); - const arraybuffer = await exporter.parse(model); + const usdzOptions = { + ar: { + anchoring: { type: 'plane' }, + planeAnchoring: { + alignment: this.arPlacement === 'wall' ? 'vertical' : 'horizontal', + }, + }, + }; + + // necessary because quicklook internally rotates model when placing vertical. + // See https://github.com/google/model-viewer/issues/3989 + if (usdzOptions.ar.planeAnchoring.alignment === 'vertical') { + model.rotateX((-90 * Math.PI) / 180); + model.updateMatrixWorld(); + } + + const exporter = new USDZExporter() as any; + const arraybuffer = await exporter.parse(model, usdzOptions); const blob = new Blob([arraybuffer], { type: 'model/vnd.usdz+zip', }); const url = URL.createObjectURL(blob); + + if (usdzOptions.ar.planeAnchoring.alignment === 'vertical') { + model.rotateX((90 * Math.PI) / 180); + model.updateMatrixWorld(); + } updateSourceProgress(1); diff --git a/packages/modelviewer.dev/examples/augmentedreality/index.html b/packages/modelviewer.dev/examples/augmentedreality/index.html index e49ec6081d..bd81118de6 100644 --- a/packages/modelviewer.dev/examples/augmentedreality/index.html +++ b/packages/modelviewer.dev/examples/augmentedreality/index.html @@ -360,6 +360,8 @@
ar-placement
attribute, which defaults to "floor", but using "wall" gives a different AR placement experience.QuickLook will ignore this attribute if a .usdz or .reality model is supplied through ios-src
and instead look at the planeAnchoring:alignment
option
+ inside the USDZ file.