From aed1d170d403f90497a72eae568cd62d36fc214d Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Mon, 5 Dec 2022 16:05:20 +0900 Subject: [PATCH 1/2] make MaterialDescriptor class --- .../Material/Importer/MaterialDescriptor.cs | 28 +------------------ 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialDescriptor.cs b/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialDescriptor.cs index b46f09bcd..41e61e9ec 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialDescriptor.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialDescriptor.cs @@ -4,7 +4,7 @@ using UnityEngine; namespace VRMShaders { - public readonly struct MaterialDescriptor : IEquatable + public sealed class MaterialDescriptor { public readonly string Name; public readonly string ShaderName; @@ -43,31 +43,5 @@ namespace VRMShaders Vectors = vectors; Actions = actions; } - - public bool Equals(MaterialDescriptor other) - { - return Name == other.Name && ShaderName == other.ShaderName && RenderQueue == other.RenderQueue && Equals(TextureSlots, other.TextureSlots) && Equals(FloatValues, other.FloatValues) && Equals(Colors, other.Colors) && Equals(Vectors, other.Vectors) && Equals(Actions, other.Actions); - } - - public override bool Equals(object obj) - { - return obj is MaterialDescriptor other && Equals(other); - } - - public override int GetHashCode() - { - unchecked - { - var hashCode = (Name != null ? Name.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (ShaderName != null ? ShaderName.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ RenderQueue.GetHashCode(); - hashCode = (hashCode * 397) ^ (TextureSlots != null ? TextureSlots.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (FloatValues != null ? FloatValues.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (Colors != null ? Colors.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (Vectors != null ? Vectors.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (Actions != null ? Actions.GetHashCode() : 0); - return hashCode; - } - } } } \ No newline at end of file From 2f915b4777298756b079b1dc80c366adc90f2c02 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Mon, 5 Dec 2022 16:30:43 +0900 Subject: [PATCH 2/2] Take off responsibility of determining shaders from ImporterContext. --- .../Runtime/UniGLTF/IO/ImporterContext.cs | 6 ++-- .../BuiltInGltfMaterialDescriptorGenerator.cs | 5 ++++ .../BuiltInGltfDefaultMaterialImporter.cs | 28 +++++++++++++++++++ ...BuiltInGltfDefaultMaterialImporter.cs.meta | 3 ++ .../IMaterialDescriptorGenerator.cs | 8 ++++++ .../UrpGltfDefaultMaterialImporter.cs | 28 +++++++++++++++++++ .../UrpGltfDefaultMaterialImporter.cs.meta | 3 ++ .../UrpGltfMaterialDescriptorGenerator.cs | 5 ++++ .../BuiltInVrmMaterialDescriptorGenerator.cs | 5 ++++ .../UrpVrmMaterialDescriptorGenerator.cs | 5 ++++ ...BuiltInVrm10MaterialDescriptorGenerator.cs | 4 +++ .../UrpVrm10MaterialDescriptorGenerator.cs | 4 +++ .../Material/Importer/MaterialDescriptor.cs | 7 ----- 13 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Import/Materials/BuiltInGltfDefaultMaterialImporter.cs create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Import/Materials/BuiltInGltfDefaultMaterialImporter.cs.meta create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Import/Materials/UrpGltfDefaultMaterialImporter.cs create mode 100644 Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Import/Materials/UrpGltfDefaultMaterialImporter.cs.meta diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs index 2a72caeac..539bac542 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -289,8 +289,8 @@ namespace UniGLTF { // no material. work around. // TODO: https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#default-material - var param = MaterialDescriptor.Default; - var material = await MaterialFactory.LoadAsync(param, TextureFactory.GetTextureAsync, awaitCaller); + var param = MaterialDescriptorGenerator.GetGltfDefault(); + await MaterialFactory.LoadAsync(param, TextureFactory.GetTextureAsync, awaitCaller); } else { @@ -298,7 +298,7 @@ namespace UniGLTF { await awaitCaller.NextFrameIfTimedOut(); var param = MaterialDescriptorGenerator.Get(Data, i); - var material = await MaterialFactory.LoadAsync(param, TextureFactory.GetTextureAsync, awaitCaller); + await MaterialFactory.LoadAsync(param, TextureFactory.GetTextureAsync, awaitCaller); } } } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Import/BuiltInGltfMaterialDescriptorGenerator.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Import/BuiltInGltfMaterialDescriptorGenerator.cs index ed75ce33b..00e2a304e 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Import/BuiltInGltfMaterialDescriptorGenerator.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Import/BuiltInGltfMaterialDescriptorGenerator.cs @@ -31,5 +31,10 @@ namespace UniGLTF new Dictionary(), new Action[]{}); } + + public MaterialDescriptor GetGltfDefault() + { + return BuiltInGltfDefaultMaterialImporter.CreateParam(); + } } } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Import/Materials/BuiltInGltfDefaultMaterialImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Import/Materials/BuiltInGltfDefaultMaterialImporter.cs new file mode 100644 index 000000000..63bc109f0 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Import/Materials/BuiltInGltfDefaultMaterialImporter.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using VRMShaders; + +namespace UniGLTF +{ + /// + /// Generate the descriptor of the glTF default material. + /// + public static class BuiltInGltfDefaultMaterialImporter + { + public static MaterialDescriptor CreateParam() + { + // FIXME + return new MaterialDescriptor( + "__default__", + "Standard", + default, + new Dictionary(), + new Dictionary(), + new Dictionary(), + new Dictionary(), + new List>() + ); + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Import/Materials/BuiltInGltfDefaultMaterialImporter.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Import/Materials/BuiltInGltfDefaultMaterialImporter.cs.meta new file mode 100644 index 000000000..d5b2c7e52 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Import/Materials/BuiltInGltfDefaultMaterialImporter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: aa5431a3a9ee4f9caac398688c3a8973 +timeCreated: 1670224943 \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/IMaterialDescriptorGenerator.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/IMaterialDescriptorGenerator.cs index 10f877c23..c727bf601 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/IMaterialDescriptorGenerator.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/IMaterialDescriptorGenerator.cs @@ -8,6 +8,14 @@ namespace UniGLTF /// public interface IMaterialDescriptorGenerator { + /// + /// Generate the MaterialDescriptor generated from the index i. + /// MaterialDescriptor Get(GltfData data, int i); + + /// + /// Generate the MaterialDescriptor for the non-specified glTF material. + /// + MaterialDescriptor GetGltfDefault(); } } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Import/Materials/UrpGltfDefaultMaterialImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Import/Materials/UrpGltfDefaultMaterialImporter.cs new file mode 100644 index 000000000..154c6d75c --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Import/Materials/UrpGltfDefaultMaterialImporter.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using VRMShaders; + +namespace UniGLTF +{ + /// + /// Generate the descriptor of the glTF default material. + /// + public static class UrpGltfDefaultMaterialImporter + { + public static MaterialDescriptor CreateParam() + { + // FIXME + return new MaterialDescriptor( + "__default__", + UrpGltfPbrMaterialImporter.ShaderName, + default, + new Dictionary(), + new Dictionary(), + new Dictionary(), + new Dictionary(), + new List>() + ); + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Import/Materials/UrpGltfDefaultMaterialImporter.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Import/Materials/UrpGltfDefaultMaterialImporter.cs.meta new file mode 100644 index 000000000..4d5d5eae0 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Import/Materials/UrpGltfDefaultMaterialImporter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 320b6d26ea014356b1c37e38425bf152 +timeCreated: 1670225169 \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Import/UrpGltfMaterialDescriptorGenerator.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Import/UrpGltfMaterialDescriptorGenerator.cs index d67dd3a81..4ab8d7e9d 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Import/UrpGltfMaterialDescriptorGenerator.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Import/UrpGltfMaterialDescriptorGenerator.cs @@ -32,5 +32,10 @@ namespace UniGLTF new Dictionary(), new Collection>()); } + + public MaterialDescriptor GetGltfDefault() + { + return UrpGltfDefaultMaterialImporter.CreateParam(); + } } } \ No newline at end of file diff --git a/Assets/VRM/Runtime/IO/MaterialIO/BuiltInRP/Import/BuiltInVrmMaterialDescriptorGenerator.cs b/Assets/VRM/Runtime/IO/MaterialIO/BuiltInRP/Import/BuiltInVrmMaterialDescriptorGenerator.cs index ed2a1db94..7f112c065 100644 --- a/Assets/VRM/Runtime/IO/MaterialIO/BuiltInRP/Import/BuiltInVrmMaterialDescriptorGenerator.cs +++ b/Assets/VRM/Runtime/IO/MaterialIO/BuiltInRP/Import/BuiltInVrmMaterialDescriptorGenerator.cs @@ -53,5 +53,10 @@ namespace VRM new Dictionary(), new Action[]{}); } + + public MaterialDescriptor GetGltfDefault() + { + return BuiltInGltfDefaultMaterialImporter.CreateParam(); + } } } diff --git a/Assets/VRM/Runtime/IO/MaterialIO/URP/Import/UrpVrmMaterialDescriptorGenerator.cs b/Assets/VRM/Runtime/IO/MaterialIO/URP/Import/UrpVrmMaterialDescriptorGenerator.cs index 6c8f2d482..3c20c7c4f 100644 --- a/Assets/VRM/Runtime/IO/MaterialIO/URP/Import/UrpVrmMaterialDescriptorGenerator.cs +++ b/Assets/VRM/Runtime/IO/MaterialIO/URP/Import/UrpVrmMaterialDescriptorGenerator.cs @@ -37,5 +37,10 @@ namespace VRM new Dictionary(), new Action[]{}); } + + public MaterialDescriptor GetGltfDefault() + { + return UrpGltfDefaultMaterialImporter.CreateParam(); + } } } diff --git a/Assets/VRM10/Runtime/IO/Material/BuiltInRP/Import/BuiltInVrm10MaterialDescriptorGenerator.cs b/Assets/VRM10/Runtime/IO/Material/BuiltInRP/Import/BuiltInVrm10MaterialDescriptorGenerator.cs index 79360e37a..5a25a5a94 100644 --- a/Assets/VRM10/Runtime/IO/Material/BuiltInRP/Import/BuiltInVrm10MaterialDescriptorGenerator.cs +++ b/Assets/VRM10/Runtime/IO/Material/BuiltInRP/Import/BuiltInVrm10MaterialDescriptorGenerator.cs @@ -31,5 +31,9 @@ namespace UniVRM10 new Action[]{}); } + public MaterialDescriptor GetGltfDefault() + { + return BuiltInGltfDefaultMaterialImporter.CreateParam(); + } } } diff --git a/Assets/VRM10/Runtime/IO/Material/URP/Import/UrpVrm10MaterialDescriptorGenerator.cs b/Assets/VRM10/Runtime/IO/Material/URP/Import/UrpVrm10MaterialDescriptorGenerator.cs index 2201e19ad..fdf8c0a0f 100644 --- a/Assets/VRM10/Runtime/IO/Material/URP/Import/UrpVrm10MaterialDescriptorGenerator.cs +++ b/Assets/VRM10/Runtime/IO/Material/URP/Import/UrpVrm10MaterialDescriptorGenerator.cs @@ -27,5 +27,9 @@ namespace UniVRM10 new Action[]{}); } + public MaterialDescriptor GetGltfDefault() + { + return UrpGltfDefaultMaterialImporter.CreateParam(); + } } } diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialDescriptor.cs b/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialDescriptor.cs index 41e61e9ec..e17e9bdde 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialDescriptor.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialDescriptor.cs @@ -17,13 +17,6 @@ namespace VRMShaders public SubAssetKey SubAssetKey => new SubAssetKey(SubAssetKey.MaterialType, Name); - public static readonly MaterialDescriptor Default = new MaterialDescriptor("__default__", "Standard", default, - new Dictionary(), - new Dictionary(), - new Dictionary(), - new Dictionary(), - new List>()); - public MaterialDescriptor( string name, string shaderName,