Skip to content

Commit

Permalink
feat(export): Legacy vertex color support
Browse files Browse the repository at this point in the history
  • Loading branch information
atteneder committed Feb 23, 2022
1 parent b526840 commit fac43d4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Runtime/Scripts/Export/GltfWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,6 @@ void BakeMeshLegacy(int meshId) {
var attribute = vertexAttributes[streamId];

switch (attribute.attribute) {
case VertexAttribute.Color:
case VertexAttribute.BlendWeight:
case VertexAttribute.BlendIndices:
Debug.LogWarning($"Vertex attribute {attribute.attribute} is not supported yet");
Expand Down Expand Up @@ -997,6 +996,8 @@ void BakeMeshLegacy(int meshId) {
attributes.TANGENT = accessorId;
break;
case VertexAttribute.Color:
accessor.componentType = GLTFComponentType.UnsignedByte;
accessor.normalized = true;
attributes.COLOR_0 = accessorId;
break;
case VertexAttribute.TexCoord0:
Expand Down Expand Up @@ -1229,8 +1230,20 @@ void BakeMeshLegacy(int meshId) {
outStream.Dispose();
break;
}
case VertexAttribute.Color:
case VertexAttribute.Color: {
var colors = new List<Color32>();
uMesh.GetColors(colors);
var outStream = new NativeArray<Color32>(colors.Count, Allocator.TempJob);
for (var i = 0; i < colors.Count; i++) {
outStream[i] = colors[i];
}
bufferViewId = WriteBufferViewToBuffer(
outStream.Reinterpret<byte>(4),
4
);
outStream.Dispose();
break;
}
case VertexAttribute.TexCoord0:
case VertexAttribute.TexCoord1:
case VertexAttribute.TexCoord2:
Expand Down

0 comments on commit fac43d4

Please sign in to comment.