xamarin / urho

Code to integrate with the Urho3D engine
Other
462 stars 122 forks source link

Load model from resources NOT in asset folder #153

Closed Fax3D closed 8 years ago

Fax3D commented 8 years ago

Hi,

About Urhosharp and Xamarin.Forms, i think it should be possible to load a 3D model (or any other type of resource) from outside the Asset folder, for example from SD Card or from a file stream taken from internet... This could be a very useful features for creating application that dont' rely only on pre-packaged resources, but need to use a more dynamic way to visualize 3D objects.

Thanks.

Fax3D commented 8 years ago

I found a solution (for Android), and i want to share with you:

To load a custom .mdl model from SD card, it's simple:

var javafile = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads;
string localPath = Path.Combine(javafile.AbsolutePath, "Models");

StaticModel _obj = baseNode.CreateComponent<StaticModel>();
_obj.Model = ResourceCache.GetModel(localPath + "/" + mModelToLoad.name + ".mdl");