mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-07-08 21:24:12 -05:00
WIP
This commit is contained in:
parent
77162748c5
commit
d5934e97d9
|
|
@ -17,15 +17,17 @@ namespace UniVRM10
|
|||
{
|
||||
public GltfData Data { get; }
|
||||
public UniGLTF.Extensions.VRMC_vrm.VRMC_vrm VrmExtension { get; }
|
||||
public readonly Migration.Vrm0Meta OldMeta;
|
||||
public readonly Vrm10FileType FileType;
|
||||
public readonly String Message;
|
||||
|
||||
public Vrm10Data(GltfData data, VRMC_vrm vrm, Vrm10FileType fileType, string message)
|
||||
public Vrm10Data(GltfData data, VRMC_vrm vrm, Vrm10FileType fileType, string message, Migration.Vrm0Meta oldMeta = null)
|
||||
{
|
||||
Data = data;
|
||||
VrmExtension = vrm;
|
||||
FileType = fileType;
|
||||
Message = message;
|
||||
OldMeta = oldMeta;
|
||||
}
|
||||
|
||||
public static bool TryParseOrMigrate(string path, bool doMigrate, out Vrm10Data result)
|
||||
|
|
@ -56,6 +58,7 @@ namespace UniVRM10
|
|||
|
||||
// try migrateion
|
||||
byte[] migrated = default;
|
||||
Migration.Vrm0Meta oldMeta = default;
|
||||
try
|
||||
{
|
||||
var glb = UniGLTF.Glb.Parse(bytes);
|
||||
|
|
@ -92,6 +95,8 @@ namespace UniVRM10
|
|||
result = new Vrm10Data(default, default, Vrm10FileType.Vrm0, "vrm0: cannot migrate");
|
||||
return false;
|
||||
}
|
||||
|
||||
oldMeta = Migration.Vrm0Meta.FromJsonBytes(json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -104,7 +109,11 @@ namespace UniVRM10
|
|||
if (UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(data.GLTF.extensions, out VRMC_vrm vrm))
|
||||
{
|
||||
// success
|
||||
result = new Vrm10Data(data, vrm, Vrm10FileType.Vrm0, "vrm0: migrated");
|
||||
if (oldMeta == null)
|
||||
{
|
||||
throw new NullReferenceException("oldMeta");
|
||||
}
|
||||
result = new Vrm10Data(data, vrm, Vrm10FileType.Vrm0, "vrm0: migrated", oldMeta);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
109
Assets/VRM10/Runtime/Migration/Vrm10Meta.cs
Normal file
109
Assets/VRM10/Runtime/Migration/Vrm10Meta.cs
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
using System;
|
||||
using UniJSON;
|
||||
|
||||
namespace UniVRM10.Migration
|
||||
{
|
||||
public enum AllowedUser
|
||||
{
|
||||
OnlyAuthor,
|
||||
ExplicitlyLicensedPerson,
|
||||
Everyone,
|
||||
}
|
||||
|
||||
public enum LicenseType
|
||||
{
|
||||
Redistribution_Prohibited,
|
||||
CC0,
|
||||
CC_BY,
|
||||
CC_BY_NC,
|
||||
CC_BY_SA,
|
||||
CC_BY_NC_SA,
|
||||
CC_BY_ND,
|
||||
CC_BY_NC_ND,
|
||||
Other
|
||||
}
|
||||
|
||||
public enum UssageLicense
|
||||
{
|
||||
Disallow,
|
||||
Allow,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// VRM0.X version meta. This class has meta before migrate.
|
||||
/// </summary>
|
||||
public class Vrm0Meta
|
||||
{
|
||||
public string title;
|
||||
public string version;
|
||||
public string author;
|
||||
public string contactInformation;
|
||||
public string reference;
|
||||
public int texture = -1;
|
||||
public AllowedUser allowedUser = AllowedUser.OnlyAuthor;
|
||||
public bool violentUsage = false;
|
||||
public bool sexualUsage = false;
|
||||
public bool commercialUsage = false;
|
||||
public string otherPermissionUrl;
|
||||
public LicenseType licenseType = LicenseType.Redistribution_Prohibited;
|
||||
public string otherLicenseUrl;
|
||||
|
||||
public static Vrm0Meta FromJsonBytes(UniJSON.JsonNode glTF)
|
||||
{
|
||||
var oldMeta = new Vrm0Meta();
|
||||
var extensions = glTF["extensions"];
|
||||
var vrm = extensions["VRM"];
|
||||
var meta = vrm["meta"];
|
||||
foreach (var kv in meta.ObjectItems())
|
||||
{
|
||||
var key = kv.Key.GetString();
|
||||
switch (key)
|
||||
{
|
||||
case "title":
|
||||
oldMeta.title = kv.Value.GetString();
|
||||
break;
|
||||
case "version":
|
||||
oldMeta.version = kv.Value.GetString();
|
||||
break;
|
||||
case "author":
|
||||
oldMeta.author = kv.Value.GetString();
|
||||
break;
|
||||
case "contactInformation":
|
||||
oldMeta.contactInformation = kv.Value.GetString();
|
||||
break;
|
||||
case "reference":
|
||||
oldMeta.reference = kv.Value.GetString();
|
||||
break;
|
||||
case "texture":
|
||||
oldMeta.texture = kv.Value.GetInt32();
|
||||
break;
|
||||
case "allowedUserName":
|
||||
oldMeta.allowedUser = (AllowedUser)Enum.Parse(typeof(AllowedUser), kv.Value.GetString(), true);
|
||||
break;
|
||||
case "violentUssageName":
|
||||
oldMeta.violentUsage = kv.Value.GetString() == "Allow";
|
||||
break;
|
||||
case "sexualUssageName":
|
||||
oldMeta.sexualUsage = kv.Value.GetString() == "Allow";
|
||||
break;
|
||||
case "commercialUssageName":
|
||||
oldMeta.commercialUsage = kv.Value.GetString() == "Allow";
|
||||
break;
|
||||
case "otherPermissionUrl":
|
||||
oldMeta.otherPermissionUrl = kv.Value.GetString();
|
||||
break;
|
||||
case "licenseName":
|
||||
oldMeta.licenseType = (LicenseType)Enum.Parse(typeof(LicenseType), kv.Value.GetString(), true);
|
||||
break;
|
||||
case "otherLicenseUrl":
|
||||
oldMeta.otherLicenseUrl = kv.Value.GetString();
|
||||
break;
|
||||
default:
|
||||
UnityEngine.Debug.Log($"{key}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return oldMeta;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/VRM10/Runtime/Migration/Vrm10Meta.cs.meta
Normal file
11
Assets/VRM10/Runtime/Migration/Vrm10Meta.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 57e782f0f79ef4d4abcd4f1c5438e9e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -254,5 +254,12 @@ namespace UniVRM10
|
|||
Assert.AreEqual(VALUE.y, springBone.Colliders[colliderIndex].Shape.Sphere.Offset[1]);
|
||||
Assert.AreEqual(VALUE.z, springBone.Colliders[colliderIndex].Shape.Sphere.Offset[2]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MigrateMeta()
|
||||
{
|
||||
Assert.True(Vrm10Data.TryParseOrMigrate(AliciaPath, true, out Vrm10Data vrm));
|
||||
var a = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user