Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Question OnPreprocessMaterialDescription to set textures from 3ds Max physical material

Discussion in '2019.3 Beta' started by susares, Nov 28, 2019.

  1. susares

    susares

    Joined:
    Nov 15, 2019
    Posts:
    2
    Hi,

    the new OnPreprocessMaterialDescription callback in order to manually initialize Materials from imported files (in our case fbx) looks promising.

    When trying to initialize the material from an exported the 3ds max physical material the following problem occurs.

    Code (CSharp):
    1.       TexturePropertyDescription baseTexture = new TexturePropertyDescription();
    2.       if (!description.TryGetProperty("base_color_map", out baseTexture))
    3.          return;
    4.  
    The call succeeds however the baseTexture.texture property then is set to null
    The baseTexture.path property contains a an entry of the form "Temp/UnityTemporaryfilexxxx/texturefilename.extension

    Which does not seem to exist anywhere in the unity project or local temp directory.

    We have also tried to extract the textures from the fbx during OnPreProcessModel.
    When calling the AssetPostProcessor script the first time the textures are extracted. However not working when the OnPreprocessMateriaDescription is called.
    Calling the script a second time either via Reimport in the editor or when running Unity from commandline (i.e. automated AssetBundle Builds). the texture property is set and working.
    AssetDatabase.Refresh() does not remove the need of a bonus round either.

    Is there anything that can be done to get it working without either extracting the textures or being forced to call the importer 2 times (which takes quite some time with fbx files ranging to 150mb or more).

    regards

    André Reschke
     
  2. thomaschollet

    thomaschollet

    Unity Technologies

    Joined:
    Nov 2, 2016
    Posts:
    17
    Hi, OnPreProcessModel gets called after OnPreprocessMateriaDescription in the import process so the textures are imported too late in this case, have you tried using OnPreprocessModel instead ?
     
  3. thomaschollet

    thomaschollet

    Unity Technologies

    Joined:
    Nov 2, 2016
    Posts:
    17
    Sorry I misread your post and read OnPreProcessModel as OnPostprocessModel... :(

    I tried reproducing your use case locally but with a standard material and it seems to work ok, here's the AssetPostprocessor code I used :
    Code (CSharp):
    1.  
    2. void OnPreprocessModel()
    3.     {
    4.         (assetImporter as ModelImporter)?.ExtractTextures("Assets/");
    5.     }
    6.  
    7.     public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] materialAnimation)
    8.     {
    9.         TexturePropertyDescription textureProperty;
    10.         if (description.TryGetProperty("DiffuseColor", out textureProperty))
    11.         {
    12.             Debug.Log(textureProperty.texture);
    13.         }
    14.     }
    15.  
    Is the issue only occuring for '3ds max physical material' on your side ?
    If so would you mind logging a bug report so that I can have a look ?
    Thanks!
     
  4. susares

    susares

    Joined:
    Nov 15, 2019
    Posts:
    2
    Ok from the looks i wrongly assumed that the Importer would also dive into subdirectories when looking for the freshly extracted textures.

    My import script was extracting the textures into a subdirectory named like the model file name to not get lost in a file mess when importing multiple fbx files.

    For my project I have a more or less empty template project with just Editor related scripts. From another tool of ours text assets and fbx files and other image files are copied to the templates Asset directory. Afterwards unity is started in batch mode to produce AssetBundles that can be used with a Unity Player for Android/IOS.

    The fbx files I tested so far work when the textures are extracted to the same directory as the corresponding fbx file.

    Is this a glitch in the new Importpipeline ?
    Because when reimporting/refreshing the Asset(Database) by script after extracting eventually the textures will be resolved at some point at least in the editor but not in Android/IOS.
     
  5. thomaschollet

    thomaschollet

    Unity Technologies

    Joined:
    Nov 2, 2016
    Posts:
    17
    Hi, this sounds like a bug, could you log a bug with a minimal project so I can try to reproduce it an investigate ?