簡體   English   中英

如何從Node.java文件訪問增強圖像的getIndex

[英]How do I access Augmented Image's getIndex from the Node.java file

我在imgdb文件中添加了一些不同的圖像,這些圖像已被arcore場景完美檢測到。 但是,我想為imgdb文件中的每個圖像顯示一個不同的3D對象。 我相信使用getIndex函數可以做到這一點,但是由於我是菜鳥,所以我不知道如何使用它。

在下面的代碼中,如何將當前檢測到的圖像的索引分配給變量“值”?

public class AugmentedImageNode extends AnchorNode {

  private static final String TAG = "AugmentedImageNode";

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

 private static CompletableFuture<ModelRenderable> ulCorner;


   public AugmentedImageNode(Context context) {

          if (value == 0) {
              // Upon construction, start loading the models for the corners of the frame.
              if (ulCorner == null) {
                  ulCorner =
                          ModelRenderable.builder()
                                  .setSource(context, Uri.parse("models/tinker.sfb"))
                                  //.setSource(context, Uri.parse("models/borderfence-small2.sfb"))
                                  .build();
                   }
          }

          if (value == 1) {
              // Upon construction, start loading the models for the corners of the frame.
              if (ulCorner == null) {
                  ulCorner =
                          ModelRenderable.builder()
                                  .setSource(context, Uri.parse("models/borderfence-small.sfb"))
                                  //.setSource(context, Uri.parse("models/borderfence-small2.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 corners are then positioned based on the
   * extents 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 corners.
   */
  @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 (!ulCorner.isDone())// || !urCorner.isDone() || !llCorner.isDone() || !lrCorner.isDone())
      {
      CompletableFuture.allOf(ulCorner)//, 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 4 corner nodes.
    Vector3 localPosition = new Vector3();
    Node cornerNode;

    // Upper left corner.
    //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.setRenderable(ulCorner.getNow(null));

  }

    private void setLocalRotation() {
    }

    public AugmentedImage getImage() {
    return image;
  }
}

您可以使用AugmentedImage可用的getIndex()函數。

public int getIndex()

從其原始圖像數據庫返回此增強圖像的從零開始的位置索引。

該索引用作數據庫中圖像的唯一標識符。

要進一步閱讀,請參考官方文檔Sceneform AugmentedImage Sample

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM