24#ifndef PXR_IMAGING_HD_ST_MESH_H
25#define PXR_IMAGING_HD_ST_MESH_H
28#include "pxr/imaging/hdSt/api.h"
29#include "pxr/imaging/hd/version.h"
30#include "pxr/imaging/hd/changeTracker.h"
31#include "pxr/imaging/hd/drawingCoord.h"
32#include "pxr/imaging/hd/mesh.h"
33#include "pxr/imaging/hd/perfLog.h"
35#include "pxr/usd/sdf/path.h"
40PXR_NAMESPACE_OPEN_SCOPE
46using HdSt_VertexAdjacencyBuilderSharedPtr =
47 std::shared_ptr<class HdSt_VertexAdjacencyBuilder>;
48using HdBufferSourceSharedPtr = std::shared_ptr<class HdBufferSource>;
49using HdSt_MeshTopologySharedPtr = std::shared_ptr<class HdSt_MeshTopology>;
51using HdStResourceRegistrySharedPtr =
52 std::shared_ptr<class HdStResourceRegistry>;
59 HF_MALLOC_TAG_NEW(
"new HdStMesh");
74 HdDirtyBits *dirtyBits,
75 TfToken const &reprToken)
override;
101 HdDirtyBits *dirtyBitsState);
103 HdBufferArrayRangeSharedPtr
104 _GetSharedPrimvarRange(uint64_t primvarId,
105 HdBufferSpecVector
const &updatedOrAddedSpecs,
106 HdBufferSpecVector
const &removedSpecs,
107 HdBufferArrayRangeSharedPtr
const &curRange,
108 bool * isFirstInstance,
109 HdStResourceRegistrySharedPtr
const &resourceRegistry)
const;
112 const SdfPath &materialId)
const;
115 const HdSt_MeshTopologySharedPtr &topology)
const;
117 bool _MaterialHasLimitSurface(
const HdRenderIndex &renderIndex,
118 const SdfPath &materialId)
const;
123 bool _UseSmoothNormals(HdSt_MeshTopologySharedPtr
const& topology)
const;
129 HdStDrawItem *drawItem,
130 HdDirtyBits *dirtyBits,
132 const HdReprSharedPtr &repr,
134 bool requireSmoothNormals,
135 bool requireFlatNormals,
136 int geomSubsetDescIndex);
140 HdStDrawItem *drawItem,
146 bool updateMaterialNetworkShader,
147 bool updateGeometricShader);
154 HdStDrawItem *drawItem,
155 HdDirtyBits *dirtyBits,
157 const HdReprSharedPtr &repr,
159 int geomSubsetDescIndex);
163 HdStDrawItem *drawItem,
165 const HdReprSharedPtr &repr,
166 const HdGeomSubsets &geomSubsets,
167 size_t oldNumGeomSubsets);
169 void _CreateTopologyRangeForGeomSubset(
170 HdStResourceRegistrySharedPtr resourceRegistry,
173 HdStDrawItem *drawItem,
175 HdBufferSourceSharedPtr indicesSource,
176 HdBufferSourceSharedPtr fvarIndicesSource,
177 HdBufferSourceSharedPtr geomSubsetFaceIndicesHelperSource,
178 const VtIntArray &faceIndices,
182 const HdReprSharedPtr &repr,
184 HdStDrawItem *drawItem,
185 int geomSubsetDescIndex,
186 HdDirtyBits *dirtyBits,
188 HdSt_MeshTopologySharedPtr topology);
190 void _PopulateAdjacency(
191 HdStResourceRegistrySharedPtr
const &resourceRegistry);
195 const HdReprSharedPtr &repr,
197 HdStDrawItem *drawItem,
198 int geomSubsetDescIndex,
199 HdDirtyBits *dirtyBits,
200 bool requireSmoothNormals);
204 const HdReprSharedPtr &repr,
206 HdStDrawItem *drawItem,
207 int geomSubsetDescIndex,
208 HdDirtyBits *dirtyBits);
212 const HdReprSharedPtr &repr,
214 HdStDrawItem *drawItem,
215 int geomSubsetDescIndex,
216 HdDirtyBits *dirtyBits,
217 bool requireFlatNormals);
226 class _FvarTopologyTracker
229 const TopologyToPrimvarVector & GetTopologyToPrimvarVector()
const {
234 void AddOrUpdateTopology(
const TfToken &primvar,
235 const VtIntArray &topology) {
236 for (
size_t i = 0; i < _topologies.size(); ++i) {
238 if (_topologies[i].first == topology) {
240 if (std::find(_topologies[i].second.begin(),
241 _topologies[i].second.end(),
242 primvar) == _topologies[i].second.end()) {
244 RemovePrimvar(primvar);
245 _topologies[i].second.push_back(primvar);
252 RemovePrimvar(primvar);
253 _topologies.push_back(
254 std::pair<VtIntArray, std::vector<TfToken>>(
255 topology, {primvar}));
259 void RemovePrimvar(
const TfToken &primvar) {
260 for (
size_t i = 0; i < _topologies.size(); ++i) {
261 _topologies[i].second.erase(std::find(
262 _topologies[i].second.begin(),
263 _topologies[i].second.end(),
264 primvar), _topologies[i].second.end());
271 void RemoveUnusedTopologies() {
272 _topologies.erase(std::remove_if(
273 _topologies.begin(), _topologies.end(), NoPrimvars),
279 int GetChannelFromPrimvar(
const TfToken &primvar)
const {
280 for (
size_t i = 0; i < _topologies.size(); ++i) {
281 if (std::find(_topologies[i].second.begin(),
282 _topologies[i].second.end(),
284 _topologies[i].second.end()) {
292 std::vector<VtIntArray> GetFvarTopologies()
const {
293 std::vector<VtIntArray> fvarTopologies;
294 for (
const auto& it : _topologies) {
295 fvarTopologies.push_back(it.first);
297 return fvarTopologies;
300 size_t GetNumTopologies()
const {
301 return _topologies.size();
307 static bool NoPrimvars(
const std::pair<VtIntArray, std::vector<TfToken>>
309 return topology.second.empty();
312 TopologyToPrimvarVector _topologies;
317 HullTopology = HdDrawingCoord::CustomSlotsBegin,
325 enum DirtyBits : HdDirtyBits {
326 DirtySmoothNormals = HdChangeTracker::CustomBitsBegin,
327 DirtyFlatNormals = (DirtySmoothNormals << 1),
328 DirtyIndices = (DirtyFlatNormals << 1),
329 DirtyHullIndices = (DirtyIndices << 1),
330 DirtyPointsIndices = (DirtyHullIndices << 1)
333 HdSt_MeshTopologySharedPtr _topology;
334 HdSt_VertexAdjacencyBuilderSharedPtr _vertexAdjacencyBuilder;
336 HdTopology::ID _topologyId;
337 HdTopology::ID _vertexPrimvarId;
338 HdDirtyBits _customDirtyBitsInUse;
340 HdType _pointsDataType;
341 HdInterpolation _sceneNormalsInterpolation;
342 HdCullStyle _cullStyle;
343 bool _hasMirroredTransform : 1;
344 bool _doubleSided : 1;
345 bool _flatShadingEnabled : 1;
346 bool _displacementEnabled : 1;
347 bool _limitNormals : 1;
348 bool _sceneNormals : 1;
349 bool _hasVaryingTopology : 1;
351 bool _displayOpacity : 1;
352 bool _occludedSelectionShowsThrough : 1;
353 bool _pointsShadingEnabled : 1;
355 std::unique_ptr<_FvarTopologyTracker> _fvarTopologyTracker;
359PXR_NAMESPACE_CLOSE_SCOPE
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine.
Hydra Schema for a subdivision surface or poly-mesh object.
Topology data for meshes.
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
Adapter class providing data exchange with the client scene graph.
A subdivision surface or poly-mesh object.
HDST_API void Sync(HdSceneDelegate *delegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits, TfToken const &reprToken) override
Pull invalidated scene data and prepare/update the renderable representation.
HDST_API HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override
This callback from Rprim gives the prim an opportunity to set additional dirty bits based on those al...
HDST_API void _InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits) override
Initialize the given representation of this Rprim.
HDST_API HdDirtyBits GetInitialDirtyBitsMask() const override
Returns the set of dirty bits that should be added to the change tracker for this prim,...
HDST_API HdMeshTopologySharedPtr GetTopology() const override
Topology (member) getter.
static HDST_API bool IsEnabledPackedNormals()
Returns whether packed (10_10_10 bits) normals to be used.
HDST_API void Finalize(HdRenderParam *renderParam) override
Finalizes object resources.
A path value used to locate objects in layers or scenegraphs.
Token for efficient comparison, assignment, and hashing of known strings.
Descriptor to configure the drawItem(s) for a repr.