Actually, what I'm trying to achieve: we have map data that historically was all 2D, and the coordinate system we use is the start point (0,0) in the upper left corner, positive x goes to the right, positive y goes down. Now we added 3D data by adding the z axis, positive z came out of the screen towards you (think from top to bottom). This is the left coordinate system, but SceneKit is the right coordinate system. I would like to apply some transformation at the top level of my SceneKit scene, which converts the scene to the left coordinate system so that I can change / position / add nodes to the scene from the point of view of our custom coordinate system, and everything will just work.
So far I have this:
let scene = SCNScene()
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.scale = SCNVector3(1,-1,1)
scene.rootNode.addChildNode(cameraNode)
This is achieved exactly what I want, but it has one big problem. It inverts all faces of the geometry, so my geometry disappears if I don't change my cullMode material:
let mapLength = 1000
let mapWidth = 800
let mapHeight = 100
cameraNode.position = SCNVector3(mapLength / 2, mapWidth / 2, 2000)
let mapPlane = SCNNode()
mapPlane.position = SCNVector3(mapLength / 2, mapWidth / 2, 0)
mapPlane.geometry = SCNPlane(width: mapLength, height: mapWidth)
mapPlane.geometry?.firstMaterial?.diffuse.contents = UIColor.blackColor()
scene.rootNode.addChildNode(mapPlane)
mapPlanenot displayed at all! You must rotate the camera to the bottom side mapPlaneto see it. You can easily fix this by adding one line:
mapPlane.geometry?.firstMaterial?.cullMode = .Front
But I do not want to change cullMode for each geometry / material. Is there a way to achieve this without requiring additional code for each geometry / material? Some kind of transformation that inverts the normals of the face geometry for all child nodes of the rootNode? Ideally, this would be fully achieved by the settings on the real Stage or through conversion to rootNode or to the camera.