Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1212 - in trunk: Model/Readers/glm scenes
- Date: Fri, 6 Oct 2006 20:51:48 -0600 (MDT)
Author: bigler
Date: Fri Oct 6 20:51:46 2006
New Revision: 1212
Modified:
trunk/Model/Readers/glm/glm.cc
trunk/scenes/objviewer.cc
Log:
Model/Readers/glm/glm.cc
Materials should be assigned to the group only after the first face
is found. This fixes the OBJ files written by Okino that decided to
put the usemtl command before the 'g' and 'o' commands (unlike
everyone else).
scenes/objviewer.cc
Moved some of the blender written file hacks into its own flag (use
-blender).
Modified: trunk/Model/Readers/glm/glm.cc
==============================================================================
--- trunk/Model/Readers/glm/glm.cc (original)
+++ trunk/Model/Readers/glm/glm.cc Fri Oct 6 20:51:46 2006
@@ -670,6 +670,7 @@
float* texcoords; /* array of texture coordinates */
GLMgroup* group; /* current group pointer */
unsigned int material; /* current material */
+ char* mtlname; /* current material name */
int v, n, t;
char buf[128];
@@ -685,6 +686,7 @@
numvertices = numnormals = numtexcoords = 1;
numtriangles = 0;
material = 0;
+ mtlname = 0;
while(fscanf(file, "%s", buf) != EOF) {
switch(buf[0]) {
case '#': /* comment */
@@ -730,8 +732,10 @@
case 'u': // usemtl
fgets(buf, sizeof(buf), file);
sscanf(buf, "%s %s", buf, buf);
- group->material = material = _glmFindMaterial(model, buf);
- group->mtlname = strdup(buf);
+ // Only assign this to the group if a face is encountered.
+ material = _glmFindMaterial(model, buf);
+ if (mtlname) free(mtlname);
+ mtlname = strdup(buf);
break;
case 'o':
case 'g': /* group */
@@ -739,10 +743,19 @@
fgets(buf, sizeof(buf), file);
sscanf(buf, "%s", buf);
group = _glmFindGroup(model, buf);
- group->material = material;
- group->mtlname = strdup(buf);
+ // Don't assign the material until you encounter a face. This
+ // is because materials are only applied to the faces
+ // following it. This code is also broken in the sense that
+ // if you can have more than one material in a group, but the
+ // code does not make this distinction.
break;
case 'f': /* face */
+ if (group->mtlname == 0) {
+ // Now that we have found a face apply the material the
+ // current working group.
+ group->material = material;
+ group->mtlname = strdup(mtlname);
+ }
v = n = t = 0;
fscanf(file, "%s", buf);
/* can be one of %d, %d//%d, %d/%d, %d/%d/%d %d//%d */
Modified: trunk/scenes/objviewer.cc
==============================================================================
--- trunk/scenes/objviewer.cc (original)
+++ trunk/scenes/objviewer.cc Fri Oct 6 20:51:46 2006
@@ -103,6 +103,8 @@
int fix_normals_degrees = 90;
bool flip_faces = false;
bool center_object = true;
+// Do blender specific things
+bool blender = false;
enum {
RealisticBvh_Build,
@@ -137,6 +139,9 @@
else if (args[i] == "-lambertian") {
use_lambertian = true;
}
+ else if (args[i] == "-blender") {
+ blender = true;
+ }
else if (args[i] == "-fixnormals") {
fix_normals = true;
@@ -317,7 +322,7 @@
///////////////////////////////////////////////////////////////////////////////
static void create_materials( GLMmodel *model ) {
-
/////////////////////////////////////////////////////////////////////////////
+
//////////////////////////////////////////////////////////////////////////
// Path to the model for loading textures.
string model_path = model->pathname;
@@ -331,9 +336,9 @@
// Read in the materials.
for (int i=0;i<model->nummaterials;++i) {
-
///////////////////////////////////////////////////////////////////////////
+
//////////////////////////////////////////////////////////////////////
// Copy out material attributes.
- string mtl_name = model->materials[i].name;
+ string mtl_name(model->materials[i].name);
// Color ambient (RGB( model->materials[i].ambient[0],
// model->materials[i].ambient[1],
@@ -354,21 +359,24 @@
// Copy out texture names.
// string ambient_map_name = (model->materials[i].ambient_map[0]
!= '\0') ?
// model->materials[i].ambient_map : "";
- string diffuse_map_name = (model->materials[i].diffuse_map[0] !=
'\0') ?
- model->materials[i].diffuse_map : "";
- string specular_map_name = (model->materials[i].specular_map[0] !=
'\0') ?
- model->materials[i].specular_map : "";
-
- // Note that the first material added by blender is always an
- // unused default material..
- int index = i-1;
+ string diffuse_map_name((model->materials[i].diffuse_map[0] !=
'\0') ?
+ model->materials[i].diffuse_map : "");
+ string specular_map_name((model->materials[i].specular_map[0] !=
'\0') ?
+ model->materials[i].specular_map : "");
+
+ int index = i;
+ if (blender) {
+ // Note that the first material added by blender is always an
+ // unused default material..
+ --index;
+ }
// Texture<Color> *diffuse_map = check_for_texture( model_path,
diffuse_map_name, diffuse );
// Lambertian Shader.
// material_array[index] = new Flat( diffuse_map );
-
///////////////////////////////////////////////////////////////////////////
+
//////////////////////////////////////////////////////////////////////
// Check for a dielectric.
if (Tr != 0) {
@@ -387,7 +395,7 @@
}
-
///////////////////////////////////////////////////////////////////////////
+
//////////////////////////////////////////////////////////////////////
// Check for a specular term.
else if (Ns != 0) {
@@ -402,7 +410,7 @@
static_cast<int>(Ns),
reflection );
}
-
///////////////////////////////////////////////////////////////////////////
+
//////////////////////////////////////////////////////////////////////
// Use a lambertian shader.
else {
@@ -425,7 +433,7 @@
TexTriangle **triangle_array = 0;
Group* bvh_group = 0;
-
/////////////////////////////////////////////////////////////////////////////
+
//////////////////////////////////////////////////////////////////////////
// Allocate storage for primitives and materials.
int total_triangles = model->numtriangles;
switch (which_BVH) {
@@ -468,14 +476,15 @@
// Read in the groups.
GLMgroup *group = model->groups;
while (group != 0) {
-
// Determine the material for this group.
Material *material;
- if ((group->material-1) < model->nummaterials) {
- material = material_array[group->material-1];
+ int material_index = group->material;
+ if (blender) --material_index;
+ if (material_index < model->nummaterials) {
+ material = material_array[material_index];
}
else {
- material = default_material;
+ material = default_material;
}
// Copy out triangles.
- [MANTA] r1212 - in trunk: Model/Readers/glm scenes, bigler, 10/06/2006
Archive powered by MHonArc 2.6.16.