7#ifndef PXR_IMAGING_HD_MESH_UTIL_H
8#define PXR_IMAGING_HD_MESH_UTIL_H
11#include "pxr/imaging/hd/api.h"
12#include "pxr/imaging/hd/version.h"
13#include "pxr/imaging/hd/types.h"
14#include "pxr/imaging/hd/meshTopology.h"
16#include "pxr/usd/sdf/path.h"
23#include "pxr/base/vt/value.h"
25PXR_NAMESPACE_OPEN_SCOPE
49 HdQuadInfo() : pointsOffset(0), numAdditionalPoints(0), maxNumVert(0) { }
52 bool IsAllQuads()
const {
return numAdditionalPoints == 0; }
55 int numAdditionalPoints;
57 std::vector<int> numVerts;
58 std::vector<int> verts;
69 : _topology(topology), _id(
id) {}
100 VtIntArray *primitiveParams,
101 VtIntArray *edgeIndices =
nullptr)
const;
152 VtIntArray *primitiveParams,
153 VtVec2iArray *edgeIndices =
nullptr)
const;
159 VtIntArray *primitiveParams,
160 VtVec2iArray *edgeIndices =
nullptr)
const;
172 VtValue *quadrangulated)
const;
183 VtValue *quadrangulated)
const;
199 std::vector<GfVec2i> * edgeVerticesOut,
200 std::vector<int> * firstEdgeIndexForFacesOut =
nullptr)
const;
224 static int EncodeCoarseFaceParam(
int faceIndex,
int edgeFlag) {
225 return ((faceIndex << 2) | (edgeFlag & 3));
227 static int DecodeFaceIndexFromCoarseFaceParam(
int coarseFaceParam) {
228 return (coarseFaceParam >> 2);
230 static int DecodeEdgeFlagFromCoarseFaceParam(
int coarseFaceParam) {
231 return (coarseFaceParam & 3);
239 int _ComputeNumQuads(VtIntArray
const &numVerts,
240 VtIntArray
const &holeIndices,
241 bool *invalidFaceFound =
nullptr)
const;
244 void _ComputeQuadIndices(
246 VtIntArray *primitiveParams,
247 VtVec2iArray *edgeIndices,
248 bool triangulate =
false)
const;
309 bool GetVerticesForEdgeIndex(
int edgeId,
GfVec2i * edgeVerticesOut)
const;
312 bool GetVerticesForEdgeIndices(
313 std::vector<int>
const & edgeIndices,
314 std::vector<GfVec2i> * edgeVerticesOut)
const;
317 bool GetEdgeIndices(
GfVec2i const & edgeVertices,
318 std::vector<int> * edgeIndicesOut)
const;
331 if (verts[0] > verts[1]) {
332 std::swap(verts[0], verts[1]);
340 struct _CompareEdgeVertices {
341 bool operator() (_Edge
const &lhs, _Edge
const & rhs)
const {
342 return (lhs.verts[0] < rhs.verts[0] ||
343 (lhs.verts[0] == rhs.verts[0] &&
344 lhs.verts[1] < rhs.verts[1]));
348 struct _EdgeVerticesHash {
350 inline size_t operator()(
GfVec2i const& v)
const {
352 int theMin = v[0], theMax = v[1];
353 if (theMin > theMax) {
354 std::swap(theMin, theMax);
357 size_t y = x + theMax;
358 return x + (y * (y + 1)) / 2;
363 std::vector<int> _firstEdgeIndexForFaces;
365 std::vector<GfVec2i> _edgeVertices;
366 std::vector<_Edge> _edgesByIndex;
377 static int const NumIndicesPerQuad = 4;
378 static int const NumIndicesPerTriQuad = 6;
381 : _outputPtr(indicesBuffer)
382 , _triangulate(triangulate)
385 void EmitQuadFace(
GfVec4i const & quadIndices) {
387 *_outputPtr++ = quadIndices[0];
388 *_outputPtr++ = quadIndices[1];
389 *_outputPtr++ = quadIndices[2];
390 *_outputPtr++ = quadIndices[2];
391 *_outputPtr++ = quadIndices[3];
392 *_outputPtr++ = quadIndices[0];
394 *_outputPtr++ = quadIndices[0];
395 *_outputPtr++ = quadIndices[1];
396 *_outputPtr++ = quadIndices[2];
397 *_outputPtr++ = quadIndices[3];
403 bool const _triangulate;
407PXR_NAMESPACE_CLOSE_SCOPE
Basic type for a vector of 2 int components.
Basic type for a vector of 4 int components.
Mesh edges are described as a pair of adjacent vertices encoded as GfVec2i.
HD_API VtIntArray CollectFaceEdgeIndices(VtIntArray const &faceIndices) const
Returns the edge indices for all faces in faceIndices.
Topology data for meshes.
Helper class for emitting a buffer of quad indices, optionally splitting each quad into two triangles...
A collection of utility algorithms for generating triangulation and quadrangulation of an input topol...
HD_API bool ComputeTriangulatedFaceVaryingPrimvar(void const *source, int numElements, HdType dataType, VtValue *triangulated) const
Return a triangulation of a face-varying primvar.
HD_API void ComputeTriangleIndices(VtVec3iArray *indices, VtIntArray *primitiveParams, VtIntArray *edgeIndices=nullptr) const
Return a triangulation of the input topology.
HD_API bool ComputeQuadrangulatedFaceVaryingPrimvar(void const *source, int numElements, HdType dataType, VtValue *quadrangulated) const
Return a quadrangulation of a face-varying primvar.
HD_API void ComputeQuadIndices(VtIntArray *indices, VtIntArray *primitiveParams, VtVec2iArray *edgeIndices=nullptr) const
Return quadrangulated indices of the input topology.
HD_API void ComputeTriQuadIndices(VtIntArray *indices, VtIntArray *primitiveParams, VtVec2iArray *edgeIndices=nullptr) const
Return triquad indices (triangulated after quadrangulation) of the input topology.
HD_API void ComputeQuadInfo(HdQuadInfo *quadInfo) const
Generate a quadInfo struct for the input topology.
HD_API bool ComputeQuadrangulatedPrimvar(HdQuadInfo const *qi, void const *source, int numElements, HdType dataType, VtValue *quadrangulated) const
Return a quadrangulation of a per-vertex primvar.
HD_API void EnumerateEdges(std::vector< GfVec2i > *edgeVerticesOut, std::vector< int > *firstEdgeIndexForFacesOut=nullptr) const
Return a buffer filled with face vertex index pairs corresponding to the sequence in which edges are ...
A path value used to locate objects in layers or scenegraphs.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
A helper class for quadrangulation computation.
bool IsAllQuads() const
Returns true if the mesh is all-quads.