我有一个Android设备,可以与ARCore一起使用,并且想从SD卡中加载Gltf或Glb文件。在网站https://developers.google.com/ar/develop/java/sceneform/create-renderables上,仅显示通过Internet加载。
我读到parse.fromFile
可以帮上忙,但这对我来说还行不通。
private static final String GLTF_ASSET =
"https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/Duck/glTF/Duck.gltf";
/* When you build a Renderable, Sceneform loads model and related resources
* in the background while returning a CompletableFuture.
* Call thenAccept(), handle(), or check isDone() before calling get().
*/
ModelRenderable.builder()
.setSource(this, RenderableSource.builder().setSource(
this,
Uri.parse(GLTF_ASSET),
RenderableSource.SourceType.GLTF2)
.setScale(0.5f) // Scale the original model to 50%.
.setRecenterMode(RenderableSource.RecenterMode.ROOT)
.build())
.setRegistryId(GLTF_ASSET)
.build()
.thenAccept(renderable -> duckRenderable = renderable)
.exceptionally(
throwable -> {
Toast toast =
Toast.makeText(this, "Unable to load renderable " +
GLTF_ASSET, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return null;
});
答案 0 :(得分:0)
是的,可以,但是您需要将.gltf和.bin下载到外部存储中的某个位置,然后在为场景中的节点设置可渲染性时从那里调用.gltf。
答案 1 :(得分:0)
是的,可以。我尝试使用gltf
,它工作正常。我已将文件下载到文件目录,并将文件路径指定为源URL。
val fileName = "myfile.gltf"
val filePath = "${filesDir.path}/${fileName}"
ModelRenderable.builder()
.setSource(this, RenderableSource.builder().setSource(
this,
Uri.parse(filePath),
RenderableSource.SourceType.GLTF2).build())
.setRegistryId(filePath)
.build()
.thenAccept {
renderable = it
}
.exceptionally {
// Error happened
return@exceptionally null
}
注意:如果您有bin
文件,请也下载该文件。