mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-04-24 23:18:04 -05:00
IBlendShapeFilter
This commit is contained in:
parent
f02d2d2ee0
commit
ce98d54976
|
|
@ -73,7 +73,7 @@ namespace UniGLTF
|
|||
|
||||
protected override void OnLayout()
|
||||
{
|
||||
m_meshes.SetRoot(State.ExportRoot, m_settings.MeshExportSettings);
|
||||
m_meshes.SetRoot(State.ExportRoot, m_settings.MeshExportSettings, new DefualtBlendShapeExportFilter());
|
||||
}
|
||||
|
||||
protected override bool DoGUI(bool isValid)
|
||||
|
|
|
|||
|
|
@ -31,15 +31,9 @@ namespace UniGLTF
|
|||
|
||||
public int ExpectedExportByteSize => Meshes.Where(x => x.IsRendererActive).Sum(x => x.ExportByteSize);
|
||||
|
||||
public MeshExportSettings Settings;
|
||||
|
||||
public virtual bool UseBlendShape(int index, string relativePath) => true;
|
||||
|
||||
public void SetRoot(GameObject ExportRoot, MeshExportSettings settings)
|
||||
public void SetRoot(GameObject ExportRoot, MeshExportSettings settings, IBlendShapeExportFilter blendShapeFilter)
|
||||
{
|
||||
Settings = settings;
|
||||
|
||||
MeshExportInfo.GetInfo(ExportRoot, Meshes, settings, UseBlendShape);
|
||||
MeshExportInfo.GetInfo(ExportRoot, Meshes, settings, blendShapeFilter);
|
||||
}
|
||||
|
||||
public Func<string, string> GltfMaterialFromUnityShaderName = DefaultGltfMaterialType;
|
||||
|
|
|
|||
18
Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/BlendShapeFilter.cs
Normal file
18
Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/BlendShapeFilter.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
namespace UniGLTF
|
||||
{
|
||||
public interface IBlendShapeExportFilter
|
||||
{
|
||||
bool UseBlendShape(int blendShapeIndex, string relativePath);
|
||||
}
|
||||
|
||||
public class DefualtBlendShapeExportFilter : IBlendShapeExportFilter
|
||||
{
|
||||
/// <summary>
|
||||
/// Export all blendshape
|
||||
/// </summary>
|
||||
/// <param name="blendShapeIndex"></param>
|
||||
/// <param name="relativePath"></param>
|
||||
/// <returns></returns>
|
||||
public bool UseBlendShape(int blendShapeIndex, string relativePath) => true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 18a610aab46d5034cb787ab237e3dea2
|
||||
guid: d962c03c08e3d3a4eb5c52f5b4e0c93f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -6,8 +6,6 @@ using UnityEngine;
|
|||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public delegate bool UseBlendShapeFunc(int blendShapeIndex, string relativePath);
|
||||
|
||||
[Serializable]
|
||||
public struct MeshExportInfo
|
||||
{
|
||||
|
|
@ -58,8 +56,8 @@ namespace UniGLTF
|
|||
/// <param name="exportRoot"></param>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="settings"></param>
|
||||
/// <param name="useBlendShape"> blendShape の export を filtering する </param>
|
||||
public static void GetInfo(GameObject exportRoot, List<MeshExportInfo> list, MeshExportSettings settings, UseBlendShapeFunc useBlendShape)
|
||||
/// <param name="blendShapeFilter"> blendShape の export を filtering する </param>
|
||||
public static void GetInfo(GameObject exportRoot, List<MeshExportInfo> list, MeshExportSettings settings, IBlendShapeExportFilter blendShapeFilter)
|
||||
{
|
||||
list.Clear();
|
||||
if (exportRoot == null)
|
||||
|
|
@ -69,14 +67,14 @@ namespace UniGLTF
|
|||
|
||||
foreach (var renderer in exportRoot.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
if (TryGetMeshInfo(exportRoot, renderer, settings, useBlendShape, out MeshExportInfo info))
|
||||
if (TryGetMeshInfo(exportRoot, renderer, settings, blendShapeFilter, out MeshExportInfo info))
|
||||
{
|
||||
list.Add(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool TryGetMeshInfo(GameObject root, Renderer renderer, MeshExportSettings settings, UseBlendShapeFunc useBlendShape, out MeshExportInfo info)
|
||||
static bool TryGetMeshInfo(GameObject root, Renderer renderer, MeshExportSettings settings, IBlendShapeExportFilter blendShapeFilter, out MeshExportInfo info)
|
||||
{
|
||||
info = default;
|
||||
if (root == null)
|
||||
|
|
@ -115,7 +113,7 @@ namespace UniGLTF
|
|||
info.VertexColor = VertexColorUtility.DetectVertexColor(info.Mesh, info.Renderer.sharedMaterials);
|
||||
|
||||
var relativePath = UniGLTF.UnityExtensions.RelativePathFrom(renderer.transform, root.transform);
|
||||
CalcMeshSize(ref info, relativePath, settings, useBlendShape);
|
||||
CalcMeshSize(ref info, relativePath, settings, blendShapeFilter);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -123,7 +121,7 @@ namespace UniGLTF
|
|||
static void CalcMeshSize(ref MeshExportInfo info,
|
||||
string relativePath,
|
||||
MeshExportSettings settings,
|
||||
UseBlendShapeFunc useBlendShape
|
||||
IBlendShapeExportFilter blendShapeFilter
|
||||
)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
|
@ -169,7 +167,7 @@ namespace UniGLTF
|
|||
info.ExportBlendShapeVertexSize = settings.ExportOnlyBlendShapePosition ? 4 * 3 : 4 * (3 + 3);
|
||||
for (var i = 0; i < info.Mesh.blendShapeCount; ++i)
|
||||
{
|
||||
if (!useBlendShape(i, relativePath))
|
||||
if (!blendShapeFilter.UseBlendShape(i, relativePath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace UniGLTF
|
|||
|
||||
try
|
||||
{
|
||||
validator.SetRoot(root, MeshExportSettings.Default);
|
||||
validator.SetRoot(root, MeshExportSettings.Default, new DefualtBlendShapeExportFilter());
|
||||
var vs = validator.Validate(root);
|
||||
Assert.False(vs.All(x => x.CanExport));
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ namespace UniGLTF
|
|||
|
||||
try
|
||||
{
|
||||
validator.SetRoot(root, MeshExportSettings.Default);
|
||||
validator.SetRoot(root, MeshExportSettings.Default, new DefualtBlendShapeExportFilter());
|
||||
var vs = validator.Validate(root);
|
||||
Assert.False(vs.All(x => x.CanExport));
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ namespace UniGLTF
|
|||
|
||||
try
|
||||
{
|
||||
validator.SetRoot(root, MeshExportSettings.Default);
|
||||
validator.SetRoot(root, MeshExportSettings.Default, new DefualtBlendShapeExportFilter());
|
||||
var vs = validator.Validate(root);
|
||||
Assert.False(vs.All(x => x.CanExport));
|
||||
}
|
||||
|
|
@ -90,7 +90,7 @@ namespace UniGLTF
|
|||
// remove MeshFilter
|
||||
Component.DestroyImmediate(child.GetComponent<MeshFilter>());
|
||||
|
||||
validator.SetRoot(root, MeshExportSettings.Default);
|
||||
validator.SetRoot(root, MeshExportSettings.Default, new DefualtBlendShapeExportFilter());
|
||||
var vs = validator.Validate(root);
|
||||
Assert.True(vs.All(x => x.CanExport));
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ namespace UniGLTF
|
|||
// set null
|
||||
child.GetComponent<MeshFilter>().sharedMesh = null;
|
||||
|
||||
validator.SetRoot(root, MeshExportSettings.Default);
|
||||
validator.SetRoot(root, MeshExportSettings.Default, new DefualtBlendShapeExportFilter());
|
||||
var vs = validator.Validate(root);
|
||||
Assert.True(vs.All(x => x.CanExport));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,7 @@ using UnityEngine;
|
|||
|
||||
namespace VRM
|
||||
{
|
||||
/// <summary>
|
||||
/// Export時にMeshを一覧する。
|
||||
///
|
||||
/// Mesh関連の Validation する。
|
||||
/// Meshのエクスポートサイズを試算する。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class VRMMeshExportValidator : MeshExportValidator
|
||||
public class VRMBlendShapeExportFilter : IBlendShapeExportFilter
|
||||
{
|
||||
static bool ClipsContainsName(IReadOnlyList<BlendShapeClip> clips, bool onlyPreset, BlendShapeBinding binding)
|
||||
{
|
||||
|
|
@ -40,7 +33,24 @@ namespace VRM
|
|||
public VRMExportSettings VRMExportSettings;
|
||||
public List<BlendShapeClip> Clips;
|
||||
|
||||
public override bool UseBlendShape(int index, string relativePath)
|
||||
public VRMBlendShapeExportFilter(GameObject exportRoot, VRMExportSettings settings)
|
||||
{
|
||||
VRMExportSettings = settings;
|
||||
Clips = new List<BlendShapeClip>();
|
||||
if (exportRoot != null)
|
||||
{
|
||||
var proxy = exportRoot.GetComponent<VRMBlendShapeProxy>();
|
||||
if (proxy != null)
|
||||
{
|
||||
if (proxy.BlendShapeAvatar != null)
|
||||
{
|
||||
Clips.AddRange(proxy.BlendShapeAvatar.Clips);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseBlendShape(int index, string relativePath)
|
||||
{
|
||||
if (VRMExportSettings.ReduceBlendshape)
|
||||
{
|
||||
|
|
@ -57,24 +67,5 @@ namespace VRM
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetRoot(GameObject ExportRoot, VRMExportSettings settings)
|
||||
{
|
||||
VRMExportSettings = settings;
|
||||
Clips = new List<BlendShapeClip>();
|
||||
if (ExportRoot != null)
|
||||
{
|
||||
var proxy = ExportRoot.GetComponent<VRMBlendShapeProxy>();
|
||||
if (proxy != null)
|
||||
{
|
||||
if (proxy.BlendShapeAvatar != null)
|
||||
{
|
||||
Clips.AddRange(proxy.BlendShapeAvatar.Clips);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetRoot(ExportRoot, settings.MeshExportSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e590565ae8d8e5f45956a20e207d3272
|
||||
guid: d634cf68918e2f947b7ea0288d52a720
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -36,7 +36,7 @@ namespace VRM
|
|||
Editor m_settingsInspector;
|
||||
|
||||
|
||||
VRMMeshExportValidator m_meshes;
|
||||
MeshExportValidator m_meshes;
|
||||
Editor m_meshesInspector;
|
||||
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ namespace VRM
|
|||
m_settings = ScriptableObject.CreateInstance<VRMExportSettings>();
|
||||
m_settingsInspector = Editor.CreateEditor(m_settings);
|
||||
|
||||
m_meshes = ScriptableObject.CreateInstance<VRMMeshExportValidator>();
|
||||
m_meshes = ScriptableObject.CreateInstance<MeshExportValidator>();
|
||||
m_meshesInspector = Editor.CreateEditor(m_meshes);
|
||||
|
||||
State.ExportRootChanged += (root) =>
|
||||
|
|
@ -179,7 +179,7 @@ namespace VRM
|
|||
|
||||
protected override void OnLayout()
|
||||
{
|
||||
m_meshes.SetRoot(State.ExportRoot, m_settings);
|
||||
m_meshes.SetRoot(State.ExportRoot, m_settings.MeshExportSettings, new VRMBlendShapeExportFilter(State.ExportRoot, m_settings));
|
||||
}
|
||||
|
||||
static bool s_foldT = true;
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
using UniGLTF;
|
||||
using UnityEditor;
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
[CustomEditor(typeof(VRMMeshExportValidator))]
|
||||
public class VRMExportMeshesEditor : MeshExportValidatorEditor
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -2,19 +2,17 @@
|
|||
"name": "VRM",
|
||||
"references": [
|
||||
"UniHumanoid",
|
||||
"MeshUtility",
|
||||
"UniGLTF",
|
||||
"VRMShaders.GLTF.IO.Runtime",
|
||||
"VRMShaders.VRM.IO.Runtime",
|
||||
"MToon"
|
||||
],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
"defineConstraints": []
|
||||
}
|
||||
|
|
@ -168,7 +168,7 @@ namespace UniVRM10
|
|||
protected override void OnLayout()
|
||||
{
|
||||
// m_settings, m_meshes.Meshes
|
||||
m_meshes.SetRoot(State.ExportRoot, m_settings.MeshExportSettings);
|
||||
m_meshes.SetRoot(State.ExportRoot, m_settings.MeshExportSettings, new DefualtBlendShapeExportFilter());
|
||||
}
|
||||
|
||||
protected override bool DoGUI(bool isValid)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user