Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Creating a Snow Globe in visionOS: From Idea to...

Jane Chao
January 15, 2025

Creating a Snow Globe in visionOS: From Idea to Reality Composer Pro

@iosconfsg 2025

Jane Chao

January 15, 2025
Tweet

Other Decks in Programming

Transcript

  1. SwiftUI Path Extrusion var options = MeshResource.ShapeExtrusionOptions() options.extrusionMethod = .linear(depth:

    0.1) options.chamferRadius = 0.05 let mesh = try await MeshResource(extruding: path, extrusionOptions: options) Code will be shared at the end
  2. Add Force 􀊖 Animation 􀄯 Billboard 􀃳 Disable / Enable

    Entity 􀇯 Emphasize 􀋮 Hide / Show 􀖀 Noti fi cation 􁹠 Orbit 􀙫 Play Audio 􀅌 Replace Behaviors 􀊯 Spin 􀢅 Transform By/To Action
  3. Receive Noti fi cations let realityKitNotifications = NotificationCenter.default .notifications( named:

    Notification.Name( "RealityKit.NotificationTrigger" ) ) for await notification in realityKitNotifications { guard let triggerID = notification.userInfo?[“RealityKit.NotificationTrigger.Identifier"] else { ... } switch triggerID { case "PrintHello": print("Hello") ... } } Code will be shared at the end
  4. Behavior Source 􀖀 Noti fi Center Post noti fi “PleaseStopTrain”

    onNoti fi “PleaseStopTrain” Action StopTheTrain Trigger
  5. Post Noti fi cation @Environment(\.realityKitScene) private var scene guard let

    scene else { print(“❌ Cannot post notification without a scene") return } NotificationCenter.default.post( name: Notification.Name("RealityKit.NotificationTrigger"), object: nil, userInfo: [ "RealityKit.NotificationTrigger.Scene": scene as Any, "RealityKit.NotificationTrigger.Identifier": "PleaseStopTrain" ] ) Code will be shared at the end
  6. RealityView { content in guard let snowGlobe = try? await

    Entity(named: "Scene", in: realityKitContentBundle), let button = scene.findEntity(named: "Button"), let steamParticleEmitter = scene.findEntity(named: "Steam_ParticleEmitter") else { print("❌ model not found.") return } content.add(snowGlobe) self.snowGlobe = snowGlobe self.button = button self.steamParticleEmitter = steamParticleEmitter } Add &
  7. .gesture( TapGesture() .targetedToEntity(button) .onEnded { _ in // you may

    have some logic check here guard button.applyTapForBehaviors() else { print("❌ OnTap Behavior not found") return } } ) Trigger
  8. Recap • Create some simple 3D icon or object with

    extrusion & box modeling • Snow globe is a fun weekend project • Special thanks to my teammate Mia ❤ Slides & code