Migrate materials when importing a VRM 0.x model.

This commit is contained in:
Masataka SUMI
2022-11-04 23:39:57 +09:00
parent 8521e98817
commit 6503493438
3 changed files with 35 additions and 2 deletions

View File

@@ -8,7 +8,7 @@
public bool IsRoughnessTextureValueSquared { get; set; } = false;
/// <summary>
/// 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.
/// </summary>
public bool IsEmissiveFactorGamma { get; set; } = false;
}

View File

@@ -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;
}

View File

@@ -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
);
}
}
}