-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1578 from ousttrue/fix10/unknown_material_validation
Fix10/unknown material validation
- Loading branch information
Showing
13 changed files
with
170 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
Assets/VRM10/Editor/GeneratorMenu.cs.meta → ...ditor/Format/VRMMaterialValidator.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.