minor improvements to examples/glFVarViewer:

- added detection of shapes without UVs and report fatal error
    - fixed command line parsing of shape file arguments and other options
    - added missing UVs from shapes/catmark_fan
This commit is contained in:
barry 2017-01-27 14:22:54 -08:00
parent 044b25e818
commit 7b2a0b239d
3 changed files with 77 additions and 22 deletions

View File

@ -407,6 +407,11 @@ rebuildMesh() {
Shape * shape = Shape::parseObj(shapeDesc.data.c_str(), shapeDesc.scheme);
if (!shape->HasUV()) {
printf("Error: shape %s does not contain face-varying UVs\n", shapeDesc.name.c_str());
exit(1);
}
// create Far mesh (topology)
OpenSubdiv::Sdc::SchemeType sdctype = GetSdcType(*shape);
OpenSubdiv::Sdc::Options sdcoptions = GetSdcOptions(*shape);
@ -1109,7 +1114,7 @@ initHUD() {
for (int i = 1; i < 11; ++i) {
char level[16];
sprintf(level, "Lv. %d", i);
g_hud.AddRadioButton(3, level, i == 2, 10, 270 + i*20, callbackLevel, i, '0'+(i%10));
g_hud.AddRadioButton(3, level, i == g_level, 10, 270 + i*20, callbackLevel, i, '0'+(i%10));
}
typedef OpenSubdiv::Sdc::Options SdcOptions;
@ -1175,26 +1180,42 @@ callbackErrorGLFW(int error, const char* description) {
fprintf(stderr, "GLFW Error (%d) : %s\n", error, description);
}
//------------------------------------------------------------------------------
static int
parseIntArg(const char* argString, int dfltValue = 0) {
char *argEndptr;
int argValue = strtol(argString, &argEndptr, 10);
if (*argEndptr != 0) {
printf("Warning: non-integer option parameter '%s' ignored\n", argString);
argValue = dfltValue;
}
return argValue;
}
//------------------------------------------------------------------------------
int main(int argc, char ** argv) {
bool fullscreen = false;
std::string str;
for (int i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "-d"))
g_level = atoi(argv[++i]);
else if (!strcmp(argv[i], "-c"))
g_repeatCount = atoi(argv[++i]);
else if (!strcmp(argv[i], "-f"))
if (!strcmp(argv[i], "-d")) {
if (++i < argc) g_level = parseIntArg(argv[i], g_level);
} else if (!strcmp(argv[i], "-c")) {
if (++i < argc) g_repeatCount = parseIntArg(argv[i], g_repeatCount);
} else if (!strcmp(argv[i], "-f")) {
fullscreen = true;
else {
std::ifstream ifs(argv[1]);
} else if (argv[i][0] == '-') {
printf("Warning: unrecognized option '%s' ignored\n", argv[i]);
} else {
std::ifstream ifs(argv[i]);
if (ifs) {
std::stringstream ss;
ss << ifs.rdbuf();
ifs.close();
str = ss.str();
g_defaultShapes.push_back(ShapeDesc(argv[1], str.c_str(), kCatmark));
g_defaultShapes.push_back(ShapeDesc(argv[i], str.c_str(), kCatmark));
} else {
printf("Warning: cannot open shape file '%s'\n", argv[i]);
}
}
}

View File

@ -40,6 +40,10 @@ static std::vector<ShapeDesc> g_defaultShapes;
//------------------------------------------------------------------------------
static void initShapes() {
//
// Note that any shapes added here must have UVs -- loading a shape without UVs is a fatal
// error and will result in termination when it is selected.
//
g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner0", catmark_cube_corner0, kCatmark ) );
g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner1", catmark_cube_corner1, kCatmark ) );
g_defaultShapes.push_back( ShapeDesc("catmark_cube_corner2", catmark_cube_corner2, kCatmark ) );

View File

@ -48,18 +48,48 @@ static const std::string catmark_fan =
"v 0.0 -.5 0.0\n"
"v 0.5 -.5 -0.5\n"
"v 1.0 -.5 -1.0\n"
"f 1 2 10 3\n"
"f 2 4 9 10\n"
"f 4 6 8 9\n"
"f 5 3 10 11\n"
"f 7 5 11 12\n"
"f 8 9 14 13\n"
"f 9 10 15 14\n"
"f 10 11 16 15\n"
"f 11 12 17 16\n"
"f 9 8 18 19\n"
"f 10 9 19 20\n"
"f 11 10 20 21\n"
"f 12 11 21 22\n"
"\n"
"vt 0.10 0.50\n"
"vt 0.10 0.40\n"
"vt 0.20 0.50\n"
"vt 0.10 0.30\n"
"vt 0.30 0.50\n"
"vt 0.10 0.20\n"
"vt 0.40 0.50\n"
"vt 0.20 0.20\n"
"vt 0.20 0.30\n"
"vt 0.20 0.40\n"
"vt 0.30 0.40\n"
"vt 0.40 0.40\n"
"vt 0.10 0.60\n"
"vt 0.20 0.60\n"
"vt 0.30 0.60\n"
"vt 0.40 0.60\n"
"vt 0.50 0.60\n"
"vt 0.10 0.70\n"
"vt 0.20 0.70\n"
"vt 0.30 0.70\n"
"vt 0.40 0.70\n"
"vt 0.50 0.70\n"
"vt 0.10 0.80\n"
"vt 0.20 0.80\n"
"vt 0.30 0.80\n"
"vt 0.40 0.80\n"
"vt 0.50 0.80\n"
"\n"
"f 1/1 2/2 10/10 3/3\n"
"f 2/2 4/4 9/9 10/10\n"
"f 4/4 6/6 8/8 9/9\n"
"f 5/5 3/3 10/10 11/11\n"
"f 7/7 5/5 11/11 12/12\n"
"f 8/18 9/19 14/24 13/23\n"
"f 9/19 10/20 15/25 14/24\n"
"f 10/20 11/21 16/26 15/25\n"
"f 11/21 12/22 17/27 16/26\n"
"f 9/19 8/18 18/13 19/14\n"
"f 10/20 9/19 19/14 20/15\n"
"f 11/21 10/20 20/15 21/16\n"
"f 12/22 11/21 21/16 22/17\n"
"\n"
"t interpolateboundary 1/0/0 1\n"
"\n";