goat3d
changeset 18:bdfc8dd14965
done with goatprim
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 27 Sep 2013 03:17:36 +0300 |
parents | 1d85d7dd0038 |
children | b35427826b60 |
files | generators/goatprim/main.c src/goat3d_writexml.cc |
diffstat | 2 files changed, 50 insertions(+), 9 deletions(-) [+] |
line diff
1.1 --- a/generators/goatprim/main.c Fri Sep 27 02:29:52 2013 +0300 1.2 +++ b/generators/goatprim/main.c Fri Sep 27 03:17:36 2013 +0300 1.3 @@ -4,10 +4,17 @@ 1.4 #include <math.h> 1.5 #include "goat3d.h" 1.6 1.7 -#define DEF_USUB 16 1.8 -#define DEF_VSUB 8 1.9 -#define DEF_SIZE 1.0 1.10 -#define DEF_OUTER 0.25 1.11 +#define DEF_USUB 16 1.12 +#define DEF_VSUB 8 1.13 +#define DEF_SIZE 1.0 1.14 +#define DEF_OUTER 0.25 1.15 +#define DEF_DIFFUSE_R 0.6 1.16 +#define DEF_DIFFUSE_G 0.6 1.17 +#define DEF_DIFFUSE_B 0.6 1.18 +#define DEF_SPECULAR_R 0.8 1.19 +#define DEF_SPECULAR_G 0.8 1.20 +#define DEF_SPECULAR_B 0.8 1.21 +#define DEF_SHININESS 60.0 1.22 1.23 enum { BOX, SPHERE, TORUS }; 1.24 1.25 @@ -26,6 +33,9 @@ 1.26 int vsub = DEF_VSUB; 1.27 float size = DEF_SIZE; 1.28 float outer = DEF_OUTER; 1.29 + float diffuse[] = {DEF_DIFFUSE_R, DEF_DIFFUSE_G, DEF_DIFFUSE_B, 1.0}; 1.30 + float specular[] = {DEF_SPECULAR_R, DEF_SPECULAR_G, DEF_SPECULAR_B, 1.0}; 1.31 + float shininess = DEF_SHININESS; 1.32 struct goat3d *goat; 1.33 struct goat3d_material *mtl; 1.34 struct goat3d_mesh *mesh; 1.35 @@ -66,6 +76,31 @@ 1.36 return 1; 1.37 } 1.38 1.39 + } else if(strcmp(argv[i], "-diffuse") == 0) { 1.40 + if(!argv[i + 1] || !argv[i + 2] || !argv[i + 3]) { 1.41 + fprintf(stderr, "-diffuse must be followed by 3 numbers (r, g, b)\n"); 1.42 + return 1; 1.43 + } 1.44 + diffuse[0] = atof(argv[++i]); 1.45 + diffuse[1] = atof(argv[++i]); 1.46 + diffuse[2] = atof(argv[++i]); 1.47 + 1.48 + } else if(strcmp(argv[i], "-specular") == 0) { 1.49 + if(!argv[i + 1] || !argv[i + 2] || !argv[i + 3]) { 1.50 + fprintf(stderr, "-specular must be followed by 3 numbers (r, g, b)\n"); 1.51 + return 1; 1.52 + } 1.53 + specular[0] = atof(argv[++i]); 1.54 + specular[1] = atof(argv[++i]); 1.55 + specular[2] = atof(argv[++i]); 1.56 + 1.57 + } else if(strcmp(argv[i], "-shininess") == 0) { 1.58 + if(!argv[i + 1]) { 1.59 + fprintf(stderr, "-shininess must be followed by a number\n"); 1.60 + return 1; 1.61 + } 1.62 + shininess = atof(argv[++i]); 1.63 + 1.64 } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) { 1.65 printf("Usage: %s [filename] [options]\n", argv[0]); 1.66 printf("Options:\n"); 1.67 @@ -76,6 +111,9 @@ 1.68 printf(" -outer <n> torus outer radius (default: %g)\n", DEF_OUTER); 1.69 printf(" -usub <n> subdivisions along the horizontal direction (default: %d)\n", DEF_USUB); 1.70 printf(" -vsub <n> subdivisions along the vertical direction (default: %d)\n", DEF_VSUB); 1.71 + printf(" -diffuse <r> <g> <b> material diffuse color (default: %g %g %g)\n", DEF_DIFFUSE_R, DEF_DIFFUSE_G, DEF_DIFFUSE_B); 1.72 + printf(" -specular <r> <g> <b> material specular color (default: %g %g %g)\n", DEF_SPECULAR_R, DEF_SPECULAR_G, DEF_SPECULAR_B); 1.73 + printf(" -shininess <n> material shininess (default: %g)\n", DEF_SHININESS); 1.74 printf(" -h, -help print usage information and exit\n"); 1.75 return 0; 1.76 1.77 @@ -97,7 +135,9 @@ 1.78 1.79 mtl = goat3d_create_mtl(); 1.80 goat3d_set_mtl_name(mtl, "mat"); 1.81 - goat3d_set_mtl_attrib4f(mtl, GOAT3D_MAT_ATTR_DIFFUSE, 1, 0, 0, 1); 1.82 + goat3d_set_mtl_attrib(mtl, GOAT3D_MAT_ATTR_DIFFUSE, diffuse); 1.83 + goat3d_set_mtl_attrib(mtl, GOAT3D_MAT_ATTR_SPECULAR, specular); 1.84 + goat3d_set_mtl_attrib1f(mtl, GOAT3D_MAT_ATTR_SHININESS, shininess); 1.85 goat3d_add_mtl(goat, mtl); 1.86 1.87 mesh = goat3d_create_mesh();
2.1 --- a/src/goat3d_writexml.cc Fri Sep 27 02:29:52 2013 +0300 2.2 +++ b/src/goat3d_writexml.cc Fri Sep 27 03:17:36 2013 +0300 2.3 @@ -17,7 +17,8 @@ 2.4 2.5 // write environment stuff 2.6 xmlout(io, 1, "<env>\n"); 2.7 - xmlout(io, 1, "</env>\n"); 2.8 + xmlout(io, 2, "<ambient float3=\"%g %g %g\"/>\n", ambient.x, ambient.y, ambient.z); 2.9 + xmlout(io, 1, "</env>\n\n"); 2.10 2.11 for(size_t i=0; i<materials.size(); i++) { 2.12 write_material(this, io, materials[i], 1); 2.13 @@ -49,14 +50,14 @@ 2.14 xmlout(io, level + 2, "<name string=\"%s\"/>\n", mat->get_attrib_name(i)); 2.15 2.16 const MaterialAttrib &attr = (*mat)[i]; 2.17 - xmlout(io, level + 2, "<val float4=\"%.3f %.3f %.3f %.3f\"/>\n", attr.value.x, 2.18 + xmlout(io, level + 2, "<val float4=\"%g %g %g %g\"/>\n", attr.value.x, 2.19 attr.value.y, attr.value.z, attr.value.w); 2.20 if(!attr.map.empty()) { 2.21 xmlout(io, level + 2, "<map string=\"%s\"/>\n", attr.map.c_str()); 2.22 } 2.23 xmlout(io, level + 1, "</attr>\n"); 2.24 } 2.25 - xmlout(io, level, "</mtl>\n"); 2.26 + xmlout(io, level, "</mtl>\n\n"); 2.27 return true; 2.28 } 2.29 2.30 @@ -80,7 +81,7 @@ 2.31 xmlout(io, level + 1, "<material string=\"%s\"/>\n", mesh->material->name.c_str()); 2.32 } 2.33 xmlout(io, level + 1, "<file string=\"%s\"/>\n", mesh_filename); 2.34 - xmlout(io, level, "</mesh>\n"); 2.35 + xmlout(io, level, "</mesh>\n\n"); 2.36 return true; 2.37 } 2.38