墙上的 SceneKit 阴影 [英] SceneKit shadows on wall

查看:65
本文介绍了墙上的 SceneKit 阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 SceneKit 应用程序中有一个立方体、一堵墙和两个 lightNode,我想让立方体在墙上投下阴影.

I have a cube, a wall and two lightNodes in my SceneKit application and I would like to make the cube throw a shadow onto the wall.

我的 lightNodes 在这里:

My lightNodes are here:

    let lightNode = SCNNode()
    lightNode.light = SCNLight()
    lightNode.light!.type = SCNLightTypeSpot
    lightNode.position = SCNVector3(x: 0, y: 0, z: 15)
    lightNode.castsShadow = true
    scene.rootNode.addChildNode(lightNode)

    // create and add an ambient light to the scene
    let ambientLightNode = SCNNode()
    ambientLightNode.light = SCNLight()
    ambientLightNode.light!.type = SCNLightTypeAmbient
    ambientLightNode.light!.color = UIColor.darkGrayColor()
    ambientLightNode.castsShadow = true
    scene.rootNode.addChildNode(ambientLightNode)

这是我的墙:

    var wall = SCNNode(geometry: SCNBox(width: 400, height: 100, length: 4, chamferRadius: 0))
    wall.geometry?.firstMaterial!.emission.contents = UIColor.lightGrayColor()
    wall.geometry?.firstMaterial!.doubleSided = false
    wall.castsShadow = true
    wall.position = SCNVector3Make(0, 0, -5)
    wall.physicsBody = SCNPhysicsBody.staticBody()
    scene.rootNode.addChildNode(wall)

如您所见,所有节点(包括立方体)都具有投射阴影的属性,因为它是 true.

As you can see all of the nodes (including the cube) have the property to cast shadow, since it is true.

墙上没有影子是怎么回事?

How does it come that there is no shadow on the wall?

推荐答案

此处相同的问题?您必须在灯光上设置 castsShadow(而不是在持有灯光的节点上).

same issue as here? You have to set castsShadow on the light (instead of on the node that holds the light).

另请注意,全向光和环境光不能投射阴影.只有平行光和聚光灯可以.

Also note that omnidirectional and ambient lights can not cast shadows. Only directional and spot lights can.

这篇关于墙上的 SceneKit 阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆