merge MeshExportSettings to GltfExportSettings

This commit is contained in:
ousttrue 2021-06-29 20:01:03 +09:00
parent f07d1cf98b
commit 6cfdf81429
21 changed files with 62 additions and 97 deletions

View File

@ -68,7 +68,7 @@ namespace UniGLTF
protected override void OnLayout()
{
m_meshes.SetRoot(State.ExportRoot, Settings.MeshExportSettings, new DefualtBlendShapeExportFilter());
m_meshes.SetRoot(State.ExportRoot, Settings, new DefualtBlendShapeExportFilter());
}
protected override bool DoGUI(bool isValid)
@ -113,13 +113,7 @@ namespace UniGLTF
using (var exporter = new gltfExporter(gltf, Settings.InverseAxis))
{
exporter.Prepare(State.ExportRoot);
var settings = new MeshExportSettings
{
ExportOnlyBlendShapePosition = Settings.DropNormal,
UseSparseAccessorForMorphTarget = Settings.Sparse,
DivideVertexBuffer = Settings.DivideVertexBuffer,
};
exporter.Export(settings, new EditorTextureSerializer());
exporter.Export(Settings, new EditorTextureSerializer());
}
if (isGlb)

View File

@ -31,7 +31,7 @@ namespace UniGLTF
public int ExpectedExportByteSize => Meshes.Where(x => x.IsRendererActive).Sum(x => x.ExportByteSize);
public void SetRoot(GameObject ExportRoot, MeshExportSettings settings, IBlendShapeExportFilter blendShapeFilter)
public void SetRoot(GameObject ExportRoot, GltfExportSettings settings, IBlendShapeExportFilter blendShapeFilter)
{
MeshExportInfo.GetInfo(ExportRoot.transform.Traverse().Skip(1), Meshes, settings);
foreach(var info in Meshes)

View File

@ -1,7 +1,6 @@
using System;
using UnityEngine;
namespace UniGLTF
{
@ -10,18 +9,36 @@ namespace UniGLTF
{
public Axes InverseAxis;
[Header("MorphTarget(BlendShape)")]
public bool Sparse;
public bool DropNormal;
/// <summary>
/// https://github.com/vrm-c/UniVRM/issues/800
///
/// VertexBuffer を共有バッファ方式にする
/// UniVRM-0.71.0 までの挙動
/// </summary>
public bool DivideVertexBuffer;
public MeshExportSettings MeshExportSettings => new MeshExportSettings
{
UseSparseAccessorForMorphTarget = Sparse,
ExportOnlyBlendShapePosition = DropNormal,
DivideVertexBuffer = DivideVertexBuffer,
};
/// <summary>
/// MorphTarget に Sparse Accessor を使う
/// </summary>
public bool UseSparseAccessorForMorphTarget;
/// <summary>
/// MorphTarget を Position だけにする(normal とか捨てる)
/// </summary>
public bool ExportOnlyBlendShapePosition;
/// <summary>
/// tangent を出力する
/// </summary>
public bool ExportTangents
#if GLTF_EXPORT_TANGENTS
= true,
#endif
;
/// <summary>
/// VRMC_materials_hdr_emissiveMultiplier
/// </summary>
public bool UseEmissiveMultiplier;
}
}

View File

@ -183,7 +183,7 @@ namespace UniGLTF
public string Summary;
#endregion
MeshExportInfo(Renderer renderer, MeshExportSettings settings)
MeshExportInfo(Renderer renderer, GltfExportSettings settings)
{
if (renderer == null)
{
@ -264,7 +264,7 @@ namespace UniGLTF
public static MeshExportInfo Create(GameObject go)
{
var list = new List<MeshExportInfo>();
GetInfo(go.transform.Traverse(), list, MeshExportSettings.Default);
GetInfo(go.transform.Traverse(), list, new GltfExportSettings());
return list[0];
}
@ -275,7 +275,7 @@ namespace UniGLTF
/// <param name="list"></param>
/// <param name="settings"></param>
/// <param name="blendShapeFilter"> blendShape の export を filtering する </param>
public static void GetInfo(IEnumerable<Transform> nodes, List<MeshExportInfo> list, MeshExportSettings settings)
public static void GetInfo(IEnumerable<Transform> nodes, List<MeshExportInfo> list, GltfExportSettings settings)
{
list.Clear();
foreach (var node in nodes)
@ -311,7 +311,7 @@ namespace UniGLTF
public void CalcMeshSize(
GameObject root,
Renderer renderer,
MeshExportSettings settings,
GltfExportSettings settings,
IBlendShapeExportFilter blendShapeFilter
)
{
@ -321,7 +321,7 @@ namespace UniGLTF
public void CalcMeshSize(
string relativePath,
MeshExportSettings settings,
GltfExportSettings settings,
IBlendShapeExportFilter blendShapeFilter
)
{

View File

@ -1,35 +0,0 @@
using System;
namespace UniGLTF
{
[Serializable]
public struct MeshExportSettings
{
//
// https://github.com/vrm-c/UniVRM/issues/800
//
// VertexBuffer を共有バッファ方式にする
// UniVRM-0.71.0 までの挙動
//
public bool DivideVertexBuffer;
// MorphTarget に Sparse Accessor を使う
public bool UseSparseAccessorForMorphTarget;
// MorphTarget を Position だけにする(normal とか捨てる)
public bool ExportOnlyBlendShapePosition;
// tangent を出力する
public bool ExportTangents;
public static MeshExportSettings Default => new MeshExportSettings
{
UseSparseAccessorForMorphTarget = false,
ExportOnlyBlendShapePosition = false,
DivideVertexBuffer = false,
#if GLTF_EXPORT_TANGENTS
ExportTangents = true,
#endif
};
}
}

View File

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

View File

@ -19,7 +19,7 @@ namespace UniGLTF
/// <returns></returns>
public static (glTFMesh, Dictionary<int, int>) Export(glTF gltf, int gltfBuffer,
MeshExportInfo unityMesh, List<Material> unityMaterials,
IAxisInverter axisInverter, MeshExportSettings settings)
IAxisInverter axisInverter, GltfExportSettings settings)
{
var mesh = unityMesh.Mesh;
var gltfMesh = new glTFMesh(mesh.name);

View File

@ -26,7 +26,7 @@ namespace UniGLTF
/// <returns></returns>
public static (glTFMesh, Dictionary<int, int> blendShapeIndexMap) Export(glTF gltf, int bufferIndex,
MeshExportInfo unityMesh, List<Material> unityMaterials,
IAxisInverter axisInverter, MeshExportSettings settings)
IAxisInverter axisInverter, GltfExportSettings settings)
{
var mesh = unityMesh.Mesh;
var materials = unityMesh.Materials;

View File

@ -215,7 +215,7 @@ namespace UniGLTF
// do nothing
}
public virtual void Export(MeshExportSettings meshExportSettings, ITextureSerializer textureSerializer)
public virtual void Export(GltfExportSettings meshExportSettings, ITextureSerializer textureSerializer)
{
var bytesBuffer = new ArrayByteBuffer(new byte[50 * 1024 * 1024]);
var bufferIndex = glTF.AddBuffer(bytesBuffer);

View File

@ -126,7 +126,7 @@ namespace UniGLTF
using (var exporter = new gltfExporter(gltf, Axes.X))
{
exporter.Prepare(root);
var settings = new MeshExportSettings
var settings = new GltfExportSettings
{
ExportOnlyBlendShapePosition = false,
UseSparseAccessorForMorphTarget = false,

View File

@ -61,7 +61,7 @@ namespace UniGLTF
using (var exporter = new gltfExporter(gltf))
{
exporter.Prepare(root);
exporter.Export(MeshExportSettings.Default, new EditorTextureSerializer());
exporter.Export(new GltfExportSettings(), new EditorTextureSerializer());
return gltf.ToGlbBytes();
}
}

View File

@ -26,7 +26,7 @@ namespace UniGLTF
try
{
validator.SetRoot(root, MeshExportSettings.Default, new DefualtBlendShapeExportFilter());
validator.SetRoot(root, new GltfExportSettings(), 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, new DefualtBlendShapeExportFilter());
validator.SetRoot(root, new GltfExportSettings(), 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, new DefualtBlendShapeExportFilter());
validator.SetRoot(root, new GltfExportSettings(), 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, new DefualtBlendShapeExportFilter());
validator.SetRoot(root, new GltfExportSettings(), 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, new DefualtBlendShapeExportFilter());
validator.SetRoot(root, new GltfExportSettings(), new DefualtBlendShapeExportFilter());
var vs = validator.Validate(root);
Assert.True(vs.All(x => x.CanExport));
}

View File

@ -128,7 +128,7 @@ namespace UniGLTF
};
var (go, mesh) = CreateMesh(Materials.ToArray());
var meshExportSettings = new MeshExportSettings
var meshExportSettings = new GltfExportSettings
{
DivideVertexBuffer = false
};
@ -176,7 +176,7 @@ namespace UniGLTF
};
var (go, mesh) = CreateMesh(Materials.ToArray());
var meshExportSettings = new MeshExportSettings
var meshExportSettings = new GltfExportSettings
{
DivideVertexBuffer = true
};

View File

@ -106,7 +106,7 @@ namespace UniGLTF
using (var exporter = new gltfExporter(gltf))
{
exporter.Prepare(go);
exporter.Export(MeshExportSettings.Default, new EditorTextureSerializer());
exporter.Export(new GltfExportSettings(), new EditorTextureSerializer());
// remove empty buffer
gltf.buffers.Clear();
@ -297,7 +297,7 @@ namespace UniGLTF
using (var exporter = new gltfExporter(gltf))
{
exporter.Prepare(CreateSimpleScene());
exporter.Export(MeshExportSettings.Default, new EditorTextureSerializer());
exporter.Export(new GltfExportSettings(), new EditorTextureSerializer());
}
var expected = gltf.ToJson().ParseAsJson();
@ -533,7 +533,7 @@ namespace UniGLTF
using (var exporter = new gltfExporter(gltf))
{
exporter.Prepare(go);
exporter.Export(UniGLTF.MeshExportSettings.Default, new EditorTextureSerializer());
exporter.Export(new UniGLTF.GltfExportSettings(), new EditorTextureSerializer());
json = gltf.ToJson();
}
@ -615,7 +615,7 @@ namespace UniGLTF
using (var exporter = new gltfExporter(gltf))
{
exporter.Prepare(go);
exporter.Export(UniGLTF.MeshExportSettings.Default, new EditorTextureSerializer());
exporter.Export(new UniGLTF.GltfExportSettings(), new EditorTextureSerializer());
json = gltf.ToJson();
}
@ -669,7 +669,7 @@ namespace UniGLTF
}
// validate
validator.SetRoot(root, MeshExportSettings.Default, new DefualtBlendShapeExportFilter());
validator.SetRoot(root, new GltfExportSettings(), new DefualtBlendShapeExportFilter());
var vs = validator.Validate(root);
Assert.True(vs.All(x => x.CanExport));
@ -679,7 +679,7 @@ namespace UniGLTF
using (var exporter = new gltfExporter(gltf))
{
exporter.Prepare(root);
exporter.Export(UniGLTF.MeshExportSettings.Default, new EditorTextureSerializer());
exporter.Export(new UniGLTF.GltfExportSettings(), new EditorTextureSerializer());
json = gltf.ToJson();
}

View File

@ -166,7 +166,7 @@ namespace VRM.Samples
*/
importedJson.RemoveValue(Utf8String.From("/bufferViews/*/byteStride"));
var vrm = VRMExporter.Export(UniGLTF.MeshExportSettings.Default, loaded.gameObject, new EditorTextureSerializer());
var vrm = VRMExporter.Export(new GltfExportSettings(), loaded.gameObject, new EditorTextureSerializer());
// TODO: Check contents in JSON
/*var exportJson = */

View File

@ -92,7 +92,7 @@ namespace VRM.Samples
return;
}
var vrm = VRMExporter.Export(UniGLTF.MeshExportSettings.Default, m_model, new RuntimeTextureSerializer());
var vrm = VRMExporter.Export(new UniGLTF.GltfExportSettings(), m_model, new RuntimeTextureSerializer());
var bytes = vrm.ToGlbBytes();
File.WriteAllBytes(path, bytes);
Debug.LogFormat("export to {0}", path);

View File

@ -50,7 +50,7 @@ namespace VRM
[Tooltip("Divide vertex buffer. For more gltf compatibility")]
public bool DivideVertexBuffer = false;
public MeshExportSettings MeshExportSettings => new MeshExportSettings
public GltfExportSettings MeshExportSettings => new GltfExportSettings
{
UseSparseAccessorForMorphTarget = UseSparseAccessor,
ExportOnlyBlendShapePosition = OnlyBlendshapePosition,

View File

@ -15,7 +15,7 @@ namespace VRM
return new VRMMaterialExporter();
}
public static glTF Export(MeshExportSettings configuration, GameObject go, ITextureSerializer textureSerializer)
public static glTF Export(GltfExportSettings configuration, GameObject go, ITextureSerializer textureSerializer)
{
var gltf = new glTF();
using (var exporter = new VRMExporter(gltf))

View File

@ -105,7 +105,7 @@ namespace VRM
try
{
// export
var vrm = VRMExporter.Export(UniGLTF.MeshExportSettings.Default, go, new EditorTextureSerializer());
var vrm = VRMExporter.Export(new UniGLTF.GltfExportSettings(), go, new EditorTextureSerializer());
// re import
if (vrm != null)

View File

@ -66,7 +66,7 @@ namespace VRM
var path = AliciaPath;
var loaded = Load(File.ReadAllBytes(path), path);
var exported = VRMExporter.Export(new UniGLTF.MeshExportSettings
var exported = VRMExporter.Export(new UniGLTF.GltfExportSettings
{
DivideVertexBuffer = true, // test this
ExportOnlyBlendShapePosition = true,

View File

@ -19,7 +19,7 @@ namespace UniVRM10
[Tooltip("Remove blendShapeClip that preset is Unknown")]
public bool ReduceBlendshapeClip = false;
public MeshExportSettings MeshExportSettings => new MeshExportSettings
public GltfExportSettings MeshExportSettings => new GltfExportSettings
{
UseSparseAccessorForMorphTarget = true,
ExportOnlyBlendShapePosition = true,