Post

Replies

Boosts

Views

Activity

Reply to How do I change the background color of a visionOS immersive space?
import SwiftUI import RealityKit import RealityKitContent import AVFoundation struct ImmersiveView: View { var body: some View { RealityView { content in guard let resource = try? TextureResource.load(named: "Starfield") else { fatalError("加载纹理贴图失败") } var material = UnlitMaterial() material.color = .init(texture: .init(resource)) let environment = Entity() environment.components.set(ModelComponent( mesh: .generateSphere(radius: 1000), materials: [material] )) environment.scale *= .init(x: -1, y: 1, z: 1) let timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in let radians = Float.pi / 180.0 let rotation = simd_quatf(angle: radians, axis: SIMD3<Float>(0,1,0)) / environment.move(to: Transform(rotation: rotation), relativeTo: environment, duration: 10, timingFunction: .linear) } RunLoop.current.add(timer, forMode: .default) content.add(environment) } } }
Dec ’23
Reply to AVPlayerVideoOutput on visionOS
maybe try let entity = Entity() let url = URL(string: url) let asset = AVURLAsset(url: url!) let playerItem = AVPlayerItem(asset: asset) let player = AVPlayer() var videoPlayerComponent = VideoPlayerComponent(avPlayer: player) videoPlayerComponent.isPassthroughTintingEnabled = true entity.components[VideoPlayerComponent.self] = videoPlayerComponent entity.scale *= 1 player.replaceCurrentItem(with: playerItem) player.play() return entity } @state var urlString = "" RealityView{content in content.add(makeMvEntity(url: urlString)) }
Nov ’23
Reply to Add light to a RealityView on visionOS
var body: some View { RealityView { content in // Add the Model content if let modelEntity = try? await Entity(named: "Victorian_Living_Room", in: realityKitContentBundle) { content.add(immersiveContentEntity) // Add an ImageBasedLight for the immersive content guard let resource = try? await EnvironmentResource(named: "shiwai_a") else { return } //An ImageBasedLightReceiverComponent has been set up for this entity, which enables the entity to receive image-based lighting. let iblComponent = ImageBasedLightComponent(source: .single(resource), intensityExponent: 0.25) modelEntity.components.set(iblComponent) modelEntity.components.set(ImageBasedLightReceiverComponent(imageBasedLight: modelEntity)) } } } }
Nov ’23