From d756e3487d17c20ecb84e5a2dcb5c31f10794438 Mon Sep 17 00:00:00 2001 From: notargs Date: Wed, 26 Apr 2023 16:24:23 +0900 Subject: [PATCH] =?UTF-8?q?MToon=20URP=E3=81=AE=E8=AA=AD=E3=81=BF=E8=BE=BC?= =?UTF-8?q?=E3=81=BF=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IO/Material/URP/Import/Materials.meta | 8 +++ .../UrpVrm10MToonMaterialImporter.cs | 49 +++++++++++++++++++ .../UrpVrm10MToonMaterialImporter.cs.meta | 3 ++ 3 files changed, 60 insertions(+) create mode 100644 Assets/VRM10/Runtime/IO/Material/URP/Import/Materials.meta create mode 100644 Assets/VRM10/Runtime/IO/Material/URP/Import/Materials/UrpVrm10MToonMaterialImporter.cs create mode 100644 Assets/VRM10/Runtime/IO/Material/URP/Import/Materials/UrpVrm10MToonMaterialImporter.cs.meta diff --git a/Assets/VRM10/Runtime/IO/Material/URP/Import/Materials.meta b/Assets/VRM10/Runtime/IO/Material/URP/Import/Materials.meta new file mode 100644 index 000000000..2c542f476 --- /dev/null +++ b/Assets/VRM10/Runtime/IO/Material/URP/Import/Materials.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1987bdfe8c2df174abb9cf04caaaba15 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/IO/Material/URP/Import/Materials/UrpVrm10MToonMaterialImporter.cs b/Assets/VRM10/Runtime/IO/Material/URP/Import/Materials/UrpVrm10MToonMaterialImporter.cs new file mode 100644 index 000000000..fae01b5b5 --- /dev/null +++ b/Assets/VRM10/Runtime/IO/Material/URP/Import/Materials/UrpVrm10MToonMaterialImporter.cs @@ -0,0 +1,49 @@ +using System; +using System.Linq; +using UniGLTF; +using UnityEngine; +using VRMShaders; +using VRMShaders.VRM10.MToon10.Runtime; + +namespace UniVRM10 +{ + /// + /// Convert MToon parameters from glTF specification to Unity implementation. + /// + public static class UrpVrm10MToonMaterialImporter + { + /// + /// VMRC_materials_mtoon の場合にマテリアル生成情報を作成する + /// + public static bool TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc) + { + var m = data.GLTF.materials[i]; + if (!UniGLTF.Extensions.VRMC_materials_mtoon.GltfDeserializer.TryGet(m.extensions, out var mtoon)) + { + // Fallback to glTF, when MToon extension does not exist. + matDesc = default; + return false; + } + + // use material.name, because material name may renamed in GltfParser. + matDesc = new MaterialDescriptor( + m.name, + Shader.Find(MToon10Meta.URPUnityShaderName), + null, + Vrm10MToonTextureImporter.EnumerateAllTextures(data, m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.Item2.Item2), + BuiltInVrm10MToonMaterialImporter.TryGetAllFloats(m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value), + BuiltInVrm10MToonMaterialImporter.TryGetAllColors(m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value), + BuiltInVrm10MToonMaterialImporter.TryGetAllFloatArrays(m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value), + new Action[] + { + material => + { + // Set hidden properties, keywords from float properties. + new MToonValidator(material).Validate(); + } + }); + + return true; + } + } +} diff --git a/Assets/VRM10/Runtime/IO/Material/URP/Import/Materials/UrpVrm10MToonMaterialImporter.cs.meta b/Assets/VRM10/Runtime/IO/Material/URP/Import/Materials/UrpVrm10MToonMaterialImporter.cs.meta new file mode 100644 index 000000000..0714adc64 --- /dev/null +++ b/Assets/VRM10/Runtime/IO/Material/URP/Import/Materials/UrpVrm10MToonMaterialImporter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 57d820ccc1ff7e2469f7fb5cc435bd5b +timeCreated: 1620630516 \ No newline at end of file