-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish Command Scheduler and start trajectory rendering
- Loading branch information
Showing
12 changed files
with
306 additions
and
163 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,47 +1,78 @@ | ||
import ARKit | ||
|
||
class CommandScheduler { | ||
var subscriptionID: Int? | ||
var namesSubID: Int? | ||
|
||
let view = CommandSchedulerView() | ||
var node: SCNNode! | ||
var plane: SCNPlane! | ||
var arScene: ARSceneView! | ||
|
||
var planeSize: Float = 0.25 | ||
var size: Float = 0.25 | ||
var height: Float = 3.0 | ||
var visible = true | ||
|
||
// add constructor | ||
var commands: [String] = [] | ||
|
||
var hasUpdatedLabel = false | ||
|
||
init(scene: ARSceneView) { | ||
NSLog("Initializing CommandScheduler") | ||
arScene = scene | ||
|
||
loadViewNode() | ||
} | ||
|
||
func subscribeToCommandScheduler(client: NT4Client, key: String) { | ||
if subscriptionID != nil { | ||
client.unsubscribe(subID: subscriptionID!) | ||
if namesSubID != nil { | ||
client.unsubscribe(subID: namesSubID!) | ||
} | ||
subscriptionID = client.subscribe( | ||
key: key, callback: { topic, timestamp, data in }, periodic: 0.1) | ||
namesSubID = client.subscribe( | ||
key: key + "/Names", | ||
callback: { topic, timestamp, data in | ||
if let commands = data as? [String] { | ||
NSLog("Recieved commands: \(commands.joined(separator: ", "))") | ||
if commands != self.commands { | ||
self.commands = commands | ||
self.updateCommands() | ||
} | ||
} | ||
}, periodic: 0.1) | ||
} | ||
|
||
func loadViewNode() { | ||
let image = view.asImage() | ||
let aspectRatio = image.size.width / image.size.height | ||
plane = SCNPlane(width: CGFloat(size), height: CGFloat(size) / aspectRatio) | ||
plane.firstMaterial?.diffuse.contents = image | ||
private func loadViewNode() { | ||
plane = SCNPlane(width: CGFloat(planeSize), height: CGFloat(planeSize)) | ||
plane.firstMaterial?.isDoubleSided = true | ||
|
||
node = SCNNode(geometry: plane) | ||
regenImage() | ||
|
||
let billboardConstraint = SCNBillboardConstraint() | ||
billboardConstraint.freeAxes = [.Y, .X] | ||
node.constraints = [billboardConstraint] | ||
|
||
node.isHidden = UserDefaults.standard.bool(forKey: "schedulerVisible") | ||
node.isHidden = !UserDefaults.standard.bool(forKey: "schedulerVisible") | ||
} | ||
|
||
private func updateCommands() { | ||
view.setCommands(commands) | ||
|
||
if commands.count > 0 { | ||
view.updateLabel(with: "\(commands.count) Commands") | ||
} else { | ||
view.updateLabel(with: "No Data") | ||
} | ||
|
||
regenImage() | ||
} | ||
|
||
func regenImage() { | ||
let image = view.asImage() | ||
let aspectRatio = image.size.width / image.size.height | ||
plane.width = CGFloat(planeSize) | ||
plane.height = CGFloat(planeSize) / aspectRatio | ||
plane.firstMaterial?.diffuse.contents = image | ||
|
||
arScene.scene.rootNode.addChildNode(node) | ||
node.geometry = plane | ||
} | ||
} |
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
Empty file.
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
Oops, something went wrong.