add VRM Export Option. Reduce BlendShape Size

This commit is contained in:
Kohei-Yanagida
2019-08-28 19:00:41 +09:00
parent eac317c43d
commit 7655d4135b
5 changed files with 28 additions and 11 deletions

View File

@@ -106,13 +106,14 @@ namespace UniGLTF
static gltfMorphTarget ExportMorphTarget(glTF gltf, int bufferIndex,
Mesh mesh, int j,
bool useSparseAccessorForMorphTarget)
bool useSparseAccessorForMorphTarget,
bool exportOnlyBlendShapePosition)
{
var blendShapeVertices = mesh.vertices;
var usePosition = blendShapeVertices != null && blendShapeVertices.Length > 0;
var blendShapeNormals = mesh.normals;
var useNormal = usePosition && blendShapeNormals != null && blendShapeNormals.Length == blendShapeVertices.Length;
var useNormal = usePosition && blendShapeNormals != null && blendShapeNormals.Length == blendShapeVertices.Length && exportOnlyBlendShapePosition;
var blendShapeTangents = mesh.tangents.Select(y => (Vector3)y).ToArray();
//var useTangent = usePosition && blendShapeTangents != null && blendShapeTangents.Length == blendShapeVertices.Length;
@@ -228,7 +229,8 @@ namespace UniGLTF
public static void ExportMeshes(glTF gltf, int bufferIndex,
List<MeshWithRenderer> unityMeshes, List<Material> unityMaterials,
bool useSparseAccessorForMorphTarget)
bool useSparseAccessorForMorphTarget,
bool exportOnlyBlendShapePosition)
{
for (int i = 0; i < unityMeshes.Count; ++i)
{
@@ -244,7 +246,8 @@ namespace UniGLTF
{
var morphTarget = ExportMorphTarget(gltf, bufferIndex,
mesh, j,
useSparseAccessorForMorphTarget);
useSparseAccessorForMorphTarget,
exportOnlyBlendShapePosition);
//
// all primitive has same blendShape

View File

@@ -450,7 +450,7 @@ namespace UniGLTF
{
mesh.AddBlendShapeFrame(blendShape.Name, FRAME_WEIGHT,
blendShape.Positions.ToArray(),
(meshContext.normals != null && meshContext.normals.Length == mesh.vertexCount) ? blendShape.Normals.ToArray() : null,
(meshContext.normals != null && meshContext.normals.Length == mesh.vertexCount && blendShape.Normals.Count() == blendShape.Positions.Count()) ? blendShape.Normals.ToArray() : null,
null
);
}

View File

@@ -60,6 +60,12 @@ namespace UniGLTF
set;
}
public bool ExportOnlyBlendShapePosition
{
get;
set;
}
public GameObject Copy
{
get;
@@ -240,7 +246,7 @@ namespace UniGLTF
return true;
})
.ToList();
MeshExporter.ExportMeshes(gltf, bufferIndex, unityMeshes, Materials, useSparseAccessorForMorphTarget);
MeshExporter.ExportMeshes(gltf, bufferIndex, unityMeshes, Materials, useSparseAccessorForMorphTarget, ExportOnlyBlendShapePosition);
Meshes = unityMeshes.Select(x => x.Mesh).ToList();
#endregion

View File

@@ -6,6 +6,7 @@ using UniGLTF;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif
@@ -26,6 +27,8 @@ namespace VRM
public bool UseExperimentalExporter = true;
public bool ReduceBlendshapeSize = false;
public IEnumerable<string> CanExport()
{
if (Source == null)
@@ -152,6 +155,7 @@ namespace VRM
{
dst.m_center = map[src.m_center];
}
dst.RootBones = src.RootBones.Select(x => map[x]).ToList();
dst.m_hitRadius = src.m_hitRadius;
if (src.ColliderGroups != null)
@@ -271,7 +275,7 @@ namespace VRM
{
var sw = System.Diagnostics.Stopwatch.StartNew();
var vrm = VRMExporter.Export(target);
var vrm = VRMExporter.Export(target, ReduceBlendshapeSize);
vrm.extensions.VRM.meta.title = Title;
vrm.extensions.VRM.meta.author = Author;
@@ -287,4 +291,4 @@ namespace VRM
}
#endif
}
}
}

View File

@@ -19,7 +19,7 @@ namespace VRM
gltf.extensions.VRM = new glTF_VRM_extensions();
}
public new static glTF Export(GameObject go)
public new static glTF Export(GameObject go, bool exportOnlyBlendShapePosition = false)
{
var gltf = new glTF();
@@ -27,12 +27,14 @@ namespace VRM
{
#if VRM_EXPORTER_USE_SPARSE
// experimental
UseSparseAccessorForBlendShape=true
UseSparseAccessorForBlendShape = true
#endif
ExportOnlyBlendShapePosition = exportOnlyBlendShapePosition
})
{
_Export(gltf, exporter, go);
}
return gltf;
}
@@ -60,6 +62,7 @@ namespace VRM
// use description
gltf.extensions.VRM.humanoid.Apply(description, nodes);
}
if (isCreated)
{
GameObject.DestroyImmediate(description);
@@ -119,6 +122,7 @@ namespace VRM
{
gltf.extensions.VRM.meta.texture = TextureIO.ExportTexture(gltf, gltf.buffers.Count - 1, meta.Thumbnail, glTFTextureTypes.Unknown);
}
gltf.extensions.VRM.meta.licenseType = meta.LicenseType;
gltf.extensions.VRM.meta.otherLicenseUrl = meta.OtherLicenseUrl;
gltf.extensions.VRM.meta.reference = meta.Reference;
@@ -208,4 +212,4 @@ namespace VRM
}
}
}
}
}