如何将 SCNPlane 颜色更改为清晰颜色 [英] How to change SCNPlane color as clear color
问题描述
我正在开发一个 ARKit 项目,在水平平面上点击时需要波纹动画效果.为此,我采用了 UIView 对象并将其作为 SCNPlane 对象材料的内容传递.我已将 Ripple 动画添加到 UIView 对象.一切正常.但我无法将 SCNPlane 颜色更改为清晰颜色.我可以为材质使用透明度属性.但它也隐藏了 Ripple 动画.所以,我在这里需要的是,SCNPlane 对象的背景颜色应该是透明的,并且应该只向用户显示 Ripple 动画.有人可以帮助我吗.
I am working on a ARKit project which needs Ripple animation effect when tapped on Horizontal Plane. For that I have took UIView object and pass that as contents for material of SCNPlane object. I have added Ripple animation to UIView object. Everything works fine. But I can't change the SCNPlane colour to clear color. I can use transparency property for the material. But it is hiding Ripple animation too. So, what I need here is, the background colour of SCNPlane object should be transparent and only Ripple animation should appear to user. Can someone help me on this.
这是我的代码.
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 应用中截取了屏幕截图.请点击此链接参考屏幕截图.这正是我需要的.
推荐答案
查看这个答案.将 UiView
isOpaque
设置为 false
对我有用.
Check out this answer. Setting the UiView
isOpaque
to false
worked for me.
这篇关于如何将 SCNPlane 颜色更改为清晰颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!