如何解决SceneKit double不支持的错误? [英] How to solve SceneKit double not supported error?

查看:193
本文介绍了如何解决SceneKit double不支持的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几天里,我一直在研究SceneKit for iOS。我在尝试创建自定义几何时遇到了一个问题。每当我尝试显示几何体时,它都不会绘制,并在运行时显示此错误。

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:错误,C3DRendererContextSetupResidentMeshSourceAtLocation - 不支持double

SceneKit: error, C3DRendererContextSetupResidentMeshSourceAtLocation - double not supported

我创建了一个针对iOS的游乐场,以测试更简单的自定义几何示例,并查看了这个问题关于使用swift vs objective c的自定义几何。

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.

我尝试了另一个使用Objective c的项目,但仍然收到了相同的错误消息。

I tried another project using objective c and still received the same error message.

在游乐场或整个项目中定位桌面时,不会出现错误,几何绘制正确。只有在定位iOS时才会出现错误消息。

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.

如何修复此问题并显示iOS的几何图形?

How can I fix this and display the geometry for iOS?

推荐答案

根据 CGFloat SCNVector3 我的猜测是个问题c>用于桌面(可以是32位或64位,具体取决于主机)和 Float 适用于iOS设备 - iOS模拟器平台(这是您在定位时获得的) iOS在游乐场中既不像设备也不像OS X. 向Apple提交错误将是一个好主意。

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.

与此同时,一个好的解决方法可能是使用更详细的初始化程序(以 init开头(数据:语义:。 .. )来创建几何源。

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.

这篇关于如何解决SceneKit double不支持的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆