Как спроецировать тени на сетчатую среду в RealityKit?

#augmented-reality #lighting #realitykit #lidar #usdz

#дополненная реальность #Освещение #realitykit #лидар #usdz

Вопрос:

Я использую RealityKit в сочетании с моделью USDZ и пониманием сцены (LiDAR iPhone) и просто хочу, чтобы моя модель проецировала несколько хороших теней на реальную среду. Я могу легко получить пользовательский прожектор для своей модели, но не могу проецировать какие-либо тени от моего ит.

Я застрял с тем, что кажется нисходящим освещением по умолчанию. Что я делаю не так?

Мой код:

 override func viewDidLoad() {

    super.viewDidLoad()

    arView.session.delegate = self
    arView.environment.sceneUnderstanding.options = []
    arView.environment.sceneUnderstanding.options.insert(.receivesLighting)

    arView.automaticallyConfigureSession = false
    let configuration = ARWorldTrackingConfiguration()
    configuration.planeDetection = [.horizontal, .vertical]
    configuration.sceneReconstruction = .mesh
    configuration.environmentTexturing = .automatic

    arView.session.run(configuration) }
 

Вот функция, которую я вызываю при добавлении модели

 @IBAction func addMyModel(_ sender: Any) {

    do {
        let mymodel = try ModelEntity.load(named: "mymodel")
        
        // Lights
        let spotLight = CustomSpotLight()
        let anchor = AnchorEntity(plane: .horizontal, minimumBounds: [0.30, 1.00])
        
        anchor.children.append(mymodel)
        anchor.addChild(spotLight)
        
        self.arView.scene.anchors.append(anchor)
        
    } catch {
        fatalError("Failed to load asset.")
    }
}
 

и, наконец, вот мой пользовательский код spotlight:

 import ARKit
import RealityKit

class CustomSpotLight: Entity, HasSpotLight {
    required init() {
        super.init()
        self.light = SpotLightComponent(color: .blue,
                                    intensity: 500000,
                          innerAngleInDegrees: 45,
                          outerAngleInDegrees: 169,
                            attenuationRadius: 9.0)
        
        self.shadow = SpotLightComponent.Shadow()
        self.position.y = 5.0
        self.orientation = simd_quatf(angle: -.pi/1.5,
                                       axis: [1,0,0])
 
    }
}