-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved around the functions in example project to make things clearer …
…what is going on
- Loading branch information
1 parent
57f0064
commit 5f1328a
Showing
4 changed files
with
115 additions
and
10 deletions.
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
MultipeerHelper+Example/MultipeerHelper+Example/RealityViewController+Gestures.swift
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
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) | ||
} | ||
} |
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
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