Ios 平行光受摄像头影响';运动

Ios 平行光受摄像头影响';运动,ios,scenekit,augmented-reality,arkit,Ios,Scenekit,Augmented Reality,Arkit,我想实现像宜家家居那样的阴影效果,在那里,阴影与虚拟对象粘在一起 这是我的实现。我向虚拟对象添加了方向光和阴影平面。当我在场景中移动虚拟对象时,阴影没有定位在虚拟对象底部的正下方 这是我的密码: func setupShadows() { let flourPlane = SCNFloor() let groundPlane = SCNNode() let groundMaterial = SCNMaterial() groundMaterial.lighti

我想实现像宜家家居那样的阴影效果,在那里,阴影与虚拟对象粘在一起

这是我的实现。我向虚拟对象添加了方向光和阴影平面。当我在场景中移动虚拟对象时,阴影没有定位在虚拟对象底部的正下方

这是我的密码:

func setupShadows() {

    let flourPlane = SCNFloor()
    let groundPlane = SCNNode()
    let groundMaterial = SCNMaterial()
    groundMaterial.lightingModel = .constant
    groundMaterial.writesToDepthBuffer = true
    groundMaterial.readsFromDepthBuffer = true
    groundMaterial.colorBufferWriteMask = []
    flourPlane.materials = [groundMaterial]
    groundPlane.geometry = flourPlane
    addChildNode(groundPlane)

    // Create a ambient light
    let ambientLight = SCNNode()
    ambientLight.light = SCNLight()
    ambientLight.light?.shadowMode = .deferred
    ambientLight.light?.color = UIColor.white
    ambientLight.light?.type = .ambient
    addChildNode(ambientLight)

    // Create a directional light node with shadow
    let directionalLightNode = SCNNode()
    directionalLightNode.light = SCNLight()
    directionalLightNode.light?.type = .directional
    directionalLightNode.light?.color = UIColor.white
    directionalLightNode.light?.castsShadow = true
    directionalLightNode.light?.automaticallyAdjustsShadowProjection = true
    directionalLightNode.light?.shadowMode = .deferred
    directionalLightNode.light?.categoryBitMask = -1
    directionalLightNode.light?.shadowColor = UIColor.black.withAlphaComponent(0.4)
    directionalLightNode.rotation = SCNVector4(x: 1, y: 0, z: 0, w: .pi * 1.5)
    addChildNode(directionalLightNode)
}

我想SceneKit或ARKit中可能有一个bug。我在iOS 12.3上测试过,没问题。但在13.1上,它不是。请发布所有代码。@ARGeo感谢您的评论。下面是我如何设置灯光的。可以使用椅子模型测试阴影。这是苹果公司提供的示例项目。我尝试了不同的场景,但没有得到您所说的问题。你的密码是什么?不是你给我的苹果密码。