0

Link to the app on google drive I have this app on gitHub but its not the exact same as this one, thats why I uploaded this version on google drive instead of gitHub

screenshot the screenshot also includes a summery of the problem

Newbie here, this might be a simple fix but I just haven't found it.

I have a menu with pictures/icons of furniture at the bottom of my screen. I want that when you click on one of the pictures and click on an anchor(place where I can put the object/asset), the object should be placed on the anchor where you're tapping

I tried logging to the debug console after tapping an anchor, just to see if the app recognizes what asset/object had been tapped on.

So if I tapped on the chair for example and then tapped on the anchor the app does manage to recognize that I tapped on a chair.

I have the sceneform plugin installed I have sceneform in my gradle dependencies

Sorry for all this code, just dont know where the problem is exactly.

My guess is that it only arises when placing the object and I wanted to add it for anyone who might need to see the missing parts

//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" />

I expected that when I click on the a picture of a furniture item and then the anchor, the object would show up on the anchor. Instead when I do this the app kind of "glitches" and then I dont get any response from my taps

ThandoBhebhe
  • 675
  • 1
  • 5
  • 11

1 Answers1

0

So after doing some testing on different devices I managed to an error message on one of them stating that there was "No such file". So I figured it must be the paths defined to the files. After fixing that I managed to get it working

ThandoBhebhe
  • 675
  • 1
  • 5
  • 11