如何将SCNPlane的颜色更改为透明颜色

5
我正在进行一个 ARKit 项目,需要在水平面上点击时产生涟漪动画效果。为此,我使用了 UIView 对象,并将其作为 SCNPlane 对象的材质内容。我已经向 UIView 对象添加了涟漪动画。一切都运行良好。但是我无法将 SCNPlane 颜色更改为透明颜色。我可以使用材质的透明度属性,但它也会隐藏涟漪动画。因此,我需要的是,SCNPlane 对象的背景颜色应该是透明的,只有涟漪动画应该出现在用户眼前。有人能帮我吗?
以下是我的代码:
    let location = tapGesture.location(in: self.sceneView)
    let results = self.sceneView.hitTest(location, types: .existingPlane)
    if !results.isEmpty{

        guard let result = results.first else{ return }
        let myUIView = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 300, height: 300)))
        myUIView.backgroundColor = .red
        let plane = SCNPlane(width: 1.0, height: 1.0)
        plane.firstMaterial?.diffuse.contents = myUIView
        let planeViewNode = SCNNode(geometry: plane)
        planeViewNode.eulerAngles.x = Float(-Double.pi / 2)
        planeViewNode.position = SCNVector3(result.worldTransform.columns.3.x, result.worldTransform.columns.3.y, result.worldTransform.columns.3.z)

        self.sceneView.scene.rootNode.addChildNode(planeViewNode)

        //Ripple animation code goes here 
    }

我从BBC的文明AR应用程序中截取了屏幕截图,请通过点击此链接参考屏幕截图。这正是我需要的。


1
你找到答案了吗?我现在也遇到了这个问题。 - Lance Samaria
这个导致其他答案的答案是有效的,为什么不接受它呢?当其他开发人员需要帮助时,他们会看到并知道它有效,这对社区更有益。 - Lance Samaria
1个回答

3

查看这个答案。将UiViewisOpaque属性设置为false对我起到了作用。


我被这个问题困扰了几周。你的答案解决了我的问题!另一个答案告诉你该怎么做,但我一直试图保持我的代码紧凑,并且一直在一行中完成所有操作,这是不正确的:material.diffuse.contents = MyViewController.view .isOpaque = false。另一个答案的关键是在将视图控制器设置为材质内容之前将viewController.isOpaque = false 设置为false1. MyViewController.isOpaque = false 然后 2. material.diffuse.contents = MyViewController.view。 - Lance Samaria

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接