diff --git a/Assets/VRM/Editor/Format/VRMEditorExporter.cs b/Assets/VRM/Editor/Format/VRMEditorExporter.cs index 2fce5b9f0..3c765525c 100644 --- a/Assets/VRM/Editor/Format/VRMEditorExporter.cs +++ b/Assets/VRM/Editor/Format/VRMEditorExporter.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Text; using UniGLTF; -using UnityEditor; using UnityEngine; using VRMShaders; @@ -17,12 +15,12 @@ namespace VRM /// /// 出力先 /// エクスポート設定 - public static void Export(string path, GameObject exportRoot, VRMMetaObject meta, VRMExportSettings settings, IReadOnlyList info) + public static byte[] Export(GameObject exportRoot, VRMMetaObject meta, VRMExportSettings settings) { List destroy = new List(); try { - Export(path, exportRoot, meta, settings, info, destroy); + return Export(exportRoot, meta, settings, destroy); } finally { @@ -137,8 +135,8 @@ namespace VRM /// /// /// 作業が終わったらDestoryするべき一時オブジェクト - static void Export(string path, GameObject exportRoot, VRMMetaObject meta, - VRMExportSettings settings, IReadOnlyList info, + static byte[] Export(GameObject exportRoot, VRMMetaObject meta, + VRMExportSettings settings, List destroy) { var target = exportRoot; @@ -201,6 +199,8 @@ namespace VRM destroy.Add(target); } + var fp = target.GetComponent(); + // 元のBlendShapeClipに変更を加えないように複製 var proxy = target.GetComponent(); if (proxy != null) @@ -228,14 +228,8 @@ namespace VRM exporter.Export(settings.MeshExportSettings, AssetTextureUtil.IsTextureEditorAsset, AssetTextureUtil.GetTextureBytesWithMime); } var bytes = gltf.ToGlbBytes(); - File.WriteAllBytes(path, bytes); Debug.LogFormat("Export elapsed {0}", sw.Elapsed); - - if (path.StartsWithUnityAssetPath()) - { - // 出力ファイルのインポートを発動 - AssetDatabase.ImportAsset(path.ToUnityRelativePath()); - } + return bytes; } } } diff --git a/Assets/VRM/Editor/Format/VRMExporterWizard.cs b/Assets/VRM/Editor/Format/VRMExporterWizard.cs index 12dc64bfb..878958efc 100644 --- a/Assets/VRM/Editor/Format/VRMExporterWizard.cs +++ b/Assets/VRM/Editor/Format/VRMExporterWizard.cs @@ -4,6 +4,7 @@ using UnityEditor; using UnityEngine; using UniGLTF; using UniGLTF.M17N; +using System.IO; namespace VRM { @@ -157,7 +158,15 @@ namespace VRM protected override void ExportPath(string path) { - VRMEditorExporter.Export(path, State.ExportRoot, Meta != null ? Meta : m_tmpMeta, m_settings, m_meshes.Meshes); + var bytes = VRMEditorExporter.Export(State.ExportRoot, Meta != null ? Meta : m_tmpMeta, m_settings); + + File.WriteAllBytes(path, bytes); + + if (path.StartsWithUnityAssetPath()) + { + // 出力ファイルのインポートを発動 + AssetDatabase.ImportAsset(path.ToUnityRelativePath()); + } } protected override void OnLayout() diff --git a/Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs b/Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs index 3f5224173..78b2b10cd 100644 --- a/Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs +++ b/Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs @@ -57,7 +57,8 @@ namespace VRM dst.FirstPersonOffset = FirstPersonOffset; dst.Renderers = Renderers.Select(x => { - var renderer = map[x.Renderer.transform].GetComponent(); + var mapped = map[x.Renderer.transform]; + var renderer = mapped.GetComponent(); return new VRMFirstPerson.RendererFirstPersonFlags { Renderer = renderer, diff --git a/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs b/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs index 9fbdcf5d8..d15039a33 100644 --- a/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs +++ b/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs @@ -214,6 +214,30 @@ namespace VRM src.CopyTo(root, map); } } + { + // look at + var src = go.GetComponent(); + if (src != null) + { + var dst = root.AddComponent(); + } + } + { + // bone applier + var src = go.GetComponent(); + if (src != null) + { + var dst = root.AddComponent(); + } + } + { + // blendshape applier + var src = go.GetComponent(); + if (src != null) + { + var dst = root.AddComponent(); + } + } { // humanoid diff --git a/Assets/VRM/Tests/VRM.Tests.asmdef b/Assets/VRM/Tests/VRM.Tests.asmdef index 92d27823b..b11a29829 100644 --- a/Assets/VRM/Tests/VRM.Tests.asmdef +++ b/Assets/VRM/Tests/VRM.Tests.asmdef @@ -2,10 +2,9 @@ "name": "VRM.Tests", "references": [ "VRM", + "UniVRM.Editor", "UniGLTF", "UniGLTF.Editor", - "MeshUtility", - "MeshUtility.Editor", "VRMShaders.GLTF.IO.Runtime", "VRMShaders.GLTF.IO.Editor" ], diff --git a/Assets/VRM/Tests/VRMLookAtTests.cs b/Assets/VRM/Tests/VRMLookAtTests.cs new file mode 100644 index 000000000..fe01e118e --- /dev/null +++ b/Assets/VRM/Tests/VRMLookAtTests.cs @@ -0,0 +1,48 @@ + +using System.IO; +using NUnit.Framework; +using UniGLTF; +using UnityEngine; + +namespace VRM +{ + public class VRMLookAtTests + { + static string AliciaPath + { + get + { + return Path.GetFullPath(Application.dataPath + "/../Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm") + .Replace("\\", "/"); + } + } + + [Test] + public void VRMLookAtTest() + { + var parser = new GltfParser(); + parser.ParsePath(AliciaPath); + byte[] bytes = default; + using (var loader = new VRMImporterContext(parser)) + { + loader.Load(); + loader.ShowMeshes(); + + var go = loader.Root; + var fp = go.GetComponent(); + GameObject.DestroyImmediate(go.GetComponent()); + go.AddComponent(); + bytes = VRMEditorExporter.Export(go, null, new VRMExportSettings + { + PoseFreeze = true, + }); + } + + var parser2 = new GltfParser(); + parser2.Parse(AliciaPath, bytes); + var loader2 = new VRMImporterContext(parser2); + + Assert.AreEqual(LookAtType.BlendShape, loader2.VRM.firstPerson.lookAtType); + } + } +} diff --git a/Assets/VRM/Tests/VRMLookAtTests.cs.meta b/Assets/VRM/Tests/VRMLookAtTests.cs.meta new file mode 100644 index 000000000..ec3dbbafa --- /dev/null +++ b/Assets/VRM/Tests/VRMLookAtTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e7b3adead70dd34489ba7921d5ccef1c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: