我想移动摄像头的位置,让物体看起来更小,但是如果我设置了更大的z值,物体就会消失。例如:cameraNode.position = SCNVector 3(0,0,800),然后硬币就会消失。我是SceneKit新手,希望得到一些帮助,谢谢!或者你能介绍一个基于SwiftUI的SceneKit教程吗?
import Foundation
import SceneKit
class CoinFlipGameScene: SCNScene{
override init() {
super.init()
createCoinNode()
setUpCamera()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension CoinFlipGameScene{
func createCoinNode(){
let coinGeometry = SCNBox(width: 100, height: 100, length: 0, chamferRadius: 0)
let coinHeadMaterial = SCNMaterial()
coinHeadMaterial.diffuse.contents = UIImage(named: "coin-head")
let coinTailMaterial = SCNMaterial()
coinTailMaterial.diffuse.contents = UIImage(named: "coin-tail")
coinGeometry.materials = [coinHeadMaterial, coinHeadMaterial, coinTailMaterial]
let coinNode = SCNNode(geometry: coinGeometry)
coinNode.position = SCNVector3(x: 0, y: 0, z: 0)
self.rootNode.addChildNode(coinNode)
}
func setUpCamera(){
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(0, 0, 100)
self.rootNode.addChildNode(cameraNode)
}
}
import SwiftUI
import SceneKit
struct CoinFlipView: View {
var scene: SCNScene{
let scene = CoinFlipGameScene()
return scene
}
var body: some View {
SceneView(scene: scene, options: [.allowsCameraControl])
.background(.clear)
}
}
struct CoinFlipView_Previews: PreviewProvider {
static var previews: some View {
CoinFlipView()
}
}
1条答案
按热度按时间yjghlzjz1#
这可以通过调整
SCNCamera
示例的zFar
属性或启用automaticallyAdjustsZRange
来解决。