我有以下代码: class ViewController:UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let sceneView = SCNView(frame: self.view.frame)
self.view.addSubview(sceneView)
let scene = SCNScene()
sceneView.scene = scene
let camera = SCNCamera()
let cameraNode = SCNNode()
cameraNode.camera = camera
cameraNode.position = SCNVector3(x: -3.0, y: 3.0, z: 3.0)
let light = SCNLight()
light.type = SCNLightTypeOmni
let lightNode = SCNNode()
lightNode.light = light
lightNode.position = SCNVector3(x: 1.5, y: 1.5, z: 1.5)
let sphereGeometry = SCNSphere(radius: 5)
let sphereNode = SCNNode(geometry: sphereGeometry)
let constraint = SCNLookAtConstraint(target: sphereNode)
constraint.gimbalLockEnabled = true
cameraNode.constraints = [constraint]
scene.rootNode.addChildNode(lightNode)
scene.rootNode.addChildNode(cameraNode)
scene.rootNode.addChildNode(sphereNode)
}
}
上面没有显示任何内容但是它成功构建。
当我改变线条时;
let sphereGeometry = SCNSphere(radius: 5)
to(创建一个多维数据集):
let cubeGeometry = SCNBox(width: 1.0, height: 1.0, length: 1.0, chamferRadius: 0.0)
我很困惑如何让球体出现。任何帮助将不胜感激:)
答案 0 :(得分:0)
代码确实产生了一个球体。半径太大,相机恰好在球体内!
将半径从5改为0.5就可以了!