From 65034934385a3f40907e9d5377d3135092fbcb69 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Fri, 4 Nov 2022 23:39:57 +0900 Subject: [PATCH] Migrate materials when importing a VRM 0.x model. --- .../Runtime/UniGLTF/IO/MigrationFlags.cs | 2 +- .../VRM/Runtime/Format/VRMVersionPartial.cs | 7 ++++- Assets/VRM/Runtime/IO/VRMData.cs | 28 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MigrationFlags.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MigrationFlags.cs index 0da201b7d..fffb08419 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MigrationFlags.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MigrationFlags.cs @@ -8,7 +8,7 @@ public bool IsRoughnessTextureValueSquared { get; set; } = false; /// - /// Built-in RP Standard shader's emission color is exported in gamma color space until UniGLTF v0.106.0. + /// Before UniGLTF v0.107.0, Built-in RP Standard shader's emission color is exported in gamma color space. /// public bool IsEmissiveFactorGamma { get; set; } = false; } diff --git a/Assets/VRM/Runtime/Format/VRMVersionPartial.cs b/Assets/VRM/Runtime/Format/VRMVersionPartial.cs index 2fe04e6da..4a739ac0b 100644 --- a/Assets/VRM/Runtime/Format/VRMVersionPartial.cs +++ b/Assets/VRM/Runtime/Format/VRMVersionPartial.cs @@ -40,6 +40,11 @@ namespace VRM return false; } + return IsNewer(newerVersion, olderVersion); + } + + public static bool IsNewer(Version newerVersion, Version olderVersion) + { if (newerVersion.Major > olderVersion.Major) { return true; @@ -55,7 +60,7 @@ namespace VRM return true; } - if (String.Compare(newerVersion.Pre, olderVersion.Pre) > 0) + if (string.CompareOrdinal(newerVersion.Pre, olderVersion.Pre) > 0) { return true; } diff --git a/Assets/VRM/Runtime/IO/VRMData.cs b/Assets/VRM/Runtime/IO/VRMData.cs index 84e85eb82..debd8c826 100644 --- a/Assets/VRM/Runtime/IO/VRMData.cs +++ b/Assets/VRM/Runtime/IO/VRMData.cs @@ -16,6 +16,34 @@ namespace VRM throw new NotVrm0Exception(); } VrmExtension = vrm; + + UpdateMigrationFlags(Data.MigrationFlags, VrmExtension.exporterVersion); + } + + private static void UpdateMigrationFlags(MigrationFlags migrationFlags, string exportedVrmVersionString) + { + if (!VRMVersion.ParseVersion(exportedVrmVersionString, out var exportedVrmVersion)) return; + + migrationFlags.IsRoughnessTextureValueSquared = VRMVersion.IsNewer( + new VRMVersion.Version + { + Major = 0, + Minor = 69, + Patch = 0, + Pre = "", + }, + exportedVrmVersion + ); + migrationFlags.IsEmissiveFactorGamma = VRMVersion.IsNewer( + new VRMVersion.Version + { + Major = 0, + Minor = 107, + Patch = 0, + Pre = "", + }, + exportedVrmVersion + ); } } }