Skip to content

Commit 0eaf14a

Browse files
authored
Merge pull request #9 from Unity-Technologies/UNI-20526-add-vertex-color
Uni 20526 add vertex color
2 parents 2a49d4b + eeaa408 commit 0eaf14a

File tree

1 file changed

+55
-24
lines changed

1 file changed

+55
-24
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,6 @@ public void ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] unm
8181
fbxLayer.SetNormals (fbxLayerElement);
8282
}
8383

84-
using (var fbxLayerElement = FbxLayerElementUV.Create (fbxMesh, "UVSet")) {
85-
fbxLayerElement.SetMappingMode (FbxLayerElement.EMappingMode.eByPolygonVertex);
86-
fbxLayerElement.SetReferenceMode (FbxLayerElement.EReferenceMode.eIndexToDirect);
87-
88-
// set texture coordinates per vertex
89-
FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray ();
90-
91-
// TODO: only copy unique UVs into this array, and index appropriately
92-
for (int n = 0; n < mesh.UV.Length; n++) {
93-
fbxElementArray.Add (new FbxVector2 (mesh.UV [n] [0],
94-
mesh.UV [n] [1]));
95-
}
96-
97-
// For each face index, point to a texture uv
98-
FbxLayerElementArray fbxIndexArray = fbxLayerElement.GetIndexArray ();
99-
fbxIndexArray.SetCount (unmergedTriangles.Length);
100-
101-
for(int i = 0; i < unmergedTriangles.Length; i++){
102-
fbxIndexArray.SetAt (i, unmergedTriangles [i]);
103-
}
104-
fbxLayer.SetUVs (fbxLayerElement, FbxLayerElement.EType.eTextureDiffuse);
105-
}
106-
10784
/// Set the binormals on Layer 0.
10885
using (var fbxLayerElement = FbxLayerElementBinormal.Create (fbxMesh, "Binormals"))
10986
{
@@ -140,6 +117,60 @@ public void ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] unm
140117
}
141118
fbxLayer.SetTangents (fbxLayerElement);
142119
}
120+
121+
using (var fbxLayerElement = FbxLayerElementUV.Create (fbxMesh, "UVSet"))
122+
{
123+
fbxLayerElement.SetMappingMode (FbxLayerElement.EMappingMode.eByPolygonVertex);
124+
fbxLayerElement.SetReferenceMode (FbxLayerElement.EReferenceMode.eIndexToDirect);
125+
126+
// set texture coordinates per vertex
127+
FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray ();
128+
129+
// TODO: only copy unique UVs into this array, and index appropriately
130+
for (int n = 0; n < mesh.UV.Length; n++) {
131+
fbxElementArray.Add (new FbxVector2 (mesh.UV [n] [0],
132+
mesh.UV [n] [1]));
133+
}
134+
135+
// For each face index, point to a texture uv
136+
FbxLayerElementArray fbxIndexArray = fbxLayerElement.GetIndexArray ();
137+
fbxIndexArray.SetCount (unmergedTriangles.Length);
138+
139+
for(int i = 0; i < unmergedTriangles.Length; i++){
140+
fbxIndexArray.SetAt (i, unmergedTriangles [i]);
141+
}
142+
fbxLayer.SetUVs (fbxLayerElement, FbxLayerElement.EType.eTextureDiffuse);
143+
}
144+
145+
using (var fbxLayerElement = FbxLayerElementVertexColor.Create (fbxMesh, "VertexColors"))
146+
{
147+
fbxLayerElement.SetMappingMode (FbxLayerElement.EMappingMode.eByPolygonVertex);
148+
fbxLayerElement.SetReferenceMode (FbxLayerElement.EReferenceMode.eIndexToDirect);
149+
150+
// set texture coordinates per vertex
151+
FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray ();
152+
153+
// TODO: only copy unique UVs into this array, and index appropriately
154+
for (int n = 0; n < mesh.VertexColors.Length; n++) {
155+
// Converting to Color from Color32, as Color32 stores the colors
156+
// as ints between 0-255, while FbxColor and Color
157+
// use doubles between 0-1
158+
Color color = mesh.VertexColors [n];
159+
fbxElementArray.Add (new FbxColor (color.r,
160+
color.g,
161+
color.b,
162+
color.a));
163+
}
164+
165+
// For each face index, point to a texture uv
166+
FbxLayerElementArray fbxIndexArray = fbxLayerElement.GetIndexArray ();
167+
fbxIndexArray.SetCount (unmergedTriangles.Length);
168+
169+
for(int i = 0; i < unmergedTriangles.Length; i++){
170+
fbxIndexArray.SetAt (i, unmergedTriangles [i]);
171+
}
172+
fbxLayer.SetVertexColors (fbxLayerElement);
173+
}
143174
}
144175

145176
/// <summary>
@@ -676,7 +707,7 @@ public Vector3 [] Binormals {
676707
/// TODO: Gets the tangents for the vertices.
677708
/// </summary>
678709
/// <value>The tangents.</value>
679-
public Color [] VertexColors { get { return mesh.colors; } }
710+
public Color32 [] VertexColors { get { return mesh.colors32; } }
680711

681712
/// <summary>
682713
/// Gets the uvs.

0 commit comments

Comments
 (0)