mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-10 04:49:28 -05:00
Add an option to remove vertex color in export menu
This commit is contained in:
@@ -18,7 +18,8 @@ namespace UniGLTF
|
||||
static glTFMesh ExportPrimitives(glTF gltf, int bufferIndex,
|
||||
string rendererName,
|
||||
Mesh mesh, Material[] materials,
|
||||
List<Material> unityMaterials)
|
||||
List<Material> unityMaterials,
|
||||
bool removeVertexColor)
|
||||
{
|
||||
var positions = mesh.vertices.Select(y => y.ReverseZ()).ToArray();
|
||||
var positionAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, positions, glBufferTarget.ARRAY_BUFFER);
|
||||
@@ -30,7 +31,10 @@ namespace UniGLTF
|
||||
var tangentAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, mesh.tangents.Select(y => y.ReverseZ()).ToArray(), glBufferTarget.ARRAY_BUFFER);
|
||||
#endif
|
||||
var uvAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, mesh.uv.Select(y => y.ReverseUV()).ToArray(), glBufferTarget.ARRAY_BUFFER);
|
||||
var colorAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, mesh.colors, glBufferTarget.ARRAY_BUFFER);
|
||||
|
||||
var colorAccessorIndex = -1;
|
||||
if (!removeVertexColor)
|
||||
colorAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, mesh.colors, glBufferTarget.ARRAY_BUFFER);
|
||||
|
||||
var boneweights = mesh.boneWeights;
|
||||
var weightAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, boneweights.Select(y => new Vector4(y.weight0, y.weight1, y.weight2, y.weight3)).ToArray(), glBufferTarget.ARRAY_BUFFER);
|
||||
@@ -231,7 +235,8 @@ namespace UniGLTF
|
||||
public static void ExportMeshes(glTF gltf, int bufferIndex,
|
||||
List<MeshWithRenderer> unityMeshes, List<Material> unityMaterials,
|
||||
bool useSparseAccessorForMorphTarget,
|
||||
bool exportOnlyBlendShapePosition)
|
||||
bool exportOnlyBlendShapePosition,
|
||||
bool removeVertexColor)
|
||||
{
|
||||
for (int i = 0; i < unityMeshes.Count; ++i)
|
||||
{
|
||||
@@ -241,7 +246,7 @@ namespace UniGLTF
|
||||
|
||||
var gltfMesh = ExportPrimitives(gltf, bufferIndex,
|
||||
x.Renderer.name,
|
||||
mesh, materials, unityMaterials);
|
||||
mesh, materials, unityMaterials, removeVertexColor);
|
||||
|
||||
for (int j = 0; j < mesh.blendShapeCount; ++j)
|
||||
{
|
||||
|
||||
@@ -66,6 +66,12 @@ namespace UniGLTF
|
||||
set;
|
||||
}
|
||||
|
||||
public bool RemoveVertexColor
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public GameObject Copy
|
||||
{
|
||||
get;
|
||||
@@ -142,7 +148,7 @@ namespace UniGLTF
|
||||
|
||||
public void Export()
|
||||
{
|
||||
FromGameObject(glTF, Copy, UseSparseAccessorForBlendShape);
|
||||
FromGameObject(glTF, Copy, UseSparseAccessorForBlendShape, RemoveVertexColor);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -188,7 +194,8 @@ namespace UniGLTF
|
||||
return node;
|
||||
}
|
||||
|
||||
void FromGameObject(glTF gltf, GameObject go, bool useSparseAccessorForMorphTarget = false)
|
||||
void FromGameObject(glTF gltf, GameObject go, bool useSparseAccessorForMorphTarget = false,
|
||||
bool removeVertexColor = false)
|
||||
{
|
||||
var bytesBuffer = new ArrayByteBuffer(new byte[50 * 1024 * 1024]);
|
||||
var bufferIndex = gltf.AddBuffer(bytesBuffer);
|
||||
@@ -247,7 +254,8 @@ namespace UniGLTF
|
||||
return true;
|
||||
})
|
||||
.ToList();
|
||||
MeshExporter.ExportMeshes(gltf, bufferIndex, unityMeshes, Materials, useSparseAccessorForMorphTarget, ExportOnlyBlendShapePosition);
|
||||
MeshExporter.ExportMeshes(gltf, bufferIndex, unityMeshes, Materials, useSparseAccessorForMorphTarget,
|
||||
ExportOnlyBlendShapePosition, removeVertexColor);
|
||||
Meshes = unityMeshes.Select(x => x.Mesh).ToList();
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -152,7 +152,8 @@ namespace VRM
|
||||
var vrm = VRMExporter.Export(target, new VRMExporterConfiguration
|
||||
{
|
||||
UseSparseAccessorForBlendShape = settings.UseSparseAccessor,
|
||||
ExportOnlyBlendShapePosition = settings.OnlyBlendshapePosition
|
||||
ExportOnlyBlendShapePosition = settings.OnlyBlendshapePosition,
|
||||
RemoveVertexColor = settings.RemoveVertexColor
|
||||
});
|
||||
vrm.extensions.VRM.meta.title = settings.Title;
|
||||
vrm.extensions.VRM.meta.version = settings.Version;
|
||||
|
||||
@@ -84,6 +84,12 @@ namespace VRM
|
||||
/// </summary>
|
||||
[Tooltip("Remove blendShapeClip that preset is Unknown")]
|
||||
public bool ReduceBlendshapeClip = false;
|
||||
|
||||
/// <summary>
|
||||
/// 頂点カラーを削除する
|
||||
/// </summary>
|
||||
[Tooltip("Remove vertex color")]
|
||||
public bool RemoveVertexColor = false;
|
||||
#endregion
|
||||
|
||||
public struct Validation
|
||||
@@ -186,6 +192,12 @@ namespace VRM
|
||||
{
|
||||
yield return Validation.Error("ReduceBlendshapeSize is need VRMBlendShapeProxy, you need to convert to VRM once.");
|
||||
}
|
||||
|
||||
var vertexColor = Source.GetComponentsInChildren<SkinnedMeshRenderer>().ToList().Any(x => x.sharedMesh.colors.Length > 0);
|
||||
if (vertexColor)
|
||||
{
|
||||
yield return Validation.Warning("This model contains vertex color");
|
||||
}
|
||||
|
||||
var renderers = Source.GetComponentsInChildren<Renderer>();
|
||||
if (renderers.All(x => !x.gameObject.activeInHierarchy))
|
||||
|
||||
@@ -33,7 +33,8 @@ namespace VRM
|
||||
using (var exporter = new VRMExporter(gltf)
|
||||
{
|
||||
UseSparseAccessorForBlendShape = configuration.UseSparseAccessorForBlendShape,
|
||||
ExportOnlyBlendShapePosition = configuration.ExportOnlyBlendShapePosition
|
||||
ExportOnlyBlendShapePosition = configuration.ExportOnlyBlendShapePosition,
|
||||
RemoveVertexColor = configuration.RemoveVertexColor,
|
||||
})
|
||||
{
|
||||
_Export(gltf, exporter, go);
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
{
|
||||
public bool UseSparseAccessorForBlendShape;
|
||||
public bool ExportOnlyBlendShapePosition;
|
||||
public bool RemoveVertexColor;
|
||||
|
||||
public static VRMExporterConfiguration Default => new VRMExporterConfiguration
|
||||
{
|
||||
UseSparseAccessorForBlendShape = true,
|
||||
ExportOnlyBlendShapePosition = false,
|
||||
RemoveVertexColor = false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user