From b90c5026a657788f9e32b92ef7c652091fbd9780 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Tue, 7 Jun 2022 17:37:07 +0900 Subject: [PATCH 1/3] =?UTF-8?q?unity-2021=20=E3=81=A7=E3=81=AF=20SetVector?= =?UTF-8?q?=20=E3=81=AB=E3=82=88=E3=82=8A=20offset,=20scale=20=E3=82=92?= =?UTF-8?q?=E3=82=BB=E3=83=83=E3=83=88=E3=81=99=E3=82=8B=E3=81=A8=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=20Property=20PROP=5FNAME=20already=20exists?= =?UTF-8?q?=20in=20the=20property=20sheet=20with=20a=20different=20type:?= =?UTF-8?q?=205=20=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=99=E3=82=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/Material/Importer/MaterialFactory.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialFactory.cs b/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialFactory.cs index a349269a1..05fb241c6 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialFactory.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialFactory.cs @@ -140,10 +140,16 @@ namespace VRMShaders material.SetColor(kv.Key, kv.Value); } - foreach (var kv in matDesc.Vectors) - { - material.SetVector(kv.Key, kv.Value); - } + // Unity-2021 くらいから offset, scale を SetVector すると + // `Property PROP_NAME already exists in the property sheet with a different type: 5` というエラーが発生するようになった。 + // Material.SetTextureOffset と SetTextureScale を使うべし。 + // 上方の SetTextureOffsetAndScale で既に対処済みです。 + // よってエラーになる下記をコメントアウトする。 + // MToon において offset, scale 以外の用途で Vector4 になる property はありません。 + // foreach (var kv in matDesc.Vectors) + // { + // material.SetVector(kv.Key, kv.Value); + // } foreach (var kv in matDesc.FloatValues) { From c0d7869258268c43c2c1621137126cf1dc1be556 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 8 Jun 2022 17:42:31 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=82=88=E3=82=8A=E4=B8=8A=E6=B5=81?= =?UTF-8?q?=E3=81=A7=E9=98=B2=E5=BE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Vector には Color も入っているぽい(Vector4 と Colorは実質同じ) * Texture が無いときにも OffsetScale が入っているケースがある --- .../Runtime/IO/VRMMToonMaterialImporter.cs | 19 ++++++++++++++++++- .../Material/Importer/MaterialFactory.cs | 15 +++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Assets/VRM/Runtime/IO/VRMMToonMaterialImporter.cs b/Assets/VRM/Runtime/IO/VRMMToonMaterialImporter.cs index 21ce7553d..702cc3590 100644 --- a/Assets/VRM/Runtime/IO/VRMMToonMaterialImporter.cs +++ b/Assets/VRM/Runtime/IO/VRMMToonMaterialImporter.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using UniGLTF; using UnityEngine; using VRMShaders; @@ -8,6 +9,19 @@ namespace VRM { public static class VRMMToonMaterialImporter { + static string[] MToonTextureSolots = new string[]{ + "_MainTex", + "_ShadeTexture", + "_BumpMap", + "_EmissionMap", + "_OutlineWidthTexture", + "_ReceiveShadowTexture", + "_RimTexture", + "_ShadingGradeTexture", + "_SphereAdd", + "_UvAnimMaskTexture", + }; + public static bool TryCreateParam(GltfData data, glTF_VRM_extensions vrm, int materialIdx, out MaterialDescriptor matDesc) { @@ -60,7 +74,10 @@ namespace VRM foreach (var kv in vrmMaterial.vectorProperties) { // vector4 exclude TextureOffsetScale - if (vrmMaterial.textureProperties.ContainsKey(kv.Key)) continue; + if (MToonTextureSolots.Contains(kv.Key)) + { + continue; + } var v = new Vector4(kv.Value[0], kv.Value[1], kv.Value[2], kv.Value[3]); vectors.Add(kv.Key, v); } diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialFactory.cs b/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialFactory.cs index 05fb241c6..6c6c39e4a 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialFactory.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/Material/Importer/MaterialFactory.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using UnityEngine; @@ -140,16 +141,10 @@ namespace VRMShaders material.SetColor(kv.Key, kv.Value); } - // Unity-2021 くらいから offset, scale を SetVector すると - // `Property PROP_NAME already exists in the property sheet with a different type: 5` というエラーが発生するようになった。 - // Material.SetTextureOffset と SetTextureScale を使うべし。 - // 上方の SetTextureOffsetAndScale で既に対処済みです。 - // よってエラーになる下記をコメントアウトする。 - // MToon において offset, scale 以外の用途で Vector4 になる property はありません。 - // foreach (var kv in matDesc.Vectors) - // { - // material.SetVector(kv.Key, kv.Value); - // } + foreach (var kv in matDesc.Vectors) + { + material.SetVector(kv.Key, kv.Value); + } foreach (var kv in matDesc.FloatValues) { From d530b0fc6d64390347fae6e80881ad45f83df8b5 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 8 Jun 2022 17:55:09 +0900 Subject: [PATCH 3/3] typo --- Assets/VRM/Runtime/IO/VRMMToonMaterialImporter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/VRM/Runtime/IO/VRMMToonMaterialImporter.cs b/Assets/VRM/Runtime/IO/VRMMToonMaterialImporter.cs index 702cc3590..56c9c95a9 100644 --- a/Assets/VRM/Runtime/IO/VRMMToonMaterialImporter.cs +++ b/Assets/VRM/Runtime/IO/VRMMToonMaterialImporter.cs @@ -9,7 +9,7 @@ namespace VRM { public static class VRMMToonMaterialImporter { - static string[] MToonTextureSolots = new string[]{ + static string[] MToonTextureSlots = new string[]{ "_MainTex", "_ShadeTexture", "_BumpMap", @@ -74,7 +74,7 @@ namespace VRM foreach (var kv in vrmMaterial.vectorProperties) { // vector4 exclude TextureOffsetScale - if (MToonTextureSolots.Contains(kv.Key)) + if (MToonTextureSlots.Contains(kv.Key)) { continue; }