google-ar / sceneform-android-sdk

Sceneform SDK for Android
https://developers.google.com/sceneform/develop/
Apache License 2.0
1.23k stars 604 forks source link

ViewRenderable + ImageView in ARCore Android Studio #516

Open bhavikshah1995 opened 5 years ago

bhavikshah1995 commented 5 years ago

I am struggling with displaying an image fetched from a URL in an ImageView within a ViewRenderable. Here is my code.

Any help is much appreciated :)

if (rendobject == null) {

            rendobject =
          ViewRenderable.builder()
                  .setView(context, R.layout.imgboard)
                  .setVerticalAlignment(ViewRenderable.VerticalAlignment.BOTTOM)
                  .setSizer(new FixedHeightViewSizer(0.12f))
                  .build()
                  .thenAccept(renderable -> {
                     // testViewRenderable = renderable;

                     ImageView imageView = (ImageView) renderable.getView();
                     Picasso.get()
                             .load("http://scoopak.com/wp-content/uploads/2013/06/free-hd-natural-wallpapers-download-for-pc.jpg")
                             .into(imageView);

                 });

    /*      ModelRenderable.builder()
                  .setSource(context, Uri.parse("models/tinker.sfb"))
                  .build();
            */
}

}

bestog commented 5 years ago

@bhavikshah1995 Here is my answer to a similar issue ( #564 ). Does that help you?

dpacholczyk commented 5 years ago

funny thing. I'm struggling with the same issue at the moment

@bestog I must say that I have problems with connecting your issue with this one. With the 3D object that is converted the case is pretty easy. But here we have a simple view that needs to be connected with a node

dpacholczyk commented 5 years ago

@bhavikshah1995 did you managed to solve the problem?

bestog commented 5 years ago

@dpacholczyk maybe, but my comment in the other issue can solve this issue with another approach. Both issues have in the end the same goal. :)

bhavikshah1995 commented 5 years ago

@dpacholczyk @bestog yes, here is my code for the same:

        ImageView imageView = new ImageView(context);
        Picasso.get()
                  .load(R.drawable.resume)
                  .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
                  .into(imageView);

        rendobject =
          ViewRenderable.builder()
                  .setView(context, imageView)
                  .setVerticalAlignment(ViewRenderable.VerticalAlignment.BOTTOM)
                  .setSizer(new FixedHeightViewSizer(0.04f))
                  .build()
                  .thenAccept(renderable -> {
                              getTestViewRenderable2 = renderable;

                      Vector3 localPosition = new Vector3();
                      Node cornerNode2;

                      localPosition.set(+0.4f * image.getExtentX(), 0.01f, +0.2f * image.getExtentZ());
                      cornerNode2 = new Node();
                      cornerNode2.setParent(this);
                      cornerNode2.setLocalPosition(localPosition);
                      cornerNode2.setLocalRotation(Quaternion.axisAngle(new Vector3(-1f, 0, 0), 90f));
                      cornerNode2.setRenderable(getTestViewRenderable2);

                  });

You can load from a URL as well within Picasso

dpacholczyk commented 5 years ago

@bhavikshah1995 could you share the whole class? I would like to understand better what is "image" and where are you putting those specific parts. I have problems with running a similar example. I hope it's not a problem.

dpacholczyk commented 5 years ago

nvm I solved the problem :)