0

我正在制作一个应用程序,将一个添加SCNTextARSCNView我创建的名为sceneView. 文本显示完美如下:(当 SCNText(string: "Test", extrusionDepth: CGFloat(0.01))) screenshot1:

截图1

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

screenshot2: 截图2 这是完整的代码:

    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)
    }
}

我不想将它添加为 a SKLabelNode,因为我想稍后将 Storyboard 用于 Collection Views。

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

4

1 回答 1

2

SCNText - developer.apple.com

“SceneKit 可以使用 Core Text 框架支持的任何字体和样式创建文本几何图形,但位图字体(例如定义颜色表情符号字符的字体)除外”。

但是,您仍然可以将表情符号作为材质/纹理放在 SCNNode(例如框)上。

编辑: 几个月前我使用表情符号创建了一个 Country flag ios App,这是一个很好的演示Youtube 视频 - Country Flags iOS App

于 2018-01-15T03:40:48.577 回答