# HG changeset patch # User John Tsiombikas # Date 1380241056 -10800 # Node ID bdfc8dd1496577670a77f39ea09df41daf6103ca # Parent 1d85d7dd00380e55d22c49d3c14a5b40fbc29e87 done with goatprim diff -r 1d85d7dd0038 -r bdfc8dd14965 generators/goatprim/main.c --- a/generators/goatprim/main.c Fri Sep 27 02:29:52 2013 +0300 +++ b/generators/goatprim/main.c Fri Sep 27 03:17:36 2013 +0300 @@ -4,10 +4,17 @@ #include #include "goat3d.h" -#define DEF_USUB 16 -#define DEF_VSUB 8 -#define DEF_SIZE 1.0 -#define DEF_OUTER 0.25 +#define DEF_USUB 16 +#define DEF_VSUB 8 +#define DEF_SIZE 1.0 +#define DEF_OUTER 0.25 +#define DEF_DIFFUSE_R 0.6 +#define DEF_DIFFUSE_G 0.6 +#define DEF_DIFFUSE_B 0.6 +#define DEF_SPECULAR_R 0.8 +#define DEF_SPECULAR_G 0.8 +#define DEF_SPECULAR_B 0.8 +#define DEF_SHININESS 60.0 enum { BOX, SPHERE, TORUS }; @@ -26,6 +33,9 @@ int vsub = DEF_VSUB; float size = DEF_SIZE; float outer = DEF_OUTER; + float diffuse[] = {DEF_DIFFUSE_R, DEF_DIFFUSE_G, DEF_DIFFUSE_B, 1.0}; + float specular[] = {DEF_SPECULAR_R, DEF_SPECULAR_G, DEF_SPECULAR_B, 1.0}; + float shininess = DEF_SHININESS; struct goat3d *goat; struct goat3d_material *mtl; struct goat3d_mesh *mesh; @@ -66,6 +76,31 @@ return 1; } + } else if(strcmp(argv[i], "-diffuse") == 0) { + if(!argv[i + 1] || !argv[i + 2] || !argv[i + 3]) { + fprintf(stderr, "-diffuse must be followed by 3 numbers (r, g, b)\n"); + return 1; + } + diffuse[0] = atof(argv[++i]); + diffuse[1] = atof(argv[++i]); + diffuse[2] = atof(argv[++i]); + + } else if(strcmp(argv[i], "-specular") == 0) { + if(!argv[i + 1] || !argv[i + 2] || !argv[i + 3]) { + fprintf(stderr, "-specular must be followed by 3 numbers (r, g, b)\n"); + return 1; + } + specular[0] = atof(argv[++i]); + specular[1] = atof(argv[++i]); + specular[2] = atof(argv[++i]); + + } else if(strcmp(argv[i], "-shininess") == 0) { + if(!argv[i + 1]) { + fprintf(stderr, "-shininess must be followed by a number\n"); + return 1; + } + shininess = atof(argv[++i]); + } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) { printf("Usage: %s [filename] [options]\n", argv[0]); printf("Options:\n"); @@ -76,6 +111,9 @@ printf(" -outer torus outer radius (default: %g)\n", DEF_OUTER); printf(" -usub subdivisions along the horizontal direction (default: %d)\n", DEF_USUB); printf(" -vsub subdivisions along the vertical direction (default: %d)\n", DEF_VSUB); + printf(" -diffuse material diffuse color (default: %g %g %g)\n", DEF_DIFFUSE_R, DEF_DIFFUSE_G, DEF_DIFFUSE_B); + printf(" -specular material specular color (default: %g %g %g)\n", DEF_SPECULAR_R, DEF_SPECULAR_G, DEF_SPECULAR_B); + printf(" -shininess material shininess (default: %g)\n", DEF_SHININESS); printf(" -h, -help print usage information and exit\n"); return 0; @@ -97,7 +135,9 @@ mtl = goat3d_create_mtl(); goat3d_set_mtl_name(mtl, "mat"); - goat3d_set_mtl_attrib4f(mtl, GOAT3D_MAT_ATTR_DIFFUSE, 1, 0, 0, 1); + goat3d_set_mtl_attrib(mtl, GOAT3D_MAT_ATTR_DIFFUSE, diffuse); + goat3d_set_mtl_attrib(mtl, GOAT3D_MAT_ATTR_SPECULAR, specular); + goat3d_set_mtl_attrib1f(mtl, GOAT3D_MAT_ATTR_SHININESS, shininess); goat3d_add_mtl(goat, mtl); mesh = goat3d_create_mesh(); diff -r 1d85d7dd0038 -r bdfc8dd14965 src/goat3d_writexml.cc --- a/src/goat3d_writexml.cc Fri Sep 27 02:29:52 2013 +0300 +++ b/src/goat3d_writexml.cc Fri Sep 27 03:17:36 2013 +0300 @@ -17,7 +17,8 @@ // write environment stuff xmlout(io, 1, "\n"); - xmlout(io, 1, "\n"); + xmlout(io, 2, "\n", ambient.x, ambient.y, ambient.z); + xmlout(io, 1, "\n\n"); for(size_t i=0; i\n", mat->get_attrib_name(i)); const MaterialAttrib &attr = (*mat)[i]; - xmlout(io, level + 2, "\n", attr.value.x, + xmlout(io, level + 2, "\n", attr.value.x, attr.value.y, attr.value.z, attr.value.w); if(!attr.map.empty()) { xmlout(io, level + 2, "\n", attr.map.c_str()); } xmlout(io, level + 1, "\n"); } - xmlout(io, level, "\n"); + xmlout(io, level, "\n\n"); return true; } @@ -80,7 +81,7 @@ xmlout(io, level + 1, "\n", mesh->material->name.c_str()); } xmlout(io, level + 1, "\n", mesh_filename); - xmlout(io, level, "\n"); + xmlout(io, level, "\n\n"); return true; }