Search Unity

Official New FBX Exporter in 2017.2

Discussion in 'Asset Importing & Exporting' started by ans_unity, Oct 12, 2017.

Thread Status:
Not open for further replies.
  1. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi @Osteel,

    It is currently not possible to create the Linked Prefab outside of the Unity project from the UI as it is recommended to store the Linked Prefab in the Assets folder.

    However, what you could do is create a symlink in the Unity project that links to a folder on your internal server. Then you can move the FBX files into this folder to store and edit the files on the internal server while still importing them into the Unity project at a different location.

    Best,
    Viktoria
     
  2. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi @SamAB,

    The FBX exporter plugin is meant to facilitate and simplify the export from 3ds Max to Unity, however it does not replace or modify the 3ds Max exporter. Instead it takes the traditional manual workflow and makes it one-click, setting the correct export settings, export path and object selection for you.

    Since the traditional export is working, it looks like this is an issue with the export settings used by the plugin. If possible, could you please send the 3ds Max file and export settings you are using with the traditional export?

    Best,
    Viktoria
     
  3. ans_unity

    ans_unity

    Unity Technologies

    Joined:
    Oct 12, 2017
    Posts:
    124
    Hi SamAB,

    Sorry about your issue, just to be clear I think you are using the FBX importer (bringing 3ds Max files in Unity) and not the FBX exporter. They are part of the same workflow but are in fact 2 different tools.

    Can you provide more detail on your process? 3ds Max imports are usually working well but maybe the Revit to 3dsMax to Unity is introducing something different?

    Also we are working on a direct Revit to Unity import workflow that should be ready before end of this year:
    https://blogs.unity3d.com/2018/11/13/visualizing-your-bim-data-with-real-time-design/
     
  4. Tony707

    Tony707

    Joined:
    Jun 15, 2015
    Posts:
    38
    Hi,

    The last version (2.0.0) changelog contains:
    * The roundtrip of assets can now be started from Maya from assets that have not been exported from Unity

    Is there a way to do that from 3ds Max ?

    Thank you,
     
  5. ans_unity

    ans_unity

    Unity Technologies

    Joined:
    Oct 12, 2017
    Posts:
    124
    Hi Tony707,
    The roundtrip can work with any DCC that supports FBX. It may not have been very clear, but the changelog was about how you could create a linked prefab from an FBX that already existed, without needing to first export it. This is related to the change we did with nested prefabs.
     
  6. Tony707

    Tony707

    Joined:
    Jun 15, 2015
    Posts:
    38
    Uhm ok,

    Maybe my question wasn' t clear, I know I can create a linked prefab from any fbx in the Unity project no matter where it comes from. I though the change log was about the ability to export from Maya without any prior importation from Unity. It looks like, in 3ds, we first need to import a fbx from Unity in order to generate a selection set and its exportation settings. Is there a way to generate it directly from a fresh max project without any prior importation ?

    Thanks
     
  7. andrewjepsen

    andrewjepsen

    Joined:
    Jan 12, 2016
    Posts:
    3
    I grabbed the 2.0 package as outlined here but I don't see a way to use UnityEditor.Formats.Fbx.Exporter.ModelExporter.ExportObjects with custom ExportModelSettings anymore. It appear that the ExportModelSettings aren't exposed to editor scripts Basically I'm just trying to export a .fbx with world absolute positioning from and editor script. Is this intentional? Is there a way to script an export with custom settings that I'm just not seeing?

    Thanks for your time!
     
    laessnb likes this.
  8. eric_funktroniclabs

    eric_funktroniclabs

    Joined:
    Oct 4, 2018
    Posts:
    19
    This works wonderfully, thank you!
     
    vkovec likes this.
  9. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi Tony,

    Yes you're right, it is possible to export from Maya without first importing the FBX and have the selection set and other meta data generated for you.
    This feature is not yet available in 3ds Max, and there currently isn't a manual way to create all the required meta data.

    Therefore, the simplest workflow is to import an fbx first (the fbx can be empty or contain a starting point). This will
    generate all the meta data for you. You can then edit the selection set contents as well as the export path and filename parameters afterwards.
    The parameters are available on the dummy object that is created on import under the "UnityFbxExportSets" dummy. The dummy object will have the following name format "{filename}_UnityExportSet". Where {filename} is the name of the imported file without the extension.

    upload_2018-11-26_12-1-22.png

    Best,
    Viktoria
     
    Tony707 likes this.
  10. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi Andrew,

    In 2.0 we internalized this functionality, however you can still access it with a small modification to the source code.

    In order to edit the source code, you will first need to copy the package so it is local to your Unity project.
    Here are the steps:

    1. To find the package source location, navigate to the package inside Unity in the Project tab, then right click and select "Show in Explorer".

    upload_2018-11-26_12-23-7.png

    On Windows the source can be found at C:\Users\{username}\AppData\Local\Unity\cache\packages\staging-packages.unity.com\com.unity.formats.fbx

    You may also need to copy the package called com.autodesk.fbx from this location as it is used by com.unity.formats.fbx

    2. Copy the packages directly into your Unity project's Packages/ directory to make it into an embedded package, then remove the package from the list in the manifest.json

    3. Now in Unity the project should look the same, except the FBX exporter source is editable from inside Unity

    4. From the Project tab open Packages/FBX Exporter/Editor/FbxExporter.cs

    5. In FbxExporter.cs, under the using statements add the following line:

    Code (csharp):
    1.  
    2. [assembly: InternalsVisibleTo("{assemblyName}")]
    3.  
    where {assemblyName} is the name of the assembly containing your scripts that call ExportObjects.

    If you do not already have an assembly definition, you can create one by right clicking in the Project view next to your C# scripts, and selecting "Create > Assembly Definition".

    Note: after copying the files they may still be read only (preventing the settings from being applied), in which case you will need to make FbxExporter.cs writeable.

    upload_2018-11-26_12-29-8.png

    Best,
    Viktoria
     
    Feelnside and laessnb like this.
  11. laessnb

    laessnb

    Joined:
    Jun 10, 2014
    Posts:
    101
    I ran into this as well -- thank you for the detailed steps on how to address it.

    I would like to throw in my two cents that, if certain settings are available via UI (such as the settings dialog for the FBX exporter that exposes the WorldAbsolute object position parameter, among others), these settings should also be accessible to script in a way that doesn't require embedding and modifying the package. Even if ExportModelSettings is kept internal, exposing its parameters as arguments to the various Export methods would be a fine fallback solution.
     
  12. andrewjepsen

    andrewjepsen

    Joined:
    Jan 12, 2016
    Posts:
    3
    Thank you, this is perfect!
     
  13. Tony707

    Tony707

    Joined:
    Jun 15, 2015
    Posts:
    38
    Great, please let me know when this feature is available for 3ds max as well.

    Thank you,
     
    vkovec likes this.
  14. corjn

    corjn

    Joined:
    Feb 6, 2014
    Posts:
    168
    Hey, while it's working fine for vertex colors, it seems like the FBX exporter is not exporting my UV sets correctly :

    I'm using a vertex painter to use channels like UV3 UVWT (or UV3 RGBA) with my complex blending shader, but the exporter seems to export only U and V.

    Here a debug with on the left the original and on the right, the export. Displaying UV3 T (or alpha) :




    Displaying UV3 UVW (RGB) :




    So you can see that UV3 W and T are missing. Same with UV0 (that can be used with the W and T channels for shading) UV1, UV2.

    Would it be possible to make an update about it ? Like the exporter could export every data of UV sets ? (UVWT in UV0 UV1 UV2 UV3 UV4 UV5 UV6 UV7, as unity now supports 8 uv sets)

    Thanks a lot for your help and time,



    Jonathan
     
    Last edited: Dec 4, 2018
  15. amorinImgSpc

    amorinImgSpc

    Joined:
    Jun 11, 2018
    Posts:
    41
    Hi!

    While I can't really give you an exact ETA, we are aware of these issues (both the missing WT data and use of the 8 UV sets) and they're logged into our system!

    Alexis
     
  16. markvi

    markvi

    Joined:
    Oct 31, 2016
    Posts:
    118
    The FBX Exporter is out of staging and now available (and discoverable) from the Package Manager, if you’re using Unity 2018.2 or newer (you’ll need to enable “Show preview packages” from the Advanced drop-down). For older Unity versions, the FBX Exporter is also available on the Asset Store.
     
    castana1962 likes this.
  17. corjn

    corjn

    Joined:
    Feb 6, 2014
    Posts:
    168
    That's good to hear, thanks for the support :)
     
  18. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    May I learn about the status of FBX Exporter and Blender?
    Is it possible to use this release with Blender?

    Thanks
     
  19. ahmidou

    ahmidou

    Joined:
    Sep 17, 2012
    Posts:
    87
    Sorry for the late reply @vkovec, I had to move to something else.
    I can't share that file, this is a production asset but I'll make a simple example.
    The goal is to directly send skinning updates from Maya to Unity without saving and reloading files.
    The vertex could be a good workaround, I also was able to generate a mapping table by analyzing and filtering the data.

    Thanks for the help!
    -A
     
    vkovec likes this.
  20. supron

    supron

    Joined:
    Aug 24, 2013
    Posts:
    67
    FBX exporter from package manager doesnt't work with 2019.1a11. I have these errors:

    Library\PackageCache\com.unity.formats.fbx@2.0.1-preview.2\Editor\IExportData.cs(3,19): error CS0234: The type or namespace name 'Timeline' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
    Library\PackageCache\com.unity.formats.fbx@2.0.1-preview.2\Editor\IExportData.cs(142,24): error CS0246: The type or namespace name 'TimelineClip' could not be found (are you missing a using directive or an assembly reference?)

    If I reference Unity.Timeline.Editor and Unity.Timeline assemblies manually in asmdef, errors are gone.
     
  21. markvi

    markvi

    Joined:
    Oct 31, 2016
    Posts:
    118
    Hi supron, thanks for the feedback. We're aware of this issue and have a fix on the way. The tricky part was finding a solution that would work with both 2018.3 and 2019.1 within the same package.

    cheers,
    -Mark
     
    supron likes this.
  22. markvi

    markvi

    Joined:
    Oct 31, 2016
    Posts:
    118
    Hi gurayg, it has always been possible to use the FBX Exporter with Blender. We added specific support for Maya and 3ds Max workflows, but these are just workflow enhancers that simplify round-tripping from the Maya/Max side. We use the official FBX SDK to create FBX files, and thus are compatible with any DCC with FBX support, including Blender.

    cheers,
    -Mark
     
  23. Brad-Newman

    Brad-Newman

    Joined:
    Feb 7, 2013
    Posts:
    185
    Running into an issue where a prefab auto instantiates in the scene when a new version of the FBX is imported.
    Unity 2018.2.19f1
    FBX Exporter 2.0.0-preview.

    Repro Steps:
    1. Export FBX from Maya 2018 into Unity.
    2. Import FBX in Unity and create Linked Prefab Instance.
    3. In Maya delete some of the meshes and re-xport.
    4. Unity imports the FBX and automatically instantiates the prefab in the root level of the currently opened scene.
    It appears some errors are happening in the AssetPostprocesser. Here is the error:

    Code (CSharp):
    1. KeyNotFoundException: The given key was not present in the dictionary.
    2. System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <f2e6809acb14476a81f399aeb800f8f2>:0)
    3. UnityEditor.Formats.Fbx.Exporter.FbxPrefabUtility+UpdateList.ImplementUpdates (UnityEngine.Formats.Fbx.Exporter.FbxPrefab prefabInstance) (at Packages/com.unity.formats.fbx@2.0.0-preview/Editor/Scripts/FbxPrefabUtility.cs:823)
    4. UnityEditor.Formats.Fbx.Exporter.FbxPrefabUtility.CompareAndUpdate () (at Packages/com.unity.formats.fbx@2.0.0-preview/Editor/Scripts/FbxPrefabUtility.cs:1045)
    5. UnityEditor.Formats.Fbx.Exporter.FbxPrefabUtility.SyncPrefab () (at Packages/com.unity.formats.fbx@2.0.0-preview/Editor/Scripts/FbxPrefabUtility.cs:1114)
    6. UnityEditor.Formats.Fbx.Exporter.FbxPrefabAutoUpdater.OnPostprocessAllAssets (System.String[] imported, System.String[] deleted, System.String[] moved, System.String[] movedFrom) (at Packages/com.unity.formats.fbx@2.0.0-preview/Editor/Scripts/FbxPrefabAutoUpdater.cs:228)
    7. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <f2e6809acb14476a81f399aeb800f8f2>:0)
    8. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    9. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <f2e6809acb14476a81f399aeb800f8f2>:0)
    10. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <f2e6809acb14476a81f399aeb800f8f2>:0)
    11. UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:140)
     
  24. deltamish

    deltamish

    Joined:
    Nov 1, 2012
    Posts:
    58
    [Possible Bug]

    Downloaded and Extracted Latest FBX Exporter from asset store . Created a scene with variety of materials . Selected all meshes and selected export. Exported to both binary and ASCII fbx.(blender doesn't support ascii fbx).

    Test Environments
    Blender 2.79b and 2.8

    Successfully imported the fbx . All materials and texture were loaded. Except few meshes had wrong materials. Which wasn't the big deal.

    3ds max 2017
    Downloaded 3ds max 2017. Installed it. Now tried imported the fbx. All meshes were loaded. But none of materials or textures were loaded properly. All meshes were bright white. And the shader were assigned to some emission with no textures attached.

    Came back to unity. Went to Edit -> Project Settings -> Fbx Export.
    There under Integrations it said no 3D application Found .

    Any hint on how to fix this ?

    Thanks
     
  25. Visual73

    Visual73

    Joined:
    Oct 21, 2017
    Posts:
    19
    Hi,

    I'm recording an animation of a camera on unity. When I charge the animation on maya, I have problems with playback speed.

    In unity, I recorded at 60 fps with unity recorder. On maya sept 60 fps and set the length of the timeline of maya, based on the timeline of unity (unity: 0 - 369 / maya: 0 - 369). Importing the animation on maya I make sure that I maintain the frame rate (60fps).

    My problem starts here.

    The animation of the camera on the timeline of maya, corresponds to the animation of the camera on the animation view of unity (animation unity image/ animation maya image).

    The problem is related to the speed of the Maya camera. Even if everything seems to be set to 60fps, the movement of the camera on maya is faster than the movement of the camera on unity.

    By activating on Playback speed: 60 fps x 1 in Time Slider, the movement of the camera is slower, but I am not sure that the slowest movement on maya is equal to the movement on unity.


    To understand if the speed of the camera in Maya, I correspond with the speed of the camera in unity, I did a trial with premiere. I imported on premiere, the video recorded by unity and a sequence of images of the animation exported by maya. In premiere everything is set to 60 fps.
    The result of the test (video premiere) shows that the two chamber movements in unity and maya do not match.
    Dark cube (maya)
    Light cube (unity)

    What should I do in Maya to have the same speed as the unity camera?
     

    Attached Files:

  26. Visual73

    Visual73

    Joined:
    Oct 21, 2017
    Posts:
    19
    I attach the image sequences.
     

    Attached Files:

  27. deltamish

    deltamish

    Joined:
    Nov 1, 2012
    Posts:
    58
    Bump
     
  28. markvi

    markvi

    Joined:
    Oct 31, 2016
    Posts:
    118
    Hi Deltamish, are you using Unity 2018.1 or greater? If so, please use the version from Package Manager - the Asset Store version is quite old. Otherwise please log a bug from the Unity Bug Reporter (accessed from inside Unity), ideally using a small repro project. Thanks!
     
    Last edited: Jan 7, 2019
  29. ArneStudio

    ArneStudio

    Joined:
    Sep 12, 2018
    Posts:
    29
    Hi All, I'm hoping to use the FBX exporter to save out a prefab which when loaded bac into a different UNITY project comes in looking exactly the same but without the ability to edit and without the tools I used to create it (Archimatix) Is this the correct tool for such a workflow? I have performed a small test and it sort of works but the results look very different, any suggestions welcome. (the original is on the right the one of the left shows the result of export then import via FBX exporter) Capture.JPG
     
  30. amorinImgSpc

    amorinImgSpc

    Joined:
    Jun 11, 2018
    Posts:
    41

    Hi!

    While we don't officially support third party in-engine tools like Archimatix, it looks from the picture that the actual geometry of your mesh fortunately exported properly! What you're witnessing, however, is the fact that Unity materials unfortunately cannot be exported to FBX, so the cause of the strange material on your exported shampoo bottle stems from the fact that it only has a generic lambert material on it.

    If you were to move that model to a new Unity project and assign a Unity material on it, your issue would probably be fixed. Here's a previous post with a little more information.

    Tell me if you need anything else!

    Alexis
     
  31. Viggy1996

    Viggy1996

    Joined:
    May 11, 2017
    Posts:
    39
    Hey! Is is possible to import FBX files from StreamingAssets at runtime?
     
  32. amorinImgSpc

    amorinImgSpc

    Joined:
    Jun 11, 2018
    Posts:
    41
    Hi!

    Do you mean if you can export FBX files at runtime? What's your planned use case for the package?

    Alexis
     
  33. Viggy1996

    Viggy1996

    Joined:
    May 11, 2017
    Posts:
    39
    I want to Import FBX files at Run-time. For Modding Purposes. I want the player, to say, put a FBX in my Streaming Assets folder and I can load it into the game. I can currently do it using Tools from the Asset Store. But using Unity's importer is what i am looking forward to.
     
  34. amorinImgSpc

    amorinImgSpc

    Joined:
    Jun 11, 2018
    Posts:
    41
    Hi again;

    Unfortunately that's not one of the features that our exporter provides.

    I suggest looking into assetbundles since some games like VRChat use them as a way to import mod content from third party developers.

    Best of luck!

    Alexis
     
  35. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
  36. AdamTegkelidis

    AdamTegkelidis

    Joined:
    Jan 22, 2019
    Posts:
    10
    Hey Everyone!

    More or less the same issues here as well. I am trying to import a model from 3ds max 2019 into Unity 2018.

    01. the FBX exporter in 3ds max is unable to export most of my materials used in the scene
    02. the imported asset in Unity, does not produce any material or texture folder as it normally should be doing
    03. the guys in Autodesk have no idea what is causing the whole problem and force me to look into commercial scripts to fix the issue.

    Does anyone have any clue on how to tackle this? It is of major importance for everyone.

    Cheers,

    Adam.
     
  37. markvi

    markvi

    Joined:
    Oct 31, 2016
    Posts:
    118
    Hi. It seems that FBX Exporter does not work with Unity 2019.x. Any roadmap or dev status?
    Hi, I just released FBX Exporter 2.0.1-preview.4 with support for Unity 2019.1:

    ## [2.0.1-preview.4] - 2018-01-31
    CHANGES
    * Updated unityRelease version in package.json

    ## [2.0.1-preview.3] - 2018-01-24
    CHANGES
    * Moved tests to separate .tests package
    * Added Timeline dependency
    * Export of blendshapes is experimental, YMMV
     
    Last edited: Jan 31, 2019
  38. markvi

    markvi

    Joined:
    Oct 31, 2016
    Posts:
    118
    We just discovered a bug in the current release of 2018.3 that results in incompatible packages being shown and installed in Package Manager.

    Please note the correct version of FBX Exporter for 2018.3.3f1 and below is 2.0.1-preview.2 and the correct version for 2019.1.0b1 is 2.0.1-preview.4.

    Unity 2018.3.4f1 (out shortly) will include backwards-compatibility for the Timeline dependency, meaning the latest package will work in both 2018.3 and 2019.1+.

    Thank you for your patience!
     
    AdamTegkelidis likes this.
  39. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    @markvi Thank you for reponse. I found some typo, "[2.0.1-preview.4] - 2018-01-31" may be 2019-01-31 ?
     
  40. markvi

    markvi

    Joined:
    Oct 31, 2016
    Posts:
    118
    Yup, typo. Thanks!
     
  41. markvi

    markvi

    Joined:
    Oct 31, 2016
    Posts:
    118
    We found a problem with preview.5 that causes builds to fail due to wrong platform settings in the Runtime asmdef. A fix will be out soon, but in the meantime if you hit this error, you can remove all platforms except Editor from com.autodesk.fbx/Runtime/Autodesk.Fbx.asmdef. You can do this on the local cached copy by right-clicking on the file (from Packages/...) and selecting "Reveal in Finder". You'll need to make the file writable first.

    Preview.6 will be out soon with a fix (Monday at the latest).
     
  42. markvi

    markvi

    Joined:
    Oct 31, 2016
    Posts:
    118
    com.unity.formats.fbx 2.0.0-preview.6 is out:

    CHANGES:
    * Updated to com.autodesk.fbx 2.0.0-preview.6
    * Updated asmdefs to only include Editor platform
     
  43. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi Adam,

    If you use the regular 3ds Max export (File > Export > Export...) to export your scene, do the materials show up in Unity?

    The Unity Max plugin is also using the same export functionality, but setting the export settings, export path and object selection for you.

    I think the problem could be that the FBX exporter does not by default embed textures on export. In order to embed textures in the FBX, you can change the settings as follows:

    Modify the export settings found in the integration folder that you chose the location for when installing the Unity Integration. The file can be found at:

    {install-path}\Integrations\Autodesk\max\scripts\unityFbxExportSettings.ms

    Change "false" to "true" in the following line to embed textures on export:

    Code (csharp):
    1.  
    2. FbxExporterSetParam "EmbedTextures" false
    3.  
    Best,
    Viktoria
     
  44. castana1962

    castana1962

    Joined:
    Apr 10, 2013
    Posts:
    400
    Hi
    Sorry for my ignorance but Did this Fbx plugin work with both Maya and 3ds Max or only Maya? Thanks
     
  45. amorinImgSpc

    amorinImgSpc

    Joined:
    Jun 11, 2018
    Posts:
    41
    Hi! Yes!

    While you can just use the in-editor plugin out-of-the-box with any DCC, our associated DCC integrations support 3DS Max and Maya 2017 and up.

    Cheers;

    Alexis
     
    Last edited: Feb 25, 2019
    castana1962 likes this.
  46. IEdge

    IEdge

    Joined:
    Mar 25, 2017
    Posts:
    51
    Hi guys, I don't know if this is the right place to post this.

    I have taken fragments of the code used by the Fbx Exporter and I have written my own so that it works in runtime, everything works well except skin weitghs are not exported properly, I need to know what I'm doing wrong?

    This is part of my exporter code:
    Code (CSharp):
    1. //====================================================================================
    2.         // Eskeleton Exporter
    3.         //====================================================================================
    4.  
    5.         public void ExportSkeletonHierarchy(GameObject go) {
    6.             var skinnedMesh = go.GetComponentsInChildren<SkinnedMeshRenderer>();
    7.  
    8.             if (skinnedMesh.Length > 0) {
    9.                 var smr = skinnedMesh.First();
    10.                 var bindPoses = smr.sharedMesh.bindposes;
    11.  
    12.                 ExportTransformHierarchy(smr.bones[0].transform.parent.gameObject, _rootNode);
    13.  
    14.                 // Step 0: map transform to index so we can look up index by bone.
    15.                 var index = new Dictionary<Transform, int>();
    16.  
    17.                 for (var i = 0; i < smr.bones.Length; i++)
    18.                     index[smr.bones[i]] = i;
    19.  
    20.                 // Step 1: Set transforms
    21.                 var boneInfo = new SkinnedMeshBoneInfo() {
    22.                     skinnedMesh = smr,
    23.                     boneDict = index,
    24.                     boneToBindPose = new Dictionary<Transform, Matrix4x4>()
    25.                 };
    26.  
    27.                 foreach (var bone in smr.bones) {
    28.                     // setup the skeleton
    29.                     var kNode = _unityObjectToFbxNode[bone.gameObject];
    30.                     var fbxSkeleton = kNode.GetSkeleton();
    31.  
    32.                     if (fbxSkeleton == null) {
    33.                         fbxSkeleton = FbxSkeleton.Create(_scene, bone.name + "_Skel");
    34.                         fbxSkeleton.Size.Set(100 / UnitScaleFactor);
    35.                         kNode.SetNodeAttribute(fbxSkeleton);
    36.                     }
    37.  
    38.                     var fbxSkeletonType = _rootNode != kNode ? FbxSkeleton.EType.eLimbNode
    39.                                           : FbxSkeleton.EType.eRoot;
    40.  
    41.                     fbxSkeleton.SetSkeletonType(fbxSkeletonType);
    42.  
    43.                     Matrix4x4 bindPose;
    44.                     Matrix4x4 pose;
    45.                     Matrix4x4 parentBindPose;
    46.                     FbxVector4 translation;
    47.  
    48.                     // get bind pose
    49.                     if (!boneInfo.boneToBindPose.TryGetValue(bone, out bindPose)) {
    50.                         bindPose = GetBindPose(bone, bindPoses, boneInfo.boneDict, boneInfo.skinnedMesh);
    51.                         boneInfo.boneToBindPose.Add(bone, bindPose);
    52.                     }
    53.  
    54.                     // get parent's bind pose
    55.                     if (!boneInfo.boneToBindPose.TryGetValue(bone.parent, out parentBindPose)) {
    56.                         parentBindPose = GetBindPose(bone.parent, bindPoses, boneInfo.boneDict, boneInfo.skinnedMesh);
    57.                         boneInfo.boneToBindPose.Add(bone.parent, parentBindPose);
    58.                     }
    59.  
    60.                     pose = parentBindPose * bindPose.inverse;
    61.  
    62.                     GetTRSFromMatrix(pose, out translation);
    63.  
    64.                     // Export bones with zero rotation, using a pivot instead to set the rotation
    65.                     // so that the bones are easier to animate and the rotation shows up as the "joint orientation" in Maya.
    66.                     var sfactor = UnitScaleFactor / 100;
    67.                     kNode.LclTranslation.Set(new FbxDouble3(-translation.X * sfactor, translation.Z * sfactor, -translation.Y * sfactor));
    68.                     kNode.SetRotationActive(true);
    69.                     kNode.SetPivotState(FbxNode.EPivotSet.eSourcePivot, FbxNode.EPivotState.ePivotReference);
    70.                 }
    71.             }
    72.         }
    73.  
    74.         //private Dictionary<int, FbxCluster> _boneCluster;
    75.  
    76.         /// <summary>
    77.         /// Export binding of mesh to skeleton
    78.         /// </summary>
    79.         public void ExportSkin(SkinnedMeshRenderer skinnedMesh, Mesh bakedMesh) {
    80.             var fbxSkin = FbxSkin.Create(_scene, skinnedMesh.name + "_Skin");
    81.             var fbxMeshMatrix = _rootNode.EvaluateGlobalTransform();
    82.  
    83.             //if (null == _boneCluster)
    84.             var boneCluster = new Dictionary<int, FbxCluster>();
    85.  
    86.             // keep track of the bone index -> fbx cluster mapping, so that we can add the bone weights afterwards
    87.             //var boneCluster = new Dictionary<int, FbxCluster>();
    88.  
    89.             for (var i = 0; i < skinnedMesh.bones.Length; i++) {
    90.                 var fbxBoneNode = _unityObjectToFbxNode[skinnedMesh.bones[i].gameObject];
    91.  
    92.                 // Create the deforming cluster
    93.                 var fbxCluster = FbxCluster.Create(_scene, "BoneWeightCluster");
    94.  
    95.                 fbxCluster.SetLink(fbxBoneNode);
    96.                 fbxCluster.SetLinkMode(FbxCluster.ELinkMode.eNormalize);
    97.  
    98.                 boneCluster.Add(i, fbxCluster);
    99.  
    100.                 // set the Transform and TransformLink matrix
    101.                 fbxCluster.SetTransformMatrix(fbxMeshMatrix);
    102.                 fbxCluster.SetTransformLinkMatrix(fbxBoneNode.EvaluateGlobalTransform());
    103.  
    104.                 // add the cluster to the skin
    105.                 fbxSkin.AddCluster(fbxCluster);
    106.             }
    107.  
    108.             // set the vertex weights for each bone
    109.             SetVertexWeights(skinnedMesh.gameObject, bakedMesh, boneCluster);
    110.  
    111.             // Add the skin to the mesh after the clusters have been added
    112.             _unitySkinnedMeshToFbxMesh[skinnedMesh].AddDeformer(fbxSkin);
    113.  
    114.             ExportBindPose(skinnedMesh);
    115.         }
    116.  
    117.        
    118.         /// <summary>
    119.         /// set vertex weights in cluster
    120.         /// </summary>
    121.         private void SetVertexWeights(GameObject owner, Mesh mesh, Dictionary<int, FbxCluster> boneCluster) {
    122.             var visitedVertices = new HashSet<int>();
    123.             var controlPointToIndex = _meshControlPoints[owner];
    124.  
    125.             // set the vertex weights for each bone
    126.             for (var i = 0; i < mesh.boneWeights.Length; i++) {
    127.                 var actualIndex = controlPointToIndex[mesh.vertices[i]];
    128.  
    129.                 if (visitedVertices.Contains(actualIndex))
    130.                     continue;
    131.  
    132.                 visitedVertices.Add(actualIndex);
    133.                
    134.                 int[] indices = {
    135.                     mesh.boneWeights[i].boneIndex0,
    136.                     mesh.boneWeights[i].boneIndex1,
    137.                     mesh.boneWeights[i].boneIndex2,
    138.                     mesh.boneWeights[i].boneIndex3
    139.                 };
    140.  
    141.                 float[] weights = {
    142.                     mesh.boneWeights[i].weight0,
    143.                     mesh.boneWeights[i].weight1,
    144.                     mesh.boneWeights[i].weight2,
    145.                     mesh.boneWeights[i].weight3
    146.                 };
    147.  
    148.                 for (var j = 0; j < indices.Length; j++) {
    149.                     if (weights[j] <= 0 || !boneCluster.ContainsKey(indices[j]))
    150.                         continue;
    151.  
    152.                     // add vertex and weighting on vertex to this bone's cluster
    153.                     boneCluster[indices[j]].AddControlPointIndex(actualIndex, weights[j]);
    154.                 }
    155.             }
    156.         }
    157.  
    158.         /// <summary>
    159.         /// Export bind pose of mesh to skeleton
    160.         /// </summary>
    161.         private void ExportBindPose(SkinnedMeshRenderer skinnedMesh/*,
    162.                                     Dictionary<SkinnedMeshRenderer, Transform[]> skinnedMeshToBonesMap*/) {
    163.             /*if (fbxMeshNode == null || skinnedMeshToBonesMap == null || fbxScene == null)
    164.             {
    165.                 return false;
    166.             }
    167. */
    168.             var fbxMeshNode = _unitySkinnedMeshToFbxMesh[skinnedMesh].GetNode();
    169.             var fbxPose = FbxPose.Create(_scene, fbxMeshNode.GetName());
    170.  
    171.             // set as bind pose
    172.             fbxPose.SetIsBindPose(true);
    173.  
    174.             // assume each bone node has one weighted vertex cluster
    175.             /*Transform[] bones;
    176.  
    177.             if (!skinnedMeshToBonesMap.TryGetValue(skinnedMesh, out bones))
    178.                 return;*/
    179.  
    180.             for (int i = 0; i < skinnedMesh.bones.Length; i++) {
    181.                 var fbxBoneNode = _unityObjectToFbxNode[skinnedMesh.bones[i].gameObject];
    182.  
    183.                 // EvaluateGlobalTransform returns an FbxAMatrix (affine matrix)
    184.                 // which has to be converted to an FbxMatrix so that it can be passed to fbxPose.Add().
    185.                 // The hierarchy for FbxMatrix and FbxAMatrix is as follows:
    186.                 //
    187.                 //      FbxDouble4x4
    188.                 //      /           \
    189.                 // FbxMatrix     FbxAMatrix
    190.                 //
    191.                 // Therefore we can't convert directly from FbxAMatrix to FbxMatrix,
    192.                 // however FbxMatrix has a constructor that takes an FbxAMatrix.
    193.                 //var fbxBindMatrix = new FbxMatrix(fbxBoneNode.EvaluateGlobalTransform ());
    194.  
    195.                 fbxPose.Add(fbxBoneNode, new FbxMatrix(fbxBoneNode.EvaluateGlobalTransform()));
    196.             }
    197.  
    198.             fbxPose.Add(fbxMeshNode, new FbxMatrix(fbxMeshNode.EvaluateGlobalTransform()));
    199.  
    200.             // add the pose to the scene
    201.             _scene.AddPose(fbxPose);
    202.         }
    And to export the model:
    Code (CSharp):
    1. IEnumerator ExportFbx_Coroutine() {
    2.  
    3.         var meshes = avatar.GetComponentsInChildren<MeshFilter>();
    4.         var skinnedMeshes = avatar.GetComponentsInChildren<SkinnedMeshRenderer>();
    5.         var fbxExporter = new FbxExporter(GetOutput(), exporterOptions, exporterInfo);
    6.         List<Transform> bones = null;
    7.  
    8.         fbxExporter.ExportSkeletonHierarchy(avatar);
    9.  
    10.         if (skinnedMeshes.Length > 0)
    11.             bones = skinnedMeshes[0].bones.ToList();
    12.  
    13.         //GetComponent<Animator>().      
    14.  
    15.         // Get all meshes on bones
    16.         for (int i = 0; i < meshes.Length; i++) {
    17.             if (meshes[i].GetComponent<SkinnedMeshRenderer>())
    18.                 continue;
    19.  
    20.             Transform parent = null;
    21.  
    22.             if (bakeMesh && bones != null && bones.Count > 0) {
    23.                 parent = bones.Find(b => b == meshes[i].transform.parent);
    24.                 meshes[i].transform.SetParent(avatar.transform);
    25.             }
    26.            
    27.             fbxExporter.ExportMesh(meshes[i].gameObject, meshes[i].sharedMesh);
    28.  
    29.             if (parent)
    30.                 meshes[i].transform.SetParent(parent);
    31.         }
    32.  
    33.         List<Mesh> bakedMeshes = null;
    34.  
    35.         if (bakeMesh) {
    36.             bakedMeshes = new List<Mesh>();
    37.  
    38.             for (int i = 0; i < skinnedMeshes.Length; i++) {
    39.                 bakedMeshes.Add(new Mesh() { name = skinnedMeshes[i].sharedMesh.name });
    40.                 skinnedMeshes[i].BakeMesh(bakedMeshes.Last());
    41.                 bakedMeshes.Last().boneWeights = skinnedMeshes[i].sharedMesh.boneWeights;
    42.             }
    43.         }
    44.  
    45.         for (int i = 0; i < skinnedMeshes.Length; i++) {
    46.             var meshFilter = skinnedMeshes[i].GetComponent<MeshFilter>();
    47.  
    48.             if (!meshFilter)
    49.                 meshFilter = skinnedMeshes[i].gameObject.AddComponent<MeshFilter>();
    50.            
    51.             meshFilter.sharedMesh = skinnedMeshes[i].sharedMesh;
    52.  
    53.             if (bakeMesh)
    54.                 meshFilter.sharedMesh = bakedMeshes[i];
    55.  
    56.             fbxExporter.ExportMesh(skinnedMeshes[i].gameObject, meshFilter.sharedMesh);
    57.             fbxExporter.ExportSkin(skinnedMeshes[i], meshFilter.sharedMesh);
    58.  
    59.             yield return null;
    60.         }
    61.     }
    I would greatly appreciate your help, thanks.
     
  47. castana1962

    castana1962

    Joined:
    Apr 10, 2013
    Posts:
    400
    Hi Alexis
    I am starting with FBX Exporter and 3ds Max and I am trying to learn it, for it, Could you let m,e get any tutorial of it?
    Sorry but I did not understood this comment yours

    While you can just use the in-editor plugin out-of-the-box with any DCC, our associated DCC integrations

    Could you explain me what does this answer means?
    Thanks for your time
    Alejandro
     
  48. amorinImgSpc

    amorinImgSpc

    Joined:
    Jun 11, 2018
    Posts:
    41
    Hey!

    To make my answer simpler (sorry about that!) I'll break it down into two parts:

    1. When you use our in-editor plugin, you can export models from Unity into fbx files that you can yes, use in any version of 3dsMax/Maya/Blender/etc. They're normal fbx files you can use anywhere!

    2. The associated DCC (and by that I mean 3dsMax and Maya) integrations we've developed aren't required to use the Unity plugin - they're there to make the round-trip between Unity and the 3D modeling app one-click, but you can for sure use the plugin without them.

    Hope that helps a little more! Let me know if you need more info.

    Alexis
     
    castana1962 likes this.
  49. amorinImgSpc

    amorinImgSpc

    Joined:
    Jun 11, 2018
    Posts:
    41
    Hi!

    We have someone on the developer team who can probably help you with this, but they're out this week. Hang tight!

    Alexis
     
    IEdge likes this.
  50. castana1962

    castana1962

    Joined:
    Apr 10, 2013
    Posts:
    400
    Hi Alexis
    First of all, thanks for your help !!!
    On the hand, I am trying the Fbx Exporter plugin from Assets Store and I am confusing myself because I got two different results doing the same in Unity.
    Example one
    I created a new Unity project and then I created a plane and added color to it and I did right button in the game object and choosed the Export to Fbx option and save it in my folder project. Then I opened it in 3ds Max and I see the plane object and its color successfully
    Example 2
    I opened my own 3D complete Unity project and chosed a game object of it and I did right button and chosed the Export to Fbx option and save it in my folder project. Then I opened it in 3ds Max and I see only the Mesh and not the materials and textures of it.
    I also see this fbx file without materials ans textures in Unity and I selected this fbx file to try to extract its Materials and textures but Unity only let me to extract the materials and not the textures.
    Surely I am doing a mistake, for it, Could you help me to fix it?
    Thanks
    Alejandro
    Ps. Hopefully you can understand me and sorry for my little English
     
Thread Status:
Not open for further replies.