tr0lczyk
tr0lczyk

Reputation: 35

How to use method setLocaleScale properly? I'm having issues with determine the size of my AR model

So, my question is kind of divided to two levels:

  1. How to determine the exact width and height of the augmented image that is my marker for displaying the 3D models in AR? I'm getting this data through getExtenzZ and getExtentX, I don't know if this is the proper way to do this.

  2. How to scale the ViewRenderable node properly so it has the width and height of the image? In my case the model on display is always bigger than it should, so I think there must be something during the scalling process that I miss...

    private void onUpdateFrame(FrameTime frameTime) {
        Frame frame = arFragment.getArSceneView().getArFrame();
       Collection<AugmentedImage> augmentedImages = frame.getUpdatedTrackables(AugmentedImage.class);
    for (AugmentedImage augmentedImage : augmentedImages) {
        if (augmentedImage.getTrackingState() == TrackingState.TRACKING) {
            if (augmentedImage.getName().equals("painting") && shouldAddModel) {
                width = augmentedImage.getExtentX();
                height = augmentedImage.getExtentZ();
                placeImageView(arFragment,augmentedImage.createAnchor(augmentedImage.getCenterPose()));
                shouldAddModel = false;
            }
        }
    }
    

    }

    private void placeImageView(ArFragment arFragment, Anchor anchor){
    CompletableFuture<Void> renderableFuture =
            ViewRenderable.builder()
                    .setView(arFragment.getContext(),R.layout.painting_module)
                    .setVerticalAlignment(ViewRenderable.VerticalAlignment.CENTER)
                    .build()
                    .thenAccept(renderable -> {
                        ImageView imageView = (ImageView) renderable.getView();
                        AnchorNode anchorNode = new AnchorNode(anchor);
                        anchorNode.setParent(arFragment.getArSceneView().getScene());
                        TransformableNode transNode = new TransformableNode(arFragment.getTransformationSystem());
                        transNode.setRenderable(renderable);
                        transNode.getScaleController().setMinScale(0.01f);
                        transNode.getScaleController().setMaxScale(2.0f);
                        transNode.setLocalScale(new Vector3(width,0,height));
                        transNode.setLocalPosition(new Vector3(0,0.00f,0));
                        transNode.setLocalRotation(Quaternion.axisAngle(new Vector3(1,0,0),-90));
                        transNode.setParent(anchorNode);
                        transNode.select();
                    });
    

    }

In my opinion the problem is on the camera and the fact that it's miscalculating the exact w and h of the augmented image, but maybe someone can give me any hint? below the effect till now:

enter image description here

Upvotes: 0

Views: 421

Answers (1)

pezcode
pezcode

Reputation: 5769

  1. Should be correct. But I'm not sure how accurate the values are.
  2. ViewRenderable size is determined using a ViewSizer. The default ViewSizer is a DpToMetersViewSizer which renders each 250DP as 1 meter. Try using one of the fixed width sizers instead (e.g. FixedHeightViewSizer) and leave the local scale untouched.

Upvotes: 1

Related Questions