之前的图像视图在创建新的图像视图后被覆盖 | ARCORE

huangapple 未分类评论45阅读模式
英文:

previous image view gets overwritten by new image view after making it | ARCORE

问题

以下是翻译好的内容:

我在处理我的AR物体弹出视图时遇到了问题。我可以放置一个AR物体,然后它的视图会显示正确的图像。但是,如果我放置一个新的AR物体,之前的图像将被新的图像覆盖。例如,如果我放置一个笔记本电脑物体,它的图像将是一台笔记本电脑。但是,如果我放置一个新的物体,比如笔记本,笔记本电脑的图像将被新的物体覆盖。

这里是我所说的情况的可视化表示:

之前的图像视图在创建新的图像视图后被覆盖 | ARCORE

我尝试了不同的方法,但结果仍然相同。

这是它们的声明方式:

private String objectName;
private int resID;

这是我放置物体的地方:

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

                    if (plane.getType() != Plane.Type.HORIZONTAL_UPWARD_FACING){
                        return;
                    }
                    Anchor anchor = hitResult.createAnchor();
                    arranchors.addElement(anchor);

                    placeObject(arFragment, arranchors.lastElement(), selectedObject);

                    if(arranchors.size() >1)
                    {
                        spreadapart();
                    }
                }
        );

这是不同物体、物体名称和它们的图像是如何选择的:
(顺便说一下,物体名称也有这个问题)

private void InitializeAssetsMenu(){
        LinearLayout gallery = findViewById(R.id.asset_layout);

        ImageView pencil = new ImageView(this);
        pencil.setImageResource(R.drawable.pencil_thumb);
        pencil.setContentDescription("pencil");
        pencil.setOnClickListener(view -> {selectedObject = Uri.parse("Pencil_01.sfb");objectName= "Pencil"; resID= R.drawable.pencil_thumb;});
        gallery.addView(pencil);

        ImageView eraser = new ImageView(this);
        eraser.setImageResource(R.drawable.eraser_thumb);
        eraser.setContentDescription("eraser");
        eraser.setOnClickListener(view -> {selectedObject = Uri.parse("Eraser_01(1).sfb");objectName="Eraser"; resID= R.drawable.eraser_thumb;});
        gallery.addView(eraser);

        ImageView laptop = new ImageView(this);
        laptop.setImageResource(R.drawable.laptop_thumb);
        laptop.setContentDescription("laptop");
        laptop.setOnClickListener(view -> {selectedObject = Uri.parse("Laptop_01.sfb");objectName="Laptop"; resID= R.drawable.laptop_thumb;});
        gallery.addView(laptop);

        ImageView notebook = new ImageView(this);
        notebook.setImageResource(R.drawable.notebook_thumb);
        notebook.setContentDescription("notebook");

        notebook.setOnClickListener(view -> {selectedObject = Uri.parse("Notebook.sfb");objectName="Notebook"; resID= R.drawable.notebook_thumb;});
        gallery.addView(notebook);
    }

这是我创建图像视图的地方:

private Node createInfoCard(TransformableNode parent){
        Node infoCard = new Node();
        infoCard.setParent(parent);
        infoCard.setEnabled(false);
        infoCard.setRenderable(cardRenderable);
        //TextView textView = (TextView)cardRenderable.getView();
        //textView.setText(this.objectName);
        ImageView imageView1 = (ImageView)cardRenderable.getView();
        imageView1.setImageResource(resID); //这里我们会有一个变量,每个相应的物体都有不同的图像。
        infoCard.setLocalPosition(new Vector3(0.0f, 0.25f, 0.0f));
        parent.setOnTapListener(
                (hitTestResult, motionEvent) -> {
                    infoCard.setEnabled(!infoCard.isEnabled());
                    spreadapart();
                });

        return infoCard;
    }

我确信问题与变量 resID 有关,但我只是不明白它是如何导致覆盖的。

英文:

I am having a problem with my AR object's pop up view. I can place one AR object and then its view shows the correct image. But then, if i were to place a new AR object, the previous images will get overwritten by the new one. So, for example, if i place a laptop object, its image will be a laptop. But then if i place a new object like the notebook, the laptop's image will get overwritten with that new one.

Here is a visual representation of what i am talking about:

之前的图像视图在创建新的图像视图后被覆盖 | ARCORE

I have tried different methods but still same result.

This is how they're declared:

private String objectName;
private int resID;

Here is where I place the object:

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

                    if (plane.getType() != Plane.Type.HORIZONTAL_UPWARD_FACING){
                        return;
                    }
                    Anchor anchor = hitResult.createAnchor();
                    arranchors.addElement(anchor);

                    placeObject(arFragment, arranchors.lastElement(), selectedObject);

                    if(arranchors.size() >1)
                    {
                        spreadapart();
                    }
                }
        );

Here is how the different objects, object names, their images is picked:
(btw, object names also has this problem)

private void InitializeAssetsMenu(){
        LinearLayout gallery = findViewById(R.id.asset_layout);

        ImageView pencil = new ImageView(this);
        pencil.setImageResource(R.drawable.pencil_thumb);
        pencil.setContentDescription("pencil");
        pencil.setOnClickListener(view -> {selectedObject = Uri.parse("Pencil_01.sfb");objectName= "Pencil"; resID= R.drawable.pencil_thumb;});
        gallery.addView(pencil);

        ImageView eraser = new ImageView(this);
        eraser.setImageResource(R.drawable.eraser_thumb);
        eraser.setContentDescription("eraser");
        eraser.setOnClickListener(view -> {selectedObject = Uri.parse("Eraser_01(1).sfb");objectName="Eraser"; resID= R.drawable.eraser_thumb;});
        gallery.addView(eraser);

        ImageView laptop = new ImageView(this);
        laptop.setImageResource(R.drawable.laptop_thumb);
        laptop.setContentDescription("laptop");
        laptop.setOnClickListener(view -> {selectedObject = Uri.parse("Laptop_01.sfb");objectName="Laptop"; resID= R.drawable.laptop_thumb;});
        gallery.addView(laptop);

        ImageView notebook = new ImageView(this);
        notebook.setImageResource(R.drawable.notebook_thumb);
        notebook.setContentDescription("notebook");

        notebook.setOnClickListener(view -> {selectedObject = Uri.parse("Notebook.sfb");objectName="Notebook"; resID= R.drawable.notebook_thumb;});
        gallery.addView(notebook);
    }

And here is where i make the image view:

private Node createInfoCard(TransformableNode parent){
        Node infoCard = new Node();
        infoCard.setParent(parent);
        infoCard.setEnabled(false);
        infoCard.setRenderable(cardRenderable);
        //TextView textView = (TextView)cardRenderable.getView();
        //textView.setText(this.objectName);
        ImageView imageView1 = (ImageView)cardRenderable.getView();
        imageView1.setImageResource(resID); //here we will have a variable that will have different image for each respective object.
        infoCard.setLocalPosition(new Vector3(0.0f, 0.25f, 0.0f));
        parent.setOnTapListener(
                (hitTestResult, motionEvent) -> {
                    infoCard.setEnabled(!infoCard.isEnabled());
                    spreadapart();
                });

        return infoCard;
    }

I'm sure the issue has to do with the variable resID but I just don't understand how it's causing the overwriting.

huangapple
  • 本文由 发表于 2020年4月5日 10:20:09
  • 转载请务必保留本文链接:https://java.coder-hub.com/61037232.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定