不确定如何用语言表达。我的应用程序在将元素放置在平面上时出现故障,此后没有任何响应

时间:2019-04-09 19:30:33

标签: android arcore sceneform android-augmented-reality

Link to the app on google drive我在gitHub上安装了此应用,但与此应用不完全相同,这就是为什么我将此版本上传到google驱动器而不是gitHub

screenshot屏幕截图还包含问题的摘要

这里的新手,这可能是一个简单的修复程序,但我只是没有找到它。

我在屏幕底部有一个带有家具图片/图标的菜单。我希望当您单击其中一张图片并单击锚点(我可以在其中放置对象/资产的地方)时,应将对象放置在您点击的锚点上

我尝试在点击锚点后登录到调试控制台,只是为了查看应用程序是否识别出被窃听了什么资产/对象。

例如,如果我轻按椅子,然后轻按锚点,则应用程序确实设法识别出我轻按了椅子。

我已经安装了sceneform插件 我的gradle依赖项中有sceneform

对不起,所有这些代码,只是不知道问题出在哪里。

我的猜测是它只会在放置对象时出现,我想为可能需要查看缺失部分的任何人添加它

//My imports

package com.google.ar.sceneform.overlei;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.google.ar.core.Anchor;
import com.google.ar.core.HitResult;
import com.google.ar.core.Plane;
import com.google.ar.sceneform.AnchorNode;
import com.google.ar.sceneform.rendering.ModelRenderable;
import com.google.ar.sceneform.rendering.Renderable;
import com.google.ar.sceneform.samples.Overlei.R;
import com.google.ar.sceneform.ux.ArFragment;
import com.google.ar.sceneform.ux.TransformableNode;

//At this point i have installed the google sceneform plugin. This is 
//whats going to help be able to work with 3D assets


public class Overlei extends AppCompatActivity {

private ArFragment fragment;
private Uri currentltySelectedObject;

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

//brings up hand and camera to scan environment
setContentView(R.layout.activity_ux);

fragment = (ArFragment) 
getSupportFragmentManager().findFragmentById(R.id.sceneform_fragment);

initializeGallary();


fragment.setOnTapArPlaneListener((HitResult hitResult, Plane plane, 
MotionEvent motionEvent) -> {


          //checking if the scene being detected is horizontal

          if (plane.getType() != Plane.Type.HORIZONTAL_UPWARD_FACING) {
            return;
          }

          //creating anchor
          Anchor anchor = hitResult.createAnchor();
          placeObject(fragment, anchor, currentltySelectedObject);

        }
);

}

//show the menu at the bottom (this works)

public void initializeGallary() {

LinearLayout gallary = findViewById(R.id.gallery_layout);

//create chair thumbnails/picturee
ImageView chair = new ImageView(this);
chair.setImageResource(R.drawable.chair_thumb);
chair.setContentDescription("chair asset");

//parsing the file, gives reference to object
chair.setOnClickListener(view -> currentltySelectedObject = 
Uri.parse("chair.sfb"));
gallary.addView(chair);

//create couch picture/icon
//where im getting the image from
ImageView couch = new ImageView(this);
//imageView resource
couch.setImageResource(R.drawable.couch_thumb);
//attaching a description
couch.setContentDescription("couch asset");
//setting onclick action to set the currentlySelectedObject
couch.setOnClickListener(view -> currentltySelectedObject = 
Uri.parse("couch.sfb"));
gallary.addView(couch);

//lampPost picture/icon
ImageView lampPost = new ImageView(this);
lampPost.setImageResource(R.drawable.lamp_thumb);
lampPost.setContentDescription("lampPost asset");
lampPost.setOnClickListener(view -> currentltySelectedObject = 
Uri.parse("lampPost.sfb"));
gallary.addView(lampPost);
}

//anchor is where im going to place the object takes into
//this method also has 'build' call method called addNodeToScene, find 
//this method below

private void placeObject(ArFragment arFragment, Anchor anchor, Uri model) {
ModelRenderable.builder().setSource(arFragment.getContext(), 
model).build()

        .thenAccept(renderable -> addNodeToScene(arFragment, anchor, 
renderable)).exceptionally((throwable -> {
  AlertDialog.Builder builder = new AlertDialog.Builder(this);
  builder.setMessage(throwable.getMessage()).setTitle("Error");

  AlertDialog dialog = builder.create();
  dialog.show();
  return null;
}));
}


private void addNodeToScene(ArFragment arFragment, Anchor anchor, 
Renderable renderable) {
//create an anchor node
AnchorNode anchorNode = new AnchorNode(anchor);
//create transformable node
TransformableNode transformableNode = new 
TransformableNode(arFragment.getTransformationSystem());
transformableNode.setRenderable(renderable);

//make anchorNode parent of transformable
transformableNode.setParent(anchorNode);
//add node for interactiion
arFragment.getArSceneView().getScene().addChild(anchorNode);

transformableNode.select();
  }

}


//============================XML CODE==============================
<android.support.constraint.ConstraintLayout 
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="com.google.ar.sceneform.overlei.Overlei">

<fragment
    android:id="@+id/sceneform_fragment"
    android:name="com.google.ar.sceneform.ux.ArFragment"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintBottom_toTopOf="@+id/gallery_layout"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_chainStyle="spread"
    app:layout_constraintVertical_weight="9" />

<LinearLayout
    android:id="@+id/gallery_layout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:gravity="center_horizontal"
    android:orientation="horizontal"

    android:visibility="visible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/sceneform_fragment"
    app:layout_constraintVertical_chainStyle="spread"
    app:layout_constraintVertical_weight="1" />

我希望当我单击家具的图片然后单击锚点时,该对象将显示在锚点上。取而代之的是,当我这样做时,该应用程序会出现“故障”,然后我的水龙头没有得到任何回应

1 个答案:

答案 0 :(得分:0)

因此,在不同的设备上进行了一些测试之后,我设法在其中一个设备上收到一条错误消息,指出没有“此类文件”。因此,我认为它必须是定义到文件的路径。修复后,我设法使其正常工作