diff --git a/Scripts/Editor/VRMMonoBehaviourComparator.cs b/Scripts/Editor/VRMMonoBehaviourComparator.cs index 931b1deb7..af67800f0 100644 --- a/Scripts/Editor/VRMMonoBehaviourComparator.cs +++ b/Scripts/Editor/VRMMonoBehaviourComparator.cs @@ -8,8 +8,8 @@ public static class VRMMonoBehaviourComparator public static bool AssertAreEquals(GameObject l, GameObject r) { return - AssertAreEquals(l, r, - (x, y) => x[0].Equals(y[0])) + AssertAreEquals(l, r, + (x, y) => x[0].Meta.Equals(y[0].Meta)) ; } diff --git a/Scripts/Format/Editor/VRMAssetWriter.cs b/Scripts/Format/Editor/VRMAssetWriter.cs index 9b609004a..baa795b4c 100644 --- a/Scripts/Format/Editor/VRMAssetWriter.cs +++ b/Scripts/Format/Editor/VRMAssetWriter.cs @@ -1,4 +1,5 @@ -using System; +#if false +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -210,3 +211,4 @@ namespace VRM } } } +#endif \ No newline at end of file diff --git a/Scripts/Format/Editor/VRMExporter.cs b/Scripts/Format/Editor/VRMExporter.cs index bae84eda5..ec747f886 100644 --- a/Scripts/Format/Editor/VRMExporter.cs +++ b/Scripts/Format/Editor/VRMExporter.cs @@ -147,21 +147,41 @@ namespace VRM }); } - // meta - var meta = exporter.Copy.GetComponent(); - if (meta != null) + // meta(obsolete) { - gltf.extensions.VRM.meta.author = meta.Author; - gltf.extensions.VRM.meta.contactInformation = meta.ContactInformation; - gltf.extensions.VRM.meta.title = meta.Title; - if (meta.Thumbnail != null) + var meta = exporter.Copy.GetComponent(); + if (meta != null) { - gltf.extensions.VRM.meta.texture = gltfExporter.ExportTexture(gltf, gltf.buffers.Count - 1, meta.Thumbnail); + gltf.extensions.VRM.meta.author = meta.Author; + gltf.extensions.VRM.meta.contactInformation = meta.ContactInformation; + gltf.extensions.VRM.meta.title = meta.Title; + if (meta.Thumbnail != null) + { + gltf.extensions.VRM.meta.texture = gltfExporter.ExportTexture(gltf, gltf.buffers.Count - 1, meta.Thumbnail); + } + gltf.extensions.VRM.meta.licenseType = meta.LicenseType; + gltf.extensions.VRM.meta.otherLicenseUrl = meta.OtherLicenseUrl; + gltf.extensions.VRM.meta.reference = meta.Reference; } - gltf.extensions.VRM.meta.licenseType = meta.LicenseType; - gltf.extensions.VRM.meta.otherLicenseUrl = meta.OtherLicenseUrl; - gltf.extensions.VRM.meta.reference = meta.Reference; } + // meta + { + var _meta = exporter.Copy.GetComponent(); + if (_meta != null && _meta.Meta!=null) + { + var meta = _meta.Meta; + gltf.extensions.VRM.meta.author = meta.Author; + gltf.extensions.VRM.meta.contactInformation = meta.ContactInformation; + gltf.extensions.VRM.meta.title = meta.Title; + if (meta.Thumbnail != null) + { + gltf.extensions.VRM.meta.texture = gltfExporter.ExportTexture(gltf, gltf.buffers.Count - 1, meta.Thumbnail); + } + gltf.extensions.VRM.meta.licenseType = meta.LicenseType; + gltf.extensions.VRM.meta.otherLicenseUrl = meta.OtherLicenseUrl; + gltf.extensions.VRM.meta.reference = meta.Reference; + } + } // firstPerson var firstPerson = exporter.Copy.GetComponent(); diff --git a/Scripts/Format/Editor/VRMHumanoidNormalizerMenu.cs b/Scripts/Format/Editor/VRMHumanoidNormalizerMenu.cs index f5be4099b..ad23d68c1 100644 --- a/Scripts/Format/Editor/VRMHumanoidNormalizerMenu.cs +++ b/Scripts/Format/Editor/VRMHumanoidNormalizerMenu.cs @@ -113,13 +113,22 @@ namespace VRM } { - // meta + // meta(obsolete) var src = go.GetComponent(); if (src != null) { src.CopyTo(root); } } + { + // meta + var src = go.GetComponent(); + if (src != null) + { + var dst = root.AddComponent(); + dst.Meta = src.Meta; + } + } { // firstPerson diff --git a/Scripts/Format/VRMImporter.cs b/Scripts/Format/VRMImporter.cs index b21225384..1fe7ce5f1 100644 --- a/Scripts/Format/VRMImporter.cs +++ b/Scripts/Format/VRMImporter.cs @@ -156,7 +156,8 @@ namespace VRM static void LoadMeta(VRMImporterContext context) { - var meta = context.Root.AddComponent(); + var meta = ScriptableObject.CreateInstance(); + meta.name = "Meta"; var gltfMeta = context.VRM.extensions.VRM.meta; meta.Author = gltfMeta.author; meta.ContactInformation = gltfMeta.contactInformation; @@ -172,12 +173,15 @@ namespace VRM var thumbnail = lookAt.CreateThumbnail(); thumbnail.name = "thumbnail"; meta.Thumbnail = thumbnail; - //context.Textures.Add(new TextureItem(thumbnail)); + context.Textures.Add(new TextureItem(thumbnail)); } - meta.LicenseType = gltfMeta.licenseType; meta.OtherLicenseUrl = gltfMeta.otherLicenseUrl; meta.Reference = gltfMeta.reference; + + var _meta = context.Root.AddComponent(); + _meta.Meta = meta; + context.Meta = meta; } static void LoadFirstPerson(VRMImporterContext context) diff --git a/Scripts/Format/VRMImporterContext.cs b/Scripts/Format/VRMImporterContext.cs index 5de440bb7..b0f407204 100644 --- a/Scripts/Format/VRMImporterContext.cs +++ b/Scripts/Format/VRMImporterContext.cs @@ -10,6 +10,7 @@ namespace VRM public UniHumanoid.AvatarDescription AvatarDescription; public Avatar HumanoidAvatar; public BlendShapeAvatar BlendShapeAvatar; + public VRMMetaObject Meta; public glTF_VRM VRM { @@ -37,6 +38,8 @@ namespace VRM yield return x; } } + + yield return Meta; } #endif } diff --git a/Scripts/Meta/VRMMeta.cs b/Scripts/Meta/VRMMeta.cs new file mode 100644 index 000000000..9f090dac4 --- /dev/null +++ b/Scripts/Meta/VRMMeta.cs @@ -0,0 +1,11 @@ +using UnityEngine; + + +namespace VRM +{ + public class VRMMeta : MonoBehaviour + { + [SerializeField] + public VRMMetaObject Meta; + } +} diff --git a/Scripts/Meta/VRMMeta.cs.meta b/Scripts/Meta/VRMMeta.cs.meta new file mode 100644 index 000000000..0b7d246ea --- /dev/null +++ b/Scripts/Meta/VRMMeta.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 690ea0146224b8b4694a1925dddeb352 +timeCreated: 1522391118 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Meta/VRMMetaInformation.cs b/Scripts/Meta/VRMMetaInformation.cs index b0f634947..e6edd6281 100644 --- a/Scripts/Meta/VRMMetaInformation.cs +++ b/Scripts/Meta/VRMMetaInformation.cs @@ -6,6 +6,7 @@ using UniGLTF; namespace VRM { + [Obsolete] [Serializable] [DisallowMultipleComponent] public class VRMMetaInformation : MonoBehaviour, IEquatable diff --git a/Scripts/Meta/VRMMetaObject.cs b/Scripts/Meta/VRMMetaObject.cs new file mode 100644 index 000000000..4c16fdb1f --- /dev/null +++ b/Scripts/Meta/VRMMetaObject.cs @@ -0,0 +1,44 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +namespace VRM +{ + public class VRMMetaObject : ScriptableObject + { + #region Info + [SerializeField, Header("Information")] + public string Title; + + [SerializeField] + public string Author; + + [SerializeField] + public string ContactInformation; + + [SerializeField] + public Texture2D Thumbnail; + + [SerializeField] + public string Reference; + #endregion + + #region License + [SerializeField, Header("License")] + public LicenseType LicenseType; + + [SerializeField] + public string OtherLicenseUrl; + #endregion + + public bool Equals(VRMMetaObject other) + { + return + Author == other.Author + && Title == other.Title + && UniGLTF.MonoBehaviourComparator.AssetAreEquals(Thumbnail, other.Thumbnail) + ; + } + } +} diff --git a/Scripts/Meta/VRMMetaObject.cs.meta b/Scripts/Meta/VRMMetaObject.cs.meta new file mode 100644 index 000000000..7ed6699a0 --- /dev/null +++ b/Scripts/Meta/VRMMetaObject.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 63b589176a34b344b9ccbee2b7e7114a +timeCreated: 1522391129 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: