Skip to content

Commit

Permalink
fix: day24
Browse files Browse the repository at this point in the history
  • Loading branch information
Satoshi Hattori committed May 24, 2024
1 parent f2b36d7 commit 3e71840
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 66 deletions.
4 changes: 0 additions & 4 deletions Day24/Day24.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
8E9DD1612A82C9C800E8B32F /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E9DD1602A82C9C800E8B32F /* ContentView.swift */; };
8E9DD1632A82C9C800E8B32F /* ImmersiveView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E9DD1622A82C9C800E8B32F /* ImmersiveView.swift */; };
8E9DD1682A82C9CB00E8B32F /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8E9DD1672A82C9CB00E8B32F /* Preview Assets.xcassets */; };
8E9DD16F2A82D43200E8B32F /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E9DD16E2A82D43200E8B32F /* ViewModel.swift */; };
8E9DD1722A82E12400E8B32F /* ayutthaya.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 8E9DD1712A82E12400E8B32F /* ayutthaya.mp4 */; };
8EE7DD812A862B59004A1D14 /* Sphere.usda in Resources */ = {isa = PBXBuildFile; fileRef = 8EE7DD802A862B59004A1D14 /* Sphere.usda */; };
/* End PBXBuildFile section */
Expand All @@ -22,7 +21,6 @@
8E9DD1602A82C9C800E8B32F /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
8E9DD1622A82C9C800E8B32F /* ImmersiveView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImmersiveView.swift; sourceTree = "<group>"; };
8E9DD1672A82C9CB00E8B32F /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
8E9DD16E2A82D43200E8B32F /* ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModel.swift; sourceTree = "<group>"; };
8E9DD1712A82E12400E8B32F /* ayutthaya.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = ayutthaya.mp4; sourceTree = "<group>"; };
8EE7DD802A862B59004A1D14 /* Sphere.usda */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Sphere.usda; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -59,7 +57,6 @@
children = (
8E9DD1702A82E0FD00E8B32F /* Resources */,
8E9DD15E2A82C9C800E8B32F /* Day24App.swift */,
8E9DD16E2A82D43200E8B32F /* ViewModel.swift */,
8E9DD1602A82C9C800E8B32F /* ContentView.swift */,
8E9DD1622A82C9C800E8B32F /* ImmersiveView.swift */,
8E9DD1662A82C9CB00E8B32F /* Preview Content */,
Expand Down Expand Up @@ -159,7 +156,6 @@
files = (
8E9DD1612A82C9C800E8B32F /* ContentView.swift in Sources */,
8E9DD15F2A82C9C800E8B32F /* Day24App.swift in Sources */,
8E9DD16F2A82D43200E8B32F /* ViewModel.swift in Sources */,
8E9DD1632A82C9C800E8B32F /* ImmersiveView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
4 changes: 1 addition & 3 deletions Day24/Day24/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import RealityKit

struct ContentView: View {

var viewModel: ViewModel

@State private var showImmersiveSpace = false

@Environment(\.openImmersiveSpace) var openImmersiveSpace
Expand All @@ -30,5 +28,5 @@ struct ContentView: View {
}

#Preview {
ContentView(viewModel: ViewModel())
ContentView()
}
6 changes: 2 additions & 4 deletions Day24/Day24/Day24App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import SwiftUI
@main
struct Day24App: App {

@State private var viewModel = ViewModel()

var body: some Scene {
WindowGroup {
ContentView(viewModel: viewModel)
ContentView()
}

ImmersiveSpace(id: "ImmersiveSpace") {
ImmersiveView(viewModel: viewModel)
ImmersiveView()
}.immersionStyle(selection: .constant(.full), in: .full)
}
}
33 changes: 19 additions & 14 deletions Day24/Day24/ImmersiveView.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import SwiftUI
import RealityKit
import AVFoundation

struct ImmersiveView: View {

var viewModel: ViewModel

var body: some View {
RealityView { content in
content.add(viewModel.setupContentEntity())
}
.onAppear() {
viewModel.play()
}
.onDisappear() {
viewModel.pause()

let avPlayer = AVPlayer()

let url = Bundle.main.url(forResource: "ayutthaya", withExtension: "mp4")!
let asset = AVAsset(url: url)
let playerItem = AVPlayerItem(asset: asset)

let material = VideoMaterial(avPlayer: avPlayer)

let videoEntity = Entity()
videoEntity.components.set(ModelComponent(mesh: .generateSphere(radius: 1E3), materials: [material]))
videoEntity.scale *= SIMD3(-1, 1, 1)
videoEntity.orientation *= simd_quatf(angle: .pi / 2, axis: [0, 1, 0])

content.add(videoEntity)

avPlayer.replaceCurrentItem(with: playerItem)
avPlayer.play()
}
}
}

#Preview {
ImmersiveView(viewModel: ViewModel())
.previewLayout(.sizeThatFits)
}
41 changes: 0 additions & 41 deletions Day24/Day24/ViewModel.swift

This file was deleted.

0 comments on commit 3e71840

Please sign in to comment.