I am new to SceneKit. I am trying to set a texture whose representation is drawn with SCNSphere code. The custom view is as follows:
class CustomView : UIView { override func drawRect(rect: CGRect) { let ctx = UIGraphicsGetCurrentContext() let centerX = self.bounds.width / 2 let centerY = self.bounds.height / 2
The view is as follows: 
To set this view as an SCNSphere texture, I took its layer and set it to contents firstMaterial .
class MyViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let sceneView = self.view as SCNView let scene = SCNScene() sceneView.scene = scene sceneView.backgroundColor = UIColor.blackColor() sceneView.autoenablesDefaultLighting = true let cameraNode = SCNNode() cameraNode.camera = SCNCamera() cameraNode.position = SCNVector3(x: 0, y: 0, z: 4) scene.rootNode.addChildNode(cameraNode) let sphere = SCNSphere(radius: 1) let customView = CustomView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) sphere.firstMaterial?.diffuse.contents = customView.layer let sphereNode = SCNNode(geometry: sphere) scene.rootNode.addChildNode(sphereNode) } }
I expect the layer to cover the entire scope, but this is what I get:

Only part of the sphere is drawn. If I comment on the entire code of the user drawing and put customView.backgroundColor = UIColor.whiteColor() instead, then I get the whole sphere covered with white.
Please tell me what I'm doing wrong here. Thanks in advance!
source share