Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1013 - in trunk: Model/Readers/glm StandAlone
- Date: Tue, 25 Apr 2006 23:36:07 -0600 (MDT)
Author: abe
Date: Tue Apr 25 23:36:07 2006
New Revision: 1013
Modified:
trunk/Model/Readers/glm/glm.cc
trunk/Model/Readers/glm/glm.h
trunk/StandAlone/v3c1_tools.cc
Log:
Added code to import Boeing777 distribution .obj files. Previously external
scripts were used.
M StandAlone/v3c1_tools.cc
M Model/Readers/glm/glm.cc
M Model/Readers/glm/glm.h
Modified: trunk/Model/Readers/glm/glm.cc
==============================================================================
--- trunk/Model/Readers/glm/glm.cc (original)
+++ trunk/Model/Readers/glm/glm.cc Tue Apr 25 23:36:07 2006
@@ -207,6 +207,7 @@
group = (GLMgroup*)malloc(sizeof(GLMgroup));
group->name = strdup(name);
group->material = 0;
+ group->mtlname = 0;
group->numtriangles = 0;
group->triangles = NULL;
group->next = model->groups;
@@ -230,7 +231,7 @@
}
/* didn't find the name, so set it as the default material */
- printf("_glmFindMaterial(): can't find material \"%s\".\n", name);
+ /* printf("_glmFindMaterial(): can't find material \"%s\".\n", name); */
i = 0;
found:
@@ -726,10 +727,11 @@
break;
}
break;
- case 'u':
+ case 'u': // usemtl
fgets(buf, sizeof(buf), file);
sscanf(buf, "%s %s", buf, buf);
group->material = material = _glmFindMaterial(model, buf);
+ group->mtlname = strdup(buf);
break;
case 'o':
case 'g': /* group */
@@ -738,6 +740,7 @@
sscanf(buf, "%s", buf);
group = _glmFindGroup(model, buf);
group->material = material;
+ group->mtlname = strdup(buf);
break;
case 'f': /* face */
v = n = t = 0;
@@ -1283,7 +1286,7 @@
}
free(normals);
- printf("glmVertexNormals(): %u normals generated\n", model->numnormals);
+ // printf("glmVertexNormals(): %u normals generated\n",
model->numnormals);
}
@@ -1444,6 +1447,7 @@
model->groups = model->groups->next;
if (group->name) free(group->name);
if (group->triangles) free(group->triangles);
+ if (group->mtlname) free(group->mtlname);
free(group);
}
Modified: trunk/Model/Readers/glm/glm.h
==============================================================================
--- trunk/Model/Readers/glm/glm.h (original)
+++ trunk/Model/Readers/glm/glm.h Tue Apr 25 23:36:07 2006
@@ -73,6 +73,7 @@
unsigned int numtriangles; /* number of triangles in
this group */
unsigned int* triangles; /* array of triangle
indices */
unsigned int material; /* index to material
for group */
+ char* mtlname; /*name of the material for this group*/
struct _GLMgroup* next; /* pointer to next group in
model */
} GLMgroup;
Modified: trunk/StandAlone/v3c1_tools.cc
==============================================================================
--- trunk/StandAlone/v3c1_tools.cc (original)
+++ trunk/StandAlone/v3c1_tools.cc Tue Apr 25 23:36:07 2006
@@ -25,7 +25,6 @@
// The program takes the input path (and recursively examines all
subdirectories)
// as well as the output file name.
-
// vn3 file format.
void search_directory( const char *directory_name, unsigned char
current_color[3] );
void process_vn3_file( const char *file_name, unsigned char
current_color[3] );
@@ -60,7 +59,7 @@
bool use_group_file = false;
bool loud = false;
-
+bool use_boeing_materials = false;
// Output file name.
char *output_file_name = 0;
@@ -266,6 +265,9 @@
plane_normal[1] = atof( argv[++i] );
plane_normal[2] = atof( argv[++i] );
}
+ else if (arg == "-boeingmaterials") {
+ use_boeing_materials = true;
+ }
}
// Check that both were found.
@@ -282,6 +284,7 @@
" -groups -- Output a .grp and .nam file.\n"
" -loud -- Print per group info.\n"
" -overwrite -- Required if output files
already exist.\n"
+ " -boeingmaterials -- Parse colors from usemtl
directives.\n"
" v3c1_tools -m -in <file1.m ...> -color <r> <g> <b>
[-out <outfile.v3c1>]\n"
" Hughes Hoppe .m file format conversion.\n\n"
" v3c1_tools -info <infile.v3c1 ...>\n"
@@ -372,7 +375,7 @@
}
}
- for (int i=file_list_begin;i<file_list_end;++i) {
+ for (int i=file_list_begin;i<file_list_end;++i) {
process_obj_file( argv[i] );
}
@@ -600,7 +603,11 @@
std::cout << "Error cannot read model from file." <<
std::endl;
return;
}
-
+
+ if (loud) {
+ printf("Total triangles: %d\n", model->numtriangles );
+ }
+
// Flip the face winding.
if (flip_face_winding) {
std::cout << "Reversing winding direction.\n";
@@ -612,13 +619,13 @@
// Check to see if
if (!model->facetnorms) {
- std::cout << "Computing facet normals\n";
+ // std::cout << "Computing facet normals\n";
glmFacetNormals( model );
}
- std::cout << "Computing vertex normals, threshold="
- << vertex_normals_angle
- << "\n";
+ // std::cout << "Computing vertex normals, threshold="
+ // << vertex_normals_angle
+ // << "\n";
glmVertexNormals( model, vertex_normals_angle );
}
@@ -646,7 +653,9 @@
if (out_file == 0) {
// Use an output file per group.
char file_name[128];
- sprintf( file_name, "%d%s.v3c1", group_num,
group->name );
+ if (loud) {
+ sprintf( file_name, "group%d.%s.v3c1", group_num, group->name );
+ }
out = fopen( file_name, "w" );
if (out == 0) {
@@ -674,7 +683,9 @@
}
}
- printf( "Group: %d File: %s ", group_num, file_name );
+ if (loud) {
+ printf( "Group: %d File: %s \n", group_num, file_name );
+ }
}
else {
// Use a single output file.
@@ -710,21 +721,22 @@
// Do we need to copy out normals?
if (normal_out) {
int normal_index = model->triangles[tri_index].nindices[v];
+ const float * f;
if (normal_index <= model->numnormals) {
- const float *f = model->normals+(normal_index*3);
+ f = model->normals+(normal_index*3);
- // Copy out the normal.
- normal[v][0] = f[0];
- normal[v][1] = f[1];
- normal[v][2] = f[2];
-
- normal[v].normalize();
}
else {
- std::cout << "Invalid normal " << normal_index
- << " specified for face: " << tri_index
- << std::endl;
+ // Use the face normal instead.
+ f = model->facetnorms + (model->triangles[tri_index].findex*3);
}
+
+ // Copy out the normal.
+ normal[v][0] = f[0];
+ normal[v][1] = f[1];
+ normal[v][2] = f[2];
+
+ normal[v].normalize();
}
// Copy texcoords?
@@ -749,7 +761,21 @@
/////////////////////////////////////////////////////////////////////////
// Specify the face color.
int mtl_index = group->material;
- if (mtl_index < model->nummaterials) {
+ if (mtl_index == 0 && use_boeing_materials) {
+
+ // Parse the color from the material name.
+ int r, g, b;
+ if (sscanf(group->mtlname, "Material%d_%d_%d", &r, &g, &b ) != 3) {
+ std::cerr << "Could not parse material from: "
+ << group->mtlname
+ << std::endl;
+ }
+
+ out_face.color[0] = (float)r/255.0f;
+ out_face.color[1] = (float)g/255.0f;
+ out_face.color[2] = (float)b/255.0f;
+ }
+ else if (mtl_index < model->nummaterials) {
// Copy out the color.
for (int c=0; c<3;++c) {
out_face.color[c] = model->materials[mtl_index].diffuse[c];
@@ -800,7 +826,7 @@
}
if (loud) {
- printf( "Group %d Faces: %d \"%s\"\n",
+ printf( "\tGroup %d Faces: %d \"%s\"\n",
group_num,
group->numtriangles,
group->name );
- [MANTA] r1013 - in trunk: Model/Readers/glm StandAlone, abe, 04/25/2006
Archive powered by MHonArc 2.6.16.