View Single Post
Old 25th January 2022, 06:31 AM   #14
Professional user
Andy's Avatar
Join Date: Jun 2003
Posts: 4,451
Default Re: Metasequoia (.mqo) export?

Wow! Most impressive. I think an AC3D plugin that exports the format you want would probably be less complicated.

Here is the main code for a simple exporter.It would be easy to transform coordinates, add texture info, etc.

static void sv_output_triangle(FILE *f, List *vertices, Surface *s)
SVertex *p1, *p2, *p3;
int col;
int id1, id2, id3; 

    // get SVertexes for this triangle
    // SVertex contains vertex pointer, texture cordinates and the normal

    p1 = (SVertex *)(s->vertlist->data);
    p2 = (SVertex *)(s->vertlist->next->data);
    p3 = (SVertex *)(s->vertlist->next->next->data);

    // get int positions of each vertex within the main object list
    id1 = list_index(vertices, p1->v);
    id2 = list_index(vertices, p2->v);
    id3 = list_index(vertices, p3->v);

    fprintf(f, "%d %d %d ", id1, id2, id3); 

    sv_output_col(f, s->col);

static void sv_output_surfaces(FILE *f, List *vertices, List *triangs)
    /** go through the triangle list and output each **/
    for (List *p = triangs; p != NULL; p = p->next)
        Surface *s = (Surface *)p->data;
        sv_output_triangle(f, vertices, s);

static void sv_output_object(FILE *f, ACObject *ob)
int numvert, numsurf, numkids;
List *vertices, *surfaces, *kids;
List *p;

    printf("outputing %s\n", ac_object_get_name(ob));

    ac_object_get_contents(ob, &numvert, &numsurf, &numkids,
        &vertices, &surfaces, &kids); 

    // we are only interested in triangles, so we a list of triangulated surfaces
    List *triangs = ac_object_get_triangle_surfaces(ob); // get list of triangles (ignores lines/polyline surfaces)

    int numtri = list_count(triangs);

    if (numtri > 0)
        fprintf(f, "%d\n", numvert); // output number of vertices
        for (p = vertices; p != NULL; p = p->next) // output each vertex
            Vertex *v = (Vertex *)p->data;

            fprintf(f, "%f %f %f\n", v->x, v->y, v->z);
        fprintf(f, "%d\n", numtri); /** output the number of triangles **/
        sv_output_surfaces(f, vertices, triangs); // output number of surfaces and each surface

    ac_surfacelist_free(&triangs); // important - free the surfaces (and list) created from ac_object_get_triangle_surfaces

    for (p = kids; p != NULL; p = p->next) // output any children objects
        sv_output_object(f, (ACObject *)p->data);
Andy is offline   Reply With Quote