Skip to content

Instantly share code, notes, and snippets.

@mzsima
Created January 7, 2018 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzsima/d833bbbb428be812ec94143f03eda415 to your computer and use it in GitHub Desktop.
Save mzsima/d833bbbb428be812ec94143f03eda415 to your computer and use it in GitHub Desktop.
arrow
//
// ViewController.swift
// arrow
//
// Created by MizushimaYusuke on 2018/01/07.
// Copyright © 2018 MizushimaYusuke. All rights reserved.
//
import UIKit
import SceneKit
import ARKit
class ViewController: UIViewController, ARSCNViewDelegate {
@IBOutlet var sceneView: ARSCNView!
override func viewDidLoad() {
super.viewDidLoad()
// Set the view's delegate
sceneView.delegate = self
// Show statistics such as fps and timing information
sceneView.showsStatistics = true
sceneView.autoenablesDefaultLighting = true
// Create a new scene
let scene = SCNScene()
// Set the scene to the view
sceneView.scene = scene
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Create a session configuration
let configuration = ARWorldTrackingConfiguration()
// Run the view's session
sceneView.session.run(configuration)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Pause the view's session
sceneView.session.pause()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let p = touches.first?.location(in: sceneView) {
if let hit = sceneView.hitTest(p, types: .featurePoint).first {
let position = SCNVector3(hit.worldTransform.columns.3.x, hit.worldTransform.columns.3.y + 0.02, hit.worldTransform.columns.3.z)
let arrowSign = SCNNode()
arrowSign.position = position
sceneView.scene.rootNode.addChildNode(arrowSign)
let path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: -0.01))
path.addLine(to: CGPoint(x: 0, y:0.01))
path.addLine(to: CGPoint(x: 0.01, y:0))
path.close()
let tri = SCNShape(path: path, extrusionDepth: 0.001)
tri.firstMaterial?.diffuse.contents = UIColor(hue: 0.5, saturation: 0.5, brightness: 1, alpha: 1)
let triNode = SCNNode(geometry: tri)
triNode.position = SCNVector3(0.005, 0, 0)
arrowSign.addChildNode(triNode)
let bar = SCNBox(width: 0.04, height: 0.01, length: 0.001, chamferRadius: 0)
bar.firstMaterial?.diffuse.contents = UIColor(hue: 0.5, saturation: 0.5, brightness: 1, alpha: 1)
let barNode = SCNNode(geometry: bar)
barNode.position = SCNVector3(-0.01, 0, 0)
arrowSign.addChildNode(barNode)
arrowSign.runAction(.rotateBy(x: 0, y: 4.0 * .pi, z: 0, duration: 3.0))
}
}
}
}
@mzsima
Copy link
Author

mzsima commented Jan 7, 2018

@vandanamodi30
Copy link

@mzsima Do you have a solution or suggestion that in sceneview how can we draw arrow in all direction using Two Points like Start vector and end point vector (draw arrow like Up side , Downside , left side up and down, right side up and down ) see attachment ,
Screenshot 2023-04-12 at 6 32 22 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment