Skip to content

Commit

Permalink
moved around the functions in example project to make things clearer …
Browse files Browse the repository at this point in the history
…what is going on
  • Loading branch information
maxxfrazer committed Nov 23, 2019
1 parent 57f0064 commit 5f1328a
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
F32BA08D238935140075556C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F32BA08B238935140075556C /* LaunchScreen.storyboard */; };
F32BA096238936210075556C /* FocusEntity in Frameworks */ = {isa = PBXBuildFile; productRef = F32BA095238936210075556C /* FocusEntity */; };
F32BA0982389B1880075556C /* RealityViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F32BA0972389B1880075556C /* RealityViewController.swift */; };
F32BA09E2389B2760075556C /* MultipeerHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F32BA09C2389B2760075556C /* MultipeerHelper.swift */; };
F32BA09F2389B2760075556C /* MultipeerHelperDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F32BA09D2389B2760075556C /* MultipeerHelperDelegate.swift */; };
F32BA0A12389E6AB0075556C /* RealityViewController+Gestures.swift in Sources */ = {isa = PBXBuildFile; fileRef = F32BA0A02389E6AB0075556C /* RealityViewController+Gestures.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -25,6 +28,9 @@
F32BA08C238935140075556C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
F32BA08E238935140075556C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F32BA0972389B1880075556C /* RealityViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RealityViewController.swift; sourceTree = "<group>"; };
F32BA09C2389B2760075556C /* MultipeerHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MultipeerHelper.swift; path = ../Sources/MultipeerHelper/MultipeerHelper.swift; sourceTree = SOURCE_ROOT; };
F32BA09D2389B2760075556C /* MultipeerHelperDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MultipeerHelperDelegate.swift; path = ../Sources/MultipeerHelper/MultipeerHelperDelegate.swift; sourceTree = SOURCE_ROOT; };
F32BA0A02389E6AB0075556C /* RealityViewController+Gestures.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RealityViewController+Gestures.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -61,9 +67,11 @@
F32BA080238935120075556C /* AppDelegate.swift */,
F32BA082238935120075556C /* ContentView.swift */,
F32BA0972389B1880075556C /* RealityViewController.swift */,
F32BA0A02389E6AB0075556C /* RealityViewController+Gestures.swift */,
F32BA086238935140075556C /* Assets.xcassets */,
F32BA08B238935140075556C /* LaunchScreen.storyboard */,
F32BA08E238935140075556C /* Info.plist */,
F32BA0992389B2470075556C /* MultipeerHelper */,
F32BA088238935140075556C /* Preview Content */,
);
path = "MultipeerHelper+Example";
Expand All @@ -77,6 +85,16 @@
path = "Preview Content";
sourceTree = "<group>";
};
F32BA0992389B2470075556C /* MultipeerHelper */ = {
isa = PBXGroup;
children = (
F32BA09C2389B2760075556C /* MultipeerHelper.swift */,
F32BA09D2389B2760075556C /* MultipeerHelperDelegate.swift */,
);
name = MultipeerHelper;
path = "MultipeerHelper+Example/MultipeerHelper";
sourceTree = SOURCE_ROOT;
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -155,8 +173,11 @@
buildActionMask = 2147483647;
files = (
F32BA083238935120075556C /* ContentView.swift in Sources */,
F32BA0A12389E6AB0075556C /* RealityViewController+Gestures.swift in Sources */,
F32BA09F2389B2760075556C /* MultipeerHelperDelegate.swift in Sources */,
F32BA0982389B1880075556C /* RealityViewController.swift in Sources */,
F32BA081238935120075556C /* AppDelegate.swift in Sources */,
F32BA09E2389B2760075556C /* MultipeerHelper.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -224,7 +245,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.2;
IPHONEOS_DEPLOYMENT_TARGET = 13.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -278,7 +299,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.2;
IPHONEOS_DEPLOYMENT_TARGET = 13.1;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand All @@ -293,6 +314,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEAD_CODE_STRIPPING = NO;
DEVELOPMENT_ASSET_PATHS = "\"MultipeerHelper+Example/Preview Content\"";
DEVELOPMENT_TEAM = N2RTJDRM64;
ENABLE_PREVIEWS = YES;
Expand All @@ -313,6 +335,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEAD_CODE_STRIPPING = NO;
DEVELOPMENT_ASSET_PATHS = "\"MultipeerHelper+Example/Preview Content\"";
DEVELOPMENT_TEAM = N2RTJDRM64;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -356,8 +379,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/maxxfrazer/FocusEntity.git";
requirement = {
kind = revision;
revision = 21651462ef16713c8fca88da70a6037cf29324d3;
branch = master;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// RealityViewController+Gestures.swift
// MultipeerHelper+Example
//
// Created by Max Cobb on 11/23/19.
// Copyright © 2019 Max Cobb. All rights reserved.
//

import UIKit
import ARKit
import RealityKit

extension RealityViewController {
/// This function does two things. Sends a message "hello!" to all peers, and also adds a cube
/// at the touch location
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let myData = "hello!".data(using: .ascii) else {
return
}
self.multipeerHelp.sendToAllPeers(myData, reliably: true)

guard let touchInView = touches.first?.location(in: self.arView) else {
return
}

guard let result = arView.raycast(
from: touchInView,
allowing: .existingPlaneGeometry, alignment: .horizontal
).first else {
return
}

let arAnchor = ARAnchor(name: "Cube Anchor", transform: result.worldTransform)
let newAnchor = AnchorEntity(anchor: arAnchor)

let cubeModel = ModelEntity(
mesh: .generateBox(size: 0.1),
materials: [SimpleMaterial(color: .red, isMetallic: false)]
)
newAnchor.addChild(cubeModel)

newAnchor.synchronization?.ownershipTransferMode = .autoAccept

newAnchor.anchoring = AnchoringComponent(arAnchor)
self.arView.scene.addAnchor(newAnchor)
self.arView.session.add(anchor: arAnchor)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,61 @@
import RealityKit
import FocusEntity
import ARKit
import MultipeerConnectivity

class RealityViewController: UIViewController {
class RealityViewController: UIViewController, ARSessionDelegate {

let arView = ARView(frame: .zero)
let focusSquare = FESquare()
var multipeerHelp: MultipeerHelper!
required init() {
super.init(nibName: nil, bundle: nil)
setupARView()
setupMultipeer()

self.focusSquare.viewDelegate = self.arView
}

func session(_ session: ARSession, didUpdate frame: ARFrame) {
self.focusSquare.updateFocusNode()
}

func setupARView() {
arView.frame = self.view.bounds
self.arView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
arView.automaticallyConfigureSession = false

arView.session.delegate = self

let arConfiguration = ARWorldTrackingConfiguration()
arConfiguration.planeDetection = .horizontal
arConfiguration.isCollaborationEnabled = true

arView.session.run(arConfiguration, options: [])
self.view.addSubview(arView)
self.focusSquare.viewDelegate = self.arView

}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

extension RealityViewController: MultipeerHelperDelegate {
func setupMultipeer() {
self.multipeerHelp = MultipeerHelper(
sessionType: .both,
serviceName: "helper-test",
delegate: self
)

// MARK: - Setting RealityKit Synchronization
guard let syncService = multipeerHelp.syncService else {
fatalError("could not create multipeerHelp.syncService")
}
self.arView.scene.synchronizationService = syncService
}
func receivedData(_ data: Data, _ peer: MCPeerID) {
print(String(data: data, encoding: .ascii) ?? "Data is not an ASCII string")
}
func peerJoined(_ peer: MCPeerID) {
print("new peer has joined: \(peer.displayName)")
}
}
2 changes: 1 addition & 1 deletion Sources/MultipeerHelper/MultipeerHelperDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension MultipeerHelperDelegate {
print("receivedStream not implemented")
}
func receivingResource(_: String, _: MCPeerID, _: Progress) -> Void {
// print("receivingResource not implemented")
print("receivingResource not implemented")
}
func receivedResource(_: String, _: MCPeerID, _: URL?, _: Error?) -> Void {
print("receivedResource not implemented")
Expand Down

0 comments on commit 5f1328a

Please sign in to comment.