Search Unity

Question Possible to export OBJ or FBX from Skinned Mesh Renderer during runtime on mobile devices?

Discussion in 'Scripting' started by BrooklynDiPi, May 25, 2023.

  1. BrooklynDiPi

    BrooklynDiPi

    Joined:
    Sep 30, 2019
    Posts:
    4
    Hello!

    Reaching out to see if I am asking for the impossible. I am currently working on a project that would benefit from allowing the user to export a selected model that is rendered in game to an OBJ (+MTL and textures) or FBX file during built runtime on a mobile device. This would likely live in the applications persistantDataPath and also be routed to a backend web service for storage.

    This seems to be an unlikely request so I am seeing lots of mixed information about it. I've noticed a lot of options that can easily write the vertex data to an OBJ but including textures with our model is critical and these do not include that. I've run a few scripting tests to inconclusive results leading me to believe its going to be harder than it looks.

    Are there any limitations here that I am missing? I saw instances of marking assets as read/write being important. I am also open to plugins or libraries that I could work from. I'm a little stumped, so any help or input in appreciated. :)
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    You would need to fully export it all, mesh and textures, if you want it to look the same.

    You'd probably want to zip it all up in order to keep things tidy.

    When you are allowing people to upload images (!!!), you would probably want some kind of basic strong global authentication (such as Google sign-in) in order to keep people from uploading nasty things to your site that you can get in a lot of trouble for.

    You would be FAR better requiring the person to have an account with a popular fileshare such as imgur.com and then partner with them to use their back end for image storage. That stuff adds up in space fast and will cost you a fortune to store.

    So yeah, not a two hour task.
     
  3. BrooklynDiPi

    BrooklynDiPi

    Joined:
    Sep 30, 2019
    Posts:
    4
    Hi Kurt,

    Thank you for the advice. :)

    Thankfully, all of these things have already been accounted for. I still am lookin for help to figure out runtime model and texture export.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    I wouldn't touch FBX, I'd just use OBJ and MTL... there's plenty of example exporters and the result is just text, so you can get that up to your webserver however you like.

    You can look up how to encode a Texture2D to PNG or JPG and stream that up as well.

    Beyond that it is just basic engineering work, plenty of examples and tutorials out there.

    https://github.com/dsapandora/UnityObjExporter