Reputation: 35
So, my question is kind of divided to two levels:
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.
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:
Upvotes: 0
Views: 421
Reputation: 5769
Upvotes: 1