-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Satoshi Hattori
committed
May 24, 2024
1 parent
f2b36d7
commit 3e71840
Showing
5 changed files
with
22 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file was deleted.
Oops, something went wrong.