Search Unity

Modified OBJ Export script includes multiple UVs and colors

Discussion in 'Scripting' started by tgraupmann, Feb 12, 2009.

  1. tgraupmann


    Sep 14, 2007
    There's an example Wavefront OBJ export script in the Wiki. It let's you export a UnityEngine.Mesh object.

    The Wavefront OBJ specification does not provide a way to save the Vertex color (other than using model colors in the MTL file). It also does not save multiple UVsets.

    So I've modified the OBJ export script to include "vc" for vertex color and "vt1" for uv1 and "vt2" for uv2.

    I've also created a Modo WaveFrontObj Perl script that can load the mesh with Colors and uvsets and create the proper vertex maps.

    ObjExporterScript has two static methods:
    Code (csharp):
    1. public static string MeshToString(MeshFilter mf)
    This converts the Mesh on a MeshFilter to a Wavefront OBJ as a string.

    Code (csharp):
    1. public static void MeshToFile(MeshFilter mf, string filename, bool append)
    This calls MeshToString with the mesh filter and then saves to a file. It can either overwrite the destination or append to it.

    In Modo, hit F6, select the Perl script and you'll get a File Open dialog to select the Wavefront OBJ for import.

    See attached.

    Attached Files: