This file contains hidden or 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
| func scanText() { | |
| var superString:String = "" | |
| let requestHandler = VNImageRequestHandler(cgImage: (selectedImage?.cgImage)!) | |
| let request = VNRecognizeTextRequest{ (request, error) in | |
| guard let observations = request.results as? [VNRecognizedTextObservation] else { return } | |
| for textObjects in observations { | |
| let topCandiate = textObjects.topCandidates(1) | |
| if let recognizedText = topCandiate.first { | |
| print(recognizedText.string) | |
| superString += recognizedText.string |
This file contains hidden or 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
| // | |
| // ContentView.swift | |
| // Molecule | |
| // | |
| // Created by localuser on 10.10.22. | |
| // | |
| import SwiftUI | |
| import SceneKit | |
| import Combine |
This file contains hidden or 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
| let doubleRecognizer = UITapGestureRecognizer(target: self, action: #selector(doubleTap(_:))) | |
| doubleRecognizer.numberOfTapsRequired = 2 | |
| view.addGestureRecognizer(doubleRecognizer) | |
| @objc func doubleTap(_ gestureRecognize: UIGestureRecognizer) { | |
| let p = gestureRecognize.location(in: view) | |
| let hitResults = view.hitTest(p, options: [:]) | |
| if hitResults.count > 0 { | |
| var result = hitResults[0].node as? NewNode |
This file contains hidden or 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
| let longRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longTap(_:))) | |
| view.addGestureRecognizer(longRecognizer) | |
| @objc func longTap(_ gestureRecognize: UIGestureRecognizer) { | |
| let p = gestureRecognize.location(in: view) | |
| let hitResults = view.hitTest(p, options: [:]) | |
| if hitResults.count > 0 { | |
| let result = hitResults[0].node as? NewNode | |
| if gestureRecognize.state == .ended { |
This file contains hidden or 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
| .gesture( | |
| DragGesture(minimumDistance: dragDistance) | |
| .onChanged { gesture in | |
| drag.send(gesture.location) | |
| } | |
| ) | |
| dragging = drag.sink(receiveValue: { [self] points in | |
| let hitResults = view.hitTest(points, options: [:]) | |
| if hitResults.count > 0 { |
This file contains hidden or 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
| let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:))) | |
| view.addGestureRecognizer(panRecognizer) | |
| @objc func handlePan(_ gestureRecognize: UIPanGestureRecognizer) { | |
| let p = gestureRecognize.location(in: view) | |
| let hitResults = view.hitTest(p, options: [:]) | |
| if hitResults.count > 0 { | |
| let result = hitResults[hitResults.count - 1].node as? NewNode | |
| let newPosition = p.scnVector3Value(view: view, depth: Float(result!.position.z)) |
This file contains hidden or 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
| while (intersects(point: newPosition, center: result!.position, radius: 0.5)) { | |
| if view.pointOfView!.worldPosition.x > 3.5 { | |
| result!.position.x += 1 | |
| } | |
| if view.pointOfView!.worldPosition.x < -3.5 { | |
| result!.position.x -= 1 | |
| } | |
| if view.pointOfView!.worldPosition.y > 3.5 { | |
| result!.position.y += 1 | |
| } |
This file contains hidden or 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
| func intersects(point:SCNVector3, center:SCNVector3, radius:Float) -> Bool | |
| { | |
| let displacementToCenter = point - center; | |
| let radiusSqr = radius * radius; | |
| let intersects = displacementToCenter.magnitude < radiusSqr; | |
| return intersects; | |
| } |
This file contains hidden or 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
| if hitResults.count == 0 { | |
| var newPosition = p.scnVector3Value(view: view, depth: 0) | |
| if gestureRecognize.state == .ended { | |
| newPosition.x = newPosition.x.rounded(FloatingPointRoundingRule.toNearestOrEven) | |
| newPosition.y = newPosition.y.rounded(FloatingPointRoundingRule.toNearestOrEven) | |
| newPosition.z = newPosition.z.rounded(FloatingPointRoundingRule.toNearestOrEven) | |
| let newPart = moleculeBody(snakePosition: newPosition, name: String("Node \(name)")) | |
| name += 1 |
This file contains hidden or 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
| func CGPointToSCNVector3(view: SCNView, depth: Float, point: CGPoint) -> SCNVector3 { | |
| let projectedOrigin = view.projectPoint(SCNVector3Make(0, 0, depth)) | |
| let locationWithz = SCNVector3Make(Float(point.x), Float(point.y), projectedOrigin.z) | |
| return view.unprojectPoint(locationWithz) | |
| } |