当SCNMaterialProperty是SpriteKit场景时,ARSCNView准备崩溃

时间:2018-12-11 12:29:37

标签: scenekit arkit

我遇到ARKit / SceneKit崩溃。

如果我执行以下操作,它就会发生:-

  • 创建SCNPlane并将SCNMaterialProperty设置为SpriteKit 场景
  • 使用SCNPlane创建SCNNode
  • 在ARSCNView上调用prepare并添加SCNNode。

当我打电话给prepare时它崩溃了。但是,如果我不调用prepare而添加SCNNode或SCNMaterialProperty不是SpriteKit场景,它也不会崩溃。

请参见下面的代码:-

var exhibitScene = SKScene(fileNamed: spriteName.lowercased())
exhibitScene?.view?.preferredFramesPerSecond = 60
exhibitScene?.view?.ignoresSiblingOrder = true
exhibitScene?.scaleMode = .aspectFit
exhibitScene?.isPaused = false

let exhibitSize = CGSize.init(width: (exhibitScene?.frame.size.width)! / PIXEL_TO_CENTIMETRE, height: (exhibitScene?.frame.size.height)! / PIXEL_TO_CENTIMETRE)

let exhibitPlane = SCNPlane(width: exhibitSize.width/100, height: exhibitSize.height/100)
exhibitPlane.firstMaterial?.diffuse.contents = exhibitScene
exhibitPlane.firstMaterial?.diffuse.contentsTransform = SCNMatrix4Translate(SCNMatrix4MakeScale(1, -1, 1), 0, 1, 0)

let exhibitNode = SCNNode(geometry: exhibitPlane)
exhibitNode.name = name
exhibitNode.geometry?.firstMaterial?.isDoubleSided = false
exhibitNode.position = SCNVector3(x/100, (y + Float(exhibitSize.height * 0.5))/100, z/100)

self.sceneView.prepare([exhibitNode], completionHandler: { (Bool) in
     self.sceneView.scene.rootNode.addChildNode(exhibitNode)
})

不确定如何解决此问题。

当SCNMaterialProperty设置为使用SpriteKit场景时,是否必须在ARSCNView上设置一个参数以准备SCNNode?

1 个答案:

答案 0 :(得分:0)

不确定您的情况,但是当SKScene(以及因此的SCNPlane)的大小超过某个限制时,我也遇到了类似的崩溃。崩溃的实际原因是SCNMaterialProperty.contents可能不超过某个限制(我相信大约是4000像素左右)。