visionOS: An Introduction

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

Lesson 02: Volumes & RealityView

Demo

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

You can start with the app in the Starter folder or continue the build from lesson one.

import RealityKit
import RealityKitContent
RealityView { content in
  if let scene = try? await Entity(named: "Scene", in: realityKitContentBundle) {
    content.add(scene)
  }
}
NavigationSplitView {
  Text("Volume Tab")
    .font(.largeTitle)
    .foregroundColor(.orange)
} detail: {
  VolumeView()
}
.tabItem {
  Image(systemName: "cube")
  Text("Volume")
}

scene.availableAnimations.forEach { animation in
  scene.playAnimation(animation.repeat(), transitionDuration: 3, startsPaused: false)
}
@State var runAnimation = false
VStack {
  Button("Start") {
    runAnimation.toggle()
  }
  //..
}
} update: { content in
    if let scene = content.entities.first {

    }
}
if runAnimation {
  scene.playAnimation(animation.repeat(), transitionDuration: 3, startsPaused: false)
} else {
  scene.stopAllAnimations()
}
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction Next: Conclusion