From 5c2191f89c823b2dea849cacbe1497820dd655cd Mon Sep 17 00:00:00 2001 From: barry Date: Fri, 19 Oct 2018 13:05:23 -0700 Subject: [PATCH] Added more common utilities to support Shapes with non-Catmark schemes: - added conversions Shape and Sdc scheme types - extended ObjAnim to take a scheme type on construction - updated far/tutorial_9 to make use of new functionality --- examples/common/objAnim.cpp | 4 +-- examples/common/objAnim.h | 7 +++-- regression/common/far_utils.h | 33 ++++++++++++++++----- tutorials/far/tutorial_9/far_tutorial_9.cpp | 7 +++-- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/examples/common/objAnim.cpp b/examples/common/objAnim.cpp index 6482f31a..92f51778 100644 --- a/examples/common/objAnim.cpp +++ b/examples/common/objAnim.cpp @@ -88,7 +88,7 @@ ObjAnim::InterpolatePositions(float time, float * positions, int stride) const { } ObjAnim const * -ObjAnim::Create(std::vector objFiles, bool axis) { +ObjAnim::Create(std::vector objFiles, bool axis, Scheme scheme) { ObjAnim * anim=0; @@ -118,7 +118,7 @@ ObjAnim::Create(std::vector objFiles, bool axis) { fflush(stdout); std::string str = ss.str(); - shape = Shape::parseObj(str.c_str(), kCatmark, false, axis); + shape = Shape::parseObj(str.c_str(), scheme, false, axis); if (i==0) { diff --git a/examples/common/objAnim.h b/examples/common/objAnim.h index 3d635df7..a012fcb6 100644 --- a/examples/common/objAnim.h +++ b/examples/common/objAnim.h @@ -25,16 +25,17 @@ #ifndef OBJ_ANIM_H #define OBJ_ANIM_H -#include +#include "../../regression/common/shape_utils.h" -struct Shape; +#include class ObjAnim { public: // Factory function - static ObjAnim const * Create(std::vector objFiles, bool axis=true); + static ObjAnim const * Create(std::vector objFiles, bool axis=true, + Scheme scheme=kCatmark); // Destructor ~ObjAnim(); diff --git a/regression/common/far_utils.h b/regression/common/far_utils.h index 3a05a836..043289be 100644 --- a/regression/common/far_utils.h +++ b/regression/common/far_utils.h @@ -36,17 +36,34 @@ //------------------------------------------------------------------------------ +inline Scheme +ConvertSdcTypeToShapeScheme(OpenSubdiv::Sdc::SchemeType sdcScheme) { + + switch (sdcScheme) { + case OpenSubdiv::Sdc::SCHEME_BILINEAR: return kBilinear; + case OpenSubdiv::Sdc::SCHEME_CATMARK: return kCatmark; + case OpenSubdiv::Sdc::SCHEME_LOOP: return kLoop; + default: printf("unknown Sdc::SchemeType : %d\n", (int)sdcScheme); break; + } + return kCatmark; +} + +inline OpenSubdiv::Sdc::SchemeType +ConvertShapeSchemeToSdcType(Scheme shapeScheme) { + + switch (shapeScheme) { + case kBilinear: return OpenSubdiv::Sdc::SCHEME_BILINEAR; + case kCatmark: return OpenSubdiv::Sdc::SCHEME_CATMARK; + case kLoop: return OpenSubdiv::Sdc::SCHEME_LOOP; + default: printf("unknown Shape Scheme : %d\n", (int)shapeScheme); break; + } + return OpenSubdiv::Sdc::SCHEME_CATMARK; +} + inline OpenSubdiv::Sdc::SchemeType GetSdcType(Shape const & shape) { - OpenSubdiv::Sdc::SchemeType type=OpenSubdiv::Sdc::SCHEME_CATMARK; - - switch (shape.scheme) { - case kBilinear: type = OpenSubdiv::Sdc::SCHEME_BILINEAR; break; - case kCatmark : type = OpenSubdiv::Sdc::SCHEME_CATMARK; break; - case kLoop : type = OpenSubdiv::Sdc::SCHEME_LOOP; break; - } - return type; + return ConvertShapeSchemeToSdcType(shape.scheme); } inline OpenSubdiv::Sdc::Options diff --git a/tutorials/far/tutorial_9/far_tutorial_9.cpp b/tutorials/far/tutorial_9/far_tutorial_9.cpp index 1b92fd9b..be036e74 100644 --- a/tutorials/far/tutorial_9/far_tutorial_9.cpp +++ b/tutorials/far/tutorial_9/far_tutorial_9.cpp @@ -239,6 +239,7 @@ namespace { // Far::TopologyRefiner * createTopologyRefinerFromObj(std::string const & objFileName, + Sdc::SchemeType schemeType, PosVector & posVector) { const char * filename = objFileName.c_str(); @@ -251,7 +252,8 @@ namespace { ifs.close(); std::string shapeString = ss.str(); - shape = Shape::parseObj(shapeString.c_str(), kCatmark, false); + shape = Shape::parseObj( + shapeString.c_str(), ConvertSdcTypeToShapeScheme(schemeType), false); if (shape == 0) { fprintf(stderr, "Error: Cannot create Shape from .obj file '%s'\n", filename); return 0; @@ -553,7 +555,8 @@ main(int argc, char **argv) { Far::TopologyRefiner * baseRefinerPtr = args.inputObjFile.empty() ? createTopologyRefinerDefault(args.geoMultiplier, basePositions) : - createTopologyRefinerFromObj(args.inputObjFile, basePositions); + createTopologyRefinerFromObj(args.inputObjFile, args.schemeType, + basePositions); assert(baseRefinerPtr); Far::TopologyRefiner & baseRefiner = *baseRefinerPtr;