From 20f31faf12ee35e93694a7a7c8db8eb61853c8fb Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 5 Mar 2025 01:31:53 +0900 Subject: [PATCH] add MaterialDescriptor constructor. add comment --- .../MaterialIO/Import/MaterialDescriptor.cs | 54 +++++++++++++++++++ .../TinyMToonMaterialImporter.cs | 6 --- .../TinyPbrMaterialImporter.cs | 6 --- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Import/MaterialDescriptor.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Import/MaterialDescriptor.cs index f91c13fdb..e5f614834 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Import/MaterialDescriptor.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/Import/MaterialDescriptor.cs @@ -25,13 +25,47 @@ namespace UniGLTF /// /// /// material = new Material(matDesc.Shader); + /// /// public readonly Shader Shader; + /// + /// + /// material.renderQueue = matDesc.RenderQueue.Value; + /// + /// public readonly int? RenderQueue; + public readonly IReadOnlyDictionary TextureSlots; + + /// + /// + /// foreach (var kv in matDesc.FloatValues) + /// { + /// material.SetFloat(kv.Key, kv.Value); + /// } + /// + /// public readonly IReadOnlyDictionary FloatValues; + + /// + /// + /// foreach (var kv in matDesc.Colors) + /// { + /// material.SetColor(kv.Key, kv.Value); + /// } + /// + /// public readonly IReadOnlyDictionary Colors; + + /// + /// + /// foreach (var kv in matDesc.Vectors) + /// { + /// material.SetVector(kv.Key, kv.Value); + /// } + /// + /// public readonly IReadOnlyDictionary Vectors; /// @@ -43,6 +77,10 @@ namespace UniGLTF /// public readonly IReadOnlyList> Actions; + /// + /// New api. for new code, this is a convenience. + /// MaterialGenerateAsyncFunc has full access to material and can get all textures. + /// public readonly IReadOnlyList AsyncActions; public SubAssetKey SubAssetKey => new SubAssetKey(SubAssetKey.MaterialType, Name); @@ -68,5 +106,21 @@ namespace UniGLTF Actions = actions; AsyncActions = asyncActions ?? new List(); } + + public MaterialDescriptor( + string name, + Shader shader, + IReadOnlyList asyncActions) + { + Name = name; + Shader = shader; + RenderQueue = default; + TextureSlots = new Dictionary(); + FloatValues = new Dictionary(); + Colors = new Dictionary(); + Vectors = new Dictionary(); + Actions = new List>(); + AsyncActions = asyncActions; + } } } \ No newline at end of file diff --git a/Assets/VRM10_Samples/VRM10Viewer/MaterialImporter/TinyMToonMaterialImporter.cs b/Assets/VRM10_Samples/VRM10Viewer/MaterialImporter/TinyMToonMaterialImporter.cs index b5f5003e0..062c6138e 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/MaterialImporter/TinyMToonMaterialImporter.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/MaterialImporter/TinyMToonMaterialImporter.cs @@ -36,12 +36,6 @@ namespace UniVRM10.VRM10Viewer matDesc = new MaterialDescriptor( GltfMaterialImportUtils.ImportMaterialName(i, src), src.alphaMode == "BLEND" ? m_alphablend.shader : m_opaque.shader, - null, - new Dictionary(), - new Dictionary(), - new Dictionary(), - new Dictionary(), - new List>(), new[] { (MaterialDescriptor.MaterialGenerateAsyncFunc)AsyncAction } ); return true; diff --git a/Assets/VRM10_Samples/VRM10Viewer/MaterialImporter/TinyPbrMaterialImporter.cs b/Assets/VRM10_Samples/VRM10Viewer/MaterialImporter/TinyPbrMaterialImporter.cs index 35f137a28..0f055cf48 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/MaterialImporter/TinyPbrMaterialImporter.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/MaterialImporter/TinyPbrMaterialImporter.cs @@ -32,12 +32,6 @@ namespace UniVRM10.VRM10Viewer matDesc = new MaterialDescriptor( GltfMaterialImportUtils.ImportMaterialName(i, src), src.alphaMode == "BLEND" ? m_alphablend.shader : m_opaque.shader, - null, - new Dictionary(), - new Dictionary(), - new Dictionary(), - new Dictionary(), - new List>(), new[] { (MaterialDescriptor.MaterialGenerateAsyncFunc)AsyncAction } ); return true;