Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1258 - in trunk: Model/Groups Model/Readers/glm fox/FManta scenes
- Date: Mon, 11 Dec 2006 22:33:36 -0700 (MST)
Author: bigler
Date: Mon Dec 11 22:33:34 2006
New Revision: 1258
Modified:
trunk/Model/Groups/KDTree.h
trunk/Model/Readers/glm/glm.cc
trunk/Model/Readers/glm/glm.h
trunk/fox/FManta/FMantaWindow.cc
trunk/scenes/objviewer.cc
Log:
Model/Groups/KDTree.h
fox/FManta/FMantaWindow.cc
Enum fixes not caught in previous commit.
Model/Readers/glm/glm.cc
Model/Readers/glm/glm.h
Added support for scaled textures.
Attempted support for multiple materials per group. Basically I
create a new group for each group name/material name combo. It
seems to work, but the scene I tried it on had weird looking
textures. I can't tell if that is the fault of the textures or of
this new feature.
scenes/objviewer.cc
Added bilinear flag for texture interpolation.
Added support for texture scaling.
Modified: trunk/Model/Groups/KDTree.h
==============================================================================
--- trunk/Model/Groups/KDTree.h (original)
+++ trunk/Model/Groups/KDTree.h Mon Dec 11 22:33:34 2006
@@ -243,7 +243,7 @@
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
- enum {
+ enum PickFlags {
PICK_HIGHLIGHT = 1,
PICK_REMOVE = 2,
};
Modified: trunk/Model/Readers/glm/glm.cc
==============================================================================
--- trunk/Model/Readers/glm/glm.cc (original)
+++ trunk/Model/Readers/glm/glm.cc Mon Dec 11 22:33:34 2006
@@ -181,6 +181,7 @@
static GLMgroup*
_glmFindGroup(GLMmodel* model, char* name)
{
+ fprintf(stderr, "Looking for group named \"%s\"\n", name);
GLMgroup* group;
assert(model);
@@ -204,6 +205,7 @@
group = _glmFindGroup(model, name);
if (!group) {
+ fprintf(stderr, "Adding group named \"%s\"\n", name);
group = (GLMgroup*)malloc(sizeof(GLMgroup));
group->name = strdup(name);
group->material = 0;
@@ -214,6 +216,10 @@
model->groups = group;
model->numgroups++;
}
+ else {
+ fprintf(stderr, "Found group named \"%s\"\n", name);
+ }
+
return group;
}
@@ -343,6 +349,13 @@
model->materials[i].ambient_map[0] = '\0';
model->materials[i].diffuse_map[0] = '\0';
model->materials[i].specular_map[0] = '\0';
+
+ model->materials[i].ambient_map_scaling[0] = 0;
+ model->materials[i].ambient_map_scaling[1] = 0;
+ model->materials[i].diffuse_map_scaling[0] = 0;
+ model->materials[i].diffuse_map_scaling[1] = 0;
+ model->materials[i].specular_map_scaling[0] = 0;
+ model->materials[i].specular_map_scaling[1] = 0;
}
model->materials[0].name = strdup("NO_ASSIGNED_MATERIAL");
@@ -378,17 +391,36 @@
fscanf(file, "%d", &model->materials[nummaterials].shader);
break;
case 'm':
-
- // Determine which type of map.
- if (strcmp(buf,"map_Ka")==0)
- fscanf(file, "%s", model->materials[nummaterials].ambient_map );
-
- else if (strcmp(buf,"map_Kd")==0)
- fscanf(file, "%s", model->materials[nummaterials].diffuse_map );
-
- else if (strcmp(buf,"map_Ks")==0)
- fscanf(file, "%s", model->materials[nummaterials].specular_map );
-
+ {
+ char* map_name = 0;
+ float* scaling = 0;
+ // Determine which type of map.
+ if (strcmp(buf,"map_Ka")==0) {
+ map_name = model->materials[nummaterials].ambient_map;
+ scaling = model->materials[nummaterials].ambient_map_scaling;
+ } else if (strcmp(buf,"map_Kd")==0) {
+ map_name = model->materials[nummaterials].diffuse_map;
+ scaling = model->materials[nummaterials].diffuse_map_scaling;
+ } else if (strcmp(buf,"map_Ks")==0) {
+ map_name = model->materials[nummaterials].specular_map;
+ scaling = model->materials[nummaterials].ambient_map_scaling;
+ }
+
+ char string_litteral[128];
+ sprintf(string_litteral, "%%%ds", (int)MaxStringLength-1);
+ //fprintf(stderr, "string_litteral = %s\n", string_litteral);
+
+ // Check to see if we have scaled textures or not
+ fscanf(file, string_litteral, map_name);
+ if (strcmp(map_name, "-s") == 0) {
+ // pick up the float scaled textures
+ fscanf(file, "%f %f", &scaling[0], &scaling[1]);
+ // Now the name of the file
+ fscanf(file, string_litteral, map_name);
+ //fprintf(stderr, " scale = %f %f ,", scaling[0],
scaling[1]);
+ }
+ //fprintf(stderr, "name = %s\n", map_name);
+ } // end case 'm'
break;
case 'K':
@@ -503,11 +535,13 @@
GLMgroup* group; /* current group */
+ char* current_group_base_name = strdup("default");
+ char* current_material_name = 0;
int v, n, t;
char buf[128];
/* make a default group */
- group = _glmAddGroup(model, "default");
+ group = _glmAddGroup(model, current_group_base_name);
numvertices = numnormals = numtexcoords = numtriangles = 0;
@@ -557,18 +591,29 @@
model->mtllibname = strdup(buf);
if (_glmReadMTL(model, buf)) {
/* Uh oh. Trouble reading in the material file. */
+ if (current_group_base_name) free(current_group_base_name);
+ if (current_material_name) free(current_material_name);
return 1;
}
break;
case 'u':
- /* eat up rest of line */
+ /* We need to create groups with their own materials */
fgets(buf, sizeof(buf), file);
+ sscanf(buf, "%s %s", buf, buf);
+ if (current_material_name) free(current_material_name);
+ current_material_name = strdup(buf);
+ sprintf(buf, "%s_MAT_%s",
+ current_group_base_name, current_material_name);
+ group = _glmAddGroup(model, buf);
break;
case 'o':
case 'g': /* group */
- /* eat up rest of line */
fgets(buf, sizeof(buf), file);
sscanf(buf, "%s", buf);
+ if (current_group_base_name) free(current_group_base_name);
+ current_group_base_name = strdup(buf);
+ sprintf(buf, "%s_MAT_%s",
+ current_group_base_name, current_material_name);
group = _glmAddGroup(model, buf);
break;
case 'f': /* face */
@@ -648,6 +693,9 @@
group->numtriangles = 0;
group = group->next;
}
+
+ if (current_group_base_name) free(current_group_base_name);
+ if (current_material_name) free(current_material_name);
return 0;
}
@@ -670,6 +718,7 @@
float* texcoords; /* array of texture coordinates */
GLMgroup* group; /* current group pointer */
unsigned int material; /* current material */
+ char* grpname; /* current group base name */
char* mtlname; /* current material name */
int v, n, t;
char buf[128];
@@ -686,6 +735,7 @@
numvertices = numnormals = numtexcoords = 1;
numtriangles = 0;
material = 0;
+ grpname = strdup("default");
mtlname = 0;
while(fscanf(file, "%s", buf) != EOF) {
switch(buf[0]) {
@@ -732,30 +782,29 @@
case 'u': // usemtl
fgets(buf, sizeof(buf), file);
sscanf(buf, "%s %s", buf, buf);
- // Only assign this to the group if a face is encountered.
- material = _glmFindMaterial(model, buf);
if (mtlname) free(mtlname);
mtlname = strdup(buf);
+ material = _glmFindMaterial(model, buf);
+ sprintf(buf, "%s_MAT_%s",
+ grpname, mtlname);
+ group = _glmFindGroup(model, buf);
+ group->material = material;
+ group->mtlname = strdup(mtlname);
break;
case 'o':
case 'g': /* group */
/* eat up rest of line */
fgets(buf, sizeof(buf), file);
sscanf(buf, "%s", buf);
+ if (grpname) free(grpname);
+ grpname = strdup(grpname);
+ sprintf(buf, "%s_MAT_%s",
+ grpname, mtlname);
group = _glmFindGroup(model, 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.
+ group->material = material;
+ group->mtlname = strdup(mtlname);
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 */
@@ -867,6 +916,8 @@
numtexcoords * 3*sizeof(float) * (numtexcoords ? 1 : 0) +
numtriangles * sizeof(GLMtriangle));
#endif
+ if (grpname) free(grpname);
+ if (mtlname) free(mtlname);
}
Modified: trunk/Model/Readers/glm/glm.h
==============================================================================
--- trunk/Model/Readers/glm/glm.h (original)
+++ trunk/Model/Readers/glm/glm.h Mon Dec 11 22:33:34 2006
@@ -34,6 +34,10 @@
GLM_SPECULAR_SHADE = (1 << 6)
};
+ enum Sizes {
+ MaxStringLength = 128
+ };
+
/* structs */
/* GLMmaterial: Structure that defines a material in a model.
@@ -51,9 +55,14 @@
int shader; // illum
// Texture maps, zero length if not specified.
- char ambient_map [128]; // map_Ka
- char diffuse_map [128]; // map_Kd
- char specular_map[128]; // map_Ks
+ char ambient_map [MaxStringLength]; // map_Ka
+ char diffuse_map [MaxStringLength]; // map_Kd
+ char specular_map[MaxStringLength]; // map_Ks
+
+ // Scaling for texture maps (initialized to 0 for not set)
+ float ambient_map_scaling[2];
+ float diffuse_map_scaling[2];
+ float specular_map_scaling[2];
} GLMmaterial;
Modified: trunk/fox/FManta/FMantaWindow.cc
==============================================================================
--- trunk/fox/FManta/FMantaWindow.cc (original)
+++ trunk/fox/FManta/FMantaWindow.cc Mon Dec 11 22:33:34 2006
@@ -688,7 +688,7 @@
manta_interface->addTransaction("Toggle hide selected",
Callback::create(this,&FMantaWindow::mantaToggleHideSelected,
- KDTree::PICK_HIGHLIGHT+checked));
+ static_cast<int>(KDTree::PICK_HIGHLIGHT)+checked));
}
return 1;
Modified: trunk/scenes/objviewer.cc
==============================================================================
--- trunk/scenes/objviewer.cc (original)
+++ trunk/scenes/objviewer.cc Mon Dec 11 22:33:34 2006
@@ -105,6 +105,7 @@
bool center_object = true;
// Do blender specific things
bool blender = false;
+bool bilinear_textures = false;
enum {
RealisticBvh_Build,
@@ -177,6 +178,9 @@
else if (args[i] == "-nocentering") {
center_object = false;
}
+ else if (args[i] == "-bilinear") {
+ bilinear_textures = true;
+ }
}
///////////////////////////////////////////////////////////////////////////
@@ -289,15 +293,22 @@
}
// Check to see if the specified file can be loaded, otherwise use the
specified color.
-Texture<Color> *check_for_texture( const string &path_name, const string
&file_name, const Color &constant_color ) {
+Texture<Color> *check_for_texture( const string &path_name, const string
&file_name, const Color &constant_color, const float* map_scaling ) {
Texture<Color> *texture = 0;
if (file_name.size()) {
// Load the image texture.
try {
- texture = load_image_texture<Color>( path_name + file_name );
- // texture = new TexCoordTexture;
+ ImageTexture<Color>* it = load_image_texture<Color>( path_name +
file_name );
+ // The values are assigned to zero in in unintialized state
+ if (map_scaling[0] != 0) {
+ it->setScale(map_scaling[0], map_scaling[1]);
+ }
+ if (bilinear_textures) {
+ it->setInterpolationMethod(ImageTexture<Color>::Bilinear);
+ }
+ texture = it;
}
catch (SCIRun::Exception &e) {
std::cerr << "Could not load diffuse map: "
@@ -363,6 +374,8 @@
model->materials[i].diffuse_map : "");
string specular_map_name((model->materials[i].specular_map[0] !=
'\0') ?
model->materials[i].specular_map : "");
+ float* diffuse_map_scaling = model->materials[i].diffuse_map_scaling;
+ float* specular_map_scaling =
model->materials[i].specular_map_scaling;
int index = i;
if (blender) {
@@ -371,7 +384,7 @@
--index;
}
- // Texture<Color> *diffuse_map = check_for_texture( model_path,
diffuse_map_name, diffuse );
+ // Texture<Color> *diffuse_map = check_for_texture( model_path,
diffuse_map_name, diffuse, diffuse_map_scaling );
// Lambertian Shader.
// material_array[index] = new Flat( diffuse_map );
@@ -386,7 +399,7 @@
Texture<Real> *n = new Constant<Real>( 1.6 );
Texture<Real> *nt = new Constant<Real>( 1.0 );
- Texture<Color> *diffuse_map = check_for_texture( model_path,
diffuse_map_name, diffuse );
+ Texture<Color> *diffuse_map = check_for_texture( model_path,
diffuse_map_name, diffuse , diffuse_map_scaling);
// Texture<Color> *diffuse_map = new Constant<Color>(
Color(RGB(.9, .8, .8)) );
// Create a dielectric shader.
@@ -401,8 +414,8 @@
std::cerr << "Material " << index << " Specular" << std::endl;
- Texture<Color> *diffuse_map = check_for_texture( model_path,
diffuse_map_name, diffuse );
- Texture<Color> *specular_map = check_for_texture( model_path,
specular_map_name, specular );
+ Texture<Color> *diffuse_map = check_for_texture( model_path,
diffuse_map_name, diffuse, diffuse_map_scaling );
+ Texture<Color> *specular_map = check_for_texture( model_path,
specular_map_name, specular, specular_map_scaling );
Texture<ColorComponent> *reflection = new
Constant<ColorComponent>( 0.0 );
// Phong shader.
@@ -416,7 +429,7 @@
std::cerr << "Material " << index << " Lambertian" << std::endl;
- Texture<Color> *diffuse_map = check_for_texture( model_path,
diffuse_map_name, diffuse );
+ Texture<Color> *diffuse_map = check_for_texture( model_path,
diffuse_map_name, diffuse, diffuse_map_scaling );
// Lambertian Shader.
material_array[index] = new Lambertian( diffuse_map );
- [MANTA] r1258 - in trunk: Model/Groups Model/Readers/glm fox/FManta scenes, bigler, 12/11/2006
Archive powered by MHonArc 2.6.16.