'how to load sfb model from url in sceneform?
I m not able to load .sfb
model from URI.parse("url")
in sceneform.
My code is
ModelRenderable.builder()
.setSource(this, Uri.parse(string))
//.setSource(this,R.raw.andy)
.build()
.thenAccept(renderable -> andyRenderable = renderable)
/* .thenAcceptBoth(futureTexture, (renderable, texture) -> {
andyRenderable = renderable;
andyRenderable.getMaterial().setTexture("None", texture);
})*/
.exceptionally(
throwable -> {
Toast toast =
Toast.makeText(this, "Unable to load andy renderable", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return null;
});
I know there is something wrong with sceneform in gradle. I used to load from Url back then. But I lost the setting or code..
Solution 1:[1]
@rikesh shrestha
Here you cannot use URL directly in Uri.pare() as setSource(Context context, Uri uri) where Uri is the only path of a file only. So, you cannot use the URL directly. For more information refere
For that, you can do one thing. Download .sfb model file from URL and store it on some path. Then use this file path as Uri which helps you to achieve your goal.
I hope that you will resolve your issue.
Solution 2:[2]
If you want to use the file that is downloaded from server it's better to use .glb files, as using .sfb files with Sceneform requires including information about them in gradle. Just download file from server and use it's path as the source. That worked for me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hemal Patel |
Solution 2 | CottaLotties |