簡體   English   中英

在ARKIT中為3D對象添加陰影

[英]Add shadow to a 3D Object in ARKIT

任何人都可以建議我如何以編程方式為3D對象添加陰影。 請看下面的圖片。 我想以相同的方式以編程方式在主席下添加陰影 在此輸入圖像描述

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM