首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ARCORE: Sceneform 1.16渲染问题

ARCORE: Sceneform 1.16渲染问题
EN

Stack Overflow用户
提问于 2020-09-21 11:14:39
回答 2查看 453关注 0票数 1

我正在使用Sceneform 1.16和andriod Studio4.1,我试图渲染,但它不起作用。

问题:

activity.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".MainActivity">

    <fragment android:name="com.google.ar.sceneform.ux.ArFragment"  <======Error ArFragment must be a fragment >
        android:id="@+id/ux_fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


</FrameLayout>

  1. MainActivity.java.

公共类MainActivity扩展AppCompatActivity {

私有ArFragment arFragment;私有ModelRenderable modelRenderable;@重写受保护的modelRenderable onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);arFragment = (ArFragment)

错误:

代码语言:javascript
运行
复制
Inconvertible types; cannot cast 'androidx.fragment.app.Fragment' to 'com.google.ar.sceneform.ux.ArFragment'

我们遵循了以下步骤:https://github.com/google-ar/sceneform-android-sdk

-开始使用Sceneform 1.16.0

你能告诉我是怎么回事吗。

生成分级文件

代码语言:javascript
运行
复制
apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "30.0.1"

    defaultConfig {
        applicationId "com.examples.myapplication"
        minSdkVersion 24
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions{
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'


    api project(":sceneformux")



}
EN

回答 2

Stack Overflow用户

发布于 2021-05-28 20:57:17

您应该编辑settings.gradle文件。增加以下几行:

代码语言:javascript
运行
复制
include ':sceneform'
project(':sceneform').projectDir = new File('sceneformsrc/sceneform')

include ':sceneformux'
project(':sceneformux').projectDir = new File('sceneformux/ux')
票数 0
EN

Stack Overflow用户

发布于 2022-04-21 09:40:26

您有扩展ArFragment的片段类吗?我就像

代码语言:javascript
运行
复制
<fragment android:name="com.example.zzz.FaceARFragment"
    android:id="@+id/face_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

它是一个FaceARFragment扩展ArFragment类,仅用于配置。在活动中:

代码语言:javascript
运行
复制
FaceARFragment arFragment = (FaceARFragment) getSupportFragmentManager().findFragmentById(R.id.face_fragment);

对我起作用了。您也可以尝试使用Sceneform 1.17,我尝试使用1.16,但是1.17对我来说更好,因为我使用的是.glb模型。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63991143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档