MaterialName

This commit is contained in:
ousttrue
2021-03-24 19:25:11 +09:00
parent 50ec690071
commit 4a4d40272f
3 changed files with 12 additions and 15 deletions

View File

@@ -156,19 +156,13 @@ namespace UniGLTF
}
}
public static Material CreateMaterial(int index, glTFMaterial src, string shaderName)
public static string MaterialName(int index, glTFMaterial src)
{
var material = new Material(Shader.Find(shaderName));
#if UNITY_EDITOR
// textureImporter.SaveAndReimport(); may destroy this material
material.hideFlags = HideFlags.DontUnloadUnusedAsset;
#endif
material.name = (src == null || string.IsNullOrEmpty(src.name))
? string.Format("material_{0:00}", index)
: src.name
;
return material;
if(src!=null && !string.IsNullOrEmpty(src.name))
{
return src.name;
}
return $"material_{index:00}";
}
public static void SetTextureOffsetAndScale(Material material, glTFTextureInfo textureInfo, string propertyName)

View File

@@ -77,13 +77,15 @@ namespace UniGLTF
getTexture = (IAwaitCaller _awaitCaller, glTF _gltf, TextureImportParam _param) => Task.FromResult<Texture2D>(null);
}
var material = new Material(Shader.Find(ShaderName));
if (i < 0 || i >= parser.GLTF.materials.Count)
{
return MaterialFactory.CreateMaterial(i, null, ShaderName);
material.name = MaterialFactory.MaterialName(i, null);
return material;
}
var src = parser.GLTF.materials[i];
var material = MaterialFactory.CreateMaterial(i, src, ShaderName);
material.name = MaterialFactory.MaterialName(i, src);
var standardParam = default(TextureImportParam);
if (src.pbrMetallicRoughness != null || src.occlusionTexture != null)
{

View File

@@ -16,7 +16,8 @@ namespace UniGLTF
}
var src = parser.GLTF.materials[i];
var material = MaterialFactory.CreateMaterial(i, src, ShaderName);
var material = new Material(Shader.Find(ShaderName));
material.name = MaterialFactory.MaterialName(i, src);
// texture
if (src.pbrMetallicRoughness.baseColorTexture != null)