尽管在iOS 12中进行了复制,节点克隆仍不维护几何

时间:2019-02-13 03:55:42

标签: ios swift scenekit

我最初在iOS 9上开发的SceneKit中有一个绘画应用程序。在一部分中,我收集了一组节点,对其进行克隆,然后将它们展平以制成一个可以移动的单个节点。

问题是,在iOS 9中,我能够成功进行“深度克隆”技术,该技术可以复制节点的几何形状和材质,并且保留了这些属性。但是,iOS 12中不是这种情况。尽管运行完全相同的代码,但几何图形却变得一团糟。我花了几个小时尝试下面的过程的不同变体,但无济于事。这是代码:

func sendPainting() {
        // a parent node that contains the canvas and frame nodes as children
        guard let configPainting = sceneView.scene!["configpainting"] else {
            return
        }

        guard let configCanvas = configPainting.childNode(withName: "canvas", recursively: true) else {
            return
        }

        guard let configFrame = configPainting.childNode(withName: "frame", recursively: true) else {
            return
        }

        let configClone = configPainting.clone()

        // copy over geometry and material      
        configClone.childNode(withName: "canvas", recursively: true)?.geometry = configCanvas.geometry?.copy() as? SCNGeometry
        configClone.childNode(withName: "canvas", recursively: true)?.geometry?.firstMaterial = configCanvas.geometry?.firstMaterial?.copy() as? SCNMaterial
        configClone.childNode(withName: "frame", recursively: true)?.geometry = configFrame.geometry?.copy() as? SCNGeometry
        configClone.childNode(withName: "frame", recursively: true)?.geometry?.firstMaterial = configFrame.geometry?.firstMaterial?.copy() as? SCNMaterial

        // make a flattened clone to now have the canvas and frame consolidated into 1 node
        let localClone = configClone.flattenedClone()

...

        // add to my scene
        sceneView.scene!["localpaintings"]?.addChildNode(localClone)
}

这是在iOS 9和12中克隆和展平前的节点组的样子:

before

及之后:

在iOS 9中,保留了几何图形(抱歉,图像不同,但是您知道了):

ios9

在iOS 12中,框架缩小并旋转:

ios12

0 个答案:

没有答案