com.google.ar.core.exceptions.CameraNotAvailableException Java Examples
The following examples show how to use
com.google.ar.core.exceptions.CameraNotAvailableException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SumerianConnector.java From amazon-sumerian-arcore-starter-app with Apache License 2.0 | 5 votes |
@JavascriptInterface public void requestHitTest(final String requestId, final float screenX, final float screenY) { if (requestId == null) { return; } mSurfaceView.queueEvent(new Runnable() { @Override public void run() { final float hitTestX = screenX * mWebView.getWidth(); final float hitTestY = screenY * mWebView.getHeight(); List<HitResult> hitTestResults = null; try { hitTestResults = mSession.update().hitTest(hitTestX, hitTestY); } catch (CameraNotAvailableException e) { e.printStackTrace(); } final String scriptString; if (hitTestResults.size() > 0) { hitTestResults.get(0).getHitPose().toMatrix(mHitTestResultPose, 0); scriptString = "ARCoreBridge.hitTestResponse('" + requestId + "', '" + serializeArray(mHitTestResultPose) + "');"; } else { scriptString = "ARCoreBridge.hitTestResponse('" + requestId + "', null);"; } evaluateWebViewJavascript(scriptString); } }); }
Example #2
Source File: LocationActivity.java From ARCore-Location with MIT License | 5 votes |
/** * Make sure we call locationScene.resume(); */ @Override protected void onResume() { super.onResume(); if (locationScene != null) { locationScene.resume(); } if (arSceneView.getSession() == null) { // If the session wasn't created yet, don't resume rendering. // This can happen if ARCore needs to be updated or permissions are not granted yet. try { Session session = DemoUtils.createArSession(this, installRequested); if (session == null) { installRequested = ARLocationPermissionHelper.hasPermission(this); return; } else { arSceneView.setupSession(session); } } catch (UnavailableException e) { DemoUtils.handleSessionException(this, e); } } try { arSceneView.resume(); } catch (CameraNotAvailableException ex) { DemoUtils.displayError(this, "Unable to get camera", ex); finish(); return; } if (arSceneView.getSession() != null) { showLoadingMessage(); } }
Example #3
Source File: SumerianConnector.java From amazon-sumerian-arcore-starter-app with Apache License 2.0 | 4 votes |
void update() { final Frame frame; try { frame = mSession.update(); } catch (CameraNotAvailableException e) { e.printStackTrace(); return; } final Camera camera = frame.getCamera(); if (camera.getTrackingState() == TrackingState.PAUSED) { return; } camera.getViewMatrix(mViewMatrix, 0); camera.getProjectionMatrix(mProjectionMatrix, 0, 0.02f, 20.0f); final String cameraUpdateString = "ARCoreBridge.viewProjectionMatrixUpdate('" + serializeArray(mViewMatrix) +"', '"+ serializeArray(mProjectionMatrix) + "');"; evaluateWebViewJavascript(cameraUpdateString); HashMap<String, float[]> anchorMap = new HashMap<>(); for (Anchor anchor : mSession.getAllAnchors()) { if (anchor.getTrackingState() != TrackingState.TRACKING) { continue; } final float[] anchorPoseMatrix = new float[16]; anchor.getPose().toMatrix(anchorPoseMatrix, 0); anchorMap.put(String.valueOf(anchor.hashCode()), anchorPoseMatrix); } if (anchorMap.size() > 0) { JSONObject jsonAnchors = new JSONObject(anchorMap); final String anchorUpdateScript = "ARCoreBridge.anchorTransformUpdate('" + jsonAnchors.toString() + "');"; evaluateWebViewJavascript(anchorUpdateScript); } if (frame.getLightEstimate().getState() != LightEstimate.State.NOT_VALID) { final float[] colorCorrectionRgba = new float[4]; frame.getLightEstimate().getColorCorrection(colorCorrectionRgba, 0); final String lightEstimateUpdateScript = "ARCoreBridge.lightingEstimateUpdate(" + String.valueOf(frame.getLightEstimate().getPixelIntensity()) + ", " + convertRgbaToTemperature(colorCorrectionRgba) + ");"; evaluateWebViewJavascript(lightEstimateUpdateScript); } // Image Recognition Collection<AugmentedImage> updatedAugmentedImages = frame.getUpdatedTrackables(AugmentedImage.class); for (AugmentedImage img : updatedAugmentedImages) { if (img.getTrackingState() == TrackingState.TRACKING) { if (img.getName().equals("SumerianAnchorImage")) { imageAnchorCreated(img); } } } }