初始化模型,位置为 SCNVector3(0, -1, -2), 对于大的模型, 初始化后不容易被用户找到, 所以初始化时让模型全貌的显示在屏幕前方
1lazy var node: AudioinARKitLocationNode = { 2 3 let modelScene = SCNScene(named: scnName)! 4 let cup = modelScene.rootNode.childNodes[0] 5 let node = AudioinARKitLocationNode(location: location, node: cup) 6 node.name = scnName 7 let boundingBox = node.boundingBox 8 let distance = boundingBox.max.distance(to: boundingBox.min) 9 let base: Float = 0.8 10 if distance > base { 11 // 缩放模型, 初始化时,不超出屏幕大小 12 let scale = base / distance 13 node.scale = SCNVector3(scale, scale, scale) 14 } 15 return node 16 17}() 18extension SCNVector3 { 19 func distance(to anotherVector: SCNVector3) -> Float { 20 return sqrt(pow(anotherVector.x - x, 2) + pow(anotherVector.z - z, 2)) 21 } 22}