SCNText没有显示表情符号 - 在Swift中的ARKit

时间:2018-01-14 17:50:35

标签: ios swift arkit scntext

我正在创建一个应用程序,为我创建的名为SCNText的{​​{1}}添加ARSCNView。文本显示如下:(当sceneView时) screenshot1:

screenshot1

但是当SCNText(string: "Test", extrusionDepth: CGFloat(0.01)) SCNText(string: "Test", extrusionDepth: CGFloat(0.01))没有显示表情符号时

screenshot2: screenshot2 这是完整的代码:

SCNText

我不想将其添加为 import UIKit import SceneKit import ARKit import Vision class ViewController: UIViewController, ARSCNViewDelegate { @IBOutlet weak var sceneView: ARSCNView! override func viewDidLoad() { super.viewDidLoad() // Set the view's delegate sceneView.delegate = self // Show statistics such as fps and timing information sceneView.showsStatistics = true // Create a new scene let scene = SCNScene() // Set the scene to the view sceneView.scene = scene // Enable Default Lighting - makes the 3D text a bit poppier. sceneView.autoenablesDefaultLighting = true sceneView.showsStatistics = true // Tap Gesture Recognizer let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(gestureRecognize:))) view.addGestureRecognizer(tapGesture) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) // Create a session configuration let configuration = ARWorldTrackingConfiguration() // Enable plane detection configuration.planeDetection = .horizontal // Run the view's session sceneView.session.run(configuration) } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) // Pause the view's session sceneView.session.pause() } // MARK: - ARSCNViewDelegate func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { DispatchQueue.main.async { } } @objc func handleTap(gestureRecognize: UITapGestureRecognizer) { self.create() } func create() { // Get Screen Centre let screenCentre : CGPoint = CGPoint(x: self.sceneView.bounds.midX, y: self.sceneView.bounds.midY) let arHitTestResults : [ARHitTestResult] = sceneView.hitTest(screenCentre, types: [.featurePoint]) if let closestResult = arHitTestResults.first { // Get Coordinates of HitTest let transform : matrix_float4x4 = closestResult.worldTransform let worldCoord : SCNVector3 = SCNVector3Make(transform.columns.3.x, transform.columns.3.y, transform.columns.3.z) // Create 3D Text let node : SCNNode = createNewParentNode() sceneView.scene.rootNode.addChildNode(node) node.position = worldCoord } } func createNewParentNode(_ text : String) -> SCNNode { let text = SCNText(string: "Test", extrusionDepth: CGFloat(0.01)) var font = UIFont(name: "Futura", size: 0.07) font = font?.withTraits(traits: .traitBold) text.font = font text.alignmentMode = kCAAlignmentCenter text.firstMaterial?.diffuse.contents = UIColor.orange text.firstMaterial?.specular.contents = UIColor.white text.firstMaterial?.isDoubleSided = true text.chamferRadius = CGFloat(bubbleDepth) let textNode = SCNNode(geometry: text) textNode.pivot = SCNMatrix4MakeTranslation( positionx, positiony, positionz) // Don't worry about the positions they work fine text.scale = SCNVector3Make(0.1, 0.1, 0.1) let NodeParent = SCNNode() NodeParent.addChildNode(text) //Add More SCNNode's to NodeParent return NodeParent } } extension UIFont { // Based on: https://stackoverflow.com/questions/4713236/how-do-i-set-bold-and-italic-on-uilabel-of-iphone-ipad func withTraits(traits:UIFontDescriptorSymbolicTraits...) -> UIFont { let descriptor = self.fontDescriptor.withSymbolicTraits(UIFontDescriptorSymbolicTraits(traits)) return UIFont(descriptor: descriptor!, size: 0) } } 因为我想稍后使用故事板进行集合视图。

它与我使用的字体有关吗?

1 个答案:

答案 0 :(得分:0)

SCNText - developer.apple.com

  

" SceneKit可以使用任何支持的字体和样式创建文本几何体   通过Core Text框架,除了位图字体(例如   作为定义颜色表情符号字符的那些)"。

但是,您仍然可以将表情符号作为素材/纹理添加到SCNNode(例如框)中。

修改 几个月前我用emoji创建了一个国旗ios App,这是一个很好的演示Youtube video - Country Flags iOS App