Sunday, February 15, 2009

Faith Model Continued

I spent several more hours examining the CH_Faith_Cinematic.upk posedAgain StaticMesh. First off, I discovered that my raw data exporter in UE3PackageViewer doesn't seem to work correctly (it cut off half of some of the data). Manually pulling out the data, I found several lists of structures:

struct UnknownStruct1 {
    struct Vertex1 {
        float x;
        float y;
        float z;
    };
    struct Vertex2 {
        float x;
        float y;
        float z;
    };
    int UnknownInt;  /* either 0 or 1 */
    union {
        struct { /* when UnknownInt == 0 */
            short int UnknownStruct1Index;
            short int UnknownStruct1IndexPlus1;
        };
        struct { /* when UnknownInt == 1 */
            short int Count;
            short int TriangleIndex;
        };
    };
};

struct Triangle {
    short int VertexIndexes[3];
    short int UnknownShort; /* material number? */
};

struct Vertex {
    float x;
    float y;
    float z;
};

struct UnknownStruct2 {
    char Unknown1[4];
    char Unknown2[4];
    int NegOne; /* always -1 */
    char Unknown3[4];
};

struct UnknownStruct3 {
    int UnknownInts[4];
};

There is also a large list of shorts and another of bools.

The list of Vertex and Triangle work out to the model in my last post. Of the rest, the list of UnknownStruct1 is the most interesting. Those verts aren't normals or texture coordinates (nearly all are > 1.0). When visualized in space, they hover all around the Faith model.

Additional searching about Unreal meshes led me back to the UnrealToX3D converter. The author wrote a nice white paper about converting the t3d format.

The real challenge was converting the texture coordinates. Unreal textures are described as tiling a plane in space coincident with the polygon on which they lie.

Each surface has a 3D vertex for U, another for V, and another for the texture normal (these are usually orthogonal). A pan value (in UV units) may also be supplied. This scheme allows for arbitrary scale, rotation, shear, and displacement of the texture without having to describe UV coordinates for each vertex on a polygon. To turn these various directionals into common UV coordinates, I find a transform that rotates the polygon from its arbitrary orientation onto the XY plane, and apply the same transform to the U and V texture components. I can now use the transformed U sand V component (which are now co-planar with the XY plane) to scale the texture. Using the pan components as offsets, I now use the polygon's coordinates (which are now all in the XY plane) to produce the UV coordinates.

Could those random points in space actually be 3D UV coordinates? I looked at the faces associated with the points, but the relation doesn't make any sense to me.

I wrote an exporter for this model and structures in Python if you want to look at the data yourself.

Other searching led me to comments in forums that say you can convert StaticMesh to brush in UnrealEd, and then export it as OBJ. I tried poking around but haven't quite found how.

2 comments:

  1. I've tried to adapt your Python script to extract meshes other than the hard-coded Faith model but so far I haven't had much luck.
    I think the problem lies in the data offset, which is different in your script from what UE3 Package Viewer reports.

    Any hints on how to extract other meshes?

    Cheers!

    ReplyDelete
  2. I also suspect the problem is with the data offset. I wish I could help more, but unfortunately everything I know and have tried is already in these two posts. With the update of Gildor's Unreal Mesh Viewer, and the activity in the on-mirrors-edge.com forums, everything I was interested in has pretty much been done already. As a result I don't have plans to dig deeper into these formats. But if I was to continue, the first priority would be to check that UT3PackageViewer is reporting correct offsets.

    If I happen to do any more exploring, I'll be sure to post about it.

    ReplyDelete