visionOS: An Introduction

Nov 21 2023 · Swift 5.9, visionOS 1.0 beta, Xcode 15

Lesson 03: Building an Immersive View

Demo Part 2

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Carry on with the build from lesson 3, part 1.

let orbit = OrbitAnimation(duration: 20.0,
axis: SIMD3<Float>(x: 0.1, y: 1.0, z: 0.0),
startTransform: scene.transform,
spinClockwise: false,
orientToPath: true,
rotationCount: 1.0,
bindTarget: .transform,
repeatMode: .repeat)

if let animation = try? AnimationResource.generate(with: orbit) {
  scene.playAnimation(animation)
}
scene.orientation = simd_quatf(angle: Float.pi/4, axis: [-0.5, 0.0, 0.0])
RealityView { content in
    guard let resource = try? await TextureResource(named: "skyView") else {
      return
    }
    var material = UnlitMaterial()
    material.color = .init(texture: .init(resource))

    let entity = Entity()
    entity.components.set(ModelComponent(mesh: .generateSphere(radius: 1000), materials: [material]
    ))
    // point the texture inwards
    entity.scale *= .init(x: -1, y: 1, z: 1)

    content.add(entity)
}

guard let resource = try? await EnvironmentResource(named: "Sunlight") else { return }
let iblComponent = ImageBasedLightComponent(source: .single(resource), intensityExponent: 2.0)
scene.components.set(iblComponent)
scene.components.set(ImageBasedLightReceiverComponent(imageBasedLight: scene))
See forum comments
Cinema mode Download course materials from Github
Previous: Demo Part 1 Next: Conclusion