From 4752bcdd69720e324f6c907b0fa1801715ef6c9a Mon Sep 17 00:00:00 2001 From: asluk Date: Tue, 14 Apr 2015 10:03:02 -0700 Subject: [PATCH 1/2] Add support for lefthanded meshes. --- examples/common/objAnim.cpp | 2 +- examples/glViewer/glViewer.cpp | 2 +- examples/glViewer/init_shapes.h | 10 +- opensubdiv/far/topologyRefinerFactory.cpp | 24 +- opensubdiv/far/topologyRefinerFactory.h | 2 + regression/common/shape_utils.cpp | 4 +- regression/common/shape_utils.h | 3 +- regression/common/vtr_utils.h | 20 +- regression/hbr_regression/main.cpp | 2 +- regression/shapes/catmark_lefthanded.h | 3697 +++++++++++++++++++++ regression/shapes/catmark_righthanded.h | 3695 ++++++++++++++++++++ 11 files changed, 7445 insertions(+), 16 deletions(-) create mode 100644 regression/shapes/catmark_lefthanded.h create mode 100644 regression/shapes/catmark_righthanded.h diff --git a/examples/common/objAnim.cpp b/examples/common/objAnim.cpp index e3f98cfd..99009de4 100644 --- a/examples/common/objAnim.cpp +++ b/examples/common/objAnim.cpp @@ -119,7 +119,7 @@ ObjAnim::Create(std::vector objFiles, bool axis) { fflush(stdout); std::string str = ss.str(); - shape = Shape::parseObj(str.c_str(), kCatmark, axis); + shape = Shape::parseObj(str.c_str(), kCatmark, false, axis); if (i==0) { diff --git a/examples/glViewer/glViewer.cpp b/examples/glViewer/glViewer.cpp index 18cee8e5..16edbd9d 100644 --- a/examples/glViewer/glViewer.cpp +++ b/examples/glViewer/glViewer.cpp @@ -486,7 +486,7 @@ createOsdMesh(ShapeDesc const & shapeDesc, int level, int kernel, Scheme scheme= if (doAnim) { shape = g_objAnim->GetShape(); } else { - shape = Shape::parseObj(shapeDesc.data.c_str(), shapeDesc.scheme); + shape = Shape::parseObj(shapeDesc.data.c_str(), shapeDesc.scheme, shapeDesc.lefthanded); } // create Vtr mesh (topology) diff --git a/examples/glViewer/init_shapes.h b/examples/glViewer/init_shapes.h index c68ae79d..88d68064 100644 --- a/examples/glViewer/init_shapes.h +++ b/examples/glViewer/init_shapes.h @@ -26,12 +26,14 @@ struct ShapeDesc { - ShapeDesc(char const * iname, std::string const & idata, Scheme ischeme) : - name(iname), data(idata), scheme(ischeme) { } + ShapeDesc(char const * iname, std::string const & idata, Scheme ischeme, + bool ilefthanded=false) : + name(iname), data(idata), scheme(ischeme), lefthanded(ilefthanded) { } std::string name, data; Scheme scheme; + bool lefthanded; }; static std::vector g_defaultShapes; @@ -73,6 +75,8 @@ static std::vector g_defaultShapes; #include #include #include +#include +#include #include #include #include @@ -139,6 +143,8 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_hole_test2", catmark_hole_test2, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_hole_test3", catmark_hole_test3, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_hole_test4", catmark_hole_test4, kCatmark ) ); + g_defaultShapes.push_back( ShapeDesc("catmark_lefthanded", catmark_lefthanded, kCatmark, true ) ); + g_defaultShapes.push_back( ShapeDesc("catmark_righthanded", catmark_righthanded, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_pyramid_creases0", catmark_pyramid_creases0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_pyramid_creases1", catmark_pyramid_creases1, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_pyramid", catmark_pyramid, kCatmark ) ); diff --git a/opensubdiv/far/topologyRefinerFactory.cpp b/opensubdiv/far/topologyRefinerFactory.cpp index 84f92eba..51fa737b 100644 --- a/opensubdiv/far/topologyRefinerFactory.cpp +++ b/opensubdiv/far/topologyRefinerFactory.cpp @@ -296,9 +296,16 @@ TopologyRefinerFactory::assignCo IndexArray dstFaceVerts = refiner.setBaseFaceVertices(face); - for (int vert=0; vert=0; --vert) { - dstFaceVerts[vert] = desc.vertIndicesPerFace[idx++]; + dstFaceVerts[vert] = desc.vertIndicesPerFace[idx++]; + } + } else { + for (int vert=0; vert::assignFa IndexArray dstFaceValues = refiner.setBaseFVarFaceValues(face, channel); - for (int vert=0; vert= 0; --vert) { + + dstFaceValues[vert] = channelIndices[idx++]; + } + } else { + for (int vert=0; vertscheme = shapescheme; + s->lefthanded = lefthanded; char * str=const_cast(shapestr), line[256], buf[256], usemtl=-1; bool done = false; diff --git a/regression/common/shape_utils.h b/regression/common/shape_utils.h index 57b6a8b0..1e356abf 100644 --- a/regression/common/shape_utils.h +++ b/regression/common/shape_utils.h @@ -71,7 +71,7 @@ struct Shape { }; static Shape * parseObj(char const * Shapestr, Scheme schme, - int axis=1, bool parsemtl=false); + bool lefthanded=false, int axis=1, bool parsemtl=false); void parseMtllib(char const * stream); @@ -100,6 +100,7 @@ struct Shape { std::vector facenormals; std::vector tags; Scheme scheme; + bool lefthanded; char FindMaterial(char const * name) { for (int i=0; i<(int)mtls.size(); ++i) { diff --git a/regression/common/vtr_utils.h b/regression/common/vtr_utils.h index c3733b3e..063c804e 100644 --- a/regression/common/vtr_utils.h +++ b/regression/common/vtr_utils.h @@ -211,8 +211,14 @@ TopologyRefinerFactory::assignComponentTopology( Far::IndexArray dstFaceVerts = refiner.setBaseFaceVertices(i); //IndexArray dstFaceEdges = refiner.setBaseFaceEdges(i); - for (int j=0; j=0; --j) { + dstFaceVerts[j] = shape.faceverts[ofs++]; + } + } else { + for (int j=0; j::assignFaceVaryingTopology( Far::IndexArray dstFaceUVs = refiner.setBaseFVarFaceValues(i, channel); - for (int j=0; j= 0; --j) { + dstFaceUVs[j] = shape.faceuvs[ofs++]; + } + } else { + for (int j=0; j Date: Wed, 15 Apr 2015 14:32:48 -0700 Subject: [PATCH 2/2] Changed lefthanded flag to isLeftHanded. --- examples/glViewer/glViewer.cpp | 2 +- examples/glViewer/init_shapes.h | 8 ++++---- opensubdiv/far/topologyRefinerFactory.cpp | 4 ++-- opensubdiv/far/topologyRefinerFactory.h | 2 +- regression/common/shape_utils.cpp | 4 ++-- regression/common/shape_utils.h | 4 ++-- regression/common/vtr_utils.h | 4 ++-- regression/hbr_regression/main.cpp | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/glViewer/glViewer.cpp b/examples/glViewer/glViewer.cpp index 16edbd9d..5db5053b 100644 --- a/examples/glViewer/glViewer.cpp +++ b/examples/glViewer/glViewer.cpp @@ -486,7 +486,7 @@ createOsdMesh(ShapeDesc const & shapeDesc, int level, int kernel, Scheme scheme= if (doAnim) { shape = g_objAnim->GetShape(); } else { - shape = Shape::parseObj(shapeDesc.data.c_str(), shapeDesc.scheme, shapeDesc.lefthanded); + shape = Shape::parseObj(shapeDesc.data.c_str(), shapeDesc.scheme, shapeDesc.isLeftHanded); } // create Vtr mesh (topology) diff --git a/examples/glViewer/init_shapes.h b/examples/glViewer/init_shapes.h index 88d68064..4490722f 100644 --- a/examples/glViewer/init_shapes.h +++ b/examples/glViewer/init_shapes.h @@ -27,13 +27,13 @@ struct ShapeDesc { ShapeDesc(char const * iname, std::string const & idata, Scheme ischeme, - bool ilefthanded=false) : - name(iname), data(idata), scheme(ischeme), lefthanded(ilefthanded) { } + bool iIsLeftHanded=false) : + name(iname), data(idata), scheme(ischeme), isLeftHanded(iIsLeftHanded) { } std::string name, data; Scheme scheme; - bool lefthanded; + bool isLeftHanded; }; static std::vector g_defaultShapes; @@ -143,7 +143,7 @@ static void initShapes() { g_defaultShapes.push_back( ShapeDesc("catmark_hole_test2", catmark_hole_test2, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_hole_test3", catmark_hole_test3, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_hole_test4", catmark_hole_test4, kCatmark ) ); - g_defaultShapes.push_back( ShapeDesc("catmark_lefthanded", catmark_lefthanded, kCatmark, true ) ); + g_defaultShapes.push_back( ShapeDesc("catmark_lefthanded", catmark_lefthanded, kCatmark, true /*isLeftHanded*/ ) ); g_defaultShapes.push_back( ShapeDesc("catmark_righthanded", catmark_righthanded, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_pyramid_creases0", catmark_pyramid_creases0, kCatmark ) ); g_defaultShapes.push_back( ShapeDesc("catmark_pyramid_creases1", catmark_pyramid_creases1, kCatmark ) ); diff --git a/opensubdiv/far/topologyRefinerFactory.cpp b/opensubdiv/far/topologyRefinerFactory.cpp index 51fa737b..70fb63e2 100644 --- a/opensubdiv/far/topologyRefinerFactory.cpp +++ b/opensubdiv/far/topologyRefinerFactory.cpp @@ -296,7 +296,7 @@ TopologyRefinerFactory::assignCo IndexArray dstFaceVerts = refiner.setBaseFaceVertices(face); - if (desc.leftHanded) { + if (desc.isLeftHanded) { for (int vert=dstFaceVerts.size()-1; vert >=0; --vert) { dstFaceVerts[vert] = desc.vertIndicesPerFace[idx++]; @@ -380,7 +380,7 @@ TopologyRefinerFactory::assignFa IndexArray dstFaceValues = refiner.setBaseFVarFaceValues(face, channel); - if (desc.leftHanded) { + if (desc.isLeftHanded) { for (int vert=dstFaceValues.size(); vert >= 0; --vert) { dstFaceValues[vert] = channelIndices[idx++]; diff --git a/opensubdiv/far/topologyRefinerFactory.h b/opensubdiv/far/topologyRefinerFactory.h index aca91875..79f9e55e 100644 --- a/opensubdiv/far/topologyRefinerFactory.h +++ b/opensubdiv/far/topologyRefinerFactory.h @@ -74,7 +74,7 @@ public: int numHoles; Index const * holeIndices; - bool leftHanded; + bool isLeftHanded; // Face-varying data channel -- value indices correspond to vertex indices, // i.e. one for every vertex of every face: diff --git a/regression/common/shape_utils.cpp b/regression/common/shape_utils.cpp index 5da7ae74..504b4527 100644 --- a/regression/common/shape_utils.cpp +++ b/regression/common/shape_utils.cpp @@ -62,12 +62,12 @@ Shape::~Shape() { //------------------------------------------------------------------------------ Shape * Shape::parseObj(char const * shapestr, Scheme shapescheme, - bool lefthanded, int axis, bool parsemtl) { + bool isLeftHanded, int axis, bool parsemtl) { Shape * s = new Shape; s->scheme = shapescheme; - s->lefthanded = lefthanded; + s->isLeftHanded = isLeftHanded; char * str=const_cast(shapestr), line[256], buf[256], usemtl=-1; bool done = false; diff --git a/regression/common/shape_utils.h b/regression/common/shape_utils.h index 1e356abf..ec92d7b2 100644 --- a/regression/common/shape_utils.h +++ b/regression/common/shape_utils.h @@ -71,7 +71,7 @@ struct Shape { }; static Shape * parseObj(char const * Shapestr, Scheme schme, - bool lefthanded=false, int axis=1, bool parsemtl=false); + bool isLeftHanded=false, int axis=1, bool parsemtl=false); void parseMtllib(char const * stream); @@ -100,7 +100,7 @@ struct Shape { std::vector facenormals; std::vector tags; Scheme scheme; - bool lefthanded; + bool isLeftHanded; char FindMaterial(char const * name) { for (int i=0; i<(int)mtls.size(); ++i) { diff --git a/regression/common/vtr_utils.h b/regression/common/vtr_utils.h index 063c804e..9adeb564 100644 --- a/regression/common/vtr_utils.h +++ b/regression/common/vtr_utils.h @@ -211,7 +211,7 @@ TopologyRefinerFactory::assignComponentTopology( Far::IndexArray dstFaceVerts = refiner.setBaseFaceVertices(i); //IndexArray dstFaceEdges = refiner.setBaseFaceEdges(i); - if (shape.lefthanded) { + if (shape.isLeftHanded) { for (int j=dstFaceVerts.size()-1; j>=0; --j) { dstFaceVerts[j] = shape.faceverts[ofs++]; } @@ -242,7 +242,7 @@ TopologyRefinerFactory::assignFaceVaryingTopology( Far::IndexArray dstFaceUVs = refiner.setBaseFVarFaceValues(i, channel); - if (shape.lefthanded) { + if (shape.isLeftHanded) { for (int j=dstFaceUVs.size()-1; j >= 0; --j) { dstFaceUVs[j] = shape.faceuvs[ofs++]; } diff --git a/regression/hbr_regression/main.cpp b/regression/hbr_regression/main.cpp index 8b5ec731..51247ea9 100644 --- a/regression/hbr_regression/main.cpp +++ b/regression/hbr_regression/main.cpp @@ -129,7 +129,7 @@ static Shape * readShape( char const * fname, Scheme scheme ) { shapeStr[size]='\0'; - return Shape::parseObj( shapeStr, scheme, false, 1 ); + return Shape::parseObj( shapeStr, scheme, false /*isLeftHanded*/, 1 ); } #define STR(x) x