2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// Copyright 2013 Pixar
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
|
|
|
//
|
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
|
|
|
//
|
|
|
|
// You may obtain a copy of the Apache License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef VTR_UTILS_H
|
|
|
|
#define VTR_UTILS_H
|
|
|
|
|
|
|
|
#include <far/topologyRefinerFactory.h>
|
|
|
|
#include <far/types.h>
|
|
|
|
|
|
|
|
#include "../../regression/common/shape_utils.h"
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
inline OpenSubdiv::Sdc::Type
|
|
|
|
GetSdcType(Shape const & shape) {
|
|
|
|
|
|
|
|
OpenSubdiv::Sdc::Type type=OpenSubdiv::Sdc::TYPE_CATMARK;
|
|
|
|
|
|
|
|
switch (shape.scheme) {
|
|
|
|
case kBilinear: type = OpenSubdiv::Sdc::TYPE_BILINEAR; break;
|
|
|
|
case kCatmark : type = OpenSubdiv::Sdc::TYPE_CATMARK; break;
|
|
|
|
case kLoop : type = OpenSubdiv::Sdc::TYPE_LOOP; break;
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline OpenSubdiv::Sdc::Options
|
|
|
|
GetSdcOptions(Shape const & shape) {
|
|
|
|
|
|
|
|
typedef OpenSubdiv::Sdc::Options Options;
|
|
|
|
|
|
|
|
Options result;
|
|
|
|
|
2014-12-12 19:10:17 +00:00
|
|
|
result.SetVtxBoundaryInterpolation(Options::VTX_BOUNDARY_EDGE_ONLY);
|
2014-09-05 22:07:46 +00:00
|
|
|
result.SetCreasingMethod(Options::CREASE_UNIFORM);
|
2014-12-11 17:19:41 +00:00
|
|
|
result.SetTriangleSubdivision(Options::TRI_SUB_CATMARK);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
for (int i=0; i<(int)shape.tags.size(); ++i) {
|
|
|
|
|
|
|
|
Shape::tag * t = shape.tags[i];
|
|
|
|
|
|
|
|
if (t->name=="interpolateboundary") {
|
|
|
|
if ((int)t->intargs.size()!=1) {
|
|
|
|
printf("expecting 1 integer for \"interpolateboundary\" tag n. %d\n", i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch( t->intargs[0] ) {
|
2014-12-12 19:10:17 +00:00
|
|
|
case 0 : result.SetVtxBoundaryInterpolation(Options::VTX_BOUNDARY_NONE); break;
|
|
|
|
case 1 : result.SetVtxBoundaryInterpolation(Options::VTX_BOUNDARY_EDGE_AND_CORNER); break;
|
|
|
|
case 2 : result.SetVtxBoundaryInterpolation(Options::VTX_BOUNDARY_EDGE_ONLY); break;
|
2014-09-05 22:07:46 +00:00
|
|
|
default: printf("unknown interpolate boundary : %d\n", t->intargs[0] ); break;
|
|
|
|
}
|
|
|
|
} else if (t->name=="facevaryinginterpolateboundary") {
|
|
|
|
if ((int)t->intargs.size()!=1) {
|
|
|
|
printf("expecting 1 integer for \"facevaryinginterpolateboundary\" tag n. %d\n", i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch( t->intargs[0] ) {
|
2014-10-10 18:57:43 +00:00
|
|
|
case 0 : result.SetFVarLinearInterpolation(Options::FVAR_LINEAR_NONE); break;
|
|
|
|
case 1 : result.SetFVarLinearInterpolation(Options::FVAR_LINEAR_CORNERS_ONLY); break;
|
|
|
|
case 2 : result.SetFVarLinearInterpolation(Options::FVAR_LINEAR_CORNERS_PLUS1); break;
|
|
|
|
case 3 : result.SetFVarLinearInterpolation(Options::FVAR_LINEAR_CORNERS_PLUS2); break;
|
|
|
|
case 4 : result.SetFVarLinearInterpolation(Options::FVAR_LINEAR_BOUNDARIES); break;
|
|
|
|
case 5 : result.SetFVarLinearInterpolation(Options::FVAR_LINEAR_ALL); break;
|
2014-09-05 22:07:46 +00:00
|
|
|
default: printf("unknown interpolate boundary : %d\n", t->intargs[0] ); break;
|
|
|
|
}
|
|
|
|
} else if (t->name=="facevaryingpropagatecorners") {
|
|
|
|
if ((int)t->intargs.size()==1) {
|
|
|
|
// XXXX no propagate corners in Options
|
|
|
|
assert(0);
|
|
|
|
} else
|
|
|
|
printf( "expecting single int argument for \"facevaryingpropagatecorners\"\n" );
|
|
|
|
} else if (t->name=="creasemethod") {
|
|
|
|
|
|
|
|
if ((int)t->stringargs.size()==0) {
|
|
|
|
printf("the \"creasemethod\" tag expects a string argument\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-12-11 17:19:41 +00:00
|
|
|
if (t->stringargs[0]=="normal") {
|
2014-09-05 22:07:46 +00:00
|
|
|
result.SetCreasingMethod(Options::CREASE_UNIFORM);
|
2014-12-11 17:19:41 +00:00
|
|
|
} else if (t->stringargs[0]=="chaikin") {
|
2014-09-05 22:07:46 +00:00
|
|
|
result.SetCreasingMethod(Options::CREASE_CHAIKIN);
|
2014-12-11 17:19:41 +00:00
|
|
|
} else {
|
2014-09-05 22:07:46 +00:00
|
|
|
printf("the \"creasemethod\" tag only accepts \"normal\" or \"chaikin\" as value (%s)\n", t->stringargs[0].c_str());
|
2014-12-11 17:19:41 +00:00
|
|
|
}
|
|
|
|
} else if (t->name=="smoothtriangles") {
|
|
|
|
|
|
|
|
if (shape.scheme!=kCatmark) {
|
|
|
|
printf("the \"smoothtriangles\" tag can only be applied to Catmark meshes\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (t->stringargs[0]=="catmark") {
|
|
|
|
result.SetTriangleSubdivision(Options::TRI_SUB_CATMARK);
|
|
|
|
} else if (t->stringargs[0]=="smooth") {
|
|
|
|
result.SetTriangleSubdivision(Options::TRI_SUB_SMOOTH);
|
|
|
|
} else {
|
|
|
|
printf("the \"smoothtriangles\" tag only accepts \"catmark\" or \"smooth\" as value (%s)\n", t->stringargs[0].c_str());
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InterpolateFVarData(OpenSubdiv::Far::TopologyRefiner & refiner,
|
|
|
|
Shape const & shape, std::vector<float> & fvarData);
|
2014-12-04 04:21:06 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
|
|
|
namespace Far {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline void
|
|
|
|
TopologyRefinerFactory<Shape>::resizeComponentTopology(
|
|
|
|
Far::TopologyRefiner & refiner, Shape const & shape) {
|
|
|
|
|
|
|
|
int nfaces = shape.GetNumFaces(),
|
|
|
|
nverts = shape.GetNumVertices();
|
|
|
|
|
|
|
|
refiner.setNumBaseFaces(nfaces);
|
|
|
|
for (int i=0; i<nfaces; ++i) {
|
|
|
|
|
|
|
|
int nv = shape.nvertsPerFace[i];
|
|
|
|
refiner.setNumBaseFaceVertices(i, nv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vertices and vert-faces and vert-edges
|
|
|
|
refiner.setNumBaseVertices(nverts);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
template <>
|
|
|
|
inline void
|
|
|
|
TopologyRefinerFactory<Shape>::assignComponentTopology(
|
|
|
|
Far::TopologyRefiner & refiner, Shape const & shape) {
|
|
|
|
|
|
|
|
{ // Face relations:
|
2015-01-05 00:33:18 +00:00
|
|
|
int nfaces = refiner.GetNumFaces(0);
|
2014-12-04 04:21:06 +00:00
|
|
|
|
|
|
|
for (int i=0, ofs=0; i < nfaces; ++i) {
|
|
|
|
|
|
|
|
Far::IndexArray dstFaceVerts = refiner.setBaseFaceVertices(i);
|
|
|
|
//IndexArray dstFaceEdges = refiner.setBaseFaceEdges(i);
|
|
|
|
|
|
|
|
for (int j=0; j<dstFaceVerts.size(); ++j) {
|
|
|
|
dstFaceVerts[j] = shape.faceverts[ofs++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
template <>
|
|
|
|
inline void
|
|
|
|
TopologyRefinerFactory<Shape>::assignFaceVaryingTopology(
|
|
|
|
Far::TopologyRefiner & refiner, Shape const & shape) {
|
|
|
|
|
|
|
|
// UV layyout (we only parse 1 channel)
|
|
|
|
if (not shape.faceuvs.empty()) {
|
|
|
|
|
2015-01-05 00:33:18 +00:00
|
|
|
int nfaces = refiner.GetNumFaces(0),
|
|
|
|
channel = refiner.createBaseFVarChannel( (int)shape.faceuvs.size() );
|
2014-12-04 04:21:06 +00:00
|
|
|
|
|
|
|
for (int i=0, ofs=0; i < nfaces; ++i) {
|
|
|
|
|
|
|
|
Far::IndexArray dstFaceUVs =
|
2015-01-05 00:33:18 +00:00
|
|
|
refiner.setBaseFVarFaceValues(i, channel);
|
2014-12-04 04:21:06 +00:00
|
|
|
|
|
|
|
for (int j=0; j<dstFaceUVs.size(); ++j) {
|
|
|
|
dstFaceUVs[j] = shape.faceuvs[ofs++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
template <>
|
|
|
|
inline void
|
|
|
|
TopologyRefinerFactory<Shape>::assignComponentTags(
|
|
|
|
Far::TopologyRefiner & refiner, Shape const & shape) {
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<(int)shape.tags.size(); ++i) {
|
|
|
|
|
|
|
|
Shape::tag * t = shape.tags[i];
|
|
|
|
|
|
|
|
if (t->name=="crease") {
|
|
|
|
|
|
|
|
for (int j=0; j<(int)t->intargs.size()-1; j += 2) {
|
|
|
|
|
|
|
|
OpenSubdiv::Vtr::Index edge = refiner.FindEdge(/*level*/0, t->intargs[j], t->intargs[j+1]);
|
|
|
|
if (edge==OpenSubdiv::Vtr::INDEX_INVALID) {
|
|
|
|
printf("cannot find edge for crease tag (%d,%d)\n", t->intargs[j], t->intargs[j+1] );
|
|
|
|
} else {
|
|
|
|
int nfloat = (int) t->floatargs.size();
|
2015-01-05 00:33:18 +00:00
|
|
|
refiner.setBaseEdgeSharpness(edge,
|
|
|
|
std::max(0.0f, ((nfloat > 1) ? t->floatargs[j] : t->floatargs[0])));
|
2014-12-04 04:21:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (t->name=="corner") {
|
|
|
|
|
|
|
|
for (int j=0; j<(int)t->intargs.size(); ++j) {
|
|
|
|
int vertex = t->intargs[j];
|
|
|
|
if (vertex<0 or vertex>=refiner.GetNumVertices(/*level*/0)) {
|
|
|
|
printf("cannot find vertex for corner tag (%d)\n", vertex );
|
|
|
|
} else {
|
|
|
|
int nfloat = (int) t->floatargs.size();
|
2015-01-05 00:33:18 +00:00
|
|
|
refiner.setBaseVertexSharpness(vertex,
|
|
|
|
std::max(0.0f, ((nfloat > 1) ? t->floatargs[j] : t->floatargs[0])));
|
2014-12-04 04:21:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{ // Hole tags
|
|
|
|
for (int i=0; i<(int)shape.tags.size(); ++i) {
|
|
|
|
Shape::tag * t = shape.tags[i];
|
|
|
|
if (t->name=="hole") {
|
|
|
|
for (int j=0; j<(int)t->intargs.size(); ++j) {
|
|
|
|
refiner.setBaseFaceHole(t->intargs[j], true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline void
|
2014-12-09 01:24:54 +00:00
|
|
|
TopologyRefinerFactory<Shape>::reportInvalidTopology(
|
|
|
|
TopologyRefinerFactory::TopologyError /* errCode */, char const * msg, Shape const & /* shape */) {
|
2014-12-04 04:21:06 +00:00
|
|
|
Warning(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Far
|
|
|
|
|
|
|
|
} // namespace OPENSUBDIV_VERSION
|
|
|
|
} // namespace OpenSubdiv
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif /* VTR_UTILS_H */
|