Skip to content

Commit

Permalink
render distant nodes behind closer nodes (#220)
Browse files Browse the repository at this point in the history
* render distant nodes behind closer nodes

* Use common code to calculate rendering order
Code style changes to match rest of code base

* Method comments get the triple slash treatment

* Update changelog
  • Loading branch information
Pilot-Marc authored and intere committed Sep 8, 2019
1 parent 1f75a59 commit 5804ee5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extension SCNNode {
/// Overlapping nodes require unique renderingOrder values to avoid flicker
/// This method will select random values if you don't care which node is in front of the other,
/// or you can specify a particular z-order value
/// Note: rendering order will be changed later based on distance from camera
func removeFlicker (withRenderingOrder renderingOrder: Int = Int.random(in: 1..<Int.max)) {
self.renderingOrder = renderingOrder
if let geom = geometry {
Expand Down
2 changes: 2 additions & 0 deletions Sources/ARKit-CoreLocation/Nodes/LocationAnnotationNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ open class LocationAnnotationNode: LocationNode {

let distance = self.location(locationManager.bestLocationEstimate).distance(from: location)

childNodes.first?.renderingOrder = renderingOrder(fromDistance: distance)

let adjustedDistance = self.adjustedDistance(setup: setup, position: position,
locationNodeLocation: nodeLocation, locationManager: locationManager)

Expand Down
12 changes: 12 additions & 0 deletions Sources/ARKit-CoreLocation/Nodes/LocationNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,23 @@ open class LocationNode: SCNNode {
SCNTransaction.begin()
SCNTransaction.animationDuration = setup ? 0.0 : 0.1

let distance = self.location(locationManager.bestLocationEstimate).distance(from:
locationManager.currentLocation ?? nodeLocation)

childNodes.first?.renderingOrder = renderingOrder(fromDistance: distance)

_ = self.adjustedDistance(setup: setup, position: position,
locationNodeLocation: nodeLocation, locationManager: locationManager)

SCNTransaction.commit()

onCompletion()
}

/// Converts distance from meters to SCNKit rendering order
/// Constant multiplier eliminates flicker caused by slight distance variations
/// Nodes with greater rendering orders are rendered last
func renderingOrder(fromDistance distance: CLLocationDistance) -> Int {
return Int.max - 1000 - (Int(distance * 1000))
}
}
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog
- 1.2.2
- [PR #220 - Render distant nodes behind closer nodes ](https://github.com/ProjectDent/ARKit-CoreLocation/pull/220)
- 1.2.1
- [PR #207 - Addresses Issue #136 - ARCL lacks CI ](https://github.com/ProjectDent/ARKit-CoreLocation/pull/207)
- [PR #209 - Updates polyline position/scale when GPS location is updated](https://github.com/ProjectDent/ARKit-CoreLocation/pull/209)
Expand Down

0 comments on commit 5804ee5

Please sign in to comment.