我正在使用Sceneform创建一个AR应用程序,无论到目前为止我做了什么尝试,Sceneform都无法在图像上正确显示视频。这是相机检测到图像时得到的结果: The Video Image that I get
这是我在相应课程上的代码:
texture = new ExternalTexture();
mediaPlayer = MediaPlayer.create(this, R.raw.video);
mediaPlayer.setSurface(texture.getSurface());
mediaPlayer.setLooping(true);
ModelRenderable
.builder()
.setSource(this, Uri.parse("video_screen.sfb"))
.build()
.thenAccept(modelRenderable -> {
renderable = modelRenderable;
modelRenderable.getMaterial().setExternalTexture("videoTexture",
texture);
modelRenderable.getMaterial().setFloat4("keyColor",
new Color(0.01843f, 1f, 0.098f));
})
.exceptionally(
throwable -> {
Toast toast = Toast.makeText(this, "Unable to load video renderable", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return null;
});
arFragment = (com.stratos.syrostownhall.CustomArFragment)getSupportFragmentManager().findFragmentById(R.id.arFragment);
if (arFragment != null) {
scene = arFragment.getArSceneView().getScene();
}
scene.addOnUpdateListener(this::onUpdate);
}
private void onUpdate(FrameTime frameTime) {
if (isImageDetected)
return;
Frame frame = arFragment.getArSceneView().getArFrame();
Collection<AugmentedImage> augmentedImages =
frame != null ? frame.getUpdatedTrackables(AugmentedImage.class) : null;
for (AugmentedImage painting : Objects.requireNonNull(augmentedImages)) {
if (painting.getTrackingState() == TrackingState.TRACKING) {
if (painting.getName().equals("painting")) {
isImageDetected = true;
playVideo(painting.createAnchor(painting.getCenterPose()), painting.getExtentX(),
painting.getExtentZ());
break;
}
}
}
}
private void playVideo(Anchor anchor, float extentX, float extentZ) {
mediaPlayer.start();
AnchorNode anchorNode = new AnchorNode(anchor);
texture.getSurfaceTexture().setOnFrameAvailableListener(surfaceTexture -> {
anchorNode.setRenderable(renderable);
texture.getSurfaceTexture().setOnFrameAvailableListener(null);
});
anchorNode.setWorldScale(new Vector3(extentX, 1f, extentZ));
scene.addChild(anchorNode);
}
此外,我使用以下语法手动添加资产:
sceneform.asset ('sampledata/video_screen.obj',
'default',
'sampledata/video_screen.sfa',
'src/main/assets/video_screen')
答案 0 :(得分:0)
问题是由video_screen.sfb
文件引起的。
如果其他人也遇到相同的问题,请尝试使用以下video_screen文件: