@@ -81,30 +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
- {
86
- fbxLayerElement . SetMappingMode ( FbxLayerElement . EMappingMode . eByPolygonVertex ) ;
87
- fbxLayerElement . SetReferenceMode ( FbxLayerElement . EReferenceMode . eIndexToDirect ) ;
88
-
89
- // set texture coordinates per vertex
90
- FbxLayerElementArray fbxElementArray = fbxLayerElement . GetDirectArray ( ) ;
91
-
92
- // TODO: only copy unique UVs into this array, and index appropriately
93
- for ( int n = 0 ; n < mesh . UV . Length ; n ++ ) {
94
- fbxElementArray . Add ( new FbxVector2 ( mesh . UV [ n ] [ 0 ] ,
95
- mesh . UV [ n ] [ 1 ] ) ) ;
96
- }
97
-
98
- // For each face index, point to a texture uv
99
- FbxLayerElementArray fbxIndexArray = fbxLayerElement . GetIndexArray ( ) ;
100
- fbxIndexArray . SetCount ( unmergedTriangles . Length ) ;
101
-
102
- for ( int i = 0 ; i < unmergedTriangles . Length ; i ++ ) {
103
- fbxIndexArray . SetAt ( i , unmergedTriangles [ i ] ) ;
104
- }
105
- fbxLayer . SetUVs ( fbxLayerElement , FbxLayerElement . EType . eTextureDiffuse ) ;
106
- }
107
-
108
84
/// Set the binormals on Layer 0.
109
85
using ( var fbxLayerElement = FbxLayerElementBinormal . Create ( fbxMesh , "Binormals" ) )
110
86
{
@@ -140,6 +116,60 @@ public void ExportComponentAttributes (MeshInfo mesh, FbxMesh fbxMesh, int[] unm
140
116
}
141
117
fbxLayer . SetTangents ( fbxLayerElement ) ;
142
118
}
119
+
120
+ using ( var fbxLayerElement = FbxLayerElementUV . Create ( fbxMesh , "UVSet" ) )
121
+ {
122
+ fbxLayerElement . SetMappingMode ( FbxLayerElement . EMappingMode . eByPolygonVertex ) ;
123
+ fbxLayerElement . SetReferenceMode ( FbxLayerElement . EReferenceMode . eIndexToDirect ) ;
124
+
125
+ // set texture coordinates per vertex
126
+ FbxLayerElementArray fbxElementArray = fbxLayerElement . GetDirectArray ( ) ;
127
+
128
+ // TODO: only copy unique UVs into this array, and index appropriately
129
+ for ( int n = 0 ; n < mesh . UV . Length ; n ++ ) {
130
+ fbxElementArray . Add ( new FbxVector2 ( mesh . UV [ n ] [ 0 ] ,
131
+ mesh . UV [ n ] [ 1 ] ) ) ;
132
+ }
133
+
134
+ // For each face index, point to a texture uv
135
+ FbxLayerElementArray fbxIndexArray = fbxLayerElement . GetIndexArray ( ) ;
136
+ fbxIndexArray . SetCount ( unmergedTriangles . Length ) ;
137
+
138
+ for ( int i = 0 ; i < unmergedTriangles . Length ; i ++ ) {
139
+ fbxIndexArray . SetAt ( i , unmergedTriangles [ i ] ) ;
140
+ }
141
+ fbxLayer . SetUVs ( fbxLayerElement , FbxLayerElement . EType . eTextureDiffuse ) ;
142
+ }
143
+
144
+ using ( var fbxLayerElement = FbxLayerElementVertexColor . Create ( fbxMesh , "VertexColors" ) )
145
+ {
146
+ fbxLayerElement . SetMappingMode ( FbxLayerElement . EMappingMode . eByPolygonVertex ) ;
147
+ fbxLayerElement . SetReferenceMode ( FbxLayerElement . EReferenceMode . eIndexToDirect ) ;
148
+
149
+ // set texture coordinates per vertex
150
+ FbxLayerElementArray fbxElementArray = fbxLayerElement . GetDirectArray ( ) ;
151
+
152
+ // TODO: only copy unique UVs into this array, and index appropriately
153
+ for ( int n = 0 ; n < mesh . VertexColors . Length ; n ++ ) {
154
+ // Converting to Color from Color32, as Color32 stores the colors
155
+ // as ints between 0-255, while FbxColor and Color
156
+ // use doubles between 0-1
157
+ Color color = mesh . VertexColors [ n ] ;
158
+ fbxElementArray . Add ( new FbxColor ( color . r ,
159
+ color . g ,
160
+ color . b ,
161
+ color . a ) ) ;
162
+ }
163
+
164
+ // For each face index, point to a texture uv
165
+ FbxLayerElementArray fbxIndexArray = fbxLayerElement . GetIndexArray ( ) ;
166
+ fbxIndexArray . SetCount ( unmergedTriangles . Length ) ;
167
+
168
+ for ( int i = 0 ; i < unmergedTriangles . Length ; i ++ ) {
169
+ fbxIndexArray . SetAt ( i , unmergedTriangles [ i ] ) ;
170
+ }
171
+ fbxLayer . SetVertexColors ( fbxLayerElement ) ;
172
+ }
143
173
}
144
174
145
175
/// <summary>
@@ -652,7 +682,7 @@ public Vector3 [] Binormals
652
682
/// TODO: Gets the tangents for the vertices.
653
683
/// </summary>
654
684
/// <value>The tangents.</value>
655
- public Color [ ] VertexColors { get { return mesh . colors ; } }
685
+ public Color32 [ ] VertexColors { get { return mesh . colors32 ; } }
656
686
657
687
/// <summary>
658
688
/// Gets the uvs.
0 commit comments