Why {videoPlayerComponent.playerScreenSize} cannot get right to the size of the video, print out the x and y is [0, 0], is this a BUG?
Post
Replies
Boosts
Views
Activity
I have updated to Xcode 15.1 Release Candidate, and I am unable to run the vision emulator. What is the situation
I have configured ARKit and PlaneDetectionProvider, but after running the code in the simulator, PlaneEntity is not displayed correctly
import Foundation
import ARKit
import RealityKit
class PlaneViewModel: ObservableObject{
var session = ARKitSession()
let planeData = PlaneDetectionProvider(alignments: [.horizontal])
var entityMap: [UUID: Entity] = [:]
var rootEntity = Entity()
func start() async {
do {
if PlaneDetectionProvider.isSupported {
try await session.run([planeData])
for await update in planeData.anchorUpdates {
if update.anchor.classification == .window { continue }
switch update.event {
case .added, .updated:
updatePlane(update.anchor)
case .removed:
removePlane(update.anchor)
}
}
}
} catch {
print("ARKit session error \(error)")
}
}
func updatePlane(_ anchor: PlaneAnchor) {
if entityMap[anchor.id] == nil {
// Add a new entity to represent this plane.
let entity = ModelEntity(
mesh: .generateText(anchor.classification.description)
)
entityMap[anchor.id] = entity
rootEntity.addChild(entity)
}
entityMap[anchor.id]?.transform = Transform(matrix: anchor.originFromAnchorTransform)
}
func removePlane(_ anchor: PlaneAnchor) {
entityMap[anchor.id]?.removeFromParent()
entityMap.removeValue(forKey: anchor.id)
}
}
var body: some View {
@stateObject var planeViewModel = PlaneViewModel()
RealityView { content in
content.add(planeViewModel.rootEntity)
}
.task {
await planeViewModel.start()
}
}