# HG changeset patch # User John Tsiombikas # Date 1380384770 -10800 # Node ID d0260d80ae0930b3221b0f3fc57281fcb48d5faf # Parent 6b651613bd9f3478e7e47de15e9362ded39475ed adding the nodes interface, and continuing the max plugin diff -r 6b651613bd9f -r d0260d80ae09 exporters/maxgoat/maxgoat.vcxproj --- a/exporters/maxgoat/maxgoat.vcxproj Sat Sep 28 06:32:00 2013 +0300 +++ b/exporters/maxgoat/maxgoat.vcxproj Sat Sep 28 19:12:50 2013 +0300 @@ -100,6 +100,7 @@ Disabled WIN32;_DEBUG;_WINDOWS;_USRDLL;MAXGOAT_EXPORTS;%(PreprocessorDefinitions) 4996 + $(SolutionDir)\src Windows @@ -139,6 +140,7 @@ true WIN32;NDEBUG;_WINDOWS;_USRDLL;MAXGOAT_EXPORTS;%(PreprocessorDefinitions) 4996 + $(SolutionDir)\src Windows diff -r 6b651613bd9f -r d0260d80ae09 exporters/maxgoat/src/maxgoat.cc --- a/exporters/maxgoat/src/maxgoat.cc Sat Sep 28 06:32:00 2013 +0300 +++ b/exporters/maxgoat/src/maxgoat.cc Sat Sep 28 19:12:50 2013 +0300 @@ -10,6 +10,7 @@ #include "IGame.h" #include "IGameExport.h" #include "IConversionmanager.h" +#include "goat3d.h" #include "config.h" @@ -48,7 +49,9 @@ int DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent = FALSE, DWORD opt = 0); - bool export_materials(FILE *fp); + void export_materials(goat3d *goat); + void export_meshes(goat3d *goat); + void process_node(goat3d *goat, IGameNode *maxnode); }; @@ -108,15 +111,8 @@ char fname[512]; wcstombs(fname, name, sizeof fname - 1); - FILE *fp = fopen(fname, "wb"); - if(!fp) { - fprintf(logfile, "failed to open %s for writting: %s", fname, strerror(errno)); - return IMPEXP_FAIL; - } - if(!(igame = GetIGameInterface())) { fprintf(logfile, "failed to get the igame interface\n"); - fclose(fp); return IMPEXP_FAIL; } IGameConversionManager *cm = GetConversionManager(); @@ -124,64 +120,128 @@ igame->InitialiseIGame(); igame->SetStaticFrame(0); - export_materials(fp); + goat3d *goat = goat3d_create(); - fclose(fp); + export_materials(goat); + export_meshes(goat); + if(goat3d_save(goat, fname) == -1) { + goat3d_free(goat); + return IMPEXP_FAIL; + } + + // process all nodes + for(int i=0; iGetTopLevelNodeCount(); i++) { + IGameNode *node = igame->GetTopLevelNode(i); + process_node(goat, node); + } + + goat3d_free(goat); return IMPEXP_SUCCESS; } -bool GoatExporter::export_materials(FILE *fp) +static const char *max_string(const MCHAR *wstr) +{ + if(!wstr) return 0; + static char str[512]; + wcstombs(str, wstr, sizeof str - 1); + return str; +} + +void GoatExporter::export_materials(goat3d *goat) { IGameProperty *prop; int num_mtl = igame->GetRootMaterialCount(); - fprintf(fp, "number of materials: %d\n", num_mtl); + for(int i=0; iGetRootMaterial(i); + if(maxmtl) { + goat3d_material *mtl = goat3d_create_mtl(); - for(int i=0; iGetRootMaterial(i); - if(mtl) { - Point3 diffuse(1, 1, 1); - Point3 specular(0, 0, 0); - float shin = 1.0, sstr = 1.0; - char name[512] = "unnamed"; - - const MCHAR *wname = mtl->GetMaterialName(); - if(wname) { - wcstombs(name, wname, sizeof name - 1); + const char *name = max_string(maxmtl->GetMaterialName()); + if(name) { + goat3d_set_mtl_name(mtl, name); } - if((prop = mtl->GetDiffuseData())) { + // diffuse + if((prop = maxmtl->GetDiffuseData())) { + Point3 diffuse(1, 1, 1); prop->GetPropertyValue(diffuse); + goat3d_set_mtl_attrib3f(mtl, GOAT3D_MAT_ATTR_DIFFUSE, diffuse[0], + diffuse[1], diffuse[2]); } - if((prop = mtl->GetSpecularData())) { + // specular + if((prop = maxmtl->GetSpecularData())) { + Point3 specular(0, 0, 0); prop->GetPropertyValue(specular); + + float sstr = 1.0; + if((prop = maxmtl->GetSpecularLevelData())) { + prop->GetPropertyValue(sstr); + } + goat3d_set_mtl_attrib3f(mtl, GOAT3D_MAT_ATTR_SPECULAR, specular[0] * sstr, + specular[1] * sstr, specular[2] * sstr); } - if((prop = mtl->GetSpecularLevelData())) { - prop->GetPropertyValue(sstr); - } - if((prop = mtl->GetGlossinessData())) { + // shininess + if((prop = maxmtl->GetGlossinessData())) { + float shin; prop->GetPropertyValue(shin); + goat3d_set_mtl_attrib1f(mtl, GOAT3D_MAT_ATTR_SHININESS, shin * 100.0); } - fprintf(fp, "Material %d (%s):\n", i, name); - fprintf(fp, " diffuse: %f %f %f\n", diffuse[0], diffuse[1], diffuse[2]); - fprintf(fp, " specular: %f %f %f\n", specular[0] * sstr, specular[1] * sstr, specular[2] * sstr); - fprintf(fp, " shininess: %f\n", shin * 100.0); + // textures + for(int j=0; jGetNumberOfTextureMaps(); j++) { + IGameTextureMap *tex = maxmtl->GetIGameTextureMap(j); - for(int j=0; jGetNumberOfTextureMaps(); j++) { - IGameTextureMap *tex = mtl->GetIGameTextureMap(j); - const MCHAR *wfname = tex->GetBitmapFileName(); - if(wfname) { - char fname[512]; - wcstombs(fname, wfname, sizeof fname - 1); - fprintf(fp, " texture%d: %s\n", j, fname); + const char *fname = max_string(tex->GetBitmapFileName()); + if(!fname) { + continue; + } + + int slot = tex->GetStdMapSlot(); + switch(slot) { + case ID_DI: // diffuse + goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_DIFFUSE, fname); + break; + + case ID_SP: + case ID_SS: + goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_SPECULAR, fname); + break; + + case ID_SH: + goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_SHININESS, fname); + break; + + case ID_BU: + goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_NORMAL, fname); + break; + + case ID_RL: + goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_REFLECTION, fname); + break; + + case ID_RR: + goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_TRANSMISSION, fname); + break; + + default: + break; } } + + goat3d_add_mtl(goat, mtl); } } +} - return true; +void GoatExporter::export_meshes(goat3d *goat) +{ + Tab meshes = igame->GetIGameNodeByType(IGameObject::IGAME_MESH); + + for(int i=0; iGetName()); + } } // ------------------------------------------ diff -r 6b651613bd9f -r d0260d80ae09 src/goat3d.cc --- a/src/goat3d.cc Sat Sep 28 06:32:00 2013 +0300 +++ b/src/goat3d.cc Sat Sep 28 19:12:50 2013 +0300 @@ -475,6 +475,93 @@ } +// node + +struct goat3d_node *goat3d_create_node(void) +{ + return new goat3d_node; +} + +void goat3d_set_node_name(struct goat3d_node *node, const char *name) +{ + node->set_name(name); +} + +const char *goat3d_get_node_name(struct goat3d_node *node) +{ + return node->get_name(); +} + +void goat3d_set_node_object(struct goat3d_node *node, enum goat3d_node_type type, void *obj) +{ + node->set_object((Object*)obj); +} + +// TODO cont. + +void *goat3d_get_node_object(struct goat3d_node *node) +{ + return 0; +} + +enum goat3d_node_type goat3d_get_node_type(struct goat3d_node *node) +{ + return GOAT3D_NODE_MESH; // TODO +} + +void goat3d_add_node_child(struct goat3d_node *node, struct goat3d_node *child) +{ +} + +int goat3d_get_node_child_count(struct goat3d_node *node) +{ + return 0; +} + +struct goat3d_node *goat3d_get_node_child(struct goat3d_node *node, int idx) +{ + return 0; +} + +void goat3d_set_node_position(struct goat3d_node *node, float x, float y, float z, long tmsec) +{ +} + +void goat3d_set_node_rotation(struct goat3d_node *node, float qx, float qy, float qz, float qw, long tmsec) +{ +} + +void goat3d_set_node_scaling(struct goat3d_node *node, float sx, float sy, float sz, long tmsec) +{ +} + +void goat3d_set_node_pivot(struct goat3d_node *node, float px, float py, float pz) +{ +} + + +void goat3d_get_node_position(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec) +{ +} + +void goat3d_get_node_rotation(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, float *wptr, long tmsec) +{ +} + +void goat3d_get_node_scaling(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec) +{ +} + +void goat3d_get_node_pivot(struct goat3d_node *node, float *xptr, float *yptr, float *zptr) +{ +} + + +void goat3d_get_node_matrix(struct goat3d_node *node, float *matrix, long tmsec) +{ +} + + } // extern "C" diff -r 6b651613bd9f -r d0260d80ae09 src/goat3d.h --- a/src/goat3d.h Sat Sep 28 06:32:00 2013 +0300 +++ b/src/goat3d.h Sat Sep 28 19:12:50 2013 +0300 @@ -25,6 +25,12 @@ NUM_GOAT3D_MESH_ATTRIBS }; +enum goat3d_node_type { + GOAT3D_NODE_MESH, + GOAT3D_NODE_LIGHT, + GOAT3D_NODE_CAMERA +}; + /* immediate mode mesh construction primitive type */ enum goat3d_im_primitive { GOAT3D_TRIANGLES, @@ -158,6 +164,32 @@ int goat3d_get_mesh_count(struct goat3d *g); struct goat3d_mesh *goat3d_get_mesh(struct goat3d *g, int idx); +/* nodes */ +struct goat3d_node *goat3d_create_node(void); + +void goat3d_set_node_name(struct goat3d_node *node, const char *name); +const char *goat3d_get_node_name(struct goat3d_node *node); + +void goat3d_set_node_object(struct goat3d_node *node, enum goat3d_node_type type, void *obj); +void *goat3d_get_node_object(struct goat3d_node *node); +enum goat3d_node_type goat3d_get_node_type(struct goat3d_node *node); + +void goat3d_add_node_child(struct goat3d_node *node, struct goat3d_node *child); +int goat3d_get_node_child_count(struct goat3d_node *node); +struct goat3d_node *goat3d_get_node_child(struct goat3d_node *node, int idx); + +void goat3d_set_node_position(struct goat3d_node *node, float x, float y, float z, long tmsec); +void goat3d_set_node_rotation(struct goat3d_node *node, float qx, float qy, float qz, float qw, long tmsec); +void goat3d_set_node_scaling(struct goat3d_node *node, float sx, float sy, float sz, long tmsec); +void goat3d_set_node_pivot(struct goat3d_node *node, float px, float py, float pz); + +void goat3d_get_node_position(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec); +void goat3d_get_node_rotation(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, float *wptr, long tmsec); +void goat3d_get_node_scaling(struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec); +void goat3d_get_node_pivot(struct goat3d_node *node, float *xptr, float *yptr, float *zptr); + +void goat3d_get_node_matrix(struct goat3d_node *node, float *matrix, long tmsec); + #ifdef __cplusplus } #endif