我在場景中創建了一個地板,並將collada文件(.dae)加載到我的場景中,並試圖在該模型下創建一個平面。但我有像下面這樣的問題。僅當使用自定義照相機在SceneKit中場景渲染不正確
此問題產生。場景呈現在正確的系統相機即如果使用不加定製相機 我的代碼如下:
import UIKit import SceneKit class TestVC: UIViewController, SCNSceneRendererDelegate { var cameraNode: SCNNode! var modelNode: SCNNode! var scnView: SCNView! var camNode: SCNNode! var cameraPosition: SCNVector3! override func viewDidLoad() { super.viewDidLoad() scnView = SCNView(frame: self.view.frame) scnView.delegate = self view.addSubview(scnView) scnView.delegate = self let scene = SCNScene() scnView.scene = scene //camera let camera = SCNCamera() cameraNode = SCNNode() cameraNode.camera = camera camera.zFar = 1000 cameraPosition = SCNVector3(0, 100, 150) cameraNode.position = cameraPosition scene.rootNode.addChildNode(cameraNode) //floor let floor = SCNFloor() floor.reflectivity = 0 let floorNode = SCNNode(geometry: floor) let firstmaterial = SCNMaterial() firstmaterial.diffuse.contents = UIImage(named: "art.scnassets/grass.jpg") firstmaterial.diffuse.wrapS = SCNWrapMode.Repeat firstmaterial.diffuse.wrapT = SCNWrapMode.Repeat floor.materials = [firstmaterial] scene.rootNode.addChildNode(floorNode) let light = SCNLight() let lightNode = SCNNode() lightNode.light = light light.type = SCNLightTypeAmbient light.color = UIColor.darkGrayColor() scene.rootNode.addChildNode(lightNode) let light1 = SCNLight() let light1Node = SCNNode() light1Node.light = light1 light1Node.position = SCNVector3(0, 200, -100) light1.type = SCNLightTypeOmni scene.rootNode.addChildNode(light1Node) let modelScene = SCNScene(named: "Barcelona Chair.dae") let solNode = modelScene?.rootNode solNode?.eulerAngles = SCNVector3(GLKMathDegreesToRadians(-90), 0, 0) scene.rootNode.addChildNode(solNode!) scnView.allowsCameraControl = true let plane = SCNPlane(width: 100, height: 100) let planeNode = SCNNode(geometry: plane) planeNode.pivot = SCNMatrix4MakeRotation(Float(M_PI_2), 1, 0, 0)//(CGFloat(M_PI_2), 1, 0, 0) planeNode.position = SCNVector3(0, 1, 0) plane.firstMaterial?.diffuse.contents = UIColor.redColor() scene.rootNode.addChildNode(planeNode) }
這可能是這個dae特有的問題。你嘗試過另一種模式嗎?你正在運行iOS 8或9嗎?使用Metal渲染器還是GL渲染器? – Toyos
是的,我也嘗試過其他模型,但結果相同。問題發生在iOS 8和iOS 9中。 –