separate MigrationVrmMeta

This commit is contained in:
ousttrue
2021-02-05 17:12:16 +09:00
parent 87a9dcb920
commit b36f23105b
4 changed files with 197 additions and 280 deletions

View File

@@ -25,283 +25,6 @@ namespace UniVRM10
return false;
}
// {
// "bone": "hips",
// "node": 14,
// "useDefaultValues": true,
// "min": {
// "x": 0,
// "y": 0,
// "z": 0
// },
// "max": {
// "x": 0,
// "y": 0,
// "z": 0
// },
// "center": {
// "x": 0,
// "y": 0,
// "z": 0
// },
// "axisLength": 0
// },
static UniGLTF.Extensions.VRMC_vrm.HumanBone MigrateHumanoidBone(JsonNode vrm0)
{
return new UniGLTF.Extensions.VRMC_vrm.HumanBone
{
Node = vrm0["node"].GetInt32(),
};
}
static UniGLTF.Extensions.VRMC_vrm.Humanoid MigrateHumanoid(JsonNode vrm0)
{
var humanoid = new UniGLTF.Extensions.VRMC_vrm.Humanoid
{
HumanBones = new UniGLTF.Extensions.VRMC_vrm.HumanBones()
};
foreach (var humanoidBone in vrm0["humanBones"].ArrayItems())
{
var boneType = humanoidBone["bone"].GetString();
switch (boneType)
{
case "hips": humanoid.HumanBones.Hips = MigrateHumanoidBone(humanoidBone); break;
case "leftUpperLeg": humanoid.HumanBones.LeftUpperLeg = MigrateHumanoidBone(humanoidBone); break;
case "rightUpperLeg": humanoid.HumanBones.RightUpperLeg = MigrateHumanoidBone(humanoidBone); break;
case "leftLowerLeg": humanoid.HumanBones.LeftLowerLeg = MigrateHumanoidBone(humanoidBone); break;
case "rightLowerLeg": humanoid.HumanBones.RightLowerLeg = MigrateHumanoidBone(humanoidBone); break;
case "leftFoot": humanoid.HumanBones.LeftFoot = MigrateHumanoidBone(humanoidBone); break;
case "rightFoot": humanoid.HumanBones.RightFoot = MigrateHumanoidBone(humanoidBone); break;
case "spine": humanoid.HumanBones.Spine = MigrateHumanoidBone(humanoidBone); break;
case "chest": humanoid.HumanBones.Chest = MigrateHumanoidBone(humanoidBone); break;
case "neck": humanoid.HumanBones.Neck = MigrateHumanoidBone(humanoidBone); break;
case "head": humanoid.HumanBones.Head = MigrateHumanoidBone(humanoidBone); break;
case "leftShoulder": humanoid.HumanBones.LeftShoulder = MigrateHumanoidBone(humanoidBone); break;
case "rightShoulder": humanoid.HumanBones.RightShoulder = MigrateHumanoidBone(humanoidBone); break;
case "leftUpperArm": humanoid.HumanBones.LeftUpperArm = MigrateHumanoidBone(humanoidBone); break;
case "rightUpperArm": humanoid.HumanBones.RightUpperArm = MigrateHumanoidBone(humanoidBone); break;
case "leftLowerArm": humanoid.HumanBones.LeftLowerArm = MigrateHumanoidBone(humanoidBone); break;
case "rightLowerArm": humanoid.HumanBones.RightLowerArm = MigrateHumanoidBone(humanoidBone); break;
case "leftHand": humanoid.HumanBones.LeftHand = MigrateHumanoidBone(humanoidBone); break;
case "rightHand": humanoid.HumanBones.RightHand = MigrateHumanoidBone(humanoidBone); break;
case "leftToes": humanoid.HumanBones.LeftToes = MigrateHumanoidBone(humanoidBone); break;
case "rightToes": humanoid.HumanBones.RightToes = MigrateHumanoidBone(humanoidBone); break;
case "leftEye": humanoid.HumanBones.LeftEye = MigrateHumanoidBone(humanoidBone); break;
case "rightEye": humanoid.HumanBones.RightEye = MigrateHumanoidBone(humanoidBone); break;
case "jaw": humanoid.HumanBones.Jaw = MigrateHumanoidBone(humanoidBone); break;
case "leftThumbProximal": humanoid.HumanBones.LeftThumbProximal = MigrateHumanoidBone(humanoidBone); break;
case "leftThumbIntermediate": humanoid.HumanBones.LeftThumbIntermediate = MigrateHumanoidBone(humanoidBone); break;
case "leftThumbDistal": humanoid.HumanBones.LeftThumbDistal = MigrateHumanoidBone(humanoidBone); break;
case "leftIndexProximal": humanoid.HumanBones.LeftIndexProximal = MigrateHumanoidBone(humanoidBone); break;
case "leftIndexIntermediate": humanoid.HumanBones.LeftIndexIntermediate = MigrateHumanoidBone(humanoidBone); break;
case "leftIndexDistal": humanoid.HumanBones.LeftIndexDistal = MigrateHumanoidBone(humanoidBone); break;
case "leftMiddleProximal": humanoid.HumanBones.LeftMiddleProximal = MigrateHumanoidBone(humanoidBone); break;
case "leftMiddleIntermediate": humanoid.HumanBones.LeftMiddleIntermediate = MigrateHumanoidBone(humanoidBone); break;
case "leftMiddleDistal": humanoid.HumanBones.LeftMiddleDistal = MigrateHumanoidBone(humanoidBone); break;
case "leftRingProximal": humanoid.HumanBones.LeftRingProximal = MigrateHumanoidBone(humanoidBone); break;
case "leftRingIntermediate": humanoid.HumanBones.LeftRingIntermediate = MigrateHumanoidBone(humanoidBone); break;
case "leftRingDistal": humanoid.HumanBones.LeftRingDistal = MigrateHumanoidBone(humanoidBone); break;
case "leftLittleProximal": humanoid.HumanBones.LeftLittleProximal = MigrateHumanoidBone(humanoidBone); break;
case "leftLittleIntermediate": humanoid.HumanBones.LeftLittleIntermediate = MigrateHumanoidBone(humanoidBone); break;
case "leftLittleDistal": humanoid.HumanBones.LeftLittleDistal = MigrateHumanoidBone(humanoidBone); break;
case "rightThumbProximal": humanoid.HumanBones.RightThumbProximal = MigrateHumanoidBone(humanoidBone); break;
case "rightThumbIntermediate": humanoid.HumanBones.RightThumbIntermediate = MigrateHumanoidBone(humanoidBone); break;
case "rightThumbDistal": humanoid.HumanBones.RightThumbDistal = MigrateHumanoidBone(humanoidBone); break;
case "rightIndexProximal": humanoid.HumanBones.RightIndexProximal = MigrateHumanoidBone(humanoidBone); break;
case "rightIndexIntermediate": humanoid.HumanBones.RightIndexIntermediate = MigrateHumanoidBone(humanoidBone); break;
case "rightIndexDistal": humanoid.HumanBones.RightIndexDistal = MigrateHumanoidBone(humanoidBone); break;
case "rightMiddleProximal": humanoid.HumanBones.RightMiddleProximal = MigrateHumanoidBone(humanoidBone); break;
case "rightMiddleIntermediate": humanoid.HumanBones.RightMiddleIntermediate = MigrateHumanoidBone(humanoidBone); break;
case "rightMiddleDistal": humanoid.HumanBones.RightMiddleDistal = MigrateHumanoidBone(humanoidBone); break;
case "rightRingProximal": humanoid.HumanBones.RightRingProximal = MigrateHumanoidBone(humanoidBone); break;
case "rightRingIntermediate": humanoid.HumanBones.RightRingIntermediate = MigrateHumanoidBone(humanoidBone); break;
case "rightRingDistal": humanoid.HumanBones.RightRingDistal = MigrateHumanoidBone(humanoidBone); break;
case "rightLittleProximal": humanoid.HumanBones.RightLittleProximal = MigrateHumanoidBone(humanoidBone); break;
case "rightLittleIntermediate": humanoid.HumanBones.RightLittleIntermediate = MigrateHumanoidBone(humanoidBone); break;
case "rightLittleDistal": humanoid.HumanBones.RightLittleDistal = MigrateHumanoidBone(humanoidBone); break;
case "upperChest": humanoid.HumanBones.UpperChest = MigrateHumanoidBone(humanoidBone); break;
default: throw new NotImplementedException($"unknown bone: {boneType}");
}
}
return humanoid;
}
///
/// 互換性の無いところ
///
/// * きつくなる方向は許す
/// * 緩くなる方向は不許可(throw)
///
// "meta": {
// "title": "Alicia Solid",
// "version": "1.10",
// "author": "© DWANGO Co., Ltd.",
// "contactInformation": "https://3d.nicovideo.jp/alicia/",
// "reference": "",
// "texture": 7,
// "allowedUserName": "Everyone",
// "violentUssageName": "Disallow",
// "sexualUssageName": "Disallow",
// "commercialUssageName": "Allow",
// "otherPermissionUrl": "https://3d.nicovideo.jp/alicia/rule.html",
// "licenseName": "Other",
// "otherLicenseUrl": "https://3d.nicovideo.jp/alicia/rule.html"
// },
static UniGLTF.Extensions.VRMC_vrm.Meta MigrateMeta(JsonNode vrm0)
{
var meta = new UniGLTF.Extensions.VRMC_vrm.Meta
{
AllowPoliticalOrReligiousUsage = false,
AllowExcessivelySexualUsage = false,
AllowExcessivelyViolentUsage = false,
AllowRedistribution = false,
AvatarPermission = UniGLTF.Extensions.VRMC_vrm.AvatarPermissionType.onlyAuthor,
CommercialUsage = UniGLTF.Extensions.VRMC_vrm.CommercialUsageType.personalNonProfit,
CreditNotation = UniGLTF.Extensions.VRMC_vrm.CreditNotationType.required,
Modification = UniGLTF.Extensions.VRMC_vrm.ModificationType.prohibited,
};
foreach (var kv in vrm0.ObjectItems())
{
var key = kv.Key.GetString();
switch (key)
{
case "title": meta.Name = kv.Value.GetString(); break;
case "version": meta.Version = kv.Value.GetString(); break;
case "author": meta.Authors = new List<string>() { kv.Value.GetString() }; break;
case "contactInformation": meta.ContactInformation = kv.Value.GetString(); break;
case "reference": meta.References = new List<string>() { kv.Value.GetString() }; break;
case "texture": meta.ThumbnailImage = kv.Value.GetInt32(); break;
case "allowedUserName":
{
var allowedUserName = kv.Value.GetString();
switch (allowedUserName)
{
case "OnlyAuthor":
meta.AvatarPermission = UniGLTF.Extensions.VRMC_vrm.AvatarPermissionType.onlyAuthor;
break;
case "ExplicitlyLicensedPerson":
meta.AvatarPermission = UniGLTF.Extensions.VRMC_vrm.AvatarPermissionType.explicitlyLicensedPerson;
break;
case "Everyone":
meta.AvatarPermission = UniGLTF.Extensions.VRMC_vrm.AvatarPermissionType.everyone;
break;
default:
throw new NotImplementedException($"{key}: {allowedUserName}");
}
}
break;
case "violentUssageName": // Typo "Ussage" is VRM 0.x spec.
{
var violentUsageName = kv.Value.GetString();
switch (violentUsageName)
{
case "Allow":
meta.AllowExcessivelyViolentUsage = true;
break;
case "Disallow":
meta.AllowExcessivelyViolentUsage = false;
break;
default:
throw new NotImplementedException($"{key}: {violentUsageName}");
}
}
break;
case "sexualUssageName": // Typo "Ussage" is VRM 0.x spec.
{
var sexualUsageName = kv.Value.GetString();
switch (sexualUsageName)
{
case "Allow":
meta.AllowExcessivelySexualUsage = true;
break;
case "Disallow":
meta.AllowExcessivelySexualUsage = false;
break;
default:
throw new NotImplementedException($"{key}: {sexualUsageName}");
}
}
break;
case "commercialUssageName": // Typo "Ussage" is VRM 0.x spec.
{
var commercialUsageName = kv.Value.GetString();
switch (commercialUsageName)
{
case "Allow":
meta.CommercialUsage = UniGLTF.Extensions.VRMC_vrm.CommercialUsageType.personalProfit;
break;
case "Disallow":
meta.CommercialUsage = UniGLTF.Extensions.VRMC_vrm.CommercialUsageType.personalNonProfit;
break;
default:
throw new NotImplementedException($"{key}: {commercialUsageName}");
}
}
break;
case "otherPermissionUrl":
{
// TODO
// var url = kv.Value.GetString();
// if (!String.IsNullOrWhiteSpace(url))
// {
// throw new NotImplementedException("otherPermissionUrl not allowd");
// }
}
break;
case "otherLicenseUrl": meta.OtherLicenseUrl = kv.Value.GetString(); break;
case "licenseName":
{
// TODO
// CreditNotation = CreditNotationType.required,
}
break;
default:
throw new NotImplementedException(key);
}
}
return meta;
}
public static string GetLicenseUrl(JsonNode vrm0)
{
string l0 = default;
string l1 = default;
foreach (var kv in vrm0.ObjectItems())
{
switch (kv.Key.GetString())
{
case "otherLicenseUrl":
l0 = kv.Value.GetString();
break;
case "otherPermissionUrl":
l1 = kv.Value.GetString();
break;
}
}
if (!string.IsNullOrWhiteSpace(l0))
{
return l0;
}
if (!string.IsNullOrWhiteSpace(l1))
{
return l1;
}
return "";
}
static float[] ReverseZ(JsonNode xyz)
{
return new float[]{
@@ -626,7 +349,7 @@ namespace UniVRM10
{
// vrm
var vrm1 = new UniGLTF.Extensions.VRMC_vrm.VRMC_vrm();
vrm1.Meta = MigrateMeta(vrm0["meta"]);
vrm1.Meta = MigrationVrmMeta.Migrate(vrm0["meta"]);
vrm1.Humanoid = MigrationVrmHumanoid.Migrate(vrm0["humanoid"]);
vrm1.Expressions = MigrateExpression(gltf, vrm0["blendShapeMaster"]).ToList();
@@ -792,7 +515,7 @@ namespace UniVRM10
}
}
if (GetLicenseUrl(vrm0) != vrm1.OtherLicenseUrl) throw new MigrationException("meta.otherLicenseUrl", vrm1.OtherLicenseUrl);
if (MigrationVrmMeta.GetLicenseUrl(vrm0) != vrm1.OtherLicenseUrl) throw new MigrationException("meta.otherLicenseUrl", vrm1.OtherLicenseUrl);
switch (vrm0["licenseName"].GetString())
{

View File

@@ -139,7 +139,7 @@ namespace UniVRM10
}
}
if (Migration.GetLicenseUrl(vrm0) != vrm1.OtherLicenseUrl) throw new MigrationException("meta.otherLicenseUrl", vrm1.OtherLicenseUrl);
if (MigrationVrmMeta.GetLicenseUrl(vrm0) != vrm1.OtherLicenseUrl) throw new MigrationException("meta.otherLicenseUrl", vrm1.OtherLicenseUrl);
switch (vrm0["licenseName"].GetString())
{

View File

@@ -0,0 +1,183 @@
using System;
using System.Collections.Generic;
using UniJSON;
namespace UniVRM10
{
///
/// 互換性の無いところ
///
/// * きつくなる方向は許す
/// * 緩くなる方向は不許可(throw)
///
// "meta": {
// "title": "Alicia Solid",
// "version": "1.10",
// "author": "© DWANGO Co., Ltd.",
// "contactInformation": "https://3d.nicovideo.jp/alicia/",
// "reference": "",
// "texture": 7,
// "allowedUserName": "Everyone",
// "violentUssageName": "Disallow",
// "sexualUssageName": "Disallow",
// "commercialUssageName": "Allow",
// "otherPermissionUrl": "https://3d.nicovideo.jp/alicia/rule.html",
// "licenseName": "Other",
// "otherLicenseUrl": "https://3d.nicovideo.jp/alicia/rule.html"
// },
public static class MigrationVrmMeta
{
public static UniGLTF.Extensions.VRMC_vrm.Meta Migrate(JsonNode vrm0)
{
var meta = new UniGLTF.Extensions.VRMC_vrm.Meta
{
AllowPoliticalOrReligiousUsage = false,
AllowExcessivelySexualUsage = false,
AllowExcessivelyViolentUsage = false,
AllowRedistribution = false,
AvatarPermission = UniGLTF.Extensions.VRMC_vrm.AvatarPermissionType.onlyAuthor,
CommercialUsage = UniGLTF.Extensions.VRMC_vrm.CommercialUsageType.personalNonProfit,
CreditNotation = UniGLTF.Extensions.VRMC_vrm.CreditNotationType.required,
Modification = UniGLTF.Extensions.VRMC_vrm.ModificationType.prohibited,
};
foreach (var kv in vrm0.ObjectItems())
{
var key = kv.Key.GetString();
switch (key)
{
case "title": meta.Name = kv.Value.GetString(); break;
case "version": meta.Version = kv.Value.GetString(); break;
case "author": meta.Authors = new List<string>() { kv.Value.GetString() }; break;
case "contactInformation": meta.ContactInformation = kv.Value.GetString(); break;
case "reference": meta.References = new List<string>() { kv.Value.GetString() }; break;
case "texture": meta.ThumbnailImage = kv.Value.GetInt32(); break;
case "allowedUserName":
{
var allowedUserName = kv.Value.GetString();
switch (allowedUserName)
{
case "OnlyAuthor":
meta.AvatarPermission = UniGLTF.Extensions.VRMC_vrm.AvatarPermissionType.onlyAuthor;
break;
case "ExplicitlyLicensedPerson":
meta.AvatarPermission = UniGLTF.Extensions.VRMC_vrm.AvatarPermissionType.explicitlyLicensedPerson;
break;
case "Everyone":
meta.AvatarPermission = UniGLTF.Extensions.VRMC_vrm.AvatarPermissionType.everyone;
break;
default:
throw new NotImplementedException($"{key}: {allowedUserName}");
}
}
break;
case "violentUssageName": // Typo "Ussage" is VRM 0.x spec.
{
var violentUsageName = kv.Value.GetString();
switch (violentUsageName)
{
case "Allow":
meta.AllowExcessivelyViolentUsage = true;
break;
case "Disallow":
meta.AllowExcessivelyViolentUsage = false;
break;
default:
throw new NotImplementedException($"{key}: {violentUsageName}");
}
}
break;
case "sexualUssageName": // Typo "Ussage" is VRM 0.x spec.
{
var sexualUsageName = kv.Value.GetString();
switch (sexualUsageName)
{
case "Allow":
meta.AllowExcessivelySexualUsage = true;
break;
case "Disallow":
meta.AllowExcessivelySexualUsage = false;
break;
default:
throw new NotImplementedException($"{key}: {sexualUsageName}");
}
}
break;
case "commercialUssageName": // Typo "Ussage" is VRM 0.x spec.
{
var commercialUsageName = kv.Value.GetString();
switch (commercialUsageName)
{
case "Allow":
meta.CommercialUsage = UniGLTF.Extensions.VRMC_vrm.CommercialUsageType.personalProfit;
break;
case "Disallow":
meta.CommercialUsage = UniGLTF.Extensions.VRMC_vrm.CommercialUsageType.personalNonProfit;
break;
default:
throw new NotImplementedException($"{key}: {commercialUsageName}");
}
}
break;
case "otherPermissionUrl":
{
// TODO
// var url = kv.Value.GetString();
// if (!String.IsNullOrWhiteSpace(url))
// {
// throw new NotImplementedException("otherPermissionUrl not allowd");
// }
}
break;
case "otherLicenseUrl": meta.OtherLicenseUrl = kv.Value.GetString(); break;
case "licenseName":
{
// TODO
// CreditNotation = CreditNotationType.required,
}
break;
default:
throw new NotImplementedException(key);
}
}
return meta;
}
public static string GetLicenseUrl(JsonNode vrm0)
{
string l0 = default;
string l1 = default;
foreach (var kv in vrm0.ObjectItems())
{
switch (kv.Key.GetString())
{
case "otherLicenseUrl":
l0 = kv.Value.GetString();
break;
case "otherPermissionUrl":
l1 = kv.Value.GetString();
break;
}
}
if (!string.IsNullOrWhiteSpace(l0))
{
return l0;
}
if (!string.IsNullOrWhiteSpace(l1))
{
return l1;
}
return "";
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bb019cd042148c2428f4e48b9391c448
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: