From 2e290d22ea53950aec05198f143e1a5995fed47a Mon Sep 17 00:00:00 2001 From: MrCsabaToth Date: Thu, 10 Nov 2022 20:28:29 -0800 Subject: [PATCH 1/6] Coarse location is needed besides fine location for API level 30+ Bump compile and target SDK level to 33 and bump app version --- app/build.gradle | 8 ++++---- app/src/main/AndroidManifest.xml | 1 + .../hellogeospatial/helpers/GeoPermissionsHelper.kt | 6 +++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 406e40c..7970130 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,16 +2,16 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { - compileSdkVersion 30 + compileSdkVersion 33 defaultConfig { applicationId "com.google.ar.core.codelabs.hellogeospatial" // AR Optional apps must declare minSdkVersion >= 14. // AR Required apps must declare minSdkVersion >= 24. minSdkVersion 24 - targetSdkVersion 30 - versionCode 1 - versionName '1.0' + targetSdkVersion 33 + versionCode 2 + versionName '1.1' } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3966cfc..c762462 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,6 +20,7 @@ + diff --git a/app/src/main/java/com/google/ar/core/codelabs/hellogeospatial/helpers/GeoPermissionsHelper.kt b/app/src/main/java/com/google/ar/core/codelabs/hellogeospatial/helpers/GeoPermissionsHelper.kt index 1712924..661dd0b 100644 --- a/app/src/main/java/com/google/ar/core/codelabs/hellogeospatial/helpers/GeoPermissionsHelper.kt +++ b/app/src/main/java/com/google/ar/core/codelabs/hellogeospatial/helpers/GeoPermissionsHelper.kt @@ -26,7 +26,11 @@ import androidx.core.content.ContextCompat /** Helper to ask camera permission. */ object GeoPermissionsHelper { - private val PERMISSIONS = arrayOf(Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION) + private val PERMISSIONS = arrayOf( + Manifest.permission.CAMERA, + Manifest.permission.ACCESS_COARSE_LOCATION, + Manifest.permission.ACCESS_FINE_LOCATION + ) /** Check to see we have the necessary permissions for this app. */ fun hasGeoPermissions(activity: Activity): Boolean { From 126a93da3663d4f2c67e6ebc0108b721a4249d03 Mon Sep 17 00:00:00 2001 From: MrCsabaToth Date: Thu, 10 Nov 2022 20:29:31 -0800 Subject: [PATCH 2/6] Bump Gradle version to latest (by the IDE) --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 602b719..f523574 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { mavenCentral() } dependencies { - classpath "com.android.tools.build:gradle:4.1.1" + classpath 'com.android.tools.build:gradle:7.3.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 57b1b7c..c389b99 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip From f5679734f312dd921d923231e21d5554f8db8d98 Mon Sep 17 00:00:00 2001 From: MrCsabaToth Date: Thu, 10 Nov 2022 20:31:27 -0800 Subject: [PATCH 3/6] Bump package versions (suggested by the IDE) --- app/build.gradle | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7970130..da411e7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,21 +30,21 @@ android { dependencies { // ARCore (Google Play Services for AR) library. - implementation 'com.google.ar:core:1.31.0' + implementation 'com.google.ar:core:1.34.0' // Obj - a simple Wavefront OBJ file loader // https://github.com/javagl/Obj implementation 'de.javagl:obj:0.2.1' - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0' + implementation 'androidx.appcompat:appcompat:1.5.1' + implementation 'androidx.lifecycle:lifecycle-common-java8:2.5.1' - implementation 'com.google.android.material:material:1.1.0' + implementation 'com.google.android.material:material:1.7.0' implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation 'com.google.android.gms:play-services-auth:20+' - implementation 'com.google.android.gms:play-services-location:19+' - implementation 'com.google.android.gms:play-services-maps:18.0.2' + implementation 'com.google.android.gms:play-services-auth:20.3.0' + implementation 'com.google.android.gms:play-services-location:21.0.1' + implementation 'com.google.android.gms:play-services-maps:18.1.0' } From 0a7f4da50cf67a52ecd5b90c6e6635e621602c53 Mon Sep 17 00:00:00 2001 From: MrCsabaToth Date: Thu, 10 Nov 2022 20:31:59 -0800 Subject: [PATCH 4/6] Bump Kotlin version (suggested by the IDE) --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index f523574..fe0f7d8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.4.20' + ext.kotlin_version = '1.7.20' repositories { google() mavenCentral() From 7d19e979418ff30face750b3a48d0d302ebfbd85 Mon Sep 17 00:00:00 2001 From: MrCsabaToth Date: Thu, 10 Nov 2022 20:34:49 -0800 Subject: [PATCH 5/6] various lint suggested changes and readability --- app/src/main/AndroidManifest.xml | 1 - .../ar/core/codelabs/hellogeospatial/HelloGeoRenderer.kt | 6 +++--- .../hellogeospatial/helpers/ARCoreSessionLifecycleHelper.kt | 2 +- .../hellogeospatial/helpers/GeoPermissionsHelper.kt | 2 +- .../ar/core/codelabs/hellogeospatial/helpers/MapView.kt | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c762462..bd23ca6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,7 +30,6 @@ { installRequested = true // tryCreateSession will be called again, so we return null for now. diff --git a/app/src/main/java/com/google/ar/core/codelabs/hellogeospatial/helpers/GeoPermissionsHelper.kt b/app/src/main/java/com/google/ar/core/codelabs/hellogeospatial/helpers/GeoPermissionsHelper.kt index 661dd0b..7bdb234 100644 --- a/app/src/main/java/com/google/ar/core/codelabs/hellogeospatial/helpers/GeoPermissionsHelper.kt +++ b/app/src/main/java/com/google/ar/core/codelabs/hellogeospatial/helpers/GeoPermissionsHelper.kt @@ -57,4 +57,4 @@ object GeoPermissionsHelper { intent.data = Uri.fromParts("package", activity.packageName, null) activity.startActivity(intent) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/google/ar/core/codelabs/hellogeospatial/helpers/MapView.kt b/app/src/main/java/com/google/ar/core/codelabs/hellogeospatial/helpers/MapView.kt index 639d8ae..baa5482 100644 --- a/app/src/main/java/com/google/ar/core/codelabs/hellogeospatial/helpers/MapView.kt +++ b/app/src/main/java/com/google/ar/core/codelabs/hellogeospatial/helpers/MapView.kt @@ -90,7 +90,7 @@ class MapView(val activity: HelloGeoActivity, val googleMap: GoogleMap) { color: Int, ): Marker { val markersOptions = MarkerOptions() - .position(LatLng(0.0,0.0)) + .position(LatLng(0.0, 0.0)) .draggable(false) .anchor(0.5f, 0.5f) .flat(true) @@ -110,4 +110,4 @@ class MapView(val activity: HelloGeoActivity, val googleMap: GoogleMap) { canvas.drawBitmap(navigationIcon, /* left= */0f, /* top= */0f, p) return navigationIcon } -} \ No newline at end of file +} From 35d01e6adc5820e9bd9b1ddb58aae053ddc77fdd Mon Sep 17 00:00:00 2001 From: MrCsabaToth Date: Sat, 21 Jan 2023 22:21:49 -0800 Subject: [PATCH 6/6] Adding back vert and frag shaders for depth visualization because BackgroundRenderer references them --- ...ground_show_depth_color_visualization.frag | 69 +++++++++++++++++++ ...ground_show_depth_color_visualization.vert | 25 +++++++ 2 files changed, 94 insertions(+) create mode 100644 app/src/main/assets/shaders/background_show_depth_color_visualization.frag create mode 100644 app/src/main/assets/shaders/background_show_depth_color_visualization.vert diff --git a/app/src/main/assets/shaders/background_show_depth_color_visualization.frag b/app/src/main/assets/shaders/background_show_depth_color_visualization.frag new file mode 100644 index 0000000..604b1d3 --- /dev/null +++ b/app/src/main/assets/shaders/background_show_depth_color_visualization.frag @@ -0,0 +1,69 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +precision mediump float; + +uniform sampler2D u_DepthTexture; +uniform sampler2D u_ColorMap; + +varying vec2 v_TexCoord; + +const float kMidDepthMeters = 8.0; +const float kMaxDepthMeters = 30.0; + +float DepthGetMillimeters(in sampler2D depth_texture, in vec2 depth_uv) { + // Depth is packed into the red and green components of its texture. + // The texture is a normalized format, storing millimeters. + vec3 packedDepthAndVisibility = texture2D(depth_texture, depth_uv).xyz; + return dot(packedDepthAndVisibility.xy, vec2(255.0, 256.0 * 255.0)); +} + +// Returns linear interpolation position of value between min and max bounds. +// E.g. InverseLerp(1100, 1000, 2000) returns 0.1. +float InverseLerp(float value, float min_bound, float max_bound) { + return clamp((value - min_bound) / (max_bound - min_bound), 0.0, 1.0); +} + +// Returns a color corresponding to the depth passed in. +// The input x is normalized in range 0 to 1. +vec3 DepthGetColorVisualization(in float x) { + return texture2D(u_ColorMap, vec2(x, 0.5)).rgb; +} + +void main() { + // Interpolating in units of meters is more stable, due to limited floating + // point precision on GPU. + float depth_mm = DepthGetMillimeters(u_DepthTexture, v_TexCoord.xy); + float depth_meters = depth_mm * 0.001; + + // Selects the portion of the color palette to use. + float normalized_depth = 0.0; + if (depth_meters < kMidDepthMeters) { + // Short-range depth (0m to 8m) maps to first half of the color palette. + normalized_depth = InverseLerp(depth_meters, 0.0, kMidDepthMeters) * 0.5; + } else { + // Long-range depth (8m to 30m) maps to second half of the color palette. + normalized_depth = + InverseLerp(depth_meters, kMidDepthMeters, kMaxDepthMeters) * 0.5 + 0.5; + } + + // Converts depth to color by with the selected value in the color map. + vec4 depth_color = vec4(DepthGetColorVisualization(normalized_depth), 1.0); + + // Invalid depth (pixels with value 0) mapped to black. + depth_color.rgb *= sign(depth_meters); + gl_FragColor = depth_color; +} diff --git a/app/src/main/assets/shaders/background_show_depth_color_visualization.vert b/app/src/main/assets/shaders/background_show_depth_color_visualization.vert new file mode 100644 index 0000000..7ef5853 --- /dev/null +++ b/app/src/main/assets/shaders/background_show_depth_color_visualization.vert @@ -0,0 +1,25 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +attribute vec4 a_Position; +attribute vec2 a_TexCoord; + +varying vec2 v_TexCoord; + +void main() { + v_TexCoord = a_TexCoord; + gl_Position = a_Position; +}