From c6dcbc9cf4b2b1d942431b8ee730b11822292ab0 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 20 Oct 2022 13:59:29 +0900 Subject: [PATCH 1/5] add MigrateExporter --- Assets/VRM/Runtime/IO/VRMExporter.cs | 7 +- Assets/VRM10/Runtime/IO/Vrm10Exporter.cs | 2 +- .../VRM10/Runtime/Migration/MigrationApi.cs | 20 ++ .../Runtime/Migration/MigrationApi.cs.meta | 11 + .../VRM10/Runtime/Migration/MigrationVrm.cs | 33 ++- Assets/VRM_BOTH_Samples.meta | 8 + Assets/VRM_BOTH_Samples/MigrateExporter.meta | 8 + .../MigrateExporter/MigrateExporter.cs | 56 ++++ .../MigrateExporter/MigrateExporter.cs.meta | 11 + .../MigrateExporter/MigrateExporter.unity | 271 ++++++++++++++++++ .../MigrateExporter.unity.meta | 7 + .../MigrateExporter/README.md | 24 ++ .../MigrateExporter/README.md.meta | 7 + 13 files changed, 456 insertions(+), 9 deletions(-) create mode 100644 Assets/VRM10/Runtime/Migration/MigrationApi.cs create mode 100644 Assets/VRM10/Runtime/Migration/MigrationApi.cs.meta create mode 100644 Assets/VRM_BOTH_Samples.meta create mode 100644 Assets/VRM_BOTH_Samples/MigrateExporter.meta create mode 100644 Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.cs create mode 100644 Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.cs.meta create mode 100644 Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.unity create mode 100644 Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.unity.meta create mode 100644 Assets/VRM_BOTH_Samples/MigrateExporter/README.md create mode 100644 Assets/VRM_BOTH_Samples/MigrateExporter/README.md.meta diff --git a/Assets/VRM/Runtime/IO/VRMExporter.cs b/Assets/VRM/Runtime/IO/VRMExporter.cs index 907b1aad9..edcdde0ef 100644 --- a/Assets/VRM/Runtime/IO/VRMExporter.cs +++ b/Assets/VRM/Runtime/IO/VRMExporter.cs @@ -28,10 +28,15 @@ namespace VRM public VRMExporter(ExportingGltfData data, GltfExportSettings exportSettings, IAnimationExporter animationExporter = null) : base( data, exportSettings, animationExporter: animationExporter) { - if (exportSettings == null || exportSettings.InverseAxis != Vrm0xSpecificationInverseAxis) + if (exportSettings == null) { throw new Exception($"VRM specification requires InverseAxis settings as {Vrm0xSpecificationInverseAxis}"); } + if (exportSettings.InverseAxis != Vrm0xSpecificationInverseAxis) + { + // migration 用に reverseX を許す + Debug.LogWarning($"VRM specification requires InverseAxis settings as {Vrm0xSpecificationInverseAxis}"); + } _gltf.extensionsUsed.Add(glTF_VRM_extensions.ExtensionName); } diff --git a/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs b/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs index e93cbcbf1..270966a4a 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs @@ -672,7 +672,7 @@ namespace UniVRM10 }; } - static int? ExportMeta(UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm, VRM10ObjectMeta meta, ITextureExporter textureExporter) + public static int? ExportMeta(UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm, VRM10ObjectMeta meta, ITextureExporter textureExporter) { vrm.Meta.Name = meta.Name; vrm.Meta.Version = meta.Version; diff --git a/Assets/VRM10/Runtime/Migration/MigrationApi.cs b/Assets/VRM10/Runtime/Migration/MigrationApi.cs new file mode 100644 index 000000000..170e9a377 --- /dev/null +++ b/Assets/VRM10/Runtime/Migration/MigrationApi.cs @@ -0,0 +1,20 @@ +using System; + +namespace UniVRM10 +{ + public static class MigrationApi + { + /// + /// マイグレーションの公開API + /// + /// MigrationVrm とその関連実装は、internal で runtime import 専用 + /// + /// + /// + /// + public static byte[] Migrate(byte[] vrm0bytes, VRM10ObjectMeta meta) + { + return MigrationVrm.Migrate(vrm0bytes, meta); + } + } +} \ No newline at end of file diff --git a/Assets/VRM10/Runtime/Migration/MigrationApi.cs.meta b/Assets/VRM10/Runtime/Migration/MigrationApi.cs.meta new file mode 100644 index 000000000..96948be1d --- /dev/null +++ b/Assets/VRM10/Runtime/Migration/MigrationApi.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: be52b15d95590934b93e744181762dfe +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/Migration/MigrationVrm.cs b/Assets/VRM10/Runtime/Migration/MigrationVrm.cs index b4bc5e288..2b69bc2d0 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationVrm.cs +++ b/Assets/VRM10/Runtime/Migration/MigrationVrm.cs @@ -15,11 +15,11 @@ namespace UniVRM10 /// static internal class MigrationVrm { - public static byte[] Migrate(byte[] src) + public static byte[] Migrate(byte[] src, VRM10ObjectMeta meta = null) { using (var data = new GlbBinaryParser(src, "migration").Parse()) { - return Migrate(data); + return Migrate(data, meta); } } @@ -35,7 +35,10 @@ namespace UniVRM10 return (min, max); } - public static byte[] Migrate(GltfData data) + /// vrm0 をパースしたデータ + /// migration 時に合成するライセンス情報 + /// + public static byte[] Migrate(GltfData data, VRM10ObjectMeta meta = null) { // VRM0 -> Unity var model = ModelReader.Read(data, VrmLib.Coordinates.Vrm0); @@ -51,7 +54,7 @@ namespace UniVRM10 gltf.extensionsUsed.Remove("VRM"); } - return MigrateVrm(gltf, bin, data.Json.ParseAsJson()["extensions"]["VRM"]); + return MigrateVrm(gltf, bin, data.Json.ParseAsJson()["extensions"]["VRM"], meta); } /// @@ -68,7 +71,7 @@ namespace UniVRM10 } } - static byte[] MigrateVrm(glTF gltf, ArraySegment bin, JsonNode vrm0) + static byte[] MigrateVrm(glTF gltf, ArraySegment bin, JsonNode vrm0, VRM10ObjectMeta meta) { var meshToNode = CreateMeshToNode(gltf); @@ -80,8 +83,24 @@ namespace UniVRM10 }; gltf.extensionsUsed.Add(UniGLTF.Extensions.VRMC_vrm.VRMC_vrm.ExtensionName); - // meta (required) - vrm1.Meta = MigrationVrmMeta.Migrate(gltf, vrm0["meta"]); + if (meta == null) + { + // migrate from vrm-0.x + vrm1.Meta = MigrationVrmMeta.Migrate(gltf, vrm0["meta"]); + } + else + { + // inject from arg + vrm1.Meta = new UniGLTF.Extensions.VRMC_vrm.Meta + { + LicenseUrl = Vrm10Exporter.LICENSE_URL_JA, + AllowExcessivelySexualUsage = false, + AllowExcessivelyViolentUsage = false, + AllowPoliticalOrReligiousUsage = false, + AllowRedistribution = false, + }; + Vrm10Exporter.ExportMeta(vrm1, meta, null); + } // humanoid (required) vrm1.Humanoid = MigrationVrmHumanoid.Migrate(vrm0["humanoid"]); diff --git a/Assets/VRM_BOTH_Samples.meta b/Assets/VRM_BOTH_Samples.meta new file mode 100644 index 000000000..e49c92f00 --- /dev/null +++ b/Assets/VRM_BOTH_Samples.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c99f52afa0263124e87a9016b287a244 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter.meta b/Assets/VRM_BOTH_Samples/MigrateExporter.meta new file mode 100644 index 000000000..d58306d74 --- /dev/null +++ b/Assets/VRM_BOTH_Samples/MigrateExporter.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 158a2cd31973b9a4faba49afbbb8bbc6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.cs b/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.cs new file mode 100644 index 000000000..d381f9d0d --- /dev/null +++ b/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.cs @@ -0,0 +1,56 @@ +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using UnityEngine; + +[DisallowMultipleComponent] +public class MigrateExporter : MonoBehaviour +{ + [SerializeField] + UniVRM10.VRM10ObjectMeta _meta = new UniVRM10.VRM10ObjectMeta(); + + async void OnGUI() + { + // validate + foreach (var validation in _meta.Validate(null)) + { + GUILayout.Label("meta validation: " + validation.Message); + if (!validation.CanExport) + { + GUI.enabled = false; + } + } + + if (GUILayout.Button("migrate")) + { + var path = UnityEditor.EditorUtility.OpenFilePanel("load vrm-0.x", null, "vrm"); + if (string.IsNullOrEmpty(path)) + { + return; + } + + Debug.Log(path); + var bytes = File.ReadAllBytes(path); + + // load + var vrm0Instance = await VRM.VrmUtility.LoadBytesAsync(path, bytes); + + // export設定 + var exportConfig = new UniGLTF.GltfExportSettings + { + }; + // export vrm0 + var vrm0 = VRM.VRMExporter.Export(exportConfig, + vrm0Instance.gameObject, new VRMShaders.RuntimeTextureSerializer()); + var vrm0bytes = vrm0.ToGlbBytes(); + + // migrate to vrm1 + var vrm1Bytes = UniVRM10.MigrationApi.Migrate(vrm0bytes, _meta); + var pathObj = VRMShaders.PathObject.FromFullPath(path); + var newPath = pathObj.Parent.Child(pathObj.Stem + ".10.vrm"); + newPath.WriteAllBytes(vrm1Bytes); + Debug.Log($"export to: {newPath}"); + } + } +} diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.cs.meta b/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.cs.meta new file mode 100644 index 000000000..727096df7 --- /dev/null +++ b/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 057dcb5c6b50f574795f903ac5989b8d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.unity b/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.unity new file mode 100644 index 000000000..56fa2bc1e --- /dev/null +++ b/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.unity @@ -0,0 +1,271 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +OcclusionCullingSettings: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 9 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 0 + m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} + m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0.12731749, g: 0.13414757, b: 0.1210787, a: 1} + m_UseRadianceAmbientProbe: 0 +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 12 + m_GIWorkflowMode: 1 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 0 + m_LightmapEditorSettings: + serializedVersion: 12 + m_Resolution: 2 + m_BakeResolution: 40 + m_AtlasSize: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_ExtractAmbientOcclusion: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_FinalGather: 0 + m_FinalGatherFiltering: 1 + m_FinalGatherRayCount: 256 + m_ReflectionCompression: 2 + m_MixedBakeMode: 2 + m_BakeBackend: 1 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 512 + m_PVRBounces: 2 + m_PVREnvironmentSampleCount: 256 + m_PVREnvironmentReferencePointCount: 2048 + m_PVRFilteringMode: 1 + m_PVRDenoiserTypeDirect: 1 + m_PVRDenoiserTypeIndirect: 1 + m_PVRDenoiserTypeAO: 1 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVREnvironmentMIS: 1 + m_PVRCulling: 1 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 + m_ExportTrainingData: 0 + m_TrainingDataDestination: TrainingData + m_LightProbeSampleCountMultiplier: 4 + m_LightingDataAsset: {fileID: 0} + m_LightingSettings: {fileID: 0} +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 2 + agentTypeID: 0 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + minRegionArea: 2 + manualCellSize: 0 + cellSize: 0.16666667 + manualTileSize: 0 + tileSize: 256 + accuratePlacement: 0 + maxJobWorkers: 0 + preserveTilesOutsideBounds: 0 + debug: + m_Flags: 0 + m_NavMeshData: {fileID: 0} +--- !u!1 &540916040 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 540916043} + - component: {fileID: 540916042} + - component: {fileID: 540916041} + m_Layer: 0 + m_Name: Camera + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &540916041 +AudioListener: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 540916040} + m_Enabled: 1 +--- !u!20 &540916042 +Camera: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 540916040} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_projectionMatrixMode: 1 + m_GateFitMode: 2 + m_FOVAxisMode: 0 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} + m_FocalLength: 50 + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!4 &540916043 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 540916040} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 4.9861307, y: -1.2857006, z: -12.386837} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &2054562369 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2054562371} + - component: {fileID: 2054562370} + m_Layer: 0 + m_Name: MigrateExporter + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &2054562370 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2054562369} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 057dcb5c6b50f574795f903ac5989b8d, type: 3} + m_Name: + m_EditorClassIdentifier: + _meta: + Name: MigrateExporter + Version: + Authors: + - MigrateExporterAuthor0 + CopyrightInformation: + ContactInformation: + References: [] + ThirdPartyLicenses: + Thumbnail: {fileID: 0} + AvatarPermission: 0 + ViolentUsage: 0 + SexualUsage: 0 + CommercialUsage: 0 + PoliticalOrReligiousUsage: 0 + AntisocialOrHateUsage: 0 + CreditNotation: 0 + Redistribution: 0 + Modification: 0 + OtherLicenseUrl: +--- !u!4 &2054562371 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2054562369} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.unity.meta b/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.unity.meta new file mode 100644 index 000000000..2a586fcdc --- /dev/null +++ b/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.unity.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5c0c00c31e7afc64bbdfaf0286ac1f5d +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter/README.md b/Assets/VRM_BOTH_Samples/MigrateExporter/README.md new file mode 100644 index 000000000..ca0648b31 --- /dev/null +++ b/Assets/VRM_BOTH_Samples/MigrateExporter/README.md @@ -0,0 +1,24 @@ +# Migration + +- for runtime +- Convert export vrm0 model directly to vrm1 +- input: vrm0 hierarchy + vrm1 meta +- output: vrm1 binary + +## detail + +最初に vrm0 モデルをエクスポートします。 +このとき後で vrm1 化する前提で通常とは別の設定にします。 + +- 正規化しない +- z+ もしくは 左手系のまま進める +- divided vertex buffer(glb 向けに実装済み) + +得られた、vrm0 バイナリを migrate します。 +このとき、vrm1 の meta を外部から注入することで +ユーザー入力無しでの migration で `完全な` vrm1 を出力します。 + +結果に対して vrm1 バリデーション。 + +- https://github.com/vrm-c/glTF-Validator/pull/1 + diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter/README.md.meta b/Assets/VRM_BOTH_Samples/MigrateExporter/README.md.meta new file mode 100644 index 000000000..2703b0002 --- /dev/null +++ b/Assets/VRM_BOTH_Samples/MigrateExporter/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 07cbd8332c1ad0645b7a7d2b51456558 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From cb906d66cf3e50de7cf538a143844437cebfecd1 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 20 Oct 2022 14:53:14 +0900 Subject: [PATCH 2/5] VRM_BOTH_Samples to VRM_0x_and_10_Samples --- Assets/{VRM_BOTH_Samples.meta => VRM_0x_and_10_Samples.meta} | 2 +- .../MigrateExporter.meta | 0 .../MigrateExporter/MigrateExporter.cs | 0 .../MigrateExporter/MigrateExporter.cs.meta | 0 .../MigrateExporter/MigrateExporter.unity | 0 .../MigrateExporter/MigrateExporter.unity.meta | 0 .../MigrateExporter/README.md | 0 .../MigrateExporter/README.md.meta | 0 8 files changed, 1 insertion(+), 1 deletion(-) rename Assets/{VRM_BOTH_Samples.meta => VRM_0x_and_10_Samples.meta} (77%) rename Assets/{VRM_BOTH_Samples => VRM_0x_and_10_Samples}/MigrateExporter.meta (100%) rename Assets/{VRM_BOTH_Samples => VRM_0x_and_10_Samples}/MigrateExporter/MigrateExporter.cs (100%) rename Assets/{VRM_BOTH_Samples => VRM_0x_and_10_Samples}/MigrateExporter/MigrateExporter.cs.meta (100%) rename Assets/{VRM_BOTH_Samples => VRM_0x_and_10_Samples}/MigrateExporter/MigrateExporter.unity (100%) rename Assets/{VRM_BOTH_Samples => VRM_0x_and_10_Samples}/MigrateExporter/MigrateExporter.unity.meta (100%) rename Assets/{VRM_BOTH_Samples => VRM_0x_and_10_Samples}/MigrateExporter/README.md (100%) rename Assets/{VRM_BOTH_Samples => VRM_0x_and_10_Samples}/MigrateExporter/README.md.meta (100%) diff --git a/Assets/VRM_BOTH_Samples.meta b/Assets/VRM_0x_and_10_Samples.meta similarity index 77% rename from Assets/VRM_BOTH_Samples.meta rename to Assets/VRM_0x_and_10_Samples.meta index e49c92f00..f9712c65b 100644 --- a/Assets/VRM_BOTH_Samples.meta +++ b/Assets/VRM_0x_and_10_Samples.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c99f52afa0263124e87a9016b287a244 +guid: 9dfe30e374f23714098e680b42e58326 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter.meta b/Assets/VRM_0x_and_10_Samples/MigrateExporter.meta similarity index 100% rename from Assets/VRM_BOTH_Samples/MigrateExporter.meta rename to Assets/VRM_0x_and_10_Samples/MigrateExporter.meta diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.cs b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs similarity index 100% rename from Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.cs rename to Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.cs.meta b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs.meta similarity index 100% rename from Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.cs.meta rename to Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs.meta diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.unity b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.unity similarity index 100% rename from Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.unity rename to Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.unity diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.unity.meta b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.unity.meta similarity index 100% rename from Assets/VRM_BOTH_Samples/MigrateExporter/MigrateExporter.unity.meta rename to Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.unity.meta diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter/README.md b/Assets/VRM_0x_and_10_Samples/MigrateExporter/README.md similarity index 100% rename from Assets/VRM_BOTH_Samples/MigrateExporter/README.md rename to Assets/VRM_0x_and_10_Samples/MigrateExporter/README.md diff --git a/Assets/VRM_BOTH_Samples/MigrateExporter/README.md.meta b/Assets/VRM_0x_and_10_Samples/MigrateExporter/README.md.meta similarity index 100% rename from Assets/VRM_BOTH_Samples/MigrateExporter/README.md.meta rename to Assets/VRM_0x_and_10_Samples/MigrateExporter/README.md.meta From 0f7d2e8f7c9d53daebcfd80cdce6c72e5bcf6019 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 20 Oct 2022 15:01:09 +0900 Subject: [PATCH 3/5] rename, namespace --- .../{MigrationApi.cs => Migrator.cs} | 2 +- ...{MigrationApi.cs.meta => Migrator.cs.meta} | 2 +- Assets/VRM10/Runtime/Migration/Vrm0Meta.cs | 2 +- .../MigrateExporter/MigrateExporter.cs | 82 +++++++++---------- .../MigrateExporter/README.md | 7 +- 5 files changed, 49 insertions(+), 46 deletions(-) rename Assets/VRM10/Runtime/Migration/{MigrationApi.cs => Migrator.cs} (93%) rename Assets/VRM10/Runtime/Migration/{MigrationApi.cs.meta => Migrator.cs.meta} (83%) diff --git a/Assets/VRM10/Runtime/Migration/MigrationApi.cs b/Assets/VRM10/Runtime/Migration/Migrator.cs similarity index 93% rename from Assets/VRM10/Runtime/Migration/MigrationApi.cs rename to Assets/VRM10/Runtime/Migration/Migrator.cs index 170e9a377..7eeed73ce 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationApi.cs +++ b/Assets/VRM10/Runtime/Migration/Migrator.cs @@ -2,7 +2,7 @@ using System; namespace UniVRM10 { - public static class MigrationApi + public static class Migrator { /// /// マイグレーションの公開API diff --git a/Assets/VRM10/Runtime/Migration/MigrationApi.cs.meta b/Assets/VRM10/Runtime/Migration/Migrator.cs.meta similarity index 83% rename from Assets/VRM10/Runtime/Migration/MigrationApi.cs.meta rename to Assets/VRM10/Runtime/Migration/Migrator.cs.meta index 96948be1d..ddc6160ae 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationApi.cs.meta +++ b/Assets/VRM10/Runtime/Migration/Migrator.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: be52b15d95590934b93e744181762dfe +guid: db393ac50cf8db343a6cf58ed69687f6 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/VRM10/Runtime/Migration/Vrm0Meta.cs b/Assets/VRM10/Runtime/Migration/Vrm0Meta.cs index b3e9dcb22..8cc99fbee 100644 --- a/Assets/VRM10/Runtime/Migration/Vrm0Meta.cs +++ b/Assets/VRM10/Runtime/Migration/Vrm0Meta.cs @@ -23,7 +23,7 @@ namespace UniVRM10.Migration Other } - public enum UssageLicense + public enum UsageLicense { Disallow, Allow, diff --git a/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs index d381f9d0d..c735d2dba 100644 --- a/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs +++ b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs @@ -1,56 +1,56 @@ -using System.Collections; -using System.Collections.Generic; using System.IO; -using System.Linq; using UnityEngine; -[DisallowMultipleComponent] -public class MigrateExporter : MonoBehaviour +namespace UniVRM10.Sample { - [SerializeField] - UniVRM10.VRM10ObjectMeta _meta = new UniVRM10.VRM10ObjectMeta(); - - async void OnGUI() + [DisallowMultipleComponent] + public class MigrateExporter : MonoBehaviour { - // validate - foreach (var validation in _meta.Validate(null)) - { - GUILayout.Label("meta validation: " + validation.Message); - if (!validation.CanExport) - { - GUI.enabled = false; - } - } + [SerializeField] + UniVRM10.VRM10ObjectMeta _meta = new UniVRM10.VRM10ObjectMeta(); - if (GUILayout.Button("migrate")) + async void OnGUI() { - var path = UnityEditor.EditorUtility.OpenFilePanel("load vrm-0.x", null, "vrm"); - if (string.IsNullOrEmpty(path)) + // validate + foreach (var validation in _meta.Validate(null)) { - return; + GUILayout.Label("meta validation: " + validation.Message); + if (!validation.CanExport) + { + GUI.enabled = false; + } } - Debug.Log(path); - var bytes = File.ReadAllBytes(path); - - // load - var vrm0Instance = await VRM.VrmUtility.LoadBytesAsync(path, bytes); - - // export設定 - var exportConfig = new UniGLTF.GltfExportSettings + if (GUILayout.Button("migrate")) { - }; - // export vrm0 - var vrm0 = VRM.VRMExporter.Export(exportConfig, - vrm0Instance.gameObject, new VRMShaders.RuntimeTextureSerializer()); - var vrm0bytes = vrm0.ToGlbBytes(); + var path = UnityEditor.EditorUtility.OpenFilePanel("load vrm-0.x", null, "vrm"); + if (string.IsNullOrEmpty(path)) + { + return; + } - // migrate to vrm1 - var vrm1Bytes = UniVRM10.MigrationApi.Migrate(vrm0bytes, _meta); - var pathObj = VRMShaders.PathObject.FromFullPath(path); - var newPath = pathObj.Parent.Child(pathObj.Stem + ".10.vrm"); - newPath.WriteAllBytes(vrm1Bytes); - Debug.Log($"export to: {newPath}"); + Debug.Log(path); + var bytes = File.ReadAllBytes(path); + + // load + var vrm0Instance = await VRM.VrmUtility.LoadBytesAsync(path, bytes); + + // export設定 + var exportConfig = new UniGLTF.GltfExportSettings + { + }; + // export vrm0 + var vrm0 = VRM.VRMExporter.Export(exportConfig, + vrm0Instance.gameObject, new VRMShaders.RuntimeTextureSerializer()); + var vrm0bytes = vrm0.ToGlbBytes(); + + // migrate to vrm1 + var vrm1Bytes = UniVRM10.Migrator.Migrate(vrm0bytes, _meta); + var pathObj = VRMShaders.PathObject.FromFullPath(path); + var newPath = pathObj.Parent.Child(pathObj.Stem + ".10.vrm"); + newPath.WriteAllBytes(vrm1Bytes); + Debug.Log($"export to: {newPath}"); + } } } } diff --git a/Assets/VRM_0x_and_10_Samples/MigrateExporter/README.md b/Assets/VRM_0x_and_10_Samples/MigrateExporter/README.md index ca0648b31..9b7d67607 100644 --- a/Assets/VRM_0x_and_10_Samples/MigrateExporter/README.md +++ b/Assets/VRM_0x_and_10_Samples/MigrateExporter/README.md @@ -1,11 +1,11 @@ -# Migration +# MigrateExporter - for runtime - Convert export vrm0 model directly to vrm1 - input: vrm0 hierarchy + vrm1 meta - output: vrm1 binary -## detail +## Detail 最初に vrm0 モデルをエクスポートします。 このとき後で vrm1 化する前提で通常とは別の設定にします。 @@ -22,3 +22,6 @@ - https://github.com/vrm-c/glTF-Validator/pull/1 +## Caution + +プログラムの利用者が、入力に使う vrm0 のライセンスを管理できるようにしてください。 From 0a1b55ec1ec36f22d53082aae9646ed59c0fe0c6 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 20 Oct 2022 15:15:00 +0900 Subject: [PATCH 4/5] =?UTF-8?q?meta=20=E3=81=AE=E3=83=90=E3=83=AA=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=80=82=E6=96=87=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/VRM10Object/VRM10ObjectMeta.cs | 4 ++-- Assets/VRM10/Runtime/Migration/MigrationVrm.cs | 4 ++-- Assets/VRM10/Runtime/Migration/Migrator.cs | 13 ++++++++++++- .../MigrateExporter/MigrateExporter.cs | 3 ++- .../VRM_0x_and_10_Samples/MigrateExporter/README.md | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectMeta.cs b/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectMeta.cs index 17c0e0c28..c9e5d55c5 100644 --- a/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectMeta.cs +++ b/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectMeta.cs @@ -70,7 +70,7 @@ namespace UniVRM10 public string OtherLicenseUrl; #endregion - public IEnumerable Validate(GameObject _) + public IEnumerable Validate(GameObject _ = null) { if (string.IsNullOrEmpty(Name)) { @@ -103,7 +103,7 @@ namespace UniVRM10 } dst.ContactInformation = ContactInformation; dst.References = References; - dst.ThirdPartyLicenses = ThirdPartyLicenses; + dst.ThirdPartyLicenses = ThirdPartyLicenses; dst.Thumbnail = Thumbnail; dst.AvatarPermission = AvatarPermission; dst.ViolentUsage = ViolentUsage; diff --git a/Assets/VRM10/Runtime/Migration/MigrationVrm.cs b/Assets/VRM10/Runtime/Migration/MigrationVrm.cs index 2b69bc2d0..a368818ae 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationVrm.cs +++ b/Assets/VRM10/Runtime/Migration/MigrationVrm.cs @@ -15,9 +15,9 @@ namespace UniVRM10 /// static internal class MigrationVrm { - public static byte[] Migrate(byte[] src, VRM10ObjectMeta meta = null) + public static byte[] Migrate(byte[] vrm0bytes, VRM10ObjectMeta meta = null) { - using (var data = new GlbBinaryParser(src, "migration").Parse()) + using (var data = new GlbBinaryParser(vrm0bytes, "migration").Parse()) { return Migrate(data, meta); } diff --git a/Assets/VRM10/Runtime/Migration/Migrator.cs b/Assets/VRM10/Runtime/Migration/Migrator.cs index 7eeed73ce..241a9c11c 100644 --- a/Assets/VRM10/Runtime/Migration/Migrator.cs +++ b/Assets/VRM10/Runtime/Migration/Migrator.cs @@ -10,10 +10,21 @@ namespace UniVRM10 /// MigrationVrm とその関連実装は、internal で runtime import 専用 /// /// - /// + /// (必須)外部から供給されるライセンス情報 /// public static byte[] Migrate(byte[] vrm0bytes, VRM10ObjectMeta meta) { + if (meta == null) + { + throw new ArgumentNullException("meta"); + } + foreach (var validation in meta.Validate()) + { + if (!validation.CanExport) + { + throw new ArgumentException(validation.Message); + } + } return MigrationVrm.Migrate(vrm0bytes, meta); } } diff --git a/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs index c735d2dba..244008d24 100644 --- a/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs +++ b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.cs @@ -12,7 +12,7 @@ namespace UniVRM10.Sample async void OnGUI() { // validate - foreach (var validation in _meta.Validate(null)) + foreach (var validation in _meta.Validate()) { GUILayout.Label("meta validation: " + validation.Message); if (!validation.CanExport) @@ -21,6 +21,7 @@ namespace UniVRM10.Sample } } + GUILayout.Label("ライセンスを変更する権利のある vrm-0.x モデルをロードしてください"); if (GUILayout.Button("migrate")) { var path = UnityEditor.EditorUtility.OpenFilePanel("load vrm-0.x", null, "vrm"); diff --git a/Assets/VRM_0x_and_10_Samples/MigrateExporter/README.md b/Assets/VRM_0x_and_10_Samples/MigrateExporter/README.md index 9b7d67607..c6447432e 100644 --- a/Assets/VRM_0x_and_10_Samples/MigrateExporter/README.md +++ b/Assets/VRM_0x_and_10_Samples/MigrateExporter/README.md @@ -24,4 +24,4 @@ ## Caution -プログラムの利用者が、入力に使う vrm0 のライセンスを管理できるようにしてください。 +対象の `vrm-0.x` のライセンスを変更する権利が必要です。 From b94b035d396a05be9bbc10279a7fbf8c88a4c35a Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 20 Oct 2022 15:17:23 +0900 Subject: [PATCH 5/5] admdef --- .../MigrateExporter/MigrateExporter.asmdef | 19 +++++++++++++++++++ .../MigrateExporter.asmdef.meta | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.asmdef create mode 100644 Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.asmdef.meta diff --git a/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.asmdef b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.asmdef new file mode 100644 index 000000000..a1997ee6f --- /dev/null +++ b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.asmdef @@ -0,0 +1,19 @@ +{ + "name": "MigrateExporter", + "rootNamespace": "", + "references": [ + "GUID:05dd262a0c0a2f841b8252c8c3815582", + "GUID:e47c917724578cc43b5506c17a27e9a0", + "GUID:8d76e605759c3f64a957d63ef96ada7c", + "GUID:da3e51d19d51a544fa14d43fee843098" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.asmdef.meta b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.asmdef.meta new file mode 100644 index 000000000..66e172362 --- /dev/null +++ b/Assets/VRM_0x_and_10_Samples/MigrateExporter/MigrateExporter.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f9969649d96863348a27d3379008cac5 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: