所以,我的问题分为两个级别:
如何确定增强图像的确切宽度和高度,这是我在AR中显示3D模型的标记?我正在通过getExtenzZ和getExtentX获取这些数据,我不知道这是否是执行此操作的正确方法。
如何正确缩放ViewRenderable节点,使其具有图像的宽度和高度?就我而言,所显示的模型总是大于应有的模型,因此我认为在缩放过程中一定会遗漏某些东西...
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();
});
}
我认为问题出在相机上,并且事实是它无法正确计算增强图像的确切w和h,但也许有人可以给我任何提示吗?到现在为止还没有达到效果:
答案 0 :(得分:0)