Использование imageview в arcore - PullRequest
0 голосов
/ 29 января 2019

Моя цель - извлечь изображение из URL и отобразить его в ARCore.Однако, как новичок в Java, я точно не знаю, что объявлять, что и что, где передавать.Любая помощь приветствуется и не должна быть слишком сложной для тех, кто хорошо разбирается в Android-студии.

В конкретных терминах я пытаюсь сделать здесь загрузку изображения с помощью Picasso в ImageView (не уверен, должен ли я использовать ImageView или экземпляр View, или как), а затемвизуализировать полученное изображение как просматриваемый вид.Также не уверены в строке кода перед Picasso.get ()

Вот мой код.

public class AugmentedImageNode extends AnchorNode {

  private static final String TAG = "AugmentedImageNode";

    // The augmented image represented by this node.
  private AugmentedImage image;

  // Models of the 4 corners.  We use completable futures here to simplify
  // the error handling and asynchronous loading.  The loading is started with the
  // first construction of an instance, and then used when the image is set.
  private static CompletableFuture<Void> rendobject;

  private ViewRenderable testViewRenderable;

    //ImageView imgView;

  public AugmentedImageNode(Context context) {
    // Upon construction, start loading the models for the corners of the frame.
      if (rendobject == null) {

          ImageView imgView = imgView.inflate(context, R.layout.imgboard, null);
                Picasso.get()
                        .load("http://scoopak.com/wp-content/uploads/2013/06/free-hd-natural-wallpapers-download-for-pc.jpg")
                        .into(imgView);


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



                         //testViewRenderable = renderable;
                     });

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

  /**
   * Called when the AugmentedImage is detected and should be rendered. A Sceneform node tree is
   * created based on an Anchor created from the image. The cornerNode is then positioned based on the
   * extent of the image. There is no need to worry about world coordinates since everything is
   * relative to the center of the image, which is the parent node of the corner.
   */
  @SuppressWarnings({"AndroidApiChecker", "FutureReturnValueIgnored"})
  public void setImage(AugmentedImage image) {
    this.image = image;

    // If any of the models are not loaded, then recurse when all are loaded.
    if (!rendobject.isDone())
      {
      CompletableFuture.allOf(rendobject)//, urCorner, llCorner, lrCorner)
          .thenAccept((Void aVoid) -> setImage(image))
          .exceptionally(
              throwable -> {
                Log.e(TAG, "Exception loading", throwable);
                return null;
              });
    }

    // Set the anchor based on the center of the image.
    setAnchor(image.createAnchor(image.getCenterPose()));

    // Make the node(s).
    Vector3 localPosition = new Vector3();
    Node cornerNode;

    //localPosition.set(-0.5f * image.getExtentX(), 0.0f, -0.5f * image.getExtentZ());
    localPosition.set(-0.0f * image.getExtentX(), 0.1f, +0.5f * image.getExtentZ());
    cornerNode = new Node();
    cornerNode.setParent(this);
    cornerNode.setLocalPosition(localPosition);
    cornerNode.setLocalRotation(Quaternion.axisAngle(new Vector3(-1f, 0, 0), 90f));
    //cornerNode.setLocalScale(scaledWidth, scaledHeight, scaledWidth);
    cornerNode.setRenderable(testViewRenderable);
  }
}
...