I have been looking into SceneKit for iOS over the past couple of days. I came across an issue when trying to create custom geometry. Whenever I tried to display the geometry, it would not draw, and show me this error during runtime.
SceneKit: error, C3DRendererContextSetupResidentMeshSourceAtLocation - double not supported
I created a playground targeting iOS to test a more simple example of custom geometry, and looked into this question about custom geometry using swift vs objective c.
I tried another project using objective c and still received the same error message.
The error does not appear when targeting the desktop on either the playground or a full project, and the geometry draws correctly. Only when targeting iOS does the error message occur.
import SceneKit
import QuartzCore // for the basic animation
import XCPlayground // for the live preview
// create a scene view with an empty scene
var sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
var scene = SCNScene()
sceneView.scene = scene
// start a live preview of that view
XCPShowView("The Scene View", sceneView)
// default lighting
sceneView.autoenablesDefaultLighting = true
// a camera
var camera = SCNCamera()
var cameraNode = SCNNode()
cameraNode.camera = camera
cameraNode.position = SCNVector3(x: 0, y: 0, z: 10)
scene.rootNode.addChildNode(cameraNode)
// create geometry
var verts = [SCNVector3(x: 0,y: 0,z: 0),SCNVector3(x: 1,y: 0,z: 0),SCNVector3(x: 0,y: 1,z: 0)]
let src = SCNGeometrySource(vertices: &verts, count: 3)
let indexes: [CInt] = [0, 1, 2]
let dat = NSData(
bytes: indexes,
length: sizeof(CInt) * countElements(indexes)
)
let ele = SCNGeometryElement(
data: dat,
primitiveType: .Triangles,
primitiveCount: 1,
bytesPerIndex: sizeof(CInt)
)
let geo = SCNGeometry(sources: [src], elements: [ele])
let nd = SCNNode(geometry: geo)
scene.rootNode.addChildNode(nd)
Here is the code I am using in the playground to draw a triangle. The same code is used when targeting the desktop.
How can I fix this and display the geometry for iOS?