Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Feedback New Asset Import Pipeline

Discussion in '2019.3 Beta' started by newguy123, Nov 12, 2019.

  1. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    383
    As per the blog post here:
    https://blogs.unity3d.com/2019/10/3...lid-foundation-for-speeding-up-asset-imports/

    When you say new features coming soon, do you mean we can get some improvements in importing FBX files please?

    We desperately need the ability to import files from 3ds Max, (via FBX), while translating physical materials into the Unity PBR equivalent of whatever pipeline our project is in. Be that HDRP or URP.

    Currently Unity only imports standard materials as well as Stingrey material (DirectX material with stingray loader). Would be awesome to also support Autodesk Physcial materials. Autodesk says the needed info is already exported into the FBX, it's up to Unity to extract the info from the FBX.
     
  2. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    383
    The physical material is the new default material in Max 2020. Makes sense to be able to import it into Unity
     
  3. thomaschollet

    thomaschollet

    Unity Technologies

    Joined:
    Nov 2, 2016
    Posts:
    16
    Hi, we've actually introduced a new material import mode in the model importer in 2019.3.
    The idea is : The model importer gathers all material properties read from FBX into a MaterialDescription structure and delegates the material creation to a callback. When using this feature, you have control over which shader to use and how the imported material properties map to the unity material.
    Take a look at https://docs.unity3d.com/2019.3/Doc...rocessor.OnPreprocessMaterialDescription.html
    I hope this helps!
     
  4. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    383
    Thanks, it sounds awesome. But, I have no idea what anything in your link means or how it is suppose to work. Seems more complicated to me now. Why can't I just import an fbx and it creates the materials for me?

    @thomaschollet can you give me a more in depth example please of how to use your link?
    Say I have a single cube in my fbx with a physical material. How should I use that script to create it?
     
  5. thomaschollet

    thomaschollet

    Unity Technologies

    Joined:
    Nov 2, 2016
    Posts:
    16
    >> Why can't I just import an fbx and it creates the materials for me?
    For 3ds physical materials, this should work out of the box with the legacy renderer and we're working on a solution for HDRP and URP. But be aware that there are limitations and some material properties cannot be converted. At the very least, the diffuse, normal and emission properties of the Physical material should be supported.
    You can find an implementation example of this in Unity 2019.3 source, look for FBXMaterialDescriptionPreprocessor.cs.

    >> Say I have a single cube in my fbx with a physical material. How should I use that script to create it?
    To use this feature use the third option of the 'material import mode' dropdown in the model importer inspector's material tab and re-import the fbx. This is going to invoke the default implementation OnPreprocessMaterialDescription that's provided with Unity. Then if you want to handle the material conversion differently, you can implement your own AssetPostprocessor.
     
  6. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    383
    Updating an old 2018 project to latest 2019.3 beta, and now getting these warnings:

    Identifier uniqueness violation: 'Name:Layer: Door, Type:Mesh'. Multiple Objects with the same name/type are generated by this Importer. There is no guarantee that subsequent imports of this asset will properly re-link to these targets.

    Identifier uniqueness violation: 'Name:Layer:Glass, Type:Mesh'. Multiple Objects with the same name/type are generated by this Importer. There is no guarantee that subsequent imports of this asset will properly re-link to these targets.

    etc etc.

    The model was originally done in AutoCAD, then imported into 3ds max deriving geometry by layer, then exporting to FBX using the Export to Unity maxscript provided by Unity.

    What does the warnings mean, and do I need to worry about it?

    In 2018, it there were updates to the model, I would just re-export to FBX, overwriting the3 exsiting one, then in UNity everything would sort itself out. Not sure what to make of these new warnings though....
     
  7. thomaschollet

    thomaschollet

    Unity Technologies

    Joined:
    Nov 2, 2016
    Posts:
    16
    Hi, that's a separate issue but I believe it's because those objects in your hierarchy have the same and therefore, if you make changes in the hierarchy in your DCC and re-import your file, then Unity won't be able to figure out which parts of the hierarchy have moved and you may lose components that you have added before re-importing.
    If you're not modifying the prefab in Unity, then you can ignore that warning.
     
  8. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    383
    OK, but the workflow we have is what we use and often need to update the model in the way we do.
    It works fine when updating the Autocad model, then the max model get updated via live link and so on.

    If it worked fine in version1, then perhaps there's a bug or an oversight on version2 that needs looking at......
     
  9. Alejandro-Martinez-Chacin

    Alejandro-Martinez-Chacin

    Joined:
    Oct 15, 2013
    Posts:
    60
    I have an issue, maybe the material description is the way to go, but in the meantime, let me explain the issue:
    1. Unity 2019.3.11f1
    2. Open a recently pulled project from a repo for the first time
    3. After all import process is done, materials created, FBX and textures processed, the materials from FBX are pink (because it goes directly to Standard Materials)
    4. Reimporting the same fbx a second time (right click import) will fix the pink issue as it will now correctly place it back as URP Lit materials (maybe it didn't find or 'URP' wasn't processed yet when it imported the FBX the first time)
    5. This poses a problem because when using build machines sometimes the cache has to be cleaned in case too big of changes happened. And actually, I haven't been able to make them work.
    6. The issue is worsened by the fact that in my case it's not pink materials, they are completely invisible (maybe I have to do something on this front, or the Internal shader error is not used anymore?)
    Work-arounds:
    • Create a prefab and extract the materials from the FBX
    • Maybe use the material description you mention?
    Would be nice to have the materials imported for the right pipeline the first time.

    Maybe I'm also doing something wrong, any help or thoughts?
    Thanks in advance.
     
  10. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    648
    @thomaschollet thanks for pointing to the right importer file, for future me, this is the one:
    https://github.com/Unity-Technologi...cessors/FBXMaterialDescriptionPreprocessor.cs

    Any hopes to get the docs to reflect what the code does? I can read the code and thus I have now much better understanding of which FBX material mode is supported in what way (and can e.g. see that 3dsMaxStandard does not support MetallicGloss, but others do), but having that in the docs would help a lot.

    EDIT: While testing the below super simple Processor, I found and reported 3 bugs, possibly related to what others have said in this thread earlier:

    • (Case 1266641) [Editor] OnPreprocessMaterialDescription does not refresh material keywords after import
    • (Case 1266631) [FBX Import][PBR] FBX imported from 3ds max with Physical Material (PBR) does not import textures/material (this one is possibly "by design" but still a workflow issue).
    • (Case 1266644) [HDRP] FBX Importer uses wrong shaders if HDRP is in project but not active pipeline
     
    Last edited: Jul 29, 2020
  11. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    648
    Also for future me (and others interested in this) here's a simple script adjusted from the Unity sample code to assign _MetallicGlossMap from FBX's SpecularFactor and _OcclusionMap from AmbientColor (not perfect but ok for workflow).

    upload_2020-7-29_10-39-50.png

    upload_2020-7-29_10-40-16.png

    Code (CSharp):
    1.  
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEngine;
    5. using UnityEditor.AssetImporters;
    6.  
    7. public class CreateMaterialFromMaterialDescription : AssetPostprocessor
    8. {
    9.     public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] materialAnimation)
    10.     {
    11.         Debug.Log("MATERIAL: " + description.materialName + " ---------------");
    12.         var shader = Shader.Find("Standard");
    13.         if (shader == null)
    14.             return;
    15.         material.shader = shader;
    16.  
    17.         List<string> props = new List<string>();
    18.  
    19.         // Log all properties for debugging
    20.         description.GetTexturePropertyNames(props);
    21.         foreach (var p in props) {
    22.             Debug.Log(p);
    23.             if(description.TryGetProperty(p, out TexturePropertyDescription texDesc))
    24.                 Debug.Log("- " + texDesc.path + ", " + texDesc.relativePath + ", " + texDesc.texture, texDesc.texture);
    25.         }
    26.         description.GetStringPropertyNames(props);
    27.         foreach (var p in props) {
    28.             Debug.Log(p);
    29.             if (description.TryGetProperty(p, out string stringDesc))
    30.                 Debug.Log("- " + stringDesc);
    31.         }
    32.  
    33.         // Use the "SpecularFactor" texture as _MetallicGlossMap
    34.         // Does not look perfect in 3ds max but comes close
    35.         TexturePropertyDescription textureProperty;
    36.         if (description.TryGetProperty("SpecularFactor", out textureProperty))
    37.             material.SetTexture("_MetallicGlossMap", textureProperty.texture);
    38.         if (description.TryGetProperty("AmbientColor", out textureProperty))
    39.             material.SetTexture("_OcclusionMap", textureProperty.texture);
    40.     }
    41. }
    42.  
     

    Attached Files:

    Last edited: Jul 29, 2020
unityunity