简单的SceneKit场景显示黑屏而不是SCNPlane

时间:2014-10-13 08:11:58

标签: swift scenekit

我正在尝试使用iOS SceneKit,但是以下示例代码(在viewDidLoad内执行)的行为不符合预期。我想要它

  1. 将相机放置在原点,方向为正z轴
  2. 在z = 100
  3. 处放置一个与xy平面平行的红色矩形

    为什么渲染不显示红色矩形而只显示黑屏?

        let scene = SCNScene()
    
        // prepare camera
    
        let camera = SCNCamera()
        camera.zNear =  90
        camera.zFar  = 110
    
        let cameraNode = SCNNode()
        cameraNode.position = SCNVector3Make(0, 0, 0)
        cameraNode.rotation = SCNVector4Make(1, 0, 0, Float(M_PI))
        cameraNode.camera   = camera
    
        scene.rootNode.addChildNode(cameraNode)
    
        // prepare light
    
        let light = SCNLight()
        light.type  = SCNLightTypeOmni
        light.color = SKColor(white: 0.3, alpha: 1.0)
    
        let lightNode = SCNNode()
        lightNode.light = light;
    
        scene.rootNode.addChildNode(lightNode)
    
        // prepare plane
    
        let plane = SCNPlane(width: 400, height: 400)
        plane.firstMaterial!.doubleSided      = true
        plane.firstMaterial!.diffuse.contents = UIColor.redColor().CGColor
    
        let planeNode = SCNNode(geometry: plane)
        planeNode.position = SCNVector3Make(0, 0, 100)
    
        scene.rootNode.addChildNode(planeNode)
    
        // prepare view as SCNView
    
        let sceneView = view as SCNView
    
        sceneView.backgroundColor  = SKColor.blackColor()
        sceneView.scene            = scene
        sceneView.delegate         = self
        sceneView.jitteringEnabled = true // i.e. improve visual rendering
        sceneView.pointOfView      = cameraNode
    

1 个答案:

答案 0 :(得分:1)

看起来像围绕x轴而不是y轴旋转(以便相机看起来朝向所需方向)