3. ARcore - waterglass2s/GraduationProject GitHub Wiki
Development Environment
Android Studio compileSdkVersion 29 / buildToolsVersion 29.0.3
Install Android Studio version 3.1 or higher with Android SDK Platform version 7.0 (API level 24) or higher.
Library version
google vision API - 1.15.0
There is a separate mobile phone model that can use ARCore. So you should check the list --> Go and check
How to use ARcore
Before you start,
- Modify your
AndroidManifest.xmlto include the following entries:
<uses-permission android:name="android.permission.CAMERA" />
<!-- Limits app visibility in the Google Play Store to ARCore supported devices
(https://developers.google.com/ar/devices). -->
<uses-feature android:name="android.hardware.camera.ar" />
<application …>
…
<!-- "AR Required" app, requires "Google Play Services for AR" (ARCore)
to be installed, as the app does not include any non-AR features. -->
<meta-data android:name="com.google.ar.core" android:value="required" />
</application>
- Ensure that your app has at least the required minSdkVersion in your app's build.gradle
android {
defaultConfig {
…
minSdkVersion 24
}
}
- Make sure your project's build.gradle file includes Google's Maven repository:
allprojects {
repositories {
google()
…
}
}
- Add the latest ARCore library as a dependency in your app's build.gradle file:
dependencies {
…
implementation 'com.google.ar:core:(your_version)'
}
--> More information, Click here
Then, you can use ARcore at Android Studio.
Use ARcore
1. First, create AR view
arFragment.setOnTapArPlaneListener(new BaseArFragment.OnTapArPlaneListener(){
@Override
public void onTapPlane(HitResult hitResult, Plane plane, MotionEvent motionEvent) {
//when user tap on plane, we will add model
if(selected == 1)
{
Anchor anchor = hitResult.createAnchor();
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(arFragment.getArSceneView().getScene());
createModel(anchorNode,selected);
}
}
});
- Create augmented name card
private void createModel(AnchorNode anchorNode, int selected){
if(selected == 1){
TransformableNode ar_text = new TransformableNode(arFragment.getTransformationSystem());
ar_text.setParent(anchorNode);
ar_text.setRenderable(tigerRenderable);
ar_text.select();
addName(anchorNode, ar_text, card_content);
}
}
- Show the content to the AR view after clicked
private void addName(AnchorNode anchorNode, TransformableNode model, String name){
TransformableNode nameView = new TransformableNode(arFragment.getTransformationSystem());
nameView.setLocalPosition(new Vector3(0f, model.getLocalPosition().y+0.5f,0));
nameView.setParent(anchorNode);
nameView.setRenderable(content);
nameView.select();
TextView txt_name = (TextView)content.getView();
txt_name.setText(name);
txt_name.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
anchorNode.setParent(null);
}
});
}