Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

Is there a way to load models from server #35

Closed
RavindraVirat opened this issue May 21, 2018 · 7 comments
Closed

Is there a way to load models from server #35

RavindraVirat opened this issue May 21, 2018 · 7 comments
Labels

Comments

@RavindraVirat
Copy link

In Sceneform sample app we are loading models from model folder, in case I have more then 20 models assume for any shopping app then if I put all those models in asset folder, apk size will increase, so my question is can we load models means 'model related files like obj, mtl, png, sfa, sfb' from server and save to local then go for rendering.

@dsternfeld7
Copy link

The generated sfb file contains all of the data for the model, so if you copy just the sfb file to a web server, you can then load the renderable via a url:

ModelRenderable.builder().setSource(this, Uri.parse("https://www.foo.com/bar.sfb")).build();

The download will automatically happen on a background thread.

Alternatively, you could write your own mechanism for downloading the .sfb files (zipped together or otherwise) and load them using a file:// URI or from an InputStream.

@RavindraVirat
Copy link
Author

Thank you for reply.

In sceneform sample app I observed that the model is already configured in gradle file as below -
sceneform.asset('sampledata/models/andy.obj',
'default',
'sampledata/models/andy.sfa',
'src/main/res/raw/Andy')

, in this case model is already available, so if I download the new model from server then how will I mention my newly downloaded file in gradle.

@dsternfeld7
Copy link

You can use a gradle project (it doesn't need to be the same project as your application) to convert the raw assets (obj + mtl) into an sfb in advance and then store just the sfbs on your web server.

The sfbs you download from the web server do not need to be mentioned in your build.gradle. res/raw can only contain resources that are packaged with the apk.

When downloading an sfb, you can load the Renderable using a URL directly, save them in device storage and access them using a "file://" URI, or load them from an inputstream directly.

@ldima
Copy link

ldima commented Jun 2, 2018

@dsternfeld7 I have got

Unable to load Renderable Unable to load Renderable registryId='file:///storage/emulated/0/Download/lion3.sfb'
java.util.concurrent.CompletionException: java.io.FileNotFoundException: /storage/emulated/0/Download/lion3.sfb

File is exist.
What does it mean?

@RavindraVirat
Copy link
Author

If you pass Uri of the .sfb file to setSource() method , it is not working, giving
IllegalArgumentException: Unable to parse url,
MalformedURLException: unknown protocol: content.

I tried like this and its able to render -
setSource(this, new Callable() {
@OverRide
public InputStream call() throws Exception {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(getFilePath());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return fileInputStream;
}
})

getFilePath() method will return path of the .sfb file.

@ishaang10
Copy link

How to load a model from a file input stream ????

I downloaded the file from server using the download manager and its path is Content://downloads/all_download/190.
so if i can somehow get it in a filestream . then how can i load that model.

its the .sfb file.

@artemtkachenko
Copy link

@ishaang10
seems like this is what you are looking for

ModelRenderable.builder()
            .setSource(context, Callable<InputStream> {
                return@Callable FileInputStream(%downloaded_file_absolute_path_string%)
            })
            .build()

Nevertheless I am not sure that a content:// uri can be a source for downloaded_file_absolute_path_string. I suggest using a file:// uri instead. It works for sure.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants