Skip to content

Instantly share code, notes, and snippets.

@donnywals
Created June 7, 2018 08:51
Show Gist options
  • Save donnywals/ecf25a0ddf56393ebfc58acd6aa2687a to your computer and use it in GitHub Desktop.
Save donnywals/ecf25a0ddf56393ebfc58acd6aa2687a to your computer and use it in GitHub Desktop.

Integrating Apps and Content with AR Quick Look

AR Quick look allows people to quickly place 3d models in the real world to see what they look like. Developers / designers provide a 3D model and AR Quick look does the rest. This uses quick look technologies throughout the system. On non-ARKit compatible devices the user can only explore the model, without seeing it in the real world. AR models can contain animations. Transform and skeletal animations are supported.

AR Quick look also works with accessibility and voice over. User get queues when items go off screen or when they come back on screen.

Files, mail messages, notes, news and safari have adopted AR Quick look. People can now use a special html tag to add 3d models to websites.

USDZ is a new file format for distributing 3D models in iOS. A model and textures are bundled in a single file. It’s based on Pixar’s USD format. This file format is supported on iOS and macOS and a converted is available.

You can also integrate AR Quick look in your own apps to allow people to easily view 3d models in their environment. You have control over transitions and presentation modes.

The preview flow in your apps

Create an instance of QLPreviewController and set a dataSource and a delegate. When you present the preview controller, you are asked for the number of items that need to be previewed. Then you are asked for a url for a preview item. Finally, you are asked for a view that should be the parent for the presentation of the preview controller.

You decide how the controller is presented, you can for instance push it on a navigation stack or show it modally.

The data source protocol is QLPreviewControllerDataSource. You can cast a URL to a QLPreviewItem. AR Quicklook is intended to be shown fullscreen, that’s how it works best. The transition works best if your source view has square frame because that animates very naturally.

Integrating AR content on the web

Safari on iOS now supports USDZ contents natively. If you use Apple’s suggested html markup, you automatically get a badge that indicates that the content is AR compatible.

<a rel="ar" href="model.usdz">
  <img src="preview-image.jpg">
</a>

This also works with the <picture> html element. Only rule is that you must provide a single <picture> child.

Your USDZ file must have the correct Mime-Type.

Creating USDZ files

Six things must be done when creating the model:

  1. Placement
  2. Size
  3. Animation
  4. Contact shadow
  5. Appearance
  6. Transparency

Placement

To get placement right, the object should face towards the camera. The base of the object must be on the floor and the pivot point must be configured correctly.

When rotating the option, position it as if you are placing the object in a display in the real world. When in doubt ask a child to draw the object. Children often pick the most natural orientation when drawing objects.

Size

If your object is too small or too large when you export it, it will look wrong in the real world. You must make sure that you understand and know your units in the 3D software you use.

Imaginary objects, like a funny robot should be made a size that makes them easy to position and scale.

Animation

When you make a fun model of a nice character that is alive, add an idle animation. For instance a small head bop can make a model look alive instead of boring and static. Don’t animate objects away from where they are to make sure people can easily pick it up and move it.

Animations should make sense at a static location. For instance making an object run on the spot is weird. But making a dinosaur stamp it’s feet makes sense.

A fish is a floating creature so keeping it in one place is strange. You can add a surrounding scene, like a bit of floor, to ensure that there is a nice bounding box that remains similar.

Contact shadow

Do not bake a shadow into the model. AR Quick Look will generate one based on. The environment. By default, the first frame in the model is used by AR Quick Look to generate the shadow. Make sure to pick a first frame that makes as much sense as possible.

Appearance

AR Quick Look uses a Physically Based Rendering (PBR) shader. The following is analysed by this shader:

  • Albedo (base color) RGB / RGBA
  • Metallic areas Grayscale
  • Roughness Grayscale
  • Normal (surface details) RGB
  • Internat shadows on the model Grayscale
  • Light emitters RGB

More info about this shader and using it is in the Creating Great AR Experiences talk.

Transparency

  • Transparency should be communicates through a separate material so don’t mix transparent and non-transparent in one material.
  • Transparency is communicated through a texture that has transparency in the image

Textures

  • Any image format supported by iOS can be used
  • Textures should be square, dimension should be a power of 2

Running well on all devices

Since iOS 12 is supported on many devices, iOS will take care of optimisations. Make sure to optimise for a high-power device like the iPhone X. iOS will downsample textures for slower devices. Animations and meshes will remain the same, it’s only textures that are downsized.

  • Freeze transforms and merge adjacent vertices.
  • Less materials / textures is better
  • You don’t have to provide all textures so don’t include ones you don’t need
  • Focus on areas in your texture that adds most realism
  • Be aware that pixels have a physical size in AR

Converting to USDZ

As part of Xcode 10, a command line tool to convert to USDZ is provided. It maps PBR textures textures to meshes and submeshes and accepts OBJ, Alembic and existing USD files.

A USDZ file is basically an uncompressed zip file. It contains a USDC file and all textures that are used by the model.

Basic use case:

xcrun usdz_converter source_file target_file.usdz

There are possibilities to take more control about grouping of meshes and textures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment