par*_*son 2 scenekit swift arkit
我试图用SceneKit和ARKit创建一个原语。无论出于什么原因,它都不起作用。
let box = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)
let node = SCNNode(geometry: box)
node.position = SCNVector3(0,0,0)
sceneView.scene.rootNode.addChildNode(node)
Run Code Online (Sandbox Code Playgroud)
我还需要输入相机坐标吗?
您的代码看起来不错,它应该可以工作。我已经尝试了以下代码:用ARKit模板创建新应用后,我替换了viewDidLoad函数。
override func viewDidLoad() {
super.viewDidLoad()
// Set the view's delegate
sceneView.delegate = self
let box = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)
let node = SCNNode(geometry: box)
node.position = SCNVector3(0,0,0)
sceneView.scene.rootNode.addChildNode(node)
}
Run Code Online (Sandbox Code Playgroud)
它在原始点(0、0、0)处创建一个框。不幸的是,您的设备在盒子里,因此您无法直视该盒子。要查看该框,请将设备移远一点。
所附图片是移动设备后的方框:
如果您想立即看到它,请将框移到前面一点,添加颜色并使第一个材料为双面(以便从内侧或外侧看到它):
let box = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)
box.firstMaterial?.diffuse.contents = UIColor.red
box.firstMaterial?.isDoubleSided = true
let boxNode = SCNNode(geometry: box)
boxNode.position = SCNVector3(0, 0, -1)
sceneView.scene.rootNode.addChildNode(boxNode)
Run Code Online (Sandbox Code Playgroud)