将3D模型放置在坐标

时间:2019-03-13 05:03:16

标签: ios swift location arkit 3d-modelling

我正在使用ARKit开发AR项目。 我想放置一个3D模型代替“坐标”。我可以在下面的代码中添加Image来代替坐标

public init(location: CLLocation?, image: UIImage) {
        let plane = SCNPlane(width: image.size.width / 100, height: image.size.height / 100)
        plane.firstMaterial!.diffuse.contents = image
        plane.firstMaterial!.lightingModel = .constant

        annotationNode = AnnotationNode(view: nil, image: image)
        annotationNode.geometry = plane

        super.init(location: location)

        let billboardConstraint = SCNBillboardConstraint()
        billboardConstraint.freeAxes = SCNBillboardAxis.Y
        constraints = [billboardConstraint]

        addChildNode(annotationNode)
    }

用于将图像放置在坐标上的AnnotationNode类的代码。

open class AnnotationNode: SCNNode {
    public var view: UIView?
    public var image: UIImage?

    public init(view: UIView?, image: UIImage?) {
        super.init()
        self.view = view
        self.image = image
    }

    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

这是在屏幕上添加3D模型的代码。

let idleScene = SCNScene(named: "art.scnassets/idleFixed.dae")!
//        let idleScene = SCNScene(named: "art.scnassets/piper_pa18.dae")!

        // This node will be parent of all the animation models
        let node1 = SCNNode()

        // Add all the child nodes to the parent node
        for child in idleScene.rootNode.childNodes {
            node1.addChildNode(child)
        }

如果我在行下方添加,则3D模型将添加到应用中,但不会添加到特定坐标中。

sceneLocationView.scene.rootNode.addChildNode(node1)

但是我想添加一个3D对象。谁能帮助我实现这一目标?

0 个答案:

没有答案