Merge pull request #1578 from ousttrue/fix10/unknown_material_validation

Fix10/unknown material validation
This commit is contained in:
ousttrue 2022-03-14 19:03:30 +09:00 committed by GitHub
commit fa4b93451e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 170 additions and 62 deletions

View File

@ -3,6 +3,9 @@ using UnityEngine;
namespace UniGLTF
{
/// <summary>
/// MeshExportValidator から使われる
/// </summary>
public interface IMaterialValidator
{
/// <summary>

View File

@ -85,7 +85,7 @@ namespace UniGLTF
var gltfMaterial = MaterialValidator.GetGltfMaterialTypeFromUnityShaderName(m.shader.name);
if (string.IsNullOrEmpty(gltfMaterial))
{
yield return Validation.Warning($"{m}: unknown shader: {m.shader.name} => export as gltf default");
yield return Validation.Warning($"{m}: unknown shader: {m.shader.name} => export as gltf default", ValidationContext.Create(m));
}
var used = new HashSet<Texture>();

View File

@ -121,42 +121,6 @@ namespace VRM
m_meshes = null;
}
/// <summary>
/// VRM0
/// </summary>
class VRMMaterialValidator : DefaultMaterialValidator
{
public override string GetGltfMaterialTypeFromUnityShaderName(string shaderName)
{
var name = VRMMaterialExporter.VrmMaterialName(shaderName);
if (!string.IsNullOrEmpty(name))
{
return name;
}
return base.GetGltfMaterialTypeFromUnityShaderName(shaderName);
}
public override IEnumerable<(string propertyName, Texture texture)> EnumerateTextureProperties(Material m)
{
if (m.shader.name != "VRM/MToon")
{
foreach (var x in base.EnumerateTextureProperties(m))
{
yield return x;
}
}
var prop = UniGLTF.ShaderPropExporter.PreShaderPropExporter.GetPropsForSupportedShader(m.shader.name);
foreach (var kv in prop.Properties)
{
if (kv.ShaderPropertyType == UniGLTF.ShaderPropExporter.ShaderPropertyType.TexEnv)
{
yield return (kv.Key, m.GetTexture(kv.Key));
}
}
}
}
protected override IEnumerable<Validator> ValidatorFactory()
{
// ヒエラルキー のチェック

View File

@ -0,0 +1,58 @@
using System.Collections.Generic;
using UnityEngine;
namespace VRM
{
/// <summary>
/// VRM0
/// </summary>
class VRMMaterialValidator : UniGLTF.DefaultMaterialValidator
{
public override string GetGltfMaterialTypeFromUnityShaderName(string shaderName)
{
var name = VRMMaterialExporter.VrmMaterialName(shaderName);
if (!string.IsNullOrEmpty(name))
{
return name;
}
return base.GetGltfMaterialTypeFromUnityShaderName(shaderName);
}
public override IEnumerable<(string propertyName, Texture texture)> EnumerateTextureProperties(Material m)
{
/// 歴史的経緯により処理ロジックが2種類ある
if (m.shader.name == "VRM/MToon")
{
// [Unity列挙]
// * UnityEditor.ShaderUtil により Shader の Property を列挙する。Editor専用。
// * あらかじめEditorで実行して property 一覧をハードコーディングしてある `Assets\VRMShaders\VRM\IO\Runtime\VRM\PreExportShaders_VRM.cs` 界隈。
// * 今は "VRM/MToon" のみ
//
// extensions.VRM.materialProperties に記録する
//
var prop = UniGLTF.ShaderPropExporter.PreShaderPropExporter.GetPropsForSupportedShader(m.shader.name);
foreach (var kv in prop.Properties)
{
if (kv.ShaderPropertyType == UniGLTF.ShaderPropExporter.ShaderPropertyType.TexEnv)
{
yield return (kv.Key, m.GetTexture(kv.Key));
}
}
}
else
{
// [Shaderの定義から手で記述]
//
// PBR, Unlit
// * DefaultMaterialValidator.EnumerateTextureProperties
//
// glTF.materials に記録する
//
foreach (var textureProperty in base.EnumerateTextureProperties(m))
{
yield return textureProperty;
}
}
}
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 7f8755f9d806837408cd04ebb587489c
guid: 43a9939275e36534797e9be6fb83c71e
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -10,11 +10,8 @@ namespace UniVRM10
/// </summary>
public class VRM10Window : EditorWindow
{
const string MENU_KEY = VRMVersion.MENU + "/VRM1 Window";
const string WINDOW_TITLE = "VRM1 Window";
[MenuItem(MENU_KEY, false, 1)]
private static void ExportFromMenu()
public static void Open()
{
var window = (VRM10Window)GetWindow(typeof(VRM10Window));
window.titleContent = new GUIContent(WINDOW_TITLE);

View File

@ -0,0 +1,41 @@
using System.Collections.Generic;
using UnityEngine;
namespace UniVRM10
{
/// <summary>
/// VRM0
/// </summary>
class VRM10MaterialValidator : UniGLTF.DefaultMaterialValidator
{
const string MTOON_SHADER_NAME = "VRM10/MToon10";
public override string GetGltfMaterialTypeFromUnityShaderName(string shaderName)
{
switch (shaderName)
{
case MTOON_SHADER_NAME:
return "VRMC_materials_mtoon";
}
// TODO: VRM-0.X
return base.GetGltfMaterialTypeFromUnityShaderName(shaderName);
}
public override IEnumerable<(string propertyName, Texture texture)> EnumerateTextureProperties(Material m)
{
if (m.shader.name == MTOON_SHADER_NAME)
{
// TODO
}
else
{
foreach (var x in base.EnumerateTextureProperties(m))
{
yield return x;
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 77bcf6c00ae8990488aaea60f0ec9173
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -13,10 +13,7 @@ namespace UniVRM10
{
public class VRM10ExportDialog : ExportDialogBase
{
const string CONVERT_HUMANOID_KEY = VRMVersion.MENU + "/Export VRM-1.0";
[MenuItem(CONVERT_HUMANOID_KEY, false, 0)]
private static void ExportFromMenu()
public static void Open()
{
var window = (VRM10ExportDialog)GetWindow(typeof(VRM10ExportDialog));
window.titleContent = new GUIContent("VRM-1.0 Exporter");
@ -136,6 +133,10 @@ namespace UniVRM10
yield break;
}
// Mesh/Renderer のチェック
m_meshes.MaterialValidator = new VRM10MaterialValidator();
yield return m_meshes.Validate;
yield return HumanoidValidator.Validate_TPose;
// MeshUtility.Validators.HumanoidValidator.EnableFreeze = false;

View File

@ -13,22 +13,8 @@ namespace UniVRM10
/// は SubModuleになった。 `$ git submodule update --init` しておくこと。
///
/// </summary>
public static class Menu
public static class Vrm10SerializerGenerator
{
#if VRM_DEVELOP
[MenuItem(UniVRM10.VRMVersion.MENU + "/Generate from JsonSchema")]
public static void Generate()
{
Run(false);
}
[MenuItem(UniVRM10.VRMVersion.MENU + "/Generate from JsonSchema(debug)")]
public static void Parse()
{
Run(true);
}
#endif
struct GenerateInfo
{
public string JsonSchema;
@ -49,7 +35,7 @@ namespace UniVRM10
const string SPEC_DIR = "vrm-specification/specification";
static void Run(bool debug)
public static void Run(bool debug)
{
var projectRoot = new DirectoryInfo(Path.GetFullPath(Path.Combine(Application.dataPath, "../")));

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e5497454373c2a458526799422de3ad
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,25 @@
using UnityEditor;
namespace UniVRM10
{
public static class Vrm10TopMenu
{
private const string UserMenuPrefix = VRMVersion.MENU;
private const string DevelopmentMenuPrefix = VRMVersion.MENU + "/Development";
const string CONVERT_HUMANOID_KEY = VRMVersion.MENU + "/Export VRM-1.0";
[MenuItem(UserMenuPrefix + "/Export VRM-1.0", priority = 1)]
static void OpenExportDialog() => VRM10ExportDialog.Open();
#if VRM_DEVELOP
[MenuItem(UserMenuPrefix + "/VRM1 Window", false, 2)]
static void OpenWindow() => VRM10Window.Open();
[MenuItem(DevelopmentMenuPrefix + "/Generate from JsonSchema")]
public static void Generate() => Vrm10SerializerGenerator.Run(false);
[MenuItem(DevelopmentMenuPrefix + "/Generate from JsonSchema(debug)")]
public static void Parse() => Vrm10SerializerGenerator.Run(true);
#endif
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 935fd2eb9940f5d48933733f69a96113
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: