Unity to sketchfab. Vertex Color

(Creativemood) #1

Hi all! How i can export vertex color from the scene? I have to build the level again without this option(

(Waleguene) #2

Hi @creativemood,

Our current Unity exporter is old and doesn't support vertex colors, so to get them you have two solution:
- Export your scene from another software (that exports vertex colors)
- Add some lines in the plugin code to export them from unity

For the second point, it's not really hard to do, you only have to concatenate colors with vertex positions.
If you look at SketchfabExporterWindow.cs, line 180, you should have:

		foreach(Vector3 lv in m.vertices) {
			Vector3 wv = mf.transform.TransformPoint(lv);
			//This is sort of ugly - inverting x-component since we're in
			//a different coordinate system than "everyone" is "used to".
			sb.Append(string.Format("v {0} {1} {2}\n",-wv.x,wv.y,wv.z));

You will export vertex colors by replacing the previous snippet with:

		Vector3[] verts = m.vertices;
		Color[] colors = m.colors;
		for (int i = 0; i < verts.Length; ++i)
			Vector3 wv = mf.transform.TransformPoint(verts[i]);
			if (colors.Length > 0)
				sb.Append(string.Format("v {0} {1} {2} {3} {4} {5} {6}\n", -wv.x, wv.y, wv.z, colors[i].r, colors[i].g, colors[i].b, colors[i].a));
				sb.Append(string.Format("v {0} {1} {2}\n", -wv.x, wv.y, wv.z));

If you have some skinned meshes with vertex colors, you will need to do the same at line 149.

This is a quick fix to help you fix your issue, but note that we are working on a new version that will have much more features than this one that becomes deprecated

(Creativemood) #3

A huge thank you for the fast reply and the solutions!
I hope this will help not only me.