Skip to content
Permalink
Browse files

AR Robots

  • Loading branch information...
ZachOrr committed Jun 6, 2018
1 parent 7761432 commit 80f16476a0a7138b2546d6096d7ebdfc06e477ce
@@ -45,6 +45,8 @@
9257DF4A208BFC4400F7E2BA /* EventAlliance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9257DF49208BFC4400F7E2BA /* EventAlliance.swift */; };
9257DF4C208C078100F7E2BA /* WLT.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9257DF4B208C078100F7E2BA /* WLT.swift */; };
9257DF4E208C0D1200F7E2BA /* EventAlliancesTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9257DF4D208C0D1200F7E2BA /* EventAlliancesTableViewController.swift */; };
925B25B420C89C8000BCECFA /* ARKitRobotViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 925B25B320C89C8000BCECFA /* ARKitRobotViewController.swift */; };
925B25B620C89D3100BCECFA /* art.scnassets in Resources */ = {isa = PBXBuildFile; fileRef = 925B25B520C89D3100BCECFA /* art.scnassets */; };
92688C2B2090091D00D12B7B /* ReactNativeService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92688C2A2090091D00D12B7B /* ReactNativeService.swift */; };
926A8EE620B9B55100A25563 /* EventStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 926A8EE520B9B55100A25563 /* EventStatus.swift */; };
926A8EE820B9B6AB00A25563 /* EventStatusQual.swift in Sources */ = {isa = PBXBuildFile; fileRef = 926A8EE720B9B6AB00A25563 /* EventStatusQual.swift */; };
@@ -187,6 +189,8 @@
9257DF49208BFC4400F7E2BA /* EventAlliance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventAlliance.swift; sourceTree = "<group>"; };
9257DF4B208C078100F7E2BA /* WLT.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WLT.swift; sourceTree = "<group>"; };
9257DF4D208C0D1200F7E2BA /* EventAlliancesTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventAlliancesTableViewController.swift; sourceTree = "<group>"; };
925B25B320C89C8000BCECFA /* ARKitRobotViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ARKitRobotViewController.swift; sourceTree = "<group>"; };
925B25B520C89D3100BCECFA /* art.scnassets */ = {isa = PBXFileReference; lastKnownFileType = wrapper.scnassets; path = art.scnassets; sourceTree = "<group>"; };
92688C2A2090091D00D12B7B /* ReactNativeService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReactNativeService.swift; sourceTree = "<group>"; };
926A8EE520B9B55100A25563 /* EventStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventStatus.swift; sourceTree = "<group>"; };
926A8EE720B9B6AB00A25563 /* EventStatusQual.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventStatusQual.swift; sourceTree = "<group>"; };
@@ -425,6 +429,7 @@
92D855DF1EC6BA3900572F27 /* TeamViewController.swift */,
92D855E11EC755D000572F27 /* TeamInfoTableViewController.swift */,
9291F7FB1EE6FC7D00EEB86B /* TeamMediaCollectionViewController.swift */,
925B25B320C89C8000BCECFA /* ARKitRobotViewController.swift */,
);
name = Team;
sourceTree = "<group>";
@@ -475,6 +480,7 @@
92E6253F208EC23000DF58C0 /* the-blue-alliance-ios.entitlements */,
92942D951E2154DA008E79CA /* AppDelegate.swift */,
92942D9E1E2154DA008E79CA /* Assets.xcassets */,
925B25B520C89D3100BCECFA /* art.scnassets */,
92942DA31E2154DA008E79CA /* Info.plist */,
92D8CD1220C2634200777D93 /* GoogleService-Info.plist */,
92942DA01E2154DA008E79CA /* LaunchScreen.storyboard */,
@@ -900,6 +906,7 @@
TargetAttributes = {
92942D911E2154DA008E79CA = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = RHCNV9ZW2S;
LastSwiftMigration = 0920;
ProvisioningStyle = Automatic;
SystemCapabilities = {
@@ -949,6 +956,7 @@
92942DBF1E215BEF008E79CA /* TeamsStoryboard.storyboard in Resources */,
92942DA21E2154DA008E79CA /* LaunchScreen.storyboard in Resources */,
929BBB081EC55A22006D3854 /* InfoTableViewCell.xib in Resources */,
925B25B620C89D3100BCECFA /* art.scnassets in Resources */,
9221C618209BFF8700477DE2 /* LoadingTableViewCell.xib in Resources */,
92942D9F1E2154DA008E79CA /* Assets.xcassets in Resources */,
92FFE5251E7C994B0037E48C /* EventTableViewCell.xib in Resources */,
@@ -1034,7 +1042,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export NODE_BINARY=node\nsubtrees/the-blue-alliance-react/node_modules/react-native/packager/react-native-xcode.sh";
shellScript = "";
};
C82BF8916C8B32282B4357B2 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
@@ -1180,6 +1188,7 @@
929FCDAA1EC8BFB000A38E46 /* DistrictRanking.swift in Sources */,
92D5A1201EE476C800EBFC6F /* DistrictEventPoints.swift in Sources */,
925471F7208CC6F100AD3204 /* EventAllianceTableViewCell.swift in Sources */,
925B25B420C89C8000BCECFA /* ARKitRobotViewController.swift in Sources */,
92FF4A2E2099616B006B99F5 /* MyTBARegister.swift in Sources */,
9257DF4E208C0D1200F7E2BA /* EventAlliancesTableViewController.swift in Sources */,
926A8EE820B9B6AB00A25563 /* EventStatusQual.swift in Sources */,
@@ -1362,11 +1371,11 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "the-blue-alliance-ios/the-blue-alliance-ios.entitlements";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = RHCNV9ZW2S;
INFOPLIST_FILE = "the-blue-alliance-ios/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.the-blue-alliance.development";
PRODUCT_BUNDLE_IDENTIFIER = "com.the-blue-alliance.zach-dev";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
@@ -1379,11 +1388,11 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "the-blue-alliance-ios/the-blue-alliance-ios.entitlements";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = RHCNV9ZW2S;
INFOPLIST_FILE = "the-blue-alliance-ios/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.the-blue-alliance.the-blue-alliance";
PRODUCT_BUNDLE_IDENTIFIER = "com.the-blue-alliance.zach-dev";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
@@ -53,7 +53,7 @@
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Release"
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
@@ -21,7 +21,8 @@ public enum MediaType: String {
static var imageTypes: [String] {
return [MediaType.cdPhotoThread.rawValue,
MediaType.imgur.rawValue,
MediaType.instagramImage.rawValue]
MediaType.instagramImage.rawValue,
MediaType.grabcad.rawValue]
}

static var socialTypes: [String] {
@@ -73,5 +73,7 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSCameraUsageDescription</key>
<string>This application will use the camera for Augmented Reality.</string>
</dict>
</plist>
@@ -0,0 +1,139 @@
import UIKit
import SceneKit
import ARKit

class ARKitRobotViewController: UIViewController, ARSCNViewDelegate {

@IBOutlet var sceneView: ARSCNView!

var nodeModel:SCNNode!
let nodeName = "frc2337"

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.debugOptions = [ARSCNDebugOptions.showFeaturePoints, ARSCNDebugOptions.showWorldOrigin]
sceneView.antialiasingMode = .multisampling4X

// Create a new scene
let scene = SCNScene()

// Set the scene to the view
sceneView.scene = scene

let modelScene = SCNScene(named:
"art.scnassets/frc2337/frc2337.scn")!

nodeModel = modelScene.rootNode
nodeModel.scale = SCNVector3(0.008, 0.008, 0.008)
}

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 didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

let location = touches.first!.location(in: sceneView)

// Let's test if a 3D Object was touch
var hitTestOptions = [SCNHitTestOption: Any]()
hitTestOptions[SCNHitTestOption.boundingBoxOnly] = true

let hitResults: [SCNHitTestResult] = sceneView.hitTest(location, options: hitTestOptions)

if let hit = hitResults.first {
if let node = getParent(hit.node) {
node.removeFromParentNode()
return
}
}

// No object was touch? Try feature points
let hitResultsFeaturePoints: [ARHitTestResult] = sceneView.hitTest(location, types: .featurePoint)

if let hit = hitResultsFeaturePoints.first {

// Get the rotation matrix of the camera
let rotate = simd_float4x4(SCNMatrix4MakeRotation(sceneView.session.currentFrame!.camera.eulerAngles.y, 0, 1, 0))

// Combine the matrices
let finalTransform = simd_mul(hit.worldTransform, rotate)
sceneView.session.add(anchor: ARAnchor(transform: finalTransform))
//sceneView.session.add(anchor: ARAnchor(transform: hit.worldTransform))
}

}

func getParent(_ nodeFound: SCNNode?) -> SCNNode? {
if let node = nodeFound {
if node.name == nodeName {
return node
} else if let parent = node.parent {
return getParent(parent)
}
}
return nil
}

// MARK: - ARSCNViewDelegate
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
if !anchor.isKind(of: ARPlaneAnchor.self) {
DispatchQueue.main.async {
let modelClone = self.nodeModel.clone()
modelClone.position = SCNVector3Zero

// Add model as a child of the node
node.addChildNode(modelClone)
}
}
}

/*
// Override to create and configure nodes for anchors added to the view's session.
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
let node = SCNNode()
return node
}
*/

func session(_ session: ARSession, didFailWithError error: Error) {
// Present an error message to the user
}

func sessionWasInterrupted(_ session: ARSession) {
// Inform the user that the session has been interrupted, for example, by presenting an overlay
}

func sessionInterruptionEnded(_ session: ARSession) {
// Reset tracking and/or remove existing anchors if consistent tracking is required
}
}
@@ -15,6 +15,8 @@ class TeamMediaCollectionViewController: TBACollectionViewController {
var playerViews: [String: PlayerView] = [:]
var downloadedImages: [String: UIImage] = [:]

var selectedMedia: (() -> Void)!

// MARK: - View Lifecycle
override func viewDidLoad() {
@@ -98,6 +100,10 @@ class TeamMediaCollectionViewController: TBACollectionViewController {
guard let media = dataSource?.object(at: indexPath) else {
return
}
if media.type == MediaType.grabcad.rawValue {
selectedMedia()
return
}
guard let url = media.viewImageURL else {
return
}
@@ -165,6 +165,9 @@ class TeamViewController: ContainerViewController, Observable {
mediaViewController = segue.destination as? TeamMediaCollectionViewController
mediaViewController.team = team
mediaViewController.year = year
mediaViewController.selectedMedia = { [weak self] in
self?.performSegue(withIdentifier: "ARKitRobotSegue", sender: nil)
}
} else if segue.identifier == "TeamAtEventSegue" {
let event = sender as! Event
let teamAtEventViewController = segue.destination as! TeamAtEventViewController
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="caC-xe-F51">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="caC-xe-F51">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
@@ -177,6 +177,7 @@
<outlet property="segmentedControl" destination="4e3-cZ-Ovp" id="7zR-OZ-9YF"/>
<outlet property="segmentedControlView" destination="7wB-xc-qxs" id="OZU-iw-BC2"/>
<segue destination="Lps-JK-pYU" kind="show" identifier="TeamAtEventSegue" id="8Uu-oj-Z11"/>
<segue destination="Ef2-Sr-Gbz" kind="presentation" identifier="ARKitRobotSegue" id="4ha-1j-yi0"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Fgu-2m-Jdl" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -188,6 +189,38 @@
</objects>
<point key="canvasLocation" x="1560.8" y="465.51724137931041"/>
</scene>
<!--Kit Robot View Controller-->
<scene sceneID="V4F-b6-PcH">
<objects>
<viewController id="Ef2-Sr-Gbz" customClass="ARKitRobotViewController" customModule="The_Blue_Alliance" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Rqf-Oc-McU"/>
<viewControllerLayoutGuide type="bottom" id="rYF-vR-J99"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="m80-di-abK">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<arscnView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fJn-h1-7Ht">
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
</arscnView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="rYF-vR-J99" firstAttribute="top" secondItem="fJn-h1-7Ht" secondAttribute="bottom" id="Eka-1L-9BO"/>
<constraint firstItem="fJn-h1-7Ht" firstAttribute="top" secondItem="Rqf-Oc-McU" secondAttribute="bottom" id="Erd-Lj-38e"/>
<constraint firstAttribute="trailing" secondItem="fJn-h1-7Ht" secondAttribute="trailing" id="Vkn-nq-wLF"/>
<constraint firstItem="fJn-h1-7Ht" firstAttribute="leading" secondItem="m80-di-abK" secondAttribute="leading" id="W1j-Vr-NMX"/>
</constraints>
</view>
<connections>
<outlet property="sceneView" destination="fJn-h1-7Ht" id="bc6-Pf-tcY"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4uz-f9-zJd" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2582" y="466"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="oEx-y3-Wd4">
<objects>
Binary file not shown.

0 comments on commit 80f1647

Please sign in to comment.
You can’t perform that action at this time.