1
\$\begingroup\$

I want to include a feature in my game that allows me to host raw 3d models (.fbx/ .obj/ etc., not AssetBundles) on a server. The game should download these files, save them to the device and load them into a scene.
I want to support multiple file formats, so writing my own parser is not an option!

First idea:
Use the WWW class to load the model data, save it as a String in the player prefs, and load it if requested.
(the last part is the problem)

Second idea:
Use the WWW class to load the model data, extract the jar file containing StreamingAssets folder to the sdcard. Writing the model data into a new file in this directory. Creating a new ZIP..ah...JAR archive from the folder and replacing the old .jar file.
Of course I would need an Android Plugin and a archive java library for that. Then the Models will be loaded from the Ressources.
(this is a pretty weird idea and cannot be the right way)

Do you know, if that works?
Has anybody ever done something like that?


UPDATE 1:

I tried to use the obj loader from samed-tarık-Çetİn's comment, but I got this error:

ArgumentNullException: Argument cannot be null.
Parameter name: key
System.Collections.Generic.Dictionary`2[System.String,UnityEngine.Material].get_Item (System.String key) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:136)
GeometryBuffer.PopulateMeshes (UnityEngine.GameObject[] gs,     System.Collections.Generic.Dictionary`2 mats) (at Assets/OBJ/src/GeometryBuffer.cs:145)
OBJ.Build () (at Assets/OBJ/src/OBJ.cs:236)
OBJ+<Load>c__Iterator0.MoveNext () (at Assets/OBJ/src/OBJ.cs:63)

Replacing line 145 in GeometryBuffer.css with
gs[i].GetComponent<Renderer>().material = new Material(Shader.Find("Standard")); did resolve the runtime error and a Material, OBJ (Mesh Filter) and Mesh Renderer Component have been added, but it still show a model.


UPDATE 2: I am behind a proxy so loading the model from the web didn't work. Loading .obj files from file:///<path to obj> works perfectly fine though.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.