嗨,我有一个非常简单的场景,其中包含3个节点:
放置STL时,它非常小,因此用户必须将相机缩放很多。我想做的是以编程方式将摄像机缩放到合适的STL节点,但不确定如何。
这是我到目前为止的工作:
stlNode = .... // Custom node
lightNode = scene?.rootNode.childNode(withName: "omni", recursively: true)
cameraNode = scene?.rootNode.childNode(withName: "camera", recursively: true)
cameraNode.constraints = [SCNLookAtConstraint(target: stlNode)]
// Zoom to fit the stlNode here.
scene?.rootNode.addChildNode(stlNode)
答案 0 :(得分:0)
您可以尝试创建cameraClass,然后添加zoomIn(),zoomOut()函数,以便进行调整。您还可以将节点扩大一点,看看是否有帮助。
var cameraEye = SCNNode()
var cameraFocus = SCNNode()
...
init()
{
cameraEye.name = "Camera Eye"
cameraFocus.name = "Camera Focus"
cameraFocus.isHidden = true
cameraFocus.position = SCNVector3(x: 0, y: 0, z: 0)
cameraEye.camera = SCNCamera()
cameraEye.constraints = []
cameraEye.position = SCNVector3(x: 0, y: 15, z: 0.1)
let vConstraint = SCNLookAtConstraint(target: cameraFocus)
vConstraint.isGimbalLockEnabled = true
cameraEye.constraints = [vConstraint]
}
// Add your camera nodes
gameNodes.addChildNode(camera.cameraEye)
gameNodes.addChildNode(camera.cameraFocus)
ZoomIn()/ zoomOut()只是调整距离的功能。