在过去的几天里,我一直在寻找适用于 iOS 的 SceneKit。我在尝试创建自定义几何时遇到了一个问题。每当我尝试显示几何体时,它都不会绘制,并在运行时显示此错误。
SceneKit:错误,C3DRendererContextSetupResidentMeshSourceAtLocation - 不支持 double
我创建了一个以 iOS 为目标的游乐场,以测试一个更简单的自定义几何示例,并使用 swift vs objective c 查看这个问题关于自定义几何体。
我尝试使用目标 c 的另一个项目,仍然收到相同的错误消息。
在操场或完整项目上定位桌面时,不会出现错误,并且几何图形正确绘制。仅在定位 iOS 时才会出现错误消息。
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)
这是我在操场上用来绘制三角形的代码。定位桌面时使用相同的代码。
如何修复此问题并显示 iOS 的几何图形?
3 回答
我的猜测是
SCNVector3
被定义为CGFloat
用于桌面(可以是 32 位或 64 位,具体取决于主机)和Float
用于 iOS 设备 - iOS 模拟器平台(这是您在定位 iOS 时获得的)在操场上)既不像设备也不像 OS X.向 Apple 提交一个错误是个好主意。与此同时,一个好的解决方法可能是使用更详细的初始化程序(以
init(data:semantic:...
开头)来创建几何源。我通过改变创建几何源的方式来解决错误。
通过遵循创建几何源的这个问题方法,错误得到修复,三角形正确绘制。
我相信解决方案是在使用
代替
因为它指定我使用 float 组件而不是 double。
更确切地说,让它为我工作的是:
我也填了一个但是和 Apple 一起