gpt4 book ai didi

ios - 如何添加阴影平面以及苹果提供的和我们创建的.scn文件的区别

转载 作者:行者123 更新时间:2023-11-28 09:31:51 26 4
gpt4 key购买 nike

在我使用 Xcode 为我的项目创建的 .scn 文件中,该文件在透视图中看起来像这样(附件中包含导弹文件)。但在 apple 在 ARKit 示例项目中提供的 .scn 模型中,平面和文件看起来差别很大。它有一个阴影平面,而且 View 看起来也完全不同。所以我的问题是,1. 如何在我的文件中添加阴影平面,它有什么用。2.这两个文件有什么区别。一个苹果给了我,一个是我创造的。3. 创建 AR 应用程序的最佳实践。

1.Apple 提供的图像 1.The image Apple provides,

2.我创建的文件(来源:turbosquid.com)

2.The file I created (source: turbosquid.com)谢谢

最佳答案

转换阴影的方式有两种:

  1. 首先在模型(或检测到的平面)下放置一个平面,将其colorBufferWriteMask设置为SCNColorMask(0)。使用 spotlight 并将其 castsShadow 设置为 true 并将 shadowMode 设置为 deferred。

    override func viewDidLoad() {

    // setup ARScene

    // Disable automatic lighting
    sceneView.autoenablesDefaultLighting = false
    sceneView.automaticallyUpdatesLighting = false

    // create secondary light
    lightNode.light = SCNLight()
    lightNode.light!.type = .omni
    lightNode.position = SCNVector3(x: 0, y: 1, z: 1)
    scene.rootNode.addChildNode(lightNode)

    // create main light that cast shadow
    lightNode2.light = SCNLight()
    lightNode2.light!.type = .spot
    lightNode2.position = SCNVector3(x: -1, y: 10, z: 1)
    lightNode2.eulerAngles = SCNVector3(-Float.pi/2, 0, 0)
    lightNode2.light?.castsShadow = true // to cast shadow
    lightNode2.light?.shadowMode = .deferred // to render shadow in transparent plane
    lightNode2.light?.shadowSampleCount = 64 //remove flickering of shadow and soften shadow
    lightNode2.light?.shadowMapSize = CGSize(width: 2048, height: 2048) //sharpen or detail shadow
    scene.rootNode.addChildNode(lightNode2)

    // create ambient light
    ambientLightNode.light = SCNLight()
    ambientLightNode.light!.type = .ambient
    ambientLightNode.light!.color = UIColor.darkGray
    scene.rootNode.addChildNode(ambientLightNode)
    }

    // match the lighting with real world
    func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
    if let estimate = sceneView.session.currentFrame?.lightEstimate{
    lightNode2.light?.intensity = estimate.ambientIntensity
    lightNode2.light?.temperature = estimate.ambientColorTemperature
    lightNode.light?.intensity = estimate.ambientIntensity/3
    lightNode.light?.temperature = estimate.ambientColorTemperature
    }
    }

    // place transparent plane to capture shadow
    func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
    if anchor is ARPlaneAnchor{

    // place object on the detected plane anchor

    // place shadow plane under your object
    let shadowPlane = SCNPlane(width: 2, height: 2)
    shadowPlane.materials.first?.colorBufferWriteMask = SCNColorMask(rawValue:0)
    let shadowPlaneNode = SCNNode(geometry: shadowPlane)
    planeNode.transform = SCNMatrix4MakeRotation(-Float.pi/2, 1, 0, 0) // because plane is created vertical
    node.addChildNode(shadowPlaneNode)
    }
    }
  2. 在 apples 项目中使用带有阴影纹理的平面。盘子的scn文件和勺子和杯子的盘子里都有一个阴影平面。如果你和他们一起玩,你就能看到它。

enter image description here

唯一的区别是苹果知道如何巧妙地让他们的模型看起来自然。使用阴影平面,PBR。
对于最佳实践,这取决于您要实现的目标。

关于ios - 如何添加阴影平面以及苹果提供的和我们创建的.scn文件的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48090797/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com