Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve SceneKit double not supported error?

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?

like image 616
ADDicting Avatar asked Feb 11 '23 14:02

ADDicting


2 Answers

I solved the error by changing how I was creating the geometry source.

By following this question's method of creating the geometry sources the error was fixed and the triangle drew properly.

I believe the solution was in using

+ (instancetype)geometrySourceWithData:(NSData *)data
                              semantic:(NSString *)semantic
                           vectorCount:(NSInteger)vectorCount
                       floatComponents:(BOOL)floatComponents
                   componentsPerVector:(NSInteger)componentsPerVector
                     bytesPerComponent:(NSInteger)bytesPerComponent
                            dataOffset:(NSInteger)offset
                            dataStride:(NSInteger)stride

instead of

+ (instancetype)geometrySourceWithVertices:(const SCNVector3 *)vertices
                                     count:(NSInteger)count

because it specifies that I am using float components instead of double.

like image 111
ADDicting Avatar answered Feb 14 '23 10:02

ADDicting


My guess would be an issue with SCNVector3 being defined in terms of CGFloat for desktop (which can be either 32 or 64 bit depending on the host) and Float for iOS devices -- the iOS Simulator platform (which is what you get when targeting iOS in a playground) is neither quite like a device nor quite like OS X. Filing a bug with Apple would be a good idea.

In the meantime, a good workaround might be to use the more detailed initializer (that starts with init(data:semantic:...) to create your geometry source.

like image 42
rickster Avatar answered Feb 14 '23 09:02

rickster