//Sceneform UX provides UX resources, including ArFragment//
implementation "com.google.ar.sceneform.ux:sceneform-ux:1.17.1"
implementation "com.android.support:appcompat-v7:28.0.0"
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.ar" android:required="true" />
<meta-data android:name="com.google.ar.core" android:value="required" />
apply plugin: 'com.google.ar.sceneform.plugin'
sceneform.asset('sampledata/Future_Car.obj', //The “Source Asset Path” you specified during import//
'default', //The “Material Path” you specified during import//
'sampledata/Future_Car.sfa', //The “.sfa Output Path” you specified during import//
'src/main/assets/Future_Car') //The “.sfb Output Path” you specified during import//
classpath 'com.google.ar.sceneform:plugin:1.17.1'
Step 17: Now open activity_a_r_screen.xml and change the layout to Relative and update the code as shown below
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".app.ARScreen">
<Button
android:id="@+id/btnbackList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="23dp"
android:layout_marginTop="16dp"
android:background="@color/transparent"
android:drawableStart="@drawable/baseline_keyboard_backspace_black_18dp"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="0dp" />
<fragment
android:id="@+id/arFragment"
android:name="com.google.ar.sceneform.ux.ArFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="0dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="0dp"
android:layout_marginBottom="-2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</RelativeLayout>
.
package com.nithesh.saparapp.app;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import com.google.ar.core.Anchor;
import com.google.ar.sceneform.AnchorNode;
import com.google.ar.sceneform.rendering.ModelRenderable;
import com.google.ar.sceneform.ux.ArFragment;
import com.google.ar.sceneform.ux.TransformableNode;
import com.nithesh.saparapp.R;
public class ARScreen extends AppCompatActivity {
private ArFragment arFragment;
Button navback;
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_a_r_screen);
arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.arFragment);
arFragment.setOnTapArPlaneListener((hitResult, plane, motionEvent) -> {
Anchor anchor = hitResult.createAnchor();
ModelRenderable.builder()
.setSource(this, Uri.parse("Future_Car.sfb"))
.build()
.thenAccept(modelRenderable -> addModelToScene(anchor, modelRenderable))
.exceptionally(throwable -> {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(throwable.getMessage())
.show();
return null;
});
});
navback = findViewById(R.id.btnbackList);
navback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
private void addModelToScene(Anchor anchor, ModelRenderable modelRenderable) {
AnchorNode anchorNode = new AnchorNode(anchor);
TransformableNode transformableNode = new TransformableNode(arFragment.getTransformationSystem());
transformableNode.setParent(anchorNode);
transformableNode.setRenderable(modelRenderable);
arFragment.getArSceneView().getScene().addChild(anchorNode);
transformableNode.select();
}
}
case ARScreen:
intent = new Intent(context, ARScreen.class);
break;
ARScreen("ARScreen",R.string.title_activity_a_r_screen , BLUE_ANDROID_ICON);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |