Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SCNNode type to init() of LocationAnnotationNode class and Annota… #307

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Node Demos/ARCLViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum Demonstration {
case fieldOfLabels
case fieldOfRadii
case dynamicNodes
case customNode
}

// swiftlint:disable:next type_body_length
Expand Down Expand Up @@ -94,6 +95,8 @@ class ARCLViewController: UIViewController {
// addSpriteKitNodes()
case .dynamicNodes:
addDynamicNodes()
case .customNode:
addCustomNode()
}
sceneLocationView?.run()
}
Expand Down Expand Up @@ -352,6 +355,29 @@ class ARCLViewController: UIViewController {
addScenewideNodeSettings(east10MetersLabelNode)
sceneLocationView?.addLocationNodeWithConfirmedLocation(locationNode: east10MetersLabelNode)
}

func addCustomNode(){
guard let currentLocation = sceneLocationView?.sceneLocationManager.currentLocation else {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
self?.addDynamicNodes()
}
return
}

// Copy the current location because it's a reference type. Necessary?
let referenceLocation = CLLocation(coordinate: currentLocation.coordinate, altitude: currentLocation.altitude)


let box = SCNBox(width: 1, height: 0.5, length: 15, chamferRadius: 0)

box.firstMaterial?.diffuse.contents = UIColor.blue
box.firstMaterial?.transparency = 0.9
let node = SCNNode(geometry: box)

let placeNode = LocationAnnotationNode(location: currentLocation, node: node)
addScenewideNodeSettings(placeNode)
sceneLocationView?.addLocationNodeWithConfirmedLocation(locationNode: placeNode)
}
}

// MARK: - ARSCNViewDelegate
Expand Down
17 changes: 15 additions & 2 deletions Sources/ARKit-CoreLocation/Nodes/LocationAnnotationNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,26 @@ open class LocationAnnotationNode: LocationNode {
/// To draw the label exactly on the true location, use a value of 0. To draw it below the true location,
/// use a negative value.
public var annotationHeightAdjustmentFactor = 1.1

public init(location : CLLocation?, node : SCNNode){
annotationNode = AnnotationNode(view: nil, image: nil, node: node)
annotationNode.addChildNode(node)
annotationNode.removeFlicker()
super.init(location: location)

let billboardConstraint = SCNBillboardConstraint()
billboardConstraint.freeAxes = SCNBillboardAxis.Y
constraints = [billboardConstraint]

addChildNode(annotationNode)
}

public init(location: CLLocation?, image: UIImage) {
let plane = SCNPlane(width: image.size.width / 100, height: image.size.height / 100)
plane.firstMaterial?.diffuse.contents = image
plane.firstMaterial?.lightingModel = .constant

annotationNode = AnnotationNode(view: nil, image: image)
annotationNode = AnnotationNode(view: nil, image: image, node: nil)
annotationNode.geometry = plane
annotationNode.removeFlicker()

Expand Down Expand Up @@ -55,7 +68,7 @@ open class LocationAnnotationNode: LocationNode {
plane.firstMaterial?.diffuse.contents = layer
plane.firstMaterial?.lightingModel = .constant

annotationNode = AnnotationNode(view: nil, image: nil, layer: layer)
annotationNode = AnnotationNode(view: nil, image: nil, layer: layer, node: nil)
annotationNode.geometry = plane
annotationNode.removeFlicker()

Expand Down
4 changes: 3 additions & 1 deletion Sources/ARKit-CoreLocation/Nodes/LocationNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ open class AnnotationNode: SCNNode {
public var view: UIView?
public var image: UIImage?
public var layer: CALayer?
public var node : SCNNode?

public init(view: UIView?, image: UIImage?, layer: CALayer? = nil) {
public init(view: UIView?, image: UIImage?, layer: CALayer? = nil, node : SCNNode?) {
super.init()
self.view = view
self.image = image
self.layer = layer
self.node = node
}

required public init?(coder aDecoder: NSCoder) {
Expand Down