KellanHiggins / AsciiFBXExporterForUnity

A tool to export any Unity GameObject into a FBX ASCII format
Other
806 stars 165 forks source link

Supporting full set of vertex properties #4

Closed artyom-zuev closed 7 years ago

artyom-zuev commented 8 years ago

Since FBX supports that along with Mesh, it would be nice to export a second UV channel and vertex colors into the generated FBX files.

A bit of reference just in case:

All vertices pack a number of properties. In addition to the most popular ones, like position (Vector3, or in other words, three floats), tangent (Vector3), normal (Vector3) and UV (Vector2), they can also carry Color (in other words, four bytes) and multiple additional UV channels (up to four).

Color name shouldn't be taken literally, it's just another place to store data. Vertex color alpha can store ambient occlusion intensity baked per vertex, RGB space can be used similarly to stencil masks or to drive lerping operations as factors directly, or individual channels can pack data like emission intensity, smoothness, metalness and so on. Vertex colors are used in an immeasurable number of artistic workflows, because who wouldn't like to pass non-mesh-wide properties to the shader code without touching any textures and texture samplers?

https://docs.unity3d.com/ScriptReference/Mesh-colors.html https://docs.unity3d.com/ScriptReference/Mesh-uv2.html

KellanHiggins commented 8 years ago

Best way to figure this out is by posting a FBX file that you are sure has vertex colors in it. Then I can decode it and see how it is implemented in the FBX file.

RobertButterworth commented 8 years ago

vertexcolor

vertexColor.fbx.txt

In the Object Block:

Objects: { Geometry: 1899319627888, "Geometry::", "Mesh" {

Color is RGBA:

LayerElementColor: 0 { Version: 101 Name: "colorSet1" MappingInformationType: "ByPolygonVertex" ReferenceInformationType: "IndexToDirect" Colors: 16 { a: 0,1,0,1,1,0,0,1,0,0,1,1,1,1,1,1 } ColorIndex: 4 { a: 0,1,2,3 } }

KellanHiggins commented 8 years ago

If I am understanding correctly, every Unity Mesh has colors already built in as extra information correct? So we can export that with the FBX exporter right?

artyom-zuev commented 8 years ago

Yes, unity mesh has a Color array "colors", meant to store RGBA vertex color imported from many formats. Before using it though, validate that it's not null and that its length is equal to vertex count of a mesh - there are cases where that wouldn't be the case, for example if the Mesh was produced by importing a file without vertex colors, or if a user modified mesh import settings to remove vertex colors. :)

KellanHiggins commented 7 years ago

Sorry for the long reply. Can you throw me an object with colors inserted into it so I can test easily?

KellanHiggins commented 7 years ago

This is now IN! @Totchinuko did it. Enjoy :)