【发布时间】:2020-10-20 22:13:14
【问题描述】:
我目前有 6 个球体,分别代表 x、-x、y、-y、z、-z 的方向,我想将每个 SCNSphere 的不透明度更改为 0,当它靠近我的相机并且满时远处时透明。
struct SceneKitView: UIViewRepresentable {
var transparency: CGFloat = 0.5
let sceneView = SCNView()
func makeUIView(context: UIViewRepresentableContext<SceneKitView>) -> SCNView {
sceneView.scene = SCNScene()
sceneView.allowsCameraControl = true
sceneView.autoenablesDefaultLighting = true
sceneView.backgroundColor = UIColor.clear
let radius: Float = 0.75
createSphere(x: 0, y: radius, z: 0)
createSphere(x: 0, y: -radius, z: 0)
createSphere(x: radius, y: 0, z: 0)
createSphere(x: -radius, y: 0, z: 0)
createSphere(x: 0, y: 0, z: radius)
createSphere(x: 0, y: 0, z: -radius)
return sceneView
}
func updateUIView(_ uiView: SCNView, context: UIViewRepresentableContext<SceneKitView>) {
}
typealias UIViewType = SCNView
func createSphere(x: Float, y: Float, z: Float) {
let sphere = SCNSphere(radius: 0.1)
sphere.firstMaterial?.diffuse.contents = UIColor.black
sphere.firstMaterial?.transparency = transparency
let spherenode = SCNNode(geometry: sphere)
spherenode.position = SCNVector3(x: x, y: y, z: z)
sceneView.scene?.rootNode.addChildNode(spherenode)
}
}
【问题讨论】:
标签: swift augmented-reality scenekit arkit