Instruction

Building to Vision Pro

In January 2024, Apple announced Vision Pro devices would be available in U.S. Apple Stores. The basic developer configuration is done by pairing the Vision Pro with your Mac. Vision Pro ships without the optional USB-C interface, which at the time of writing, is also only available to U.S.-based developers.

In order to build the app to the device, you’ll need to change the configuration to the build settings, as you would for iOS devices. To begin, click Xcode in the menu bar and go to Settings… then Accounts. If you don’t see your developer Apple ID, click + and log in. After logging in, open the starter project and select the project file at the top of the Project Navigator. Under the Signing and Capabilities tab, select your team and enter a reverse domain name before the app name. This will be the Bundle Identifier of this build, which is needed to build to the Vision Pro.

If you don’t have the optional Developer Strap for the Vision Pro then you’ll need to pair your Vision Pro and your Mac. To pair your Vision Pro and Mac, go to Settings on the Vision Pro. In the General tab, scroll down to Remote Devices. Select your Mac to begin pairing.

Note: In most cases, you don’t need the Developer Strap to build to the Vision Pro from Xcode. You can pair your devices and build. It uses WiFi to communicate but it’s not that much slower. If your network restricts pairing because of a security policy, you may need the strap. You could also push builds to TestFlight or Xcode Cloud in a pinch.

Back in Xcode, go to Devices and Simulators under the Window menu. Make sure the Vision Pro and your Mac are on the same WiFi network. The Vision Pro may appear under the Disconnected section. Select your Vision Pro and click the Pair button. Enter the pairing code from the Vision Pro on your Mac. After you follow these steps, the Developer Mode will appear at the bottom of the Privacy and Security section of the Settings app. You’ll be required to reboot the Vision Pro after you flip the toggle to “on”.

RealityKit Physics 101

Vision Pro is phenomenal for watching Immersive 3D movies, TV and film — as well as for getting work done. The real fun of using the Vision Pro is interacting with virtual objects as if they’re in the real world. Using RealityKit, you’ve seen that you can put virtual objects into the viewer’s environment. The next three lessons will delve into making and interacting with Entities.

In the previous lesson, you learned how to make a sphere, apply material components and apply gravity to it. You used physics components to do that. In order for virtual objects to behave like real world objects, you can refine the properties in the physics component.

You may be familiar with a wooden toy labyrinth. Building a complete labyrinth is beyond the scope of this lesson, but you can build a section and tilt it to get a sense of the game mechanics.

Giving your ball entity mass will make it behave like a real ball bearing. In RealityKit, mass is measured in kilograms. When you start to tilt the surface, the ball won’t fly off if it has some mass.

RealityKit also lets you define or generate three key properties that affect relative motion: staticFriction, dynamicFriction, and restitution.

Static friction is the stickiness, or resistance to move, of the object versus the force applied to it. Here you’ll use the gravity you already enabled to move the ball as you tilt the surface it sits on. A higher value applied will mean the ball will need more force to move it.

Dynamic friction is how likely the ball is to slow down once it’s moving. A higher value here means the ball would come to rest sooner. Naturally a square block would have greater dynamic friction than a ball.

Restitution is how bouncy the object is. A rubber ball would have a high restitution, but a steel ball or a rock would have a low restitution. A steel ball can bounce but not as well as a rubber ball would.

In the lesson, you’ll create a surface above the floor to rest the ball on. Once at rest, you’ll need to tilt the surface to let the force of gravity move the ball. Here, you’ll use a transform to rotate the surface. To roll the ball left and right, rotate the ball about the z-axis. There are a few ways to rotate objects in RealityKit.

In the Introduction the visionOS, you used simd_quatf to move the biplane in an orbital direction. simd_quatf is a a single-precision quaternion - a set of four numbers, or homogenous coordinates w, x, y, z, common in 3D graphics. This gets into 4-dimensional math and isn’t needed in this example.

You just want to tilt the surface, right? In this case, you can use a simpler rotation system. An entity can be rotated around the x, y and z axes with pitch, yaw and roll, respectively. In this example, you can “roll” the surface on the z-axis and the ball will roll left or right. These terms are common in air flight. Imagine you’re flying a plane. To turn the nose up or down, you pitch the plane, on the x-axis. To turn the plane to the left or right, you use yaw on the y-axis. Therefore, roll would be rotating on the z-axis.

The last thing you’ll want to add is some signage for the user on how to move the ball. You’ll use another part of a RealityView - the accessory closure - to add some text for the user.

Continue on to the next section, where you’ll learn how to build the app in Xcode and run it on the Simulator or Vision Pro hardware.

See forum comments
Download course materials from Github
Previous: Introduction Next: Demo