Skip to content

Commit

Permalink
Update samples to Azure Spatial Anchors 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Treasure committed Jul 26, 2019
1 parent 61a1e39 commit bd662ab
Show file tree
Hide file tree
Showing 195 changed files with 4,815 additions and 2,977 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
*.dll filter=lfs diff=lfs merge=lfs -text
*.jar filter=lfs diff=lfs merge=lfs -text
*.exe filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.pdb filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.7z filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "glm"]
path = Android/NDK/libraries/glm
url = https://github.com/g-truc/glm
29 changes: 0 additions & 29 deletions Android/Java/.idea/codeStyles/Project.xml

This file was deleted.

6 changes: 3 additions & 3 deletions Android/Java/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'com.android.application'

def azureSpatialAnchorsSdkVersion = '1.1.1'
def azureSpatialAnchorsSdkVersion = '1.3.0'

android {
compileSdkVersion 27
Expand Down Expand Up @@ -35,9 +35,9 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
//noinspection GradleDependency
implementation 'com.google.ar:core:1.7.0'
implementation 'com.google.ar:core:1.8.0'
//noinspection GradleDependency
implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.7.0'
implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.8.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation "com.microsoft.azure.spatialanchors:spatialanchors_jni:[${azureSpatialAnchorsSdkVersion}]"
implementation "com.microsoft.azure.spatialanchors:spatialanchors_java:[${azureSpatialAnchorsSdkVersion}]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ protected void onResume() {
super.onResume();

// ArFragment of Sceneform automatically requests the camera permission before creating the AR session,
// so we don't need to request the camera permission explicitly
// so we don't need to request the camera permission explicitly.
// This will cause onResume to be called again after the user responds to the permission request.
if (!SceneformHelper.hasCameraPermission(this)) {
return;
}
Expand All @@ -135,13 +136,10 @@ protected void onResume() {

finish();
}
}

@Override
protected void onStart() {
super.onStart();

startDemo();
if (currentDemoStep == DemoStep.Start) {
startDemo();
}
}

private void advanceDemo() {
Expand Down Expand Up @@ -229,7 +227,7 @@ private void advanceDemo() {

AnchorLocateCriteria nearbyLocateCriteria = new AnchorLocateCriteria();
NearAnchorCriteria nearAnchorCriteria = new NearAnchorCriteria();
nearAnchorCriteria.setDistanceInMeters(5);
nearAnchorCriteria.setDistanceInMeters(10);
nearAnchorCriteria.setSourceAnchor(anchorVisuals.get(anchorID).getCloudAnchor());
nearbyLocateCriteria.setNearAnchor(nearAnchorCriteria);
// Cannot run more than one watcher concurrently
Expand Down Expand Up @@ -447,7 +445,7 @@ private void startDemo() {

private void startNewSession() {
destroySession();

cloudAnchorManager = new AzureSpatialAnchorsManager(sceneView.getSession());
cloudAnchorManager.addAnchorLocatedListener(this::onAnchorLocated);
cloudAnchorManager.addLocateAnchorsCompletedListener(this::onLocateAnchorsCompleted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class AzureSpatialAnchorsManager {
private final CloudSpatialAnchorSession spatialAnchorsSession;

public AzureSpatialAnchorsManager(Session arCoreSession) {
if (arCoreSession == null) {
throw new IllegalArgumentException("The arCoreSession may not be null.");
}

spatialAnchorsSession = new CloudSpatialAnchorSession();
spatialAnchorsSession.getConfiguration().setAccountId(SpatialAnchorsAccountId);
spatialAnchorsSession.getConfiguration().setAccountKey(SpatialAnchorsAccountKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ protected void onResume() {
super.onResume();

// ArFragment of Sceneform automatically requests the camera permission before creating the AR session,
// so we don't need to request the camera permission explicitly
// so we don't need to request the camera permission explicitly.
// This will cause onResume to be called again after the user responds to the permission request.
if (!SceneformHelper.hasCameraPermission(this)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion Android/Java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.4.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Binary file modified Android/Java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions Android/Java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Feb 06 09:07:01 PST 2019
#Thu Jul 11 21:48:24 PDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
29 changes: 0 additions & 29 deletions Android/NDK/.idea/codeStyles/Project.xml

This file was deleted.

2 changes: 1 addition & 1 deletion Android/NDK/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set_target_properties(azurespatialanchorsndk PROPERTIES IMPORTED_LOCATION
# Import the glm header file from the NDK.
add_library( glm INTERFACE )
set_target_properties( glm PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${ANDROID_NDK}/sources/third_party/vulkan/src/libs/glm
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/../libraries/glm/glm
)

# This is the main app library.
Expand Down
8 changes: 3 additions & 5 deletions Android/NDK/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'com.android.application'

def azureSpatialAnchorsSdkVersion = '1.1.1'
def azureSpatialAnchorsSdkVersion = '1.3.0'

/*
The arcore aar library contains the native shared libraries. These are
Expand Down Expand Up @@ -53,17 +53,15 @@ android {

dependencies {
// ARCore library
implementation 'com.google.ar:core:1.7.0'
natives 'com.google.ar:core:1.7.0'
implementation 'com.google.ar:core:1.8.0'
natives 'com.google.ar:core:1.8.0'

// Spatial Services
implementation "com.microsoft.azure.spatialanchors:spatialanchors_ndk:[${azureSpatialAnchorsSdkVersion}]"
natives "com.microsoft.azure.spatialanchors:spatialanchors_ndk:[${azureSpatialAnchorsSdkVersion}]"

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation "com.microsoft.azure.spatialanchors:spatialanchors_java:[${azureSpatialAnchorsSdkVersion}]"

}

// Extracts the shared libraries from aars in the natives configuration.
Expand Down
4 changes: 2 additions & 2 deletions Android/NDK/app/src/main/assets/shaders/cube.frag
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

precision mediump float;

varying vec3 vColor;
uniform vec4 uColor;

void main() {
gl_FragColor = vec4(vColor, 1.0);
gl_FragColor = uColor;
}
4 changes: 0 additions & 4 deletions Android/NDK/app/src/main/assets/shaders/cube.vert
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
// Licensed under the MIT license.

attribute vec4 aPosition;
attribute vec3 aColor;

uniform mat4 uModelViewProjection;

varying vec3 vColor;

void main() {
gl_Position = uModelViewProjection * aPosition;
vColor = aColor;
}
37 changes: 33 additions & 4 deletions Android/NDK/app/src/main/cpp/AzureSpatialAnchorsApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ void AzureSpatialAnchorsApplication::OnDrawFrame() {
for (const auto& visualPair : m_anchorVisuals) {
const auto &visual = visualPair.second;

if (visual.color == NoColor)
{
continue;
}

ArTrackingState trackingState = AR_TRACKING_STATE_STOPPED;
ArAnchor_getTrackingState(m_arSession, visual.localAnchor, &trackingState);

Expand All @@ -156,7 +161,7 @@ void AzureSpatialAnchorsApplication::OnDrawFrame() {
ArPose_getMatrix(m_arSession, anchorPose.AcquireArPose(), glm::value_ptr(modelMat));

glm::mat4 mvp_mat = projectionMat * viewMat * modelMat;
m_cubeRenderer.Draw(mvp_mat);
m_cubeRenderer.Draw(mvp_mat, visual.color);
}
}

Expand Down Expand Up @@ -226,6 +231,7 @@ void AzureSpatialAnchorsApplication::OnTouched(float x, float y) {
AnchorVisual visual;
visual.localAnchor = anchor;
visual.identifier = ""; // Set local anchor id to empty.
visual.color = ReadyColor;

m_anchorVisuals[visual.identifier] = visual;

Expand All @@ -234,7 +240,7 @@ void AzureSpatialAnchorsApplication::OnTouched(float x, float y) {
}

void AzureSpatialAnchorsApplication::AcquireArHitResult(float x, float y, ArHitResult **hitResult) {
// Return if an oriented point was hit.
// Return if a plane or an oriented point was hit.
ArHitResultList* hitResultList = nullptr;
ArHitResultList_create(m_arSession, &hitResultList);
CHECK(hitResultList);
Expand All @@ -259,15 +265,30 @@ void AzureSpatialAnchorsApplication::AcquireArHitResult(float x, float y, ArHitR
ArTrackableType trackableType = AR_TRACKABLE_NOT_VALID;
ArTrackable_getType(m_arSession, trackable, &trackableType);

if (trackableType == AR_TRACKABLE_POINT) {
if (trackableType == AR_TRACKABLE_PLANE) {
Util::ScopedArPose hitPose(m_arSession);
ArHitResult_getHitPose(m_arSession, arHit, hitPose.AcquireArPose());
int32_t inPolygon = 0;
ArPlane* arPlane = ArAsPlane(trackable);
ArPlane_isPoseInPolygon(m_arSession, arPlane, hitPose.AcquireArPose(), &inPolygon);

if (inPolygon) {
*hitResult = arHit;
ArTrackable_release(trackable);
break;
}
} else if (trackableType == AR_TRACKABLE_POINT) {
ArPoint *arPoint = ArAsPoint(trackable);
ArPointOrientationMode mode;
ArPoint_getOrientationMode(m_arSession, arPoint, &mode);
if (mode == AR_POINT_ORIENTATION_ESTIMATED_SURFACE_NORMAL) {
*hitResult = arHit;
ArTrackable_release(trackable);
break;
}
}

ArTrackable_release(trackable);
}

ArHitResultList_destroy(hitResultList);
Expand Down Expand Up @@ -384,6 +405,7 @@ void AzureSpatialAnchorsApplication::AddEventListeners() {
foundVisual.cloudAnchor = args->Anchor();
foundVisual.localAnchor = foundVisual.cloudAnchor->LocalAnchor();
foundVisual.identifier = foundVisual.cloudAnchor->Identifier();
foundVisual.color = FoundColor;
m_anchorVisuals[foundVisual.identifier] = foundVisual;
}
break;
Expand Down Expand Up @@ -447,7 +469,7 @@ void AzureSpatialAnchorsApplication::QueryNearbyAnchors(std::shared_ptr<CloudSpa

auto criteria = std::make_shared<AnchorLocateCriteria>();
auto nearbyCriteria = std::make_shared<NearAnchorCriteria>();
nearbyCriteria->DistanceInMeters(5);
nearbyCriteria->DistanceInMeters(10);
nearbyCriteria->SourceAnchor(sourceAnchor);
criteria->NearAnchor(nearbyCriteria);

Expand Down Expand Up @@ -481,11 +503,13 @@ void AzureSpatialAnchorsApplication::CreateCloudAnchor() {
auto itr = m_anchorVisuals.find("");
auto &visual = itr->second;
if (status != Status::OK) {
visual.color = FailedColor;
m_buttonText = "Save Failed: " + std::to_string(static_cast<uint32_t>(status));
return;
}
m_saveCount++;
visual.identifier = visual.cloudAnchor->Identifier();
visual.color = SavedColor;
m_anchorVisuals[visual.identifier] = visual;
m_anchorVisuals.erase("");

Expand All @@ -507,11 +531,16 @@ void AzureSpatialAnchorsApplication::DeleteCloudAnchor() {
for (auto &toDeleteVisualPair : m_anchorVisuals) {
auto &visual = toDeleteVisualPair.second;
std::string id = visual.identifier;
visual.color = NoColor;
m_cloudSession->DeleteAnchorAsync(visual.cloudAnchor,
[this, id](Status status) {
m_saveCount--;
if (status != Status::OK) {
m_buttonText = "Delete Failed: " + std::to_string(static_cast<uint32_t>(status));
auto itr = m_anchorVisuals.find(id);
if (itr != m_anchorVisuals.end()) {
itr->second.color = FailedColor;
}
}

if (m_demoMode == DemoMode::Basic || m_saveCount == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace AzureSpatialAnchors {
ArAnchor* localAnchor;
std::shared_ptr<Microsoft::Azure::SpatialAnchors::CloudSpatialAnchor> cloudAnchor;
std::string identifier;
glm::vec3 color;
};

ArSession* m_arSession = nullptr;
Expand Down
Loading

0 comments on commit bd662ab

Please sign in to comment.