I am trying to scale and SCNNode in real time using the Pinch gesture:
This is my current code
let pinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(handlePinch(from:)))
sceneView.addGestureRecognizer(pinchGestureRecognizer)
@objc
func handlePinch(from recognizer: UIPinchGestureRecognizer){
var pinchScale = recognizer.scale
pinchScale = round(pinchScale * 1000) / 1000.0
sceneView.scene.rootNode.enumerateChildNodes { (node, stop) -> Void in
if(node.name == "Box01"){
node.scale = SCNVector3(x: pinchScale, y: pinchScale, z: pinchScale)
}
}
}
However the node doesn't scale big or small? Can someone please point my mistake?
The SCNNode is loaded and has an animation on applied like so,
sceneView.scene.rootNode.addChildNode(node)
loadAnimation(animation: .Attack, sceneName: "art.scnassets/attack", animationIdentifier: "attackID");
Got it to work in swift
@objc func handlePinch(gesture: UIPinchGestureRecognizer){
if(scnnodeSelected){
if (gesture.state == .changed) {
let pinchScaleX = Float(gesture.scale) * tappedObjectNode.scale.x
let pinchScaleY = Float(gesture.scale) * tappedObjectNode.scale.y
let pinchScaleZ = Float(gesture.scale) * tappedObjectNode.scale.z
tappedObjectNode.scale = SCNVector3(pinchScaleX, pinchScaleY, pinchScaleZ)
gesture.scale=1
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With