Merge pull request #894 from ousttrue/fix/export_BlendShapeApplyer

正規化するときにBlendShapeを使うLookAtがExportされない
This commit is contained in:
PoChang007
2021-04-21 15:11:42 +09:00
committed by GitHub
7 changed files with 103 additions and 17 deletions

View File

@@ -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
/// </summary>
/// <param name="path">出力先</param>
/// <param name="settings">エクスポート設定</param>
public static void Export(string path, GameObject exportRoot, VRMMetaObject meta, VRMExportSettings settings, IReadOnlyList<MeshExportInfo> info)
public static byte[] Export(GameObject exportRoot, VRMMetaObject meta, VRMExportSettings settings)
{
List<GameObject> destroy = new List<GameObject>();
try
{
Export(path, exportRoot, meta, settings, info, destroy);
return Export(exportRoot, meta, settings, destroy);
}
finally
{
@@ -137,8 +135,8 @@ namespace VRM
/// <param name="path"></param>
/// <param name="settings"></param>
/// <param name="destroy">作業が終わったらDestoryするべき一時オブジェクト</param>
static void Export(string path, GameObject exportRoot, VRMMetaObject meta,
VRMExportSettings settings, IReadOnlyList<UniGLTF.MeshExportInfo> info,
static byte[] Export(GameObject exportRoot, VRMMetaObject meta,
VRMExportSettings settings,
List<GameObject> destroy)
{
var target = exportRoot;
@@ -201,6 +199,8 @@ namespace VRM
destroy.Add(target);
}
var fp = target.GetComponent<VRMFirstPerson>();
// 元のBlendShapeClipに変更を加えないように複製
var proxy = target.GetComponent<VRMBlendShapeProxy>();
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;
}
}
}

View File

@@ -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()

View File

@@ -57,7 +57,8 @@ namespace VRM
dst.FirstPersonOffset = FirstPersonOffset;
dst.Renderers = Renderers.Select(x =>
{
var renderer = map[x.Renderer.transform].GetComponent<Renderer>();
var mapped = map[x.Renderer.transform];
var renderer = mapped.GetComponent<Renderer>();
return new VRMFirstPerson.RendererFirstPersonFlags
{
Renderer = renderer,

View File

@@ -214,6 +214,30 @@ namespace VRM
src.CopyTo(root, map);
}
}
{
// look at
var src = go.GetComponent<VRMLookAtHead>();
if (src != null)
{
var dst = root.AddComponent<VRMLookAtHead>();
}
}
{
// bone applier
var src = go.GetComponent<VRMLookAtBoneApplyer>();
if (src != null)
{
var dst = root.AddComponent<VRMLookAtBoneApplyer>();
}
}
{
// blendshape applier
var src = go.GetComponent<VRMLookAtBlendShapeApplyer>();
if (src != null)
{
var dst = root.AddComponent<VRMLookAtBlendShapeApplyer>();
}
}
{
// humanoid

View File

@@ -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"
],

View File

@@ -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<VRMFirstPerson>();
GameObject.DestroyImmediate(go.GetComponent<VRMLookAtBoneApplyer>());
go.AddComponent<VRMLookAtBlendShapeApplyer>();
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);
}
}
}

View File

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