@@ -81,29 +81,6 @@ public void ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] unm
81
81
fbxLayer . SetNormals ( fbxLayerElement ) ;
82
82
}
83
83
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
-
107
84
/// Set the binormals on Layer 0.
108
85
using ( var fbxLayerElement = FbxLayerElementBinormal . Create ( fbxMesh , "Binormals" ) )
109
86
{
@@ -140,6 +117,60 @@ public void ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] unm
140
117
}
141
118
fbxLayer . SetTangents ( fbxLayerElement ) ;
142
119
}
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
+ }
143
174
}
144
175
145
176
/// <summary>
@@ -676,7 +707,7 @@ public Vector3 [] Binormals {
676
707
/// TODO: Gets the tangents for the vertices.
677
708
/// </summary>
678
709
/// <value>The tangents.</value>
679
- public Color [ ] VertexColors { get { return mesh . colors ; } }
710
+ public Color32 [ ] VertexColors { get { return mesh . colors32 ; } }
680
711
681
712
/// <summary>
682
713
/// Gets the uvs.
0 commit comments