![]() |
#1 |
Junior Member
Member
Join Date: Sep 2004
Location: Tampere, Finland
Posts: 14
|
![]()
I wrote a very simple export plugin. If I filter out surfaces only of type POLYGON some (visually random) surfaces don't get exported. So, what surface types exactly are there?
If I smooth the surfaces before exporting, nothing gets exported. The surface type will then be 8 (undocumented) if I remember correctly.. I got things working for now when I process all polygons regardless of their type and just try to triangulate them.. Is this the right way to go? - Mikko |
![]() |
![]() |
![]() |
#2 |
Junior Member
Member
Join Date: Sep 2004
Location: Tampere, Finland
Posts: 14
|
![]()
I ofcourse forgot the most important problem I have:
Vertex normals seem to be all messed up. I read vertex normals from the vertices of triangulated (if not triangle already) surfaces (svertex->v->normal). They aren't even unit vectors, length is close to zero. The normals from the surface itself seems fine, but I need the vertex normals to allow smooth surfaces when rendering the resulting exported model.. Any Ideas what might be wrong? I tried recalculating normals using object_calc_normals_force(), but I didn't help. |
![]() |
![]() |
![]() |
#3 |
Administrator
Professional user
Join Date: Jun 2003
Posts: 4,523
|
![]()
Can you post the main part or send the plugin code?
Andy |
![]() |
![]() |
![]() |
#4 |
Junior Member
Member
Join Date: Sep 2004
Location: Tampere, Finland
Posts: 14
|
![]()
Here comes the essential part of the source code.
FMeshBuilder is an object that generated my mesh format. The line commented out in fmesh_export_triangle_surface() is the line that causes bad normals for vertices.. - - clip - - Code:
static void fmesh_export_triangle_surface(Surface* surface, FMeshBuilder& builder, int materialindex) { printf("exporting surface..\n"); int vertexindex = -1; for(List* v = surface->vertlist; v != NULL; v = v->next) { SVertex* vertex = (SVertex*)v->data; FMeshVector3 pos(vertex->v->x, vertex->v->y, vertex->v->z); // FMeshVector3 n(vertex->v->normal.x, vertex->v->normal.y, vertex->v->normal.z); FMeshVector3 n(surface->normal.x, surface->normal.y, surface->normal.z); FMeshVector3 tc(vertex->tx, vertex->ty, 0); vertexindex = builder.addVertex(pos, &n, &tc); } builder.addFace(materialindex, vertexindex - 2, vertexindex - 1, vertexindex); } static void fmesh_export_object(ACObject* obj, FMeshBuilder& builder) { if(ac_object_get_num_surfaces(obj) > 0) { object_calc_normals_force(obj); printf("exporting object..\n"); int materialindex = -1; char* data = ac_object_get_data(obj); if(data[0]) materialindex = builder.addMaterial(data); else materialindex = builder.addMaterial("default"); printf("materialindex = %u\n", materialindex); List* surfaces = ac_object_get_surfacelist(obj); for (List* s = surfaces; s != NULL; s = s->next) { Surface *surface = (Surface *)s->data; // if(surface->type == SURFACE_POLYGON) { if(surface->numvert == 3) { fmesh_export_triangle_surface(surface, builder, materialindex); } else if(surface->numvert > 3) { // Triangulate surface List* triangles = surface_get_triangulations(surface); for(List* t = triangles; t != NULL; t = t->next) { Surface* triangle = (Surface*)t->data; fmesh_export_triangle_surface(triangle, builder, materialindex); surface_free(triangle); } list_free(&triangles); } else printf("skipping numvert = %d surface ..\n", (int)surface->numvert); } // else // printf("skipping non-polygon surface %d..\n", (int)surface->type); } } List* children = ac_object_get_childrenlist(obj); for(List* c = children; c != NULL; c = c->next) fmesh_export_object((ACObject *)c->data, builder); } static void fmesh_export() { char *filename; FILE *file; char *filter[] = {"fmesh files", ".fmesh", "All files", "*", NULL}; filename = ac_get_save_filename("Export fmesh file", filter); if((filename == NULL) || (*filename =='\0')) return; FMeshBuilder builder; builder.begin("exported", 1, 1, 0); fmesh_export_object(ac_get_world(), builder); builder.writeToFile(filename); } AC3D_PLUGIN_FUNC int AC3DPluginInit(AC3DPluginInitData *d) { double ver = ac_get_version_number(); ac_add_command("fmesh_export_plugin", fmesh_export); ac_add_export_menu_item("fmesh...", "ac3d fmesh_export_plugin"); return(0); } |
![]() |
![]() |
![]() |
#5 |
Administrator
Professional user
Join Date: Jun 2003
Posts: 4,523
|
![]()
There was a bug in surface_get_triangulations where sv normals got messed up. This should have been in the release you have.
See my private message. Andy |
![]() |
![]() |
![]() |
#6 |
Junior Member
Member
Join Date: Sep 2004
Location: Tampere, Finland
Posts: 14
|
![]()
Argh! I'm now using AC3D 5.0 for linux, and the situation isn't any better.
SVertex normals for triangulated surfaces are still at random values (most often [0,0,0]). Should I also update my SDK header and rebuild my plugin with that? The ac_plugin.h that I have seems to be dated 22nd July 1999.. |
![]() |
![]() |
![]() |
#7 |
Junior Member
Member
Join Date: Sep 2004
Location: Tampere, Finland
Posts: 14
|
![]()
The problem isn't in the triangulation anymore. It seems that the vertex normals are bad, even if I triagulate the model manually before exporting. AC3D shows the model correctly smoothed.
I added a printf() in the code below to see, where the normals go bad. All I get is lots of "SVertex normal: (0.000000, 0.000000, 0.000000)" messages.. Code:
static void fmesh_export_triangle_surface(Surface* surface, FMeshBuilder& builder, int materialindex) { printf("exporting surface..\n"); int vertexindex = -1; for(List* v = surface->vertlist; v != NULL; v = v->next) { SVertex* vertex = (SVertex*)v->data; FMeshVector3 pos(vertex->v->x, vertex->v->y, vertex->v->z); //FMeshVector3 n(vertex->v->normal.x, vertex->v->normal.y, vertex->v->normal.z); printf("SVertex normal: (%f, %f, %f)\n", vertex->v->normal.x, vertex->v->normal.y, vertex->v->normal.z); FMeshVector3 n(surface->normal.x, surface->normal.y, surface->normal.z); FMeshVector3 tc(vertex->tx, vertex->ty, 0); vertexindex = builder.addVertex(pos, &n, &tc); } builder.addFace(materialindex, vertexindex - 2, vertexindex - 1, vertexindex); } |
![]() |
![]() |
![]() |
#8 |
Administrator
Professional user
Join Date: Jun 2003
Posts: 4,523
|
![]()
The normal is part of the SVertex and not the Vertex.
You code appears to be accesing a normal which is part of the vertex. I can't see why this would compile, unless you have a very old header file. In your code you should be using vertex->normal. Aha - looked further down your message - a lot has changed since 1999... I'll email you the new headers - which you will need for 5.0 anyway. Andy |
![]() |
![]() |
![]() |
#9 |
Junior Member
Member
Join Date: Sep 2004
Location: Tampere, Finland
Posts: 14
|
![]()
Thanks a lot! I got the exporter plugin working. A six year update did help
![]() |
![]() |
![]() |
![]() |
Thread Tools | |
Display Modes | |
|
|