mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-26 04:42:06 -05:00
Make unsupported shaders visible
This commit is contained in:
@@ -9,9 +9,9 @@ namespace UniVRM10
|
||||
{
|
||||
public static class PreviewMaterialUtil
|
||||
{
|
||||
public static PreviewMaterialItem CreateForPreview(Material material)
|
||||
public static bool TryCreateForPreview(Material material, out PreviewMaterialItem item)
|
||||
{
|
||||
var item = new PreviewMaterialItem(material);
|
||||
item = new PreviewMaterialItem(material);
|
||||
|
||||
var propNames = new List<string>();
|
||||
for (int i = 0; i < ShaderUtil.GetPropertyCount(material.shader); ++i)
|
||||
@@ -24,11 +24,24 @@ namespace UniVRM10
|
||||
case ShaderUtil.ShaderPropertyType.Color:
|
||||
// 色
|
||||
{
|
||||
var bindType = PreviewMaterialItem.GetBindType(name);
|
||||
if (!PreviewMaterialItem.TryGetBindType(name, out var bindType))
|
||||
{
|
||||
Debug.LogError($"{material.shader.name}.{name} is unsupported property name");
|
||||
item = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Enum.TryParse(propType.ToString(), true, out ShaderPropertyType propertyType))
|
||||
{
|
||||
Debug.LogError($"{material.shader.name}.{propertyType.ToString()} is unsupported property type");
|
||||
item = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
item.PropMap.Add(bindType, new PropItem
|
||||
{
|
||||
Name = name,
|
||||
PropertyType = (UniVRM10.ShaderPropertyType)Enum.Parse(typeof(UniVRM10.ShaderPropertyType), propType.ToString(), true),
|
||||
PropertyType = propertyType,
|
||||
DefaultValues = material.GetColor(name),
|
||||
});
|
||||
propNames.Add(name);
|
||||
@@ -40,7 +53,7 @@ namespace UniVRM10
|
||||
}
|
||||
}
|
||||
item.PropNames = propNames.ToArray();
|
||||
return item;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,10 +94,17 @@ namespace UniVRM10
|
||||
{
|
||||
dst = new Material(src);
|
||||
map.Add(src, dst);
|
||||
|
||||
if (!PreviewMaterialUtil.TryCreateForPreview(dst, out var previewMaterialItem))
|
||||
{
|
||||
// Return cloned material for preview
|
||||
return dst;
|
||||
}
|
||||
|
||||
m_materialMap.Add(src.name, previewMaterialItem);
|
||||
|
||||
//Debug.LogFormat("add material {0}", src.name);
|
||||
materialNames.Add(src.name);
|
||||
m_materialMap.Add(src.name, PreviewMaterialUtil.CreateForPreview(dst));
|
||||
}
|
||||
return dst;
|
||||
};
|
||||
|
||||
@@ -85,34 +85,39 @@ namespace UniVRM10
|
||||
public static readonly string SHADE_COLOR_PROPERTY = MToon10Prop.ShadeColorFactor.ToUnityShaderLabName();
|
||||
public static readonly string MATCAP_COLOR_PROPERTY = MToon10Prop.MatcapColorFactor.ToUnityShaderLabName();
|
||||
|
||||
public static MaterialColorType GetBindType(string property)
|
||||
public static bool TryGetBindType(string property, out MaterialColorType type)
|
||||
{
|
||||
if (property == COLOR_PROPERTY)
|
||||
{
|
||||
return MaterialColorType.color;
|
||||
type = MaterialColorType.color;
|
||||
}
|
||||
if (property == EMISSION_COLOR_PROPERTY)
|
||||
else if (property == EMISSION_COLOR_PROPERTY)
|
||||
{
|
||||
return MaterialColorType.emissionColor;
|
||||
type = MaterialColorType.emissionColor;
|
||||
}
|
||||
if (property == RIM_COLOR_PROPERTY)
|
||||
else if (property == RIM_COLOR_PROPERTY)
|
||||
{
|
||||
return MaterialColorType.rimColor;
|
||||
type = MaterialColorType.rimColor;
|
||||
}
|
||||
if (property == OUTLINE_COLOR_PROPERTY)
|
||||
else if (property == OUTLINE_COLOR_PROPERTY)
|
||||
{
|
||||
return MaterialColorType.outlineColor;
|
||||
type = MaterialColorType.outlineColor;
|
||||
}
|
||||
if (property == SHADE_COLOR_PROPERTY)
|
||||
else if (property == SHADE_COLOR_PROPERTY)
|
||||
{
|
||||
return MaterialColorType.shadeColor;
|
||||
type = MaterialColorType.shadeColor;
|
||||
}
|
||||
if (property == MATCAP_COLOR_PROPERTY)
|
||||
else if (property == MATCAP_COLOR_PROPERTY)
|
||||
{
|
||||
return MaterialColorType.matcapColor;
|
||||
type = MaterialColorType.matcapColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
type = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user