Search Unity

Unity Fbx Exporter - Export Meshes, Skinned Meshes, Terrains and Textures

Discussion in 'Assets and Asset Store' started by UnLogick, Oct 2, 2016.

  1. SIT_XR

    SIT_XR

    Joined:
    Jan 8, 2020
    Posts:
    5
    Hello,

    i got a big problem with this asset. I tried many configurations and spent a few hours to get an result, but everytime i exported an fbx at runtime it doesnt work. But with "Window | Fbx Exporter" it works. So i tested a little bit and it seems to be a problem that the gameobject i want to export, is created at runtime. Because, when i take it at runtime and drag it into the assets, so i get a prefab. I can convert the prefab at runtime. But when i try to generate my gameobject (with many child rect gameobjects and textures) its always an 4 kb empty fbx file.
     
  2. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Thanks for the bug report, I will investigate in the weekend.
     
    Zarbuz likes this.
  3. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    That sounds very weird, there is no difference between runtime game objects and edit time game objects. The fact that it works with exactly the same game object made into a prefab is baffling. When you say runtime, do you mean runtime in the editor or a standalone build?

    Also what version of Unity are you using?
     
  4. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    I forgot to say that I will obviously retest with latest version and dynamically created content, however that pretty much describes the UMA character customization which I've tested recently. So if you can provide a repro project that would be very helpful.
     
  5. SIT_XR

    SIT_XR

    Joined:
    Jan 8, 2020
    Posts:
    5
    Hi,
    i cannot upload my project because of security policies. Can i call you and share my screen with you, so i can describe the process. I think this would be the fastest way. Maybe in discord?
     
  6. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    That would work, however with two small kids at home we'll have to book the time slot with some flex built in. What time zone are you in? Usually evening hours like 9-11pm CET would be easiest, but we can try other hours as well.
     
  7. SIT_XR

    SIT_XR

    Joined:
    Jan 8, 2020
    Posts:
    5
    Hi it would be nice to call at 9 pm :)
    my Timezone is CEST, (Berlin)
    I send you an pm with my discord name :)
     
  8. natsims

    natsims

    Joined:
    May 21, 2018
    Posts:
    5
    Dear Mr Unlogick, I'm a big fan of your work and was excited to try out your FBX Exporter. But despite reading the whole description, I completely missed that it is Windows only. (In fact I didn't realize there were any Unity plugins that weren't cross-platform, but that's my fault too.)

    I usually do have a Windows box but it is at my fellow "more senior" :p dev's house while we shelter in place; I have just my Mac. Would you take mercy on me and refund me? And I guess, do you think you'll ever write a version for MacOS? Thank you!
     
  9. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Just pm me your invoice number and I'll get you a refund. I had plans to write a MacOS version, but right now it's far down on the list.
     
  10. draverik

    draverik

    Joined:
    Feb 17, 2019
    Posts:
    19
    Hello,

    I will be waiting for news about texture exporting and scale fix :)

    Thanks!
     
  11. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    I just verified that texture exporting works correctly in 2019.4.
    I also verified that the scene objects are scaled as expected in 2019.4.

    Please send a pm with a repro case, a simple project with the source scene and list of steps to reproduce the problem. Once I have that I'm confident I can figure out what is causing the incorrect scaling you're experiencing.
     
  12. draverik

    draverik

    Joined:
    Feb 17, 2019
    Posts:
    19
    Hello,

    We have problems with texture exporting and now we don't need this asset anymore - can you please make a refund?
     
  13. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Sure, just pm me your invoice number
     
  14. CathyR

    CathyR

    Joined:
    Feb 23, 2015
    Posts:
    4
    Hi,
    just bought this package
    I am getting error
    Copying assembly from 'Temp/Unity.Timeline.Editor.dll' to 'Library/ScriptAssemblies/Unity.Timeline.Editor.dll' failed
    how do I solve this?
    thanks
     
  15. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    That error is completely unrelated to the fbx exporter. There is no script in the fbx exporter that uses Timeline at all. These kinds of Unity errors pops up once in a while at random, usually a restart takes care of it, sometimes you need to delete the temp folder or even the library folder (before you start unity again).
     
  16. chrpetry

    chrpetry

    Joined:
    Mar 7, 2018
    Posts:
    65
    Hello,

    I actually have the same problem (but even when in Play mode in the editor, Unity 2019.3.14f1).

    Code (CSharp):
    1. Fbx Exporter - DLL unable to load!
    2. The Fbx Exporter DLL was located at Packages/<company>/UnLogickFactory/FbxExporter/DLL/UnityFbxExporter_x86_64_v14.dll but failed to load.
    3. UnityEngine.Debug:LogErrorFormat(String, Object[])
    4. UnLogickFactory.FbxExporter:LogErrorFormat(Boolean, String, Object[]) (at D:/GitRepos/UnityRuntimeExporter/UnLogickFactory/FbxExporter/Scripts/FbxExporter.cs:562)
    5. UnLogickFactory.UnityFbxExporterBinding:Init(Int32) (at D:/GitRepos/UnityRuntimeExporter/UnLogickFactory/FbxExporter/Scripts/UnityFbxExporterBinding.cs:99)
    6. UnLogickFactory.FbxExporter:GetDefaultFormat() (at D:/GitRepos/UnityRuntimeExporter/UnLogickFactory/FbxExporter/Scripts/FbxExporter.cs:38)
    7. UnLogickFactory.FbxExporter:Export(String, Transform[]) (at D:/GitRepos/UnityRuntimeExporter/UnLogickFactory/FbxExporter/Scripts/FbxExporter.cs:77)
    I tried installing all redistributable packages. Still no luck.
    Any idea whats going wrong?

    EDIT: Small addition on that: I am wrapping your asset in a separate assembly (asmdef).

    EDIT2: Found a solution! As I work with local packages (UPM) the path loading inside your "LoadLibrary(string path)" does not work correct.
    I simply converted the path to a full path:
    Code (CSharp):
    1. path = Path.GetFullPath(path);
    Now it works!
    Best regards,
    Christian
     
    Last edited: Jul 24, 2020
    UnLogick likes this.
  17. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Hi Christian

    Glad you got it working, getting the dll to reliably load at runtime across unity versions was tricky, but the current setup has proven reliable until now. Thank you for providing the fix I'll make sure to add it for the next release.

    I'd rather not rely on exceptions, please confirm that before the GetFullPath a File.Exists(path) returns false.
     
  18. chrpetry

    chrpetry

    Joined:
    Mar 7, 2018
    Posts:
    65
    Alright! I also wrapped it in a async call.

    I now see that using the FbxTextureExportScheme you provided creates a lot of texture files.
    In my scene there are many meshes having almost always the same materials (non standard unity shaders).
    Can I somehow export only each material + texture once?

    EDIT: It seems although the materials are shared (changing color proves this) the mat.GetInstanceID() always returns a different value which then produces each time a different texture file I suppose.

    Best regards,
    Christian
     
    Last edited: Jul 24, 2020
  19. chrpetry

    chrpetry

    Joined:
    Mar 7, 2018
    Posts:
    65
    By the way, I found out that this does not work correctly:

    Code (CSharp):
    1. protected bool AllocateTextureBasedOnMaterial(Material mat,
    2. string shaderVariableName, ref Texture2D _diffuseTexture, ref int maxResolutionX, ref int maxResolutionY)
    3.         {
    4.             if (mat.HasProperty(shaderVariableName))
    5.             {
    6.                 var texture = mat.GetTexture(shaderVariableName);
    7. ...
    HasProperty() does not check for texture properties.
    https://answers.unity.com/questions/1023485/materialhasproperty-mismatch-with-materialgettextu.html

    I fixed using GetTexturePropertyNames() this like this (using Linq)
    Code (CSharp):
    1.  
    2. protected bool AllocateTextureBasedOnMaterial(Material mat,
    3. string shaderVariableName, ref Texture2D _diffuseTexture, ref int maxResolutionX, ref int maxResolutionY)
    4.         {
    5.             if (mat.GetTexturePropertyNames().Contains(shaderVariableName))
    6.             {
    7.                 var texture = mat.GetTexture(shaderVariableName);
    8.                 if (texture != null)
     
  20. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    I am strongly opposed to the idea that a unity publisher adds Linq code to his packages for any reason. Even if it's in something as resource intensive and rare as an fbx export where the Linq garbage wouldn't matter one bit.

    I do consider this a minor issue, it's looking for property names typically associated with textures so it should be relatively rare.

    Unless I hear a ton of complaining I'll only fix this properly for 2019.3+ with the new API to get the property type.
     
  21. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    I'm actually adding texture tracking to the exporter, so that even if different materials use the same texture it will only be exported once. Changing this requires significant changes throughout the system. The hard part is making sure I don't F*** up some other corner case. Since I don't actually know how people use my exporter I'm reluctant to change the texture naming scheme. (But that is pretty much unavoidable)
     
  22. chrpetry

    chrpetry

    Joined:
    Mar 7, 2018
    Posts:
    65
    I understood now that I should override the FbxTextureExportScheme. With this most of my problems I can cover.
    Just noticed in AllocateTextureBasedOnMaterial() that you always use _diffuseTexture. Is this intended?
    On some textures I get them exported in all black.

    A lot of materials I use don't use any textures (only colors). Had to adjust some things in the TextureExporter to also set the color itself. I also managed to reduce the number to only the textures actually used.
     
  23. myth1991

    myth1991

    Joined:
    Jun 2, 2020
    Posts:
    4
    I would be glad if you answer my question here.

    and

    There is an error when getting prefab from the uma character I created.

    It looks pink when I put the prefab I bought on stage.
    I guess he didn't take his shaders

    and I guess you couldn't find time to answer my message below.
     
  24. chrpetry

    chrpetry

    Joined:
    Mar 7, 2018
    Posts:
    65
    Now I have nearly every problem solved on my side.
    I hope it is okay when I post my solutions here for each of them:

    • SkinnedMeshRenderer scale:
      Inside FbxExporter I had to apply the worldToLocalMatrix (thought I would need it the other way round...) to the vertices.

      Code (CSharp):
      1.  
      2. ...
      3. smr.BakeMesh(bakedMesh);
      4.  
      5. vertices = bakedMesh.vertices;
      6. for (int i = 0; i < vertices.Length; i++)
      7. {
      8.     vertices[i] = smr.worldToLocalMatrix * vertices[i];
      9. }
      10. ...

    • Extract color from texture export process:
      As the export material (_textureExporter.sharedMaterial) copies all attributes from the material the color is also applied but should not be baked into the texture itself. So inside the TextureExporter.cs I saved the color and used white for the export process. Afterwards its applied again for the fbx mesh export + color.

      Code (CSharp):
      1.  
      2. protected void PerformTextureExport(int resolutionX, int resolutionY)
      3. {    
      4. var savedColor = _textureExporter.sharedMaterial.color;
      5.  _textureExporter.sharedMaterial.color = Color.white;  
      6. ...
      7. _textureExporter.sharedMaterial.color = savedColor;
      8. }
      9.  
     
  25. chrpetry

    chrpetry

    Joined:
    Mar 7, 2018
    Posts:
    65
    All in all I want to summarize that this is a really great asset!
    It is really fast, exports everything I need and (with a few adjustments) does exactly what I need!

    Thanks a lot!
     
  26. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    That is awesome! It was a conscious decision to make the sdk dll a lightweight wrapper and leave all the control in the C# scripts. Glad to see that let you hack your way to exactly the solution you needed.

    I have a branch where I'm working on improving the material/texture exporting. In particular to handle the tinting you want. So stuff like no textures and texture reuse between materials. The problem is of course that some users want the tint to be baked and some doesn't, on top some want texture reuse and others doesn't.

    If you have some design ideas on a generic architecture that would be flexible enough to achieve this you're welcome to share.
     
  27. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    I already answered this in the Power Tools support thread. This is the Fbx Exporter support thread. In short you're not using the latest version of the power tools. Please go to the unity asset store and get the latest version. If you already got the power tools 2.10 from the asset store, sometimes the asset store doesn't properly overwrite all files, you may need to remove the power tools entirely and then get it again.
     
  28. Random_Dev78

    Random_Dev78

    Joined:
    Feb 28, 2016
    Posts:
    6
    Hello, I just purchased this plugin and I am using Unity 2019.3. I am currently not sure how to even execute this plugin. I'm new to Unity, could I get some assistance using this, please?

    I just want to add that after importing the plugin under the "Window" menu there is no option for for the plugin at all.
     
    Last edited: Aug 8, 2020
  29. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Are you on a windows system? Does your project compile or are there any error messages in the console?
     
  30. Random_Dev78

    Random_Dev78

    Joined:
    Feb 28, 2016
    Posts:
    6
    So here's the thing so far.
    I've noticed it doesn't stay consistent. I could leave unity and have to re-import the package again.
    Sometimes when I try to import the package it does not allow me to check all the boxes and I can't check the DLLs
    If that happens, it won't work.

    I did however about the 5th try on a new build get it to install and "work".
    However, the one thing I will say is in the textures it turned all the transparency to black producing very useless textures.

    And yes, I'm on Windows 10.
     
  31. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    That sounds very annoying, I haven't experienced anything like that. The one thing I have noticed around native DLLs in general is that unity will never unload them! If you try removing them while unity is running unity will recreate the files behind your back! So in order to remove the fbx exporter dll from your project (after using the export!) you actually have to close unity first, you can then restart unity and remove it normally or you can remove it while unity isn't running. That's actually why I added the version to the dll filename, so that when upgrading the exporter a new dll will be placed in your project even if the old dll was loaded. The reason I bring this up is that if you use version control and switch back and forth between branches with and without the fbx exporter I can imagine bad stuff might happen.

    Other than that I'm completely blank to what is causing your issue. Can you record the issue? Perhaps once I see your use cases I might spot what is going on.

    About black and transparency, I recall having some issues with black transparency outline on blender... is that what you're referring to?
     
  32. Random_Dev78

    Random_Dev78

    Joined:
    Feb 28, 2016
    Posts:
    6
    So as of right now, I have it working. I basically got it working once and have not closed Unity since lol. I've got the same place it works and loads in open so I haven't chanced it breaking again.

    The two problems I'm having:

    1. When I export a texture, for example, a texture of some hanging vines which is mostly transparent. That texture when I export it and try to import it in blender ends up having all the transparent parts of it black so there's actually no transparency at all. Not just the outline, the whole transparency.

    2. I have another map that I'm trying to export that uses linear textures, something I've always struggled with when there are multiple texture files to one mesh. When I try to use the exporter, even if I set the texture color space to Linear, the entire FBX does not export at all. I've actually tried every combination on these textures ranging from different color space, what it's exporting, whole scenes vs. selected objects, etc. If I attempt to export the textures at all I get nothing. Unfortunately in this scene I really need these textures exported too as I don't know how to manually apply these source files.
     
  33. Random_Dev78

    Random_Dev78

    Joined:
    Feb 28, 2016
    Posts:
    6
    Okay, so we had a power outage yesterday and it's done. I have not yet been able to get this thing to load again even on the one I got it to load on the first time. This is what it looks like when I try to even import it.
    Note I cannot check the unchecked boxes period.
    Package Import.PNG

    I do not know if this has something to do with it but I get this warning as well.

    Obsolete API.PNG
     
  34. Random_Dev78

    Random_Dev78

    Joined:
    Feb 28, 2016
    Posts:
    6
    Between the extreme difficulty to use and the lack of being able to use anything I've exported with this I'm having a great deal of trouble reconciling the $100 I paid for this plugin.
    Even the stuff I was able to get to export at all did not export right. Here's a comparison.
    WallModelTexUnity.PNG
    This wall is in Unity.
    Now export it to Blender
    And you get this...
    WallModelTexBlender.PNG
    Here's an entire exported map scene...
    BlackTransparency.PNG

    There's nothing I have been able to do to reconcile this.
    So far I haven't been able to export a single usable scene.
    I have the FBX for the models and the texture files.
    The only use this has at all would be to export a scene.
    But so far it produces nothing I can even work with.
     
  35. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    That looks quite horrible.

    Please send me a small project with the terrain, the fence and a couple of trees so that I can investigate why you're getting so poor results with these assets.
     
  36. Ko8e

    Ko8e

    Joined:
    Jan 10, 2020
    Posts:
    14
    Hi, we are trying to export a mesh along with material and textures into fbx format at runtime in windows standalone build. Would that be possible with this asset??
     
  37. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    yes, all you have to do is select the dll file in the unity project view and specify that it should be part of the windows build and then call FbxExporter.Export(...) at runtime.
     
  38. Ko8e

    Ko8e

    Joined:
    Jan 10, 2020
    Posts:
    14
    Initially, i couldnt export textures at runtime neither in the editor nor in the standalone build. It was working fine with fbx exporter editor window but I need to be able to do it in the build.
    But now, it won't export at all and gives a no dll found error.
     
  39. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Please make sure the correct dll file is configured to be part of the platform build (Win32 or Win64). There are a couple of fallback locations where it will try to find the dll, the easiest to remember is the same folder as the exe file. If that fails please record a small video of you walking through your setup and send it to me for diagnostics.
     
  40. Ko8e

    Ko8e

    Joined:
    Jan 10, 2020
    Posts:
    14
    Ok, i manged to fix the dll error. Now, i am able to export fbx along with textures only in the editor with the default textureScheme. I created a custom textureScheme and used it for standalone build. It gave an error saying i need to keep texture exporter prefab in the resources/.../fbxExporter path. So i moved the prefab to the said location. Now, it only exports the textures and not the mesh and gives an error "ArgumentNullException: Value cannot be null. Parameter name: shader".
     
  41. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    That's very specific with you making custom changes like that, I'll need a repro case to see exactly what goes wrong here.
     
  42. Ko8e

    Ko8e

    Joined:
    Jan 10, 2020
    Posts:
    14
    i had to make that change in order for the texture to export. Otherwise, the textures won't export at all.
     
  43. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    I have never experienced this problem. The only real problem I'm aware of with the material exporting is actually when there is materials without textures. Please send me a repro project so that I can get this working properly.
     
  44. Ko8e

    Ko8e

    Joined:
    Jan 10, 2020
    Posts:
    14
    Ok. Let me create a seperate demo project. I'll send it to you in a while.
     
  45. Ko8e

    Ko8e

    Joined:
    Jan 10, 2020
    Posts:
    14
  46. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Nice and clean repro! That made it super easy to fix.

    The bug is quite severe and I'll be uploading a new version within the week. Essentially it merges materials with the same name.

    Hotfix
    TextureExporter.cs, Line 144:
    Code (CSharp):
    1. result.name = string.Format("{0}_{1}", mat.name, mat.GetInstanceID());
    I actually think this bug interfered with my previous work to support materials without textures. So with a little luck this is a two for one.
     
    Ko8e likes this.
  47. Ko8e

    Ko8e

    Joined:
    Jan 10, 2020
    Posts:
    14
    I am also having the 2nd issue. Need help with this.
     
    argel1200 likes this.
  48. argel1200

    argel1200

    Joined:
    Aug 28, 2020
    Posts:
    4
    I'm running into the "only sometimes shows up in the menu" problem. I've seen it a couple times. Last time was after importing 3D SciFi Kit Vol 1, which had some additional package manager dependencies.

    It looks like there's a compatibility issue with "Package Manager UI". As soon as I used the Package Manager to Remove it, the menu item came back. Edit1: That was with 2.0.7.

    Edit2: Dang, have another project that removing the above did not work. But I had a lot of other stuff in it too, so I'll try with a new project.
     
    Last edited: Sep 3, 2020
  49. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Followed your steps from PM and got repro on 2nd issue.

    Seems like there is some features that hasn't aged well.
    • FbxCustomPropertyExporterExample doesn't setup a proper TextureExportScheme
    • The dll path lookup needs updating
    • There is a dependency on having the Standard Specular shader in your build.
    This requires changes in multiple places so no hotfix this time, but a new release is imminent.
     
    argel1200 likes this.
  50. Ko8e

    Ko8e

    Joined:
    Jan 10, 2020
    Posts:
    14
    May I know when is the earliest we can expect an update?