Created
October 15, 2018 12:44
-
-
Save shrawan2015/38d0b6043b230e46e024580cc9045123 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// on Tap to reposition the cube | |
@objc func addCubeToSceneView(withGestureRecognizer recognizer: UIGestureRecognizer) { | |
let tapLocation = recognizer.location(in: sceneView) | |
switch recognizer.state { | |
case .began: | |
print("Object began to move") | |
let hitResults = self.sceneView.hitTest(tapLocation, options: nil) | |
if hitResults.isEmpty { return } | |
let hitResult = hitResults.first | |
if let node = hitResult?.node.parent?.parent?.parent { | |
self.object = node | |
} | |
case .changed: | |
print("Moving object position changed") | |
case .ended: | |
print("Done moving object") | |
let hitTestResults = sceneView.hitTest(tapLocation, types: .existingPlaneUsingExtent) | |
guard let hitTestResult = hitTestResults.first else { | |
DispatchQueue.main.async { | |
showTost(withMessage:AppConstant.Message.addFailure_on_surface ,fromViewController:self) | |
} | |
return } | |
planeNode.removeFromParentNode() | |
planeAnchorNode.removeFromParentNode() | |
shadowNode.removeFromParentNode() | |
let translation = hitTestResult.worldTransform.translation | |
let x = translation.x | |
let y = translation.y | |
let z = translation.z | |
object.position = SCNVector3(x,y,z) | |
sceneView.scene.rootNode.addChildNode(object) | |
shadowNode = shadowPlane() | |
shadowNode.position = SCNVector3(x,y - 0.1,z) | |
sceneView.scene.rootNode.addChildNode(shadowNode) | |
default: | |
break | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment