Hi i have a very simple scene that contains 3 nodes:
When placing the STL it is very small so the user has to zoom the camera an aweful lot. What i would like to do is to zoom the camera to the fit STL node programatically but im not sure how.
This is wat i have so far:
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)
You might try creating a cameraClass, then add zoomIn(),zoomOut() functions so that you can make adjustments. You could also scale your node up a bit, see if that helps.
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() would just be a function of adjusting your distance.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.