11using OpenSubdiv::Far::ConstPatchParamArray;
12using OpenSubdiv::Far::Index;
13using OpenSubdiv::Far::PatchParam;
14using OpenSubdiv::Far::PatchParamTable;
15using OpenSubdiv::Far::PatchTable;
27 for (
int i = 0; i < 4; ++i) {
38 assert(!children[quadrant].isSet);
39 children[quadrant].isSet =
true;
40 children[quadrant].isLeaf = isLeaf;
41 children[quadrant].index = index;
44inline void PatchMap::assignRootNode(
QuadNode *node,
int index)
48 node->SetChildren(index);
61 node->
SetChild(quadrant, index,
true);
64 if (node->children[quadrant].isSet) {
65 return &_quadtree[node->children[quadrant].index];
68 int newChildNodeIndex = (
int)_quadtree.size();
69 _quadtree.push_back(QuadNode());
70 node->SetChild(quadrant, newChildNodeIndex,
false);
71 return &_quadtree[newChildNodeIndex];
79 : _minPatchFace(-1), _maxPatchFace(-1), _maxDepth(0)
82 _patchesAreTriangular = patchTable.GetVaryingPatchDescriptor().GetNumControlVertices() == 3;
84 if (patchTable.GetNumPatchesTotal() > 0) {
85 initializeHandles(patchTable);
86 initializeQuadtree(patchTable);
90void PatchMap::initializeHandles(PatchTable
const &patchTable)
97 _minPatchFace = (
int)patchTable.GetPatchParamTable()[0].GetFaceId();
98 _maxPatchFace = _minPatchFace;
100 int numArrays = (
int)patchTable.GetNumPatchArrays();
101 int numPatches = (
int)patchTable.GetNumPatchesTotal();
103 _handles.resize(numPatches);
105 for (
int pArray = 0, handleIndex = 0; pArray < numArrays; ++pArray) {
107 ConstPatchParamArray
params = patchTable.GetPatchParams(pArray);
109 int patchSize = patchTable.GetPatchArrayDescriptor(pArray).GetNumControlVertices();
111 for (Index j = 0; j < patchTable.GetNumPatches(pArray); ++j, ++handleIndex) {
113 Handle &h = _handles[handleIndex];
115 h.arrayIndex = pArray;
116 h.patchIndex = handleIndex;
117 h.vertIndex = j * patchSize;
119 int patchFaceId =
params[j].GetFaceId();
120 _minPatchFace = std::min(_minPatchFace, patchFaceId);
121 _maxPatchFace = std::max(_maxPatchFace, patchFaceId);
126void PatchMap::initializeQuadtree(PatchTable
const &patchTable)
133 int nPatchFaces = (_maxPatchFace - _minPatchFace) + 1;
135 int nHandles =
int(_handles.size());
137 _quadtree.reserve(nPatchFaces + nHandles);
138 _quadtree.resize(nPatchFaces);
140 PatchParamTable
const &
params = patchTable.GetPatchParamTable();
142 for (
int handle = 0; handle < nHandles; ++handle) {
144 PatchParam
const ¶m =
params[handle];
146 int depth = param.GetDepth();
147 int rootDepth = param.NonQuadRoot();
149 _maxDepth = std::max(_maxDepth, depth);
151 QuadNode *node = &_quadtree[param.GetFaceId() - _minPatchFace];
153 if (depth == rootDepth) {
154 assignRootNode(node, handle);
158 if (!_patchesAreTriangular) {
160 int u = param.GetU();
161 int v = param.GetV();
163 for (
int j = rootDepth + 1; j <= depth; ++j) {
164 int uBit = (u >> (depth - j)) & 1;
165 int vBit = (
v >> (depth - j)) & 1;
167 int quadrant = (vBit << 1) | uBit;
169 node = assignLeafOrChildNode(node, (j == depth), quadrant, handle);
176 param.UnnormalizeTriangle(u,
v);
179 bool triRotated =
false;
181 for (
int j = rootDepth + 1; j <= depth; ++j, median *= 0.5) {
182 int quadrant = transformUVToTriQuadrant(median, u,
v, triRotated);
184 node = assignLeafOrChildNode(node, (j == depth), quadrant, handle);
190 QuadTree tmpTree = _quadtree;
191 _quadtree.swap(tmpTree);
ATTR_WARN_UNUSED_RESULT const BMVert * v
PatchMap(OpenSubdiv::Far::PatchTable const &patchTable)
Constructor.
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void SetChildren(int index)
void SetChild(int quadrant, int index, bool isLeaf)