Posts

Post not yet marked as solved
0 Replies
346 Views
Hello:I am using ARKit to build an app. It works well as a regular iOS app. However it crash every time when move it to iPad playground. Things is that playground carsh if I add couple more SCNNode to the scene. Can u tell me why?import ARKit import SceneKit import UIKit import PlaygroundSupport public class HomeViewController: UIViewController, ARSessionDelegate, ARSCNViewDelegate { public let scene = SCNScene() public var sceneView = ARSCNView(frame: CGRect(x: 0,y: 0,width: 640,height: 800)) var point1: SCNSphere! var node1: SCNNode! var point2: SCNSphere! var node2: SCNNode! var point3: SCNSphere! var node3: SCNNode! var point4: SCNSphere! var node4: SCNNode! var point5: SCNSphere! var node5: SCNNode! var point6: SCNSphere! var node6: SCNNode! override public func viewDidLoad() { //viewdidload config super.viewDidLoad() sceneView.delegate = self sceneView.session.delegate = self sceneView.scene = scene let config = ARWorldTrackingConfiguration() config.planeDetection = [.horizontal] sceneView.session.run(config) view.addSubview(sceneView) point1 = SCNSphere(radius: 0.1) point1.firstMaterial?.diffuse.contents = UIColor.blue node1 = SCNNode(geometry: point1) node1.position = SCNVector3(0, 0, -0.2) point2 = SCNSphere(radius: 0.1) point2.firstMaterial?.diffuse.contents = UIColor.black node2 = SCNNode(geometry: point2) node2.position = SCNVector3(-0.2, 0, 0) point3 = SCNSphere(radius: 0.1) point3.firstMaterial?.diffuse.contents = UIColor.yellow node3 = SCNNode(geometry: point3) node3.position = SCNVector3(0, -0.2, 0) point4 = SCNSphere(radius: 0.1) point4.firstMaterial?.diffuse.contents = UIColor.red node4 = SCNNode(geometry: point4) node4.position = SCNVector3(0, 0, 0.2) point5 = SCNSphere(radius: 0.1) point5.firstMaterial?.diffuse.contents = UIColor.green node5 = SCNNode(geometry: point5) node5.position = SCNVector3(0.2, 0, 0) point6 = SCNSphere(radius: 0.1) point6.firstMaterial?.diffuse.contents = UIColor.orange node6 = SCNNode(geometry: point6) node6.position = SCNVector3(0, 0.2, 0) sceneView.scene.rootNode.addChildNode(node1) sceneView.scene.rootNode.addChildNode(node2) sceneView.scene.rootNode.addChildNode(node3) sceneView.scene.rootNode.addChildNode(node4) sceneView.scene.rootNode.addChildNode(node5) sceneView.scene.rootNode.addChildNode(node6) } var a = 0 public func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { if a <= 100 { node1.position.y += 0.01 node2.position.x += 0.01 node3.position.z += 0.01 node4.position.y += 0.01 node5.position.y += 0.01 node6.position.z += 0.01 }else { node1.position.y -= 0.01 node2.position.x += 0.01 node3.position.z += 0.01 node4.position.y += 0.01 node5.position.y += 0.01 node6.position.z += 0.01 } a += 1 if a == 200 { a = 0 } } public func session(_ session: ARSession, didFailWithError error: Error) {} public func sessionWasInterrupted(_ session: ARSession) {} public func sessionInterruptionEnded(_ session: ARSession) {} } PlaygroundPage.current.liveView = HomeViewController() PlaygroundPage.current.needsIndefiniteExecution = true
Posted
by haoboxuxu.
Last updated
.