ios - 在 ARKIT 中为 3D 对象添加阴影

标签 ios swift arkit

任何人都可以建议我如何以编程方式向 3D 对象添加阴影。请看下图。我想以同样的方式以编程方式在椅子下添加阴影 enter image description here .

最佳答案

    // 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

关于ios - 在 ARKIT 中为 3D 对象添加阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47273756/

相关文章:

iOS 将 ARSCNView 推送到 UINavigationController 并从中返回

ios - 从 SCNScene url 获取下载进度

ios - 替换已弃用的 -sizeWithFont :constrainedToSize:lineBreakMode: in iOS 7?

ios - ListView 的 SwiftUI .onDelete 导致应用程序崩溃

ios - 在 UICollectionViewController 的搜索栏中隐藏键盘

ios - 如何在没有SDK的情况下在iOS中集成Linkedin登录?

swift - 创建一个可复制的协议(protocol)默认初始化器

ARKit estimatedVerticalPlane HitTest 获取平面旋转

ios - UITableView:在初始滚动时使用自定义/可变单元格高度滚动到底部不准确

ios - 在 Swift 中从 NSData 读取时的 EXC_ARM_DA_ALIGN