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

Convert mutliple .obj to .sfa and .sfb #217

Closed
ManuelTS opened this issue Jul 27, 2018 · 24 comments
Closed

Convert mutliple .obj to .sfa and .sfb #217

ManuelTS opened this issue Jul 27, 2018 · 24 comments
Labels
feature request New feature or request

Comments

@ManuelTS
Copy link

ManuelTS commented Jul 27, 2018

With the import wizard in Android Studio which imports one Sceneform asset, allow to select a directory full of .obj files and to convert all of them as a batch to .sfa and .sfb files.

I have circa 3.000 .obj files, how can I convert them automatically to .sfa and .sfb files?

@gdamoreira
Copy link

Hi, I had a similar problem and found a solution using the sceneform convert binary direct from command line. I created a shell script to do the conversion.

I also created a repo with the convert binaries too. Try using: https://github.com/necrostylery/google-ar-asset-converter

@ManuelTS
Copy link
Author

Thanks for the link and your hint. I did the same and it works perfectly. But where did you find the converter program as well as matc? The SDK downloads of ARCore lack those two:
https://developers.google.com/ar/develop/downloads

@gdamoreira
Copy link

I extracted them from the sceneform gradle plugin jar file.

@ManuelTS
Copy link
Author

ManuelTS commented Jul 31, 2018

Great deed. But you don't get in Android Studio the message "File was loaded in the wrong encoding..." no matter if you reload it with UTF-8, -16, ISO-8859-1, or US-ASCII? The converter and matc files do not provide any enconding opentions if you call them with the "-h" parameter.

@gdamoreira
Copy link

Hi @ManuelTS,
about this wrong encoding, I've never seen something similar with my assets. This error is reproduced with sceneform gradle plugin?

Maybe you should open a different issue for this problem.

@ManuelTS
Copy link
Author

ManuelTS commented Aug 1, 2018

Done in issue #226.

@ManuelTS
Copy link
Author

ManuelTS commented Aug 1, 2018

A manual import works now, but an self made automatic one via shell script not. The Sceneform plugin got updated to 1.4.0
https://plugins.jetbrains.com/plugin/10698-google-sceneform-tools-beta-
I am unable to extract the converter and matc from the .jar files. Not a single .jar in there is close the size of 25 MB, how and from which .jar did you do the extraction? Another approach is you extract them and update your repo, maybe then I can make it work. I was so bold to make an issue in your repo:
gdamoreira/google-ar-asset-converter#6

@gdamoreira
Copy link

Hi @ManuelTS ! I updated the repo binaries, please try again!

@ManuelTS
Copy link
Author

ManuelTS commented Aug 10, 2018

Hi @necrostylery, sorry I got caught up in implementing other features of my app and now I'm back to generating multiple .sfb files, the error persists, I made a script to process all the ~3000 files. Since your update of binaries I redid the first two files of my database by hand, here the single commands:

cd appRootDir/base/sampledata

wget https://github.com/necrostylery/google-ar-asset-converter/raw/master/sceneform_sdk/linux/converter
wget https://github.com/necrostylery/google-ar-asset-converter/raw/master/sceneform_sdk/linux/matc
wget https://raw.githubusercontent.com/necrostylery/google-ar-asset-converter/master/sceneform_sdk/default_materials/obj_material.sfm

sudo chmod 777 converter
sudo chmod 777 matc
sudo chmod 777 obj_material.sfm

cp xxxxxx/database/*.obj ./
<fj1252.obj, fj1253.obj, converter, matc, and obj_material.sfm are now in appRootDir/base/sampledata>

./converter -a -d --mat obj_material.sfm --outdir models/ fj1252.obj
./converter -a -d --mat obj_material.sfm --outdir models/ fj1253.obj
<fj1252.sfb and fj1253.sfb along with their .sfa files are now in appRootDir/base/sampledata/models>

But both generated .sfb files give me the aforementioned error.

I'm startled, what am I doing wrong?

/Edit: Maybe it is worth to mention that I have a instant app folder structure but I'm not running the instant app nor do I use any of its features. This causes the appRootDir/base/sampledata path instead of appRootDir/app/sampledata

@gdamoreira
Copy link

Hi @ManuelTS,
could you send me some of the assets? I will try to identify your problem.

@ManuelTS
Copy link
Author

Thank you for your support @necrostylery ! Of course I can:
Frist2Files.zip

@gdamoreira
Copy link

Hi @ManuelTS, I tried run this command:

cd ~/
mkdir github
cd github
git clone https://github.com/necrostylery/google-ar-asset-converter.git
cd google-ar-asset-converter
cp ~/Downloads/Frist2Files/FJ1252.obj ./input
cp ~/Downloads/Frist2Files/FJ1253.obj ./input
./sceneform_sdk/mac/converter -a -d --mat ./sceneform_sdk/default_materials/obj_material.sfm --outdir ./output/ ./input/FJ1252.obj
./sceneform_sdk/mac/converter -a -d --mat ./sceneform_sdk/default_materials/obj_material.sfm --outdir ./output/ ./input/FJ1253.obj

That's the output messages:

Warning: Imported asset was very large (69.5 x 53.9 x 18.4 m)
         Setting scale to: 0.0544069 to compensate
Info: Generated SFA from ./input/FJ1252.obj
Info: Wrote SFA (json) to ./output/FJ1252.sfa (957 bytes)
Info: Wrote SFB to ./output/FJ1252.sfb (121416 bytes)

Warning: Imported asset was very large (75.3 x 53.5 x 36.0 m)
         Setting scale to: 0.0277778 to compensate
Info: Generated SFA from ./input/FJ1253.obj
Info: Wrote SFA (json) to ./output/FJ1253.sfa (957 bytes)
Info: Wrote SFB to ./output/FJ1253.sfb (119432 bytes)

and the output folder:

total 1160
drwxr-xr-x  8 guilherme  staff     272 Aug 14 09:33 .
drwxr-xr-x  7 guilherme  staff     238 Aug  3 10:45 ..
-rw-r--r--  1 guilherme  staff     957 Aug 14 09:33 FJ1252.sfa
-rw-r--r--  1 guilherme  staff  121416 Aug 14 09:33 FJ1252.sfb
-rw-r--r--  1 guilherme  staff     957 Aug 14 09:33 FJ1253.sfa
-rw-r--r--  1 guilherme  staff  119432 Aug 14 09:33 FJ1253.sfb

It worked normally for me, maybe is some problem with your OS system?? Have you tried with another computer?

Sorry if I couldn't help more.

@ManuelTS
Copy link
Author

ManuelTS commented Aug 14, 2018

I did the same with he same result, only difference is I used the converters from linux or from windows with executed with wine, respectively. All generated .sfb files show in Android Studio "File was loaded in the wrong encoding...". :( Can you, @necrostylery, please upload your generated files so I can open them with my Android Studio?

For now only with my computer but I will try it with other ones and other OSs. You helped me a lot already, thank you very much for that 😄

@gdamoreira
Copy link

Hmm. @ManuelTS now I see your problem. In fact the error occurred here as well. Maybe is a bug? Have you tried import this .obj file in some 3d designer software and re-exported the .obj file?

Maybe have something inside that has an invalid character.

These are the files I converted.
files_zipped.zip

@ManuelTS
Copy link
Author

@necrostylery propably a bug, no I have no since I cannot export circa 3000 files. As far as I know no special characters are in there. However, I will do exactly this for the two files attached here and I will report back.

My full explanation and conclusion for the Sceneform developer team:

I use objects from download # 9 from the BodyParts3D database. When I create a single sfa and .sfb out of an .obj file with the android studio importer wizard the file works, see #226. But creating one or multiple files via command line lets Android Studio, or rather its Sceneform plugin, say "File was loaded in the wrong encoding...". This applies to files created on Ubuntu 18.04, Windows 10, and Mac. Here the same single generated .sfa and .sfb files from .obj files from the Body Parts 3D database:

  • Ubuntu.zip
  • Windows10.zip
  • Mac.zip
    And the object files too
  • Objs.zip
    I think since it is a scientific DB the .obj files should be okay, but nobody can really know for sure. After a reexport via a designer software and regeneration of .sfa and .sfb files I will report back.

@gstanlo
Copy link

gstanlo commented Aug 16, 2018

Ah, I think this is a bug that happens when your sfb doesn't correspond to a sfa that gradle recognizes. The viewer won't display it properly, but it should still render correctly if you include it in an app.

@ManuelTS
Copy link
Author

This story has gone a long way and to be honest I don't care anymore, it takes too long and too much time, look at all the workarounds and tries before, I'm frustrated I cannot view the models in Android Studio. I know that the models render nonetheless in ARCore.

Why the sceneform guys did not included a simple multiple file-to-.sfa-.sfb conversion is beyond me, new File().listFiles() should no be too hard to use, especially if you are a developer from Google.

@necrostylery, using a graphical design program for regernating the .obj files results in the following:

The two files imported into blender and exported create also FJxxxx.mtl files. Trying use the materials in the conversion results in

Info: Generated SFA from ./Databases/BodyParts3D/isa_BP3D_4/FJ1252_blender.obj
ERROR: Jsonnet Error: [1]: STATIC ERROR: FJ1252_blender.mtl:1:107: Unexpected: ";" while parsing terminal

Using the original, standard material works, here the generated files with blender. Error is the same as before:
Blender.zip

@malik-at-work malik-at-work added the feature request New feature or request label Oct 10, 2018
@malik-at-work
Copy link

Closing this as will not fix for now.

@ManuelTS
Copy link
Author

A issue as feature request which is closed? Shouldn't you have written "will never fix"?

@marcspraragen
Copy link

marcspraragen commented Jul 15, 2019

Hi-- I am trying to get the sfb/sfa coverter running as a batch/command line for fbx files. Each fbx is self-contained with 3 built-in animations and png-based texture.

Here is my problem. The Android Studio wizard does this import perfectly. Animations and all.
My manual try with the command line, not so much:
converter -a .\ww.fbx
I'm sure I'm missing about 30 flags but have no idea where to start with the file I'm trying to convert.

I've attached the two generated .sfa JSON files (with .txt extension so they'd upload) for reference, along with a screenshot of the android studio wizard parameters.

Any and all help greatly appreciated!

ww-wizard
ww-command-line.sfa.txt
ww-android-studio-wizard.sfa.txt

@ManuelTS
Copy link
Author

In this topic on comment you have a bash script to give you an idea to convert multiple files. Also check out the dedicated repo google-ar-asset-converter of @gdamoreira. There you see how you get a short description explaining the single command line arguments of the converter.

@zabdielcead
Copy link

zabdielcead commented Sep 11, 2019

I have a solution
update android studio to the last version 3.5

download plugin Google sceneform tools (beta) v.11.1

update dependencies
implementation 'com.google.ar:core:1.11.0'
implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.11.0'
implementation 'com.google.ar.sceneform:core:1.11.0'

and again create the step import scneform from assets

actually that works for me, on running app!!!!!!! :)

@manojghorela69
Copy link

manojghorela69 commented Oct 3, 2019

I am downloading obj and mtl file using url in my Android app. Can anyone help how can I use sceneform plugin to convert them to sfb. @gdamoreira I have seen your converter but it is specifically for Windows and Linux. How can I write a script for my Android App?
@zabdielcead can you help?

@bobekos
Copy link

bobekos commented Oct 3, 2019

You canno't. Actually you can do only two things. First one is to convert you models into sfb and download them or the second one you can download your models as gltf files and then you can convert them at runtime in your app.

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

No branches or pull requests

8 participants