0

我在哪里将 sceneform_hand_phone.png 图像更改为自定义图像?这是带有 ARCore 的 Android 库场景表单中使用的手的图像。

谢谢

4

2 回答 2

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);
    }
}

活动_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>

将自定义手部动画放在它自己的布局文件中(必须动态创建),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>

构建.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
}
于 2018-08-13T11:57:21.860 回答
0

这是您正在寻找的 API 端点 - 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)
    }
}
于 2018-11-16T00:56:59.133 回答