【问题标题】:Add shadow to a 3D Object in ARKIT在 ARKIT 中为 3D 对象添加阴影
【发布时间】:2018-07-21 05:56:11
【问题描述】:

谁能建议我如何以编程方式向 3D 对象添加阴影。请看下图。我想以同样的方式以编程方式在椅子下添加阴影。

【问题讨论】:

  • 你发现了吗?
  • 你能弄清楚吗>

标签: ios swift arkit


【解决方案1】:
    // To Add Shadow on 3D Model Just Copy Paste this code and it will appear a shadow of 3D Model on Ground

    let flourPlane = SCNFloor()
    let groundPlane = SCNNode()
    let groundMaterial = SCNMaterial()
    groundMaterial.lightingModel = .constant
    groundMaterial.writesToDepthBuffer = true
    groundMaterial.colorBufferWriteMask = []
    groundMaterial.isDoubleSided = true
    flourPlane.materials = [groundMaterial]
    groundPlane.geometry = flourPlane
    //
    mainNode.addChildNode(groundPlane)
    // Create a ambient light
    let ambientLight = SCNNode()
    ambientLight.light = SCNLight()
    ambientLight.light?.shadowMode = .deferred
    ambientLight.light?.color = UIColor.white
    ambientLight.light?.type = SCNLight.LightType.ambient
    ambientLight.position = SCNVector3(x: 0,y: 5,z: 0)
    // Create a directional light node with shadow
    let myNode = SCNNode()
    myNode.light = SCNLight()
    myNode.light?.type = SCNLight.LightType.directional
    myNode.light?.color = UIColor.white
    myNode.light?.castsShadow = true
    myNode.light?.automaticallyAdjustsShadowProjection = true
    myNode.light?.shadowSampleCount = 64
    myNode.light?.shadowRadius = 16
    myNode.light?.shadowMode = .deferred
    myNode.light?.shadowMapSize = CGSize(width: 2048, height: 2048)
    myNode.light?.shadowColor = UIColor.black.withAlphaComponent(0.75)
    myNode.position = SCNVector3(x: 0,y: 5,z: 0)
    myNode.eulerAngles = SCNVector3(-Float.pi / 2, 0, 0)
    // Add the lights to the container
    mainNode.addChildNode(ambientLight)
    mainNode.addChildNode(myNode)
    // End

【讨论】:

  • 太棒了!您为我节省了几天的工作时间...非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-12
  • 1970-01-01
  • 2018-07-13
  • 2018-03-21
  • 2021-02-19
  • 2018-01-05
  • 1970-01-01
相关资源
最近更新 更多