0

where I change the sceneform_hand_phone.png image to a custom one?. This is the image of the hand that is used in the library sceneform for Android with ARCore.

Thank you

Atlas Keel
  • 21
  • 1

2 Answers2

5

HelloSceneformActivity.java:

public class HelloSceneformActivity extends AppCompatActivity {
    private ArFragment arFragment;
    private View phoneImage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_ux);

        // Get AR fragment from layout
        arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);

        // Disable plane discovery hand motion animation
        arFragment.getPlaneDiscoveryController().hide();

        ViewGroup container = findViewById(R.id.sceneform_hand_layout);
        container.removeAllViews();

        // Create the new plane discovery animation and add it to the hand layout.
        phoneImage = getLayoutInflater().inflate(R.layout.hand_layout, container, true);

        // Set the instructions view in the plane discovery controller.
        arFragment.getPlaneDiscoveryController().setInstructionView(phoneImage);
    }
}

activity_ux.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/sceneform_hand_layout"
    android:clipChildren="false"
    tools:context=".HelloSceneformActivity">

  <fragment class="com.google.ar.sceneform.ux.ArFragment"
      android:id="@+id/ux_fragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />

</FrameLayout>

Put the custom hand animation in it's own layout file (it must be created dynamically), hand_layout.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  <com.google.ar.sceneform.ux.HandMotionView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:foregroundGravity="center"
      android:scaleType="center"
      android:src="@drawable/YOURIMAGE" />

</FrameLayout>

build.gradle:

buildscript {
    repositories {
        google()
        jcenter()
        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
       classpath 'com.google.ar.sceneform:plugin:1.3.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenLocal()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Canato
  • 3,598
  • 5
  • 33
  • 57
  • Hello I did what you indicate, the new image appears but the camera does not appear. Only the image with white background is seen. – Atlas Keel Aug 19 '18 at 12:06
  • @AtlasKeel sorry for delay, but ti show is not related with this code. I'm on another country now far away from my laptop, but you need to render the frame. – Canato Aug 22 '18 at 10:53
0

Here's the API endpoint you're looking for - https://developers.google.com/ar/reference/java/com/google/ar/sceneform/ux/PlaneDiscoveryController#setInstructionView(android.view.View)

class ExampleFragment : ArFragment() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState);
        ...
        val customDiscoveryView = <inflate custom view>
        planeDiscoveryController.setInstructionView(customDiscoveryView)
    }
}
AlgoRyan
  • 537
  • 3
  • 10