Reputation: 1
For a school project I have to use ArCore for displaying a .obj that was given to me by a client I am doing the project for. I have tried at first with a random .obj that I have found in a license free website and it works quite well, but whenever I try with the .obj of the client, it tells me that it cannot be loaded and I don't really know what to do.
Here is the error in the logcat :
2020-04-10 21:08:28.745 28542-29004/com.example.artest E/ModelRenderable: Unable to load Renderable registryId='sebastien.sfb'
java.util.concurrent.CompletionException: java.io.FileNotFoundException: sebastien.sfb (No such file or directory)
at com.google.ar.sceneform.utilities.SceneformBufferUtils.inputStreamToByteBuffer(SourceFile:48)
And here is my code :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);
createScene();
}
private void createScene() {
mScene = arFragment.getArSceneView().getScene();
ModelRenderable.builder()
.setSource(this, Uri.parse("sebastien.sfb"))
.build()
.thenAccept(renderable -> onRenderableLoaded(renderable))
.exceptionally(throwable -> {
Log.i("Sceneform", "failed to load model");
return null;
});
}
void onRenderableLoaded(ModelRenderable model) {
Node modelNode = new Node();
modelNode.setRenderable(model);
modelNode.setParent(mScene);
modelNode.setLocalPosition(new Vector3(0, 0, 0));
mScene.addChild(modelNode);
}
Thank you in advance for your help.
Upvotes: 0
Views: 2947
Reputation: 1
The main issue was the size of the file. I followed some instructions given here.
I had other warnings and errors I had to address :
I added a library 'com.google.ar.sceneform:animation:1.15.0'
(but I don't think this one is mandatory)
I added libraries such as :
'com.google.android.gms:play-services-plus:17.0.0'
'com.google.android.gms:play-services-base:17.2.1'
'com.google.android.gms:play-services-location:17.0.0'
I don't know why these ones were requiered, but adding them made the app work...
Upvotes: 0
Reputation: 121
I'm not posting this as an answer but I really do want to see if I can help but do not have enough reputation points yet to add comments. I don't know how much experience you have with ARCore and loading object file. I myself have only taken up Android coding two weeks ago and jumped right into the deep end writing an ARCore app. It was a steep learning curve but very exciting. I've learned a LOT. So, even though I have 25+ years of coding experience, I'm a newbie Kotlin/Android/ARCore coder.
From your question I take it that you have tested your code using the model you downloaded and your code works fine. I am also assuming that both models are in the same folder location and that for both models the sfa- and sfb files were created, correct?
I do see from the log file "sebastien.sfb (No such file or directory)". This could mean that the .sfb file was not created or when you try to import the file, you are referencing the wrong folder. Please check the following:
In your build.gradle (app) file should be the code that defines the object file as an asset, similar to the code below. When compiling our code, this will build the .sfa and .sfb file for you. It is also worthwhile to delete the sebastian.sfa & sebastian.sfb files (if they already exist) to have them recreated.
sceneform.asset('sampledata/sebastien.obj',
// 'Source Asset Path' specified during
// import. This will typically be the
// app/sampledata folder since resources in
// this file is not compiled into your
// application
'default', // 'Material Path' specified during import.
'sampledata/sebastien.sfa', // '.sfa Output Path' specified during import.
'src/main/res/raw/sebastien') // '.sfb Output Path' specified during import.
Typicall when I load the object I use code such as below. Note that I do not make use of Uri.parse but I rather use R.raw.sebastian which directly references the resource folder (res\raw) that the sebastian.sfb file is in.
val sebastianStage = ModelRenderable.builder().setSource(this, R.raw.sebastian).build()
Another couple of questions:
BTW A good source for free 3D models is https://poly.google.com/
Upvotes: 1