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.
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 Unity - Scripting API: AssetPostprocessor.OnPreprocessMaterialDescription(MaterialDescription,Material, AnimationClip[])
I hope this helps!
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?
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.
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âŚ
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.
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âŚ
I have an issue, maybe the material description is the way to go, but in the meantime, let me explain the issue:
Unity 2019.3.11f1
Open a recently pulled project from a repo for the first time
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)
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)
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.
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.
@thomaschollet thanks for pointing to the right importer file, for future me, this is the one:
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
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).
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.AssetImporters;
public class CreateMaterialFromMaterialDescription : AssetPostprocessor
{
public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] materialAnimation)
{
Debug.Log("MATERIAL: " + description.materialName + " ---------------");
var shader = Shader.Find("Standard");
if (shader == null)
return;
material.shader = shader;
List<string> props = new List<string>();
// Log all properties for debugging
description.GetTexturePropertyNames(props);
foreach (var p in props) {
Debug.Log(p);
if(description.TryGetProperty(p, out TexturePropertyDescription texDesc))
Debug.Log("- " + texDesc.path + ", " + texDesc.relativePath + ", " + texDesc.texture, texDesc.texture);
}
description.GetStringPropertyNames(props);
foreach (var p in props) {
Debug.Log(p);
if (description.TryGetProperty(p, out string stringDesc))
Debug.Log("- " + stringDesc);
}
// Use the "SpecularFactor" texture as _MetallicGlossMap
// Does not look perfect in 3ds max but comes close
TexturePropertyDescription textureProperty;
if (description.TryGetProperty("SpecularFactor", out textureProperty))
material.SetTexture("_MetallicGlossMap", textureProperty.texture);
if (description.TryGetProperty("AmbientColor", out textureProperty))
material.SetTexture("_OcclusionMap", textureProperty.texture);
}
}